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 q19_discounted_revenue(revenue double); |
| 7 | |
| 8 | set mapred.min.split.size=268435456; |
| 9 | set hive.exec.reducers.bytes.per.reducer=1040000000; |
| 10 | |
| 11 | -- the query |
| 12 | insert overwrite table q19_discounted_revenue |
| 13 | select |
| 14 | sum(l_extendedprice * (1 - l_discount) ) as revenue |
| 15 | from |
| 16 | lineitem l join part p |
| 17 | on |
| 18 | p.p_partkey = l.l_partkey |
| 19 | where |
| 20 | ( |
| 21 | p_brand = 'Brand#12' |
| 22 | and p_container REGEXP 'SM CASE||SM BOX||SM PACK||SM PKG' |
| 23 | and l_quantity >= 1 and l_quantity <= 11 |
| 24 | and p_size >= 1 and p_size <= 5 |
| 25 | and l_shipmode REGEXP 'AIR||AIR REG' |
| 26 | and l_shipinstruct = 'DELIVER IN PERSON' |
| 27 | ) |
| 28 | or |
| 29 | ( |
| 30 | p_brand = 'Brand#23' |
| 31 | and p_container REGEXP 'MED BAG||MED BOX||MED PKG||MED PACK' |
| 32 | and l_quantity >= 10 and l_quantity <= 20 |
| 33 | and p_size >= 1 and p_size <= 10 |
| 34 | and l_shipmode REGEXP 'AIR||AIR REG' |
| 35 | and l_shipinstruct = 'DELIVER IN PERSON' |
| 36 | ) |
| 37 | or |
| 38 | ( |
| 39 | p_brand = 'Brand#34' |
| 40 | and p_container REGEXP 'LG CASE||LG BOX||LG PACK||LG PKG' |
| 41 | and l_quantity >= 20 and l_quantity <= 30 |
| 42 | and p_size >= 1 and p_size <= 15 |
| 43 | and l_shipmode REGEXP 'AIR||AIR REG' |
| 44 | and l_shipinstruct = 'DELIVER IN PERSON' |
| 45 | ); |
| 46 | |
| 47 | DROP TABLE lineitem; |
| 48 | DROP TABLE part; |
| 49 | DROP TABLE q19_discounted_revenue; |