buyingyi | c73348c | 2012-11-02 00:31:31 +0000 | [diff] [blame^] | 1 | -- create the tables and load the data |
| 2 | 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/100/lineitem'; |
| 3 | 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/100/part'; |
| 4 | |
| 5 | -- create the result table |
| 6 | create table q14_promotion_effect(promo_revenue double); |
| 7 | |
| 8 | set mapred.min.split.size=536870912; |
| 9 | set hive.exec.reducers.bytes.per.reducer=1040000000; |
| 10 | |
| 11 | -- the query |
| 12 | insert overwrite table q14_promotion_effect |
| 13 | select |
| 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 |
| 20 | from |
| 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 | |
| 25 | DROP TABLE lineitem; |
| 26 | DROP TABLE part; |
| 27 | DROP TABLE q14_promotion_effect; |