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