blob: d2547937289eacd178c164c2a66e6f9a741f5351 [file] [log] [blame]
buyingyic73348c2012-11-02 00:31:31 +00001-- create tables and load data
2create 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';
3create external table supplier (S_SUPPKEY INT, S_NAME STRING, S_ADDRESS STRING, S_NATIONKEY INT, S_PHONE STRING, S_ACCTBAL DOUBLE, S_COMMENT STRING) ROW FORMAT DELIMITED FIELDS TERMINATED BY '|' STORED AS TEXTFILE LOCATION '/tpch/100/supplier';
4create external table nation (N_NATIONKEY INT, N_NAME STRING, N_REGIONKEY INT, N_COMMENT STRING) ROW FORMAT DELIMITED FIELDS TERMINATED BY '|' STORED AS TEXTFILE LOCATION '/tpch/100/nation';
5create external table partsupp (PS_PARTKEY INT, PS_SUPPKEY INT, PS_AVAILQTY INT, PS_SUPPLYCOST DOUBLE, PS_COMMENT STRING) ROW FORMAT DELIMITED FIELDS TERMINATED BY '|' STORED AS TEXTFILE LOCATION'/tpch/100/partsupp';
6create external table part (P_PARTKEY INT, P_NAME STRING, P_MFGR STRING, P_BRAND STRING, P_TYPE STRING, P_SIZE INT, P_CONTAINER STRING, P_RETAILPRICE DOUBLE, P_COMMENT STRING) ROW FORMAT DELIMITED FIELDS TERMINATED BY '|' STORED AS TEXTFILE LOCATION '/tpch/100/part';
7
8-- create the target table
9create table q20_tmp1(p_partkey int);
10create table q20_tmp2(l_partkey int, l_suppkey int, sum_quantity double);
11create table q20_tmp3(ps_suppkey int, ps_availqty int, sum_quantity double);
12create table q20_tmp4(ps_suppkey int);
13create table q20_potential_part_promotion(s_name string, s_address string);
14
15set mapred.min.split.size=536870912;
16
17-- the query
18insert overwrite table q20_tmp1
19select distinct p_partkey
20from
21 part
22where
23 p_name like 'forest%';
24
25insert overwrite table q20_tmp2
26select
27 l_partkey, l_suppkey, 0.5 * sum(l_quantity)
28from
29 lineitem
30where
31 l_shipdate >= '1994-01-01'
32 and l_shipdate < '1995-01-01'
33group by l_partkey, l_suppkey;
34
35insert overwrite table q20_tmp3
36select
37 ps_suppkey, ps_availqty, sum_quantity
38from
39 partsupp ps join q20_tmp1 t1
40 on
41 ps.ps_partkey = t1.p_partkey
42 join q20_tmp2 t2
43 on
44 ps.ps_partkey = t2.l_partkey and ps.ps_suppkey = t2.l_suppkey;
45
46insert overwrite table q20_tmp4
47select
48 ps_suppkey
49from
50 q20_tmp3
51where
52 ps_availqty > sum_quantity
53group by ps_suppkey;
54
55insert overwrite table q20_potential_part_promotion
56select
57 s_name, s_address
58from
59 supplier s join nation n
60 on
61 s.s_nationkey = n.n_nationkey
62 and n.n_name = 'CANADA'
63 join q20_tmp4 t4
64 on
65 s.s_suppkey = t4.ps_suppkey
66order by s_name;
67
68DROP TABLE partsupp;
69DROP TABLE lineitem;
70DROP TABLE supplier;
71DROP TABLE nation;
72DROP TABLE q20_tmp1;
73DROP TABLE q20_tmp2;
74DROP TABLE q20_tmp3;
75DROP TABLE q20_tmp4;
76DROP TABLE q20_potential_part_promotion;