blob: 40ae42395a76a3f851f36c0a4db5710e750fa562 [file] [log] [blame]
buyingyic73348c2012-11-02 00:31:31 +00001DROP TABLE partsupp;
2DROP TABLE lineitem;
3DROP TABLE supplier;
4DROP TABLE nation;
5DROP TABLE q20_tmp1;
6DROP TABLE q20_tmp2;
7DROP TABLE q20_tmp3;
8DROP TABLE q20_tmp4;
9DROP TABLE q20_potential_part_promotion;
10
11-- create tables and load data
12create 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';
13create 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/10/supplier';
14create 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/10/nation';
15create 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/10/partsupp';
16
17-- create the target table
18create table q20_tmp1(p_partkey int);
19create table q20_tmp2(l_partkey int, l_suppkey int, sum_quantity double);
20create table q20_tmp3(ps_suppkey int, ps_availqty int, sum_quantity double);
21create table q20_tmp4(ps_suppkey int);
22create table q20_potential_part_promotion(s_name string, s_address string);
23
24set mapred.min.split.size=536870912;
25
26-- the query
27insert overwrite table q20_tmp1
28select distinct p_partkey
29from
30 part
31where
32 p_name like 'forest%';
33
34insert overwrite table q20_tmp2
35select
36 l_partkey, l_suppkey, 0.5 * sum(l_quantity)
37from
38 lineitem
39where
40 l_shipdate >= '1994-01-01'
41 and l_shipdate < '1995-01-01'
42group by l_partkey, l_suppkey;
43
44insert overwrite table q20_tmp3
45select
46 ps_suppkey, ps_availqty, sum_quantity
47from
48 partsupp ps join q20_tmp1 t1
49 on
50 ps.ps_partkey = t1.p_partkey
51 join q20_tmp2 t2
52 on
53 ps.ps_partkey = t2.l_partkey and ps.ps_suppkey = t2.l_suppkey;
54
55insert overwrite table q20_tmp4
56select
57 ps_suppkey
58from
59 q20_tmp3
60where
61 ps_availqty > sum_quantity
62group by ps_suppkey;
63
64insert overwrite table q20_potential_part_promotion
65select
66 s_name, s_address
67from
68 supplier s join nation n
69 on
70 s.s_nationkey = n.n_nationkey
71 and n.n_name = 'CANADA'
72 join q20_tmp4 t4
73 on
74 s.s_suppkey = t4.ps_suppkey
75order by s_name;
76
77