blob: f5b10d81f1650e94d1d6d8d1a27ceba4f53d4625 [file] [log] [blame]
buyingyic73348c2012-11-02 00:31:31 +00001DROP TABLE customer;
2DROP TABLE orders;
3DROP TABLE lineitem;
4DROP TABLE supplier;
5DROP TABLE nation;
6DROP TABLE region;
7DROP TABLE q5_local_supplier_volume;
8
9-- create tables and load data
10create external table customer (C_CUSTKEY INT, C_NAME STRING, C_ADDRESS STRING, C_NATIONKEY INT, C_PHONE STRING, C_ACCTBAL DOUBLE, C_MKTSEGMENT STRING, C_COMMENT STRING) ROW FORMAT DELIMITED FIELDS TERMINATED BY '|' STORED AS TEXTFILE LOCATION '/tpch/10/customer';
11Create external table lineitem (L_ORDERKEY INT, L_PARTKEY INT, L_SUPPKEY INT, L_LINENUMBER INT, L_QUANTITY DOUBLE, L_EXTENDEDPRICE DOUBLE, L_DISCOUNT DOUBLE, L_TAX DOUBLE, L_RETURNFLAG STRING, L_LINESTATUS STRING, L_SHIPDATE STRING, L_COMMITDATE STRING, L_RECEIPTDATE STRING, L_SHIPINSTRUCT STRING, L_SHIPMODE STRING, L_COMMENT STRING) ROW FORMAT DELIMITED FIELDS TERMINATED BY '|' STORED AS TEXTFILE LOCATION '/tpch/10/lineitem';
12create external table orders (O_ORDERKEY INT, O_CUSTKEY INT, O_ORDERSTATUS STRING, O_TOTALPRICE DOUBLE, O_ORDERDATE STRING, O_ORDERPRIORITY STRING, O_CLERK STRING, O_SHIPPRIORITY INT, O_COMMENT STRING) ROW FORMAT DELIMITED FIELDS TERMINATED BY '|' STORED AS TEXTFILE LOCATION '/tpch/10/orders';
13create 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';
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 the target table
18create table q5_local_supplier_volume (N_NAME STRING, REVENUE DOUBLE);
19
20set mapred.min.split.size=536870912;
21
22-- the query
23insert overwrite table q5_local_supplier_volume
24select
25 n_name, sum(l_extendedprice * (1 - l_discount)) as revenue
26from
27 customer c join
28 ( select n_name, l_extendedprice, l_discount, s_nationkey, o_custkey from orders o join
29 ( select n_name, l_extendedprice, l_discount, l_orderkey, s_nationkey from lineitem l join
30 ( select n_name, s_suppkey, s_nationkey from supplier s join
31 ( select n_name, n_nationkey
32 from nation n join region r
33 on n.n_regionkey = r.r_regionkey and r.r_name = 'ASIA'
34 ) n1 on s.s_nationkey = n1.n_nationkey
35 ) s1 on l.l_suppkey = s1.s_suppkey
36 ) l1 on l1.l_orderkey = o.o_orderkey and o.o_orderdate >= '1994-01-01'
37 and o.o_orderdate < '1995-01-01'
38) o1
39on c.c_nationkey = o1.s_nationkey and c.c_custkey = o1.o_custkey
40group by n_name
41order by revenue desc;
42