blob: ca6d6b2cb0430a40e5f2303c4b2bd66581c5e79a [file] [log] [blame]
buyingyi55df5212013-03-24 07:20:08 +00001-- create the tables and load the data
2create 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/100/lineitem';
3create 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';
4
5-- create the result table
6create table q14_promotion_effect(promo_revenue double);
7
8set mapred.min.split.size=536870912;
9set hive.exec.reducers.bytes.per.reducer=1040000000;
10
11-- the query
12insert overwrite table q14_promotion_effect
13select
14 100.00 * sum(case
15 when p_type like 'PROMO%'
16 then l_extendedprice*(1-l_discount)
17 else 0.0
18 end
19 ) / sum(l_extendedprice * (1 - l_discount)) as promo_revenue
20from
21 part p join lineitem l
22 on
23 l.l_partkey = p.p_partkey and l.l_shipdate >= '1995-09-01' and l.l_shipdate < '1995-10-01';
24
25DROP TABLE lineitem;
26DROP TABLE part;
27DROP TABLE q14_promotion_effect;