blob: 0ae896c992102c69089f520077ef24d010cc3a68 [file] [log] [blame]
buyingyic73348c2012-11-02 00:31:31 +00001DROP TABLE lineitem;
2DROP TABLE orders;
3DROP TABLE q12_shipping;
4
5-- create the tables and load the data
6create 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';
7create 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';
8
9-- create the result table
10create table q12_shipping(l_shipmode string, high_line_count double, low_line_count double);
11
12set mapred.min.split.size=536870912;
13set hive.exec.reducers.bytes.per.reducer=1225000000;
14
15-- the query
16insert overwrite table q12_shipping
17select
18 l_shipmode,
19 sum(case
20 when o_orderpriority ='1-URGENT'
21 or o_orderpriority ='2-HIGH'
22 then 1
23 else 0
24end
25 ) as high_line_count,
26 sum(case
27 when o_orderpriority <> '1-URGENT'
28 and o_orderpriority <> '2-HIGH'
29 then 1
30 else 0
31end
32 ) as low_line_count
33from
34 orders o join lineitem l
35 on
36 o.o_orderkey = l.l_orderkey and l.l_commitdate < l.l_receiptdate
37and l.l_shipdate < l.l_commitdate and l.l_receiptdate >= '1994-01-01'
38and l.l_receiptdate < '1995-01-01'
39where
40 l.l_shipmode = 'MAIL' or l.l_shipmode = 'SHIP'
41group by l_shipmode
42order by l_shipmode;