buyingyi | c73348c | 2012-11-02 00:31:31 +0000 | [diff] [blame] | 1 | DROP TABLE customer; |
| 2 | DROP TABLE orders; |
| 3 | DROP TABLE lineitem; |
| 4 | DROP TABLE supplier; |
| 5 | DROP TABLE nation; |
| 6 | DROP TABLE region; |
| 7 | DROP TABLE q5_local_supplier_volume; |
| 8 | |
| 9 | -- create tables and load data |
| 10 | create 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'; |
| 11 | Create 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'; |
| 12 | create 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'; |
| 13 | 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'; |
| 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 the target table |
| 18 | create table q5_local_supplier_volume (N_NAME STRING, REVENUE DOUBLE); |
| 19 | |
| 20 | set mapred.min.split.size=536870912; |
| 21 | |
| 22 | -- the query |
| 23 | insert overwrite table q5_local_supplier_volume |
| 24 | select |
| 25 | n_name, sum(l_extendedprice * (1 - l_discount)) as revenue |
| 26 | from |
| 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 |
| 39 | on c.c_nationkey = o1.s_nationkey and c.c_custkey = o1.o_custkey |
| 40 | group by n_name |
| 41 | order by revenue desc; |
| 42 | |