blob: 647d5006b1fb4845923316d80ef5269415e967fa [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 ;
39
40-- explain insert overwrite table q2_minimum_cost_supplier_tmp2
41-- select
42-- p_partkey, min(ps_supplycost)
43-- from
44-- q2_minimum_cost_supplier_tmp1
45-- group by p_partkey
46