buyingyi | c73348c | 2012-11-02 00:31:31 +0000 | [diff] [blame] | 1 | -- create tables and load 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 | |
| 4 | -- create the target table |
| 5 | CREATE TABLE q1_pricing_summary_report ( L_RETURNFLAG STRING, L_LINESTATUS STRING, SUM_QTY DOUBLE, SUM_BASE_PRICE DOUBLE, SUM_DISC_PRICE DOUBLE, SUM_CHARGE DOUBLE, AVE_QTY DOUBLE, AVE_PRICE DOUBLE, AVE_DISC DOUBLE, COUNT_ORDER INT); |
| 6 | |
| 7 | set mapred.min.split.size=536870912; |
| 8 | |
| 9 | -- the query |
| 10 | INSERT OVERWRITE TABLE q1_pricing_summary_report |
| 11 | SELECT |
| 12 | L_RETURNFLAG, L_LINESTATUS, SUM(L_QUANTITY), SUM(L_EXTENDEDPRICE), SUM(L_EXTENDEDPRICE*(1-L_DISCOUNT)), SUM(L_EXTENDEDPRICE*(1-L_DISCOUNT)*(1+L_TAX)), AVG(L_QUANTITY), AVG(L_EXTENDEDPRICE), AVG(L_DISCOUNT), COUNT(1) |
| 13 | FROM |
| 14 | lineitem |
| 15 | WHERE |
| 16 | L_SHIPDATE<='1998-09-02' |
| 17 | GROUP BY L_RETURNFLAG, L_LINESTATUS |
| 18 | ORDER BY L_RETURNFLAG, L_LINESTATUS; |
| 19 | |
| 20 | DROP TABLE lineitem; |
| 21 | DROP TABLE q1_pricing_summary_report; |