buyingyi | c73348c | 2012-11-02 00:31:31 +0000 | [diff] [blame^] | 1 | DROP TABLE part; |
| 2 | DROP TABLE supplier; |
| 3 | DROP TABLE partsupp; |
| 4 | DROP TABLE nation; |
| 5 | DROP TABLE region; |
| 6 | DROP TABLE q2_minimum_cost_supplier; |
| 7 | DROP TABLE q2_minimum_cost_supplier_tmp1; |
| 8 | DROP TABLE q2_minimum_cost_supplier_tmp2; |
| 9 | |
| 10 | -- create the tables and load the data |
| 11 | create 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'; |
| 12 | create 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'; |
| 13 | create 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'; |
| 14 | create 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'; |
| 15 | create 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 |
| 18 | create 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); |
| 19 | create table q2_minimum_cost_supplier_tmp2 (p_partkey int, ps_min_supplycost double); |
| 20 | create 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 |
| 23 | insert overwrite table q2_minimum_cost_supplier_tmp1 |
| 24 | select |
| 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 |
| 26 | from |
| 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 |
| 32 | s.s_nationkey = n.n_nationkey |
| 33 | join partsupp ps |
| 34 | on |
| 35 | s.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 | |