buyingyi | c73348c | 2012-11-02 00:31:31 +0000 | [diff] [blame] | 1 | -- create tables and load data |
| 2 | 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'; |
| 3 | 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'; |
| 4 | 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/100/customer'; |
| 5 | |
| 6 | -- create the target table |
| 7 | create table q3_shipping_priority (l_orderkey int, revenue double, o_orderdate string, o_shippriority int); |
| 8 | |
| 9 | set mapred.min.split.size=536870912; |
| 10 | set hive.exec.reducers.bytes.per.reducer=1024000000; |
| 11 | |
| 12 | -- the query |
| 13 | Insert overwrite table q3_shipping_priority |
| 14 | select |
| 15 | l_orderkey, sum(l_extendedprice*(1-l_discount)) as revenue, o_orderdate, o_shippriority |
| 16 | from |
| 17 | customer c join orders o |
| 18 | on c.c_mktsegment = 'BUILDING' and c.c_custkey = o.o_custkey |
| 19 | join lineitem l |
| 20 | on l.l_orderkey = o.o_orderkey |
| 21 | where |
| 22 | o_orderdate < '1995-03-15' and l_shipdate > '1995-03-15' |
| 23 | group by l_orderkey, o_orderdate, o_shippriority |
| 24 | order by revenue desc, o_orderdate |
| 25 | limit 10; |
| 26 | |
| 27 | DROP TABLE orders; |
| 28 | DROP TABLE lineitem; |
| 29 | DROP TABLE customer; |
| 30 | DROP TABLE q3_shipping_priority; |