From fb331e7127664cb630265ae9e06499054bc8faba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=AB=98=E9=93=81?= Date: Wed, 27 Jan 2021 13:29:52 +0800 Subject: [PATCH] add testcase --- src/main/resources/tpcds/create_tables.sql | 690 ++++++++++++++++++ src/main/resources/tpcds/query01.sql | 19 + src/main/resources/tpcds/query02.sql | 66 ++ src/main/resources/tpcds/query03.sql | 9 + src/main/resources/tpcds/query04.sql | 113 +++ src/main/resources/tpcds/query05.sql | 72 ++ src/main/resources/tpcds/query06.sql | 23 + src/main/resources/tpcds/query07.sql | 18 + src/main/resources/tpcds/query08.sql | 105 +++ src/main/resources/tpcds/query09.sql | 48 ++ src/main/resources/tpcds/query10.sql | 56 ++ src/main/resources/tpcds/query11.sql | 78 ++ src/main/resources/tpcds/query12.sql | 31 + src/main/resources/tpcds/query13.sql | 49 ++ src/main/resources/tpcds/query14.sql | 195 +++++ src/main/resources/tpcds/query15.sql | 17 + src/main/resources/tpcds/query16.sql | 28 + src/main/resources/tpcds/query17.sql | 42 ++ src/main/resources/tpcds/query18.sql | 31 + src/main/resources/tpcds/query19.sql | 22 + src/main/resources/tpcds/query20.sql | 27 + src/main/resources/tpcds/query21.sql | 27 + src/main/resources/tpcds/query22.sql | 17 + src/main/resources/tpcds/query23.sql | 104 +++ src/main/resources/tpcds/query24.sql | 104 +++ src/main/resources/tpcds/query25.sql | 45 ++ src/main/resources/tpcds/query26.sql | 18 + src/main/resources/tpcds/query27.sql | 20 + src/main/resources/tpcds/query28.sql | 50 ++ src/main/resources/tpcds/query29.sql | 44 ++ src/main/resources/tpcds/query30.sql | 28 + src/main/resources/tpcds/query31.sql | 49 ++ src/main/resources/tpcds/query32.sql | 25 + src/main/resources/tpcds/query33.sql | 72 ++ src/main/resources/tpcds/query34.sql | 28 + src/main/resources/tpcds/query35.sql | 55 ++ src/main/resources/tpcds/query36.sql | 27 + src/main/resources/tpcds/query37.sql | 14 + src/main/resources/tpcds/query38.sql | 20 + src/main/resources/tpcds/query39.sql | 50 ++ src/main/resources/tpcds/query40.sql | 25 + src/main/resources/tpcds/query41.sql | 49 ++ src/main/resources/tpcds/query42.sql | 19 + src/main/resources/tpcds/query43.sql | 16 + src/main/resources/tpcds/query44.sql | 32 + src/main/resources/tpcds/query45.sql | 17 + src/main/resources/tpcds/query46.sql | 32 + src/main/resources/tpcds/query47.sql | 48 ++ src/main/resources/tpcds/query48.sql | 64 ++ src/main/resources/tpcds/query49.sql | 124 ++++ src/main/resources/tpcds/query50.sql | 56 ++ src/main/resources/tpcds/query51.sql | 42 ++ src/main/resources/tpcds/query52.sql | 19 + src/main/resources/tpcds/query53.sql | 25 + src/main/resources/tpcds/query54.sql | 53 ++ src/main/resources/tpcds/query55.sql | 11 + src/main/resources/tpcds/query56.sql | 65 ++ src/main/resources/tpcds/query57.sql | 45 ++ src/main/resources/tpcds/query58.sql | 62 ++ src/main/resources/tpcds/query59.sql | 41 ++ src/main/resources/tpcds/query60.sql | 75 ++ src/main/resources/tpcds/query61.sql | 41 ++ src/main/resources/tpcds/query62.sql | 32 + src/main/resources/tpcds/query63.sql | 26 + src/main/resources/tpcds/query64.sql | 116 +++ src/main/resources/tpcds/query65.sql | 26 + src/main/resources/tpcds/query66.sql | 217 ++++++ src/main/resources/tpcds/query67.sql | 41 ++ src/main/resources/tpcds/query68.sql | 39 + src/main/resources/tpcds/query69.sql | 44 ++ src/main/resources/tpcds/query70.sql | 35 + src/main/resources/tpcds/query71.sql | 37 + src/main/resources/tpcds/query72.sql | 26 + src/main/resources/tpcds/query73.sql | 25 + src/main/resources/tpcds/query74.sql | 58 ++ src/main/resources/tpcds/query75.sql | 67 ++ src/main/resources/tpcds/query76.sql | 21 + src/main/resources/tpcds/query77.sql | 105 +++ src/main/resources/tpcds/query78.sql | 55 ++ src/main/resources/tpcds/query79.sql | 20 + src/main/resources/tpcds/query80.sql | 93 +++ src/main/resources/tpcds/query81.sql | 28 + src/main/resources/tpcds/query82.sql | 14 + src/main/resources/tpcds/query83.sql | 64 ++ src/main/resources/tpcds/query84.sql | 18 + src/main/resources/tpcds/query85.sql | 81 ++ src/main/resources/tpcds/query86.sql | 23 + src/main/resources/tpcds/query87.sql | 20 + src/main/resources/tpcds/query88.sql | 90 +++ src/main/resources/tpcds/query89.sql | 25 + src/main/resources/tpcds/query90.sql | 19 + src/main/resources/tpcds/query91.sql | 28 + src/main/resources/tpcds/query92.sql | 27 + src/main/resources/tpcds/query93.sql | 15 + src/main/resources/tpcds/query94.sql | 26 + src/main/resources/tpcds/query95.sql | 29 + src/main/resources/tpcds/query96.sql | 13 + src/main/resources/tpcds/query97.sql | 22 + src/main/resources/tpcds/query98.sql | 30 + src/main/resources/tpcds/query99.sql | 32 + src/main/resources/tpch/create_tables.sql | 92 +++ .../resources/tpch/insert_lineitem_200.sql | 1 + src/main/resources/tpch/q1.sql | 22 + src/main/resources/tpch/q10.sql | 33 + src/main/resources/tpch/q11.sql | 27 + src/main/resources/tpch/q12.sql | 29 + src/main/resources/tpch/q13.sql | 21 + src/main/resources/tpch/q14.sql | 13 + src/main/resources/tpch/q15.sql | 15 + src/main/resources/tpch/q16.sql | 30 + src/main/resources/tpch/q17.sql | 16 + src/main/resources/tpch/q18.sql | 34 + src/main/resources/tpch/q19.sql | 35 + src/main/resources/tpch/q2.sql | 42 ++ src/main/resources/tpch/q20.sql | 33 + src/main/resources/tpch/q21.sql | 39 + src/main/resources/tpch/q22.sql | 35 + src/main/resources/tpch/q3.sql | 24 + src/main/resources/tpch/q4.sql | 19 + src/main/resources/tpch/q5.sql | 25 + src/main/resources/tpch/q6.sql | 9 + src/main/resources/tpch/q7.sql | 39 + src/main/resources/tpch/q8.sql | 38 + src/main/resources/tpch/q9.sql | 32 + .../com/alibaba/druid/benckmark/TPCDS.java | 36 + .../com/alibaba/druid/benckmark/TPCH.java | 46 ++ .../bvt/sql/mysql/resolve/ResolveTest_0.java | 143 ++++ .../bvt/sql/mysql/resolve/ResolveTest_1.java | 109 +++ .../mysql/resolve/Resolve_AllColumn_Test.java | 88 +++ .../resolve/Resolve_AllColumn_Test_1.java | 25 + .../sql/mysql/resolve/TPCDS_ALL_Resolve.java | 57 ++ 131 files changed, 6391 insertions(+) create mode 100644 src/main/resources/tpcds/create_tables.sql create mode 100644 src/main/resources/tpcds/query01.sql create mode 100644 src/main/resources/tpcds/query02.sql create mode 100644 src/main/resources/tpcds/query03.sql create mode 100644 src/main/resources/tpcds/query04.sql create mode 100644 src/main/resources/tpcds/query05.sql create mode 100644 src/main/resources/tpcds/query06.sql create mode 100644 src/main/resources/tpcds/query07.sql create mode 100644 src/main/resources/tpcds/query08.sql create mode 100644 src/main/resources/tpcds/query09.sql create mode 100644 src/main/resources/tpcds/query10.sql create mode 100644 src/main/resources/tpcds/query11.sql create mode 100644 src/main/resources/tpcds/query12.sql create mode 100644 src/main/resources/tpcds/query13.sql create mode 100644 src/main/resources/tpcds/query14.sql create mode 100644 src/main/resources/tpcds/query15.sql create mode 100644 src/main/resources/tpcds/query16.sql create mode 100644 src/main/resources/tpcds/query17.sql create mode 100644 src/main/resources/tpcds/query18.sql create mode 100644 src/main/resources/tpcds/query19.sql create mode 100644 src/main/resources/tpcds/query20.sql create mode 100644 src/main/resources/tpcds/query21.sql create mode 100644 src/main/resources/tpcds/query22.sql create mode 100644 src/main/resources/tpcds/query23.sql create mode 100644 src/main/resources/tpcds/query24.sql create mode 100644 src/main/resources/tpcds/query25.sql create mode 100644 src/main/resources/tpcds/query26.sql create mode 100644 src/main/resources/tpcds/query27.sql create mode 100644 src/main/resources/tpcds/query28.sql create mode 100644 src/main/resources/tpcds/query29.sql create mode 100644 src/main/resources/tpcds/query30.sql create mode 100644 src/main/resources/tpcds/query31.sql create mode 100644 src/main/resources/tpcds/query32.sql create mode 100644 src/main/resources/tpcds/query33.sql create mode 100644 src/main/resources/tpcds/query34.sql create mode 100644 src/main/resources/tpcds/query35.sql create mode 100644 src/main/resources/tpcds/query36.sql create mode 100644 src/main/resources/tpcds/query37.sql create mode 100644 src/main/resources/tpcds/query38.sql create mode 100644 src/main/resources/tpcds/query39.sql create mode 100644 src/main/resources/tpcds/query40.sql create mode 100644 src/main/resources/tpcds/query41.sql create mode 100644 src/main/resources/tpcds/query42.sql create mode 100644 src/main/resources/tpcds/query43.sql create mode 100644 src/main/resources/tpcds/query44.sql create mode 100644 src/main/resources/tpcds/query45.sql create mode 100644 src/main/resources/tpcds/query46.sql create mode 100644 src/main/resources/tpcds/query47.sql create mode 100644 src/main/resources/tpcds/query48.sql create mode 100644 src/main/resources/tpcds/query49.sql create mode 100644 src/main/resources/tpcds/query50.sql create mode 100644 src/main/resources/tpcds/query51.sql create mode 100644 src/main/resources/tpcds/query52.sql create mode 100644 src/main/resources/tpcds/query53.sql create mode 100644 src/main/resources/tpcds/query54.sql create mode 100644 src/main/resources/tpcds/query55.sql create mode 100644 src/main/resources/tpcds/query56.sql create mode 100644 src/main/resources/tpcds/query57.sql create mode 100644 src/main/resources/tpcds/query58.sql create mode 100644 src/main/resources/tpcds/query59.sql create mode 100644 src/main/resources/tpcds/query60.sql create mode 100644 src/main/resources/tpcds/query61.sql create mode 100644 src/main/resources/tpcds/query62.sql create mode 100644 src/main/resources/tpcds/query63.sql create mode 100644 src/main/resources/tpcds/query64.sql create mode 100644 src/main/resources/tpcds/query65.sql create mode 100644 src/main/resources/tpcds/query66.sql create mode 100644 src/main/resources/tpcds/query67.sql create mode 100644 src/main/resources/tpcds/query68.sql create mode 100644 src/main/resources/tpcds/query69.sql create mode 100644 src/main/resources/tpcds/query70.sql create mode 100644 src/main/resources/tpcds/query71.sql create mode 100644 src/main/resources/tpcds/query72.sql create mode 100644 src/main/resources/tpcds/query73.sql create mode 100644 src/main/resources/tpcds/query74.sql create mode 100644 src/main/resources/tpcds/query75.sql create mode 100644 src/main/resources/tpcds/query76.sql create mode 100644 src/main/resources/tpcds/query77.sql create mode 100644 src/main/resources/tpcds/query78.sql create mode 100644 src/main/resources/tpcds/query79.sql create mode 100644 src/main/resources/tpcds/query80.sql create mode 100644 src/main/resources/tpcds/query81.sql create mode 100644 src/main/resources/tpcds/query82.sql create mode 100644 src/main/resources/tpcds/query83.sql create mode 100644 src/main/resources/tpcds/query84.sql create mode 100644 src/main/resources/tpcds/query85.sql create mode 100644 src/main/resources/tpcds/query86.sql create mode 100644 src/main/resources/tpcds/query87.sql create mode 100644 src/main/resources/tpcds/query88.sql create mode 100644 src/main/resources/tpcds/query89.sql create mode 100644 src/main/resources/tpcds/query90.sql create mode 100644 src/main/resources/tpcds/query91.sql create mode 100644 src/main/resources/tpcds/query92.sql create mode 100644 src/main/resources/tpcds/query93.sql create mode 100644 src/main/resources/tpcds/query94.sql create mode 100644 src/main/resources/tpcds/query95.sql create mode 100644 src/main/resources/tpcds/query96.sql create mode 100644 src/main/resources/tpcds/query97.sql create mode 100644 src/main/resources/tpcds/query98.sql create mode 100644 src/main/resources/tpcds/query99.sql create mode 100644 src/main/resources/tpch/create_tables.sql create mode 100644 src/main/resources/tpch/insert_lineitem_200.sql create mode 100644 src/main/resources/tpch/q1.sql create mode 100644 src/main/resources/tpch/q10.sql create mode 100644 src/main/resources/tpch/q11.sql create mode 100644 src/main/resources/tpch/q12.sql create mode 100644 src/main/resources/tpch/q13.sql create mode 100644 src/main/resources/tpch/q14.sql create mode 100644 src/main/resources/tpch/q15.sql create mode 100644 src/main/resources/tpch/q16.sql create mode 100644 src/main/resources/tpch/q17.sql create mode 100644 src/main/resources/tpch/q18.sql create mode 100644 src/main/resources/tpch/q19.sql create mode 100644 src/main/resources/tpch/q2.sql create mode 100644 src/main/resources/tpch/q20.sql create mode 100644 src/main/resources/tpch/q21.sql create mode 100644 src/main/resources/tpch/q22.sql create mode 100644 src/main/resources/tpch/q3.sql create mode 100644 src/main/resources/tpch/q4.sql create mode 100644 src/main/resources/tpch/q5.sql create mode 100644 src/main/resources/tpch/q6.sql create mode 100644 src/main/resources/tpch/q7.sql create mode 100644 src/main/resources/tpch/q8.sql create mode 100644 src/main/resources/tpch/q9.sql create mode 100644 src/test/java/com/alibaba/druid/benckmark/TPCDS.java create mode 100644 src/test/java/com/alibaba/druid/benckmark/TPCH.java create mode 100644 src/test/java/com/alibaba/druid/bvt/sql/mysql/resolve/ResolveTest_0.java create mode 100644 src/test/java/com/alibaba/druid/bvt/sql/mysql/resolve/ResolveTest_1.java create mode 100644 src/test/java/com/alibaba/druid/bvt/sql/mysql/resolve/Resolve_AllColumn_Test.java create mode 100644 src/test/java/com/alibaba/druid/bvt/sql/mysql/resolve/Resolve_AllColumn_Test_1.java create mode 100644 src/test/java/com/alibaba/druid/bvt/sql/mysql/resolve/TPCDS_ALL_Resolve.java diff --git a/src/main/resources/tpcds/create_tables.sql b/src/main/resources/tpcds/create_tables.sql new file mode 100644 index 0000000000..6e765f5a43 --- /dev/null +++ b/src/main/resources/tpcds/create_tables.sql @@ -0,0 +1,690 @@ +drop table if exists call_center_text; +create table call_center_text +( + cc_call_center_sk int, + cc_call_center_id string, + cc_rec_start_date string, + cc_rec_end_date string, + cc_closed_date_sk int, + cc_open_date_sk int, + cc_name string, + cc_class string, + cc_employees int, + cc_sq_ft int, + cc_hours string, + cc_manager string, + cc_mkt_id int, + cc_mkt_class string, + cc_mkt_desc string, + cc_market_manager string, + cc_division int, + cc_division_name string, + cc_company int, + cc_company_name string, + cc_street_number string, + cc_street_name string, + cc_street_type string, + cc_suite_number string, + cc_city string, + cc_county string, + cc_state string, + cc_zip string, + cc_country string, + cc_gmt_offset double, + cc_tax_percentage double +) +; +drop table if exists call_center; +create table call_center +as (select * from call_center_text) +; +drop table if exists call_center_text; + +drop table if exists catalog_page_text; +create table catalog_page_text +( + cp_catalog_page_sk int, + cp_catalog_page_id string, + cp_start_date_sk int, + cp_end_date_sk int, + cp_department string, + cp_catalog_number int, + cp_catalog_page_number int, + cp_description string, + cp_type string +) +; +drop table if exists catalog_page; +create table catalog_page +as (select * from catalog_page_text) +; +drop table if exists catalog_page_text; + +drop table if exists catalog_returns_text; +create table catalog_returns_text +( + cr_returned_date_sk int, + cr_returned_time_sk int, + cr_item_sk int, + cr_refunded_customer_sk int, + cr_refunded_cdemo_sk int, + cr_refunded_hdemo_sk int, + cr_refunded_addr_sk int, + cr_returning_customer_sk int, + cr_returning_cdemo_sk int, + cr_returning_hdemo_sk int, + cr_returning_addr_sk int, + cr_call_center_sk int, + cr_catalog_page_sk int, + cr_ship_mode_sk int, + cr_warehouse_sk int, + cr_reason_sk int, + cr_order_number int, + cr_return_quantity int, + cr_return_amount double, + cr_return_tax double, + cr_return_amt_inc_tax double, + cr_fee double, + cr_return_ship_cost double, + cr_refunded_cash double, + cr_reversed_charge double, + cr_store_credit double, + cr_net_loss double +) +; +drop table if exists catalog_returns; +create table catalog_returns +as (select * from catalog_returns_text) +; +drop table if exists catalog_returns_text; + + +drop table if exists catalog_sales_text; +create table catalog_sales_text +( + cs_sold_date_sk int, + cs_sold_time_sk int, + cs_ship_date_sk int, + cs_bill_customer_sk int, + cs_bill_cdemo_sk int, + cs_bill_hdemo_sk int, + cs_bill_addr_sk int, + cs_ship_customer_sk int, + cs_ship_cdemo_sk int, + cs_ship_hdemo_sk int, + cs_ship_addr_sk int, + cs_call_center_sk int, + cs_catalog_page_sk int, + cs_ship_mode_sk int, + cs_warehouse_sk int, + cs_item_sk int, + cs_promo_sk int, + cs_order_number int, + cs_quantity int, + cs_wholesale_cost double, + cs_list_price double, + cs_sales_price double, + cs_ext_discount_amt double, + cs_ext_sales_price double, + cs_ext_wholesale_cost double, + cs_ext_list_price double, + cs_ext_tax double, + cs_coupon_amt double, + cs_ext_ship_cost double, + cs_net_paid double, + cs_net_paid_inc_tax double, + cs_net_paid_inc_ship double, + cs_net_paid_inc_ship_tax double, + cs_net_profit double +) +; +drop table if exists catalog_sales; +create table catalog_sales +as (select * from catalog_sales_text) +; +drop table if exists catalog_sales_text; + +drop table if exists customer_text; +create table customer_text +( + c_customer_sk int, + c_customer_id string, + c_current_cdemo_sk int, + c_current_hdemo_sk int, + c_current_addr_sk int, + c_first_shipto_date_sk int, + c_first_sales_date_sk int, + c_salutation string, + c_first_name string, + c_last_name string, + c_preferred_cust_flag string, + c_birth_day int, + c_birth_month int, + c_birth_year int, + c_birth_country string, + c_login string, + c_email_address string, + c_last_review_date string +) +; +drop table if exists customer; +create table customer +as (select * from customer_text) +; +drop table if exists customer_text; + + +drop table if exists customer_address_text; +create table customer_address_text +( + ca_address_sk int, + ca_address_id string, + ca_street_number string, + ca_street_name string, + ca_street_type string, + ca_suite_number string, + ca_city string, + ca_county string, + ca_state string, + ca_zip string, + ca_country string, + ca_gmt_offset double, + ca_location_type string +) +; +drop table if exists customer_address; +create table customer_address +as (select * from customer_address_text) +; +drop table if exists customer_address_text; + +drop table if exists customer_demographics_text; +create table customer_demographics_text +( + cd_demo_sk int, + cd_gender string, + cd_marital_status string, + cd_education_status string, + cd_purchase_estimate int, + cd_credit_rating string, + cd_dep_count int, + cd_dep_employed_count int, + cd_dep_college_count int +) +; +drop table if exists customer_demographics; +create table customer_demographics +as (select * from customer_demographics_text) +; +drop table if exists customer_demographics_text; + +drop table if exists date_dim_text; +create table date_dim_text +( + d_date_sk int, + d_date_id string, + d_date string, + d_month_seq int, + d_week_seq int, + d_quarter_seq int, + d_year int, + d_dow int, + d_moy int, + d_dom int, + d_qoy int, + d_fy_year int, + d_fy_quarter_seq int, + d_fy_week_seq int, + d_day_name string, + d_quarter_name string, + d_holiday string, + d_weekend string, + d_following_holiday string, + d_first_dom int, + d_last_dom int, + d_same_day_ly int, + d_same_day_lq int, + d_current_day string, + d_current_week string, + d_current_month string, + d_current_quarter string, + d_current_year string +) +; +drop table if exists date_dim; +create table date_dim +as (select * from date_dim_text) +; +drop table if exists date_dim_text; + +drop table if exists household_demographics_text; +create table household_demographics_text +( + hd_demo_sk int, + hd_income_band_sk int, + hd_buy_potential string, + hd_dep_count int, + hd_vehicle_count int +) +; +drop table if exists household_demographics; +create table household_demographics +as (select * from household_demographics_text) +; +drop table if exists household_demographics_text; + +drop table if exists income_band_text; +create table income_band_text +( + ib_income_band_sk int, + ib_lower_bound int, + ib_upper_bound int +) +; +drop table if exists income_band; +create table income_band +as (select * from income_band_text) +; +drop table if exists income_band_text; + +drop table if exists inventory_text; +create table inventory_text +( + inv_date_sk int, + inv_item_sk int, + inv_warehouse_sk int, + inv_quantity_on_hand bigint +) +; +drop table if exists inventory; +create table inventory +as (select * from inventory_text) +; +drop table if exists inventory_text; + +drop table if exists item_text; +create table item_text +( + i_item_sk int, + i_item_id string, + i_rec_start_date string, + i_rec_end_date string, + i_item_desc string, + i_current_price double, + i_wholesale_cost double, + i_brand_id int, + i_brand string, + i_class_id int, + i_class string, + i_category_id int, + i_category string, + i_manufact_id int, + i_manufact string, + i_size string, + i_formulation string, + i_color string, + i_units string, + i_container string, + i_manager_id int, + i_product_name string +) +; +drop table if exists item; +create table item +as (select * from item_text) +; +drop table if exists item_text; + +drop table if exists promotion_text; +create table promotion_text +( + p_promo_sk int, + p_promo_id string, + p_start_date_sk int, + p_end_date_sk int, + p_item_sk int, + p_cost double, + p_response_target int, + p_promo_name string, + p_channel_dmail string, + p_channel_email string, + p_channel_catalog string, + p_channel_tv string, + p_channel_radio string, + p_channel_press string, + p_channel_event string, + p_channel_demo string, + p_channel_details string, + p_purpose string, + p_discount_active string +) +; +drop table if exists promotion; +create table promotion +as (select * from promotion_text) +; +drop table if exists promotion_text; + +drop table if exists reason_text; +create table reason_text +( + r_reason_sk int, + r_reason_id string, + r_reason_desc string +) +; +drop table if exists reason; +create table reason +as (select * from reason_text) +; +drop table if exists reason_text; + +drop table if exists ship_mode_text; +create table ship_mode_text +( + sm_ship_mode_sk int, + sm_ship_mode_id string, + sm_type string, + sm_code string, + sm_carrier string, + sm_contract string +) +; +drop table if exists ship_mode; +create table ship_mode +as (select * from ship_mode_text) +; +drop table if exists ship_mode_text; + +drop table if exists store_text; +create table store_text +( + s_store_sk int, + s_store_id string, + s_rec_start_date string, + s_rec_end_date string, + s_closed_date_sk int, + s_store_name string, + s_number_employees int, + s_floor_space int, + s_hours string, + s_manager string, + s_market_id int, + s_geography_class string, + s_market_desc string, + s_market_manager string, + s_division_id int, + s_division_name string, + s_company_id int, + s_company_name string, + s_street_number string, + s_street_name string, + s_street_type string, + s_suite_number string, + s_city string, + s_county string, + s_state string, + s_zip string, + s_country string, + s_gmt_offset double, + s_tax_precentage double +) +; +drop table if exists store; +create table store +as (select * from store_text) +; +drop table if exists store_text; + +drop table if exists store_returns_text; +create table store_returns_text +( + sr_returned_date_sk int, + sr_return_time_sk int, + sr_item_sk int, + sr_customer_sk int, + sr_cdemo_sk int, + sr_hdemo_sk int, + sr_addr_sk int, + sr_store_sk int, + sr_reason_sk int, + sr_ticket_number int, + sr_return_quantity int, + sr_return_amt double, + sr_return_tax double, + sr_return_amt_inc_tax double, + sr_fee double, + sr_return_ship_cost double, + sr_refunded_cash double, + sr_reversed_charge double, + sr_store_credit double, + sr_net_loss double +) +; +drop table if exists store_returns; +create table store_returns +as (select * from store_returns_text) +; +drop table if exists store_returns_text; + +drop table if exists store_sales_text; +create table store_sales_text +( + ss_sold_date_sk int, + ss_sold_time_sk int, + ss_item_sk int, + ss_customer_sk int, + ss_cdemo_sk int, + ss_hdemo_sk int, + ss_addr_sk int, + ss_store_sk int, + ss_promo_sk int, + ss_ticket_number int, + ss_quantity int, + ss_wholesale_cost double, + ss_list_price double, + ss_sales_price double, + ss_ext_discount_amt double, + ss_ext_sales_price double, + ss_ext_wholesale_cost double, + ss_ext_list_price double, + ss_ext_tax double, + ss_coupon_amt double, + ss_net_paid double, + ss_net_paid_inc_tax double, + ss_net_profit double +) +; +drop table if exists store_sales; +create table store_sales +as (select * from store_sales_text) +; +drop table if exists store_sales_text; + +drop table if exists time_dim_text; +create table time_dim_text +( + t_time_sk int, + t_time_id string, + t_time int, + t_hour int, + t_minute int, + t_second int, + t_am_pm string, + t_shift string, + t_sub_shift string, + t_meal_time string +) +; +drop table if exists time_dim; +create table time_dim +as (select * from time_dim_text) +; +drop table if exists time_dim_text; + +drop table if exists warehouse_text; +create table warehouse_text +( + w_warehouse_sk int, + w_warehouse_id string, + w_warehouse_name string, + w_warehouse_sq_ft int, + w_street_number string, + w_street_name string, + w_street_type string, + w_suite_number string, + w_city string, + w_county string, + w_state string, + w_zip string, + w_country string, + w_gmt_offset double +) +; +drop table if exists warehouse; +create table warehouse +as (select * from warehouse_text) +; +drop table if exists warehouse_text; + +drop table if exists web_page_text; +create table web_page_text +( + wp_web_page_sk int, + wp_web_page_id string, + wp_rec_start_date string, + wp_rec_end_date string, + wp_creation_date_sk int, + wp_access_date_sk int, + wp_autogen_flag string, + wp_customer_sk int, + wp_url string, + wp_type string, + wp_char_count int, + wp_link_count int, + wp_image_count int, + wp_max_ad_count int +) +; +drop table if exists web_page; +create table web_page +as (select * from web_page_text) +; +drop table if exists web_page_text; + +drop table if exists web_returns_text; +create table web_returns_text +( + wr_returned_date_sk int, + wr_returned_time_sk int, + wr_item_sk int, + wr_refunded_customer_sk int, + wr_refunded_cdemo_sk int, + wr_refunded_hdemo_sk int, + wr_refunded_addr_sk int, + wr_returning_customer_sk int, + wr_returning_cdemo_sk int, + wr_returning_hdemo_sk int, + wr_returning_addr_sk int, + wr_web_page_sk int, + wr_reason_sk int, + wr_order_number int, + wr_return_quantity int, + wr_return_amt double, + wr_return_tax double, + wr_return_amt_inc_tax double, + wr_fee double, + wr_return_ship_cost double, + wr_refunded_cash double, + wr_reversed_charge double, + wr_account_credit double, + wr_net_loss double +) +; +drop table if exists web_returns; +create table web_returns +as (select * from web_returns_text) +; +drop table if exists web_returns_text; + +drop table if exists web_sales_text; +create table web_sales_text +( + ws_sold_date_sk int, + ws_sold_time_sk int, + ws_ship_date_sk int, + ws_item_sk int, + ws_bill_customer_sk int, + ws_bill_cdemo_sk int, + ws_bill_hdemo_sk int, + ws_bill_addr_sk int, + ws_ship_customer_sk int, + ws_ship_cdemo_sk int, + ws_ship_hdemo_sk int, + ws_ship_addr_sk int, + ws_web_page_sk int, + ws_web_site_sk int, + ws_ship_mode_sk int, + ws_warehouse_sk int, + ws_promo_sk int, + ws_order_number int, + ws_quantity int, + ws_wholesale_cost double, + ws_list_price double, + ws_sales_price double, + ws_ext_discount_amt double, + ws_ext_sales_price double, + ws_ext_wholesale_cost double, + ws_ext_list_price double, + ws_ext_tax double, + ws_coupon_amt double, + ws_ext_ship_cost double, + ws_net_paid double, + ws_net_paid_inc_tax double, + ws_net_paid_inc_ship double, + ws_net_paid_inc_ship_tax double, + ws_net_profit double +) +; +drop table if exists web_sales; +create table web_sales +as (select * from web_sales_text) +; +drop table if exists web_sales_text; + +drop table if exists web_site_text; +create table web_site_text +( + web_site_sk int, + web_site_id string, + web_rec_start_date string, + web_rec_end_date string, + web_name string, + web_open_date_sk int, + web_close_date_sk int, + web_class string, + web_manager string, + web_mkt_id int, + web_mkt_class string, + web_mkt_desc string, + web_market_manager string, + web_company_id int, + web_company_name string, + web_street_number string, + web_street_name string, + web_street_type string, + web_suite_number string, + web_city string, + web_county string, + web_state string, + web_zip string, + web_country string, + web_gmt_offset double, + web_tax_percentage double +) +; +drop table if exists web_site; +create table web_site +as (select * from web_site_text) +; +drop table if exists web_site_text; diff --git a/src/main/resources/tpcds/query01.sql b/src/main/resources/tpcds/query01.sql new file mode 100644 index 0000000000..4a53627b1b --- /dev/null +++ b/src/main/resources/tpcds/query01.sql @@ -0,0 +1,19 @@ +WITH customer_total_return AS ( + SELECT sr_customer_sk AS ctr_customer_sk, sr_store_sk AS ctr_store_sk, sum(SR_RETURN_AMT) AS ctr_total_return + FROM store_returns, date_dim + WHERE sr_returned_date_sk = d_date_sk + AND d_year = 2000 + GROUP BY sr_customer_sk, sr_store_sk + ) +SELECT c_customer_id +FROM customer_total_return ctr1, store, customer +WHERE ctr1.ctr_total_return > ( + SELECT avg(ctr_total_return) * 1.2 + FROM customer_total_return ctr2 + WHERE ctr1.ctr_store_sk = ctr2.ctr_store_sk + ) + AND s_store_sk = ctr1.ctr_store_sk + AND s_state = 'TN' + AND ctr1.ctr_customer_sk = c_customer_sk +ORDER BY c_customer_id +LIMIT 100 \ No newline at end of file diff --git a/src/main/resources/tpcds/query02.sql b/src/main/resources/tpcds/query02.sql new file mode 100644 index 0000000000..35773b3a1d --- /dev/null +++ b/src/main/resources/tpcds/query02.sql @@ -0,0 +1,66 @@ +WITH wscs AS ( + SELECT sold_date_sk, sales_price + FROM ( + SELECT ws_sold_date_sk AS sold_date_sk, ws_ext_sales_price AS sales_price + FROM web_sales + UNION ALL + SELECT cs_sold_date_sk AS sold_date_sk, cs_ext_sales_price AS sales_price + FROM catalog_sales + ) x + ), + wswscs AS ( + SELECT d_week_seq + , sum(CASE + WHEN d_day_name = 'Sunday' THEN sales_price + ELSE NULL + END) AS sun_sales + , sum(CASE + WHEN d_day_name = 'Monday' THEN sales_price + ELSE NULL + END) AS mon_sales + , sum(CASE + WHEN d_day_name = 'Tuesday' THEN sales_price + ELSE NULL + END) AS tue_sales + , sum(CASE + WHEN d_day_name = 'Wednesday' THEN sales_price + ELSE NULL + END) AS wed_sales + , sum(CASE + WHEN d_day_name = 'Thursday' THEN sales_price + ELSE NULL + END) AS thu_sales + , sum(CASE + WHEN d_day_name = 'Friday' THEN sales_price + ELSE NULL + END) AS fri_sales + , sum(CASE + WHEN d_day_name = 'Saturday' THEN sales_price + ELSE NULL + END) AS sat_sales + FROM wscs, date_dim + WHERE d_date_sk = sold_date_sk + GROUP BY d_week_seq + ) +SELECT d_week_seq1, round(sun_sales1 / sun_sales2, 2) + , round(mon_sales1 / mon_sales2, 2) + , round(tue_sales1 / tue_sales2, 2) + , round(wed_sales1 / wed_sales2, 2) + , round(thu_sales1 / thu_sales2, 2) + , round(fri_sales1 / fri_sales2, 2) + , round(sat_sales1 / sat_sales2, 2) +FROM ( + SELECT wswscs.d_week_seq AS d_week_seq1, sun_sales AS sun_sales1, mon_sales AS mon_sales1, tue_sales AS tue_sales1, wed_sales AS wed_sales1 + , thu_sales AS thu_sales1, fri_sales AS fri_sales1, sat_sales AS sat_sales1 + FROM wswscs, date_dim + WHERE date_dim.d_week_seq = wswscs.d_week_seq + AND d_year = 2001 +) y, ( + SELECT wswscs.d_week_seq AS d_week_seq2, sun_sales AS sun_sales2, mon_sales AS mon_sales2, tue_sales AS tue_sales2, wed_sales AS wed_sales2 + , thu_sales AS thu_sales2, fri_sales AS fri_sales2, sat_sales AS sat_sales2 + FROM wswscs, date_dim + WHERE date_dim.d_week_seq = wswscs.d_week_seq + AND d_year = 2001 + 1 + ) z +WHERE d_week_seq1 = d_week_seq2 - 53 +ORDER BY d_week_seq1 \ No newline at end of file diff --git a/src/main/resources/tpcds/query03.sql b/src/main/resources/tpcds/query03.sql new file mode 100644 index 0000000000..0c135df065 --- /dev/null +++ b/src/main/resources/tpcds/query03.sql @@ -0,0 +1,9 @@ +SELECT dt.d_year, item.i_brand_id AS brand_id, item.i_brand AS brand, sum(ss_ext_sales_price) AS sum_agg +FROM date_dim dt, store_sales, item +WHERE dt.d_date_sk = store_sales.ss_sold_date_sk + AND store_sales.ss_item_sk = item.i_item_sk + AND item.i_manufact_id = 128 + AND dt.d_moy = 11 +GROUP BY dt.d_year, item.i_brand, item.i_brand_id +ORDER BY dt.d_year, sum_agg DESC, brand_id +LIMIT 100 \ No newline at end of file diff --git a/src/main/resources/tpcds/query04.sql b/src/main/resources/tpcds/query04.sql new file mode 100644 index 0000000000..4df5318b60 --- /dev/null +++ b/src/main/resources/tpcds/query04.sql @@ -0,0 +1,113 @@ +with year_total as ( + select c_customer_id customer_id + ,c_first_name customer_first_name + ,c_last_name customer_last_name + ,c_preferred_cust_flag customer_preferred_cust_flag + ,c_birth_country customer_birth_country + ,c_login customer_login + ,c_email_address customer_email_address + ,d_year dyear + ,sum(((ss_ext_list_price-ss_ext_wholesale_cost-ss_ext_discount_amt)+ss_ext_sales_price)/2) year_total + ,'s' sale_type + from customer + ,store_sales + ,date_dim + where c_customer_sk = ss_customer_sk + and ss_sold_date_sk = d_date_sk + group by c_customer_id + ,c_first_name + ,c_last_name + ,c_preferred_cust_flag + ,c_birth_country + ,c_login + ,c_email_address + ,d_year + union all + select c_customer_id customer_id + ,c_first_name customer_first_name + ,c_last_name customer_last_name + ,c_preferred_cust_flag customer_preferred_cust_flag + ,c_birth_country customer_birth_country + ,c_login customer_login + ,c_email_address customer_email_address + ,d_year dyear + ,sum((((cs_ext_list_price-cs_ext_wholesale_cost-cs_ext_discount_amt)+cs_ext_sales_price)/2) ) year_total + ,'c' sale_type + from customer + ,catalog_sales + ,date_dim + where c_customer_sk = cs_bill_customer_sk + and cs_sold_date_sk = d_date_sk + group by c_customer_id + ,c_first_name + ,c_last_name + ,c_preferred_cust_flag + ,c_birth_country + ,c_login + ,c_email_address + ,d_year +union all + select c_customer_id customer_id + ,c_first_name customer_first_name + ,c_last_name customer_last_name + ,c_preferred_cust_flag customer_preferred_cust_flag + ,c_birth_country customer_birth_country + ,c_login customer_login + ,c_email_address customer_email_address + ,d_year dyear + ,sum((((ws_ext_list_price-ws_ext_wholesale_cost-ws_ext_discount_amt)+ws_ext_sales_price)/2) ) year_total + ,'w' sale_type + from customer + ,web_sales + ,date_dim + where c_customer_sk = ws_bill_customer_sk + and ws_sold_date_sk = d_date_sk + group by c_customer_id + ,c_first_name + ,c_last_name + ,c_preferred_cust_flag + ,c_birth_country + ,c_login + ,c_email_address + ,d_year + ) + select + t_s_secyear.customer_id + ,t_s_secyear.customer_first_name + ,t_s_secyear.customer_last_name + ,t_s_secyear.customer_preferred_cust_flag + from year_total t_s_firstyear + ,year_total t_s_secyear + ,year_total t_c_firstyear + ,year_total t_c_secyear + ,year_total t_w_firstyear + ,year_total t_w_secyear + where t_s_secyear.customer_id = t_s_firstyear.customer_id + and t_s_firstyear.customer_id = t_c_secyear.customer_id + and t_s_firstyear.customer_id = t_c_firstyear.customer_id + and t_s_firstyear.customer_id = t_w_firstyear.customer_id + and t_s_firstyear.customer_id = t_w_secyear.customer_id + and t_s_firstyear.sale_type = 's' + and t_c_firstyear.sale_type = 'c' + and t_w_firstyear.sale_type = 'w' + and t_s_secyear.sale_type = 's' + and t_c_secyear.sale_type = 'c' + and t_w_secyear.sale_type = 'w' + and t_s_firstyear.dyear = 2001 + and t_s_secyear.dyear = 2001+1 + and t_c_firstyear.dyear = 2001 + and t_c_secyear.dyear = 2001+1 + and t_w_firstyear.dyear = 2001 + and t_w_secyear.dyear = 2001+1 + and t_s_firstyear.year_total > 0 + and t_c_firstyear.year_total > 0 + and t_w_firstyear.year_total > 0 + and case when t_c_firstyear.year_total > 0 then t_c_secyear.year_total / t_c_firstyear.year_total else null end + > case when t_s_firstyear.year_total > 0 then t_s_secyear.year_total / t_s_firstyear.year_total else null end + and case when t_c_firstyear.year_total > 0 then t_c_secyear.year_total / t_c_firstyear.year_total else null end + > case when t_w_firstyear.year_total > 0 then t_w_secyear.year_total / t_w_firstyear.year_total else null end + order by t_s_secyear.customer_id + ,t_s_secyear.customer_first_name + ,t_s_secyear.customer_last_name + ,t_s_secyear.customer_preferred_cust_flag + limit 100 diff --git a/src/main/resources/tpcds/query05.sql b/src/main/resources/tpcds/query05.sql new file mode 100644 index 0000000000..123f01683b --- /dev/null +++ b/src/main/resources/tpcds/query05.sql @@ -0,0 +1,72 @@ +WITH ssr AS ( + SELECT s_store_id, sum(sales_price) AS sales, sum(profit) AS profit + , sum(return_amt) AS returns, sum(net_loss) AS profit_loss + FROM ( + SELECT ss_store_sk AS store_sk, ss_sold_date_sk AS date_sk, ss_ext_sales_price AS sales_price, ss_net_profit AS profit, CAST(0 AS decimal(7, 2)) AS return_amt + , CAST(0 AS decimal(7, 2)) AS net_loss + FROM store_sales + UNION ALL + SELECT sr_store_sk AS store_sk, sr_returned_date_sk AS date_sk, CAST(0 AS decimal(7, 2)) AS sales_price, CAST(0 AS decimal(7, 2)) AS profit, sr_return_amt AS return_amt + , sr_net_loss AS net_loss + FROM store_returns + ) salesreturns, date_dim, store + WHERE date_sk = d_date_sk + AND d_date BETWEEN CAST('2000-08-23' AS date) AND date_add(CAST('2000-08-23' AS date), 14) + AND store_sk = s_store_sk + GROUP BY s_store_id + ), + csr AS ( + SELECT cp_catalog_page_id, sum(sales_price) AS sales, sum(profit) AS profit + , sum(return_amt) AS returns, sum(net_loss) AS profit_loss + FROM ( + SELECT cs_catalog_page_sk AS page_sk, cs_sold_date_sk AS date_sk, cs_ext_sales_price AS sales_price, cs_net_profit AS profit, CAST(0 AS decimal(7, 2)) AS return_amt + , CAST(0 AS decimal(7, 2)) AS net_loss + FROM catalog_sales + UNION ALL + SELECT cr_catalog_page_sk AS page_sk, cr_returned_date_sk AS date_sk, CAST(0 AS decimal(7, 2)) AS sales_price, CAST(0 AS decimal(7, 2)) AS profit, cr_return_amount AS return_amt + , cr_net_loss AS net_loss + FROM catalog_returns + ) salesreturns, date_dim, catalog_page + WHERE date_sk = d_date_sk + AND d_date BETWEEN CAST('2000-08-23' AS date) AND date_add(CAST('2000-08-23' AS date), 14) + AND page_sk = cp_catalog_page_sk + GROUP BY cp_catalog_page_id + ), + wsr AS ( + SELECT web_site_id, sum(sales_price) AS sales, sum(profit) AS profit + , sum(return_amt) AS returns, sum(net_loss) AS profit_loss + FROM ( + SELECT ws_web_site_sk AS wsr_web_site_sk, ws_sold_date_sk AS date_sk, ws_ext_sales_price AS sales_price, ws_net_profit AS profit, CAST(0 AS decimal(7, 2)) AS return_amt + , CAST(0 AS decimal(7, 2)) AS net_loss + FROM web_sales + UNION ALL + SELECT ws_web_site_sk AS wsr_web_site_sk, wr_returned_date_sk AS date_sk, CAST(0 AS decimal(7, 2)) AS sales_price, CAST(0 AS decimal(7, 2)) AS profit, wr_return_amt AS return_amt + , wr_net_loss AS net_loss + FROM web_returns + LEFT JOIN web_sales + ON wr_item_sk = ws_item_sk + AND wr_order_number = ws_order_number + ) salesreturns, date_dim, web_site + WHERE date_sk = d_date_sk + AND d_date BETWEEN CAST('2000-08-23' AS date) AND date_add(CAST('2000-08-23' AS date), 14) + AND wsr_web_site_sk = web_site_sk + GROUP BY web_site_id + ) +SELECT channel, id, sum(sales) AS sales + , sum(returns) AS returns, sum(profit) AS profit +FROM ( + SELECT 'store channel' AS channel, concat('store', s_store_id) AS id, sales + , returns, profit - profit_loss AS profit + FROM ssr + UNION ALL + SELECT 'catalog channel' AS channel, concat('catalog_page', cp_catalog_page_id) AS id, sales + , returns, profit - profit_loss AS profit + FROM csr + UNION ALL + SELECT 'web channel' AS channel, concat('web_site', web_site_id) AS id, sales + , returns, profit - profit_loss AS profit + FROM wsr +) x +GROUP BY ROLLUP (channel, id) +ORDER BY channel, id +LIMIT 100 \ No newline at end of file diff --git a/src/main/resources/tpcds/query06.sql b/src/main/resources/tpcds/query06.sql new file mode 100644 index 0000000000..418966902c --- /dev/null +++ b/src/main/resources/tpcds/query06.sql @@ -0,0 +1,23 @@ +select a.ca_state state, count(*) cnt + from customer_address a + ,customer c + ,store_sales s + ,date_dim d + ,item i + where a.ca_address_sk = c.c_current_addr_sk + and c.c_customer_sk = s.ss_customer_sk + and s.ss_sold_date_sk = d.d_date_sk + and s.ss_item_sk = i.i_item_sk + and d.d_month_seq = + (select distinct (d_month_seq) + from date_dim + where d_year = 2001 + and d_moy = 1 ) + and i.i_current_price > 1.2 * + (select avg(j.i_current_price) + from item j + where j.i_category = i.i_category) + group by a.ca_state + having count(*) >= 10 + order by cnt + limit 100 diff --git a/src/main/resources/tpcds/query07.sql b/src/main/resources/tpcds/query07.sql new file mode 100644 index 0000000000..62e32cb3eb --- /dev/null +++ b/src/main/resources/tpcds/query07.sql @@ -0,0 +1,18 @@ +select i_item_id, + avg(ss_quantity) agg1, + avg(ss_list_price) agg2, + avg(ss_coupon_amt) agg3, + avg(ss_sales_price) agg4 + from store_sales, customer_demographics, date_dim, item, promotion + where ss_sold_date_sk = d_date_sk and + ss_item_sk = i_item_sk and + ss_cdemo_sk = cd_demo_sk and + ss_promo_sk = p_promo_sk and + cd_gender = 'M' and + cd_marital_status = 'S' and + cd_education_status = 'College' and + (p_channel_email = 'N' or p_channel_event = 'N') and + d_year = 2000 + group by i_item_id + order by i_item_id + limit 100 diff --git a/src/main/resources/tpcds/query08.sql b/src/main/resources/tpcds/query08.sql new file mode 100644 index 0000000000..e31c34c422 --- /dev/null +++ b/src/main/resources/tpcds/query08.sql @@ -0,0 +1,105 @@ +select s_store_name + ,sum(ss_net_profit) + from store_sales + ,date_dim + ,store, + (select ca_zip + from ( + SELECT substr(ca_zip,1,5) ca_zip + FROM customer_address + WHERE substr(ca_zip,1,5) IN ( + '24128','76232','65084','87816','83926','77556', + '20548','26231','43848','15126','91137', + '61265','98294','25782','17920','18426', + '98235','40081','84093','28577','55565', + '17183','54601','67897','22752','86284', + '18376','38607','45200','21756','29741', + '96765','23932','89360','29839','25989', + '28898','91068','72550','10390','18845', + '47770','82636','41367','76638','86198', + '81312','37126','39192','88424','72175', + '81426','53672','10445','42666','66864', + '66708','41248','48583','82276','18842', + '78890','49448','14089','38122','34425', + '79077','19849','43285','39861','66162', + '77610','13695','99543','83444','83041', + '12305','57665','68341','25003','57834', + '62878','49130','81096','18840','27700', + '23470','50412','21195','16021','76107', + '71954','68309','18119','98359','64544', + '10336','86379','27068','39736','98569', + '28915','24206','56529','57647','54917', + '42961','91110','63981','14922','36420', + '23006','67467','32754','30903','20260', + '31671','51798','72325','85816','68621', + '13955','36446','41766','68806','16725', + '15146','22744','35850','88086','51649', + '18270','52867','39972','96976','63792', + '11376','94898','13595','10516','90225', + '58943','39371','94945','28587','96576', + '57855','28488','26105','83933','25858', + '34322','44438','73171','30122','34102', + '22685','71256','78451','54364','13354', + '45375','40558','56458','28286','45266', + '47305','69399','83921','26233','11101', + '15371','69913','35942','15882','25631', + '24610','44165','99076','33786','70738', + '26653','14328','72305','62496','22152', + '10144','64147','48425','14663','21076', + '18799','30450','63089','81019','68893', + '24996','51200','51211','45692','92712', + '70466','79994','22437','25280','38935', + '71791','73134','56571','14060','19505', + '72425','56575','74351','68786','51650', + '20004','18383','76614','11634','18906', + '15765','41368','73241','76698','78567', + '97189','28545','76231','75691','22246', + '51061','90578','56691','68014','51103', + '94167','57047','14867','73520','15734', + '63435','25733','35474','24676','94627', + '53535','17879','15559','53268','59166', + '11928','59402','33282','45721','43933', + '68101','33515','36634','71286','19736', + '58058','55253','67473','41918','19515', + '36495','19430','22351','77191','91393', + '49156','50298','87501','18652','53179', + '18767','63193','23968','65164','68880', + '21286','72823','58470','67301','13394', + '31016','70372','67030','40604','24317', + '45748','39127','26065','77721','31029', + '31880','60576','24671','45549','13376', + '50016','33123','19769','22927','97789', + '46081','72151','15723','46136','51949', + '68100','96888','64528','14171','79777', + '28709','11489','25103','32213','78668', + '22245','15798','27156','37930','62971', + '21337','51622','67853','10567','38415', + '15455','58263','42029','60279','37125', + '56240','88190','50308','26859','64457', + '89091','82136','62377','36233','63837', + '58078','17043','30010','60099','28810', + '98025','29178','87343','73273','30469', + '64034','39516','86057','21309','90257', + '67875','40162','11356','73650','61810', + '72013','30431','22461','19512','13375', + '55307','30625','83849','68908','26689', + '96451','38193','46820','88885','84935', + '69035','83144','47537','56616','94983', + '48033','69952','25486','61547','27385', + '61860','58048','56910','16807','17871', + '35258','31387','35458','35576') + intersect + select ca_zip + from (SELECT substr(ca_zip,1,5) ca_zip,count(*) cnt + FROM customer_address, customer + WHERE ca_address_sk = c_current_addr_sk and + c_preferred_cust_flag='Y' + group by ca_zip + having count(*) > 10)A1)A2) V1 + where ss_store_sk = s_store_sk + and ss_sold_date_sk = d_date_sk + and d_qoy = 2 and d_year = 1998 + and (substr(s_zip,1,2) = substr(V1.ca_zip,1,2)) + group by s_store_name + order by s_store_name + limit 100 diff --git a/src/main/resources/tpcds/query09.sql b/src/main/resources/tpcds/query09.sql new file mode 100644 index 0000000000..8a03c62b7b --- /dev/null +++ b/src/main/resources/tpcds/query09.sql @@ -0,0 +1,48 @@ +select case when (select count(*) + from store_sales + where ss_quantity between 1 and 20) > 74129 + then (select avg(ss_ext_discount_amt) + from store_sales + where ss_quantity between 1 and 20) + else (select avg(ss_net_paid) + from store_sales + where ss_quantity between 1 and 20) end bucket1 , + case when (select count(*) + from store_sales + where ss_quantity between 21 and 40) > 122840 + then (select avg(ss_ext_discount_amt) + from store_sales + where ss_quantity between 21 and 40) + else (select avg(ss_net_paid) + from store_sales + where ss_quantity between 21 and 40) end bucket2, + case when (select count(*) + from store_sales + where ss_quantity between 41 and 60) > 56580 + then (select avg(ss_ext_discount_amt) + from store_sales + where ss_quantity between 41 and 60) + else (select avg(ss_net_paid) + from store_sales + where ss_quantity between 41 and 60) end bucket3, + case when (select count(*) + from store_sales + where ss_quantity between 61 and 80) > 10097 + then (select avg(ss_ext_discount_amt) + from store_sales + where ss_quantity between 61 and 80) + else (select avg(ss_net_paid) + from store_sales + where ss_quantity between 61 and 80) end bucket4, + case when (select count(*) + from store_sales + where ss_quantity between 81 and 100) > 165306 + then (select avg(ss_ext_discount_amt) + from store_sales + where ss_quantity between 81 and 100) + else (select avg(ss_net_paid) + from store_sales + where ss_quantity between 81 and 100) end bucket5 +from reason +where r_reason_sk = 1 + diff --git a/src/main/resources/tpcds/query10.sql b/src/main/resources/tpcds/query10.sql new file mode 100644 index 0000000000..752d852f1d --- /dev/null +++ b/src/main/resources/tpcds/query10.sql @@ -0,0 +1,56 @@ +select + cd_gender, + cd_marital_status, + cd_education_status, + count(*) cnt1, + cd_purchase_estimate, + count(*) cnt2, + cd_credit_rating, + count(*) cnt3, + cd_dep_count, + count(*) cnt4, + cd_dep_employed_count, + count(*) cnt5, + cd_dep_college_count, + count(*) cnt6 + from + customer c,customer_address ca,customer_demographics + where + c.c_current_addr_sk = ca.ca_address_sk and + ca_county in ('Rush County','Toole County','Jefferson County','Dona Ana County','La Porte County') and + cd_demo_sk = c.c_current_cdemo_sk and + exists (select * + from store_sales,date_dim + where c.c_customer_sk = ss_customer_sk and + ss_sold_date_sk = d_date_sk and + d_year = 2002 and + d_moy between 1 and 1+3) and + (exists (select * + from web_sales,date_dim + where c.c_customer_sk = ws_bill_customer_sk and + ws_sold_date_sk = d_date_sk and + d_year = 2002 and + d_moy between 1 ANd 1+3) or + exists (select * + from catalog_sales,date_dim + where c.c_customer_sk = cs_ship_customer_sk and + cs_sold_date_sk = d_date_sk and + d_year = 2002 and + d_moy between 1 and 1+3)) + group by cd_gender, + cd_marital_status, + cd_education_status, + cd_purchase_estimate, + cd_credit_rating, + cd_dep_count, + cd_dep_employed_count, + cd_dep_college_count + order by cd_gender, + cd_marital_status, + cd_education_status, + cd_purchase_estimate, + cd_credit_rating, + cd_dep_count, + cd_dep_employed_count, + cd_dep_college_count + limit 100 diff --git a/src/main/resources/tpcds/query11.sql b/src/main/resources/tpcds/query11.sql new file mode 100644 index 0000000000..671ddb1783 --- /dev/null +++ b/src/main/resources/tpcds/query11.sql @@ -0,0 +1,78 @@ +with year_total as ( + select c_customer_id customer_id + ,c_first_name customer_first_name + ,c_last_name customer_last_name + ,c_preferred_cust_flag customer_preferred_cust_flag + ,c_birth_country customer_birth_country + ,c_login customer_login + ,c_email_address customer_email_address + ,d_year dyear + ,sum(ss_ext_list_price-ss_ext_discount_amt) year_total + ,'s' sale_type + from customer + ,store_sales + ,date_dim + where c_customer_sk = ss_customer_sk + and ss_sold_date_sk = d_date_sk + group by c_customer_id + ,c_first_name + ,c_last_name + ,c_preferred_cust_flag + ,c_birth_country + ,c_login + ,c_email_address + ,d_year + union all + select c_customer_id customer_id + ,c_first_name customer_first_name + ,c_last_name customer_last_name + ,c_preferred_cust_flag customer_preferred_cust_flag + ,c_birth_country customer_birth_country + ,c_login customer_login + ,c_email_address customer_email_address + ,d_year dyear + ,sum(ws_ext_list_price-ws_ext_discount_amt) year_total + ,'w' sale_type + from customer + ,web_sales + ,date_dim + where c_customer_sk = ws_bill_customer_sk + and ws_sold_date_sk = d_date_sk + group by c_customer_id + ,c_first_name + ,c_last_name + ,c_preferred_cust_flag + ,c_birth_country + ,c_login + ,c_email_address + ,d_year + ) + select + t_s_secyear.customer_id + ,t_s_secyear.customer_first_name + ,t_s_secyear.customer_last_name + ,t_s_secyear.customer_preferred_cust_flag + from year_total t_s_firstyear + ,year_total t_s_secyear + ,year_total t_w_firstyear + ,year_total t_w_secyear + where t_s_secyear.customer_id = t_s_firstyear.customer_id + and t_s_firstyear.customer_id = t_w_secyear.customer_id + and t_s_firstyear.customer_id = t_w_firstyear.customer_id + and t_s_firstyear.sale_type = 's' + and t_w_firstyear.sale_type = 'w' + and t_s_secyear.sale_type = 's' + and t_w_secyear.sale_type = 'w' + and t_s_firstyear.dyear = 2001 + and t_s_secyear.dyear = 2001+1 + and t_w_firstyear.dyear = 2001 + and t_w_secyear.dyear = 2001+1 + and t_s_firstyear.year_total > 0 + and t_w_firstyear.year_total > 0 + and case when t_w_firstyear.year_total > 0 then t_w_secyear.year_total / t_w_firstyear.year_total else 0.0 end + > case when t_s_firstyear.year_total > 0 then t_s_secyear.year_total / t_s_firstyear.year_total else 0.0 end + order by t_s_secyear.customer_id + ,t_s_secyear.customer_first_name + ,t_s_secyear.customer_last_name + ,t_s_secyear.customer_preferred_cust_flag + limit 100 diff --git a/src/main/resources/tpcds/query12.sql b/src/main/resources/tpcds/query12.sql new file mode 100644 index 0000000000..91cefc0481 --- /dev/null +++ b/src/main/resources/tpcds/query12.sql @@ -0,0 +1,31 @@ +select i_item_id + ,i_item_desc + ,i_category + ,i_class + ,i_current_price + ,sum(ws_ext_sales_price) as itemrevenue + ,sum(ws_ext_sales_price)*100/sum(sum(ws_ext_sales_price)) over + (partition by i_class) as revenueratio +from + web_sales + ,item + ,date_dim +where + ws_item_sk = i_item_sk + and i_category in ('Sports', 'Books', 'Home') + and ws_sold_date_sk = d_date_sk + and d_date between cast('1999-02-22' as date) + and date_add(cast('1999-02-22' as date), 30 ) +group by + i_item_id + ,i_item_desc + ,i_category + ,i_class + ,i_current_price +order by + i_category + ,i_class + ,i_item_id + ,i_item_desc + ,revenueratio + limit 100 diff --git a/src/main/resources/tpcds/query13.sql b/src/main/resources/tpcds/query13.sql new file mode 100644 index 0000000000..2e383ab06b --- /dev/null +++ b/src/main/resources/tpcds/query13.sql @@ -0,0 +1,49 @@ +select avg(ss_quantity) + ,avg(ss_ext_sales_price) + ,avg(ss_ext_wholesale_cost) + ,sum(ss_ext_wholesale_cost) + from store_sales + ,store + ,customer_demographics + ,household_demographics + ,customer_address + ,date_dim + where s_store_sk = ss_store_sk + and ss_sold_date_sk = d_date_sk and d_year = 2001 + and((ss_hdemo_sk=hd_demo_sk + and cd_demo_sk = ss_cdemo_sk + and cd_marital_status = 'M' + and cd_education_status = 'Advanced Degree' + and ss_sales_price between 100.00 and 150.00 + and hd_dep_count = 3 + )or + (ss_hdemo_sk=hd_demo_sk + and cd_demo_sk = ss_cdemo_sk + and cd_marital_status = 'S' + and cd_education_status = 'College' + and ss_sales_price between 50.00 and 100.00 + and hd_dep_count = 1 + ) or + (ss_hdemo_sk=hd_demo_sk + and cd_demo_sk = ss_cdemo_sk + and cd_marital_status = 'W' + and cd_education_status = '2 yr Degree' + and ss_sales_price between 150.00 and 200.00 + and hd_dep_count = 1 + )) + and((ss_addr_sk = ca_address_sk + and ca_country = 'United States' + and ca_state in ('TX', 'OH', 'TX') + and ss_net_profit between 100 and 200 + ) or + (ss_addr_sk = ca_address_sk + and ca_country = 'United States' + and ca_state in ('OR', 'NM', 'KY') + and ss_net_profit between 150 and 300 + ) or + (ss_addr_sk = ca_address_sk + and ca_country = 'United States' + and ca_state in ('VA', 'TX', 'MS') + and ss_net_profit between 50 and 250 + )) + diff --git a/src/main/resources/tpcds/query14.sql b/src/main/resources/tpcds/query14.sql new file mode 100644 index 0000000000..b110af303c --- /dev/null +++ b/src/main/resources/tpcds/query14.sql @@ -0,0 +1,195 @@ +with cross_items as + (select i_item_sk ss_item_sk + from item, + (select iss.i_brand_id brand_id + ,iss.i_class_id class_id + ,iss.i_category_id category_id + from store_sales + ,item iss + ,date_dim d1 + where ss_item_sk = iss.i_item_sk + and ss_sold_date_sk = d1.d_date_sk + and d1.d_year between 1999 AND 1999 + 2 + intersect + select ics.i_brand_id + ,ics.i_class_id + ,ics.i_category_id + from catalog_sales + ,item ics + ,date_dim d2 + where cs_item_sk = ics.i_item_sk + and cs_sold_date_sk = d2.d_date_sk + and d2.d_year between 1999 AND 1999 + 2 + intersect + select iws.i_brand_id + ,iws.i_class_id + ,iws.i_category_id + from web_sales + ,item iws + ,date_dim d3 + where ws_item_sk = iws.i_item_sk + and ws_sold_date_sk = d3.d_date_sk + and d3.d_year between 1999 AND 1999 + 2) + where i_brand_id = brand_id + and i_class_id = class_id + and i_category_id = category_id +), + avg_sales as + (select avg(quantity*list_price) average_sales + from (select ss_quantity quantity + ,ss_list_price list_price + from store_sales + ,date_dim + where ss_sold_date_sk = d_date_sk + and d_year between 1999 and 1999 + 2 + union all + select cs_quantity quantity + ,cs_list_price list_price + from catalog_sales + ,date_dim + where cs_sold_date_sk = d_date_sk + and d_year between 1999 and 1999 + 2 + union all + select ws_quantity quantity + ,ws_list_price list_price + from web_sales + ,date_dim + where ws_sold_date_sk = d_date_sk + and d_year between 1999 and 1999 + 2) x) + select channel, i_brand_id,i_class_id,i_category_id,sum(sales), sum(number_sales) + from( + select 'store' channel, i_brand_id,i_class_id + ,i_category_id,sum(ss_quantity*ss_list_price) sales + , count(*) number_sales + from store_sales + ,item + ,date_dim + where ss_item_sk in (select ss_item_sk from cross_items) + and ss_item_sk = i_item_sk + and ss_sold_date_sk = d_date_sk + and d_year = 1999+2 + and d_moy = 11 + group by i_brand_id,i_class_id,i_category_id + having sum(ss_quantity*ss_list_price) > (select average_sales from avg_sales) + union all + select 'catalog' channel, i_brand_id,i_class_id,i_category_id, sum(cs_quantity*cs_list_price) sales, count(*) number_sales + from catalog_sales + ,item + ,date_dim + where cs_item_sk in (select ss_item_sk from cross_items) + and cs_item_sk = i_item_sk + and cs_sold_date_sk = d_date_sk + and d_year = 1999+2 + and d_moy = 11 + group by i_brand_id,i_class_id,i_category_id + having sum(cs_quantity*cs_list_price) > (select average_sales from avg_sales) + union all + select 'web' channel, i_brand_id,i_class_id,i_category_id, sum(ws_quantity*ws_list_price) sales , count(*) number_sales + from web_sales + ,item + ,date_dim + where ws_item_sk in (select ss_item_sk from cross_items) + and ws_item_sk = i_item_sk + and ws_sold_date_sk = d_date_sk + and d_year = 1999+2 + and d_moy = 11 + group by i_brand_id,i_class_id,i_category_id + having sum(ws_quantity*ws_list_price) > (select average_sales from avg_sales) + ) y + group by rollup (channel, i_brand_id,i_class_id,i_category_id) + order by channel,i_brand_id,i_class_id,i_category_id + limit 100; + with cross_items as + (select i_item_sk ss_item_sk + from item, + (select iss.i_brand_id brand_id + ,iss.i_class_id class_id + ,iss.i_category_id category_id + from store_sales + ,item iss + ,date_dim d1 + where ss_item_sk = iss.i_item_sk + and ss_sold_date_sk = d1.d_date_sk + and d1.d_year between 1999 AND 1999 + 2 + intersect + select ics.i_brand_id + ,ics.i_class_id + ,ics.i_category_id + from catalog_sales + ,item ics + ,date_dim d2 + where cs_item_sk = ics.i_item_sk + and cs_sold_date_sk = d2.d_date_sk + and d2.d_year between 1999 AND 1999 + 2 + intersect + select iws.i_brand_id + ,iws.i_class_id + ,iws.i_category_id + from web_sales + ,item iws + ,date_dim d3 + where ws_item_sk = iws.i_item_sk + and ws_sold_date_sk = d3.d_date_sk + and d3.d_year between 1999 AND 1999 + 2) x + where i_brand_id = brand_id + and i_class_id = class_id + and i_category_id = category_id +), + avg_sales as +(select avg(quantity*list_price) average_sales + from (select ss_quantity quantity + ,ss_list_price list_price + from store_sales + ,date_dim + where ss_sold_date_sk = d_date_sk + and d_year between 1999 and 1999 + 2 + union all + select cs_quantity quantity + ,cs_list_price list_price + from catalog_sales + ,date_dim + where cs_sold_date_sk = d_date_sk + and d_year between 1999 and 1999 + 2 + union all + select ws_quantity quantity + ,ws_list_price list_price + from web_sales + ,date_dim + where ws_sold_date_sk = d_date_sk + and d_year between 1999 and 1999 + 2) x) + select * from + (select 'store' channel, i_brand_id,i_class_id,i_category_id + ,sum(ss_quantity*ss_list_price) sales, count(*) number_sales + from store_sales + ,item + ,date_dim + where ss_item_sk in (select ss_item_sk from cross_items) + and ss_item_sk = i_item_sk + and ss_sold_date_sk = d_date_sk + and d_week_seq = (select d_week_seq + from date_dim + where d_year = 1999 + 1 + and d_moy = 12 + and d_dom = 11) + group by i_brand_id,i_class_id,i_category_id + having sum(ss_quantity*ss_list_price) > (select average_sales from avg_sales)) this_year, + (select 'store' channel_2, i_brand_id as i_brand_id_2, i_class_id as i_class_id_2 + ,i_category_id as i_category_id_2 , sum(ss_quantity*ss_list_price) sales_2, count(*) number_sales_2 + from store_sales + ,item + ,date_dim + where ss_item_sk in (select ss_item_sk from cross_items) + and ss_item_sk = i_item_sk + and ss_sold_date_sk = d_date_sk + and d_week_seq = (select d_week_seq + from date_dim + where d_year = 1999 + and d_moy = 12 + and d_dom = 11) + group by i_brand_id,i_class_id,i_category_id + having sum(ss_quantity*ss_list_price) > (select average_sales from avg_sales)) last_year + where this_year.i_brand_id= last_year.i_brand_id_2 + and this_year.i_class_id = last_year.i_class_id_2 + and this_year.i_category_id = last_year.i_category_id_2 + order by this_year.channel, this_year.i_brand_id, this_year.i_class_id, this_year.i_category_id + limit 100 diff --git a/src/main/resources/tpcds/query15.sql b/src/main/resources/tpcds/query15.sql new file mode 100644 index 0000000000..e838df9077 --- /dev/null +++ b/src/main/resources/tpcds/query15.sql @@ -0,0 +1,17 @@ +select ca_zip + ,sum(cs_sales_price) + from catalog_sales + ,customer + ,customer_address + ,date_dim + where cs_bill_customer_sk = c_customer_sk + and c_current_addr_sk = ca_address_sk + and ( substr(ca_zip,1,5) in ('85669', '86197','88274','83405','86475', + '85392', '85460', '80348', '81792') + or ca_state in ('CA','WA','GA') + or cs_sales_price > 500) + and cs_sold_date_sk = d_date_sk + and d_qoy = 2 and d_year = 2001 + group by ca_zip + order by ca_zip + limit 100 \ No newline at end of file diff --git a/src/main/resources/tpcds/query16.sql b/src/main/resources/tpcds/query16.sql new file mode 100644 index 0000000000..43f2d00e21 --- /dev/null +++ b/src/main/resources/tpcds/query16.sql @@ -0,0 +1,28 @@ +select + count(distinct cs_order_number) as order_count + ,sum(cs_ext_ship_cost) as total_shipping_cost + ,sum(cs_net_profit) as total_net_profit +from + catalog_sales cs1 + ,date_dim + ,customer_address + ,call_center +where + d_date between cast('2002-2-01' as date) and + date_add(cast('2002-2-01' as date), 60 ) +and cs1.cs_ship_date_sk = d_date_sk +and cs1.cs_ship_addr_sk = ca_address_sk +and ca_state = 'GA' +and cs1.cs_call_center_sk = cc_call_center_sk +and cc_county in ('Williamson County','Williamson County','Williamson County','Williamson County', + 'Williamson County' +) +and exists (select * + from catalog_sales cs2 + where cs1.cs_order_number = cs2.cs_order_number + and cs1.cs_warehouse_sk <> cs2.cs_warehouse_sk) +and not exists(select * + from catalog_returns cr1 + where cs1.cs_order_number = cr1.cr_order_number) +order by count(distinct cs_order_number) + limit 100 diff --git a/src/main/resources/tpcds/query17.sql b/src/main/resources/tpcds/query17.sql new file mode 100644 index 0000000000..a1bb556616 --- /dev/null +++ b/src/main/resources/tpcds/query17.sql @@ -0,0 +1,42 @@ +select i_item_id + ,i_item_desc + ,s_state + ,count(ss_quantity) as store_sales_quantitycount + ,avg(ss_quantity) as store_sales_quantityave + ,stddev_samp(ss_quantity) as store_sales_quantitystdev + ,stddev_samp(ss_quantity)/avg(ss_quantity) as store_sales_quantitycov + ,count(sr_return_quantity) as store_returns_quantitycount + ,avg(sr_return_quantity) as store_returns_quantityave + ,stddev_samp(sr_return_quantity) as store_returns_quantitystdev + ,stddev_samp(sr_return_quantity)/avg(sr_return_quantity) as store_returns_quantitycov + ,count(cs_quantity) as catalog_sales_quantitycount ,avg(cs_quantity) as catalog_sales_quantityave + ,stddev_samp(cs_quantity) as catalog_sales_quantitystdev + ,stddev_samp(cs_quantity)/avg(cs_quantity) as catalog_sales_quantitycov + from store_sales + ,store_returns + ,catalog_sales + ,date_dim d1 + ,date_dim d2 + ,date_dim d3 + ,store + ,item + where d1.d_quarter_name = '2001Q1' + and d1.d_date_sk = ss_sold_date_sk + and i_item_sk = ss_item_sk + and s_store_sk = ss_store_sk + and ss_customer_sk = sr_customer_sk + and ss_item_sk = sr_item_sk + and ss_ticket_number = sr_ticket_number + and sr_returned_date_sk = d2.d_date_sk + and d2.d_quarter_name in ('2001Q1','2001Q2','2001Q3') + and sr_customer_sk = cs_bill_customer_sk + and sr_item_sk = cs_item_sk + and cs_sold_date_sk = d3.d_date_sk + and d3.d_quarter_name in ('2001Q1','2001Q2','2001Q3') + group by i_item_id + ,i_item_desc + ,s_state + order by i_item_id + ,i_item_desc + ,s_state + limit 100 \ No newline at end of file diff --git a/src/main/resources/tpcds/query18.sql b/src/main/resources/tpcds/query18.sql new file mode 100644 index 0000000000..e43a5bc4e6 --- /dev/null +++ b/src/main/resources/tpcds/query18.sql @@ -0,0 +1,31 @@ +select i_item_id, + ca_country, + ca_state, + ca_county, + avg( cast(cs_quantity as decimal(12,2))) agg1, + avg( cast(cs_list_price as decimal(12,2))) agg2, + avg( cast(cs_coupon_amt as decimal(12,2))) agg3, + avg( cast(cs_sales_price as decimal(12,2))) agg4, + avg( cast(cs_net_profit as decimal(12,2))) agg5, + avg( cast(c_birth_year as decimal(12,2))) agg6, + avg( cast(cd1.cd_dep_count as decimal(12,2))) agg7 + from catalog_sales, customer_demographics cd1, + customer_demographics cd2, customer, customer_address, date_dim, item + where cs_sold_date_sk = d_date_sk and + cs_item_sk = i_item_sk and + cs_bill_cdemo_sk = cd1.cd_demo_sk and + cs_bill_customer_sk = c_customer_sk and + cd1.cd_gender = 'F' and + cd1.cd_education_status = 'Unknown' and + c_current_cdemo_sk = cd2.cd_demo_sk and + c_current_addr_sk = ca_address_sk and + c_birth_month in (1,6,8,9,12,2) and + d_year = 1998 and + ca_state in ('MS','IN','ND' + ,'OK','NM','VA','MS') + group by rollup (i_item_id, ca_country, ca_state, ca_county) + order by ca_country, + ca_state, + ca_county, + i_item_id + limit 100 diff --git a/src/main/resources/tpcds/query19.sql b/src/main/resources/tpcds/query19.sql new file mode 100644 index 0000000000..0ce2adcaa7 --- /dev/null +++ b/src/main/resources/tpcds/query19.sql @@ -0,0 +1,22 @@ +select i_brand_id brand_id, i_brand brand, i_manufact_id, i_manufact, + sum(ss_ext_sales_price) ext_price + from date_dim, store_sales, item,customer,customer_address,store + where d_date_sk = ss_sold_date_sk + and ss_item_sk = i_item_sk + and i_manager_id=8 + and d_moy=11 + and d_year=1998 + and ss_customer_sk = c_customer_sk + and c_current_addr_sk = ca_address_sk + and substr(ca_zip,1,5) <> substr(s_zip,1,5) + and ss_store_sk = s_store_sk + group by i_brand + ,i_brand_id + ,i_manufact_id + ,i_manufact + order by ext_price desc + ,i_brand + ,i_brand_id + ,i_manufact_id + ,i_manufact + limit 100 diff --git a/src/main/resources/tpcds/query20.sql b/src/main/resources/tpcds/query20.sql new file mode 100644 index 0000000000..235c350549 --- /dev/null +++ b/src/main/resources/tpcds/query20.sql @@ -0,0 +1,27 @@ +select i_item_id + ,i_item_desc + ,i_category + ,i_class + ,i_current_price + ,sum(cs_ext_sales_price) as itemrevenue + ,sum(cs_ext_sales_price)*100/sum(sum(cs_ext_sales_price)) over + (partition by i_class) as revenueratio + from catalog_sales + ,item + ,date_dim + where cs_item_sk = i_item_sk + and i_category in ('Sports', 'Books', 'Home') + and cs_sold_date_sk = d_date_sk + and d_date between cast('1999-02-22' as date) + and date_add(cast('1999-02-22' as date), 30) + group by i_item_id + ,i_item_desc + ,i_category + ,i_class + ,i_current_price + order by i_category + ,i_class + ,i_item_id + ,i_item_desc + ,revenueratio + limit 100 diff --git a/src/main/resources/tpcds/query21.sql b/src/main/resources/tpcds/query21.sql new file mode 100644 index 0000000000..d2a3f49c4c --- /dev/null +++ b/src/main/resources/tpcds/query21.sql @@ -0,0 +1,27 @@ +select * + from(select w_warehouse_name + ,i_item_id + ,sum(case when (cast(d_date as date) < cast ('2000-03-11' as date)) + then inv_quantity_on_hand + else 0 end) as inv_before + ,sum(case when (cast(d_date as date) >= cast ('2000-03-11' as date)) + then inv_quantity_on_hand + else 0 end) as inv_after + from inventory + ,warehouse + ,item + ,date_dim + where i_current_price between 0.99 and 1.49 + and i_item_sk = inv_item_sk + and inv_warehouse_sk = w_warehouse_sk + and inv_date_sk = d_date_sk + and d_date between date_sub(cast ('2000-03-11' as date), 30 ) + and date_add(cast ('2000-03-11' as date), 30 ) + group by w_warehouse_name, i_item_id) x + where (case when inv_before > 0 + then inv_after / inv_before + else null + end) between 2.0/3.0 and 3.0/2.0 + order by w_warehouse_name + ,i_item_id + limit 100 diff --git a/src/main/resources/tpcds/query22.sql b/src/main/resources/tpcds/query22.sql new file mode 100644 index 0000000000..a4f795a4a7 --- /dev/null +++ b/src/main/resources/tpcds/query22.sql @@ -0,0 +1,17 @@ +select i_product_name + ,i_brand + ,i_class + ,i_category + ,avg(inv_quantity_on_hand) qoh + from inventory + ,date_dim + ,item + where inv_date_sk=d_date_sk + and inv_item_sk=i_item_sk + and d_month_seq between 1200 and 1200 + 11 + group by rollup(i_product_name + ,i_brand + ,i_class + ,i_category) +order by qoh, i_product_name, i_brand, i_class, i_category + limit 100 diff --git a/src/main/resources/tpcds/query23.sql b/src/main/resources/tpcds/query23.sql new file mode 100644 index 0000000000..dc009be7dd --- /dev/null +++ b/src/main/resources/tpcds/query23.sql @@ -0,0 +1,104 @@ +with frequent_ss_items as + (select substr(i_item_desc,1,30) itemdesc,i_item_sk item_sk,d_date solddate,count(*) cnt + from store_sales + ,date_dim + ,item + where ss_sold_date_sk = d_date_sk + and ss_item_sk = i_item_sk + and d_year in (2000,2000+1,2000+2,2000+3) + group by substr(i_item_desc,1,30),i_item_sk,d_date + having count(*) >4), + max_store_sales as + (select max(csales) tpcds_cmax + from (select c_customer_sk,sum(ss_quantity*ss_sales_price) csales + from store_sales + ,customer + ,date_dim + where ss_customer_sk = c_customer_sk + and ss_sold_date_sk = d_date_sk + and d_year in (2000,2000+1,2000+2,2000+3) + group by c_customer_sk)), + best_ss_customer as + (select c_customer_sk,sum(ss_quantity*ss_sales_price) ssales + from store_sales + ,customer + where ss_customer_sk = c_customer_sk + group by c_customer_sk + having sum(ss_quantity*ss_sales_price) > (50/100.0) * (select + * +from + max_store_sales)) + select sum(sales) + from (select cs_quantity*cs_list_price sales + from catalog_sales + ,date_dim + where d_year = 2000 + and d_moy = 2 + and cs_sold_date_sk = d_date_sk + and cs_item_sk in (select item_sk from frequent_ss_items) + and cs_bill_customer_sk in (select c_customer_sk from best_ss_customer) + union all + select ws_quantity*ws_list_price sales + from web_sales + ,date_dim + where d_year = 2000 + and d_moy = 2 + and ws_sold_date_sk = d_date_sk + and ws_item_sk in (select item_sk from frequent_ss_items) + and ws_bill_customer_sk in (select c_customer_sk from best_ss_customer)) + limit 100; + with frequent_ss_items as + (select substr(i_item_desc,1,30) itemdesc,i_item_sk item_sk,d_date solddate,count(*) cnt + from store_sales + ,date_dim + ,item + where ss_sold_date_sk = d_date_sk + and ss_item_sk = i_item_sk + and d_year in (2000,2000 + 1,2000 + 2,2000 + 3) + group by substr(i_item_desc,1,30),i_item_sk,d_date + having count(*) >4), + max_store_sales as + (select max(csales) tpcds_cmax + from (select c_customer_sk,sum(ss_quantity*ss_sales_price) csales + from store_sales + ,customer + ,date_dim + where ss_customer_sk = c_customer_sk + and ss_sold_date_sk = d_date_sk + and d_year in (2000,2000+1,2000+2,2000+3) + group by c_customer_sk)), + best_ss_customer as + (select c_customer_sk,sum(ss_quantity*ss_sales_price) ssales + from store_sales + ,customer + where ss_customer_sk = c_customer_sk + group by c_customer_sk + having sum(ss_quantity*ss_sales_price) > (50/100.0) * (select + * + from max_store_sales)) + select c_last_name,c_first_name,sales + from (select c_last_name,c_first_name,sum(cs_quantity*cs_list_price) sales + from catalog_sales + ,customer + ,date_dim + where d_year = 2000 + and d_moy = 2 + and cs_sold_date_sk = d_date_sk + and cs_item_sk in (select item_sk from frequent_ss_items) + and cs_bill_customer_sk in (select c_customer_sk from best_ss_customer) + and cs_bill_customer_sk = c_customer_sk + group by c_last_name,c_first_name + union all + select c_last_name,c_first_name,sum(ws_quantity*ws_list_price) sales + from web_sales + ,customer + ,date_dim + where d_year = 2000 + and d_moy = 2 + and ws_sold_date_sk = d_date_sk + and ws_item_sk in (select item_sk from frequent_ss_items) + and ws_bill_customer_sk in (select c_customer_sk from best_ss_customer) + and ws_bill_customer_sk = c_customer_sk + group by c_last_name,c_first_name) + order by c_last_name,c_first_name,sales + limit 100 diff --git a/src/main/resources/tpcds/query24.sql b/src/main/resources/tpcds/query24.sql new file mode 100644 index 0000000000..46eb60affb --- /dev/null +++ b/src/main/resources/tpcds/query24.sql @@ -0,0 +1,104 @@ +with ssales as +(select c_last_name + ,c_first_name + ,s_store_name + ,ca_state + ,s_state + ,i_color + ,i_current_price + ,i_manager_id + ,i_units + ,i_size + ,sum(ss_net_paid) netpaid +from store_sales + ,store_returns + ,store + ,item + ,customer + ,customer_address +where ss_ticket_number = sr_ticket_number + and ss_item_sk = sr_item_sk + and ss_customer_sk = c_customer_sk + and ss_item_sk = i_item_sk + and ss_store_sk = s_store_sk + and c_current_addr_sk = ca_address_sk + and c_birth_country <> upper(ca_country) + and s_zip = ca_zip +and s_market_id=8 +group by c_last_name + ,c_first_name + ,s_store_name + ,ca_state + ,s_state + ,i_color + ,i_current_price + ,i_manager_id + ,i_units + ,i_size) +select c_last_name + ,c_first_name + ,s_store_name + ,sum(netpaid) paid +from ssales +where i_color = 'pale' +group by c_last_name + ,c_first_name + ,s_store_name +having sum(netpaid) > (select 0.05*avg(netpaid) + from ssales) +order by c_last_name + ,c_first_name + ,s_store_name +; +with ssales as +(select c_last_name + ,c_first_name + ,s_store_name + ,ca_state + ,s_state + ,i_color + ,i_current_price + ,i_manager_id + ,i_units + ,i_size + ,sum(ss_net_paid) netpaid +from store_sales + ,store_returns + ,store + ,item + ,customer + ,customer_address +where ss_ticket_number = sr_ticket_number + and ss_item_sk = sr_item_sk + and ss_customer_sk = c_customer_sk + and ss_item_sk = i_item_sk + and ss_store_sk = s_store_sk + and c_current_addr_sk = ca_address_sk + and c_birth_country <> upper(ca_country) + and s_zip = ca_zip + and s_market_id = 8 +group by c_last_name + ,c_first_name + ,s_store_name + ,ca_state + ,s_state + ,i_color + ,i_current_price + ,i_manager_id + ,i_units + ,i_size) +select c_last_name + ,c_first_name + ,s_store_name + ,sum(netpaid) paid +from ssales +where i_color = 'chiffon' +group by c_last_name + ,c_first_name + ,s_store_name +having sum(netpaid) > (select 0.05*avg(netpaid) + from ssales) +order by c_last_name + ,c_first_name + ,s_store_name + diff --git a/src/main/resources/tpcds/query25.sql b/src/main/resources/tpcds/query25.sql new file mode 100644 index 0000000000..f075f0f185 --- /dev/null +++ b/src/main/resources/tpcds/query25.sql @@ -0,0 +1,45 @@ +select + i_item_id + ,i_item_desc + ,s_store_id + ,s_store_name + ,sum(ss_net_profit) as store_sales_profit + ,sum(sr_net_loss) as store_returns_loss + ,sum(cs_net_profit) as catalog_sales_profit + from + store_sales + ,store_returns + ,catalog_sales + ,date_dim d1 + ,date_dim d2 + ,date_dim d3 + ,store + ,item + where + d1.d_moy = 4 + and d1.d_year = 2001 + and d1.d_date_sk = ss_sold_date_sk + and i_item_sk = ss_item_sk + and s_store_sk = ss_store_sk + and ss_customer_sk = sr_customer_sk + and ss_item_sk = sr_item_sk + and ss_ticket_number = sr_ticket_number + and sr_returned_date_sk = d2.d_date_sk + and d2.d_moy between 4 and 10 + and d2.d_year = 2001 + and sr_customer_sk = cs_bill_customer_sk + and sr_item_sk = cs_item_sk + and cs_sold_date_sk = d3.d_date_sk + and d3.d_moy between 4 and 10 + and d3.d_year = 2001 + group by + i_item_id + ,i_item_desc + ,s_store_id + ,s_store_name + order by + i_item_id + ,i_item_desc + ,s_store_id + ,s_store_name + limit 100 diff --git a/src/main/resources/tpcds/query26.sql b/src/main/resources/tpcds/query26.sql new file mode 100644 index 0000000000..038562973f --- /dev/null +++ b/src/main/resources/tpcds/query26.sql @@ -0,0 +1,18 @@ +select i_item_id, + avg(cs_quantity) agg1, + avg(cs_list_price) agg2, + avg(cs_coupon_amt) agg3, + avg(cs_sales_price) agg4 + from catalog_sales, customer_demographics, date_dim, item, promotion + where cs_sold_date_sk = d_date_sk and + cs_item_sk = i_item_sk and + cs_bill_cdemo_sk = cd_demo_sk and + cs_promo_sk = p_promo_sk and + cd_gender = 'M' and + cd_marital_status = 'S' and + cd_education_status = 'College' and + (p_channel_email = 'N' or p_channel_event = 'N') and + d_year = 2000 + group by i_item_id + order by i_item_id + limit 100 diff --git a/src/main/resources/tpcds/query27.sql b/src/main/resources/tpcds/query27.sql new file mode 100644 index 0000000000..44699ccb6d --- /dev/null +++ b/src/main/resources/tpcds/query27.sql @@ -0,0 +1,20 @@ +select i_item_id, + s_state, grouping(s_state) g_state, + avg(ss_quantity) agg1, + avg(ss_list_price) agg2, + avg(ss_coupon_amt) agg3, + avg(ss_sales_price) agg4 + from store_sales, customer_demographics, date_dim, store, item + where ss_sold_date_sk = d_date_sk and + ss_item_sk = i_item_sk and + ss_store_sk = s_store_sk and + ss_cdemo_sk = cd_demo_sk and + cd_gender = 'M' and + cd_marital_status = 'S' and + cd_education_status = 'College' and + d_year = 2002 and + s_state in ('TN','TN', 'TN', 'TN', 'TN', 'TN') + group by rollup (i_item_id, s_state) + order by i_item_id + ,s_state + limit 100 diff --git a/src/main/resources/tpcds/query28.sql b/src/main/resources/tpcds/query28.sql new file mode 100644 index 0000000000..0985f943b7 --- /dev/null +++ b/src/main/resources/tpcds/query28.sql @@ -0,0 +1,50 @@ +select * +from (select avg(ss_list_price) B1_LP + ,count(ss_list_price) B1_CNT + ,count(distinct ss_list_price) B1_CNTD + from store_sales + where ss_quantity between 0 and 5 + and (ss_list_price between 8 and 8+10 + or ss_coupon_amt between 459 and 459+1000 + or ss_wholesale_cost between 57 and 57+20)) B1, + (select avg(ss_list_price) B2_LP + ,count(ss_list_price) B2_CNT + ,count(distinct ss_list_price) B2_CNTD + from store_sales + where ss_quantity between 6 and 10 + and (ss_list_price between 90 and 90+10 + or ss_coupon_amt between 2323 and 2323+1000 + or ss_wholesale_cost between 31 and 31+20)) B2, + (select avg(ss_list_price) B3_LP + ,count(ss_list_price) B3_CNT + ,count(distinct ss_list_price) B3_CNTD + from store_sales + where ss_quantity between 11 and 15 + and (ss_list_price between 142 and 142+10 + or ss_coupon_amt between 12214 and 12214+1000 + or ss_wholesale_cost between 79 and 79+20)) B3, + (select avg(ss_list_price) B4_LP + ,count(ss_list_price) B4_CNT + ,count(distinct ss_list_price) B4_CNTD + from store_sales + where ss_quantity between 16 and 20 + and (ss_list_price between 135 and 135+10 + or ss_coupon_amt between 6071 and 6071+1000 + or ss_wholesale_cost between 38 and 38+20)) B4, + (select avg(ss_list_price) B5_LP + ,count(ss_list_price) B5_CNT + ,count(distinct ss_list_price) B5_CNTD + from store_sales + where ss_quantity between 21 and 25 + and (ss_list_price between 122 and 122+10 + or ss_coupon_amt between 836 and 836+1000 + or ss_wholesale_cost between 17 and 17+20)) B5, + (select avg(ss_list_price) B6_LP + ,count(ss_list_price) B6_CNT + ,count(distinct ss_list_price) B6_CNTD + from store_sales + where ss_quantity between 26 and 30 + and (ss_list_price between 154 and 154+10 + or ss_coupon_amt between 7326 and 7326+1000 + or ss_wholesale_cost between 7 and 7+20)) B6 + limit 100 diff --git a/src/main/resources/tpcds/query29.sql b/src/main/resources/tpcds/query29.sql new file mode 100644 index 0000000000..48d2cd27d9 --- /dev/null +++ b/src/main/resources/tpcds/query29.sql @@ -0,0 +1,44 @@ +select + i_item_id + ,i_item_desc + ,s_store_id + ,s_store_name + ,sum(ss_quantity) as store_sales_quantity + ,sum(sr_return_quantity) as store_returns_quantity + ,sum(cs_quantity) as catalog_sales_quantity + from + store_sales + ,store_returns + ,catalog_sales + ,date_dim d1 + ,date_dim d2 + ,date_dim d3 + ,store + ,item + where + d1.d_moy = 9 + and d1.d_year = 1999 + and d1.d_date_sk = ss_sold_date_sk + and i_item_sk = ss_item_sk + and s_store_sk = ss_store_sk + and ss_customer_sk = sr_customer_sk + and ss_item_sk = sr_item_sk + and ss_ticket_number = sr_ticket_number + and sr_returned_date_sk = d2.d_date_sk + and d2.d_moy between 9 and 9 + 3 + and d2.d_year = 1999 + and sr_customer_sk = cs_bill_customer_sk + and sr_item_sk = cs_item_sk + and cs_sold_date_sk = d3.d_date_sk + and d3.d_year in (1999,1999+1,1999+2) + group by + i_item_id + ,i_item_desc + ,s_store_id + ,s_store_name + order by + i_item_id + ,i_item_desc + ,s_store_id + ,s_store_name + limit 100 diff --git a/src/main/resources/tpcds/query30.sql b/src/main/resources/tpcds/query30.sql new file mode 100644 index 0000000000..fca4057b8f --- /dev/null +++ b/src/main/resources/tpcds/query30.sql @@ -0,0 +1,28 @@ +with customer_total_return as + (select wr_returning_customer_sk as ctr_customer_sk + ,ca_state as ctr_state, + sum(wr_return_amt) as ctr_total_return + from web_returns + ,date_dim + ,customer_address + where wr_returned_date_sk = d_date_sk + and d_year =2002 + and wr_returning_addr_sk = ca_address_sk + group by wr_returning_customer_sk + ,ca_state) + select c_customer_id,c_salutation,c_first_name,c_last_name,c_preferred_cust_flag + ,c_birth_day,c_birth_month,c_birth_year,c_birth_country,c_login,c_email_address + ,c_last_review_date,ctr_total_return + from customer_total_return ctr1 + ,customer_address + ,customer + where ctr1.ctr_total_return > (select avg(ctr_total_return)*1.2 + from customer_total_return ctr2 + where ctr1.ctr_state = ctr2.ctr_state) + and ca_address_sk = c_current_addr_sk + and ca_state = 'GA' + and ctr1.ctr_customer_sk = c_customer_sk + order by c_customer_id,c_salutation,c_first_name,c_last_name,c_preferred_cust_flag + ,c_birth_day,c_birth_month,c_birth_year,c_birth_country,c_login,c_email_address + ,c_last_review_date,ctr_total_return + limit 100 diff --git a/src/main/resources/tpcds/query31.sql b/src/main/resources/tpcds/query31.sql new file mode 100644 index 0000000000..74e49a5e39 --- /dev/null +++ b/src/main/resources/tpcds/query31.sql @@ -0,0 +1,49 @@ +with ss as + (select ca_county,d_qoy, d_year,sum(ss_ext_sales_price) as store_sales + from store_sales,date_dim,customer_address + where ss_sold_date_sk = d_date_sk + and ss_addr_sk=ca_address_sk + group by ca_county,d_qoy, d_year), + ws as + (select ca_county,d_qoy, d_year,sum(ws_ext_sales_price) as web_sales + from web_sales,date_dim,customer_address + where ws_sold_date_sk = d_date_sk + and ws_bill_addr_sk=ca_address_sk + group by ca_county,d_qoy, d_year) + select + ss1.ca_county + ,ss1.d_year + ,ws2.web_sales/ws1.web_sales web_q1_q2_increase + ,ss2.store_sales/ss1.store_sales store_q1_q2_increase + ,ws3.web_sales/ws2.web_sales web_q2_q3_increase + ,ss3.store_sales/ss2.store_sales store_q2_q3_increase + from + ss ss1 + ,ss ss2 + ,ss ss3 + ,ws ws1 + ,ws ws2 + ,ws ws3 + where + ss1.d_qoy = 1 + and ss1.d_year = 2000 + and ss1.ca_county = ss2.ca_county + and ss2.d_qoy = 2 + and ss2.d_year = 2000 + and ss2.ca_county = ss3.ca_county + and ss3.d_qoy = 3 + and ss3.d_year = 2000 + and ss1.ca_county = ws1.ca_county + and ws1.d_qoy = 1 + and ws1.d_year = 2000 + and ws1.ca_county = ws2.ca_county + and ws2.d_qoy = 2 + and ws2.d_year = 2000 + and ws1.ca_county = ws3.ca_county + and ws3.d_qoy = 3 + and ws3.d_year =2000 + and case when ws1.web_sales > 0 then ws2.web_sales/ws1.web_sales else null end + > case when ss1.store_sales > 0 then ss2.store_sales/ss1.store_sales else null end + and case when ws2.web_sales > 0 then ws3.web_sales/ws2.web_sales else null end + > case when ss2.store_sales > 0 then ss3.store_sales/ss2.store_sales else null end + order by ss1.ca_county diff --git a/src/main/resources/tpcds/query32.sql b/src/main/resources/tpcds/query32.sql new file mode 100644 index 0000000000..ca4cd153fb --- /dev/null +++ b/src/main/resources/tpcds/query32.sql @@ -0,0 +1,25 @@ +select sum(cs_ext_discount_amt) as excess_discount_amount +from + catalog_sales + ,item + ,date_dim +where +i_manufact_id = 977 +and i_item_sk = cs_item_sk +and d_date between '2000-01-27' and + date_add(cast('2000-01-27' as date), 90 ) +and d_date_sk = cs_sold_date_sk +and cs_ext_discount_amt + > ( + select + 1.3 * avg(cs_ext_discount_amt) + from + catalog_sales + ,date_dim + where + cs_item_sk = i_item_sk + and d_date between '2000-01-27' and + date_add(cast('2000-01-27' as date), 90 ) + and d_date_sk = cs_sold_date_sk + ) + limit 100 diff --git a/src/main/resources/tpcds/query33.sql b/src/main/resources/tpcds/query33.sql new file mode 100644 index 0000000000..53df422a1f --- /dev/null +++ b/src/main/resources/tpcds/query33.sql @@ -0,0 +1,72 @@ +with ss as ( + select + i_manufact_id,sum(ss_ext_sales_price) total_sales + from + store_sales, + date_dim, + customer_address, + item + where + i_manufact_id in (select + i_manufact_id +from + item +where i_category in ('Electronics')) + and ss_item_sk = i_item_sk + and ss_sold_date_sk = d_date_sk + and d_year = 1998 + and d_moy = 5 + and ss_addr_sk = ca_address_sk + and ca_gmt_offset = -5 + group by i_manufact_id), + cs as ( + select + i_manufact_id,sum(cs_ext_sales_price) total_sales + from + catalog_sales, + date_dim, + customer_address, + item + where + i_manufact_id in (select + i_manufact_id +from + item +where i_category in ('Electronics')) + and cs_item_sk = i_item_sk + and cs_sold_date_sk = d_date_sk + and d_year = 1998 + and d_moy = 5 + and cs_bill_addr_sk = ca_address_sk + and ca_gmt_offset = -5 + group by i_manufact_id), + ws as ( + select + i_manufact_id,sum(ws_ext_sales_price) total_sales + from + web_sales, + date_dim, + customer_address, + item + where + i_manufact_id in (select + i_manufact_id +from + item +where i_category in ('Electronics')) + and ws_item_sk = i_item_sk + and ws_sold_date_sk = d_date_sk + and d_year = 1998 + and d_moy = 5 + and ws_bill_addr_sk = ca_address_sk + and ca_gmt_offset = -5 + group by i_manufact_id) + select i_manufact_id ,sum(total_sales) total_sales + from (select * from ss + union all + select * from cs + union all + select * from ws) tmp1 + group by i_manufact_id + order by total_sales + limit 100 diff --git a/src/main/resources/tpcds/query34.sql b/src/main/resources/tpcds/query34.sql new file mode 100644 index 0000000000..b2cf22d732 --- /dev/null +++ b/src/main/resources/tpcds/query34.sql @@ -0,0 +1,28 @@ +select c_last_name + ,c_first_name + ,c_salutation + ,c_preferred_cust_flag + ,ss_ticket_number + ,cnt from + (select ss_ticket_number + ,ss_customer_sk + ,count(*) cnt + from store_sales,date_dim,store,household_demographics + where store_sales.ss_sold_date_sk = date_dim.d_date_sk + and store_sales.ss_store_sk = store.s_store_sk + and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk + and (date_dim.d_dom between 1 and 3 or date_dim.d_dom between 25 and 28) + and (household_demographics.hd_buy_potential = '>10000' or + household_demographics.hd_buy_potential = 'Unknown') + and household_demographics.hd_vehicle_count > 0 + and (case when household_demographics.hd_vehicle_count > 0 + then household_demographics.hd_dep_count/ household_demographics.hd_vehicle_count + else null + end) > 1.2 + and date_dim.d_year in (1999,1999+1,1999+2) + and store.s_county in ('Williamson County','Williamson County','Williamson County','Williamson County', + 'Williamson County','Williamson County','Williamson County','Williamson County') + group by ss_ticket_number,ss_customer_sk) dn,customer + where ss_customer_sk = c_customer_sk + and cnt between 15 and 20 + order by c_last_name,c_first_name,c_salutation,c_preferred_cust_flag desc, ss_ticket_number diff --git a/src/main/resources/tpcds/query35.sql b/src/main/resources/tpcds/query35.sql new file mode 100644 index 0000000000..cc221b14ff --- /dev/null +++ b/src/main/resources/tpcds/query35.sql @@ -0,0 +1,55 @@ +select + ca_state, + cd_gender, + cd_marital_status, + cd_dep_count, + count(*) cnt1, + min(cd_dep_count), + max(cd_dep_count), + avg(cd_dep_count), + cd_dep_employed_count, + count(*) cnt2, + min(cd_dep_employed_count), + max(cd_dep_employed_count), + avg(cd_dep_employed_count), + cd_dep_college_count, + count(*) cnt3, + min(cd_dep_college_count), + max(cd_dep_college_count), + avg(cd_dep_college_count) + from + customer c,customer_address ca,customer_demographics + where + c.c_current_addr_sk = ca.ca_address_sk and + cd_demo_sk = c.c_current_cdemo_sk and + exists (select * + from store_sales,date_dim + where c.c_customer_sk = ss_customer_sk and + ss_sold_date_sk = d_date_sk and + d_year = 2002 and + d_qoy < 4) and + (exists (select * + from web_sales,date_dim + where c.c_customer_sk = ws_bill_customer_sk and + ws_sold_date_sk = d_date_sk and + d_year = 2002 and + d_qoy < 4) or + exists (select * + from catalog_sales,date_dim + where c.c_customer_sk = cs_ship_customer_sk and + cs_sold_date_sk = d_date_sk and + d_year = 2002 and + d_qoy < 4)) + group by ca_state, + cd_gender, + cd_marital_status, + cd_dep_count, + cd_dep_employed_count, + cd_dep_college_count + order by ca_state, + cd_gender, + cd_marital_status, + cd_dep_count, + cd_dep_employed_count, + cd_dep_college_count + limit 100 diff --git a/src/main/resources/tpcds/query36.sql b/src/main/resources/tpcds/query36.sql new file mode 100644 index 0000000000..1ec161c648 --- /dev/null +++ b/src/main/resources/tpcds/query36.sql @@ -0,0 +1,27 @@ +select + sum(ss_net_profit)/sum(ss_ext_sales_price) as gross_margin + ,i_category + ,i_class + ,grouping(i_category)+grouping(i_class) as lochierarchy + ,rank() over ( + partition by grouping(i_category)+grouping(i_class), + case when grouping(i_class) = 0 then i_category end + order by sum(ss_net_profit)/sum(ss_ext_sales_price) asc) as rank_within_parent + from + store_sales + ,date_dim d1 + ,item + ,store + where + d1.d_year = 2001 + and d1.d_date_sk = ss_sold_date_sk + and i_item_sk = ss_item_sk + and s_store_sk = ss_store_sk + and s_state in ('TN','TN','TN','TN', + 'TN','TN','TN','TN') + group by rollup(i_category,i_class) + order by + lochierarchy desc + ,case when lochierarchy = 0 then i_category end + ,rank_within_parent + limit 100 diff --git a/src/main/resources/tpcds/query37.sql b/src/main/resources/tpcds/query37.sql new file mode 100644 index 0000000000..c37a8cec92 --- /dev/null +++ b/src/main/resources/tpcds/query37.sql @@ -0,0 +1,14 @@ +select i_item_id + ,i_item_desc + ,i_current_price + from item, inventory, date_dim, catalog_sales + where i_current_price between 68 and 68 + 30 + and inv_item_sk = i_item_sk + and d_date_sk=inv_date_sk + and d_date between cast('2000-02-01' as date) and date_add(cast('2000-02-01' as date), 60 ) + and i_manufact_id in (677,940,694,808) + and inv_quantity_on_hand between 100 and 500 + and cs_item_sk = i_item_sk + group by i_item_id,i_item_desc,i_current_price + order by i_item_id + limit 100 diff --git a/src/main/resources/tpcds/query38.sql b/src/main/resources/tpcds/query38.sql new file mode 100644 index 0000000000..de6da3b65a --- /dev/null +++ b/src/main/resources/tpcds/query38.sql @@ -0,0 +1,20 @@ +select count(*) from ( + select distinct c_last_name, c_first_name, d_date + from store_sales, date_dim, customer + where store_sales.ss_sold_date_sk = date_dim.d_date_sk + and store_sales.ss_customer_sk = customer.c_customer_sk + and d_month_seq between 1200 and 1200 + 11 + intersect + select distinct c_last_name, c_first_name, d_date + from catalog_sales, date_dim, customer + where catalog_sales.cs_sold_date_sk = date_dim.d_date_sk + and catalog_sales.cs_bill_customer_sk = customer.c_customer_sk + and d_month_seq between 1200 and 1200 + 11 + intersect + select distinct c_last_name, c_first_name, d_date + from web_sales, date_dim, customer + where web_sales.ws_sold_date_sk = date_dim.d_date_sk + and web_sales.ws_bill_customer_sk = customer.c_customer_sk + and d_month_seq between 1200 and 1200 + 11 +) hot_cust + limit 100 diff --git a/src/main/resources/tpcds/query39.sql b/src/main/resources/tpcds/query39.sql new file mode 100644 index 0000000000..e6f1d525b1 --- /dev/null +++ b/src/main/resources/tpcds/query39.sql @@ -0,0 +1,50 @@ +with inv as +(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy + ,stdev,mean, case mean when 0 then null else stdev/mean end cov + from(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy + ,stddev_samp(inv_quantity_on_hand) stdev,avg(inv_quantity_on_hand) mean + from inventory + ,item + ,warehouse + ,date_dim + where inv_item_sk = i_item_sk + and inv_warehouse_sk = w_warehouse_sk + and inv_date_sk = d_date_sk + and d_year =2001 + group by w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy) foo + where case mean when 0 then 0 else stdev/mean end > 1) +select inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean, inv1.cov + ,inv2.w_warehouse_sk as w_warehouse_sk_2,inv2.i_item_sk as i_item_sk_2,inv2.d_moy as d_moy_2,inv2.mean as mean_2, inv2.cov as cov_2 +from inv inv1,inv inv2 +where inv1.i_item_sk = inv2.i_item_sk + and inv1.w_warehouse_sk = inv2.w_warehouse_sk + and inv1.d_moy=1 + and inv2.d_moy=1+1 +order by inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean,inv1.cov + ,d_moy_2,mean_2, cov_2 +; +with inv as +(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy + ,stdev,mean, case mean when 0 then null else stdev/mean end cov + from(select w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy + ,stddev_samp(inv_quantity_on_hand) stdev,avg(inv_quantity_on_hand) mean + from inventory + ,item + ,warehouse + ,date_dim + where inv_item_sk = i_item_sk + and inv_warehouse_sk = w_warehouse_sk + and inv_date_sk = d_date_sk + and d_year =2001 + group by w_warehouse_name,w_warehouse_sk,i_item_sk,d_moy) foo + where case mean when 0 then 0 else stdev/mean end > 1) +select inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean, inv1.cov + ,inv2.w_warehouse_sk as w_warehouse_sk_2,inv2.i_item_sk as i_item_sk_2,inv2.d_moy as d_moy_2,inv2.mean as mean_2, inv2.cov as cov_2 +from inv inv1,inv inv2 +where inv1.i_item_sk = inv2.i_item_sk + and inv1.w_warehouse_sk = inv2.w_warehouse_sk + and inv1.d_moy=1 + and inv2.d_moy=1+1 + and inv1.cov > 1.5 +order by inv1.w_warehouse_sk,inv1.i_item_sk,inv1.d_moy,inv1.mean,inv1.cov + ,d_moy_2,mean_2, cov_2 diff --git a/src/main/resources/tpcds/query40.sql b/src/main/resources/tpcds/query40.sql new file mode 100644 index 0000000000..53a4e3e545 --- /dev/null +++ b/src/main/resources/tpcds/query40.sql @@ -0,0 +1,25 @@ +select + w_state + ,i_item_id + ,sum(case when (cast(d_date as date) < cast ('2000-03-11' as date)) + then cs_sales_price - coalesce(cr_refunded_cash,0) else 0 end) as sales_before + ,sum(case when (cast(d_date as date) >= cast ('2000-03-11' as date)) + then cs_sales_price - coalesce(cr_refunded_cash,0) else 0 end) as sales_after + from + catalog_sales left outer join catalog_returns on + (cs_order_number = cr_order_number + and cs_item_sk = cr_item_sk) + ,warehouse + ,item + ,date_dim + where + i_current_price between 0.99 and 1.49 + and i_item_sk = cs_item_sk + and cs_warehouse_sk = w_warehouse_sk + and cs_sold_date_sk = d_date_sk + and d_date between date_sub(cast ('2000-03-11' as date), 30 ) + and date_add(cast ('2000-03-11' as date), 30 ) + group by + w_state,i_item_id + order by w_state,i_item_id + limit 100 diff --git a/src/main/resources/tpcds/query41.sql b/src/main/resources/tpcds/query41.sql new file mode 100644 index 0000000000..dca19eafaa --- /dev/null +++ b/src/main/resources/tpcds/query41.sql @@ -0,0 +1,49 @@ +select distinct(i_product_name) + from item i1 + where i_manufact_id between 738 and 738+40 + and (select count(*) as item_cnt + from item + where (i_manufact = i1.i_manufact and + ((i_category = 'Women' and + (i_color = 'powder' or i_color = 'khaki') and + (i_units = 'Ounce' or i_units = 'Oz') and + (i_size = 'medium' or i_size = 'extra large') + ) or + (i_category = 'Women' and + (i_color = 'brown' or i_color = 'honeydew') and + (i_units = 'Bunch' or i_units = 'Ton') and + (i_size = 'N/A' or i_size = 'small') + ) or + (i_category = 'Men' and + (i_color = 'floral' or i_color = 'deep') and + (i_units = 'N/A' or i_units = 'Dozen') and + (i_size = 'petite' or i_size = 'large') + ) or + (i_category = 'Men' and + (i_color = 'light' or i_color = 'cornflower') and + (i_units = 'Box' or i_units = 'Pound') and + (i_size = 'medium' or i_size = 'extra large') + ))) or + (i_manufact = i1.i_manufact and + ((i_category = 'Women' and + (i_color = 'midnight' or i_color = 'snow') and + (i_units = 'Pallet' or i_units = 'Gross') and + (i_size = 'medium' or i_size = 'extra large') + ) or + (i_category = 'Women' and + (i_color = 'cyan' or i_color = 'papaya') and + (i_units = 'Cup' or i_units = 'Dram') and + (i_size = 'N/A' or i_size = 'small') + ) or + (i_category = 'Men' and + (i_color = 'orange' or i_color = 'frosted') and + (i_units = 'Each' or i_units = 'Tbl') and + (i_size = 'petite' or i_size = 'large') + ) or + (i_category = 'Men' and + (i_color = 'forest' or i_color = 'ghost') and + (i_units = 'Lb' or i_units = 'Bundle') and + (i_size = 'medium' or i_size = 'extra large') + )))) > 0 + order by i_product_name + limit 100 diff --git a/src/main/resources/tpcds/query42.sql b/src/main/resources/tpcds/query42.sql new file mode 100644 index 0000000000..f95f132e26 --- /dev/null +++ b/src/main/resources/tpcds/query42.sql @@ -0,0 +1,19 @@ +select dt.d_year + ,item.i_category_id + ,item.i_category + ,sum(ss_ext_sales_price) + from date_dim dt + ,store_sales + ,item + where dt.d_date_sk = store_sales.ss_sold_date_sk + and store_sales.ss_item_sk = item.i_item_sk + and item.i_manager_id = 1 + and dt.d_moy=11 + and dt.d_year=2000 + group by dt.d_year + ,item.i_category_id + ,item.i_category + order by sum(ss_ext_sales_price) desc,dt.d_year + ,item.i_category_id + ,item.i_category + limit 100 diff --git a/src/main/resources/tpcds/query43.sql b/src/main/resources/tpcds/query43.sql new file mode 100644 index 0000000000..2be9e4a859 --- /dev/null +++ b/src/main/resources/tpcds/query43.sql @@ -0,0 +1,16 @@ +select s_store_name, s_store_id, + sum(case when (d_day_name='Sunday') then ss_sales_price else null end) sun_sales, + sum(case when (d_day_name='Monday') then ss_sales_price else null end) mon_sales, + sum(case when (d_day_name='Tuesday') then ss_sales_price else null end) tue_sales, + sum(case when (d_day_name='Wednesday') then ss_sales_price else null end) wed_sales, + sum(case when (d_day_name='Thursday') then ss_sales_price else null end) thu_sales, + sum(case when (d_day_name='Friday') then ss_sales_price else null end) fri_sales, + sum(case when (d_day_name='Saturday') then ss_sales_price else null end) sat_sales + from date_dim, store_sales, store + where d_date_sk = ss_sold_date_sk and + s_store_sk = ss_store_sk and + s_gmt_offset = -5 and + d_year = 2000 + group by s_store_name, s_store_id + order by s_store_name, s_store_id,sun_sales,mon_sales,tue_sales,wed_sales,thu_sales,fri_sales,sat_sales + limit 100 diff --git a/src/main/resources/tpcds/query44.sql b/src/main/resources/tpcds/query44.sql new file mode 100644 index 0000000000..294e4bc584 --- /dev/null +++ b/src/main/resources/tpcds/query44.sql @@ -0,0 +1,32 @@ +select asceding.rnk, i1.i_product_name best_performing, i2.i_product_name worst_performing +from(select * + from (select item_sk,rank() over (order by rank_col asc) rnk + from (select ss_item_sk item_sk,avg(ss_net_profit) rank_col + from store_sales ss1 + where ss_store_sk = 4 + group by ss_item_sk + having avg(ss_net_profit) > 0.9*(select avg(ss_net_profit) rank_col + from store_sales + where ss_store_sk = 4 + and ss_addr_sk is null + group by ss_store_sk))V1)V11 + where rnk < 11) asceding, + (select * + from (select item_sk,rank() over (order by rank_col desc) rnk + from (select ss_item_sk item_sk,avg(ss_net_profit) rank_col + from store_sales ss1 + where ss_store_sk = 4 + group by ss_item_sk + having avg(ss_net_profit) > 0.9*(select avg(ss_net_profit) rank_col + from store_sales + where ss_store_sk = 4 + and ss_addr_sk is null + group by ss_store_sk))V2)V21 + where rnk < 11) descending, +item i1, +item i2 +where asceding.rnk = descending.rnk + and i1.i_item_sk=asceding.item_sk + and i2.i_item_sk=descending.item_sk +order by asceding.rnk + limit 100 diff --git a/src/main/resources/tpcds/query45.sql b/src/main/resources/tpcds/query45.sql new file mode 100644 index 0000000000..29d3da4ffc --- /dev/null +++ b/src/main/resources/tpcds/query45.sql @@ -0,0 +1,17 @@ +select ca_zip, ca_city, sum(ws_sales_price) + from web_sales, customer, customer_address, date_dim, item + where ws_bill_customer_sk = c_customer_sk + and c_current_addr_sk = ca_address_sk + and ws_item_sk = i_item_sk + and ( substr(ca_zip,1,5) in ('85669', '86197','88274','83405','86475', '85392', '85460', '80348', '81792') + or + i_item_id in (select i_item_id + from item + where i_item_sk in (2, 3, 5, 7, 11, 13, 17, 19, 23, 29) + ) + ) + and ws_sold_date_sk = d_date_sk + and d_qoy = 2 and d_year = 2001 + group by ca_zip, ca_city + order by ca_zip, ca_city + limit 100 diff --git a/src/main/resources/tpcds/query46.sql b/src/main/resources/tpcds/query46.sql new file mode 100644 index 0000000000..244619d80b --- /dev/null +++ b/src/main/resources/tpcds/query46.sql @@ -0,0 +1,32 @@ +select c_last_name + ,c_first_name + ,ca_city + ,bought_city + ,ss_ticket_number + ,amt,profit + from + (select ss_ticket_number + ,ss_customer_sk + ,ca_city bought_city + ,sum(ss_coupon_amt) amt + ,sum(ss_net_profit) profit + from store_sales,date_dim,store,household_demographics,customer_address + where store_sales.ss_sold_date_sk = date_dim.d_date_sk + and store_sales.ss_store_sk = store.s_store_sk + and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk + and store_sales.ss_addr_sk = customer_address.ca_address_sk + and (household_demographics.hd_dep_count = 4 or + household_demographics.hd_vehicle_count= 3) + and date_dim.d_dow in (6,0) + and date_dim.d_year in (1999,1999+1,1999+2) + and store.s_city in ('Fairview','Midway','Fairview','Fairview','Fairview') + group by ss_ticket_number,ss_customer_sk,ss_addr_sk,ca_city) dn,customer,customer_address current_addr + where ss_customer_sk = c_customer_sk + and customer.c_current_addr_sk = current_addr.ca_address_sk + and current_addr.ca_city <> bought_city + order by c_last_name + ,c_first_name + ,ca_city + ,bought_city + ,ss_ticket_number + limit 100 diff --git a/src/main/resources/tpcds/query47.sql b/src/main/resources/tpcds/query47.sql new file mode 100644 index 0000000000..811107396b --- /dev/null +++ b/src/main/resources/tpcds/query47.sql @@ -0,0 +1,48 @@ +with v1 as( + select i_category, i_brand, + s_store_name, s_company_name, + d_year, d_moy, + sum(ss_sales_price) sum_sales, + avg(sum(ss_sales_price)) over + (partition by i_category, i_brand, + s_store_name, s_company_name, d_year) + avg_monthly_sales, + rank() over + (partition by i_category, i_brand, + s_store_name, s_company_name + order by d_year, d_moy) rn + from item, store_sales, date_dim, store + where ss_item_sk = i_item_sk and + ss_sold_date_sk = d_date_sk and + ss_store_sk = s_store_sk and + ( + d_year = 1999 or + ( d_year = 1999-1 and d_moy =12) or + ( d_year = 1999+1 and d_moy =1) + ) + group by i_category, i_brand, + s_store_name, s_company_name, + d_year, d_moy), + v2 as( + select v1.i_category, v1.i_brand, v1.s_store_name, v1.s_company_name + ,v1.d_year, v1.d_moy + ,v1.avg_monthly_sales + ,v1.sum_sales, v1_lag.sum_sales psum, v1_lead.sum_sales nsum + from v1, v1 v1_lag, v1 v1_lead + where v1.i_category = v1_lag.i_category and + v1.i_category = v1_lead.i_category and + v1.i_brand = v1_lag.i_brand and + v1.i_brand = v1_lead.i_brand and + v1.s_store_name = v1_lag.s_store_name and + v1.s_store_name = v1_lead.s_store_name and + v1.s_company_name = v1_lag.s_company_name and + v1.s_company_name = v1_lead.s_company_name and + v1.rn = v1_lag.rn + 1 and + v1.rn = v1_lead.rn - 1) + select * + from v2 + where d_year = 1999 and + avg_monthly_sales > 0 and + case when avg_monthly_sales > 0 then abs(sum_sales - avg_monthly_sales) / avg_monthly_sales else null end > 0.1 + order by sum_sales - avg_monthly_sales, 3 + limit 100 diff --git a/src/main/resources/tpcds/query48.sql b/src/main/resources/tpcds/query48.sql new file mode 100644 index 0000000000..91f5015515 --- /dev/null +++ b/src/main/resources/tpcds/query48.sql @@ -0,0 +1,64 @@ +select sum (ss_quantity) + from store_sales, store, customer_demographics, customer_address, date_dim + where s_store_sk = ss_store_sk + and ss_sold_date_sk = d_date_sk and d_year = 2000 + and + ( + ( + cd_demo_sk = ss_cdemo_sk + and + cd_marital_status = 'M' + and + cd_education_status = '4 yr Degree' + and + ss_sales_price between 100.00 and 150.00 + ) + or + ( + cd_demo_sk = ss_cdemo_sk + and + cd_marital_status = 'D' + and + cd_education_status = '2 yr Degree' + and + ss_sales_price between 50.00 and 100.00 + ) + or + ( + cd_demo_sk = ss_cdemo_sk + and + cd_marital_status = 'S' + and + cd_education_status = 'College' + and + ss_sales_price between 150.00 and 200.00 + ) + ) + and + ( + ( + ss_addr_sk = ca_address_sk + and + ca_country = 'United States' + and + ca_state in ('CO', 'OH', 'TX') + and ss_net_profit between 0 and 2000 + ) + or + (ss_addr_sk = ca_address_sk + and + ca_country = 'United States' + and + ca_state in ('OR', 'MN', 'KY') + and ss_net_profit between 150 and 3000 + ) + or + (ss_addr_sk = ca_address_sk + and + ca_country = 'United States' + and + ca_state in ('VA', 'CA', 'MS') + and ss_net_profit between 50 and 25000 + ) + ) + diff --git a/src/main/resources/tpcds/query49.sql b/src/main/resources/tpcds/query49.sql new file mode 100644 index 0000000000..63f71cab7f --- /dev/null +++ b/src/main/resources/tpcds/query49.sql @@ -0,0 +1,124 @@ +select + 'web' as channel + ,web.item + ,web.return_ratio + ,web.return_rank + ,web.currency_rank + from ( + select + item + ,return_ratio + ,currency_ratio + ,rank() over (order by return_ratio) as return_rank + ,rank() over (order by currency_ratio) as currency_rank + from + ( select ws.ws_item_sk as item + ,(cast(sum(coalesce(wr.wr_return_quantity,0)) as decimal(15,4))/ + cast(sum(coalesce(ws.ws_quantity,0)) as decimal(15,4) )) as return_ratio + ,(cast(sum(coalesce(wr.wr_return_amt,0)) as decimal(15,4))/ + cast(sum(coalesce(ws.ws_net_paid,0)) as decimal(15,4) )) as currency_ratio + from + web_sales ws left outer join web_returns wr + on (ws.ws_order_number = wr.wr_order_number and + ws.ws_item_sk = wr.wr_item_sk) + ,date_dim + where + wr.wr_return_amt > 10000 + and ws.ws_net_profit > 1 + and ws.ws_net_paid > 0 + and ws.ws_quantity > 0 + and ws_sold_date_sk = d_date_sk + and d_year = 2001 + and d_moy = 12 + group by ws.ws_item_sk + ) in_web + ) web + where + ( + web.return_rank <= 10 + or + web.currency_rank <= 10 + ) + union + select + 'catalog' as channel + ,catalog.item + ,catalog.return_ratio + ,catalog.return_rank + ,catalog.currency_rank + from ( + select + item + ,return_ratio + ,currency_ratio + ,rank() over (order by return_ratio) as return_rank + ,rank() over (order by currency_ratio) as currency_rank + from + ( select + cs.cs_item_sk as item + ,(cast(sum(coalesce(cr.cr_return_quantity,0)) as decimal(15,4))/ + cast(sum(coalesce(cs.cs_quantity,0)) as decimal(15,4) )) as return_ratio + ,(cast(sum(coalesce(cr.cr_return_amount,0)) as decimal(15,4))/ + cast(sum(coalesce(cs.cs_net_paid,0)) as decimal(15,4) )) as currency_ratio + from + catalog_sales cs left outer join catalog_returns cr + on (cs.cs_order_number = cr.cr_order_number and + cs.cs_item_sk = cr.cr_item_sk) + ,date_dim + where + cr.cr_return_amount > 10000 + and cs.cs_net_profit > 1 + and cs.cs_net_paid > 0 + and cs.cs_quantity > 0 + and cs_sold_date_sk = d_date_sk + and d_year = 2001 + and d_moy = 12 + group by cs.cs_item_sk + ) in_cat + ) catalog + where + ( + catalog.return_rank <= 10 + or + catalog.currency_rank <=10 + ) + union + select + 'store' as channel + ,store.item + ,store.return_ratio + ,store.return_rank + ,store.currency_rank + from ( + select + item + ,return_ratio + ,currency_ratio + ,rank() over (order by return_ratio) as return_rank + ,rank() over (order by currency_ratio) as currency_rank + from + ( select sts.ss_item_sk as item + ,(cast(sum(coalesce(sr.sr_return_quantity,0)) as decimal(15,4))/cast(sum(coalesce(sts.ss_quantity,0)) as decimal(15,4) )) as return_ratio + ,(cast(sum(coalesce(sr.sr_return_amt,0)) as decimal(15,4))/cast(sum(coalesce(sts.ss_net_paid,0)) as decimal(15,4) )) as currency_ratio + from + store_sales sts left outer join store_returns sr + on (sts.ss_ticket_number = sr.sr_ticket_number and sts.ss_item_sk = sr.sr_item_sk) + ,date_dim + where + sr.sr_return_amt > 10000 + and sts.ss_net_profit > 1 + and sts.ss_net_paid > 0 + and sts.ss_quantity > 0 + and ss_sold_date_sk = d_date_sk + and d_year = 2001 + and d_moy = 12 + group by sts.ss_item_sk + ) in_store + ) store + where ( + store.return_rank <= 10 + or + store.currency_rank <= 10 + ) + order by 1,4,5 + limit 100 diff --git a/src/main/resources/tpcds/query50.sql b/src/main/resources/tpcds/query50.sql new file mode 100644 index 0000000000..4e34de0538 --- /dev/null +++ b/src/main/resources/tpcds/query50.sql @@ -0,0 +1,56 @@ +select + s_store_name + ,s_company_id + ,s_street_number + ,s_street_name + ,s_street_type + ,s_suite_number + ,s_city + ,s_county + ,s_state + ,s_zip + ,sum(case when (sr_returned_date_sk - ss_sold_date_sk <= 30 ) then 1 else 0 end) as "30_days" + ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 30) and + (sr_returned_date_sk - ss_sold_date_sk <= 60) then 1 else 0 end ) as "31_60_days" + ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 60) and + (sr_returned_date_sk - ss_sold_date_sk <= 90) then 1 else 0 end) as "61_90_days" + ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 90) and + (sr_returned_date_sk - ss_sold_date_sk <= 120) then 1 else 0 end) as "91_120_days" + ,sum(case when (sr_returned_date_sk - ss_sold_date_sk > 120) then 1 else 0 end) as above120_days +from + store_sales + ,store_returns + ,store + ,date_dim d1 + ,date_dim d2 +where + d2.d_year = 2001 +and d2.d_moy = 8 +and ss_ticket_number = sr_ticket_number +and ss_item_sk = sr_item_sk +and ss_sold_date_sk = d1.d_date_sk +and sr_returned_date_sk = d2.d_date_sk +and ss_customer_sk = sr_customer_sk +and ss_store_sk = s_store_sk +group by + s_store_name + ,s_company_id + ,s_street_number + ,s_street_name + ,s_street_type + ,s_suite_number + ,s_city + ,s_county + ,s_state + ,s_zip +order by s_store_name + ,s_company_id + ,s_street_number + ,s_street_name + ,s_street_type + ,s_suite_number + ,s_city + ,s_county + ,s_state + ,s_zip + limit 100 diff --git a/src/main/resources/tpcds/query51.sql b/src/main/resources/tpcds/query51.sql new file mode 100644 index 0000000000..865c23e9b9 --- /dev/null +++ b/src/main/resources/tpcds/query51.sql @@ -0,0 +1,42 @@ +WITH web_v1 as ( +select + ws_item_sk item_sk, d_date, + sum(sum(ws_sales_price)) + over (partition by ws_item_sk order by d_date rows between unbounded preceding and current row) cume_sales +from web_sales + ,date_dim +where ws_sold_date_sk=d_date_sk + and d_month_seq between 1200 and 1200+11 + and ws_item_sk is not NULL +group by ws_item_sk, d_date), +store_v1 as ( +select + ss_item_sk item_sk, d_date, + sum(sum(ss_sales_price)) + over (partition by ss_item_sk order by d_date rows between unbounded preceding and current row) cume_sales +from store_sales + ,date_dim +where ss_sold_date_sk=d_date_sk + and d_month_seq between 1200 and 1200+11 + and ss_item_sk is not NULL +group by ss_item_sk, d_date) + select * +from (select item_sk + ,d_date + ,web_sales + ,store_sales + ,max(web_sales) + over (partition by item_sk order by d_date rows between unbounded preceding and current row) web_cumulative + ,max(store_sales) + over (partition by item_sk order by d_date rows between unbounded preceding and current row) store_cumulative + from (select case when web.item_sk is not null then web.item_sk else store.item_sk end item_sk + ,case when web.d_date is not null then web.d_date else store.d_date end d_date + ,web.cume_sales web_sales + ,store.cume_sales store_sales + from web_v1 web full outer join store_v1 store on (web.item_sk = store.item_sk + and web.d_date = store.d_date) + )x )y +where web_cumulative > store_cumulative +order by item_sk + ,d_date + limit 100 diff --git a/src/main/resources/tpcds/query52.sql b/src/main/resources/tpcds/query52.sql new file mode 100644 index 0000000000..9083f16316 --- /dev/null +++ b/src/main/resources/tpcds/query52.sql @@ -0,0 +1,19 @@ +select dt.d_year + ,item.i_brand_id brand_id + ,item.i_brand brand + ,sum(ss_ext_sales_price) ext_price + from date_dim dt + ,store_sales + ,item + where dt.d_date_sk = store_sales.ss_sold_date_sk + and store_sales.ss_item_sk = item.i_item_sk + and item.i_manager_id = 1 + and dt.d_moy=11 + and dt.d_year=2000 + group by dt.d_year + ,item.i_brand + ,item.i_brand_id + order by dt.d_year + ,ext_price desc + ,brand_id + limit 100 diff --git a/src/main/resources/tpcds/query53.sql b/src/main/resources/tpcds/query53.sql new file mode 100644 index 0000000000..b06146fada --- /dev/null +++ b/src/main/resources/tpcds/query53.sql @@ -0,0 +1,25 @@ +select * from +(select i_manufact_id, +sum(ss_sales_price) sum_sales, +avg(sum(ss_sales_price)) over (partition by i_manufact_id) avg_quarterly_sales +from item, store_sales, date_dim, store +where ss_item_sk = i_item_sk and +ss_sold_date_sk = d_date_sk and +ss_store_sk = s_store_sk and +d_month_seq in (1200,1200+1,1200+2,1200+3,1200+4,1200+5,1200+6,1200+7,1200+8,1200+9,1200+10,1200+11) and +((i_category in ('Books','Children','Electronics') and +i_class in ('personal','portable','reference','self-help') and +i_brand in ('scholaramalgamalg #14','scholaramalgamalg #7', + 'exportiunivamalg #9','scholaramalgamalg #9')) +or(i_category in ('Women','Music','Men') and +i_class in ('accessories','classical','fragrances','pants') and +i_brand in ('amalgimporto #1','edu packscholar #1','exportiimporto #1', + 'importoamalg #1'))) +group by i_manufact_id, d_qoy ) tmp1 +where case when avg_quarterly_sales > 0 + then abs (sum_sales - avg_quarterly_sales)/ avg_quarterly_sales + else null end > 0.1 +order by avg_quarterly_sales, + sum_sales, + i_manufact_id + limit 100 diff --git a/src/main/resources/tpcds/query54.sql b/src/main/resources/tpcds/query54.sql new file mode 100644 index 0000000000..f9b363d066 --- /dev/null +++ b/src/main/resources/tpcds/query54.sql @@ -0,0 +1,53 @@ +with my_customers as ( + select distinct c_customer_sk + , c_current_addr_sk + from + ( select cs_sold_date_sk sold_date_sk, + cs_bill_customer_sk customer_sk, + cs_item_sk item_sk + from catalog_sales + union all + select ws_sold_date_sk sold_date_sk, + ws_bill_customer_sk customer_sk, + ws_item_sk item_sk + from web_sales + ) cs_or_ws_sales, + item, + date_dim, + customer + where sold_date_sk = d_date_sk + and item_sk = i_item_sk + and i_category = 'Women' + and i_class = 'maternity' + and c_customer_sk = cs_or_ws_sales.customer_sk + and d_moy = 12 + and d_year = 1998 + ) + , my_revenue as ( + select c_customer_sk, + sum(ss_ext_sales_price) as revenue + from my_customers, + store_sales, + customer_address, + store, + date_dim + where c_current_addr_sk = ca_address_sk + and ca_county = s_county + and ca_state = s_state + and ss_sold_date_sk = d_date_sk + and c_customer_sk = ss_customer_sk + and d_month_seq between (select distinct d_month_seq+1 + from date_dim where d_year = 1998 and d_moy = 12) + and (select distinct d_month_seq+3 + from date_dim where d_year = 1998 and d_moy = 12) + group by c_customer_sk + ) + , segments as + (select cast((revenue/50) as int) as segment + from my_revenue + ) + select segment, count(*) as num_customers, segment*50 as segment_base + from segments + group by segment + order by segment, num_customers + limit 100 diff --git a/src/main/resources/tpcds/query55.sql b/src/main/resources/tpcds/query55.sql new file mode 100644 index 0000000000..74018ae3db --- /dev/null +++ b/src/main/resources/tpcds/query55.sql @@ -0,0 +1,11 @@ +select i_brand_id brand_id, i_brand brand, + sum(ss_ext_sales_price) ext_price + from date_dim, store_sales, item + where d_date_sk = ss_sold_date_sk + and ss_item_sk = i_item_sk + and i_manager_id=28 + and d_moy=11 + and d_year=1999 + group by i_brand, i_brand_id + order by ext_price desc, i_brand_id + limit 100 diff --git a/src/main/resources/tpcds/query56.sql b/src/main/resources/tpcds/query56.sql new file mode 100644 index 0000000000..43ce093072 --- /dev/null +++ b/src/main/resources/tpcds/query56.sql @@ -0,0 +1,65 @@ +with ss as ( + select i_item_id,sum(ss_ext_sales_price) total_sales + from + store_sales, + date_dim, + customer_address, + item + where i_item_id in (select + i_item_id +from item +where i_color in ('slate','blanched','burnished')) + and ss_item_sk = i_item_sk + and ss_sold_date_sk = d_date_sk + and d_year = 2001 + and d_moy = 2 + and ss_addr_sk = ca_address_sk + and ca_gmt_offset = -5 + group by i_item_id), + cs as ( + select i_item_id,sum(cs_ext_sales_price) total_sales + from + catalog_sales, + date_dim, + customer_address, + item + where + i_item_id in (select + i_item_id +from item +where i_color in ('slate','blanched','burnished')) + and cs_item_sk = i_item_sk + and cs_sold_date_sk = d_date_sk + and d_year = 2001 + and d_moy = 2 + and cs_bill_addr_sk = ca_address_sk + and ca_gmt_offset = -5 + group by i_item_id), + ws as ( + select i_item_id,sum(ws_ext_sales_price) total_sales + from + web_sales, + date_dim, + customer_address, + item + where + i_item_id in (select + i_item_id +from item +where i_color in ('slate','blanched','burnished')) + and ws_item_sk = i_item_sk + and ws_sold_date_sk = d_date_sk + and d_year = 2001 + and d_moy = 2 + and ws_bill_addr_sk = ca_address_sk + and ca_gmt_offset = -5 + group by i_item_id) + select i_item_id ,sum(total_sales) total_sales + from (select * from ss + union all + select * from cs + union all + select * from ws) tmp1 + group by i_item_id + order by total_sales + limit 100 diff --git a/src/main/resources/tpcds/query57.sql b/src/main/resources/tpcds/query57.sql new file mode 100644 index 0000000000..9cb2f7601e --- /dev/null +++ b/src/main/resources/tpcds/query57.sql @@ -0,0 +1,45 @@ +with v1 as( + select i_category, i_brand, + cc_name, + d_year, d_moy, + sum(cs_sales_price) sum_sales, + avg(sum(cs_sales_price)) over + (partition by i_category, i_brand, + cc_name, d_year) + avg_monthly_sales, + rank() over + (partition by i_category, i_brand, + cc_name + order by d_year, d_moy) rn + from item, catalog_sales, date_dim, call_center + where cs_item_sk = i_item_sk and + cs_sold_date_sk = d_date_sk and + cc_call_center_sk= cs_call_center_sk and + ( + d_year = 1999 or + ( d_year = 1999-1 and d_moy =12) or + ( d_year = 1999+1 and d_moy =1) + ) + group by i_category, i_brand, + cc_name , d_year, d_moy), + v2 as( + select v1.i_category, v1.i_brand, v1.cc_name + ,v1.d_year, v1.d_moy + ,v1.avg_monthly_sales + ,v1.sum_sales, v1_lag.sum_sales psum, v1_lead.sum_sales nsum + from v1, v1 v1_lag, v1 v1_lead + where v1.i_category = v1_lag.i_category and + v1.i_category = v1_lead.i_category and + v1.i_brand = v1_lag.i_brand and + v1.i_brand = v1_lead.i_brand and + v1. cc_name = v1_lag. cc_name and + v1. cc_name = v1_lead. cc_name and + v1.rn = v1_lag.rn + 1 and + v1.rn = v1_lead.rn - 1) + select * + from v2 + where d_year = 1999 and + avg_monthly_sales > 0 and + case when avg_monthly_sales > 0 then abs(sum_sales - avg_monthly_sales) / avg_monthly_sales else null end > 0.1 + order by sum_sales - avg_monthly_sales, 3 + limit 100 diff --git a/src/main/resources/tpcds/query58.sql b/src/main/resources/tpcds/query58.sql new file mode 100644 index 0000000000..05fe511390 --- /dev/null +++ b/src/main/resources/tpcds/query58.sql @@ -0,0 +1,62 @@ +with ss_items as + (select i_item_id item_id + ,sum(ss_ext_sales_price) ss_item_rev + from store_sales + ,item + ,date_dim + where ss_item_sk = i_item_sk + and d_date in (select d_date + from date_dim + where d_week_seq = (select d_week_seq + from date_dim + where d_date = '2000-01-03')) + and ss_sold_date_sk = d_date_sk + group by i_item_id), + cs_items as + (select i_item_id item_id + ,sum(cs_ext_sales_price) cs_item_rev + from catalog_sales + ,item + ,date_dim + where cs_item_sk = i_item_sk + and d_date in (select d_date + from date_dim + where d_week_seq = (select d_week_seq + from date_dim + where d_date = '2000-01-03')) + and cs_sold_date_sk = d_date_sk + group by i_item_id), + ws_items as + (select i_item_id item_id + ,sum(ws_ext_sales_price) ws_item_rev + from web_sales + ,item + ,date_dim + where ws_item_sk = i_item_sk + and d_date in (select d_date + from date_dim + where d_week_seq =(select d_week_seq + from date_dim + where d_date = '2000-01-03')) + and ws_sold_date_sk = d_date_sk + group by i_item_id) + select ss_items.item_id + ,ss_item_rev + ,ss_item_rev/((ss_item_rev+cs_item_rev+ws_item_rev)/3) * 100 ss_dev + ,cs_item_rev + ,cs_item_rev/((ss_item_rev+cs_item_rev+ws_item_rev)/3) * 100 cs_dev + ,ws_item_rev + ,ws_item_rev/((ss_item_rev+cs_item_rev+ws_item_rev)/3) * 100 ws_dev + ,(ss_item_rev+cs_item_rev+ws_item_rev)/3 average + from ss_items,cs_items,ws_items + where ss_items.item_id=cs_items.item_id + and ss_items.item_id=ws_items.item_id + and ss_item_rev between 0.9 * cs_item_rev and 1.1 * cs_item_rev + and ss_item_rev between 0.9 * ws_item_rev and 1.1 * ws_item_rev + and cs_item_rev between 0.9 * ss_item_rev and 1.1 * ss_item_rev + and cs_item_rev between 0.9 * ws_item_rev and 1.1 * ws_item_rev + and ws_item_rev between 0.9 * ss_item_rev and 1.1 * ss_item_rev + and ws_item_rev between 0.9 * cs_item_rev and 1.1 * cs_item_rev + order by item_id + ,ss_item_rev + limit 100 diff --git a/src/main/resources/tpcds/query59.sql b/src/main/resources/tpcds/query59.sql new file mode 100644 index 0000000000..474d0ad3cb --- /dev/null +++ b/src/main/resources/tpcds/query59.sql @@ -0,0 +1,41 @@ +with wss as + (select d_week_seq, + ss_store_sk, + sum(case when (d_day_name='Sunday') then ss_sales_price else null end) sun_sales, + sum(case when (d_day_name='Monday') then ss_sales_price else null end) mon_sales, + sum(case when (d_day_name='Tuesday') then ss_sales_price else null end) tue_sales, + sum(case when (d_day_name='Wednesday') then ss_sales_price else null end) wed_sales, + sum(case when (d_day_name='Thursday') then ss_sales_price else null end) thu_sales, + sum(case when (d_day_name='Friday') then ss_sales_price else null end) fri_sales, + sum(case when (d_day_name='Saturday') then ss_sales_price else null end) sat_sales + from store_sales,date_dim + where d_date_sk = ss_sold_date_sk + group by d_week_seq,ss_store_sk + ) + select s_store_name1,s_store_id1,d_week_seq1 + ,sun_sales1/sun_sales2,mon_sales1/mon_sales2 + ,tue_sales1/tue_sales2,wed_sales1/wed_sales2,thu_sales1/thu_sales2 + ,fri_sales1/fri_sales2,sat_sales1/sat_sales2 + from + (select s_store_name s_store_name1,wss.d_week_seq d_week_seq1 + ,s_store_id s_store_id1,sun_sales sun_sales1 + ,mon_sales mon_sales1,tue_sales tue_sales1 + ,wed_sales wed_sales1,thu_sales thu_sales1 + ,fri_sales fri_sales1,sat_sales sat_sales1 + from wss,store,date_dim d + where d.d_week_seq = wss.d_week_seq and + ss_store_sk = s_store_sk and + d_month_seq between 1212 and 1212 + 11) y, + (select s_store_name s_store_name2,wss.d_week_seq d_week_seq2 + ,s_store_id s_store_id2,sun_sales sun_sales2 + ,mon_sales mon_sales2,tue_sales tue_sales2 + ,wed_sales wed_sales2,thu_sales thu_sales2 + ,fri_sales fri_sales2,sat_sales sat_sales2 + from wss,store,date_dim d + where d.d_week_seq = wss.d_week_seq and + ss_store_sk = s_store_sk and + d_month_seq between 1212+ 12 and 1212 + 23) x + where s_store_id1=s_store_id2 + and d_week_seq1=d_week_seq2-52 + order by s_store_name1,s_store_id1,d_week_seq1 + limit 100 diff --git a/src/main/resources/tpcds/query60.sql b/src/main/resources/tpcds/query60.sql new file mode 100644 index 0000000000..037217fb8b --- /dev/null +++ b/src/main/resources/tpcds/query60.sql @@ -0,0 +1,75 @@ +with ss as ( + select + i_item_id,sum(ss_ext_sales_price) total_sales + from + store_sales, + date_dim, + customer_address, + item + where + i_item_id in (select + i_item_id +from + item +where i_category in ('Music')) + and ss_item_sk = i_item_sk + and ss_sold_date_sk = d_date_sk + and d_year = 1998 + and d_moy = 9 + and ss_addr_sk = ca_address_sk + and ca_gmt_offset = -5 + group by i_item_id), + cs as ( + select + i_item_id,sum(cs_ext_sales_price) total_sales + from + catalog_sales, + date_dim, + customer_address, + item + where + i_item_id in (select + i_item_id +from + item +where i_category in ('Music')) + and cs_item_sk = i_item_sk + and cs_sold_date_sk = d_date_sk + and d_year = 1998 + and d_moy = 9 + and cs_bill_addr_sk = ca_address_sk + and ca_gmt_offset = -5 + group by i_item_id), + ws as ( + select + i_item_id,sum(ws_ext_sales_price) total_sales + from + web_sales, + date_dim, + customer_address, + item + where + i_item_id in (select + i_item_id +from + item +where i_category in ('Music')) + and ws_item_sk = i_item_sk + and ws_sold_date_sk = d_date_sk + and d_year = 1998 + and d_moy = 9 + and ws_bill_addr_sk = ca_address_sk + and ca_gmt_offset = -5 + group by i_item_id) + select + i_item_id +,sum(total_sales) total_sales + from (select * from ss + union all + select * from cs + union all + select * from ws) tmp1 + group by i_item_id + order by i_item_id + ,total_sales + limit 100 diff --git a/src/main/resources/tpcds/query61.sql b/src/main/resources/tpcds/query61.sql new file mode 100644 index 0000000000..51cdd177c2 --- /dev/null +++ b/src/main/resources/tpcds/query61.sql @@ -0,0 +1,41 @@ +select promotions,total,cast(promotions as decimal(15,4))/cast(total as decimal(15,4))*100 +from + (select sum(ss_ext_sales_price) promotions + from store_sales + ,store + ,promotion + ,date_dim + ,customer + ,customer_address + ,item + where ss_sold_date_sk = d_date_sk + and ss_store_sk = s_store_sk + and ss_promo_sk = p_promo_sk + and ss_customer_sk= c_customer_sk + and ca_address_sk = c_current_addr_sk + and ss_item_sk = i_item_sk + and ca_gmt_offset = -5 + and i_category = 'Jewelry' + and (p_channel_dmail = 'Y' or p_channel_email = 'Y' or p_channel_tv = 'Y') + and s_gmt_offset = -5 + and d_year = 1998 + and d_moy = 11) promotional_sales, + (select sum(ss_ext_sales_price) total + from store_sales + ,store + ,date_dim + ,customer + ,customer_address + ,item + where ss_sold_date_sk = d_date_sk + and ss_store_sk = s_store_sk + and ss_customer_sk= c_customer_sk + and ca_address_sk = c_current_addr_sk + and ss_item_sk = i_item_sk + and ca_gmt_offset = -5 + and i_category = 'Jewelry' + and s_gmt_offset = -5 + and d_year = 1998 + and d_moy = 11) all_sales +order by promotions, total + limit 100 diff --git a/src/main/resources/tpcds/query62.sql b/src/main/resources/tpcds/query62.sql new file mode 100644 index 0000000000..63d59deaed --- /dev/null +++ b/src/main/resources/tpcds/query62.sql @@ -0,0 +1,32 @@ +select + substr(w_warehouse_name,1,20) + ,sm_type + ,web_name + ,sum(case when (ws_ship_date_sk - ws_sold_date_sk <= 30 ) then 1 else 0 end) as "30_days " + ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 30) and + (ws_ship_date_sk - ws_sold_date_sk <= 60) then 1 else 0 end ) as "31_60_days " + ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 60) and + (ws_ship_date_sk - ws_sold_date_sk <= 90) then 1 else 0 end) as "61_90_days " + ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 90) and + (ws_ship_date_sk - ws_sold_date_sk <= 120) then 1 else 0 end) as "91_120_days" + ,sum(case when (ws_ship_date_sk - ws_sold_date_sk > 120) then 1 else 0 end) as above120_days +from + web_sales + ,warehouse + ,ship_mode + ,web_site + ,date_dim +where + d_month_seq between 1200 and 1200 + 11 +and ws_ship_date_sk = d_date_sk +and ws_warehouse_sk = w_warehouse_sk +and ws_ship_mode_sk = sm_ship_mode_sk +and ws_web_site_sk = web_site_sk +group by + substr(w_warehouse_name,1,20) + ,sm_type + ,web_name +order by substr(w_warehouse_name,1,20) + ,sm_type + ,web_name + limit 100 diff --git a/src/main/resources/tpcds/query63.sql b/src/main/resources/tpcds/query63.sql new file mode 100644 index 0000000000..7a5b0bdee7 --- /dev/null +++ b/src/main/resources/tpcds/query63.sql @@ -0,0 +1,26 @@ +select * +from (select i_manager_id + ,sum(ss_sales_price) sum_sales + ,avg(sum(ss_sales_price)) over (partition by i_manager_id) avg_monthly_sales + from item + ,store_sales + ,date_dim + ,store + where ss_item_sk = i_item_sk + and ss_sold_date_sk = d_date_sk + and ss_store_sk = s_store_sk + and d_month_seq in (1200,1200+1,1200+2,1200+3,1200+4,1200+5,1200+6,1200+7,1200+8,1200+9,1200+10,1200+11) + and (( i_category in ('Books','Children','Electronics') + and i_class in ('personal','portable','reference','self-help') + and i_brand in ('scholaramalgamalg #14','scholaramalgamalg #7', + 'exportiunivamalg #9','scholaramalgamalg #9')) + or( i_category in ('Women','Music','Men') + and i_class in ('accessories','classical','fragrances','pants') + and i_brand in ('amalgimporto #1','edu packscholar #1','exportiimporto #1', + 'importoamalg #1'))) +group by i_manager_id, d_moy) tmp1 +where case when avg_monthly_sales > 0 then abs (sum_sales - avg_monthly_sales) / avg_monthly_sales else null end > 0.1 +order by i_manager_id + ,avg_monthly_sales + ,sum_sales + limit 100 diff --git a/src/main/resources/tpcds/query64.sql b/src/main/resources/tpcds/query64.sql new file mode 100644 index 0000000000..3ab66c6fb1 --- /dev/null +++ b/src/main/resources/tpcds/query64.sql @@ -0,0 +1,116 @@ +with cs_ui as + (select cs_item_sk + ,sum(cs_ext_list_price) as sale,sum(cr_refunded_cash+cr_reversed_charge+cr_store_credit) as refund + from catalog_sales + ,catalog_returns + where cs_item_sk = cr_item_sk + and cs_order_number = cr_order_number + group by cs_item_sk + having sum(cs_ext_list_price)>2*sum(cr_refunded_cash+cr_reversed_charge+cr_store_credit)), +cross_sales as + (select i_product_name product_name + ,i_item_sk item_sk + ,s_store_name store_name + ,s_zip store_zip + ,ad1.ca_street_number b_street_number + ,ad1.ca_street_name b_street_name + ,ad1.ca_city b_city + ,ad1.ca_zip b_zip + ,ad2.ca_street_number c_street_number + ,ad2.ca_street_name c_street_name + ,ad2.ca_city c_city + ,ad2.ca_zip c_zip + ,d1.d_year as syear + ,d2.d_year as fsyear + ,d3.d_year s2year + ,count(*) cnt + ,sum(ss_wholesale_cost) s1 + ,sum(ss_list_price) s2 + ,sum(ss_coupon_amt) s3 + FROM store_sales + ,store_returns + ,cs_ui + ,date_dim d1 + ,date_dim d2 + ,date_dim d3 + ,store + ,customer + ,customer_demographics cd1 + ,customer_demographics cd2 + ,promotion + ,household_demographics hd1 + ,household_demographics hd2 + ,customer_address ad1 + ,customer_address ad2 + ,income_band ib1 + ,income_band ib2 + ,item + WHERE ss_store_sk = s_store_sk AND + ss_sold_date_sk = d1.d_date_sk AND + ss_customer_sk = c_customer_sk AND + ss_cdemo_sk= cd1.cd_demo_sk AND + ss_hdemo_sk = hd1.hd_demo_sk AND + ss_addr_sk = ad1.ca_address_sk and + ss_item_sk = i_item_sk and + ss_item_sk = sr_item_sk and + ss_ticket_number = sr_ticket_number and + ss_item_sk = cs_ui.cs_item_sk and + c_current_cdemo_sk = cd2.cd_demo_sk AND + c_current_hdemo_sk = hd2.hd_demo_sk AND + c_current_addr_sk = ad2.ca_address_sk and + c_first_sales_date_sk = d2.d_date_sk and + c_first_shipto_date_sk = d3.d_date_sk and + ss_promo_sk = p_promo_sk and + hd1.hd_income_band_sk = ib1.ib_income_band_sk and + hd2.hd_income_band_sk = ib2.ib_income_band_sk and + cd1.cd_marital_status <> cd2.cd_marital_status and + i_color in ('purple','burlywood','indian','spring','floral','medium') and + i_current_price between 64 and 64 + 10 and + i_current_price between 64 + 1 and 64 + 15 +group by i_product_name + ,i_item_sk + ,s_store_name + ,s_zip + ,ad1.ca_street_number + ,ad1.ca_street_name + ,ad1.ca_city + ,ad1.ca_zip + ,ad2.ca_street_number + ,ad2.ca_street_name + ,ad2.ca_city + ,ad2.ca_zip + ,d1.d_year + ,d2.d_year + ,d3.d_year +) +select cs1.product_name + ,cs1.store_name + ,cs1.store_zip + ,cs1.b_street_number + ,cs1.b_street_name + ,cs1.b_city + ,cs1.b_zip + ,cs1.c_street_number + ,cs1.c_street_name + ,cs1.c_city + ,cs1.c_zip + ,cs1.syear + ,cs1.cnt + ,cs1.s1 as s11 + ,cs1.s2 as s21 + ,cs1.s3 as s31 + ,cs2.s1 as s12 + ,cs2.s2 as s22 + ,cs2.s3 as s32 + ,cs2.syear as syear_2 + ,cs2.cnt as cnt_2 +from cross_sales cs1,cross_sales cs2 +where cs1.item_sk=cs2.item_sk and + cs1.syear = 1999 and + cs2.syear = 1999 + 1 and + cs2.cnt <= cs1.cnt and + cs1.store_name = cs2.store_name and + cs1.store_zip = cs2.store_zip +order by cs1.product_name + ,cs1.store_name + ,cnt_2 diff --git a/src/main/resources/tpcds/query65.sql b/src/main/resources/tpcds/query65.sql new file mode 100644 index 0000000000..2ad70b5941 --- /dev/null +++ b/src/main/resources/tpcds/query65.sql @@ -0,0 +1,26 @@ +select + s_store_name, + i_item_desc, + sc.revenue, + i_current_price, + i_wholesale_cost, + i_brand + from store, item, + (select ss_store_sk, avg(revenue) as ave + from + (select ss_store_sk, ss_item_sk, + sum(ss_sales_price) as revenue + from store_sales, date_dim + where ss_sold_date_sk = d_date_sk and d_month_seq between 1176 and 1176+11 + group by ss_store_sk, ss_item_sk) sa + group by ss_store_sk) sb, + (select ss_store_sk, ss_item_sk, sum(ss_sales_price) as revenue + from store_sales, date_dim + where ss_sold_date_sk = d_date_sk and d_month_seq between 1176 and 1176+11 + group by ss_store_sk, ss_item_sk) sc + where sb.ss_store_sk = sc.ss_store_sk and + sc.revenue <= 0.1 * sb.ave and + s_store_sk = sc.ss_store_sk and + i_item_sk = sc.ss_item_sk + order by s_store_name, i_item_desc + limit 100 diff --git a/src/main/resources/tpcds/query66.sql b/src/main/resources/tpcds/query66.sql new file mode 100644 index 0000000000..fff9c1db43 --- /dev/null +++ b/src/main/resources/tpcds/query66.sql @@ -0,0 +1,217 @@ +select + w_warehouse_name + ,w_warehouse_sq_ft + ,w_city + ,w_county + ,w_state + ,w_country + ,ship_carriers + ,year + ,sum(jan_sales) as jan_sales + ,sum(feb_sales) as feb_sales + ,sum(mar_sales) as mar_sales + ,sum(apr_sales) as apr_sales + ,sum(may_sales) as may_sales + ,sum(jun_sales) as jun_sales + ,sum(jul_sales) as jul_sales + ,sum(aug_sales) as aug_sales + ,sum(sep_sales) as sep_sales + ,sum(oct_sales) as oct_sales + ,sum(nov_sales) as nov_sales + ,sum(dec_sales) as dec_sales + ,sum(jan_sales/w_warehouse_sq_ft) as jan_sales_per_sq_foot + ,sum(feb_sales/w_warehouse_sq_ft) as feb_sales_per_sq_foot + ,sum(mar_sales/w_warehouse_sq_ft) as mar_sales_per_sq_foot + ,sum(apr_sales/w_warehouse_sq_ft) as apr_sales_per_sq_foot + ,sum(may_sales/w_warehouse_sq_ft) as may_sales_per_sq_foot + ,sum(jun_sales/w_warehouse_sq_ft) as jun_sales_per_sq_foot + ,sum(jul_sales/w_warehouse_sq_ft) as jul_sales_per_sq_foot + ,sum(aug_sales/w_warehouse_sq_ft) as aug_sales_per_sq_foot + ,sum(sep_sales/w_warehouse_sq_ft) as sep_sales_per_sq_foot + ,sum(oct_sales/w_warehouse_sq_ft) as oct_sales_per_sq_foot + ,sum(nov_sales/w_warehouse_sq_ft) as nov_sales_per_sq_foot + ,sum(dec_sales/w_warehouse_sq_ft) as dec_sales_per_sq_foot + ,sum(jan_net) as jan_net + ,sum(feb_net) as feb_net + ,sum(mar_net) as mar_net + ,sum(apr_net) as apr_net + ,sum(may_net) as may_net + ,sum(jun_net) as jun_net + ,sum(jul_net) as jul_net + ,sum(aug_net) as aug_net + ,sum(sep_net) as sep_net + ,sum(oct_net) as oct_net + ,sum(nov_net) as nov_net + ,sum(dec_net) as dec_net + from ( + select + w_warehouse_name + ,w_warehouse_sq_ft + ,w_city + ,w_county + ,w_state + ,w_country + ,concat('DHL' , ',' , 'BARIAN') as ship_carriers + ,d_year as year + ,sum(case when d_moy = 1 + then ws_ext_sales_price* ws_quantity else 0 end) as jan_sales + ,sum(case when d_moy = 2 + then ws_ext_sales_price* ws_quantity else 0 end) as feb_sales + ,sum(case when d_moy = 3 + then ws_ext_sales_price* ws_quantity else 0 end) as mar_sales + ,sum(case when d_moy = 4 + then ws_ext_sales_price* ws_quantity else 0 end) as apr_sales + ,sum(case when d_moy = 5 + then ws_ext_sales_price* ws_quantity else 0 end) as may_sales + ,sum(case when d_moy = 6 + then ws_ext_sales_price* ws_quantity else 0 end) as jun_sales + ,sum(case when d_moy = 7 + then ws_ext_sales_price* ws_quantity else 0 end) as jul_sales + ,sum(case when d_moy = 8 + then ws_ext_sales_price* ws_quantity else 0 end) as aug_sales + ,sum(case when d_moy = 9 + then ws_ext_sales_price* ws_quantity else 0 end) as sep_sales + ,sum(case when d_moy = 10 + then ws_ext_sales_price* ws_quantity else 0 end) as oct_sales + ,sum(case when d_moy = 11 + then ws_ext_sales_price* ws_quantity else 0 end) as nov_sales + ,sum(case when d_moy = 12 + then ws_ext_sales_price* ws_quantity else 0 end) as dec_sales + ,sum(case when d_moy = 1 + then ws_net_paid * ws_quantity else 0 end) as jan_net + ,sum(case when d_moy = 2 + then ws_net_paid * ws_quantity else 0 end) as feb_net + ,sum(case when d_moy = 3 + then ws_net_paid * ws_quantity else 0 end) as mar_net + ,sum(case when d_moy = 4 + then ws_net_paid * ws_quantity else 0 end) as apr_net + ,sum(case when d_moy = 5 + then ws_net_paid * ws_quantity else 0 end) as may_net + ,sum(case when d_moy = 6 + then ws_net_paid * ws_quantity else 0 end) as jun_net + ,sum(case when d_moy = 7 + then ws_net_paid * ws_quantity else 0 end) as jul_net + ,sum(case when d_moy = 8 + then ws_net_paid * ws_quantity else 0 end) as aug_net + ,sum(case when d_moy = 9 + then ws_net_paid * ws_quantity else 0 end) as sep_net + ,sum(case when d_moy = 10 + then ws_net_paid * ws_quantity else 0 end) as oct_net + ,sum(case when d_moy = 11 + then ws_net_paid * ws_quantity else 0 end) as nov_net + ,sum(case when d_moy = 12 + then ws_net_paid * ws_quantity else 0 end) as dec_net + from + web_sales + ,warehouse + ,date_dim + ,time_dim + ,ship_mode + where + ws_warehouse_sk = w_warehouse_sk + and ws_sold_date_sk = d_date_sk + and ws_sold_time_sk = t_time_sk + and ws_ship_mode_sk = sm_ship_mode_sk + and d_year = 2001 + and t_time between 30838 and 30838+28800 + and sm_carrier in ('DHL','BARIAN') + group by + w_warehouse_name + ,w_warehouse_sq_ft + ,w_city + ,w_county + ,w_state + ,w_country + ,d_year + union all + select + w_warehouse_name + ,w_warehouse_sq_ft + ,w_city + ,w_county + ,w_state + ,w_country + ,concat('DHL' , ',' , 'BARIAN') as ship_carriers + ,d_year as year + ,sum(case when d_moy = 1 + then cs_sales_price* cs_quantity else 0 end) as jan_sales + ,sum(case when d_moy = 2 + then cs_sales_price* cs_quantity else 0 end) as feb_sales + ,sum(case when d_moy = 3 + then cs_sales_price* cs_quantity else 0 end) as mar_sales + ,sum(case when d_moy = 4 + then cs_sales_price* cs_quantity else 0 end) as apr_sales + ,sum(case when d_moy = 5 + then cs_sales_price* cs_quantity else 0 end) as may_sales + ,sum(case when d_moy = 6 + then cs_sales_price* cs_quantity else 0 end) as jun_sales + ,sum(case when d_moy = 7 + then cs_sales_price* cs_quantity else 0 end) as jul_sales + ,sum(case when d_moy = 8 + then cs_sales_price* cs_quantity else 0 end) as aug_sales + ,sum(case when d_moy = 9 + then cs_sales_price* cs_quantity else 0 end) as sep_sales + ,sum(case when d_moy = 10 + then cs_sales_price* cs_quantity else 0 end) as oct_sales + ,sum(case when d_moy = 11 + then cs_sales_price* cs_quantity else 0 end) as nov_sales + ,sum(case when d_moy = 12 + then cs_sales_price* cs_quantity else 0 end) as dec_sales + ,sum(case when d_moy = 1 + then cs_net_paid_inc_tax * cs_quantity else 0 end) as jan_net + ,sum(case when d_moy = 2 + then cs_net_paid_inc_tax * cs_quantity else 0 end) as feb_net + ,sum(case when d_moy = 3 + then cs_net_paid_inc_tax * cs_quantity else 0 end) as mar_net + ,sum(case when d_moy = 4 + then cs_net_paid_inc_tax * cs_quantity else 0 end) as apr_net + ,sum(case when d_moy = 5 + then cs_net_paid_inc_tax * cs_quantity else 0 end) as may_net + ,sum(case when d_moy = 6 + then cs_net_paid_inc_tax * cs_quantity else 0 end) as jun_net + ,sum(case when d_moy = 7 + then cs_net_paid_inc_tax * cs_quantity else 0 end) as jul_net + ,sum(case when d_moy = 8 + then cs_net_paid_inc_tax * cs_quantity else 0 end) as aug_net + ,sum(case when d_moy = 9 + then cs_net_paid_inc_tax * cs_quantity else 0 end) as sep_net + ,sum(case when d_moy = 10 + then cs_net_paid_inc_tax * cs_quantity else 0 end) as oct_net + ,sum(case when d_moy = 11 + then cs_net_paid_inc_tax * cs_quantity else 0 end) as nov_net + ,sum(case when d_moy = 12 + then cs_net_paid_inc_tax * cs_quantity else 0 end) as dec_net + from + catalog_sales + ,warehouse + ,date_dim + ,time_dim + ,ship_mode + where + cs_warehouse_sk = w_warehouse_sk + and cs_sold_date_sk = d_date_sk + and cs_sold_time_sk = t_time_sk + and cs_ship_mode_sk = sm_ship_mode_sk + and d_year = 2001 + and t_time between 30838 AND 30838+28800 + and sm_carrier in ('DHL','BARIAN') + group by + w_warehouse_name + ,w_warehouse_sq_ft + ,w_city + ,w_county + ,w_state + ,w_country + ,d_year + ) x + group by + w_warehouse_name + ,w_warehouse_sq_ft + ,w_city + ,w_county + ,w_state + ,w_country + ,ship_carriers + ,year + order by w_warehouse_name + limit 100 diff --git a/src/main/resources/tpcds/query67.sql b/src/main/resources/tpcds/query67.sql new file mode 100644 index 0000000000..17af92b4f5 --- /dev/null +++ b/src/main/resources/tpcds/query67.sql @@ -0,0 +1,41 @@ +select * +from (select i_category + ,i_class + ,i_brand + ,i_product_name + ,d_year + ,d_qoy + ,d_moy + ,s_store_id + ,sumsales + ,rank() over (partition by i_category order by sumsales desc) rk + from (select i_category + ,i_class + ,i_brand + ,i_product_name + ,d_year + ,d_qoy + ,d_moy + ,s_store_id + ,sum(coalesce(ss_sales_price*ss_quantity,0)) sumsales + from store_sales + ,date_dim + ,store + ,item + where ss_sold_date_sk=d_date_sk + and ss_item_sk=i_item_sk + and ss_store_sk = s_store_sk + and d_month_seq between 1200 and 1200+11 + group by rollup(i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy,s_store_id))dw1) dw2 +where rk <= 100 +order by i_category + ,i_class + ,i_brand + ,i_product_name + ,d_year + ,d_qoy + ,d_moy + ,s_store_id + ,sumsales + ,rk + limit 100 diff --git a/src/main/resources/tpcds/query68.sql b/src/main/resources/tpcds/query68.sql new file mode 100644 index 0000000000..dccc63cd64 --- /dev/null +++ b/src/main/resources/tpcds/query68.sql @@ -0,0 +1,39 @@ +select c_last_name + ,c_first_name + ,ca_city + ,bought_city + ,ss_ticket_number + ,extended_price + ,extended_tax + ,list_price + from (select ss_ticket_number + ,ss_customer_sk + ,ca_city bought_city + ,sum(ss_ext_sales_price) extended_price + ,sum(ss_ext_list_price) list_price + ,sum(ss_ext_tax) extended_tax + from store_sales + ,date_dim + ,store + ,household_demographics + ,customer_address + where store_sales.ss_sold_date_sk = date_dim.d_date_sk + and store_sales.ss_store_sk = store.s_store_sk + and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk + and store_sales.ss_addr_sk = customer_address.ca_address_sk + and date_dim.d_dom between 1 and 2 + and (household_demographics.hd_dep_count = 4 or + household_demographics.hd_vehicle_count= 3) + and date_dim.d_year in (1999,1999+1,1999+2) + and store.s_city in ('Fairview','Midway') + group by ss_ticket_number + ,ss_customer_sk + ,ss_addr_sk,ca_city) dn + ,customer + ,customer_address current_addr + where ss_customer_sk = c_customer_sk + and customer.c_current_addr_sk = current_addr.ca_address_sk + and current_addr.ca_city <> bought_city + order by c_last_name + ,ss_ticket_number + limit 100 diff --git a/src/main/resources/tpcds/query69.sql b/src/main/resources/tpcds/query69.sql new file mode 100644 index 0000000000..2efec64112 --- /dev/null +++ b/src/main/resources/tpcds/query69.sql @@ -0,0 +1,44 @@ +select + cd_gender, + cd_marital_status, + cd_education_status, + count(*) cnt1, + cd_purchase_estimate, + count(*) cnt2, + cd_credit_rating, + count(*) cnt3 + from + customer c,customer_address ca,customer_demographics + where + c.c_current_addr_sk = ca.ca_address_sk and + ca_state in ('KY','GA','NM') and + cd_demo_sk = c.c_current_cdemo_sk and + exists (select * + from store_sales,date_dim + where c.c_customer_sk = ss_customer_sk and + ss_sold_date_sk = d_date_sk and + d_year = 2001 and + d_moy between 4 and 4+2) and + (not exists (select * + from web_sales,date_dim + where c.c_customer_sk = ws_bill_customer_sk and + ws_sold_date_sk = d_date_sk and + d_year = 2001 and + d_moy between 4 and 4+2) and + not exists (select * + from catalog_sales,date_dim + where c.c_customer_sk = cs_ship_customer_sk and + cs_sold_date_sk = d_date_sk and + d_year = 2001 and + d_moy between 4 and 4+2)) + group by cd_gender, + cd_marital_status, + cd_education_status, + cd_purchase_estimate, + cd_credit_rating + order by cd_gender, + cd_marital_status, + cd_education_status, + cd_purchase_estimate, + cd_credit_rating + limit 100 diff --git a/src/main/resources/tpcds/query70.sql b/src/main/resources/tpcds/query70.sql new file mode 100644 index 0000000000..c2ad44b282 --- /dev/null +++ b/src/main/resources/tpcds/query70.sql @@ -0,0 +1,35 @@ +select + sum(ss_net_profit) as total_sum + ,s_state + ,s_county + ,grouping(s_state)+grouping(s_county) as lochierarchy + ,rank() over ( + partition by grouping(s_state)+grouping(s_county), + case when grouping(s_county) = 0 then s_state end + order by sum(ss_net_profit) desc) as rank_within_parent + from + store_sales + ,date_dim d1 + ,store + where + d1.d_month_seq between 1200 and 1200+11 + and d1.d_date_sk = ss_sold_date_sk + and s_store_sk = ss_store_sk + and s_state in + ( select s_state + from (select s_state as s_state, + rank() over ( partition by s_state order by sum(ss_net_profit) desc) as ranking + from store_sales, store, date_dim + where d_month_seq between 1200 and 1200+11 + and d_date_sk = ss_sold_date_sk + and s_store_sk = ss_store_sk + group by s_state + ) tmp1 + where ranking <= 5 + ) + group by rollup(s_state,s_county) + order by + lochierarchy desc + ,case when lochierarchy = 0 then s_state end + ,rank_within_parent + limit 100 diff --git a/src/main/resources/tpcds/query71.sql b/src/main/resources/tpcds/query71.sql new file mode 100644 index 0000000000..8c0d727aef --- /dev/null +++ b/src/main/resources/tpcds/query71.sql @@ -0,0 +1,37 @@ +select i_brand_id brand_id, i_brand brand,t_hour,t_minute, + sum(ext_price) ext_price + from item, (select ws_ext_sales_price as ext_price, + ws_sold_date_sk as sold_date_sk, + ws_item_sk as sold_item_sk, + ws_sold_time_sk as time_sk + from web_sales,date_dim + where d_date_sk = ws_sold_date_sk + and d_moy=11 + and d_year=1999 + union all + select cs_ext_sales_price as ext_price, + cs_sold_date_sk as sold_date_sk, + cs_item_sk as sold_item_sk, + cs_sold_time_sk as time_sk + from catalog_sales,date_dim + where d_date_sk = cs_sold_date_sk + and d_moy=11 + and d_year=1999 + union all + select ss_ext_sales_price as ext_price, + ss_sold_date_sk as sold_date_sk, + ss_item_sk as sold_item_sk, + ss_sold_time_sk as time_sk + from store_sales,date_dim + where d_date_sk = ss_sold_date_sk + and d_moy=11 + and d_year=1999 + ) tmp,time_dim + where + sold_item_sk = i_item_sk + and i_manager_id=1 + and time_sk = t_time_sk + and (t_meal_time = 'breakfast' or t_meal_time = 'dinner') + group by i_brand, i_brand_id,t_hour,t_minute + order by ext_price desc, i_brand_id + diff --git a/src/main/resources/tpcds/query72.sql b/src/main/resources/tpcds/query72.sql new file mode 100644 index 0000000000..067cd95ec8 --- /dev/null +++ b/src/main/resources/tpcds/query72.sql @@ -0,0 +1,26 @@ +select i_item_desc + ,w_warehouse_name + ,d1.d_week_seq + ,sum(case when p_promo_sk is null then 1 else 0 end) no_promo + ,sum(case when p_promo_sk is not null then 1 else 0 end) promo + ,count(*) total_cnt +from catalog_sales +join inventory on (cs_item_sk = inv_item_sk) +join warehouse on (w_warehouse_sk=inv_warehouse_sk) +join item on (i_item_sk = cs_item_sk) +join customer_demographics on (cs_bill_cdemo_sk = cd_demo_sk) +join household_demographics on (cs_bill_hdemo_sk = hd_demo_sk) +join date_dim d1 on (cs_sold_date_sk = d1.d_date_sk) +join date_dim d2 on (inv_date_sk = d2.d_date_sk) +join date_dim d3 on (cs_ship_date_sk = d3.d_date_sk) +left outer join promotion on (cs_promo_sk=p_promo_sk) +left outer join catalog_returns on (cr_item_sk = cs_item_sk and cr_order_number = cs_order_number) +where d1.d_week_seq = d2.d_week_seq + and inv_quantity_on_hand < cs_quantity + and d3.d_date > date_add(cast(d1.d_date as date),5) + and hd_buy_potential = '>10000' + and d1.d_year = 1999 + and cd_marital_status = 'D' +group by i_item_desc,w_warehouse_name,d1.d_week_seq +order by total_cnt desc, i_item_desc, w_warehouse_name, d_week_seq + limit 100 diff --git a/src/main/resources/tpcds/query73.sql b/src/main/resources/tpcds/query73.sql new file mode 100644 index 0000000000..21b70271ab --- /dev/null +++ b/src/main/resources/tpcds/query73.sql @@ -0,0 +1,25 @@ +select c_last_name + ,c_first_name + ,c_salutation + ,c_preferred_cust_flag + ,ss_ticket_number + ,cnt from + (select ss_ticket_number + ,ss_customer_sk + ,count(*) cnt + from store_sales,date_dim,store,household_demographics + where store_sales.ss_sold_date_sk = date_dim.d_date_sk + and store_sales.ss_store_sk = store.s_store_sk + and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk + and date_dim.d_dom between 1 and 2 + and (household_demographics.hd_buy_potential = '>10000' or + household_demographics.hd_buy_potential = 'Unknown') + and household_demographics.hd_vehicle_count > 0 + and case when household_demographics.hd_vehicle_count > 0 then + household_demographics.hd_dep_count/ household_demographics.hd_vehicle_count else null end > 1 + and date_dim.d_year in (1999,1999+1,1999+2) + and store.s_county in ('Williamson County','Franklin Parish','Bronx County','Orange County') + group by ss_ticket_number,ss_customer_sk) dj,customer + where ss_customer_sk = c_customer_sk + and cnt between 1 and 5 + order by cnt desc, c_last_name asc diff --git a/src/main/resources/tpcds/query74.sql b/src/main/resources/tpcds/query74.sql new file mode 100644 index 0000000000..ca30d76109 --- /dev/null +++ b/src/main/resources/tpcds/query74.sql @@ -0,0 +1,58 @@ +with year_total as ( + select c_customer_id customer_id + ,c_first_name customer_first_name + ,c_last_name customer_last_name + ,d_year as year + ,sum(ss_net_paid) year_total + ,'s' sale_type + from customer + ,store_sales + ,date_dim + where c_customer_sk = ss_customer_sk + and ss_sold_date_sk = d_date_sk + and d_year in (2001,2001+1) + group by c_customer_id + ,c_first_name + ,c_last_name + ,d_year + union all + select c_customer_id customer_id + ,c_first_name customer_first_name + ,c_last_name customer_last_name + ,d_year as year + ,sum(ws_net_paid) year_total + ,'w' sale_type + from customer + ,web_sales + ,date_dim + where c_customer_sk = ws_bill_customer_sk + and ws_sold_date_sk = d_date_sk + and d_year in (2001,2001+1) + group by c_customer_id + ,c_first_name + ,c_last_name + ,d_year + ) + select + t_s_secyear.customer_id, t_s_secyear.customer_first_name, t_s_secyear.customer_last_name + from year_total t_s_firstyear + ,year_total t_s_secyear + ,year_total t_w_firstyear + ,year_total t_w_secyear + where t_s_secyear.customer_id = t_s_firstyear.customer_id + and t_s_firstyear.customer_id = t_w_secyear.customer_id + and t_s_firstyear.customer_id = t_w_firstyear.customer_id + and t_s_firstyear.sale_type = 's' + and t_w_firstyear.sale_type = 'w' + and t_s_secyear.sale_type = 's' + and t_w_secyear.sale_type = 'w' + and t_s_firstyear.year = 2001 + and t_s_secyear.year = 2001+1 + and t_w_firstyear.year = 2001 + and t_w_secyear.year = 2001+1 + and t_s_firstyear.year_total > 0 + and t_w_firstyear.year_total > 0 + and case when t_w_firstyear.year_total > 0 then t_w_secyear.year_total / t_w_firstyear.year_total else null end + > case when t_s_firstyear.year_total > 0 then t_s_secyear.year_total / t_s_firstyear.year_total else null end + order by 1,1,1 + limit 100 diff --git a/src/main/resources/tpcds/query75.sql b/src/main/resources/tpcds/query75.sql new file mode 100644 index 0000000000..d7dc80b447 --- /dev/null +++ b/src/main/resources/tpcds/query75.sql @@ -0,0 +1,67 @@ +WITH all_sales AS ( + SELECT d_year + ,i_brand_id + ,i_class_id + ,i_category_id + ,i_manufact_id + ,SUM(sales_cnt) AS sales_cnt + ,SUM(sales_amt) AS sales_amt + FROM (SELECT d_year + ,i_brand_id + ,i_class_id + ,i_category_id + ,i_manufact_id + ,cs_quantity - COALESCE(cr_return_quantity,0) AS sales_cnt + ,cs_ext_sales_price - COALESCE(cr_return_amount,0.0) AS sales_amt + FROM catalog_sales JOIN item ON i_item_sk=cs_item_sk + JOIN date_dim ON d_date_sk=cs_sold_date_sk + LEFT JOIN catalog_returns ON (cs_order_number=cr_order_number + AND cs_item_sk=cr_item_sk) + WHERE i_category='Books' + UNION + SELECT d_year + ,i_brand_id + ,i_class_id + ,i_category_id + ,i_manufact_id + ,ss_quantity - COALESCE(sr_return_quantity,0) AS sales_cnt + ,ss_ext_sales_price - COALESCE(sr_return_amt,0.0) AS sales_amt + FROM store_sales JOIN item ON i_item_sk=ss_item_sk + JOIN date_dim ON d_date_sk=ss_sold_date_sk + LEFT JOIN store_returns ON (ss_ticket_number=sr_ticket_number + AND ss_item_sk=sr_item_sk) + WHERE i_category='Books' + UNION + SELECT d_year + ,i_brand_id + ,i_class_id + ,i_category_id + ,i_manufact_id + ,ws_quantity - COALESCE(wr_return_quantity,0) AS sales_cnt + ,ws_ext_sales_price - COALESCE(wr_return_amt,0.0) AS sales_amt + FROM web_sales JOIN item ON i_item_sk=ws_item_sk + JOIN date_dim ON d_date_sk=ws_sold_date_sk + LEFT JOIN web_returns ON (ws_order_number=wr_order_number + AND ws_item_sk=wr_item_sk) + WHERE i_category='Books') sales_detail + GROUP BY d_year, i_brand_id, i_class_id, i_category_id, i_manufact_id) + SELECT prev_yr.d_year AS prev_year + ,curr_yr.d_year AS year + ,curr_yr.i_brand_id + ,curr_yr.i_class_id + ,curr_yr.i_category_id + ,curr_yr.i_manufact_id + ,prev_yr.sales_cnt AS prev_yr_cnt + ,curr_yr.sales_cnt AS curr_yr_cnt + ,curr_yr.sales_cnt-prev_yr.sales_cnt AS sales_cnt_diff + ,curr_yr.sales_amt-prev_yr.sales_amt AS sales_amt_diff + FROM all_sales curr_yr, all_sales prev_yr + WHERE curr_yr.i_brand_id=prev_yr.i_brand_id + AND curr_yr.i_class_id=prev_yr.i_class_id + AND curr_yr.i_category_id=prev_yr.i_category_id + AND curr_yr.i_manufact_id=prev_yr.i_manufact_id + AND curr_yr.d_year=2002 + AND prev_yr.d_year=2002-1 + AND CAST(curr_yr.sales_cnt AS DECIMAL(17,2))/CAST(prev_yr.sales_cnt AS DECIMAL(17,2))<0.9 + ORDER BY sales_cnt_diff + limit 100 diff --git a/src/main/resources/tpcds/query76.sql b/src/main/resources/tpcds/query76.sql new file mode 100644 index 0000000000..391e2cd577 --- /dev/null +++ b/src/main/resources/tpcds/query76.sql @@ -0,0 +1,21 @@ +select channel, col_name, d_year, d_qoy, i_category, COUNT(*) sales_cnt, SUM(ext_sales_price) sales_amt FROM ( + SELECT 'store' as channel, 'ss_store_sk' col_name, d_year, d_qoy, i_category, ss_ext_sales_price ext_sales_price + FROM store_sales, item, date_dim + WHERE ss_store_sk IS NULL + AND ss_sold_date_sk=d_date_sk + AND ss_item_sk=i_item_sk + UNION ALL + SELECT 'web' as channel, 'ws_ship_customer_sk' col_name, d_year, d_qoy, i_category, ws_ext_sales_price ext_sales_price + FROM web_sales, item, date_dim + WHERE ws_ship_customer_sk IS NULL + AND ws_sold_date_sk=d_date_sk + AND ws_item_sk=i_item_sk + UNION ALL + SELECT 'catalog' as channel, 'cs_ship_addr_sk' col_name, d_year, d_qoy, i_category, cs_ext_sales_price ext_sales_price + FROM catalog_sales, item, date_dim + WHERE cs_ship_addr_sk IS NULL + AND cs_sold_date_sk=d_date_sk + AND cs_item_sk=i_item_sk) foo +GROUP BY channel, col_name, d_year, d_qoy, i_category +ORDER BY channel, col_name, d_year, d_qoy, i_category + limit 100 diff --git a/src/main/resources/tpcds/query77.sql b/src/main/resources/tpcds/query77.sql new file mode 100644 index 0000000000..3007c01d4e --- /dev/null +++ b/src/main/resources/tpcds/query77.sql @@ -0,0 +1,105 @@ +with ss as + (select s_store_sk, + sum(ss_ext_sales_price) as sales, + sum(ss_net_profit) as profit + from store_sales, + date_dim, + store + where ss_sold_date_sk = d_date_sk + and d_date between cast('2000-08-23' as date) + and date_add(cast('2000-08-23' as date), 30 ) + and ss_store_sk = s_store_sk + group by s_store_sk) + , + sr as + (select s_store_sk, + sum(sr_return_amt) as returns, + sum(sr_net_loss) as profit_loss + from store_returns, + date_dim, + store + where sr_returned_date_sk = d_date_sk + and d_date between cast('2000-08-23' as date) + and date_add(cast('2000-08-23' as date), 30 ) + and sr_store_sk = s_store_sk + group by s_store_sk), + cs as + (select cs_call_center_sk, + sum(cs_ext_sales_price) as sales, + sum(cs_net_profit) as profit + from catalog_sales, + date_dim + where cs_sold_date_sk = d_date_sk + and d_date between cast('2000-08-23' as date) + and date_add(cast('2000-08-23' as date), 30 ) + group by cs_call_center_sk + ), + cr as + (select cr_call_center_sk, + sum(cr_return_amount) as returns, + sum(cr_net_loss) as profit_loss + from catalog_returns, + date_dim + where cr_returned_date_sk = d_date_sk + and d_date between cast('2000-08-23' as date) + and date_add(cast('2000-08-23' as date), 30 ) + group by cr_call_center_sk + ), + ws as + ( select wp_web_page_sk, + sum(ws_ext_sales_price) as sales, + sum(ws_net_profit) as profit + from web_sales, + date_dim, + web_page + where ws_sold_date_sk = d_date_sk + and d_date between cast('2000-08-23' as date) + and date_add(cast('2000-08-23' as date), 30 ) + and ws_web_page_sk = wp_web_page_sk + group by wp_web_page_sk), + wr as + (select wp_web_page_sk, + sum(wr_return_amt) as returns, + sum(wr_net_loss) as profit_loss + from web_returns, + date_dim, + web_page + where wr_returned_date_sk = d_date_sk + and d_date between cast('2000-08-23' as date) + and date_add(cast('2000-08-23' as date), 30 ) + and wr_web_page_sk = wp_web_page_sk + group by wp_web_page_sk) + select channel + , id + , sum(sales) as sales + , sum(returns) as returns + , sum(profit) as profit + from + (select 'store channel' as channel + , ss.s_store_sk as id + , sales + , coalesce(returns, 0) as returns + , (profit - coalesce(profit_loss,0)) as profit + from ss left join sr + on ss.s_store_sk = sr.s_store_sk + union all + select 'catalog channel' as channel + , cs_call_center_sk as id + , sales + , returns + , (profit - profit_loss) as profit + from cs + , cr + union all + select 'web channel' as channel + , ws.wp_web_page_sk as id + , sales + , coalesce(returns, 0) returns + , (profit - coalesce(profit_loss,0)) as profit + from ws left join wr + on ws.wp_web_page_sk = wr.wp_web_page_sk + ) x + group by rollup (channel, id) + order by channel + ,id + limit 100 diff --git a/src/main/resources/tpcds/query78.sql b/src/main/resources/tpcds/query78.sql new file mode 100644 index 0000000000..052bab4a72 --- /dev/null +++ b/src/main/resources/tpcds/query78.sql @@ -0,0 +1,55 @@ +with ws as + (select d_year AS ws_sold_year, ws_item_sk, + ws_bill_customer_sk ws_customer_sk, + sum(ws_quantity) ws_qty, + sum(ws_wholesale_cost) ws_wc, + sum(ws_sales_price) ws_sp + from web_sales + left join web_returns on wr_order_number=ws_order_number and ws_item_sk=wr_item_sk + join date_dim on ws_sold_date_sk = d_date_sk + where wr_order_number is null + group by d_year, ws_item_sk, ws_bill_customer_sk + ), +cs as + (select d_year AS cs_sold_year, cs_item_sk, + cs_bill_customer_sk cs_customer_sk, + sum(cs_quantity) cs_qty, + sum(cs_wholesale_cost) cs_wc, + sum(cs_sales_price) cs_sp + from catalog_sales + left join catalog_returns on cr_order_number=cs_order_number and cs_item_sk=cr_item_sk + join date_dim on cs_sold_date_sk = d_date_sk + where cr_order_number is null + group by d_year, cs_item_sk, cs_bill_customer_sk + ), +ss as + (select d_year AS ss_sold_year, ss_item_sk, + ss_customer_sk, + sum(ss_quantity) ss_qty, + sum(ss_wholesale_cost) ss_wc, + sum(ss_sales_price) ss_sp + from store_sales + left join store_returns on sr_ticket_number=ss_ticket_number and ss_item_sk=sr_item_sk + join date_dim on ss_sold_date_sk = d_date_sk + where sr_ticket_number is null + group by d_year, ss_item_sk, ss_customer_sk + ) + select +ss_sold_year, ss_item_sk, ss_customer_sk, +round(ss_qty/(coalesce(ws_qty,0)+coalesce(cs_qty,0)),2) ratio, +ss_qty store_qty, ss_wc store_wholesale_cost, ss_sp store_sales_price, +coalesce(ws_qty,0)+coalesce(cs_qty,0) other_chan_qty, +coalesce(ws_wc,0)+coalesce(cs_wc,0) other_chan_wholesale_cost, +coalesce(ws_sp,0)+coalesce(cs_sp,0) other_chan_sales_price +from ss +left join ws on (ws_sold_year=ss_sold_year and ws_item_sk=ss_item_sk and ws_customer_sk=ss_customer_sk) +left join cs on (cs_sold_year=ss_sold_year and cs_item_sk=ss_item_sk and cs_customer_sk=ss_customer_sk) +where (coalesce(ws_qty,0)>0 or coalesce(cs_qty, 0)>0) and ss_sold_year=2000 +order by + ss_sold_year, ss_item_sk, ss_customer_sk, + ss_qty desc, ss_wc desc, ss_sp desc, + other_chan_qty, + other_chan_wholesale_cost, + other_chan_sales_price, + round(ss_qty/(coalesce(ws_qty+cs_qty,1)),2) + limit 100 diff --git a/src/main/resources/tpcds/query79.sql b/src/main/resources/tpcds/query79.sql new file mode 100644 index 0000000000..208beb9ef9 --- /dev/null +++ b/src/main/resources/tpcds/query79.sql @@ -0,0 +1,20 @@ +select + c_last_name,c_first_name,substr(s_city,1,30),ss_ticket_number,amt,profit + from + (select ss_ticket_number + ,ss_customer_sk + ,store.s_city + ,sum(ss_coupon_amt) amt + ,sum(ss_net_profit) profit + from store_sales,date_dim,store,household_demographics + where store_sales.ss_sold_date_sk = date_dim.d_date_sk + and store_sales.ss_store_sk = store.s_store_sk + and store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk + and (household_demographics.hd_dep_count = 6 or household_demographics.hd_vehicle_count > 2) + and date_dim.d_dow = 1 + and date_dim.d_year in (1999,1999+1,1999+2) + and store.s_number_employees between 200 and 295 + group by ss_ticket_number,ss_customer_sk,ss_addr_sk,store.s_city) ms,customer + where ss_customer_sk = c_customer_sk + order by c_last_name,c_first_name,substr(s_city,1,30), profit + limit 100 diff --git a/src/main/resources/tpcds/query80.sql b/src/main/resources/tpcds/query80.sql new file mode 100644 index 0000000000..aca45200d6 --- /dev/null +++ b/src/main/resources/tpcds/query80.sql @@ -0,0 +1,93 @@ +with ssr as + (select s_store_id as store_id, + sum(ss_ext_sales_price) as sales, + sum(coalesce(sr_return_amt, 0)) as returns, + sum(ss_net_profit - coalesce(sr_net_loss, 0)) as profit + from store_sales left outer join store_returns on + (ss_item_sk = sr_item_sk and ss_ticket_number = sr_ticket_number), + date_dim, + store, + item, + promotion + where ss_sold_date_sk = d_date_sk + and d_date between cast('2000-08-23' as date) + and date_add(cast('2000-08-23' as date), 30 ) + and ss_store_sk = s_store_sk + and ss_item_sk = i_item_sk + and i_current_price > 50 + and ss_promo_sk = p_promo_sk + and p_channel_tv = 'N' + group by s_store_id) + , + csr as + (select cp_catalog_page_id as catalog_page_id, + sum(cs_ext_sales_price) as sales, + sum(coalesce(cr_return_amount, 0)) as returns, + sum(cs_net_profit - coalesce(cr_net_loss, 0)) as profit + from catalog_sales left outer join catalog_returns on + (cs_item_sk = cr_item_sk and cs_order_number = cr_order_number), + date_dim, + catalog_page, + item, + promotion + where cs_sold_date_sk = d_date_sk + and d_date between cast('2000-08-23' as date) + and date_add(cast('2000-08-23' as date), 30 ) + and cs_catalog_page_sk = cp_catalog_page_sk + and cs_item_sk = i_item_sk + and i_current_price > 50 + and cs_promo_sk = p_promo_sk + and p_channel_tv = 'N' +group by cp_catalog_page_id) + , + wsr as + (select web_site_id, + sum(ws_ext_sales_price) as sales, + sum(coalesce(wr_return_amt, 0)) as returns, + sum(ws_net_profit - coalesce(wr_net_loss, 0)) as profit + from web_sales left outer join web_returns on + (ws_item_sk = wr_item_sk and ws_order_number = wr_order_number), + date_dim, + web_site, + item, + promotion + where ws_sold_date_sk = d_date_sk + and d_date between cast('2000-08-23' as date) + and date_add(cast('2000-08-23' as date), 30 ) + and ws_web_site_sk = web_site_sk + and ws_item_sk = i_item_sk + and i_current_price > 50 + and ws_promo_sk = p_promo_sk + and p_channel_tv = 'N' +group by web_site_id) + select channel + , id + , sum(sales) as sales + , sum(returns) as returns + , sum(profit) as profit + from + (select 'store channel' as channel + , concat( 'store' , store_id ) as id + , sales + , returns + , profit + from ssr + union all + select 'catalog channel' as channel + , concat( 'catalog_page' , catalog_page_id ) as id + , sales + , returns + , profit + from csr + union all + select 'web channel' as channel + , concat( 'web_site' , web_site_id ) as id + , sales + , returns + , profit + from wsr + ) x + group by rollup (channel, id) + order by channel + ,id + limit 100 diff --git a/src/main/resources/tpcds/query81.sql b/src/main/resources/tpcds/query81.sql new file mode 100644 index 0000000000..2a4278dd69 --- /dev/null +++ b/src/main/resources/tpcds/query81.sql @@ -0,0 +1,28 @@ +with customer_total_return as + (select cr_returning_customer_sk as ctr_customer_sk + ,ca_state as ctr_state, + sum(cr_return_amt_inc_tax) as ctr_total_return + from catalog_returns + ,date_dim + ,customer_address + where cr_returned_date_sk = d_date_sk + and d_year =2000 + and cr_returning_addr_sk = ca_address_sk + group by cr_returning_customer_sk + ,ca_state ) + select c_customer_id,c_salutation,c_first_name,c_last_name,ca_street_number,ca_street_name + ,ca_street_type,ca_suite_number,ca_city,ca_county,ca_state,ca_zip,ca_country,ca_gmt_offset + ,ca_location_type,ctr_total_return + from customer_total_return ctr1 + ,customer_address + ,customer + where ctr1.ctr_total_return > (select avg(ctr_total_return)*1.2 + from customer_total_return ctr2 + where ctr1.ctr_state = ctr2.ctr_state) + and ca_address_sk = c_current_addr_sk + and ca_state = 'GA' + and ctr1.ctr_customer_sk = c_customer_sk + order by c_customer_id,c_salutation,c_first_name,c_last_name,ca_street_number,ca_street_name + ,ca_street_type,ca_suite_number,ca_city,ca_county,ca_state,ca_zip,ca_country,ca_gmt_offset + ,ca_location_type,ctr_total_return + limit 100 diff --git a/src/main/resources/tpcds/query82.sql b/src/main/resources/tpcds/query82.sql new file mode 100644 index 0000000000..c9168efb82 --- /dev/null +++ b/src/main/resources/tpcds/query82.sql @@ -0,0 +1,14 @@ +select i_item_id + ,i_item_desc + ,i_current_price + from item, inventory, date_dim, store_sales + where i_current_price between 62 and 62+30 + and inv_item_sk = i_item_sk + and d_date_sk=inv_date_sk + and d_date between cast('2000-05-25' as date) and date_add(cast('2000-05-25' as date), 60 ) + and i_manufact_id in (129,270,821,423) + and inv_quantity_on_hand between 100 and 500 + and ss_item_sk = i_item_sk + group by i_item_id,i_item_desc,i_current_price + order by i_item_id + limit 100 diff --git a/src/main/resources/tpcds/query83.sql b/src/main/resources/tpcds/query83.sql new file mode 100644 index 0000000000..c0e036914c --- /dev/null +++ b/src/main/resources/tpcds/query83.sql @@ -0,0 +1,64 @@ +with sr_items as + (select i_item_id item_id, + sum(sr_return_quantity) sr_item_qty + from store_returns, + item, + date_dim + where sr_item_sk = i_item_sk + and d_date in + (select d_date + from date_dim + where d_week_seq in + (select d_week_seq + from date_dim + where d_date in ('2000-06-30','2000-09-27','2000-11-17'))) + and sr_returned_date_sk = d_date_sk + group by i_item_id), + cr_items as + (select i_item_id item_id, + sum(cr_return_quantity) cr_item_qty + from catalog_returns, + item, + date_dim + where cr_item_sk = i_item_sk + and d_date in + (select d_date + from date_dim + where d_week_seq in + (select d_week_seq + from date_dim + where d_date in ('2000-06-30','2000-09-27','2000-11-17'))) + and cr_returned_date_sk = d_date_sk + group by i_item_id), + wr_items as + (select i_item_id item_id, + sum(wr_return_quantity) wr_item_qty + from web_returns, + item, + date_dim + where wr_item_sk = i_item_sk + and d_date in + (select d_date + from date_dim + where d_week_seq in + (select d_week_seq + from date_dim + where d_date in ('2000-06-30','2000-09-27','2000-11-17'))) + and wr_returned_date_sk = d_date_sk + group by i_item_id) + select sr_items.item_id + ,sr_item_qty + ,sr_item_qty/(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 * 100 sr_dev + ,cr_item_qty + ,cr_item_qty/(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 * 100 cr_dev + ,wr_item_qty + ,wr_item_qty/(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 * 100 wr_dev + ,(sr_item_qty+cr_item_qty+wr_item_qty)/3.0 average + from sr_items + ,cr_items + ,wr_items + where sr_items.item_id=cr_items.item_id + and sr_items.item_id=wr_items.item_id + order by sr_items.item_id + ,sr_item_qty + limit 100 diff --git a/src/main/resources/tpcds/query84.sql b/src/main/resources/tpcds/query84.sql new file mode 100644 index 0000000000..c331868034 --- /dev/null +++ b/src/main/resources/tpcds/query84.sql @@ -0,0 +1,18 @@ +select c_customer_id as customer_id + ,concat(c_last_name , ', ' , coalesce(c_first_name,'')) as customername + from customer + ,customer_address + ,customer_demographics + ,household_demographics + ,income_band + ,store_returns + where ca_city = 'Edgewood' + and c_current_addr_sk = ca_address_sk + and ib_lower_bound >= 38128 + and ib_upper_bound <= 38128 + 50000 + and ib_income_band_sk = hd_income_band_sk + and cd_demo_sk = c_current_cdemo_sk + and hd_demo_sk = c_current_hdemo_sk + and sr_cdemo_sk = cd_demo_sk + order by c_customer_id + limit 100 diff --git a/src/main/resources/tpcds/query85.sql b/src/main/resources/tpcds/query85.sql new file mode 100644 index 0000000000..ec2e7feb1e --- /dev/null +++ b/src/main/resources/tpcds/query85.sql @@ -0,0 +1,81 @@ +select substr(r_reason_desc,1,20) + ,avg(ws_quantity) + ,avg(wr_refunded_cash) + ,avg(wr_fee) + from web_sales, web_returns, web_page, customer_demographics cd1, + customer_demographics cd2, customer_address, date_dim, reason + where ws_web_page_sk = wp_web_page_sk + and ws_item_sk = wr_item_sk + and ws_order_number = wr_order_number + and ws_sold_date_sk = d_date_sk and d_year = 2000 + and cd1.cd_demo_sk = wr_refunded_cdemo_sk + and cd2.cd_demo_sk = wr_returning_cdemo_sk + and ca_address_sk = wr_refunded_addr_sk + and r_reason_sk = wr_reason_sk + and + ( + ( + cd1.cd_marital_status = 'M' + and + cd1.cd_marital_status = cd2.cd_marital_status + and + cd1.cd_education_status = 'Advanced Degree' + and + cd1.cd_education_status = cd2.cd_education_status + and + ws_sales_price between 100.00 and 150.00 + ) + or + ( + cd1.cd_marital_status = 'S' + and + cd1.cd_marital_status = cd2.cd_marital_status + and + cd1.cd_education_status = 'College' + and + cd1.cd_education_status = cd2.cd_education_status + and + ws_sales_price between 50.00 and 100.00 + ) + or + ( + cd1.cd_marital_status = 'W' + and + cd1.cd_marital_status = cd2.cd_marital_status + and + cd1.cd_education_status = '2 yr Degree' + and + cd1.cd_education_status = cd2.cd_education_status + and + ws_sales_price between 150.00 and 200.00 + ) + ) + and + ( + ( + ca_country = 'United States' + and + ca_state in ('IN', 'OH', 'NJ') + and ws_net_profit between 100 and 200 + ) + or + ( + ca_country = 'United States' + and + ca_state in ('WI', 'CT', 'KY') + and ws_net_profit between 150 and 300 + ) + or + ( + ca_country = 'United States' + and + ca_state in ('LA', 'IA', 'AR') + and ws_net_profit between 50 and 250 + ) + ) +group by r_reason_desc +order by substr(r_reason_desc,1,20) + ,avg(ws_quantity) + ,avg(wr_refunded_cash) + ,avg(wr_fee) + limit 100 diff --git a/src/main/resources/tpcds/query86.sql b/src/main/resources/tpcds/query86.sql new file mode 100644 index 0000000000..2745b99f3e --- /dev/null +++ b/src/main/resources/tpcds/query86.sql @@ -0,0 +1,23 @@ +select + sum(ws_net_paid) as total_sum + ,i_category + ,i_class + ,grouping(i_category)+grouping(i_class) as lochierarchy + ,rank() over ( + partition by grouping(i_category)+grouping(i_class), + case when grouping(i_class) = 0 then i_category end + order by sum(ws_net_paid) desc) as rank_within_parent + from + web_sales + ,date_dim d1 + ,item + where + d1.d_month_seq between 1200 and 1200+11 + and d1.d_date_sk = ws_sold_date_sk + and i_item_sk = ws_item_sk + group by rollup(i_category,i_class) + order by + lochierarchy desc, + case when lochierarchy = 0 then i_category end, + rank_within_parent + limit 100 diff --git a/src/main/resources/tpcds/query87.sql b/src/main/resources/tpcds/query87.sql new file mode 100644 index 0000000000..197e374891 --- /dev/null +++ b/src/main/resources/tpcds/query87.sql @@ -0,0 +1,20 @@ +select count(*) +from ((select distinct c_last_name, c_first_name, d_date + from store_sales, date_dim, customer + where store_sales.ss_sold_date_sk = date_dim.d_date_sk + and store_sales.ss_customer_sk = customer.c_customer_sk + and d_month_seq between 1200 and 1200+11) + except + (select distinct c_last_name, c_first_name, d_date + from catalog_sales, date_dim, customer + where catalog_sales.cs_sold_date_sk = date_dim.d_date_sk + and catalog_sales.cs_bill_customer_sk = customer.c_customer_sk + and d_month_seq between 1200 and 1200+11) + except + (select distinct c_last_name, c_first_name, d_date + from web_sales, date_dim, customer + where web_sales.ws_sold_date_sk = date_dim.d_date_sk + and web_sales.ws_bill_customer_sk = customer.c_customer_sk + and d_month_seq between 1200 and 1200+11) +) cool_cust + diff --git a/src/main/resources/tpcds/query88.sql b/src/main/resources/tpcds/query88.sql new file mode 100644 index 0000000000..84a6a12912 --- /dev/null +++ b/src/main/resources/tpcds/query88.sql @@ -0,0 +1,90 @@ +select * +from + (select count(*) h8_30_to_9 + from store_sales, household_demographics , time_dim, store + where ss_sold_time_sk = time_dim.t_time_sk + and ss_hdemo_sk = household_demographics.hd_demo_sk + and ss_store_sk = s_store_sk + and time_dim.t_hour = 8 + and time_dim.t_minute >= 30 + and ((household_demographics.hd_dep_count = 4 and household_demographics.hd_vehicle_count<=4+2) or + (household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2) or + (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2)) + and store.s_store_name = 'ese') s1, + (select count(*) h9_to_9_30 + from store_sales, household_demographics , time_dim, store + where ss_sold_time_sk = time_dim.t_time_sk + and ss_hdemo_sk = household_demographics.hd_demo_sk + and ss_store_sk = s_store_sk + and time_dim.t_hour = 9 + and time_dim.t_minute < 30 + and ((household_demographics.hd_dep_count = 4 and household_demographics.hd_vehicle_count<=4+2) or + (household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2) or + (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2)) + and store.s_store_name = 'ese') s2, + (select count(*) h9_30_to_10 + from store_sales, household_demographics , time_dim, store + where ss_sold_time_sk = time_dim.t_time_sk + and ss_hdemo_sk = household_demographics.hd_demo_sk + and ss_store_sk = s_store_sk + and time_dim.t_hour = 9 + and time_dim.t_minute >= 30 + and ((household_demographics.hd_dep_count = 4 and household_demographics.hd_vehicle_count<=4+2) or + (household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2) or + (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2)) + and store.s_store_name = 'ese') s3, + (select count(*) h10_to_10_30 + from store_sales, household_demographics , time_dim, store + where ss_sold_time_sk = time_dim.t_time_sk + and ss_hdemo_sk = household_demographics.hd_demo_sk + and ss_store_sk = s_store_sk + and time_dim.t_hour = 10 + and time_dim.t_minute < 30 + and ((household_demographics.hd_dep_count = 4 and household_demographics.hd_vehicle_count<=4+2) or + (household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2) or + (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2)) + and store.s_store_name = 'ese') s4, + (select count(*) h10_30_to_11 + from store_sales, household_demographics , time_dim, store + where ss_sold_time_sk = time_dim.t_time_sk + and ss_hdemo_sk = household_demographics.hd_demo_sk + and ss_store_sk = s_store_sk + and time_dim.t_hour = 10 + and time_dim.t_minute >= 30 + and ((household_demographics.hd_dep_count = 4 and household_demographics.hd_vehicle_count<=4+2) or + (household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2) or + (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2)) + and store.s_store_name = 'ese') s5, + (select count(*) h11_to_11_30 + from store_sales, household_demographics , time_dim, store + where ss_sold_time_sk = time_dim.t_time_sk + and ss_hdemo_sk = household_demographics.hd_demo_sk + and ss_store_sk = s_store_sk + and time_dim.t_hour = 11 + and time_dim.t_minute < 30 + and ((household_demographics.hd_dep_count = 4 and household_demographics.hd_vehicle_count<=4+2) or + (household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2) or + (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2)) + and store.s_store_name = 'ese') s6, + (select count(*) h11_30_to_12 + from store_sales, household_demographics , time_dim, store + where ss_sold_time_sk = time_dim.t_time_sk + and ss_hdemo_sk = household_demographics.hd_demo_sk + and ss_store_sk = s_store_sk + and time_dim.t_hour = 11 + and time_dim.t_minute >= 30 + and ((household_demographics.hd_dep_count = 4 and household_demographics.hd_vehicle_count<=4+2) or + (household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2) or + (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2)) + and store.s_store_name = 'ese') s7, + (select count(*) h12_to_12_30 + from store_sales, household_demographics , time_dim, store + where ss_sold_time_sk = time_dim.t_time_sk + and ss_hdemo_sk = household_demographics.hd_demo_sk + and ss_store_sk = s_store_sk + and time_dim.t_hour = 12 + and time_dim.t_minute < 30 + and ((household_demographics.hd_dep_count = 4 and household_demographics.hd_vehicle_count<=4+2) or + (household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2) or + (household_demographics.hd_dep_count = 0 and household_demographics.hd_vehicle_count<=0+2)) + and store.s_store_name = 'ese') s8 diff --git a/src/main/resources/tpcds/query89.sql b/src/main/resources/tpcds/query89.sql new file mode 100644 index 0000000000..94718dce0b --- /dev/null +++ b/src/main/resources/tpcds/query89.sql @@ -0,0 +1,25 @@ +select * +from( +select i_category, i_class, i_brand, + s_store_name, s_company_name, + d_moy, + sum(ss_sales_price) sum_sales, + avg(sum(ss_sales_price)) over + (partition by i_category, i_brand, s_store_name, s_company_name) + avg_monthly_sales +from item, store_sales, date_dim, store +where ss_item_sk = i_item_sk and + ss_sold_date_sk = d_date_sk and + ss_store_sk = s_store_sk and + d_year in (1999) and + ((i_category in ('Books','Electronics','Sports') and + i_class in ('computers','stereo','football') + ) + or (i_category in ('Men','Jewelry','Women') and + i_class in ('shirts','birdal','dresses') + )) +group by i_category, i_class, i_brand, + s_store_name, s_company_name, d_moy) tmp1 +where case when (avg_monthly_sales <> 0) then (abs(sum_sales - avg_monthly_sales) / avg_monthly_sales) else null end > 0.1 +order by sum_sales - avg_monthly_sales, s_store_name + limit 100 diff --git a/src/main/resources/tpcds/query90.sql b/src/main/resources/tpcds/query90.sql new file mode 100644 index 0000000000..e177b7b38d --- /dev/null +++ b/src/main/resources/tpcds/query90.sql @@ -0,0 +1,19 @@ +select cast(amc as decimal(15,4))/cast(pmc as decimal(15,4)) am_pm_ratio + from ( select count(*) amc + from web_sales, household_demographics , time_dim, web_page + where ws_sold_time_sk = time_dim.t_time_sk + and ws_ship_hdemo_sk = household_demographics.hd_demo_sk + and ws_web_page_sk = web_page.wp_web_page_sk + and time_dim.t_hour between 8 and 8+1 + and household_demographics.hd_dep_count = 6 + and web_page.wp_char_count between 5000 and 5200) at1, + ( select count(*) pmc + from web_sales, household_demographics , time_dim, web_page + where ws_sold_time_sk = time_dim.t_time_sk + and ws_ship_hdemo_sk = household_demographics.hd_demo_sk + and ws_web_page_sk = web_page.wp_web_page_sk + and time_dim.t_hour between 19 and 19+1 + and household_demographics.hd_dep_count = 6 + and web_page.wp_char_count between 5000 and 5200) pt + order by am_pm_ratio + limit 100 diff --git a/src/main/resources/tpcds/query91.sql b/src/main/resources/tpcds/query91.sql new file mode 100644 index 0000000000..ed67b9e6b3 --- /dev/null +++ b/src/main/resources/tpcds/query91.sql @@ -0,0 +1,28 @@ +select + cc_call_center_id Call_Center, + cc_name Call_Center_Name, + cc_manager Manager, + sum(cr_net_loss) Returns_Loss +from + call_center, + catalog_returns, + date_dim, + customer, + customer_address, + customer_demographics, + household_demographics +where + cr_call_center_sk = cc_call_center_sk +and cr_returned_date_sk = d_date_sk +and cr_returning_customer_sk= c_customer_sk +and cd_demo_sk = c_current_cdemo_sk +and hd_demo_sk = c_current_hdemo_sk +and ca_address_sk = c_current_addr_sk +and d_year = 1998 +and d_moy = 11 +and ( (cd_marital_status = 'M' and cd_education_status = 'Unknown') + or(cd_marital_status = 'W' and cd_education_status = 'Advanced Degree')) +and hd_buy_potential like 'Unknown%' +and ca_gmt_offset = -7 +group by cc_call_center_id,cc_name,cc_manager,cd_marital_status,cd_education_status +order by sum(cr_net_loss) desc diff --git a/src/main/resources/tpcds/query92.sql b/src/main/resources/tpcds/query92.sql new file mode 100644 index 0000000000..e80a8e17d5 --- /dev/null +++ b/src/main/resources/tpcds/query92.sql @@ -0,0 +1,27 @@ +select + sum(ws_ext_discount_amt) as Excess_Discount_Amount +from + web_sales + ,item + ,date_dim +where +i_manufact_id = 350 +and i_item_sk = ws_item_sk +and d_date between '2000-01-27' and + date_add(cast('2000-01-27' as date), 90 ) +and d_date_sk = ws_sold_date_sk +and ws_ext_discount_amt + > ( + SELECT + 1.3 * avg(ws_ext_discount_amt) + FROM + web_sales + ,date_dim + WHERE + ws_item_sk = i_item_sk + and d_date between '2000-01-27' and + date_add(cast('2000-01-27' as date), 90 ) + and d_date_sk = ws_sold_date_sk + ) +order by sum(ws_ext_discount_amt) + limit 100 diff --git a/src/main/resources/tpcds/query93.sql b/src/main/resources/tpcds/query93.sql new file mode 100644 index 0000000000..97ef85ef70 --- /dev/null +++ b/src/main/resources/tpcds/query93.sql @@ -0,0 +1,15 @@ +select ss_customer_sk + ,sum(act_sales) sumsales + from (select ss_item_sk + ,ss_ticket_number + ,ss_customer_sk + ,case when sr_return_quantity is not null then (ss_quantity-sr_return_quantity)*ss_sales_price + else (ss_quantity*ss_sales_price) end act_sales + from store_sales left outer join store_returns on (sr_item_sk = ss_item_sk + and sr_ticket_number = ss_ticket_number) + ,reason + where sr_reason_sk = r_reason_sk + and r_reason_desc = 'reason 28') t + group by ss_customer_sk + order by sumsales, ss_customer_sk + limit 100 diff --git a/src/main/resources/tpcds/query94.sql b/src/main/resources/tpcds/query94.sql new file mode 100644 index 0000000000..8c0b958e29 --- /dev/null +++ b/src/main/resources/tpcds/query94.sql @@ -0,0 +1,26 @@ +select + count(distinct ws_order_number) as order_count + ,sum(ws_ext_ship_cost) as total_shipping_cost + ,sum(ws_net_profit) as total_net_profit +from + web_sales ws1 + ,date_dim + ,customer_address + ,web_site +where + d_date between cast('1999-2-01' as date) and + date_add(cast('1999-2-01' as date), 60 ) +and ws1.ws_ship_date_sk = d_date_sk +and ws1.ws_ship_addr_sk = ca_address_sk +and ca_state = 'IL' +and ws1.ws_web_site_sk = web_site_sk +and web_company_name = 'pri' +and exists (select * + from web_sales ws2 + where ws1.ws_order_number = ws2.ws_order_number + and ws1.ws_warehouse_sk <> ws2.ws_warehouse_sk) +and not exists(select * + from web_returns wr1 + where ws1.ws_order_number = wr1.wr_order_number) +order by count(distinct ws_order_number) + limit 100 diff --git a/src/main/resources/tpcds/query95.sql b/src/main/resources/tpcds/query95.sql new file mode 100644 index 0000000000..db332740d8 --- /dev/null +++ b/src/main/resources/tpcds/query95.sql @@ -0,0 +1,29 @@ +with ws_wh as +(select ws1.ws_order_number,ws1.ws_warehouse_sk wh1,ws2.ws_warehouse_sk wh2 + from web_sales ws1,web_sales ws2 + where ws1.ws_order_number = ws2.ws_order_number + and ws1.ws_warehouse_sk <> ws2.ws_warehouse_sk) + select + count(distinct ws_order_number) as order_count + ,sum(ws_ext_ship_cost) as total_shipping_cost + ,sum(ws_net_profit) as total_net_profit +from + web_sales ws1 + ,date_dim + ,customer_address + ,web_site +where + d_date between '1999-2-01' and + date_add(cast('1999-2-01' as date), 60 ) +and ws1.ws_ship_date_sk = d_date_sk +and ws1.ws_ship_addr_sk = ca_address_sk +and ca_state = 'IL' +and ws1.ws_web_site_sk = web_site_sk +and web_company_name = 'pri' +and ws1.ws_order_number in (select ws_order_number + from ws_wh) +and ws1.ws_order_number in (select wr_order_number + from web_returns,ws_wh + where wr_order_number = ws_wh.ws_order_number) +order by count(distinct ws_order_number) + limit 100 diff --git a/src/main/resources/tpcds/query96.sql b/src/main/resources/tpcds/query96.sql new file mode 100644 index 0000000000..f5b709f54c --- /dev/null +++ b/src/main/resources/tpcds/query96.sql @@ -0,0 +1,13 @@ +select count(*) +from store_sales + ,household_demographics + ,time_dim, store +where ss_sold_time_sk = time_dim.t_time_sk + and ss_hdemo_sk = household_demographics.hd_demo_sk + and ss_store_sk = s_store_sk + and time_dim.t_hour = 20 + and time_dim.t_minute >= 30 + and household_demographics.hd_dep_count = 7 + and store.s_store_name = 'ese' +order by count(*) + limit 100 diff --git a/src/main/resources/tpcds/query97.sql b/src/main/resources/tpcds/query97.sql new file mode 100644 index 0000000000..7a006b9ccb --- /dev/null +++ b/src/main/resources/tpcds/query97.sql @@ -0,0 +1,22 @@ +with ssci as ( +select ss_customer_sk customer_sk + ,ss_item_sk item_sk +from store_sales,date_dim +where ss_sold_date_sk = d_date_sk + and d_month_seq between 1200 and 1200 + 11 +group by ss_customer_sk + ,ss_item_sk), +csci as( + select cs_bill_customer_sk customer_sk + ,cs_item_sk item_sk +from catalog_sales,date_dim +where cs_sold_date_sk = d_date_sk + and d_month_seq between 1200 and 1200 + 11 +group by cs_bill_customer_sk + ,cs_item_sk) + select sum(case when ssci.customer_sk is not null and csci.customer_sk is null then 1 else 0 end) store_only + ,sum(case when ssci.customer_sk is null and csci.customer_sk is not null then 1 else 0 end) catalog_only + ,sum(case when ssci.customer_sk is not null and csci.customer_sk is not null then 1 else 0 end) store_and_catalog +from ssci full outer join csci on (ssci.customer_sk=csci.customer_sk + and ssci.item_sk = csci.item_sk) + limit 100 diff --git a/src/main/resources/tpcds/query98.sql b/src/main/resources/tpcds/query98.sql new file mode 100644 index 0000000000..2321ae8fc1 --- /dev/null +++ b/src/main/resources/tpcds/query98.sql @@ -0,0 +1,30 @@ +select i_item_id + ,i_item_desc + ,i_category + ,i_class + ,i_current_price + ,sum(ss_ext_sales_price) as itemrevenue + ,sum(ss_ext_sales_price)*100/sum(sum(ss_ext_sales_price)) over + (partition by i_class) as revenueratio +from + store_sales + ,item + ,date_dim +where + ss_item_sk = i_item_sk + and i_category in ('Sports', 'Books', 'Home') + and ss_sold_date_sk = d_date_sk + and d_date between cast('1999-02-22' as date) + and date_add(cast('1999-02-22' as date), 30 ) +group by + i_item_id + ,i_item_desc + ,i_category + ,i_class + ,i_current_price +order by + i_category + ,i_class + ,i_item_id + ,i_item_desc + ,revenueratio diff --git a/src/main/resources/tpcds/query99.sql b/src/main/resources/tpcds/query99.sql new file mode 100644 index 0000000000..61cf1b9524 --- /dev/null +++ b/src/main/resources/tpcds/query99.sql @@ -0,0 +1,32 @@ +select + substr(w_warehouse_name,1,20) + ,sm_type + ,cc_name + ,sum(case when (cs_ship_date_sk - cs_sold_date_sk <= 30 ) then 1 else 0 end) as "30_days" + ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 30) and + (cs_ship_date_sk - cs_sold_date_sk <= 60) then 1 else 0 end ) as "31_60_days" + ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 60) and + (cs_ship_date_sk - cs_sold_date_sk <= 90) then 1 else 0 end) as "61_90_days" + ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 90) and + (cs_ship_date_sk - cs_sold_date_sk <= 120) then 1 else 0 end) as "91_120_days" + ,sum(case when (cs_ship_date_sk - cs_sold_date_sk > 120) then 1 else 0 end) as above120_days +from + catalog_sales + ,warehouse + ,ship_mode + ,call_center + ,date_dim +where + d_month_seq between 1200 and 1200 + 11 +and cs_ship_date_sk = d_date_sk +and cs_warehouse_sk = w_warehouse_sk +and cs_ship_mode_sk = sm_ship_mode_sk +and cs_call_center_sk = cc_call_center_sk +group by + substr(w_warehouse_name,1,20) + ,sm_type + ,cc_name +order by substr(w_warehouse_name,1,20) + ,sm_type + ,cc_name + limit 100 diff --git a/src/main/resources/tpch/create_tables.sql b/src/main/resources/tpch/create_tables.sql new file mode 100644 index 0000000000..d30b1f8e82 --- /dev/null +++ b/src/main/resources/tpch/create_tables.sql @@ -0,0 +1,92 @@ +create table nation ( + N_NATIONKEY INT, + N_NAME STRING, + N_REGIONKEY INT, + N_COMMENT STRING, + primary key(N_NATIONKEY) +); + +create 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, + primary key(L_ORDERKEY, L_PARTKEY, L_SUPPKEY, L_LINENUMBER) +); + +create table orders ( + O_ORDERKEY INT, + O_CUSTKEY INT, + O_ORDERSTATUS STRING, + O_TOTALPRICE DOUBLE, + O_ORDERDATE STRING, + O_ORDERPRIORITY STRING, + O_CLERK STRING, + O_SHIPPRIORITY INT, + O_COMMENT STRING, + primary key(O_ORDERKEY) +); + +create table supplier( + S_SUPPKEY INT, + S_NAME STRING, + S_ADDRESS STRING, + S_NATIONKEY INT, + S_PHONE STRING, + S_ACCTBAL DOUBLE, + S_COMMENT STRING, + primary key(S_SUPPKEY) +); + +create table partsupp ( + PS_PARTKEY INT, + PS_SUPPKEY INT, + PS_AVAILQTY INT, + PS_SUPPLYCOST DOUBLE, + PS_COMMENT STRING, + primary key(PS_PARTKEY,PS_SUPPKEY) +); + +create table customer ( + C_CUSTKEY INT, + C_NAME STRING, + C_ADDRESS STRING, + C_NATIONKEY INT, + C_PHONE STRING, + C_ACCTBAL DOUBLE, + C_MKTSEGMENT STRING, + C_COMMENT STRING, + primary key(C_CUSTKEY) +); + +create 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, + primary key(P_PARTKEY) +); + +create table region ( + R_REGIONKEY INT, + R_NAME STRING, + R_COMMENT STRING, + primary key(R_REGIONKEY) +); diff --git a/src/main/resources/tpch/insert_lineitem_200.sql b/src/main/resources/tpch/insert_lineitem_200.sql new file mode 100644 index 0000000000..d9a1a0871e --- /dev/null +++ b/src/main/resources/tpch/insert_lineitem_200.sql @@ -0,0 +1 @@ +insert into lineitem VALUES (1,15519,785,1,17,24386.67,0.04,0.02,'N','O','1996-03-13','1996-02-12','1996-03-22','DELIVER IN PERSON','TRUCK','egular courts above the'),(1,6731,732,2,36,58958.28,0.09,0.06,'N','O','1996-04-12','1996-02-28','1996-04-20','TAKE BACK RETURN','MAIL','ly final dependencies: slyly bold '),(1,6370,371,3,8,10210.96,0.10,0.02,'N','O','1996-01-29','1996-03-05','1996-01-31','TAKE BACK RETURN','REG AIR','riously. regular, express dep'),(1,214,465,4,28,31197.88,0.09,0.06,'N','O','1996-04-21','1996-03-30','1996-05-16','NONE','AIR','lites. fluffily even de'),(1,2403,160,5,24,31329.60,0.10,0.04,'N','O','1996-03-30','1996-03-14','1996-04-01','NONE','FOB',' pending foxes. slyly re'),(1,1564,67,6,32,46897.92,0.07,0.02,'N','O','1996-01-30','1996-02-07','1996-02-03','DELIVER IN PERSON','MAIL','arefully slyly ex'),(2,10617,138,1,38,58049.18,0.00,0.05,'N','O','1997-01-28','1997-01-14','1997-02-02','TAKE BACK RETURN','RAIL','ven requests. deposits breach a'),(3,430,181,1,45,59869.35,0.06,0.00,'R','F','1994-02-02','1994-01-04','1994-02-23','NONE','AIR','ongside of the furiously brave acco'),(3,1904,658,2,49,88489.10,0.10,0.00,'R','F','1993-11-09','1993-12-20','1993-11-24','TAKE BACK RETURN','RAIL',' unusual accounts. eve'),(3,12845,370,3,27,47461.68,0.06,0.07,'A','F','1994-01-16','1993-11-22','1994-01-23','DELIVER IN PERSON','SHIP','nal foxes wake. '),(3,2938,191,4,2,3681.86,0.01,0.06,'A','F','1993-12-04','1994-01-07','1994-01-01','NONE','TRUCK','y. fluffily pending d'),(3,18310,115,5,28,34392.68,0.04,0.00,'R','F','1993-12-14','1994-01-10','1994-01-01','TAKE BACK RETURN','FOB','ages nag slyly pending'),(3,6215,984,6,26,29151.46,0.10,0.02,'A','F','1993-10-29','1993-12-18','1993-11-04','TAKE BACK RETURN','RAIL','ges sleep after the caref'),(4,8804,579,1,30,51384.00,0.03,0.08,'N','O','1996-01-10','1995-12-14','1996-01-18','DELIVER IN PERSON','REG AIR','- quickly regular packages sleep. idly'),(5,10857,858,1,15,26517.75,0.02,0.04,'R','F','1994-10-31','1994-08-31','1994-11-20','NONE','AIR','ts wake furiously '),(5,12393,394,2,26,33940.14,0.07,0.08,'R','F','1994-10-16','1994-09-25','1994-10-19','NONE','FOB','sts use slyly quickly special instruc'),(5,3754,8,3,50,82887.50,0.08,0.03,'A','F','1994-08-08','1994-10-13','1994-08-26','DELIVER IN PERSON','AIR','eodolites. fluffily unusual'),(6,13964,228,1,37,69484.52,0.08,0.03,'A','F','1992-04-27','1992-05-15','1992-05-02','TAKE BACK RETURN','TRUCK','p furiously special foxes'),(7,18206,11,1,12,13490.40,0.07,0.03,'N','O','1996-05-07','1996-03-13','1996-06-03','TAKE BACK RETURN','FOB','ss pinto beans wake against th'),(7,14525,790,2,9,12955.68,0.08,0.08,'N','O','1996-02-01','1996-03-02','1996-02-19','TAKE BACK RETURN','SHIP','es. instructions'),(7,9478,997,3,46,63823.62,0.10,0.07,'N','O','1996-01-15','1996-03-27','1996-02-03','COLLECT COD','MAIL',' unusual reques'),(7,16308,309,4,28,34280.40,0.03,0.04,'N','O','1996-03-21','1996-04-08','1996-04-20','NONE','FOB','. slyly special requests haggl'),(7,15190,986,5,38,41997.22,0.08,0.01,'N','O','1996-02-11','1996-02-24','1996-02-18','DELIVER IN PERSON','TRUCK','ns haggle carefully ironic deposits. bl'),(7,7926,184,6,35,64187.20,0.06,0.03,'N','O','1996-01-16','1996-02-23','1996-01-22','TAKE BACK RETURN','FOB','jole. excuses wake carefully alongside of '),(7,15724,255,7,5,8198.60,0.04,0.02,'N','O','1996-02-10','1996-03-26','1996-02-13','NONE','FOB','ithely regula'),(32,8271,788,1,28,33019.56,0.05,0.08,'N','O','1995-10-23','1995-08-27','1995-10-26','TAKE BACK RETURN','TRUCK','sleep quickly. req'),(32,19793,63,2,32,54809.28,0.02,0.00,'N','O','1995-08-14','1995-10-07','1995-08-27','COLLECT COD','AIR','lithely regular deposits. fluffily '),(32,4417,672,3,2,2642.82,0.09,0.02,'N','O','1995-08-07','1995-10-07','1995-08-23','DELIVER IN PERSON','AIR',' express accounts wake according to the'),(32,275,776,4,4,4701.08,0.09,0.03,'N','O','1995-08-04','1995-10-01','1995-09-03','NONE','REG AIR','e slyly final pac'),(32,8582,841,5,44,65585.52,0.05,0.06,'N','O','1995-08-28','1995-08-20','1995-09-14','DELIVER IN PERSON','AIR','symptotes nag according to the ironic depo'),(32,1162,414,6,6,6378.96,0.04,0.03,'N','O','1995-07-21','1995-09-23','1995-07-25','COLLECT COD','RAIL',' gifts cajole carefully.'),(33,6134,903,1,31,32244.03,0.09,0.04,'A','F','1993-10-29','1993-12-19','1993-11-08','COLLECT COD','TRUCK','ng to the furiously ironic package'),(33,6052,565,2,32,30657.60,0.02,0.05,'A','F','1993-12-09','1994-01-04','1993-12-28','COLLECT COD','MAIL','gular theodolites'),(33,13747,11,3,5,8303.70,0.05,0.03,'A','F','1993-12-09','1993-12-25','1993-12-23','TAKE BACK RETURN','AIR','. stealthily bold exc'),(33,3392,393,4,41,53110.99,0.09,0.00,'R','F','1993-11-09','1994-01-24','1993-11-11','TAKE BACK RETURN','MAIL','unusual packages doubt caref'),(34,8837,96,1,13,22695.79,0.00,0.07,'N','O','1998-10-23','1998-09-14','1998-11-06','NONE','REG AIR','nic accounts. deposits are alon'),(34,8942,201,2,22,40720.68,0.08,0.06,'N','O','1998-10-09','1998-10-16','1998-10-12','NONE','FOB','thely slyly p'),(34,16955,488,3,6,11231.70,0.02,0.06,'N','O','1998-10-30','1998-09-20','1998-11-05','NONE','FOB','ar foxes sleep '),(35,45,296,1,24,22680.96,0.02,0.00,'N','O','1996-02-21','1996-01-03','1996-03-18','TAKE BACK RETURN','FOB',', regular tithe'),(35,16194,461,2,34,37746.46,0.06,0.08,'N','O','1996-01-22','1996-01-06','1996-01-27','DELIVER IN PERSON','RAIL','s are carefully against the f'),(35,12090,877,3,7,7014.63,0.06,0.04,'N','O','1996-01-19','1995-12-22','1996-01-29','NONE','MAIL',' the carefully regular '),(35,8518,777,4,25,35662.75,0.06,0.05,'N','O','1995-11-26','1995-12-25','1995-12-21','DELIVER IN PERSON','SHIP',' quickly unti'),(35,11992,515,5,34,64735.66,0.08,0.06,'N','O','1995-11-08','1996-01-15','1995-11-26','COLLECT COD','MAIL','. silent, unusual deposits boost'),(35,3077,331,6,28,27441.96,0.03,0.02,'N','O','1996-02-01','1995-12-24','1996-02-28','COLLECT COD','RAIL','ly alongside of '),(36,11977,978,1,42,79336.74,0.09,0.00,'N','O','1996-02-03','1996-01-21','1996-02-23','COLLECT COD','SHIP',' careful courts. special '),(37,2263,516,1,40,46610.40,0.09,0.03,'A','F','1992-07-21','1992-08-01','1992-08-15','NONE','REG AIR','luffily regular requests. slyly final acco'),(37,12679,204,2,39,62075.13,0.05,0.02,'A','F','1992-07-02','1992-08-18','1992-07-28','TAKE BACK RETURN','RAIL','the final requests. ca'),(37,1291,543,3,43,51268.47,0.05,0.08,'A','F','1992-07-10','1992-07-06','1992-08-02','DELIVER IN PERSON','TRUCK','iously ste'),(38,17584,119,1,44,66069.52,0.04,0.02,'N','O','1996-09-29','1996-11-17','1996-09-30','COLLECT COD','MAIL','s. blithely unusual theodolites am'),(39,232,983,1,44,49818.12,0.09,0.06,'N','O','1996-11-14','1996-12-15','1996-12-12','COLLECT COD','RAIL','eodolites. careful'),(39,18659,464,2,26,41018.90,0.08,0.04,'N','O','1996-11-04','1996-10-20','1996-11-20','NONE','FOB','ckages across the slyly silent'),(39,6784,553,3,46,77775.88,0.06,0.08,'N','O','1996-09-26','1996-12-19','1996-10-26','DELIVER IN PERSON','AIR','he carefully e'),(39,2059,312,4,32,30753.60,0.07,0.05,'N','O','1996-10-02','1996-12-19','1996-10-14','COLLECT COD','MAIL','heodolites sleep silently pending foxes. ac'),(39,5452,963,5,43,58370.35,0.01,0.01,'N','O','1996-10-17','1996-11-14','1996-10-26','COLLECT COD','MAIL','yly regular i'),(39,9437,697,6,40,53857.20,0.06,0.05,'N','O','1996-12-08','1996-10-22','1997-01-01','COLLECT COD','AIR','quickly ironic fox'),(64,8596,597,1,21,31596.39,0.05,0.02,'R','F','1994-09-30','1994-09-18','1994-10-26','DELIVER IN PERSON','REG AIR','ch slyly final, thin platelets.'),(65,5970,481,1,26,48775.22,0.03,0.03,'A','F','1995-04-20','1995-04-25','1995-05-13','NONE','TRUCK','pending deposits nag even packages. ca'),(65,7382,897,2,22,28366.36,0.00,0.05,'N','O','1995-07-17','1995-06-04','1995-07-19','COLLECT COD','FOB',' ideas. special, r'),(65,139,390,3,21,21821.73,0.09,0.07,'N','O','1995-07-06','1995-05-14','1995-07-31','DELIVER IN PERSON','RAIL','bove the even packages. accounts nag carefu'),(66,11512,774,1,31,44128.81,0.00,0.08,'R','F','1994-02-19','1994-03-11','1994-02-20','TAKE BACK RETURN','RAIL','ut the unusual accounts sleep at the bo'),(66,17349,350,2,41,51919.94,0.04,0.07,'A','F','1994-02-21','1994-03-01','1994-03-18','COLLECT COD','AIR',' regular de'),(67,2164,921,1,4,4264.64,0.09,0.04,'N','O','1997-04-17','1997-01-31','1997-04-20','NONE','SHIP',' cajole thinly expres'),(67,2020,525,2,12,11064.24,0.09,0.05,'N','O','1997-01-27','1997-02-21','1997-02-22','NONE','REG AIR',' even packages cajole'),(67,17360,628,3,5,6386.80,0.03,0.07,'N','O','1997-02-20','1997-02-12','1997-02-21','DELIVER IN PERSON','TRUCK','y unusual packages thrash pinto '),(67,8752,753,4,44,73073.00,0.08,0.06,'N','O','1997-03-18','1997-01-29','1997-04-13','DELIVER IN PERSON','RAIL','se quickly above the even, express reques'),(67,4062,825,5,23,22219.38,0.05,0.07,'N','O','1997-04-19','1997-02-14','1997-05-06','DELIVER IN PERSON','REG AIR','ly regular deposit'),(67,17831,99,6,29,50716.07,0.02,0.05,'N','O','1997-01-25','1997-01-27','1997-01-27','DELIVER IN PERSON','FOB','ultipliers '),(68,707,958,1,3,4823.10,0.05,0.02,'N','O','1998-07-04','1998-06-05','1998-07-21','NONE','RAIL','fully special instructions cajole. furious'),(68,17518,320,2,46,66033.46,0.02,0.05,'N','O','1998-06-26','1998-06-07','1998-07-05','NONE','MAIL',' requests are unusual, regular pinto '),(68,3498,752,3,46,64468.54,0.04,0.05,'N','O','1998-08-13','1998-07-08','1998-08-29','NONE','RAIL','egular dependencies affix ironically along '),(68,9473,251,4,20,27649.40,0.07,0.01,'N','O','1998-06-27','1998-05-23','1998-07-02','NONE','REG AIR',' excuses integrate fluffily '),(68,8276,535,5,27,31975.29,0.03,0.06,'N','O','1998-06-19','1998-06-25','1998-06-29','DELIVER IN PERSON','SHIP','ccounts. deposits use. furiously'),(68,10257,518,6,30,35017.50,0.05,0.06,'N','O','1998-08-11','1998-07-11','1998-08-14','NONE','RAIL','oxes are slyly blithely fin'),(68,13925,189,7,41,75395.72,0.09,0.08,'N','O','1998-06-24','1998-06-27','1998-07-06','NONE','SHIP','eposits nag special ideas. furiousl'),(69,11521,783,1,48,68760.96,0.01,0.07,'A','F','1994-08-17','1994-08-11','1994-09-08','NONE','TRUCK','regular epitaphs. carefully even ideas hag'),(69,10418,939,2,32,42509.12,0.08,0.06,'A','F','1994-08-24','1994-08-17','1994-08-31','NONE','REG AIR','s sleep carefully bold, '),(69,13727,517,3,17,27892.24,0.09,0.00,'A','F','1994-07-02','1994-07-07','1994-07-03','TAKE BACK RETURN','AIR','final, pending instr'),(69,3751,258,4,3,4964.25,0.09,0.04,'R','F','1994-06-06','1994-07-27','1994-06-15','NONE','MAIL',' blithely final d'),(69,9207,726,5,42,46880.40,0.07,0.04,'R','F','1994-07-31','1994-07-26','1994-08-28','DELIVER IN PERSON','REG AIR','tect regular, speci'),(69,1851,103,6,23,40315.55,0.05,0.00,'A','F','1994-10-03','1994-08-06','1994-10-24','NONE','SHIP','nding accounts ca'),(70,6413,926,1,8,10555.28,0.03,0.08,'R','F','1994-01-12','1994-02-27','1994-01-14','TAKE BACK RETURN','FOB','ggle. carefully pending dependenc'),(70,19616,155,2,13,19962.93,0.06,0.06,'A','F','1994-03-03','1994-02-13','1994-03-26','COLLECT COD','AIR','lyly special packag'),(70,17981,783,3,1,1898.98,0.03,0.05,'R','F','1994-01-26','1994-03-05','1994-01-28','TAKE BACK RETURN','RAIL','quickly. fluffily unusual theodolites c'),(70,4574,83,4,11,16264.27,0.01,0.05,'A','F','1994-03-17','1994-03-17','1994-03-27','NONE','MAIL','alongside of the deposits. fur'),(70,3714,221,5,37,59855.27,0.09,0.04,'R','F','1994-02-13','1994-03-16','1994-02-21','COLLECT COD','MAIL','n accounts are. q'),(70,5566,332,6,19,27959.64,0.06,0.03,'A','F','1994-01-26','1994-02-17','1994-02-06','TAKE BACK RETURN','SHIP',' packages wake pending accounts.'),(71,6194,195,1,25,27504.75,0.09,0.07,'N','O','1998-04-10','1998-04-22','1998-04-11','COLLECT COD','FOB','ckly. slyly'),(71,6592,361,2,3,4495.77,0.09,0.07,'N','O','1998-05-23','1998-04-03','1998-06-02','COLLECT COD','SHIP','y. pinto beans haggle after the'),(71,3444,204,3,45,60634.80,0.00,0.07,'N','O','1998-02-23','1998-03-20','1998-03-24','DELIVER IN PERSON','SHIP',' ironic packages believe blithely a'),(71,9665,925,4,33,51963.78,0.00,0.01,'N','O','1998-04-12','1998-03-20','1998-04-15','NONE','FOB',' serve quickly fluffily bold deposi'),(71,10326,587,5,39,48216.48,0.08,0.06,'N','O','1998-01-29','1998-04-07','1998-02-18','DELIVER IN PERSON','RAIL','l accounts sleep across the pack'),(71,19564,103,6,34,50441.04,0.04,0.01,'N','O','1998-03-05','1998-04-22','1998-03-30','DELIVER IN PERSON','TRUCK','s cajole. '),(96,12308,95,1,23,28066.90,0.10,0.06,'A','F','1994-07-19','1994-06-29','1994-07-25','DELIVER IN PERSON','TRUCK','ep-- carefully reg'),(96,13539,540,2,30,43575.90,0.01,0.06,'R','F','1994-06-03','1994-05-29','1994-06-22','DELIVER IN PERSON','TRUCK','e quickly even ideas. furiou'),(97,11948,210,1,13,24179.22,0.00,0.02,'R','F','1993-04-01','1993-04-04','1993-04-08','NONE','TRUCK','ayers cajole against the furiously'),(97,4957,212,2,37,68892.15,0.02,0.06,'A','F','1993-04-13','1993-03-30','1993-04-14','DELIVER IN PERSON','SHIP','ic requests boost carefully quic'),(97,7770,542,3,19,31877.63,0.06,0.08,'R','F','1993-05-14','1993-03-05','1993-05-25','TAKE BACK RETURN','RAIL','gifts. furiously ironic packages cajole. '),(98,4022,23,1,28,25928.56,0.06,0.07,'A','F','1994-12-24','1994-10-25','1995-01-16','COLLECT COD','REG AIR',' pending, regular accounts s'),(98,10975,756,2,1,1885.97,0.00,0.00,'A','F','1994-12-01','1994-12-12','1994-12-15','DELIVER IN PERSON','TRUCK','. unusual instructions against'),(98,4471,472,3,14,19256.58,0.05,0.02,'A','F','1994-12-30','1994-11-22','1995-01-27','COLLECT COD','AIR',' cajole furiously. blithely ironic ideas '),(98,16718,719,4,10,16347.10,0.03,0.03,'A','F','1994-10-23','1994-11-08','1994-11-09','COLLECT COD','RAIL',' carefully. quickly ironic ideas'),(99,8712,487,1,10,16207.10,0.02,0.01,'A','F','1994-05-18','1994-06-03','1994-05-23','COLLECT COD','RAIL','kages. requ'),(99,12377,378,2,5,6446.85,0.02,0.07,'R','F','1994-05-06','1994-05-28','1994-05-20','TAKE BACK RETURN','RAIL','ests cajole fluffily waters. blithe'),(99,13409,199,3,42,55540.80,0.02,0.02,'A','F','1994-04-19','1994-05-18','1994-04-20','NONE','RAIL','kages are fluffily furiously ir'),(99,10834,95,4,36,62813.88,0.09,0.02,'A','F','1994-07-04','1994-04-17','1994-07-30','DELIVER IN PERSON','AIR','slyly. slyly e'),(100,6203,204,1,28,31057.60,0.04,0.05,'N','O','1998-05-08','1998-05-13','1998-06-07','COLLECT COD','TRUCK','sts haggle. slowl'),(100,11598,860,2,22,33210.98,0.00,0.07,'N','O','1998-06-24','1998-04-12','1998-06-29','DELIVER IN PERSON','SHIP','nto beans alongside of the fi'),(100,4615,870,3,46,69902.06,0.03,0.04,'N','O','1998-05-02','1998-04-10','1998-05-22','TAKE BACK RETURN','SHIP','ular accounts. even'),(100,3803,310,4,14,23895.20,0.06,0.03,'N','O','1998-05-22','1998-05-01','1998-06-03','COLLECT COD','MAIL','y. furiously ironic ideas gr'),(100,5344,110,5,37,46225.58,0.05,0.00,'N','O','1998-03-06','1998-04-16','1998-03-31','TAKE BACK RETURN','TRUCK','nd the quickly s'),(101,11829,613,1,49,85300.18,0.10,0.00,'N','O','1996-06-21','1996-05-27','1996-06-29','DELIVER IN PERSON','REG AIR','ts-- final packages sleep furiousl'),(101,16334,133,2,36,45011.88,0.00,0.01,'N','O','1996-05-19','1996-05-01','1996-06-04','DELIVER IN PERSON','AIR','tes. blithely pending dolphins x-ray f'),(101,13842,632,3,12,21070.08,0.06,0.02,'N','O','1996-03-29','1996-04-20','1996-04-12','COLLECT COD','MAIL','. quickly regular'),(102,8892,409,1,37,66632.93,0.06,0.00,'N','O','1997-07-24','1997-08-02','1997-08-07','TAKE BACK RETURN','SHIP','ully across the ideas. final deposit'),(102,16924,723,2,34,62591.28,0.03,0.08,'N','O','1997-08-09','1997-07-28','1997-08-26','TAKE BACK RETURN','SHIP','eposits cajole across'),(102,18233,502,3,25,28780.75,0.01,0.01,'N','O','1997-07-31','1997-07-24','1997-08-17','NONE','RAIL','bits. ironic accoun'),(102,6116,885,4,15,15331.65,0.07,0.07,'N','O','1997-06-02','1997-07-13','1997-06-04','DELIVER IN PERSON','SHIP','final packages. carefully even excu'),(103,19466,274,1,6,8312.76,0.03,0.05,'N','O','1996-10-11','1996-07-25','1996-10-28','NONE','FOB','cajole. carefully ex'),(103,1043,295,2,37,34929.48,0.02,0.07,'N','O','1996-09-17','1996-07-27','1996-09-20','TAKE BACK RETURN','MAIL','ies. quickly ironic requests use blithely'),(103,2844,845,3,23,40177.32,0.01,0.04,'N','O','1996-09-11','1996-09-18','1996-09-26','NONE','FOB','ironic accou'),(103,2903,408,4,32,57788.80,0.01,0.07,'N','O','1996-07-30','1996-08-06','1996-08-04','NONE','RAIL','kages doze. special, regular deposit'),(128,10683,944,1,38,60559.84,0.06,0.01,'A','F','1992-09-01','1992-08-27','1992-10-01','TAKE BACK RETURN','FOB',' cajole careful'),(129,287,538,1,46,54614.88,0.08,0.02,'R','F','1993-02-15','1993-01-24','1993-03-05','COLLECT COD','TRUCK','uietly bold theodolites. fluffil'),(129,18517,518,2,36,51678.36,0.01,0.02,'A','F','1992-11-25','1992-12-25','1992-12-09','TAKE BACK RETURN','REG AIR','packages are care'),(129,3945,199,3,33,61015.02,0.04,0.06,'A','F','1993-01-08','1993-02-14','1993-01-29','COLLECT COD','SHIP','sts nag bravely. fluffily'),(129,13514,41,4,34,48535.34,0.00,0.01,'R','F','1993-01-29','1993-02-14','1993-02-10','COLLECT COD','MAIL','quests. express ideas'),(129,3138,898,5,24,24987.12,0.06,0.00,'A','F','1992-12-07','1993-01-02','1992-12-11','TAKE BACK RETURN','FOB','uests. foxes cajole slyly after the ca'),(129,7705,477,6,22,35479.40,0.06,0.01,'R','F','1993-02-15','1993-01-31','1993-02-24','COLLECT COD','SHIP','e. fluffily regular '),(129,16857,390,7,1,1773.85,0.05,0.04,'R','F','1993-01-26','1993-01-08','1993-02-24','DELIVER IN PERSON','FOB','e carefully blithely bold dolp'),(130,12882,883,1,14,25128.32,0.08,0.05,'A','F','1992-08-15','1992-07-25','1992-09-13','COLLECT COD','RAIL',' requests. final instruction'),(130,174,425,2,48,51560.16,0.03,0.02,'R','F','1992-07-01','1992-07-12','1992-07-24','NONE','AIR','lithely alongside of the regu'),(130,1186,187,3,18,19569.24,0.04,0.08,'A','F','1992-07-04','1992-06-14','1992-07-29','DELIVER IN PERSON','MAIL',' slyly ironic decoys abou'),(130,11564,348,4,13,19182.28,0.09,0.02,'R','F','1992-06-26','1992-07-29','1992-07-05','NONE','FOB',' pending dolphins sleep furious'),(130,6913,426,5,31,56417.21,0.06,0.05,'R','F','1992-09-01','1992-07-18','1992-09-02','TAKE BACK RETURN','RAIL','thily about the ruth'),(131,16751,18,1,45,75048.75,0.10,0.02,'R','F','1994-09-14','1994-09-02','1994-10-04','NONE','FOB','ironic, bold accounts. careful'),(131,4426,935,2,50,66521.00,0.02,0.04,'A','F','1994-09-17','1994-08-10','1994-09-21','NONE','SHIP','ending requests. final, ironic pearls slee'),(131,18903,172,3,4,7287.60,0.04,0.03,'A','F','1994-09-20','1994-08-30','1994-09-23','COLLECT COD','REG AIR',' are carefully slyly i'),(132,14045,310,1,18,17262.72,0.00,0.08,'R','F','1993-07-10','1993-08-05','1993-07-13','NONE','TRUCK','ges. platelets wake furio'),(132,11906,907,2,43,78169.70,0.01,0.08,'R','F','1993-09-01','1993-08-16','1993-09-22','NONE','TRUCK','y pending theodolites'),(132,11442,443,3,32,43310.08,0.04,0.04,'A','F','1993-07-12','1993-08-05','1993-08-05','COLLECT COD','TRUCK','d instructions hagg'),(132,2809,566,4,23,39371.40,0.10,0.00,'A','F','1993-06-16','1993-08-27','1993-06-23','DELIVER IN PERSON','AIR','refully blithely bold acco'),(133,10344,605,1,27,33867.18,0.00,0.02,'N','O','1997-12-21','1998-02-23','1997-12-27','TAKE BACK RETURN','MAIL','yly even gifts after the sl'),(133,17628,430,2,12,18547.44,0.02,0.06,'N','O','1997-12-02','1998-01-15','1997-12-29','DELIVER IN PERSON','REG AIR','ts cajole fluffily quickly i'),(133,11735,519,3,29,47755.17,0.09,0.08,'N','O','1998-02-28','1998-01-30','1998-03-09','DELIVER IN PERSON','RAIL',' the carefully regular theodoli'),(133,8986,761,4,11,20844.78,0.06,0.01,'N','O','1998-03-21','1998-01-15','1998-04-04','DELIVER IN PERSON','REG AIR','e quickly across the dolphins'),(134,65,66,1,21,20266.26,0.00,0.03,'A','F','1992-07-17','1992-07-08','1992-07-26','COLLECT COD','SHIP','s. quickly regular'),(134,16465,998,2,35,48351.10,0.06,0.07,'A','F','1992-08-23','1992-06-01','1992-08-24','NONE','MAIL','ajole furiously. instructio'),(134,18826,363,3,26,45365.32,0.09,0.06,'A','F','1992-06-20','1992-07-12','1992-07-16','NONE','RAIL',' among the pending depos'),(134,14401,402,4,47,61823.80,0.05,0.00,'A','F','1992-08-16','1992-07-06','1992-08-28','NONE','REG AIR','s! carefully unusual requests boost careful'),(134,3518,519,5,12,17058.12,0.05,0.02,'A','F','1992-07-03','1992-06-01','1992-07-11','COLLECT COD','TRUCK','nts are quic'),(134,13311,575,6,12,14691.72,0.00,0.00,'A','F','1992-08-08','1992-07-07','1992-08-20','TAKE BACK RETURN','FOB','lyly regular pac'),(135,10821,822,1,47,81395.54,0.06,0.08,'N','O','1996-02-18','1996-01-01','1996-02-25','COLLECT COD','RAIL','ctions wake slyly abo'),(135,19835,643,2,21,36851.43,0.00,0.07,'N','O','1996-02-11','1996-01-12','1996-02-13','DELIVER IN PERSON','SHIP',' deposits believe. furiously regular p'),(135,15751,547,3,33,55002.75,0.02,0.00,'N','O','1996-01-03','1995-11-21','1996-02-01','TAKE BACK RETURN','MAIL','ptotes boost slowly care'),(135,6701,958,4,34,54661.80,0.02,0.03,'N','O','1996-01-12','1996-01-19','1996-02-05','NONE','TRUCK','counts doze against the blithely ironi'),(135,13625,152,5,20,30772.40,0.01,0.04,'N','O','1996-01-25','1995-11-20','1996-02-09','NONE','MAIL','theodolites. quickly p'),(135,11500,284,6,13,18349.50,0.04,0.02,'N','O','1995-11-12','1995-12-22','1995-11-17','NONE','FOB','nal ideas. final instr'),(160,1479,982,1,36,49696.92,0.07,0.01,'N','O','1997-03-11','1997-03-11','1997-03-20','COLLECT COD','MAIL','old, ironic deposits are quickly abov'),(160,8639,898,2,22,34047.86,0.00,0.04,'N','O','1997-02-18','1997-03-05','1997-03-05','COLLECT COD','RAIL','ncies about the request'),(160,2008,513,3,34,30940.00,0.01,0.05,'N','O','1997-01-31','1997-03-13','1997-02-14','NONE','FOB','st sleep even gifts. dependencies along'),(161,10281,62,1,19,22634.32,0.01,0.01,'A','F','1994-12-13','1994-11-19','1994-12-26','DELIVER IN PERSON','TRUCK',', regular sheaves sleep along'),(162,18929,466,1,2,3695.84,0.02,0.01,'N','O','1995-09-02','1995-06-17','1995-09-08','COLLECT COD','FOB','es! final somas integrate'),(163,16755,554,1,43,71885.25,0.01,0.00,'N','O','1997-09-19','1997-11-19','1997-10-03','COLLECT COD','REG AIR','al, bold dependencies wake. iron'),(163,12071,72,2,13,12779.91,0.01,0.04,'N','O','1997-11-11','1997-10-18','1997-12-07','DELIVER IN PERSON','TRUCK','inal requests. even pinto beans hag'),(163,3682,936,3,27,42813.36,0.04,0.08,'N','O','1997-12-26','1997-11-28','1998-01-05','COLLECT COD','REG AIR','ously express dependen'),(163,19265,535,4,5,5921.30,0.02,0.00,'N','O','1997-11-17','1997-10-09','1997-12-05','DELIVER IN PERSON','TRUCK',' must belie'),(163,12609,872,5,12,18259.20,0.10,0.00,'N','O','1997-12-18','1997-10-26','1997-12-22','COLLECT COD','TRUCK','ly blithe accounts cajole '),(163,19083,622,6,20,20041.60,0.00,0.07,'N','O','1997-09-27','1997-11-15','1997-10-07','TAKE BACK RETURN','FOB','tructions integrate b'),(164,9131,391,1,26,27043.38,0.09,0.04,'A','F','1993-01-04','1992-11-21','1993-01-07','NONE','RAIL','s. blithely special courts are blithel'),(164,1849,352,2,24,42020.16,0.05,0.05,'R','F','1992-12-22','1992-11-27','1993-01-06','NONE','AIR','side of the slyly unusual theodolites. f'),(164,12551,338,3,38,55614.90,0.03,0.06,'R','F','1992-12-04','1992-11-23','1993-01-02','TAKE BACK RETURN','AIR','counts cajole fluffily regular packages. b'),(164,1753,5,4,32,52952.00,0.05,0.01,'R','F','1992-12-21','1992-12-23','1992-12-28','COLLECT COD','RAIL','ts wake again'),(164,14751,280,5,43,71627.25,0.06,0.01,'R','F','1992-11-26','1993-01-03','1992-12-08','COLLECT COD','RAIL','y carefully regular dep'),(164,10890,891,6,27,48624.03,0.10,0.04,'R','F','1992-12-23','1993-01-16','1993-01-10','DELIVER IN PERSON','AIR','ayers wake carefully a'),(164,304,555,7,23,27698.90,0.09,0.04,'A','F','1992-11-03','1992-12-02','1992-11-12','NONE','REG AIR','ress packages haggle ideas. blithely spec'),(165,3318,825,1,3,3663.93,0.01,0.08,'R','F','1993-03-29','1993-03-06','1993-04-12','DELIVER IN PERSON','REG AIR','riously requests. depos'),(165,16163,962,2,43,46403.88,0.08,0.05,'R','F','1993-02-27','1993-04-19','1993-03-03','DELIVER IN PERSON','TRUCK','jole slyly according '),(165,5852,618,3,15,26367.75,0.00,0.05,'R','F','1993-04-10','1993-03-29','1993-05-01','COLLECT COD','SHIP',' bold packages mainta'),(165,13919,446,4,49,89812.59,0.07,0.06,'A','F','1993-02-20','1993-04-02','1993-03-10','COLLECT COD','REG AIR','uses sleep slyly ruthlessly regular a'),(165,15509,775,5,27,38461.50,0.01,0.04,'R','F','1993-04-27','1993-03-04','1993-05-13','NONE','MAIL','around the ironic, even orb'),(166,6489,2,1,37,51632.76,0.09,0.03,'N','O','1995-11-16','1995-10-17','1995-12-13','NONE','MAIL','lar frays wake blithely a'),(166,16637,638,2,13,20197.19,0.09,0.05,'N','O','1995-11-09','1995-11-18','1995-11-14','COLLECT COD','SHIP','fully above the blithely fina'),(166,9966,226,3,41,76914.36,0.07,0.03,'N','O','1995-11-13','1995-11-07','1995-12-08','COLLECT COD','FOB','hily along the blithely pending fo'),(166,4503,758,4,8,11260.00,0.05,0.02,'N','O','1995-12-30','1995-11-29','1996-01-29','DELIVER IN PERSON','RAIL','e carefully bold '),(167,10118,119,1,28,28787.08,0.06,0.01,'R','F','1993-02-19','1993-02-16','1993-03-03','DELIVER IN PERSON','TRUCK','sly during the u'),(167,17156,424,2,27,28975.05,0.09,0.00,'R','F','1993-05-01','1993-03-31','1993-05-31','TAKE BACK RETURN','FOB','eans affix furiously-- packages'),(192,9702,221,1,23,37069.10,0.00,0.00,'N','O','1998-02-05','1998-02-06','1998-03-07','TAKE BACK RETURN','AIR','ly pending theodolites haggle quickly fluf'),(192,16137,936,2,20,21062.60,0.07,0.01,'N','O','1998-03-13','1998-02-02','1998-03-31','TAKE BACK RETURN','REG AIR','tes. carefu'),(192,11026,549,3,15,14055.30,0.09,0.01,'N','O','1998-01-30','1998-02-10','1998-02-23','TAKE BACK RETURN','TRUCK','he ironic requests haggle about'),(192,19640,448,4,2,3119.28,0.06,0.02,'N','O','1998-03-06','1998-02-03','1998-03-24','COLLECT COD','SHIP','s. dependencies nag furiously alongside'),(192,8292,809,5,25,30007.25,0.02,0.03,'N','O','1998-02-15','1998-01-11','1998-03-17','COLLECT COD','TRUCK','. carefully regular'),(192,14101,366,6,45,45679.50,0.00,0.05,'N','O','1998-03-11','1998-01-09','1998-04-03','NONE','MAIL','equests. ideas sleep idea'),(193,9264,524,1,9,10559.34,0.06,0.06,'A','F','1993-09-17','1993-10-08','1993-09-30','COLLECT COD','TRUCK','against the fluffily regular d'),(193,15396,192,2,15,19670.85,0.02,0.07,'R','F','1993-11-22','1993-10-09','1993-12-05','TAKE BACK RETURN','SHIP','ffily. regular packages d'),(193,9388,648,3,23,29839.74,0.06,0.05,'A','F','1993-08-21','1993-10-11','1993-09-02','DELIVER IN PERSON','TRUCK','ly even accounts wake blithely bold'),(194,260,511,1,17,19724.42,0.05,0.04,'R','F','1992-05-24','1992-05-22','1992-05-30','COLLECT COD','AIR',' regular deposi'),(194,18353,622,2,1,1271.35,0.04,0.06,'R','F','1992-04-30','1992-05-18','1992-05-23','NONE','REG AIR',' regular theodolites. regular, iron'),(194,6600,369,3,13,19585.80,0.08,0.08,'A','F','1992-05-07','1992-06-18','1992-05-10','NONE','AIR','about the blit'),(194,14515,516,4,36,51462.36,0.00,0.05,'R','F','1992-05-21','1992-05-18','1992-05-27','TAKE BACK RETURN','RAIL','pecial packages wake after the slyly r'),(194,5618,129,5,8,12188.88,0.04,0.00,'R','F','1992-07-06','1992-06-25','1992-07-11','COLLECT COD','FOB','uriously unusual excuses'),(194,14899,164,6,16,29022.24,0.06,0.03,'A','F','1992-05-14','1992-06-14','1992-05-21','TAKE BACK RETURN','TRUCK','y regular requests. furious') \ No newline at end of file diff --git a/src/main/resources/tpch/q1.sql b/src/main/resources/tpch/q1.sql new file mode 100644 index 0000000000..67424c82af --- /dev/null +++ b/src/main/resources/tpch/q1.sql @@ -0,0 +1,22 @@ +-- database: presto; groups: tpch; tables: lineitem +SELECT + l_returnflag, + l_linestatus, + sum(l_quantity) AS sum_qty, + sum(l_extendedprice) AS sum_base_price, + sum(l_extendedprice * (1 - l_discount)) AS sum_disc_price, + sum(l_extendedprice * (1 - l_discount) * (1 + l_tax)) AS sum_charge, + avg(l_quantity) AS avg_qty, + avg(l_extendedprice) AS avg_price, + avg(l_discount) AS avg_disc, + count(*) AS count_order +FROM + lineitem +WHERE + l_shipdate <= DATE '1998-12-01' - INTERVAL '90' DAY +GROUP BY +l_returnflag, +l_linestatus +ORDER BY +l_returnflag, +l_linestatus diff --git a/src/main/resources/tpch/q10.sql b/src/main/resources/tpch/q10.sql new file mode 100644 index 0000000000..f9579f7a38 --- /dev/null +++ b/src/main/resources/tpch/q10.sql @@ -0,0 +1,33 @@ +-- database: presto; groups: tpch; tables: customer,orders,lineitem,nation +SELECT + c_custkey, + c_name, + sum(l_extendedprice * (1 - l_discount)) AS revenue, + c_acctbal, + n_name, + c_address, + c_phone, + c_comment +FROM + customer, + orders, + lineitem, + nation +WHERE + c_custkey = o_custkey + AND l_orderkey = o_orderkey + AND o_orderdate >= DATE '1993-10-01' + AND o_orderdate < DATE '1993-10-01' + INTERVAL '3' MONTH + AND l_returnflag = 'R' + AND c_nationkey = n_nationkey +GROUP BY + c_custkey, + c_name, + c_acctbal, + c_phone, + n_name, + c_address, + c_comment +ORDER BY + revenue DESC +LIMIT 20 diff --git a/src/main/resources/tpch/q11.sql b/src/main/resources/tpch/q11.sql new file mode 100644 index 0000000000..8bd691e25f --- /dev/null +++ b/src/main/resources/tpch/q11.sql @@ -0,0 +1,27 @@ +SELECT + ps_partkey, + sum(ps_supplycost * ps_availqty) AS value +FROM + partsupp, + supplier, + nation +WHERE + ps_suppkey = s_suppkey + AND s_nationkey = n_nationkey + AND n_name = 'GERMANY' +GROUP BY + ps_partkey +HAVING + sum(ps_supplycost * ps_availqty) > ( + SELECT sum(ps_supplycost * ps_availqty) * 0.0001 + FROM + partsupp, + supplier, + nation + WHERE + ps_suppkey = s_suppkey + AND s_nationkey = n_nationkey + AND n_name = 'GERMANY' + ) +ORDER BY + value DESC diff --git a/src/main/resources/tpch/q12.sql b/src/main/resources/tpch/q12.sql new file mode 100644 index 0000000000..16f477ff59 --- /dev/null +++ b/src/main/resources/tpch/q12.sql @@ -0,0 +1,29 @@ +-- database: presto; groups: tpch; tables: orders,lineitem +SELECT + l_shipmode, + sum(CASE + WHEN o_orderpriority = '1-URGENT' + OR o_orderpriority = '2-HIGH' + THEN 1 + ELSE 0 + END) AS high_line_count, + sum(CASE + WHEN o_orderpriority <> '1-URGENT' + AND o_orderpriority <> '2-HIGH' + THEN 1 + ELSE 0 + END) AS low_line_count +FROM + orders, + lineitem +WHERE + o_orderkey = l_orderkey + AND l_shipmode IN ('MAIL', 'SHIP') + AND l_commitdate < l_receiptdate + AND l_shipdate < l_commitdate + AND l_receiptdate >= DATE '1994-01-01' + AND l_receiptdate < DATE '1994-01-01' + INTERVAL '1' YEAR +GROUP BY + l_shipmode +ORDER BY + l_shipmode diff --git a/src/main/resources/tpch/q13.sql b/src/main/resources/tpch/q13.sql new file mode 100644 index 0000000000..84603c8f50 --- /dev/null +++ b/src/main/resources/tpch/q13.sql @@ -0,0 +1,21 @@ +-- database: presto; groups: tpch; tables: customer +SELECT + c_count, + count(*) AS custdist +FROM ( + SELECT + c_custkey, + count(o_orderkey) + FROM + customer + LEFT OUTER JOIN orders ON + c_custkey = o_custkey + AND o_comment NOT LIKE '%special%requests%' + GROUP BY + c_custkey + ) AS c_orders (c_custkey, c_count) +GROUP BY + c_count +ORDER BY + custdist DESC, + c_count DESC diff --git a/src/main/resources/tpch/q14.sql b/src/main/resources/tpch/q14.sql new file mode 100644 index 0000000000..9df5f443a8 --- /dev/null +++ b/src/main/resources/tpch/q14.sql @@ -0,0 +1,13 @@ +-- database: presto; groups: tpch; tables: lineitem,part +SELECT 100.00 * sum(CASE + WHEN p_type LIKE 'PROMO%' + THEN l_extendedprice * (1 - l_discount) + ELSE 0 + END) / sum(l_extendedprice * (1 - l_discount)) AS promo_revenue +FROM + lineitem, + part +WHERE + l_partkey = p_partkey + AND l_shipdate >= DATE '1995-09-01' + AND l_shipdate < DATE '1995-09-01' + INTERVAL '1' MONTH diff --git a/src/main/resources/tpch/q15.sql b/src/main/resources/tpch/q15.sql new file mode 100644 index 0000000000..6fd8d4f8e0 --- /dev/null +++ b/src/main/resources/tpch/q15.sql @@ -0,0 +1,15 @@ +WITH revenue0 AS +( +SELECT l_suppkey AS supplier_no, sum(l_extendedprice * (1 - l_discount)) AS total_revenue +FROM lineitem +WHERE date_parse(l_shipdate, '%Y-%m-%d %H:%i:%s') >= DATE '1993-01-01' +AND date_parse(l_shipdate, '%Y-%m-%d %H:%i:%s') < DATE '1993-01-01' + interval '3' month +GROUP BY l_suppkey +) +SELECT s_suppkey, s_name, s_address, s_phone, total_revenue +FROM supplier_rcfile_string, revenue0 +WHERE s_suppkey = supplier_no +AND total_revenue IN ( + SELECT max(total_revenue) + FROM revenue0 ) +ORDER BY s_suppkey \ No newline at end of file diff --git a/src/main/resources/tpch/q16.sql b/src/main/resources/tpch/q16.sql new file mode 100644 index 0000000000..b0935dfe2d --- /dev/null +++ b/src/main/resources/tpch/q16.sql @@ -0,0 +1,30 @@ +-- database: presto; groups: tpch; tables: partsupp,part,supplier +SELECT + p_brand, + p_type, + p_size, + count(DISTINCT ps_suppkey) AS supplier_cnt +FROM + partsupp, + part +WHERE + p_partkey = ps_partkey + AND p_brand <> 'Brand#45' + AND p_type NOT LIKE 'MEDIUM POLISHED%' + AND p_size IN (49, 14, 23, 45, 19, 3, 36, 9) + AND ps_suppkey NOT IN ( + SELECT s_suppkey + FROM + supplier + WHERE + s_comment LIKE '%Customer%Complaints%' + ) +GROUP BY + p_brand, + p_type, + p_size +ORDER BY + supplier_cnt DESC, + p_brand, + p_type, + p_size diff --git a/src/main/resources/tpch/q17.sql b/src/main/resources/tpch/q17.sql new file mode 100644 index 0000000000..8ed8cd84ac --- /dev/null +++ b/src/main/resources/tpch/q17.sql @@ -0,0 +1,16 @@ +-- database: presto; groups: tpch; tables: lineitem,part +SELECT sum(l_extendedprice) / 7.0 AS avg_yearly +FROM + lineitem, + part +WHERE + p_partkey = l_partkey + AND p_brand = 'Brand#23' + AND p_container = 'MED BOX' + AND l_quantity < ( + SELECT 0.2 * avg(l_quantity) + FROM + lineitem + WHERE + l_partkey = p_partkey + ) diff --git a/src/main/resources/tpch/q18.sql b/src/main/resources/tpch/q18.sql new file mode 100644 index 0000000000..ab1d73a361 --- /dev/null +++ b/src/main/resources/tpch/q18.sql @@ -0,0 +1,34 @@ +-- database: presto; groups: tpch, big_query; tables: customer,orders,lineitem +SELECT + c_name, + c_custkey, + o_orderkey, + o_orderdate, + o_totalprice, + sum(l_quantity) +FROM + customer, + orders, + lineitem +WHERE + o_orderkey IN ( + SELECT l_orderkey + FROM + lineitem + GROUP BY + l_orderkey + HAVING + sum(l_quantity) > 300 + ) + AND c_custkey = o_custkey + AND o_orderkey = l_orderkey +GROUP BY + c_name, + c_custkey, + o_orderkey, + o_orderdate, + o_totalprice +ORDER BY + o_totalprice DESC, + o_orderdate +LIMIT 100 diff --git a/src/main/resources/tpch/q19.sql b/src/main/resources/tpch/q19.sql new file mode 100644 index 0000000000..d8a15914da --- /dev/null +++ b/src/main/resources/tpch/q19.sql @@ -0,0 +1,35 @@ +-- database: presto; groups: tpch; tables: lineitem,part +SELECT sum(l_extendedprice * (1 - l_discount)) AS revenue +FROM + lineitem, + part +WHERE + ( + p_partkey = l_partkey + AND p_brand = 'Brand#12' + AND p_container IN ('SM CASE', 'SM BOX', 'SM PACK', 'SM PKG') + AND l_quantity >= 1 AND l_quantity <= 1 + 10 + AND p_size BETWEEN 1 AND 5 + AND l_shipmode IN ('AIR', 'AIR REG') + AND l_shipinstruct = 'DELIVER IN PERSON' + ) + OR + ( + p_partkey = l_partkey + AND p_brand = 'Brand#23' + AND p_container IN ('MED BAG', 'MED BOX', 'MED PKG', 'MED PACK') + AND l_quantity >= 10 AND l_quantity <= 10 + 10 + AND p_size BETWEEN 1 AND 10 + AND l_shipmode IN ('AIR', 'AIR REG') + AND l_shipinstruct = 'DELIVER IN PERSON' + ) + OR + ( + p_partkey = l_partkey + AND p_brand = 'Brand#34' + AND p_container IN ('LG CASE', 'LG BOX', 'LG PACK', 'LG PKG') + AND l_quantity >= 20 AND l_quantity <= 20 + 10 + AND p_size BETWEEN 1 AND 15 + AND l_shipmode IN ('AIR', 'AIR REG') + AND l_shipinstruct = 'DELIVER IN PERSON' + ) diff --git a/src/main/resources/tpch/q2.sql b/src/main/resources/tpch/q2.sql new file mode 100644 index 0000000000..c87f09d937 --- /dev/null +++ b/src/main/resources/tpch/q2.sql @@ -0,0 +1,42 @@ +-- database: presto; groups: tpch; tables: part,supplier,partsupp,nation,region +SELECT + s_acctbal, + s_name, + n_name, + p_partkey, + p_mfgr, + s_address, + s_phone, + s_comment +FROM + part, + supplier, + partsupp, + nation, + region +WHERE + p_partkey = ps_partkey + AND s_suppkey = ps_suppkey + AND p_size = 15 + AND p_type LIKE '%BRASS' + AND s_nationkey = n_nationkey + AND n_regionkey = r_regionkey + AND r_name = 'EUROPE' + AND ps_supplycost = ( + SELECT min(ps_supplycost) + FROM + partsupp, supplier, + nation, region + WHERE + p_partkey = ps_partkey + AND s_suppkey = ps_suppkey + AND s_nationkey = n_nationkey + AND n_regionkey = r_regionkey + AND r_name = 'EUROPE' + ) +ORDER BY + s_acctbal DESC, + n_name, + s_name, + p_partkey +LIMIT 100 diff --git a/src/main/resources/tpch/q20.sql b/src/main/resources/tpch/q20.sql new file mode 100644 index 0000000000..255da61965 --- /dev/null +++ b/src/main/resources/tpch/q20.sql @@ -0,0 +1,33 @@ +-- database: presto; groups: tpch; tables: supplier,nation,partsupp,lineitem,part +SELECT + s_name, + s_address +FROM + supplier, nation +WHERE + s_suppkey IN ( + SELECT ps_suppkey + FROM + partsupp + WHERE + ps_partkey IN ( + SELECT p_partkey + FROM + part + WHERE + p_name LIKE 'forest%' + ) + AND ps_availqty > ( + SELECT 0.5 * sum(l_quantity) + FROM + lineitem + WHERE + l_partkey = ps_partkey + AND l_suppkey = ps_suppkey + AND l_shipdate >= date('1994-01-01') + AND l_shipdate < date('1994-01-01') + interval '1' YEAR +) +) +AND s_nationkey = n_nationkey +AND n_name = 'CANADA' +ORDER BY s_name diff --git a/src/main/resources/tpch/q21.sql b/src/main/resources/tpch/q21.sql new file mode 100644 index 0000000000..484303d875 --- /dev/null +++ b/src/main/resources/tpch/q21.sql @@ -0,0 +1,39 @@ +-- database: presto; groups: tpch,big_query; tables: supplier,lineitem,orders,nation +SELECT + s_name, + count(*) AS numwait +FROM + supplier, + lineitem l1, + orders, + nation +WHERE + s_suppkey = l1.l_suppkey + AND o_orderkey = l1.l_orderkey + AND o_orderstatus = 'F' + AND l1.l_receiptdate > l1.l_commitdate + AND exists( + SELECT * + FROM + lineitem l2 + WHERE + l2.l_orderkey = l1.l_orderkey + AND l2.l_suppkey <> l1.l_suppkey + ) + AND NOT exists( + SELECT * + FROM + lineitem l3 + WHERE + l3.l_orderkey = l1.l_orderkey + AND l3.l_suppkey <> l1.l_suppkey + AND l3.l_receiptdate > l3.l_commitdate + ) + AND s_nationkey = n_nationkey + AND n_name = 'SAUDI ARABIA' +GROUP BY + s_name +ORDER BY + numwait DESC, + s_name +LIMIT 100 diff --git a/src/main/resources/tpch/q22.sql b/src/main/resources/tpch/q22.sql new file mode 100644 index 0000000000..fd86397d13 --- /dev/null +++ b/src/main/resources/tpch/q22.sql @@ -0,0 +1,35 @@ +-- database: presto; groups: tpch; tables: orders,customer +SELECT + cntrycode, + count(*) AS numcust, + sum(c_acctbal) AS totacctbal +FROM ( + SELECT + substr(c_phone, 1, 2) AS cntrycode, + c_acctbal + FROM + customer + WHERE + substr(c_phone, 1, 2) IN + ('13', '31', '23', '29', '30', '18', '17') + AND c_acctbal > ( + SELECT avg(c_acctbal) + FROM + customer + WHERE + c_acctbal > 0.00 + AND substr(c_phone, 1, 2) IN + ('13', '31', '23', '29', '30', '18', '17') + ) + AND NOT exists( + SELECT * + FROM + orders + WHERE + o_custkey = c_custkey + ) + ) AS custsale +GROUP BY + cntrycode +ORDER BY + cntrycode diff --git a/src/main/resources/tpch/q3.sql b/src/main/resources/tpch/q3.sql new file mode 100644 index 0000000000..53756183ae --- /dev/null +++ b/src/main/resources/tpch/q3.sql @@ -0,0 +1,24 @@ +-- database: presto; groups: tpch; tables: customer,orders,lineitem +SELECT + l_orderkey, + sum(l_extendedprice * (1 - l_discount)) AS revenue, + o_orderdate, + o_shippriority +FROM + customer, + orders, + lineitem +WHERE + c_mktsegment = 'BUILDING' + AND c_custkey = o_custkey + AND l_orderkey = o_orderkey + AND o_orderdate < DATE '1995-03-15' + AND l_shipdate > DATE '1995-03-15' +GROUP BY + l_orderkey, + o_orderdate, + o_shippriority +ORDER BY + revenue DESC, + o_orderdate +LIMIT 10 diff --git a/src/main/resources/tpch/q4.sql b/src/main/resources/tpch/q4.sql new file mode 100644 index 0000000000..7fb40265f3 --- /dev/null +++ b/src/main/resources/tpch/q4.sql @@ -0,0 +1,19 @@ +-- database: presto; groups: tpch; tables: orders,lineitem +SELECT + o_orderpriority, + count(*) AS order_count +FROM orders +WHERE + o_orderdate >= DATE '1993-07-01' + AND o_orderdate < DATE '1993-07-01' + INTERVAL '3' MONTH +AND EXISTS ( +SELECT * +FROM lineitem +WHERE +l_orderkey = o_orderkey +AND l_commitdate < l_receiptdate +) +GROUP BY +o_orderpriority +ORDER BY +o_orderpriority diff --git a/src/main/resources/tpch/q5.sql b/src/main/resources/tpch/q5.sql new file mode 100644 index 0000000000..58ec7efacc --- /dev/null +++ b/src/main/resources/tpch/q5.sql @@ -0,0 +1,25 @@ +-- database: presto; groups: big_query, tpch; tables: customer,orders,lineitem,supplier,nation,region +SELECT + n_name, + sum(l_extendedprice * (1 - l_discount)) AS revenue +FROM + customer, + orders, + lineitem, + supplier, + nation, + region +WHERE + c_custkey = o_custkey + AND l_orderkey = o_orderkey + AND l_suppkey = s_suppkey + AND c_nationkey = s_nationkey + AND s_nationkey = n_nationkey + AND n_regionkey = r_regionkey + AND r_name = 'ASIA' + AND o_orderdate >= DATE '1994-01-01' + AND o_orderdate < DATE '1994-01-01' + INTERVAL '1' YEAR +GROUP BY +n_name +ORDER BY +revenue DESC diff --git a/src/main/resources/tpch/q6.sql b/src/main/resources/tpch/q6.sql new file mode 100644 index 0000000000..d58319e4d2 --- /dev/null +++ b/src/main/resources/tpch/q6.sql @@ -0,0 +1,9 @@ +-- database: presto; groups: tpch; tables: lineitem +SELECT sum(l_extendedprice * l_discount) AS revenue +FROM + lineitem +WHERE + l_shipdate >= DATE '1994-01-01' + AND l_shipdate < DATE '1994-01-01' + INTERVAL '1' YEAR +AND l_discount BETWEEN decimal '0.06' - decimal '0.01' AND decimal '0.06' + decimal '0.01' +AND l_quantity < 24 diff --git a/src/main/resources/tpch/q7.sql b/src/main/resources/tpch/q7.sql new file mode 100644 index 0000000000..153465c7fa --- /dev/null +++ b/src/main/resources/tpch/q7.sql @@ -0,0 +1,39 @@ +-- database: presto; groups: tpch; tables: supplier,lineitem,orders,customer,nation +SELECT + supp_nation, + cust_nation, + l_year, + sum(volume) AS revenue +FROM ( + SELECT + n1.n_name AS supp_nation, + n2.n_name AS cust_nation, + extract(YEAR FROM l_shipdate) AS l_year, + l_extendedprice * (1 - l_discount) AS volume + FROM + supplier, + lineitem, + orders, + customer, + nation n1, + nation n2 + WHERE + s_suppkey = l_suppkey + AND o_orderkey = l_orderkey + AND c_custkey = o_custkey + AND s_nationkey = n1.n_nationkey + AND c_nationkey = n2.n_nationkey + AND ( + (n1.n_name = 'FRANCE' AND n2.n_name = 'GERMANY') + OR (n1.n_name = 'GERMANY' AND n2.n_name = 'FRANCE') + ) + AND l_shipdate BETWEEN DATE '1995-01-01' AND DATE '1996-12-31' + ) AS shipping +GROUP BY + supp_nation, + cust_nation, + l_year +ORDER BY + supp_nation, + cust_nation, + l_year diff --git a/src/main/resources/tpch/q8.sql b/src/main/resources/tpch/q8.sql new file mode 100644 index 0000000000..a43b1cd3a3 --- /dev/null +++ b/src/main/resources/tpch/q8.sql @@ -0,0 +1,38 @@ +-- database: presto; groups: tpch, big_query; tables: part,supplier,lineitem,orders,customer,nation +SELECT + o_year, + sum(CASE + WHEN nation = 'BRAZIL' + THEN volume + ELSE 0 + END) / sum(volume) AS mkt_share +FROM ( + SELECT + extract(YEAR FROM o_orderdate) AS o_year, + l_extendedprice * (1 - l_discount) AS volume, + n2.n_name AS nation + FROM + part, + supplier, + lineitem, + orders, + customer, + nation n1, + nation n2, + region + WHERE + p_partkey = l_partkey + AND s_suppkey = l_suppkey + AND l_orderkey = o_orderkey + AND o_custkey = c_custkey + AND c_nationkey = n1.n_nationkey + AND n1.n_regionkey = r_regionkey + AND r_name = 'AMERICA' + AND s_nationkey = n2.n_nationkey + AND o_orderdate BETWEEN DATE '1995-01-01' AND DATE '1996-12-31' + AND p_type = 'ECONOMY ANODIZED STEEL' + ) AS all_nations +GROUP BY + o_year +ORDER BY + o_year diff --git a/src/main/resources/tpch/q9.sql b/src/main/resources/tpch/q9.sql new file mode 100644 index 0000000000..9b99ca3b79 --- /dev/null +++ b/src/main/resources/tpch/q9.sql @@ -0,0 +1,32 @@ +-- database: presto; groups: tpch, big_query; tables: part,supplier,lineitem,partsupp,orders,nation +SELECT + nation, + o_year, + sum(amount) AS sum_profit +FROM ( + SELECT + n_name AS nation, + extract(YEAR FROM o_orderdate) AS o_year, + l_extendedprice * (1 - l_discount) - ps_supplycost * l_quantity AS amount + FROM + part, + supplier, + lineitem, + partsupp, + orders, + nation + WHERE + s_suppkey = l_suppkey + AND ps_suppkey = l_suppkey + AND ps_partkey = l_partkey + AND p_partkey = l_partkey + AND o_orderkey = l_orderkey + AND s_nationkey = n_nationkey + AND p_name LIKE '%green%' + ) AS profit +GROUP BY + nation, + o_year +ORDER BY + nation, + o_year DESC diff --git a/src/test/java/com/alibaba/druid/benckmark/TPCDS.java b/src/test/java/com/alibaba/druid/benckmark/TPCDS.java new file mode 100644 index 0000000000..00c1e8d8a7 --- /dev/null +++ b/src/test/java/com/alibaba/druid/benckmark/TPCDS.java @@ -0,0 +1,36 @@ +package com.alibaba.druid.benckmark; + +import com.alibaba.druid.util.JdbcUtils; +import com.alibaba.druid.util.Utils; + +import java.io.InputStream; + +public class TPCDS { + private static String ddl; + private static String[] QUERIES = new String[99]; + + static { + for (int i = 1; i <= 99; ++i) { + String num = (i < 10 ? "0" : "") + i; + String path = "tpcds/query" + num + ".sql"; + InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream(path); + String sql = Utils.read(is); + QUERIES[i-1] = sql; + JdbcUtils.close(is); + } + { + String path = "tpcds/create_tables.sql"; + InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream(path); + ddl = Utils.read(is); + JdbcUtils.close(is); + } + } + + public static String getQuery(int index) { + return QUERIES[index - 1]; + } + + public static String getDDL() { + return ddl; + } +} diff --git a/src/test/java/com/alibaba/druid/benckmark/TPCH.java b/src/test/java/com/alibaba/druid/benckmark/TPCH.java new file mode 100644 index 0000000000..f9b5c7ab0e --- /dev/null +++ b/src/test/java/com/alibaba/druid/benckmark/TPCH.java @@ -0,0 +1,46 @@ +package com.alibaba.druid.benckmark; + +import com.alibaba.druid.util.JdbcUtils; +import com.alibaba.druid.util.Utils; + +import java.io.InputStream; + +public class TPCH { + private static final String insert_lineitem_200; + private static String ddl; + private static String[] QUERIES = new String[22]; + + static { + for (int i = 1; i <= 22; ++i) { + String path = "tpch/q" + i + ".sql"; + InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream(path); + String sql = Utils.read(is); + QUERIES[i-1] = sql; + JdbcUtils.close(is); + } + { + String path = "tpch/create_tables.sql"; + InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream(path); + ddl = Utils.read(is); + JdbcUtils.close(is); + } + { + String path = "tpch/insert_lineitem_200.sql"; + InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream(path); + insert_lineitem_200 = Utils.read(is); + JdbcUtils.close(is); + } + } + + public static String getQuery(int index) { + return QUERIES[index - 1]; + } + + public static String getDDL() { + return ddl; + } + + public static String getInsertLineitem200() { + return insert_lineitem_200; + } +} diff --git a/src/test/java/com/alibaba/druid/bvt/sql/mysql/resolve/ResolveTest_0.java b/src/test/java/com/alibaba/druid/bvt/sql/mysql/resolve/ResolveTest_0.java new file mode 100644 index 0000000000..44cef9edc6 --- /dev/null +++ b/src/test/java/com/alibaba/druid/bvt/sql/mysql/resolve/ResolveTest_0.java @@ -0,0 +1,143 @@ +package com.alibaba.druid.bvt.sql.mysql.resolve; + +import com.alibaba.druid.DbType; +import com.alibaba.druid.sql.SQLUtils; +import com.alibaba.druid.sql.ast.SQLExpr; +import com.alibaba.druid.sql.ast.expr.SQLIdentifierExpr; +import com.alibaba.druid.sql.ast.expr.SQLPropertyExpr; +import com.alibaba.druid.sql.ast.statement.*; +import com.alibaba.druid.sql.repository.SchemaRepository; +import com.alibaba.druid.sql.visitor.SQLASTVisitorAdapter; +import junit.framework.TestCase; + +public class ResolveTest_0 extends TestCase { + private SchemaRepository repository = new SchemaRepository(DbType.mysql); + + protected void setUp() throws Exception { + repository.setSchemaLoader(new SchemaRepository.SchemaLoader() { + @Override + public String loadDDL(String catalog, String schema, String objectName) { + if ("t_order".equalsIgnoreCase(objectName)) { + return "create table c1.s1.t_order (fid bigint, f_user_id bigint);"; + } + + if ("t_user".equalsIgnoreCase(objectName)) { + return "create table c1.s1.t_user (fid bigint, fname varchar(50));"; + } + + if ("nation".equalsIgnoreCase(objectName)) { + return "create table nation (fid bigint, fname varchar(50));"; + } + return null; + } + }); + } + + public void test_0() throws Exception { + String sql = "with x as (select * from t_order o where o.fid = 3) select * from x inner join t_user u on x.fid = u.fid"; + SQLSelectStatement stmt = (SQLSelectStatement) SQLUtils.parseStatements(sql, DbType.mysql).get(0); + repository.resolve(stmt); + + SQLSelectQueryBlock queryBlock = stmt.getSelect().getQueryBlock(); + + SQLJoinTableSource join = (SQLJoinTableSource) queryBlock.getFrom(); + + SQLCreateTableStatement createTable = (SQLCreateTableStatement) ((SQLExprTableSource) join.getRight()).getSchemaObject().getStatement(); + SQLExprTableSource left = (SQLExprTableSource) join.getLeft(); + + System.out.println(queryBlock.toString()); + } + + public void test_1() throws Exception { + String sql = "with x as (select * from t_order o where o.fid = 3) select * from x inner join t_user u on x.fid = u.fid"; + SQLSelectStatement stmt = (SQLSelectStatement) SQLUtils.parseStatements(sql, DbType.mysql).get(0); + repository.resolve(stmt); + + stmt.accept(new SetCatalogVisitor()); + + System.out.println(stmt.toString()); + } + + public void test_2() throws Exception { + String sql = "select t_order.fid from t_order"; + SQLSelectStatement stmt = (SQLSelectStatement) SQLUtils.parseStatements(sql, DbType.mysql).get(0); + repository.resolve(stmt); + + stmt.accept(new SetCatalogVisitor()); + + System.out.println(stmt.toString()); + } + + public void test_3() throws Exception { + String sql = "select s1.t_order.fid from s1.t_order"; + SQLSelectStatement stmt = (SQLSelectStatement) SQLUtils.parseStatements(sql, DbType.mysql).get(0); + repository.resolve(stmt); + + stmt.accept(new SetCatalogVisitor()); + + System.out.println(stmt.toString()); + } + + public void test_4() throws Exception { + String sql = "with temp_table as\n" + + "(\n" + + " select 0.5 * sum(l_quantity) as col1\n" + + " from lineitem,\n" + + " partsupp\n" + + " where l_partkey = ps_partkey and l_suppkey = ps_suppkey\n" + + " and date_parse(l_shipdate, '%Y-%m-%d %H:%i:%s') >= date '1993-01-01'\n" + + " and date_parse(l_shipdate, '%Y-%m-%d %H:%i:%s') < date '1993-01-01' + interval '1' year\n" + + ")\n" + + "select s_name, s_address\n" + + "from supplier,\n" + + " nation\n" + + "where s_suppkey in (\n" + + " select ps_suppkey\n" + + " from partsupp,\n" + + " temp_table\n" + + " where ps_partkey in (\n" + + " select p_partkey\n" + + " from part\n" + + " where p_name like 'dark%' )\n" + + " and ps_availqty > temp_table.col1 )\n" + + " and s_nationkey = n_nationkey and n_name = 'JORDAN'\n" + + "order by s_name\n" + + "limit 1;"; + SQLSelectStatement stmt = (SQLSelectStatement) SQLUtils.parseStatements(sql, DbType.mysql).get(0); + repository.resolve(stmt); + + stmt.accept(new SetCatalogVisitor()); + + System.out.println(stmt.toString()); + } + + public static class SetCatalogVisitor extends SQLASTVisitorAdapter { + public boolean visit(SQLExprTableSource x) { + if (x.getSchemaObject() != null) { + x.setCatalog("c1", "s1"); + } + return false; + } + + public boolean visit(SQLPropertyExpr x) { + SQLExprTableSource tableSource = (SQLExprTableSource) x.getResolvedTableSource(); + if (tableSource.getSchemaObject() == null) { + return false; + } + + SQLExpr owner = x.getOwner(); + if (owner instanceof SQLIdentifierExpr) { + x.setOwner( + new SQLPropertyExpr("c1", "s1", ((SQLIdentifierExpr) owner).getName()) + ); + } else if (owner instanceof SQLPropertyExpr) { + SQLPropertyExpr owner2 = (SQLPropertyExpr) owner; + if (owner2.getOwner() instanceof SQLIdentifierExpr) { + owner2.setOwner(new SQLPropertyExpr("c1", ((SQLIdentifierExpr) owner2.getOwner()).getName())); + } + } + + return false; + } + } +} diff --git a/src/test/java/com/alibaba/druid/bvt/sql/mysql/resolve/ResolveTest_1.java b/src/test/java/com/alibaba/druid/bvt/sql/mysql/resolve/ResolveTest_1.java new file mode 100644 index 0000000000..414c1daa4c --- /dev/null +++ b/src/test/java/com/alibaba/druid/bvt/sql/mysql/resolve/ResolveTest_1.java @@ -0,0 +1,109 @@ +package com.alibaba.druid.bvt.sql.mysql.resolve; + +import com.alibaba.druid.DbType; +import com.alibaba.druid.sql.SQLUtils; +import com.alibaba.druid.sql.ast.SQLExpr; +import com.alibaba.druid.sql.ast.expr.SQLIdentifierExpr; +import com.alibaba.druid.sql.ast.expr.SQLPropertyExpr; +import com.alibaba.druid.sql.ast.statement.*; +import com.alibaba.druid.sql.repository.SchemaObject; +import com.alibaba.druid.sql.repository.SchemaRepository; +import com.alibaba.druid.sql.visitor.SQLASTVisitorAdapter; +import junit.framework.TestCase; + +public class ResolveTest_1 extends TestCase { + private SchemaRepository repository = new SchemaRepository(DbType.mysql, DbType.hive); + + protected void setUp() throws Exception { + repository.setSchemaLoader(new SchemaRepository.SchemaLoader() { + @Override + public String loadDDL(String catalog, String schema, String objectName) { + if ("b".equalsIgnoreCase(objectName)) { + return "create table ots.a.b ( id int not null, shippingaddress STRUCT);\n"; + } + + if ("foo".equalsIgnoreCase(objectName)) { + return mockDDL("mysql", "hello", "foo"); + } else if ("bar".equalsIgnoreCase(objectName)) { + return mockDDL("oss", "world", "bar"); + } else if ("oss".equalsIgnoreCase(objectName)) { + return mockDDL("oss", "world", "error"); + } + + return null; + } + }); + } + + private String mockDDL(String catalogType, String schemaName, String tableName) { + return "CREATE EXTERNAL TABLE " + catalogType + "." + schemaName + "." + tableName + " (\n" + + " `name_text` VARCHAR" + + ")"; + } + + public void test_0() throws Exception { + String sql = "select * from a.b"; + SQLSelectStatement stmt = (SQLSelectStatement) SQLUtils.parseStatements(sql, DbType.mysql).get(0); + repository.resolve(stmt); + stmt.accept(new SetCatalogVisitor()); + + SQLSelectQueryBlock queryBlock = stmt.getSelect().getQueryBlock(); + + SQLExprTableSource tableSource = (SQLExprTableSource) queryBlock.getFrom(); + + final SchemaObject schemaObject = tableSource.getSchemaObject(); + assertEquals("b", schemaObject.getName()); + assertEquals("ots.a", schemaObject.getSchema().getName()); + assertEquals("ots", schemaObject.getSchema().getCatalog()); + SQLCreateTableStatement createTable = (SQLCreateTableStatement) schemaObject.getStatement(); + assertNotNull(createTable); + + System.out.println(queryBlock.toString()); + } + + public void test_1() throws Exception { + String sql = "insert into foo select * from bar"; + SQLInsertStatement stmt = (SQLInsertStatement) SQLUtils.parseStatements(sql, DbType.mysql).get(0); + repository.resolve(stmt); + stmt.accept(new SetCatalogVisitor()); + + SQLSelectQueryBlock queryBlock = (SQLSelectQueryBlock) stmt.getQuery().getQuery(); + + SQLExprTableSource tableSource = (SQLExprTableSource) queryBlock.getFrom(); + + final SchemaObject schemaObject = tableSource.getSchemaObject(); + assertEquals("bar", schemaObject.getName()); + assertEquals("oss.world", schemaObject.getSchema().getName()); + assertEquals("oss", schemaObject.getSchema().getCatalog()); + } + + public static class SetCatalogVisitor extends SQLASTVisitorAdapter { + public boolean visit(SQLExprTableSource x) { + if (x.getSchemaObject() != null) { + x.setCatalog("c1", "s1"); + } + return false; + } + + public boolean visit(SQLPropertyExpr x) { + SQLExprTableSource tableSource = (SQLExprTableSource) x.getResolvedTableSource(); + if (tableSource.getSchemaObject() == null) { + return false; + } + + SQLExpr owner = x.getOwner(); + if (owner instanceof SQLIdentifierExpr) { + x.setOwner( + new SQLPropertyExpr("c1", "s1", ((SQLIdentifierExpr) owner).getName()) + ); + } else if (owner instanceof SQLPropertyExpr) { + SQLPropertyExpr owner2 = (SQLPropertyExpr) owner; + if (owner2.getOwner() instanceof SQLIdentifierExpr) { + owner2.setOwner(new SQLPropertyExpr("c1", ((SQLIdentifierExpr) owner2.getOwner()).getName())); + } + } + + return false; + } + } +} diff --git a/src/test/java/com/alibaba/druid/bvt/sql/mysql/resolve/Resolve_AllColumn_Test.java b/src/test/java/com/alibaba/druid/bvt/sql/mysql/resolve/Resolve_AllColumn_Test.java new file mode 100644 index 0000000000..85e575d875 --- /dev/null +++ b/src/test/java/com/alibaba/druid/bvt/sql/mysql/resolve/Resolve_AllColumn_Test.java @@ -0,0 +1,88 @@ +package com.alibaba.druid.bvt.sql.mysql.resolve; + +import com.alibaba.druid.DbType; +import com.alibaba.druid.sql.SQLUtils; +import com.alibaba.druid.sql.ast.SQLExpr; +import com.alibaba.druid.sql.ast.SQLStatement; +import com.alibaba.druid.sql.ast.expr.SQLAllColumnExpr; +import com.alibaba.druid.sql.ast.expr.SQLIdentifierExpr; +import com.alibaba.druid.sql.ast.expr.SQLPropertyExpr; +import com.alibaba.druid.sql.ast.statement.SQLSelectItem; +import com.alibaba.druid.sql.ast.statement.SQLSelectQueryBlock; +import com.alibaba.druid.sql.ast.statement.SQLSelectStatement; +import com.alibaba.druid.sql.repository.SchemaRepository; +import com.alibaba.druid.sql.repository.SchemaResolveVisitor; +import com.alibaba.druid.sql.visitor.SQLASTVisitorAdapter; +import junit.framework.TestCase; + +import java.util.List; + +public class Resolve_AllColumn_Test extends TestCase { + public void test_resolve() throws Exception { + SchemaRepository repository = new SchemaRepository(DbType.mysql); + + repository.acceptDDL("create table t_emp(emp_id bigint, name varchar(20));"); + + SQLStatement stmt = SQLUtils.parseSingleMysqlStatement("select * from t_emp"); + repository.resolve(stmt, SchemaResolveVisitor.Option.ResolveAllColumn); + + assertEquals("SELECT emp_id, name\n" + + "FROM t_emp", stmt.toString()); + + SQLSelectQueryBlock queryBlock = ((SQLSelectStatement) stmt).getSelect().getQueryBlock(); + SQLIdentifierExpr expr = (SQLIdentifierExpr) queryBlock.getSelectList().get(0).getExpr(); + assertNotNull(expr.getResolvedColumn()); + + new SQLASTVisitorAdapter() { + public boolean visit(SQLSelectQueryBlock queryBlock) { + final List selectList = queryBlock.getSelectList(); + for (int i = 0; i < selectList.size(); i++) { + final SQLSelectItem selectItem = selectList.get(i); + final SQLExpr expr = selectItem.getExpr(); + if (expr instanceof SQLAllColumnExpr) { + + } else if (expr instanceof SQLPropertyExpr && ((SQLPropertyExpr) expr).getName().equals("*")) { + + } + + } + return true; + } + }; + } + + public void test_resolve_1() throws Exception { + SchemaRepository repository = new SchemaRepository(DbType.mysql); + + repository.acceptDDL("create table t_emp(emp_id bigint, name varchar(20));"); + + + SQLStatement stmt = SQLUtils.parseSingleMysqlStatement("select * from (select * from t_emp) x"); + repository.resolve(stmt, SchemaResolveVisitor.Option.ResolveAllColumn); + + assertEquals("SELECT emp_id, name\n" + + "FROM (\n" + + "\tSELECT emp_id, name\n" + + "\tFROM t_emp\n" + + ") x", stmt.toString()); + } + + public void test_resolve_2() throws Exception { + SchemaRepository repository = new SchemaRepository(DbType.mysql); + + repository.acceptDDL("create table t_emp(emp_id bigint, name varchar(20));"); + + + SQLStatement stmt = SQLUtils.parseSingleMysqlStatement("select * from (select * from t_emp union all select * from t_emp) x"); + repository.resolve(stmt, SchemaResolveVisitor.Option.ResolveAllColumn); + + assertEquals("SELECT emp_id, name\n" + + "FROM (\n" + + "\tSELECT emp_id, name\n" + + "\tFROM t_emp\n" + + "\tUNION ALL\n" + + "\tSELECT emp_id, name\n" + + "\tFROM t_emp\n" + + ") x", stmt.toString()); + } +} diff --git a/src/test/java/com/alibaba/druid/bvt/sql/mysql/resolve/Resolve_AllColumn_Test_1.java b/src/test/java/com/alibaba/druid/bvt/sql/mysql/resolve/Resolve_AllColumn_Test_1.java new file mode 100644 index 0000000000..de4c75d103 --- /dev/null +++ b/src/test/java/com/alibaba/druid/bvt/sql/mysql/resolve/Resolve_AllColumn_Test_1.java @@ -0,0 +1,25 @@ +package com.alibaba.druid.bvt.sql.mysql.resolve; + +import com.alibaba.druid.DbType; +import com.alibaba.druid.sql.SQLUtils; +import com.alibaba.druid.sql.ast.SQLStatement; +import com.alibaba.druid.sql.repository.SchemaRepository; +import com.alibaba.druid.sql.repository.SchemaResolveVisitor; +import junit.framework.TestCase; + +public class Resolve_AllColumn_Test_1 extends TestCase { + public void test_resolve() throws Exception { + SchemaRepository repository = new SchemaRepository(DbType.mysql); + + repository.acceptDDL("create table t_emp(emp_id bigint, name varchar(20));"); + + + SQLStatement stmt = SQLUtils.parseSingleMysqlStatement("select 1 as tag, * from t_emp"); + repository.resolve(stmt, SchemaResolveVisitor.Option.ResolveAllColumn); + + assertEquals("SELECT 1 AS tag, emp_id, name\n" + + "FROM t_emp", stmt.toString()); + + + } +} diff --git a/src/test/java/com/alibaba/druid/bvt/sql/mysql/resolve/TPCDS_ALL_Resolve.java b/src/test/java/com/alibaba/druid/bvt/sql/mysql/resolve/TPCDS_ALL_Resolve.java new file mode 100644 index 0000000000..2d1500c642 --- /dev/null +++ b/src/test/java/com/alibaba/druid/bvt/sql/mysql/resolve/TPCDS_ALL_Resolve.java @@ -0,0 +1,57 @@ +package com.alibaba.druid.bvt.sql.mysql.resolve; + +import com.alibaba.druid.DbType; +import com.alibaba.druid.benckmark.TPCDS; +import com.alibaba.druid.sql.SQLUtils; +import com.alibaba.druid.sql.ast.SQLDataType; +import com.alibaba.druid.sql.ast.SQLStatement; +import com.alibaba.druid.sql.ast.expr.SQLAllColumnExpr; +import com.alibaba.druid.sql.ast.statement.SQLSelect; +import com.alibaba.druid.sql.ast.statement.SQLSelectItem; +import com.alibaba.druid.sql.ast.statement.SQLSelectQueryBlock; +import com.alibaba.druid.sql.ast.statement.SQLSelectStatement; +import com.alibaba.druid.sql.repository.SchemaRepository; +import junit.framework.TestCase; + +import java.util.List; + +public class TPCDS_ALL_Resolve extends TestCase { + private SchemaRepository repository = new SchemaRepository(DbType.mysql); + + protected void setUp() throws Exception { + repository.acceptDDL(TPCDS.getDDL()); + } + + public void test_q01() throws Exception { + for (int q = 1; q <= 99; ++q) { + System.out.println("tpcds query-" + q); + System.out.println("-----------------------------------------------------"); + String sql = TPCDS.getQuery(q); + + final List statements = SQLUtils.parseStatements(sql, DbType.mysql); + + for (SQLStatement stmt : statements) { + repository.resolve(stmt); + + final SQLSelect select = ((SQLSelectStatement) stmt).getSelect(); + final SQLSelectQueryBlock firstQueryBlock = select.getFirstQueryBlock(); + if (firstQueryBlock == null) { + continue; + } + + final List selectList = firstQueryBlock.getSelectList(); + for (int i = 0; i < selectList.size(); i++) { + SQLSelectItem selectItem = selectList.get(i); + if (selectItem.getExpr() instanceof SQLAllColumnExpr) { + continue; + } + final SQLDataType dataType = selectItem.computeDataType(); + if (dataType == null) { +// fail("dataType is null : " + selectItem); + } + } + } + } + } + +}