buyingyi | c73348c | 2012-11-02 00:31:31 +0000 | [diff] [blame] | 1 | DROP TABLE lineitem; |
| 2 | DROP TABLE orders; |
| 3 | DROP TABLE customer; |
| 4 | DROP TABLE q18_tmp; |
| 5 | DROP TABLE q18_large_volume_customer; |
| 6 | |
| 7 | -- create the tables and load the data |
| 8 | 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'; |
| 9 | 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'; |
| 10 | create 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 |
| 13 | create table q18_tmp(l_orderkey int, t_sum_quantity double); |
| 14 | create table q18_large_volume_customer(c_name string, c_custkey int, o_orderkey int, o_orderdate string, o_totalprice double, sum_quantity double); |
| 15 | |
| 16 | set mapred.min.split.size=268435456; |
| 17 | set hive.exec.reducers.bytes.per.reducer=1164000000; |
| 18 | |
| 19 | -- the query |
| 20 | insert overwrite table q18_tmp |
| 21 | select |
| 22 | l_orderkey, sum(l_quantity) as t_sum_quantity |
| 23 | from |
| 24 | lineitem |
| 25 | group by l_orderkey; |
| 26 | |
| 27 | insert overwrite table q18_large_volume_customer |
| 28 | select |
| 29 | c_name,c_custkey,o_orderkey,o_orderdate,o_totalprice,sum(l_quantity) |
| 30 | from |
| 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 |
| 40 | group by c_name,c_custkey,o_orderkey,o_orderdate,o_totalprice |
| 41 | order by o_totalprice desc,o_orderdate |
| 42 | limit 100; |
| 43 | |