buyingyi | c73348c | 2012-11-02 00:31:31 +0000 | [diff] [blame] | 1 | -- create tables and load data |
| 2 | 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/100/orders'; |
| 3 | 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/100/lineitem'; |
| 4 | |
| 5 | -- create the target table |
| 6 | CREATE TABLE q4_order_priority_tmp (O_ORDERKEY INT); |
| 7 | CREATE TABLE q4_order_priority (O_ORDERPRIORITY STRING, ORDER_COUNT INT); |
| 8 | |
| 9 | set mapred.min.split.size=536870912; |
| 10 | -- the query |
| 11 | INSERT OVERWRITE TABLE q4_order_priority_tmp |
| 12 | select |
| 13 | DISTINCT l_orderkey |
| 14 | from |
| 15 | lineitem |
| 16 | where |
| 17 | l_commitdate < l_receiptdate; |
| 18 | INSERT OVERWRITE TABLE q4_order_priority |
| 19 | select o_orderpriority, count(1) as order_count |
| 20 | from |
| 21 | orders o join q4_order_priority_tmp t |
| 22 | on |
| 23 | o.o_orderkey = t.o_orderkey and o.o_orderdate >= '1993-07-01' and o.o_orderdate < '1993-10-01' |
| 24 | group by o_orderpriority |
| 25 | order by o_orderpriority; |
| 26 | |
| 27 | DROP TABLE orders; |
| 28 | DROP TABLE lineitem; |
| 29 | DROP TABLE q4_order_priority_tmp; |
| 30 | DROP TABLE q4_order_priority; |