blob: b55158145f6b494867443f71a502f0c67fdbc685 [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 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';
4create 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';
5
6-- create the result table
7create table q16_parts_supplier_relationship(p_brand string, p_type string, p_size int, supplier_cnt int);
8create table q16_tmp(p_brand string, p_type string, p_size int, ps_suppkey int);
9create table supplier_tmp(s_suppkey int);
10
11-- the query
12insert overwrite table supplier_tmp
13select
14 s_suppkey
15from
16 supplier
17where
18 not s_comment like '%Customer%Complaints%';
19
20insert overwrite table q16_tmp
21select
22 p_brand, p_type, p_size, ps_suppkey
23from
24 partsupp ps join part p
25 on
26 p.p_partkey = ps.ps_partkey and p.p_brand <> 'Brand#45'
27 and not p.p_type like 'MEDIUM POLISHED%'
28 join supplier_tmp s
29 on
30 ps.ps_suppkey = s.s_suppkey;
31
32insert overwrite table q16_parts_supplier_relationship
33select
34 p_brand, p_type, p_size, count(distinct ps_suppkey) as supplier_cnt
35from
36 (select
37 *
38 from
39 q16_tmp
40 where p_size = 49 or p_size = 14 or p_size = 23 or
41 p_size = 45 or p_size = 19 or p_size = 3 or
42 p_size = 36 or p_size = 9
43) q16_all
44group by p_brand, p_type, p_size
45order by supplier_cnt desc, p_brand, p_type, p_size;
46
47DROP TABLE partsupp;
48DROP TABLE part;
49DROP TABLE supplier;
50DROP TABLE q16_parts_supplier_relationship;
51DROP TABLE q16_tmp;
52DROP TABLE supplier_tmp;