blob: 04081adb8528d1e6e3f1f4a781eca472a906b859 [file] [log] [blame]
buyingyic73348c2012-11-02 00:31:31 +00001DROP TABLE lineitem;
2DROP TABLE orders;
3DROP TABLE customer;
4DROP TABLE q18_tmp;
5DROP TABLE q18_large_volume_customer;
6
7-- create the tables and load the data
8create 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';
9create 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';
10create external table customer (C_CUSTKEY INT, C_NAME STRING, C_ADDRESS STRING, C_NATIONKEY INT, C_PHONE STRING, C_ACCTBAL DOUBLE, C_MKTSEGMENT STRING, C_COMMENT STRING) ROW FORMAT DELIMITED FIELDS TERMINATED BY '|' STORED AS TEXTFILE LOCATION '/tpch/10/customer';
11
12-- create the result tables
13create table q18_tmp(l_orderkey int, t_sum_quantity double);
14create table q18_large_volume_customer(c_name string, c_custkey int, o_orderkey int, o_orderdate string, o_totalprice double, sum_quantity double);
15
16set mapred.min.split.size=268435456;
17set hive.exec.reducers.bytes.per.reducer=1164000000;
18
19-- the query
20insert overwrite table q18_tmp
21select
22 l_orderkey, sum(l_quantity) as t_sum_quantity
23from
24 lineitem
25group by l_orderkey;
26
27insert overwrite table q18_large_volume_customer
28select
29 c_name,c_custkey,o_orderkey,o_orderdate,o_totalprice,sum(l_quantity)
30from
31 customer c join orders o
32 on
33 c.c_custkey = o.o_custkey
34 join q18_tmp t
35 on
36 o.o_orderkey = t.l_orderkey and t.t_sum_quantity > 300
37 join lineitem l
38 on
39 o.o_orderkey = l.l_orderkey
40group by c_name,c_custkey,o_orderkey,o_orderdate,o_totalprice
41order by o_totalprice desc,o_orderdate
42limit 100;
43