blob: afea99822c613bd99099f0c38669b510eae7aa87 [file] [log] [blame]
buyingyic73348c2012-11-02 00:31:31 +00001-- create the tables and load the data
2create 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';
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 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';
5create 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';
6create external table region (R_REGIONKEY INT, R_NAME STRING, R_COMMENT STRING) ROW FORMAT DELIMITED FIELDS TERMINATED BY '|' STORED AS TEXTFILE LOCATION '/tpch/100/region';
7
8-- create result tables
9create table q2_minimum_cost_supplier_tmp1 (s_acctbal double, s_name string, n_name string, p_partkey int, ps_supplycost double, p_mfgr string, s_address string, s_phone string, s_comment string);
10create table q2_minimum_cost_supplier_tmp2 (p_partkey int, ps_min_supplycost double);
11create table q2_minimum_cost_supplier (s_acctbal double, s_name string, n_name string, p_partkey int, p_mfgr string, s_address string, s_phone string, s_comment string);
12
13-- the query
14insert overwrite table q2_minimum_cost_supplier_tmp1
15select
16 s.s_acctbal, s.s_name, n.n_name, p.p_partkey, ps.ps_supplycost, p.p_mfgr, s.s_address, s.s_phone, s.s_comment
17from
18 nation n join region r
19 on
20 n.n_regionkey = r.r_regionkey and r.r_name = 'EUROPE'
21 join supplier s
22 on
23s.s_nationkey = n.n_nationkey
24 join partsupp ps
25 on
26s.s_suppkey = ps.ps_suppkey
27 join part p
28 on
29 p.p_partkey = ps.ps_partkey and p.p_size = 15 and p.p_type like '%BRASS' ;
30
31insert overwrite table q2_minimum_cost_supplier_tmp2
32select
33 p_partkey, min(ps_supplycost)
34from
35 q2_minimum_cost_supplier_tmp1
36group by p_partkey;
37
38insert overwrite table q2_minimum_cost_supplier
39select
40 t1.s_acctbal, t1.s_name, t1.n_name, t1.p_partkey, t1.p_mfgr, t1.s_address, t1.s_phone, t1.s_comment
41from
42 q2_minimum_cost_supplier_tmp1 t1 join q2_minimum_cost_supplier_tmp2 t2
43on
44 t1.p_partkey = t2.p_partkey and t1.ps_supplycost=t2.ps_min_supplycost
45order by s_acctbal desc, n_name, s_name, p_partkey
46limit 100;
47
48DROP TABLE part;
49DROP TABLE supplier;
50DROP TABLE partsupp;
51DROP TABLE nation;
52DROP TABLE region;
53DROP TABLE q2_minimum_cost_supplier;
54DROP TABLE q2_minimum_cost_supplier_tmp1;
55DROP TABLE q2_minimum_cost_supplier_tmp2;