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