buyingyi | c73348c | 2012-11-02 00:31:31 +0000 | [diff] [blame^] | 1 | DROP TABLE lineitem; |
| 2 | DROP TABLE orders; |
| 3 | DROP TABLE q12_shipping; |
| 4 | |
| 5 | -- create the tables and load the data |
| 6 | create external table lineitem (L_ORDERKEY INT, L_PARTKEY INT, L_SUPPKEY INT, L_LINENUMBER INT, L_QUANTITY DOUBLE, L_EXTENDEDPRICE DOUBLE, L_DISCOUNT DOUBLE, L_TAX DOUBLE, L_RETURNFLAG STRING, L_LINESTATUS STRING, L_SHIPDATE STRING, L_COMMITDATE STRING, L_RECEIPTDATE STRING, L_SHIPINSTRUCT STRING, L_SHIPMODE STRING, L_COMMENT STRING) ROW FORMAT DELIMITED FIELDS TERMINATED BY '|' STORED AS TEXTFILE LOCATION '/tpch/10/lineitem'; |
| 7 | create external table orders (O_ORDERKEY INT, O_CUSTKEY INT, O_ORDERSTATUS STRING, O_TOTALPRICE DOUBLE, O_ORDERDATE STRING, O_ORDERPRIORITY STRING, O_CLERK STRING, O_SHIPPRIORITY INT, O_COMMENT STRING) ROW FORMAT DELIMITED FIELDS TERMINATED BY '|' STORED AS TEXTFILE LOCATION '/tpch/10/orders'; |
| 8 | |
| 9 | -- create the result table |
| 10 | create table q12_shipping(l_shipmode string, high_line_count double, low_line_count double); |
| 11 | |
| 12 | set mapred.min.split.size=536870912; |
| 13 | set hive.exec.reducers.bytes.per.reducer=1225000000; |
| 14 | |
| 15 | -- the query |
| 16 | insert overwrite table q12_shipping |
| 17 | select |
| 18 | l_shipmode, |
| 19 | sum(case |
| 20 | when o_orderpriority ='1-URGENT' |
| 21 | or o_orderpriority ='2-HIGH' |
| 22 | then 1 |
| 23 | else 0 |
| 24 | end |
| 25 | ) as high_line_count, |
| 26 | sum(case |
| 27 | when o_orderpriority <> '1-URGENT' |
| 28 | and o_orderpriority <> '2-HIGH' |
| 29 | then 1 |
| 30 | else 0 |
| 31 | end |
| 32 | ) as low_line_count |
| 33 | from |
| 34 | orders o join lineitem l |
| 35 | on |
| 36 | o.o_orderkey = l.l_orderkey and l.l_commitdate < l.l_receiptdate |
| 37 | and l.l_shipdate < l.l_commitdate and l.l_receiptdate >= '1994-01-01' |
| 38 | and l.l_receiptdate < '1995-01-01' |
| 39 | where |
| 40 | l.l_shipmode = 'MAIL' or l.l_shipmode = 'SHIP' |
| 41 | group by l_shipmode |
| 42 | order by l_shipmode; |