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