diff --git a/.circleci/config.yml b/.circleci/config.yml index 3e53c6b74a538..ea5cb008e43c9 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -58,7 +58,7 @@ jobs: ccache -sz -M 8Gi source /opt/rh/gcc-toolset-9/enable cd presto-native-execution - cmake -B _build/debug -GNinja -DTREAT_WARNINGS_AS_ERRORS=1 -DENABLE_ALL_WARNINGS=1 -DCMAKE_BUILD_TYPE=Debug -DCMAKE_PREFIX_PATH=/usr/local -DCMAKE_CXX_COMPILER_LAUNCHER=ccache + cmake -B _build/debug -GNinja -DTREAT_WARNINGS_AS_ERRORS=1 -DENABLE_ALL_WARNINGS=1 -DCMAKE_BUILD_TYPE=Debug -DCMAKE_PREFIX_PATH=/usr/local -DCMAKE_CXX_COMPILER_LAUNCHER=ccache -DPRESTO_ENABLE_PARQUET=ON ninja -C _build/debug -j 8 ccache -s - save_cache: diff --git a/presto-native-execution/src/test/java/com/facebook/presto/hive/HiveExternalWorkerQueryRunner.java b/presto-native-execution/src/test/java/com/facebook/presto/hive/HiveExternalWorkerQueryRunner.java index f30c94dfea071..263ba146bc370 100644 --- a/presto-native-execution/src/test/java/com/facebook/presto/hive/HiveExternalWorkerQueryRunner.java +++ b/presto-native-execution/src/test/java/com/facebook/presto/hive/HiveExternalWorkerQueryRunner.java @@ -15,6 +15,7 @@ import com.facebook.airlift.log.Logger; import com.facebook.airlift.log.Logging; +import com.facebook.presto.Session; import com.facebook.presto.testing.QueryRunner; import com.facebook.presto.tests.DistributedQueryRunner; import com.google.common.collect.ImmutableList; @@ -33,6 +34,8 @@ public class HiveExternalWorkerQueryRunner { + public static final String DEFAULT_STORAGE_FORMAT = "PARQUET"; + private HiveExternalWorkerQueryRunner() {} public static QueryRunner createQueryRunner() @@ -64,7 +67,7 @@ public static QueryRunner createQueryRunner( checkArgument(dataDirectory.isPresent(), "Path to data files must be specified when testing external workers"); } - QueryRunner defaultQueryRunner = createJavaQueryRunner(dataDirectory); + QueryRunner defaultQueryRunner = createJavaQueryRunner(dataDirectory, DEFAULT_STORAGE_FORMAT); if (!prestoServerPath.isPresent()) { return defaultQueryRunner; @@ -72,12 +75,13 @@ public static QueryRunner createQueryRunner( defaultQueryRunner.close(); - return createNativeQueryRunner(dataDirectory.get().toString(), prestoServerPath.get(), workerCount, cacheMaxSize, true); + return createNativeQueryRunner(dataDirectory.get().toString(), prestoServerPath.get(), workerCount, cacheMaxSize, true, DEFAULT_STORAGE_FORMAT); } - public static QueryRunner createJavaQueryRunner(Optional dataDirectory) + public static QueryRunner createJavaQueryRunner(Optional dataDirectory, String storageFormat) throws Exception { + Optional finalDataDir = dataDirectory.map(path -> Paths.get(path.toString() + '/' + storageFormat)); DistributedQueryRunner queryRunner = HiveQueryRunner.createQueryRunner( ImmutableList.of(), @@ -88,9 +92,9 @@ public static QueryRunner createJavaQueryRunner(Optional dataDirectory) "deprecated.legacy-date-timestamp-to-varchar-coercion", "true"), "sql-standard", ImmutableMap.of( - "hive.storage-format", "DWRF", + "hive.storage-format", storageFormat, "hive.pushdown-filter-enabled", "true"), - dataDirectory); + finalDataDir); // DWRF doesn't support date type. Convert date columns to varchar for lineitem and orders. createLineitem(queryRunner); @@ -109,6 +113,33 @@ public static QueryRunner createJavaQueryRunner(Optional dataDirectory) createPrestoBenchTables(queryRunner); createBucketedLineitemAndOrders(queryRunner); + Session hiveTpcdsSession = Session.builder(queryRunner.getDefaultSession()) + .setSchema("tpcds").build(); + createTpcdsCallCenter(queryRunner, hiveTpcdsSession); + createTpcdsCatalogPage(queryRunner, hiveTpcdsSession); + createTpcdsCatalogReturns(queryRunner, hiveTpcdsSession); + createTpcdsCatalogSales(queryRunner, hiveTpcdsSession); + createTpcdsCustomer(queryRunner, hiveTpcdsSession); + createTpcdsCustomerAddress(queryRunner, hiveTpcdsSession); + createTpcdsCustomerDemographics(queryRunner, hiveTpcdsSession); + createTpcdsDateDim(queryRunner, hiveTpcdsSession); + createTpcdsHouseholdDemographics(queryRunner, hiveTpcdsSession); + createTpcdsIncomeBand(queryRunner, hiveTpcdsSession); + createTpcdsInventory(queryRunner, hiveTpcdsSession); + createTpcdsItem(queryRunner, hiveTpcdsSession); + createTpcdsPromotion(queryRunner, hiveTpcdsSession); + createTpcdsReason(queryRunner, hiveTpcdsSession); + createTpcdsShipMode(queryRunner, hiveTpcdsSession); + createTpcdsStore(queryRunner, hiveTpcdsSession); + createTpcdsStoreReturns(queryRunner, hiveTpcdsSession); + createTpcdsStoreSales(queryRunner, hiveTpcdsSession); + createTpcdsTimeDim(queryRunner, hiveTpcdsSession); + createTpcdsWarehouse(queryRunner, hiveTpcdsSession); + createTpcdsWebPage(queryRunner, hiveTpcdsSession); + createTpcdsWebReturns(queryRunner, hiveTpcdsSession); + createTpcdsWebSales(queryRunner, hiveTpcdsSession); + createTpcdsWebSite(queryRunner, hiveTpcdsSession); + return queryRunner; } @@ -117,7 +148,8 @@ public static QueryRunner createNativeQueryRunner( String prestoServerPath, Optional workerCount, int cacheMaxSize, - boolean useThrift) + boolean useThrift, + String storageFormat) throws Exception { // Make query runner with external workers for tests @@ -126,6 +158,7 @@ public static QueryRunner createNativeQueryRunner( ImmutableList.of(), ImmutableMap.builder() .put("optimizer.optimize-hash-generation", "false") + .put("optimizer.use-mark-distinct", "false") .put("parse-decimal-literals-as-double", "true") .put("http-server.http.port", "8080") .put("experimental.internal-communication.thrift-transport-enabled", String.valueOf(useThrift)) @@ -137,14 +170,16 @@ public static QueryRunner createNativeQueryRunner( // To achieve that, we set inline-sql-functions to false. .put("inline-sql-functions", "false") .put("use-alternative-function-signatures", "true") + .put("query.max-stage-count", "150") .build(), ImmutableMap.of(), "legacy", ImmutableMap.of( - "hive.storage-format", "DWRF", - "hive.pushdown-filter-enabled", "true"), + "hive.storage-format", storageFormat, + "hive.pushdown-filter-enabled", "true", + "hive.parquet.pushdown-filter-enabled", "true"), workerCount, - Optional.of(Paths.get(dataDirectory)), + Optional.of(Paths.get(dataDirectory + '/' + storageFormat)), Optional.of((workerIndex, discoveryUri) -> { try { Path tempDirectoryPath = Files.createTempDirectory(HiveExternalWorkerQueryRunner.class.getSimpleName()); @@ -462,6 +497,327 @@ private static void createBucketedLineitemAndOrders(QueryRunner queryRunner) } } + private static void createTpcdsCallCenter(QueryRunner queryRunner, Session session) + { + if (!queryRunner.tableExists(session, "call_center")) { + queryRunner.execute(session, "CREATE TABLE call_center AS " + + "SELECT cc_call_center_sk, cast(cc_call_center_id as varchar) as cc_call_center_id, cast(cc_rec_start_date as varchar) as cc_rec_start_date, " + + " cast(cc_rec_end_date as varchar) as cc_rec_end_date, " + + " cc_closed_date_sk, cc_open_date_sk, cc_name, cc_class, cc_employees, cc_sq_ft, cast(cc_hours as varchar) as cc_hours, " + + " cc_manager, cc_mkt_id, cast(cc_mkt_class as varchar) as cc_mkt_class, cc_mkt_desc, cc_market_manager, " + + " cc_division, cc_division_name, cc_company, cast(cc_company_name as varchar) as cc_company_name," + + " cast(cc_street_number as varchar ) as cc_street_number, cc_street_name, cast(cc_street_type as varchar) as cc_street_type, " + + " cast(cc_suite_number as varchar) as cc_suite_number, cc_city, cc_county, cast(cc_state as varchar) as cc_state, " + + " cast(cc_zip as varchar) as cc_zip, cc_country, cast(cc_gmt_offset as double) as cc_gmt_offset, " + + " cast(cc_tax_percentage as double) as cc_tax_percentage " + + "FROM tpcds.tiny.call_center"); + } + } + + private static void createTpcdsCatalogPage(QueryRunner queryRunner, Session session) + { + if (!queryRunner.tableExists(session, "catalog_page")) { + queryRunner.execute(session, "CREATE TABLE catalog_page AS " + + "SELECT cp_catalog_page_sk, cast(cp_catalog_page_id as varchar) as cp_catalog_page_id, cp_start_date_sk, cp_end_date_sk, " + + " cp_department, cp_catalog_number, cp_catalog_page_number, cp_description, cp_type " + + "FROM tpcds.tiny.catalog_page"); + } + } + + private static void createTpcdsCatalogReturns(QueryRunner queryRunner, Session session) + { + if (!queryRunner.tableExists(session, "catalog_returns")) { + queryRunner.execute(session, "CREATE TABLE catalog_returns AS " + + "SELECT cr_returned_date_sk, cr_returned_time_sk, cr_item_sk, cr_refunded_customer_sk, cr_refunded_cdemo_sk, " + + " cr_refunded_hdemo_sk, cr_refunded_addr_sk, cr_returning_customer_sk, cr_returning_cdemo_sk, cr_returning_hdemo_sk, " + + " cr_returning_addr_sk, cr_call_center_sk, cr_catalog_page_sk, cr_ship_mode_sk, cr_warehouse_sk, cr_reason_sk, " + + " cr_order_number, cr_return_quantity, cast(cr_return_amount as double) as cr_return_amount, " + + " cast(cr_return_tax as double) as cr_return_tax, cast(cr_return_amt_inc_tax as double) as cr_return_amt_inc_tax, " + + " cast(cr_fee as double) as cr_fee, cast(cr_return_ship_cost as double) as cr_return_ship_cost, " + + " cast(cr_refunded_cash as double) as cr_refunded_cash, cast(cr_reversed_charge as double) as cr_reversed_charge, " + + " cast(cr_store_credit as double) as cr_store_credit, cast(cr_net_loss as double) as cr_net_loss " + + "FROM tpcds.tiny.catalog_returns"); + } + } + + private static void createTpcdsCatalogSales(QueryRunner queryRunner, Session session) + { + if (!queryRunner.tableExists(session, "catalog_sales")) { + queryRunner.execute(session, "CREATE TABLE catalog_sales AS " + + "SELECT cs_sold_date_sk, cs_sold_time_sk, cs_ship_date_sk, cs_bill_customer_sk, cs_bill_cdemo_sk, " + + " cs_bill_hdemo_sk, cs_bill_addr_sk, cs_ship_customer_sk, cs_ship_cdemo_sk, cs_ship_hdemo_sk, " + + " cs_ship_addr_sk, cs_call_center_sk, cs_catalog_page_sk, cs_ship_mode_sk, cs_warehouse_sk, cs_item_sk, " + + " cs_promo_sk, cs_order_number, cs_quantity, cast(cs_wholesale_cost as double) as cs_wholesale_cost, " + + " cast(cs_list_price as double) as cs_list_price, cast(cs_sales_price as double) as cs_sales_price, " + + " cast(cs_ext_discount_amt as double) as cs_ext_discount_amt, cast(cs_ext_sales_price as double) as cs_ext_sales_price, " + + " cast(cs_ext_wholesale_cost as double) as cs_ext_wholesale_cost, cast(cs_ext_list_price as double) as cs_ext_list_price, " + + " cast(cs_ext_tax as double) as cs_ext_tax, cast(cs_coupon_amt as double) as cs_coupon_amt, " + + " cast(cs_ext_ship_cost as double) as cs_ext_ship_cost, cast(cs_net_paid as double) as cs_net_paid, " + + " cast(cs_net_paid_inc_tax as double) as cs_net_paid_inc_tax, cast(cs_net_paid_inc_ship as double) as cs_net_paid_inc_ship, " + + " cast(cs_net_paid_inc_ship_tax as double) as cs_net_paid_inc_ship_tax, cast(cs_net_profit as double) as cs_net_profit " + + "FROM tpcds.tiny.catalog_sales"); + } + } + + private static void createTpcdsCustomer(QueryRunner queryRunner, Session session) + { + if (!queryRunner.tableExists(session, "customer")) { + queryRunner.execute(session, "CREATE TABLE customer AS " + + "SELECT c_customer_sk, cast(c_customer_id as varchar) as c_customer_id, c_current_cdemo_sk, c_current_hdemo_sk, " + + " c_current_addr_sk, c_first_shipto_date_sk, c_first_sales_date_sk, cast(c_salutation as varchar) as c_salutation, " + + " cast(c_first_name as varchar) as c_first_name, cast(c_last_name as varchar) as c_last_name, " + + " cast(c_preferred_cust_flag as varchar) as c_preferred_cust_flag, c_birth_day, c_birth_month, c_birth_year, " + + " c_birth_country, cast(c_login as varchar) as c_login, cast(c_email_address as varchar) as c_email_address, " + + " c_last_review_date_sk " + + "FROM tpcds.tiny.customer"); + } + } + + private static void createTpcdsCustomerAddress(QueryRunner queryRunner, Session session) + { + if (!queryRunner.tableExists(session, "customer_address")) { + queryRunner.execute(session, "CREATE TABLE customer_address AS " + + "SELECT ca_address_sk, cast(ca_address_id as varchar) as ca_address_id, cast(ca_street_number as varchar) as ca_street_number, " + + " ca_street_name, cast(ca_street_type as varchar) as ca_street_type, cast(ca_suite_number as varchar) as ca_suite_number, " + + " ca_city, ca_county, cast(ca_state as varchar) as ca_state, cast(ca_zip as varchar) as ca_zip, " + + " ca_country, cast(ca_gmt_offset as double) as ca_gmt_offset, " + + " cast(ca_location_type as varchar) as ca_location_type " + + "FROM tpcds.tiny.customer_address"); + } + } + + private static void createTpcdsCustomerDemographics(QueryRunner queryRunner, Session session) + { + if (!queryRunner.tableExists(session, "customer_demographics")) { + queryRunner.execute(session, "CREATE TABLE customer_demographics AS " + + "SELECT cd_demo_sk, cast(cd_gender as varchar) as cd_gender, cast(cd_marital_status as varchar) as cd_marital_status, " + + " cast(cd_education_status as varchar) as cd_education_status, cd_purchase_estimate, " + + " cast(cd_credit_rating as varchar) as cd_credit_rating, cd_dep_count, cd_dep_employed_count, cd_dep_college_count " + + "FROM tpcds.tiny.customer_demographics"); + } + } + + private static void createTpcdsDateDim(QueryRunner queryRunner, Session session) + { + if (!queryRunner.tableExists(session, "date_dim")) { + queryRunner.execute(session, "CREATE TABLE date_dim AS " + + "SELECT d_date_sk, cast(d_date_id as varchar) as d_date_id, cast(d_date as varchar) as d_date, " + + " d_month_seq, d_week_seq, d_quarter_seq, d_year, d_dow, d_moy, d_dom, d_qoy, d_fy_year, " + + " d_fy_quarter_seq, d_fy_week_seq, cast(d_day_name as varchar) as d_day_name, cast(d_quarter_name as varchar) as d_quarter_name, " + + " cast(d_holiday as varchar) as d_holiday, cast(d_weekend as varchar) as d_weekend, " + + " cast(d_following_holiday as varchar) as d_following_holiday, d_first_dom, d_last_dom, d_same_day_ly, d_same_day_lq, " + + " cast(d_current_day as varchar) as d_current_day, cast(d_current_week as varchar) as d_current_week, " + + " cast(d_current_month as varchar) as d_current_month, cast(d_current_quarter as varchar) as d_current_quarter, " + + " cast(d_current_year as varchar) as d_current_year " + + "FROM tpcds.tiny.date_dim"); + } + } + + private static void createTpcdsHouseholdDemographics(QueryRunner queryRunner, Session session) + { + if (!queryRunner.tableExists(session, "household_demographics")) { + queryRunner.execute(session, "CREATE TABLE household_demographics AS " + + "SELECT hd_demo_sk, hd_income_band_sk, cast(hd_buy_potential as varchar) as hd_buy_potential, hd_dep_count, hd_vehicle_count " + + "FROM tpcds.tiny.household_demographics"); + } + } + + private static void createTpcdsIncomeBand(QueryRunner queryRunner, Session session) + { + if (!queryRunner.tableExists(session, "income_band")) { + queryRunner.execute(session, "CREATE TABLE income_band AS " + + "SELECT * FROM tpcds.tiny.income_band"); + } + } + + private static void createTpcdsInventory(QueryRunner queryRunner, Session session) + { + if (!queryRunner.tableExists(session, "inventory")) { + queryRunner.execute(session, "CREATE TABLE inventory AS " + + "SELECT * FROM tpcds.tiny.inventory"); + } + } + + private static void createTpcdsItem(QueryRunner queryRunner, Session session) + { + if (!queryRunner.tableExists(session, "item")) { + queryRunner.execute(session, "CREATE TABLE item AS " + + "SELECT i_item_sk, cast(i_item_id as varchar) as i_item_id, cast(i_rec_start_date as varchar) as i_rec_start_date, " + + " cast(i_rec_end_date as varchar) as i_rec_end_date, i_item_desc, cast(i_current_price as double) as i_current_price, " + + " cast(i_wholesale_cost as double) as i_wholesale_cost, i_brand_id, cast(i_brand as varchar) as i_brand, " + + " i_class_id, cast(i_class as varchar) as i_class, i_category_id, cast(i_category as varchar) as i_category, i_manufact_id, " + + " cast(i_manufact as varchar) as i_manufact, cast(i_size as varchar) as i_size, cast(i_formulation as varchar) as i_formulation, " + + " cast(i_color as varchar) as i_color, cast(i_units as varchar) as i_units, cast(i_container as varchar) as i_container, i_manager_id, " + + " cast(i_product_name as varchar) as i_product_name " + + "FROM tpcds.tiny.item"); + } + } + + private static void createTpcdsPromotion(QueryRunner queryRunner, Session session) + { + if (!queryRunner.tableExists(session, "promotion")) { + queryRunner.execute(session, "CREATE TABLE promotion AS " + + "SELECT p_promo_sk, cast(p_promo_id as varchar) as p_promo_id, p_start_date_sk, p_end_date_sk, p_item_sk, " + + " cast(p_cost as double) as p_cost, p_response_targe, cast(p_promo_name as varchar) as p_promo_name, " + + " cast(p_channel_dmail as varchar) as p_channel_dmail, cast(p_channel_email as varchar) as p_channel_email, " + + " cast(p_channel_catalog as varchar) as p_channel_catalog, cast(p_channel_tv as varchar) as p_channel_tv, " + + " cast(p_channel_radio as varchar) as p_channel_radio, cast(p_channel_press as varchar) as p_channel_press, " + + " cast(p_channel_event as varchar) as p_channel_event, cast(p_channel_demo as varchar) as p_channel_demo, p_channel_details, " + + " cast(p_purpose as varchar) as p_purpose, cast(p_discount_active as varchar) as p_discount_active " + + "FROM tpcds.tiny.promotion"); + } + } + + private static void createTpcdsReason(QueryRunner queryRunner, Session session) + { + if (!queryRunner.tableExists(session, "reason")) { + queryRunner.execute(session, "CREATE TABLE reason AS " + + "SELECT r_reason_sk, cast(r_reason_id as varchar) as r_reason_id, cast(r_reason_desc as varchar) as r_reason_desc " + + "FROM tpcds.tiny.reason"); + } + } + + private static void createTpcdsShipMode(QueryRunner queryRunner, Session session) + { + if (!queryRunner.tableExists(session, "ship_mode")) { + queryRunner.execute(session, "CREATE TABLE ship_mode AS " + + "SELECT sm_ship_mode_sk, cast(sm_ship_mode_id as varchar) as sm_ship_mode_id, cast(sm_type as varchar) as sm_type, " + + " cast(sm_code as varchar) as sm_code, cast(sm_carrier as varchar) as sm_carrier, cast(sm_contract as varchar) as sm_contract " + + "FROM tpcds.tiny.ship_mode"); + } + } + + private static void createTpcdsStore(QueryRunner queryRunner, Session session) + { + if (!queryRunner.tableExists(session, "store")) { + queryRunner.execute(session, "CREATE TABLE store AS " + + "SELECT s_store_sk, cast(s_store_id as varchar) as s_store_id, cast(s_rec_start_date as varchar) as s_rec_start_date, " + + " cast(s_rec_end_date as varchar) as s_rec_end_date, s_closed_date_sk, s_store_name, s_number_employees, s_floor_space, " + + " cast(s_hours as varchar) as s_hours, s_manager, s_market_id, s_geography_class, s_market_desc, s_market_manager, " + + " s_division_id, s_division_name, s_company_id, s_company_name, s_street_number, s_street_name, " + + " cast(s_street_type as varchar) as s_street_type, cast(s_suite_number as varchar) as s_suite_number, s_city, s_county, " + + " cast(s_state as varchar ) as s_state, cast(s_zip as varchar) as s_zip, s_country, " + + " cast(s_gmt_offset as double) as s_gmt_offset, " + + " cast(s_tax_precentage as double) as s_tax_precentage " + + "FROM tpcds.tiny.store"); + } + } + + private static void createTpcdsStoreReturns(QueryRunner queryRunner, Session session) + { + if (!queryRunner.tableExists(session, "store_returns")) { + queryRunner.execute(session, "CREATE TABLE store_returns AS " + + "SELECT sr_returned_date_sk, sr_return_time_sk, sr_item_sk, sr_customer_sk, sr_cdemo_sk, sr_hdemo_sk, " + + " sr_addr_sk, sr_store_sk, sr_reason_sk, sr_ticket_number, sr_return_quantity, " + + " cast(sr_return_amt as double) as sr_return_amt, cast(sr_return_tax as double) as sr_return_tax, " + + " cast(sr_return_amt_inc_tax as double) as sr_return_amt_inc_tax, cast(sr_fee as double) as sr_fee, " + + " cast(sr_return_ship_cost as double) as sr_return_ship_cost, cast(sr_refunded_cash as double) as sr_refunded_cash, " + + " cast(sr_reversed_charge as double) as sr_reversed_charge, cast(sr_store_credit as double) as sr_store_credit, " + + " cast(sr_net_loss as double) as sr_net_loss " + + "FROM tpcds.tiny.store_returns"); + } + } + + private static void createTpcdsStoreSales(QueryRunner queryRunner, Session session) + { + if (!queryRunner.tableExists(session, "store_sales")) { + queryRunner.execute(session, "CREATE TABLE store_sales AS " + + "SELECT ss_sold_date_sk, ss_sold_time_sk, ss_item_sk, ss_customer_sk, ss_cdemo_sk, ss_hdemo_sk, " + + " ss_addr_sk, ss_store_sk, ss_promo_sk, ss_ticket_number, ss_quantity, cast(ss_wholesale_cost as double) as ss_wholesale_cost, " + + " cast(ss_list_price as double) as ss_list_price, cast(ss_sales_price as double) as ss_sales_price, " + + " cast(ss_ext_discount_amt as double) as ss_ext_discount_amt, cast(ss_ext_sales_price as double) as ss_ext_sales_price, " + + " cast(ss_ext_wholesale_cost as double) as ss_ext_wholesale_cost, cast(ss_ext_list_price as double) as ss_ext_list_price, " + + " cast(ss_ext_tax as double) as ss_ext_tax, cast(ss_coupon_amt as double) as ss_coupon_amt, " + + " cast(ss_net_paid as double) as ss_net_paid, cast(ss_net_paid_inc_tax as double) as ss_net_paid_inc_tax," + + " cast(ss_net_profit as double) as ss_net_profit " + + "FROM tpcds.tiny.store_sales"); + } + } + + private static void createTpcdsTimeDim(QueryRunner queryRunner, Session session) + { + if (!queryRunner.tableExists(session, "time_dim")) { + queryRunner.execute(session, "CREATE TABLE time_dim AS " + + "SELECT t_time_sk, cast(t_time_id as varchar) as t_time_id, t_time, t_hour, t_minute, t_second, " + + " cast(t_am_pm as varchar) as t_am_pm, cast(t_shift as varchar) as t_shift, " + + " cast(t_sub_shift as varchar) as t_sub_shift, cast(t_meal_time as varchar) as t_meal_time " + + "FROM tpcds.tiny.time_dim"); + } + } + + private static void createTpcdsWarehouse(QueryRunner queryRunner, Session session) + { + if (!queryRunner.tableExists(session, "warehouse")) { + queryRunner.execute(session, "CREATE TABLE warehouse AS " + + "SELECT w_warehouse_sk, cast(w_warehouse_id as varchar) as w_warehouse_id, w_warehouse_name, w_warehouse_sq_ft, " + + " cast(w_street_number as varchar) as w_street_number, w_street_name, cast(w_street_type as varchar) as w_street_type, " + + " cast(w_suite_number as varchar) as w_suite_number, w_city, w_county, cast(w_state as varchar) as w_state," + + " cast(w_zip as varchar) as w_zip, w_country, cast(w_gmt_offset as double) as w_gmt_offset " + + "FROM tpcds.tiny.warehouse"); + } + } + + private static void createTpcdsWebPage(QueryRunner queryRunner, Session session) + { + if (!queryRunner.tableExists(session, "web_page")) { + queryRunner.execute(session, "CREATE TABLE web_page AS " + + "SELECT wp_web_page_sk, cast(wp_web_page_id as varchar) as wp_web_page_id, cast(wp_rec_start_date as varchar) as wp_rec_start_date, " + + " cast(wp_rec_end_date as varchar) as wp_rec_end_date, wp_creation_date_sk, wp_access_date_sk, " + + " cast(wp_autogen_flag as varchar) as wp_autogen_flag, wp_customer_sk, wp_url, cast(wp_type as varchar) as wp_type, " + + " wp_char_count, wp_link_count, wp_image_count, wp_max_ad_count " + + "FROM tpcds.tiny.web_page"); + } + } + + private static void createTpcdsWebReturns(QueryRunner queryRunner, Session session) + { + if (!queryRunner.tableExists(session, "web_returns")) { + queryRunner.execute(session, "CREATE TABLE web_returns AS " + + "SELECT wr_returned_date_sk, wr_returned_time_sk, wr_item_sk, wr_refunded_customer_sk, wr_refunded_cdemo_sk, " + + " wr_refunded_hdemo_sk, wr_refunded_addr_sk, wr_returning_customer_sk, wr_returning_cdemo_sk, wr_returning_hdemo_sk, " + + " wr_returning_addr_sk, wr_web_page_sk, wr_reason_sk, wr_order_number, wr_return_quantity, cast(wr_return_amt as double) as wr_return_amt, " + + " cast(wr_return_tax as double) as wr_return_tax, cast(wr_return_amt_inc_tax as double) as wr_return_amt_inc_tax, " + + " cast(wr_fee as double) as wr_fee, cast(wr_return_ship_cost as double) as wr_return_ship_cost, " + + " cast(wr_refunded_cash as double) as wr_refunded_cash, cast(wr_reversed_charge as double) as wr_reversed_charge, " + + " cast(wr_account_credit as double) as wr_account_credit, cast(wr_net_loss as double) as wr_net_loss " + + "FROM tpcds.tiny.web_returns"); + } + } + + private static void createTpcdsWebSales(QueryRunner queryRunner, Session session) + { + if (!queryRunner.tableExists(session, "web_sales")) { + queryRunner.execute(session, "CREATE TABLE web_sales AS " + + "SELECT ws_sold_date_sk, ws_sold_time_sk, ws_ship_date_sk, ws_item_sk, ws_bill_customer_sk, " + + " ws_bill_cdemo_sk, ws_bill_hdemo_sk, ws_bill_addr_sk, ws_ship_customer_sk, ws_ship_cdemo_sk, " + + " ws_ship_hdemo_sk, ws_ship_addr_sk, ws_web_page_sk, ws_web_site_sk, ws_ship_mode_sk, ws_warehouse_sk, " + + " ws_promo_sk, ws_order_number, ws_quantity, cast(ws_wholesale_cost as double) as ws_wholesale_cost, " + + " cast(ws_list_price as double) as ws_list_price, cast(ws_sales_price as double) as ws_sales_price, " + + " cast(ws_ext_discount_amt as double) as ws_ext_discount_amt, cast(ws_ext_sales_price as double) as ws_ext_sales_price, " + + " cast(ws_ext_wholesale_cost as double) as ws_ext_wholesale_cost, cast(ws_ext_list_price as double) as ws_ext_list_price, " + + " cast(ws_ext_tax as double) as ws_ext_tax, cast(ws_coupon_amt as double) as ws_coupon_amt, " + + " cast(ws_ext_ship_cost as double) as ws_ext_ship_cost, cast(ws_net_paid as double) as ws_net_paid, " + + " cast(ws_net_paid_inc_tax as double) as ws_net_paid_inc_tax, cast(ws_net_paid_inc_ship as double) as ws_net_paid_inc_ship, " + + " cast(ws_net_paid_inc_ship_tax as double) as ws_net_paid_inc_ship_tax, cast(ws_net_profit as double) as ws_net_profit " + + "FROM tpcds.tiny.web_sales"); + } + } + + private static void createTpcdsWebSite(QueryRunner queryRunner, Session session) + { + if (!queryRunner.tableExists(session, "web_site")) { + queryRunner.execute(session, "CREATE TABLE web_site AS " + + "SELECT web_site_sk, cast(web_site_id as varchar) as web_site_id, cast(web_rec_start_date as varchar) as web_rec_start_date, " + + " cast(web_rec_end_date as varchar) as web_rec_end_date, web_name, web_open_date_sk, web_close_date_sk, web_class, " + + " web_manager, web_mkt_id, web_mkt_class, web_mkt_desc, web_market_manager, web_company_id, cast(web_company_name as varchar) as web_company_name, " + + " cast(web_street_number as varchar) as web_street_number, web_street_name, cast(web_street_type as varchar) as web_street_type, " + + " cast(web_suite_number as varchar) as web_suite_number, web_city, web_county, cast(web_state as varchar) as web_state, " + + " cast(web_zip as varchar) as web_zip, web_country, cast(web_gmt_offset as double) as web_gmt_offset, " + + " cast(web_tax_percentage as double) as web_tax_percentage " + + "FROM tpcds.tiny.web_site"); + } + } + public static void main(String[] args) throws Exception { diff --git a/presto-native-execution/src/test/java/com/facebook/presto/nativeworker/AbstractTestHiveQueries.java b/presto-native-execution/src/test/java/com/facebook/presto/nativeworker/AbstractTestHiveQueries.java index ab4d9c2b37dca..9e734c929d604 100644 --- a/presto-native-execution/src/test/java/com/facebook/presto/nativeworker/AbstractTestHiveQueries.java +++ b/presto-native-execution/src/test/java/com/facebook/presto/nativeworker/AbstractTestHiveQueries.java @@ -26,11 +26,16 @@ public class AbstractTestHiveQueries extends AbstractTestQueryFramework { + static final String PARQUET_STORAGE_FORMAT = "PARQUET"; + static final String DWARF_STORAGE_FORMAT = "DWRF"; + private final boolean useThrift; + private final String storageFormat; - protected AbstractTestHiveQueries(boolean useThrift) + protected AbstractTestHiveQueries(boolean useThrift, String storageFormat) { this.useThrift = useThrift; + this.storageFormat = storageFormat; } @Override @@ -45,7 +50,7 @@ protected QueryRunner createQueryRunner() assertNotNull(prestoServerPath, "Native worker binary path is missing. Add -DPRESTO_SERVER= to your JVM arguments."); assertNotNull(dataDirectory, "Data directory path is missing. Add -DDATA_DIR= to your JVM arguments."); - return HiveExternalWorkerQueryRunner.createNativeQueryRunner(dataDirectory, prestoServerPath, Optional.ofNullable(workerCount).map(Integer::parseInt), cacheMaxSize, useThrift); + return HiveExternalWorkerQueryRunner.createNativeQueryRunner(dataDirectory, prestoServerPath, Optional.ofNullable(workerCount).map(Integer::parseInt), cacheMaxSize, useThrift, storageFormat); } @Override @@ -53,6 +58,6 @@ protected ExpectedQueryRunner createExpectedQueryRunner() throws Exception { String dataDirectory = System.getProperty("DATA_DIR"); - return HiveExternalWorkerQueryRunner.createJavaQueryRunner(Optional.of(Paths.get(dataDirectory))); + return HiveExternalWorkerQueryRunner.createJavaQueryRunner(Optional.of(Paths.get(dataDirectory)), storageFormat); } } diff --git a/presto-native-execution/src/test/java/com/facebook/presto/nativeworker/TestHiveAggregationQueries.java b/presto-native-execution/src/test/java/com/facebook/presto/nativeworker/TestHiveAggregationQueries.java index 4d1394d3a9511..a7e63db5bcdda 100644 --- a/presto-native-execution/src/test/java/com/facebook/presto/nativeworker/TestHiveAggregationQueries.java +++ b/presto-native-execution/src/test/java/com/facebook/presto/nativeworker/TestHiveAggregationQueries.java @@ -22,7 +22,7 @@ public class TestHiveAggregationQueries { public TestHiveAggregationQueries() { - super(true); + super(true, DWARF_STORAGE_FORMAT); } @Test diff --git a/presto-native-execution/src/test/java/com/facebook/presto/nativeworker/TestHiveBitwiseFunctionQueries.java b/presto-native-execution/src/test/java/com/facebook/presto/nativeworker/TestHiveBitwiseFunctionQueries.java index ac21d1c068810..2ae7e5e0c131b 100644 --- a/presto-native-execution/src/test/java/com/facebook/presto/nativeworker/TestHiveBitwiseFunctionQueries.java +++ b/presto-native-execution/src/test/java/com/facebook/presto/nativeworker/TestHiveBitwiseFunctionQueries.java @@ -21,7 +21,7 @@ public class TestHiveBitwiseFunctionQueries { public TestHiveBitwiseFunctionQueries() { - super(false); + super(false, DWARF_STORAGE_FORMAT); } @Test diff --git a/presto-native-execution/src/test/java/com/facebook/presto/nativeworker/TestHiveJoinQueries.java b/presto-native-execution/src/test/java/com/facebook/presto/nativeworker/TestHiveJoinQueries.java index 1bc4a781bae38..be5b309a52731 100644 --- a/presto-native-execution/src/test/java/com/facebook/presto/nativeworker/TestHiveJoinQueries.java +++ b/presto-native-execution/src/test/java/com/facebook/presto/nativeworker/TestHiveJoinQueries.java @@ -21,7 +21,7 @@ public class TestHiveJoinQueries { public TestHiveJoinQueries() { - super(true); + super(true, DWARF_STORAGE_FORMAT); } @Test diff --git a/presto-native-execution/src/test/java/com/facebook/presto/nativeworker/TestHiveQueries.java b/presto-native-execution/src/test/java/com/facebook/presto/nativeworker/TestHiveQueries.java index 5e906ca8f621d..125a9d25f98e3 100644 --- a/presto-native-execution/src/test/java/com/facebook/presto/nativeworker/TestHiveQueries.java +++ b/presto-native-execution/src/test/java/com/facebook/presto/nativeworker/TestHiveQueries.java @@ -30,7 +30,7 @@ abstract class TestHiveQueries { protected TestHiveQueries(boolean useThrift) { - super(useThrift); + super(useThrift, DWARF_STORAGE_FORMAT); } @Test diff --git a/presto-native-execution/src/test/java/com/facebook/presto/nativeworker/TestHiveTpcdsQueries.java b/presto-native-execution/src/test/java/com/facebook/presto/nativeworker/TestHiveTpcdsQueries.java new file mode 100644 index 0000000000000..ef301df7bc80b --- /dev/null +++ b/presto-native-execution/src/test/java/com/facebook/presto/nativeworker/TestHiveTpcdsQueries.java @@ -0,0 +1,818 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.facebook.presto.nativeworker; + +import com.facebook.presto.Session; +import com.facebook.presto.hive.HiveExternalWorkerQueryRunner; +import com.facebook.presto.testing.ExpectedQueryRunner; +import com.facebook.presto.testing.QueryRunner; +import com.facebook.presto.tests.AbstractTestQueryFramework; +import com.google.common.io.Resources; +import org.testng.annotations.Test; + +import java.io.IOException; +import java.nio.file.Paths; +import java.util.Optional; + +import static java.nio.charset.StandardCharsets.UTF_8; +import static org.testng.Assert.assertNotNull; + +public abstract class TestHiveTpcdsQueries + extends AbstractTestQueryFramework +{ + private final String storageFormat; + private final Boolean useThrift; + private Session hiveTpcdsSession; + + public TestHiveTpcdsQueries(boolean useThrift, String storageFormat) + { + this.useThrift = useThrift; + this.storageFormat = storageFormat; + } + + @Override + protected QueryRunner createQueryRunner() + throws Exception + { + String prestoServerPath = System.getProperty("PRESTO_SERVER"); + String baseDataDir = System.getProperty("DATA_DIR"); + String workerCount = System.getProperty("WORKER_COUNT"); + int cacheMaxSize = 0; + + assertNotNull(prestoServerPath); + assertNotNull(baseDataDir); + + return HiveExternalWorkerQueryRunner.createNativeQueryRunner(baseDataDir, prestoServerPath, Optional.ofNullable(workerCount).map(Integer::parseInt), cacheMaxSize, + useThrift, storageFormat); + } + + @Override + protected ExpectedQueryRunner createExpectedQueryRunner() + throws Exception + { + String baseDataDir = System.getProperty("DATA_DIR"); + return HiveExternalWorkerQueryRunner.createJavaQueryRunner(Optional.of(Paths.get(baseDataDir)), storageFormat); + } + + protected static String getTpcdsQuery(String q) + throws IOException + { + String sql = Resources.toString(Resources.getResource("tpcds/queries/q" + q + ".sql"), UTF_8); + sql = sql.replaceFirst("(?m);$", ""); + return sql; + } + + @Override + protected Session getSession() + { + if (hiveTpcdsSession == null) { + hiveTpcdsSession = Session.builder(super.getSession()) + .setSchema("tpcds").build(); + } + + return hiveTpcdsSession; + } + + @Test + public void testTpcdsQ1() + throws Exception + { + assertQuery(getTpcdsQuery("01")); + } + + @Test + public void testTpcdsQ2() + throws Exception + { + assertQuery(getTpcdsQuery("02")); + } + + @Test + public void testTpcdsQ3() + throws Exception + { + assertQuery(getTpcdsQuery("03")); + } + + @Test + public void testTpcdsQ4() + throws Exception + { + assertQuery(getTpcdsQuery("04")); + } + + @Test + public void testTpcdsQ5() + throws Exception + { + assertQuery(getTpcdsQuery("05")); + } + + @Test + public void testTpcdsQ6() + throws Exception + { + assertQuery(getTpcdsQuery("06")); + } + + @Test + public void testTpcdsQ7() + throws Exception + { + assertQuery(getTpcdsQuery("07")); + } + + @Test + public void testTpcdsQ8() + throws Exception + { + assertQuery(getTpcdsQuery("08")); + } + + @Test + public void testTpcdsQ9() + throws Exception + { + assertQuery(getTpcdsQuery("09")); + } + + @Test + public void testTpcdsQ10() + throws Exception + { + assertQuery(getTpcdsQuery("10")); + } + + @Test + public void testTpcdsQ11() + throws Exception + { + assertQuery(getTpcdsQuery("11")); + } + + @Test(enabled = false) + public void testTpcdsQ12() + throws Exception + { + assertQuery(getTpcdsQuery("12")); + } + + @Test + public void testTpcdsQ13() + throws Exception + { + assertQuery(getTpcdsQuery("13")); + } + + @Test + public void testTpcdsQ14_1() + throws Exception + { + assertQueryFails(getTpcdsQuery("14_1"), + "[\\s\\S]*Unexpected parameters[\\s\\S]*for function sum[\\s\\S]*"); + } + + @Test + public void testTpcdsQ14_2() + throws Exception + { + assertQuery(getTpcdsQuery("14_2")); + } + + @Test + public void testTpcdsQ15() + throws Exception + { + assertQuery(getTpcdsQuery("15")); + } + + @Test + public void testTpcdsQ16() + throws Exception + { + assertQueryFails(getTpcdsQuery("16"), "[\\s\\S]*mismatched input \'\"total shipping cost\"\'[\\s\\S]*"); + } + + @Test + public void testTpcdsQ17() + throws Exception + { + assertQuery(getTpcdsQuery("17")); + } + + @Test + public void testTpcdsQ18() + throws Exception + { + // Results not equal + assertQuerySucceeds(getTpcdsQuery("18")); + } + + @Test + public void testTpcdsQ19() + throws Exception + { + assertQuery(getTpcdsQuery("19")); + } + + // Disabled this case since it might crash the worker + @Test(enabled = false) + public void testTpcdsQ20() + throws Exception + { + assertQuery(getTpcdsQuery("20")); + } + + @Test + public void testTpcdsQ21() + throws Exception + { + assertQuery(getTpcdsQuery("21")); + } + + @Test + public void testTpcdsQ22() + throws Exception + { + assertQuery(getTpcdsQuery("22")); + } + + @Test + public void testTpcdsQ23_1() + throws Exception + { + assertQuery(getTpcdsQuery("23_1")); + } + + @Test + public void testTpcdsQ23_2() + throws Exception + { + assertQuery(getTpcdsQuery("23_2")); + } + + @Test + public void testTpcdsQ24_1() + throws Exception + { + assertQuery(getTpcdsQuery("24_1")); + } + + @Test + public void testTpcdsQ24_2() + throws Exception + { + assertQuery(getTpcdsQuery("24_2")); + } + + @Test + public void testTpcdsQ25() + throws Exception + { + assertQuery(getTpcdsQuery("25")); + } + + @Test + public void testTpcdsQ26() + throws Exception + { + assertQuery(getTpcdsQuery("26")); + } + + @Test + public void testTpcdsQ27() + throws Exception + + { + // Results not equal + assertQuerySucceeds(getTpcdsQuery("27")); + } + + @Test + public void testTpcdsQ28() + throws Exception + { + // Results not equal + // Actual rows (up to 100 of 1 extra rows shown, 1 rows in total): + // [77.93, 1468, 1468, 69.55, 1518, 1518, 134.06, 1167, 1167, 81.56, 1258, 1258, 60.27, 1523, 1523, 38.99, 1322, 1322] + //Expected rows (up to 100 of 1 missing rows shown, 1 rows in total): + // [77.93, 1468, 1345, 69.55, 1518, 1331, 134.06, 1167, 1107, 81.56, 1258, 1158, 60.27, 1523, 1342, 38.99, 1322, 1152] + assertQuerySucceeds(getTpcdsQuery("28")); + } + + @Test + public void testTpcdsQ29() + throws Exception + { + assertQuery(getTpcdsQuery("29")); + } + + @Test + public void testTpcdsQ30() + throws Exception + { + assertQuery(getTpcdsQuery("30")); + } + + @Test + public void testTpcdsQ31() + throws Exception + { + assertQuery(getTpcdsQuery("31")); + } + + // Disabled this case since it might crash the worker + @Test(enabled = false) + public void testTpcdsQ32() + throws Exception + { + assertQuery(getTpcdsQuery("32")); + } + + @Test + public void testTpcdsQ33() + throws Exception + { + assertQuery(getTpcdsQuery("33")); + } + + @Test + public void testTpcdsQ34() + throws Exception + { + assertQuery(getTpcdsQuery("34")); + } + + @Test + public void testTpcdsQ35() + throws Exception + { + assertQuery(getTpcdsQuery("35")); + } + + @Test + public void testTpcdsQ36() + throws Exception + { + assertQuery(getTpcdsQuery("36")); + } + + @Test + public void testTpcdsQ37() + throws Exception + { + assertQuery(getTpcdsQuery("37")); + } + + @Test + public void testTpcdsQ38() + throws Exception + { + assertQuery(getTpcdsQuery("38")); + } + + @Test + public void testTpcdsQ39_1() + throws Exception + { + assertQuery(getTpcdsQuery("39_1")); + } + + @Test + public void testTpcdsQ39_2() + throws Exception + { + assertQuery(getTpcdsQuery("39_2")); + } + + @Test + public void testTpcdsQ40() + throws Exception + { + assertQuery(getTpcdsQuery("40")); + } + + @Test + public void testTpcdsQ41() + throws Exception + { + assertQuery(getTpcdsQuery("41")); + } + + @Test + public void testTpcdsQ42() + throws Exception + { + assertQuery(getTpcdsQuery("42")); + } + + @Test + public void testTpcdsQ43() + throws Exception + { + assertQuery(getTpcdsQuery("43")); + } + + @Test + public void testTpcdsQ44() + throws Exception + { + assertQuery(getTpcdsQuery("44")); + } + + @Test + public void testTpcdsQ45() + throws Exception + { + assertQueryFails(getTpcdsQuery("45"), "([\\s\\S]*Field not found:[\\s\\S]*)|([\\s\\S]*Exhausted retries:[\\s\\S]*)|([\\s\\S]*Unsupported Filter over SemiJoin[\\s\\S]*)"); + } + + @Test + public void testTpcdsQ46() + throws Exception + { + assertQuery(getTpcdsQuery("46")); + } + + @Test + public void testTpcdsQ47() + throws Exception + { + assertQueryFails(getTpcdsQuery("47"), "[\\s\\S]*Cannot nest aggregations inside aggregation[\\s\\S]*"); + } + + @Test + public void testTpcdsQ48() + throws Exception + { + assertQuery(getTpcdsQuery("48")); + } + + @Test + public void testTpcdsQ49() + throws Exception + { + assertQuery(getTpcdsQuery("49")); + } + + @Test + public void testTpcdsQ50() + throws Exception + { + assertQuery(getTpcdsQuery("50")); + } + + @Test + public void testTpcdsQ51() + throws Exception + { + assertQueryFails(getTpcdsQuery("51"), "[\\s\\S]*Cannot nest aggregations inside aggregation[\\s\\S]*"); + } + + @Test + public void testTpcdsQ52() + throws Exception + { + assertQuery(getTpcdsQuery("52")); + } + + @Test + public void testTpcdsQ53() + throws Exception + { + assertQueryFails(getTpcdsQuery("53"), "[\\s\\S]*Cannot nest aggregations inside aggregation[\\s\\S]*"); + } + + @Test + public void testTpcdsQ54() + throws Exception + { + assertQuery(getTpcdsQuery("54")); + } + + @Test + public void testTpcdsQ55() + throws Exception + { + assertQuery(getTpcdsQuery("55")); + } + + @Test + public void testTpcdsQ56() + throws Exception + { + assertQuery(getTpcdsQuery("56")); + } + + @Test + public void testTpcdsQ57() + throws Exception + { + assertQueryFails(getTpcdsQuery("57"), "[\\s\\S]*Cannot nest aggregations inside aggregation[\\s\\S]*"); + } + + @Test + public void testTpcdsQ58() + throws Exception + { + assertQuery(getTpcdsQuery("58")); + } + + @Test + public void testTpcdsQ59() + throws Exception + { + assertQuery(getTpcdsQuery("59")); + } + + @Test + public void testTpcdsQ60() + throws Exception + { + assertQuery(getTpcdsQuery("60")); + } + + @Test + public void testTpcdsQ61() + throws Exception + { + assertQuery(getTpcdsQuery("61")); + } + + @Test + public void testTpcdsQ62() + throws Exception + { + assertQuery(getTpcdsQuery("62")); + } + + @Test + public void testTpcdsQ63() + throws Exception + { + assertQueryFails(getTpcdsQuery("63"), "[\\s\\S]*Cannot nest aggregations inside aggregation[\\s\\S]*"); + } + + @Test + public void testTpcdsQ64() + throws Exception + { + assertQuery(getTpcdsQuery("64")); + } + + @Test + public void testTpcdsQ65() + throws Exception + { + assertQuery(getTpcdsQuery("65")); + } + + @Test + public void testTpcdsQ66() + throws Exception + { + assertQuery(getTpcdsQuery("66")); + } + + @Test + public void testTpcdsQ67() + throws Exception + { + assertQuery(getTpcdsQuery("67")); + } + + @Test + public void testTpcdsQ68() + throws Exception + { + assertQuery(getTpcdsQuery("68")); + } + + @Test + public void testTpcdsQ69() + throws Exception + { + assertQuerySucceeds(getTpcdsQuery("69")); + } + + @Test + public void testTpcdsQ70() + throws Exception + { + assertQuery(getTpcdsQuery("70")); + } + + @Test + public void testTpcdsQ71() + throws Exception + { + assertQuery(getTpcdsQuery("71")); + } + + @Test + public void testTpcdsQ72() + throws Exception + { + assertQuery(getTpcdsQuery("72")); + } + + @Test + public void testTpcdsQ73() + throws Exception + { + assertQuery(getTpcdsQuery("73")); + } + + @Test + public void testTpcdsQ74() + throws Exception + { + assertQuery(getTpcdsQuery("74")); + } + + @Test + public void testTpcdsQ75() + throws Exception + { + assertQuery(getTpcdsQuery("75")); + } + + @Test + public void testTpcdsQ76() + throws Exception + { + assertQuery(getTpcdsQuery("76")); + } + + @Test + public void testTpcdsQ77() + throws Exception + { + assertQuery(getTpcdsQuery("77")); + } + + @Test + public void testTpcdsQ78() + throws Exception + { + assertQuery(getTpcdsQuery("78")); + } + + @Test + public void testTpcdsQ79() + throws Exception + { + assertQuery(getTpcdsQuery("79")); + } + + @Test + public void testTpcdsQ80() + throws Exception + { + assertQuery(getTpcdsQuery("80")); + } + + @Test + public void testTpcdsQ81() + throws Exception + { + assertQuery(getTpcdsQuery("81")); + } + + @Test + public void testTpcdsQ82() + throws Exception + { + assertQuery(getTpcdsQuery("82")); + } + + @Test + public void testTpcdsQ83() + throws Exception + { + assertQuery(getTpcdsQuery("83")); + } + + @Test + public void testTpcdsQ84() + throws Exception + { + assertQuery(getTpcdsQuery("84")); + } + + @Test + public void testTpcdsQ85() + throws Exception + { + assertQuery(getTpcdsQuery("85")); + } + + @Test + public void testTpcdsQ86() + throws Exception + { + assertQuery(getTpcdsQuery("86")); + } + + @Test + public void testTpcdsQ87() + throws Exception + { + assertQuery(getTpcdsQuery("87")); + } + + @Test + public void testTpcdsQ88() + throws Exception + { + assertQuery(getTpcdsQuery("88")); + } + + @Test + public void testTpcdsQ89() + throws Exception + { + assertQueryFails(getTpcdsQuery("89"), "[\\s\\S]*Cannot nest aggregations inside aggregation[\\s\\S]*"); + } + + @Test + public void testTpcdsQ90() + throws Exception + { + assertQuery(getTpcdsQuery("90")); + } + + @Test + public void testTpcdsQ91() + throws Exception + { + assertQuery(getTpcdsQuery("91")); + } + + @Test + public void testTpcdsQ92() + throws Exception + { + assertQuery(getTpcdsQuery("92")); + } + + @Test + public void testTpcdsQ93() + throws Exception + { + assertQuery(getTpcdsQuery("93")); + } + + @Test + public void testTpcdsQ94() + throws Exception + { + assertQuery(getTpcdsQuery("94")); + } + + @Test + public void testTpcdsQ95() + throws Exception + { + assertQuery(getTpcdsQuery("95")); + } + + @Test + public void testTpcdsQ96() + throws Exception + { + assertQuery(getTpcdsQuery("96")); + } + + @Test + public void testTpcdsQ97() + throws Exception + { + assertQuery(getTpcdsQuery("97")); + } + + @Test(enabled = false) + public void testTpcdsQ98() + throws Exception + { + assertQuery(getTpcdsQuery("98")); + } + + @Test + public void testTpcdsQ99() + throws Exception + { + assertQuery(getTpcdsQuery("99")); + } +} diff --git a/presto-native-execution/src/test/java/com/facebook/presto/nativeworker/TestHiveTpcdsQueriesDwarfUsingThrift.java b/presto-native-execution/src/test/java/com/facebook/presto/nativeworker/TestHiveTpcdsQueriesDwarfUsingThrift.java new file mode 100644 index 0000000000000..d32853715def2 --- /dev/null +++ b/presto-native-execution/src/test/java/com/facebook/presto/nativeworker/TestHiveTpcdsQueriesDwarfUsingThrift.java @@ -0,0 +1,23 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.facebook.presto.nativeworker; + +public class TestHiveTpcdsQueriesDwarfUsingThrift + extends TestHiveTpcdsQueries +{ + public TestHiveTpcdsQueriesDwarfUsingThrift() + { + super(true, "DWRF"); + } +} diff --git a/presto-native-execution/src/test/java/com/facebook/presto/nativeworker/TestHiveTpcdsQueriesParquetUsingJson.java b/presto-native-execution/src/test/java/com/facebook/presto/nativeworker/TestHiveTpcdsQueriesParquetUsingJson.java new file mode 100644 index 0000000000000..03d644bfb6e42 --- /dev/null +++ b/presto-native-execution/src/test/java/com/facebook/presto/nativeworker/TestHiveTpcdsQueriesParquetUsingJson.java @@ -0,0 +1,23 @@ +/* + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.facebook.presto.nativeworker; + +public class TestHiveTpcdsQueriesParquetUsingJson + extends TestHiveTpcdsQueries +{ + public TestHiveTpcdsQueriesParquetUsingJson() + { + super(false, "PARQUET"); + } +} diff --git a/presto-native-execution/src/test/java/com/facebook/presto/nativeworker/TestHiveTpchQueries.java b/presto-native-execution/src/test/java/com/facebook/presto/nativeworker/TestHiveTpchQueries.java index 4ed5c0e59bd23..8793580a38cc3 100644 --- a/presto-native-execution/src/test/java/com/facebook/presto/nativeworker/TestHiveTpchQueries.java +++ b/presto-native-execution/src/test/java/com/facebook/presto/nativeworker/TestHiveTpchQueries.java @@ -30,7 +30,17 @@ public abstract class TestHiveTpchQueries extends AbstractTestQueryFramework { - public static QueryRunner createNativeQueryRunner(boolean useThrift) + private final String storageFormat; + private final Boolean useThrift; + + public TestHiveTpchQueries(boolean useThrift, String storageFormat) + { + this.useThrift = useThrift; + this.storageFormat = storageFormat; + } + + @Override + public QueryRunner createQueryRunner() throws Exception { String prestoServerPath = System.getProperty("PRESTO_SERVER"); @@ -41,7 +51,7 @@ public static QueryRunner createNativeQueryRunner(boolean useThrift) assertNotNull(prestoServerPath); assertNotNull(dataDirectory); - return HiveExternalWorkerQueryRunner.createNativeQueryRunner(dataDirectory, prestoServerPath, Optional.ofNullable(workerCount).map(Integer::parseInt), cacheMaxSize, useThrift); + return HiveExternalWorkerQueryRunner.createNativeQueryRunner(dataDirectory, prestoServerPath, Optional.ofNullable(workerCount).map(Integer::parseInt), cacheMaxSize, useThrift, storageFormat); } @Override @@ -49,7 +59,7 @@ protected ExpectedQueryRunner createExpectedQueryRunner() throws Exception { String dataDirectory = System.getProperty("DATA_DIR"); - return HiveExternalWorkerQueryRunner.createJavaQueryRunner(Optional.of(Paths.get(dataDirectory))); + return HiveExternalWorkerQueryRunner.createJavaQueryRunner(Optional.of(Paths.get(dataDirectory)), storageFormat); } private static String getTpchQuery(int q) diff --git a/presto-native-execution/src/test/java/com/facebook/presto/nativeworker/TestHiveTpchQueriesUsingJSON.java b/presto-native-execution/src/test/java/com/facebook/presto/nativeworker/TestHiveTpchQueriesDwarfUsingJSON.java similarity index 72% rename from presto-native-execution/src/test/java/com/facebook/presto/nativeworker/TestHiveTpchQueriesUsingJSON.java rename to presto-native-execution/src/test/java/com/facebook/presto/nativeworker/TestHiveTpchQueriesDwarfUsingJSON.java index 12b05b3f5c46f..25b7ac30d1b31 100644 --- a/presto-native-execution/src/test/java/com/facebook/presto/nativeworker/TestHiveTpchQueriesUsingJSON.java +++ b/presto-native-execution/src/test/java/com/facebook/presto/nativeworker/TestHiveTpchQueriesDwarfUsingJSON.java @@ -13,15 +13,11 @@ */ package com.facebook.presto.nativeworker; -import com.facebook.presto.testing.QueryRunner; - -public class TestHiveTpchQueriesUsingJSON +public class TestHiveTpchQueriesDwarfUsingJSON extends TestHiveTpchQueries { - @Override - protected QueryRunner createQueryRunner() - throws Exception + public TestHiveTpchQueriesDwarfUsingJSON() { - return TestHiveTpchQueries.createNativeQueryRunner(false); + super(false, "DWRF"); } } diff --git a/presto-native-execution/src/test/java/com/facebook/presto/nativeworker/TestHiveTpchQueriesUsingThrift.java b/presto-native-execution/src/test/java/com/facebook/presto/nativeworker/TestHiveTpchQueriesParquetUsingThrift.java similarity index 72% rename from presto-native-execution/src/test/java/com/facebook/presto/nativeworker/TestHiveTpchQueriesUsingThrift.java rename to presto-native-execution/src/test/java/com/facebook/presto/nativeworker/TestHiveTpchQueriesParquetUsingThrift.java index de2115f7599b6..c2f8cd25d6fd9 100644 --- a/presto-native-execution/src/test/java/com/facebook/presto/nativeworker/TestHiveTpchQueriesUsingThrift.java +++ b/presto-native-execution/src/test/java/com/facebook/presto/nativeworker/TestHiveTpchQueriesParquetUsingThrift.java @@ -13,15 +13,11 @@ */ package com.facebook.presto.nativeworker; -import com.facebook.presto.testing.QueryRunner; - -public class TestHiveTpchQueriesUsingThrift +public class TestHiveTpchQueriesParquetUsingThrift extends TestHiveTpchQueries { - @Override - protected QueryRunner createQueryRunner() - throws Exception + public TestHiveTpchQueriesParquetUsingThrift() { - return TestHiveTpchQueries.createNativeQueryRunner(true); + super(true, "PARQUET"); } } diff --git a/presto-native-execution/src/test/java/com/facebook/presto/nativeworker/TestHiveWindowQueries.java b/presto-native-execution/src/test/java/com/facebook/presto/nativeworker/TestHiveWindowQueries.java index 2f46b815b66e1..fd0a18a50939c 100644 --- a/presto-native-execution/src/test/java/com/facebook/presto/nativeworker/TestHiveWindowQueries.java +++ b/presto-native-execution/src/test/java/com/facebook/presto/nativeworker/TestHiveWindowQueries.java @@ -24,7 +24,7 @@ public class TestHiveWindowQueries { public TestHiveWindowQueries() { - super(true); + super(true, DWARF_STORAGE_FORMAT); } protected List getRankingQueries(String rankingFunction) diff --git a/presto-native-execution/src/test/java/com/facebook/presto/nativeworker/TestTpchQueries.java b/presto-native-execution/src/test/java/com/facebook/presto/nativeworker/TestTpchQueries.java index 84de6827756c9..6eb269ebc9fef 100644 --- a/presto-native-execution/src/test/java/com/facebook/presto/nativeworker/TestTpchQueries.java +++ b/presto-native-execution/src/test/java/com/facebook/presto/nativeworker/TestTpchQueries.java @@ -21,7 +21,7 @@ public class TestTpchQueries { public TestTpchQueries() { - super(true); + super(true, DWARF_STORAGE_FORMAT); } @Test diff --git a/presto-native-execution/src/test/resources/tpcds/queries/q01.sql b/presto-native-execution/src/test/resources/tpcds/queries/q01.sql new file mode 100644 index 0000000000000..3232f127dbfba --- /dev/null +++ b/presto-native-execution/src/test/resources/tpcds/queries/q01.sql @@ -0,0 +1,29 @@ +WITH + customer_total_return AS ( + SELECT + "sr_customer_sk" "ctr_customer_sk" + , "sr_store_sk" "ctr_store_sk" + , "round"("sum"("sr_return_amt"), 2) "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") * DECIMAL '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" ASC +LIMIT 100 diff --git a/presto-native-execution/src/test/resources/tpcds/queries/q02.sql b/presto-native-execution/src/test/resources/tpcds/queries/q02.sql new file mode 100644 index 0000000000000..4e07e87681944 --- /dev/null +++ b/presto-native-execution/src/test/resources/tpcds/queries/q02.sql @@ -0,0 +1,80 @@ +WITH + wscs AS ( + SELECT + "sold_date_sk" + , "sales_price" + FROM + ( + SELECT + "ws_sold_date_sk" "sold_date_sk" + , "ws_ext_sales_price" "sales_price" + FROM + web_sales + ) +UNION ALL ( + SELECT + "cs_sold_date_sk" "sold_date_sk" + , "cs_ext_sales_price" "sales_price" + FROM + catalog_sales + ) ) +, wswscs AS ( + SELECT + "d_week_seq" + , "sum"((CASE WHEN ("d_day_name" = 'Sunday') THEN "sales_price" ELSE null END)) "sun_sales" + , "sum"((CASE WHEN ("d_day_name" = 'Monday') THEN "sales_price" ELSE null END)) "mon_sales" + , "sum"((CASE WHEN ("d_day_name" = 'Tuesday') THEN "sales_price" ELSE null END)) "tue_sales" + , "sum"((CASE WHEN ("d_day_name" = 'Wednesday') THEN "sales_price" ELSE null END)) "wed_sales" + , "sum"((CASE WHEN ("d_day_name" = 'Thursday') THEN "sales_price" ELSE null END)) "thu_sales" + , "sum"((CASE WHEN ("d_day_name" = 'Friday') THEN "sales_price" ELSE null END)) "fri_sales" + , "sum"((CASE WHEN ("d_day_name" = 'Saturday') THEN "sales_price" ELSE null END)) "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" "d_week_seq1" + , "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 + wswscs + , date_dim + WHERE ("date_dim"."d_week_seq" = "wswscs"."d_week_seq") + AND ("d_year" = 2001) +) y +, ( + SELECT + "wswscs"."d_week_seq" "d_week_seq2" + , "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 + 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" ASC diff --git a/presto-native-execution/src/test/resources/tpcds/queries/q03.sql b/presto-native-execution/src/test/resources/tpcds/queries/q03.sql new file mode 100644 index 0000000000000..23fb8e8a904b9 --- /dev/null +++ b/presto-native-execution/src/test/resources/tpcds/queries/q03.sql @@ -0,0 +1,16 @@ +SELECT + "dt"."d_year" +, "item"."i_brand_id" "brand_id" +, "item"."i_brand" "brand" +, "round"("sum"("ss_ext_sales_price"), 2) "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" ASC, "sum_agg" DESC, "brand_id" ASC +LIMIT 100 diff --git a/presto-native-execution/src/test/resources/tpcds/queries/q04.sql b/presto-native-execution/src/test/resources/tpcds/queries/q04.sql new file mode 100644 index 0000000000000..ea91fe5ad1437 --- /dev/null +++ b/presto-native-execution/src/test/resources/tpcds/queries/q04.sql @@ -0,0 +1,93 @@ +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" + , "round"("sum"((((("ss_ext_list_price" - "ss_ext_wholesale_cost") - "ss_ext_discount_amt") + "ss_ext_sales_price") / 2)), 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" + , "round"("sum"((((("cs_ext_list_price" - "cs_ext_wholesale_cost") - "cs_ext_discount_amt") + "cs_ext_sales_price") / 2)), 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" + , "round"("sum"((((("ws_ext_list_price" - "ws_ext_wholesale_cost") - "ws_ext_discount_amt") + "ws_ext_sales_price") / 2)), 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" ASC, "t_s_secyear"."customer_first_name" ASC, "t_s_secyear"."customer_last_name" ASC, "t_s_secyear"."customer_preferred_cust_flag" ASC +LIMIT 100 diff --git a/presto-native-execution/src/test/resources/tpcds/queries/q05.sql b/presto-native-execution/src/test/resources/tpcds/queries/q05.sql new file mode 100644 index 0000000000000..070541be2f955 --- /dev/null +++ b/presto-native-execution/src/test/resources/tpcds/queries/q05.sql @@ -0,0 +1,144 @@ +WITH + ssr AS ( + SELECT + "s_store_id" + , "round"("sum"("sales_price"), 2) "sales" + , "round"("sum"("profit"), 2) "profit" + , "round"("sum"("return_amt"), 2) "returns" + , "round"("sum"("net_loss"), 2) "profit_loss" + FROM + ( + SELECT + "ss_store_sk" "store_sk" + , "ss_sold_date_sk" "date_sk" + , "ss_ext_sales_price" "sales_price" + , "ss_net_profit" "profit" + , CAST(0 AS DECIMAL(7,2)) "return_amt" + , CAST(0 AS DECIMAL(7,2)) "net_loss" + FROM + store_sales +UNION ALL SELECT + "sr_store_sk" "store_sk" + , "sr_returned_date_sk" "date_sk" + , CAST(0 AS DECIMAL(7,2)) "sales_price" + , CAST(0 AS DECIMAL(7,2)) "profit" + , "sr_return_amt" "return_amt" + , "sr_net_loss" "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 (CAST('2000-08-23' AS DATE) + INTERVAL '14' DAY)) + AND ("store_sk" = "s_store_sk") + GROUP BY "s_store_id" +) +, csr AS ( + SELECT + "cp_catalog_page_id" + , "round"("sum"("sales_price"), 2) "sales" + , "round"("sum"("profit"), 2) "profit" + , "round"("sum"("return_amt"), 2) "returns" + , "round"("sum"("net_loss"), 2) "profit_loss" + FROM + ( + SELECT + "cs_catalog_page_sk" "page_sk" + , "cs_sold_date_sk" "date_sk" + , "cs_ext_sales_price" "sales_price" + , "cs_net_profit" "profit" + , CAST(0 AS DECIMAL(7,2)) "return_amt" + , CAST(0 AS DECIMAL(7,2)) "net_loss" + FROM + catalog_sales +UNION ALL SELECT + "cr_catalog_page_sk" "page_sk" + , "cr_returned_date_sk" "date_sk" + , CAST(0 AS DECIMAL(7,2)) "sales_price" + , CAST(0 AS DECIMAL(7,2)) "profit" + , "cr_return_amount" "return_amt" + , "cr_net_loss" "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 (CAST('2000-08-23' AS DATE) + INTERVAL '14' DAY)) + AND ("page_sk" = "cp_catalog_page_sk") + GROUP BY "cp_catalog_page_id" +) +, wsr AS ( + SELECT + "web_site_id" + , "round"("sum"("sales_price"), 2) "sales" + , "round"("sum"("profit"), 2) "profit" + , "round"("sum"("return_amt"), 2) "returns" + , "round"("sum"("net_loss"), 2) "profit_loss" + FROM + ( + SELECT + "ws_web_site_sk" "wsr_web_site_sk" + , "ws_sold_date_sk" "date_sk" + , "ws_ext_sales_price" "sales_price" + , "ws_net_profit" "profit" + , CAST(0 AS DECIMAL(7,2)) "return_amt" + , CAST(0 AS DECIMAL(7,2)) "net_loss" + FROM + web_sales +UNION ALL SELECT + "ws_web_site_sk" "wsr_web_site_sk" + , "wr_returned_date_sk" "date_sk" + , CAST(0 AS DECIMAL(7,2)) "sales_price" + , CAST(0 AS DECIMAL(7,2)) "profit" + , "wr_return_amt" "return_amt" + , "wr_net_loss" "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 (CAST('2000-08-23' AS DATE) + INTERVAL '14' DAY)) + AND ("wsr_web_site_sk" = "web_site_sk") + GROUP BY "web_site_id" +) +SELECT + "channel" +, "id" +, "round"("sum"("sales"), 2) "sales" +, "round"("sum"("returns"), 2) "returns" +, "round"("sum"("profit"), 2) "profit" +FROM + ( + SELECT + 'store channel' "channel" + , "concat"('store', "s_store_id") "id" + , "sales" + , "returns" + , ("profit" - "profit_loss") "profit" + FROM + ssr +UNION ALL SELECT + 'catalog channel' "channel" + , "concat"('catalog_page', "cp_catalog_page_id") "id" + , "sales" + , "returns" + , ("profit" - "profit_loss") "profit" + FROM + csr +UNION ALL SELECT + 'web channel' "channel" + , "concat"('web_site', "web_site_id") "id" + , "sales" + , "returns" + , ("profit" - "profit_loss") "profit" + FROM + wsr +) x +GROUP BY ROLLUP (channel, id) +ORDER BY "channel" ASC, "id" ASC +LIMIT 100 diff --git a/presto-native-execution/src/test/resources/tpcds/queries/q06.sql b/presto-native-execution/src/test/resources/tpcds/queries/q06.sql new file mode 100644 index 0000000000000..e9d8758845fbf --- /dev/null +++ b/presto-native-execution/src/test/resources/tpcds/queries/q06.sql @@ -0,0 +1,30 @@ +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" > (DECIMAL '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" ASC, "a"."ca_state" ASC +LIMIT 100 diff --git a/presto-native-execution/src/test/resources/tpcds/queries/q07.sql b/presto-native-execution/src/test/resources/tpcds/queries/q07.sql new file mode 100644 index 0000000000000..a387dbc17521a --- /dev/null +++ b/presto-native-execution/src/test/resources/tpcds/queries/q07.sql @@ -0,0 +1,25 @@ +SELECT + "i_item_id" +, "round"("avg"("ss_quantity"), 4) "agg1" +, "round"("avg"("ss_list_price"), 2) "agg2" +, "round"("avg"("ss_coupon_amt"), 4) "agg3" +, "round"("avg"("ss_sales_price"), 2) "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" ASC +LIMIT 100 diff --git a/presto-native-execution/src/test/resources/tpcds/queries/q08.sql b/presto-native-execution/src/test/resources/tpcds/queries/q08.sql new file mode 100644 index 0000000000000..37b0b2f84defa --- /dev/null +++ b/presto-native-execution/src/test/resources/tpcds/queries/q08.sql @@ -0,0 +1,441 @@ +SELECT + "s_store_name" +, "round"("sum"("ss_net_profit"), 2) +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' + , '57834' + , '13354' + , '15734' + , '78668' + , '76232' + , '62878' + , '45375' + , '63435' + , '22245' + , '65084' + , '49130' + , '40558' + , '25733' + , '15798' + , '87816' + , '81096' + , '56458' + , '35474' + , '27156' + , '83926' + , '18840' + , '28286' + , '24676' + , '37930' + , '77556' + , '27700' + , '45266' + , '94627' + , '62971' + , '20548' + , '23470' + , '47305' + , '53535' + , '21337' + , '26231' + , '50412' + , '69399' + , '17879' + , '51622' + , '43848' + , '21195' + , '83921' + , '15559' + , '67853' + , '15126' + , '16021' + , '26233' + , '53268' + , '10567' + , '91137' + , '76107' + , '11101' + , '59166' + , '38415' + , '61265' + , '71954' + , '15371' + , '11928' + , '15455' + , '98294' + , '68309' + , '69913' + , '59402' + , '58263' + , '25782' + , '18119' + , '35942' + , '33282' + , '42029' + , '17920' + , '98359' + , '15882' + , '45721' + , '60279' + , '18426' + , '64544' + , '25631' + , '43933' + , '37125' + , '98235' + , '10336' + , '24610' + , '68101' + , '56240' + , '40081' + , '86379' + , '44165' + , '33515' + , '88190' + , '84093' + , '27068' + , '99076' + , '36634' + , '50308' + , '28577' + , '39736' + , '33786' + , '71286' + , '26859' + , '55565' + , '98569' + , '70738' + , '19736' + , '64457' + , '17183' + , '28915' + , '26653' + , '58058' + , '89091' + , '54601' + , '24206' + , '14328' + , '55253' + , '82136' + , '67897' + , '56529' + , '72305' + , '67473' + , '62377' + , '22752' + , '57647' + , '62496' + , '41918' + , '36233' + , '86284' + , '54917' + , '22152' + , '19515' + , '63837' + , '18376' + , '42961' + , '10144' + , '36495' + , '58078' + , '38607' + , '91110' + , '64147' + , '19430' + , '17043' + , '45200' + , '63981' + , '48425' + , '22351' + , '30010' + , '21756' + , '14922' + , '14663' + , '77191' + , '60099' + , '29741' + , '36420' + , '21076' + , '91393' + , '28810' + , '96765' + , '23006' + , '18799' + , '49156' + , '98025' + , '23932' + , '67467' + , '30450' + , '50298' + , '29178' + , '89360' + , '32754' + , '63089' + , '87501' + , '87343' + , '29839' + , '30903' + , '81019' + , '18652' + , '73273' + , '25989' + , '20260' + , '68893' + , '53179' + , '30469' + , '28898' + , '31671' + , '24996' + , '18767' + , '64034' + , '91068' + , '51798' + , '51200' + , '63193' + , '39516' + , '72550' + , '72325' + , '51211' + , '23968' + , '86057' + , '10390' + , '85816' + , '45692' + , '65164' + , '21309' + , '18845' + , '68621' + , '92712' + , '68880' + , '90257' + , '47770' + , '13955' + , '70466' + , '21286' + , '67875' + , '82636' + , '36446' + , '79994' + , '72823' + , '40162' + , '41367' + , '41766' + , '22437' + , '58470' + , '11356' + , '76638' + , '68806' + , '25280' + , '67301' + , '73650' + , '86198' + , '16725' + , '38935' + , '13394' + , '61810' + , '81312' + , '15146' + , '71791' + , '31016' + , '72013' + , '37126' + , '22744' + , '73134' + , '70372' + , '30431' + , '39192' + , '35850' + , '56571' + , '67030' + , '22461' + , '88424' + , '88086' + , '14060' + , '40604' + , '19512' + , '72175' + , '51649' + , '19505' + , '24317' + , '13375' + , '81426' + , '18270' + , '72425' + , '45748' + , '55307' + , '53672' + , '52867' + , '56575' + , '39127' + , '30625' + , '10445' + , '39972' + , '74351' + , '26065' + , '83849' + , '42666' + , '96976' + , '68786' + , '77721' + , '68908' + , '66864' + , '63792' + , '51650' + , '31029' + , '26689' + , '66708' + , '11376' + , '20004' + , '31880' + , '96451' + , '41248' + , '94898' + , '18383' + , '60576' + , '38193' + , '48583' + , '13595' + , '76614' + , '24671' + , '46820' + , '82276' + , '10516' + , '11634' + , '45549' + , '88885' + , '18842' + , '90225' + , '18906' + , '13376' + , '84935' + , '78890' + , '58943' + , '15765' + , '50016' + , '69035' + , '49448' + , '39371' + , '41368' + , '33123' + , '83144' + , '14089' + , '94945' + , '73241' + , '19769' + , '47537' + , '38122' + , '28587' + , '76698' + , '22927' + , '56616' + , '34425' + , '96576' + , '78567' + , '97789' + , '94983' + , '79077' + , '57855' + , '97189' + , '46081' + , '48033' + , '19849' + , '28488' + , '28545' + , '72151' + , '69952' + , '43285' + , '26105' + , '76231' + , '15723' + , '25486' + , '39861' + , '83933' + , '75691' + , '46136' + , '61547' + , '66162' + , '25858' + , '22246' + , '51949' + , '27385' + , '77610' + , '34322' + , '51061' + , '68100' + , '61860' + , '13695' + , '44438' + , '90578' + , '96888' + , '58048' + , '99543' + , '73171' + , '56691' + , '64528' + , '56910' + , '83444' + , '30122' + , '68014' + , '14171' + , '16807' + , '83041' + , '34102' + , '51103' + , '79777' + , '17871' + , '12305' + , '22685' + , '94167' + , '28709' + , '35258' + , '57665' + , '71256' + , '57047' + , '11489' + , '31387' + , '68341' + , '78451' + , '14867' + , '25103' + , '35458' + , '25003' + , '54364' + , '73520' + , '32213' + , '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" ASC +LIMIT 100 diff --git a/presto-native-execution/src/test/resources/tpcds/queries/q09.sql b/presto-native-execution/src/test/resources/tpcds/queries/q09.sql new file mode 100644 index 0000000000000..b21552bf4f888 --- /dev/null +++ b/presto-native-execution/src/test/resources/tpcds/queries/q09.sql @@ -0,0 +1,84 @@ +SELECT + (CASE WHEN (( + SELECT "count"(*) + FROM + store_sales + WHERE ("ss_quantity" BETWEEN 1 AND 20) + ) > 74129) THEN ( + SELECT "round"("avg"("ss_ext_discount_amt"), 2) + FROM + store_sales + WHERE ("ss_quantity" BETWEEN 1 AND 20) +) ELSE ( + SELECT "round"("avg"("ss_net_paid"), 2) + 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 "round"("avg"("ss_ext_discount_amt"), 2) + FROM + store_sales + WHERE ("ss_quantity" BETWEEN 21 AND 40) +) ELSE ( + SELECT "round"("avg"("ss_net_paid"), 2) + 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 "round"("avg"("ss_ext_discount_amt"), 2) + FROM + store_sales + WHERE ("ss_quantity" BETWEEN 41 AND 60) +) ELSE ( + SELECT "round"("avg"("ss_net_paid"), 2) + 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 "round"("avg"("ss_ext_discount_amt"), 2) + FROM + store_sales + WHERE ("ss_quantity" BETWEEN 61 AND 80) +) ELSE ( + SELECT "round"("avg"("ss_net_paid"), 2) + 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 "round"("avg"("ss_ext_discount_amt"), 2) + FROM + store_sales + WHERE ("ss_quantity" BETWEEN 81 AND 100) +) ELSE ( + SELECT "round"("avg"("ss_net_paid"), 2) + FROM + store_sales + WHERE ("ss_quantity" BETWEEN 81 AND 100) +) END) "bucket5" +FROM + reason +WHERE ("r_reason_sk" = 1) diff --git a/presto-native-execution/src/test/resources/tpcds/queries/q10.sql b/presto-native-execution/src/test/resources/tpcds/queries/q10.sql new file mode 100644 index 0000000000000..311e0a36064e4 --- /dev/null +++ b/presto-native-execution/src/test/resources/tpcds/queries/q10.sql @@ -0,0 +1,55 @@ +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" ASC, "cd_marital_status" ASC, "cd_education_status" ASC, "cd_purchase_estimate" ASC, "cd_credit_rating" ASC, "cd_dep_count" ASC, "cd_dep_employed_count" ASC, "cd_dep_college_count" ASC +LIMIT 100 diff --git a/presto-native-execution/src/test/resources/tpcds/queries/q11.sql b/presto-native-execution/src/test/resources/tpcds/queries/q11.sql new file mode 100644 index 0000000000000..965cc13b00e61 --- /dev/null +++ b/presto-native-execution/src/test/resources/tpcds/queries/q11.sql @@ -0,0 +1,67 @@ +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" + , "round"("sum"(("ss_ext_list_price" - "ss_ext_discount_amt")), 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" + , "round"("sum"(("ws_ext_list_price" - "ws_ext_discount_amt")), 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" +, "t_s_secyear"."customer_birth_country" +, "t_s_secyear"."customer_login" +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 DECIMAL '0.0' END) > (CASE WHEN ("t_s_firstyear"."year_total" > 0) THEN ("t_s_secyear"."year_total" / "t_s_firstyear"."year_total") ELSE DECIMAL '0.0' END)) +ORDER BY "t_s_secyear"."customer_id" ASC, "t_s_secyear"."customer_first_name" ASC, "t_s_secyear"."customer_last_name" ASC, "t_s_secyear"."customer_preferred_cust_flag" ASC +LIMIT 100 diff --git a/presto-native-execution/src/test/resources/tpcds/queries/q12.sql b/presto-native-execution/src/test/resources/tpcds/queries/q12.sql new file mode 100644 index 0000000000000..5ebcbfd69a089 --- /dev/null +++ b/presto-native-execution/src/test/resources/tpcds/queries/q12.sql @@ -0,0 +1,19 @@ +SELECT + "i_item_id" +, "i_item_desc" +, "i_category" +, "i_class" +, "i_current_price" +, "round"("sum"("ws_ext_sales_price"), 2) "itemrevenue" +, "round"((("sum"("ws_ext_sales_price") * 100) / "sum"("sum"("ws_ext_sales_price")) OVER (PARTITION BY "i_class")), 4) "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 (CAST("d_date" AS DATE) BETWEEN CAST('1999-02-22' AS DATE) AND (CAST('1999-02-22' AS DATE) + INTERVAL '30' DAY)) +GROUP BY "i_item_id", "i_item_desc", "i_category", "i_class", "i_current_price" +ORDER BY "i_category" ASC, "i_class" ASC, "i_item_id" ASC, "i_item_desc" ASC, "revenueratio" ASC +LIMIT 100 diff --git a/presto-native-execution/src/test/resources/tpcds/queries/q13.sql b/presto-native-execution/src/test/resources/tpcds/queries/q13.sql new file mode 100644 index 0000000000000..2ef6c85e6af55 --- /dev/null +++ b/presto-native-execution/src/test/resources/tpcds/queries/q13.sql @@ -0,0 +1,45 @@ +SELECT + "round"("avg"("ss_quantity"), 2) +, "round"("avg"("ss_ext_sales_price"), 2) +, "round"("avg"("ss_ext_wholesale_cost"), 2) +, "round"("sum"("ss_ext_wholesale_cost"), 2) +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 DECIMAL '100.00' AND DECIMAL '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 DECIMAL '50.00' AND DECIMAL '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 DECIMAL '150.00' AND DECIMAL '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/presto-native-execution/src/test/resources/tpcds/queries/q14_1.sql b/presto-native-execution/src/test/resources/tpcds/queries/q14_1.sql new file mode 100644 index 0000000000000..dccc70b02cd22 --- /dev/null +++ b/presto-native-execution/src/test/resources/tpcds/queries/q14_1.sql @@ -0,0 +1,165 @@ +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 "round"("avg"(("quantity" * "list_price")), 2) "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" +, "round"("sum"("sales"), 2) +, "round"("sum"("number_sales"), 2) +FROM + ( + SELECT + 'store' "channel" + , "i_brand_id" + , "i_class_id" + , "i_category_id" + , "round"("sum"(("ss_quantity" * "ss_list_price")), 2) "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 ("round"("sum"(("ss_quantity" * "ss_list_price"), 2)) > ( + SELECT "average_sales" + FROM + avg_sales + )) +UNION ALL SELECT + 'catalog' "channel" + , "i_brand_id" + , "i_class_id" + , "i_category_id" + , "round"("sum"(("cs_quantity" * "cs_list_price")), 2) "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 ("round"("sum"("cs_quantity" * "cs_list_price"), 2) > ( + SELECT "average_sales" + FROM + avg_sales + )) +UNION ALL SELECT + 'web' "channel" + , "i_brand_id" + , "i_class_id" + , "i_category_id" + , "round"("sum"("ws_quantity" * "ws_list_price"), 2) "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 ("round"("sum"(("ws_quantity" * "ws_list_price")), 2) > ( + SELECT "average_sales" + FROM + avg_sales + )) +) +GROUP BY ROLLUP (channel, i_brand_id, i_class_id, i_category_id) +ORDER BY "channel" ASC, "i_brand_id" ASC, "i_class_id" ASC, "i_category_id" ASC +LIMIT 100 diff --git a/presto-native-execution/src/test/resources/tpcds/queries/q14_2.sql b/presto-native-execution/src/test/resources/tpcds/queries/q14_2.sql new file mode 100644 index 0000000000000..867baae035e40 --- /dev/null +++ b/presto-native-execution/src/test/resources/tpcds/queries/q14_2.sql @@ -0,0 +1,149 @@ +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 "round"("avg"(("quantity" * "list_price")), 2) "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)) + ) +) +SELECT * +FROM + ( + SELECT + 'store' "channel" + , "i_brand_id" + , "i_class_id" + , "i_category_id" + , "round"("sum"(("ss_quantity" * "ss_list_price")), 2) "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 ("round"("sum"("ss_quantity" * "ss_list_price"), 2) > ( + SELECT "average_sales" + FROM + avg_sales + )) +) this_year +, ( + SELECT + 'store' "channel" + , "i_brand_id" + , "i_class_id" + , "i_category_id" + , "round"("sum"(("ss_quantity" * "ss_list_price")), 2) "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) + AND ("d_moy" = 12) + AND ("d_dom" = 11) + )) + GROUP BY "i_brand_id", "i_class_id", "i_category_id" + HAVING ("round"("sum"(("ss_quantity" * "ss_list_price")), 2) > ( + SELECT "average_sales" + FROM + avg_sales + )) +) last_year +WHERE ("this_year"."i_brand_id" = "last_year"."i_brand_id") + AND ("this_year"."i_class_id" = "last_year"."i_class_id") + AND ("this_year"."i_category_id" = "last_year"."i_category_id") +ORDER BY "this_year"."channel" ASC, "this_year"."i_brand_id" ASC, "this_year"."i_class_id" ASC, "this_year"."i_category_id" ASC +LIMIT 100 diff --git a/presto-native-execution/src/test/resources/tpcds/queries/q15.sql b/presto-native-execution/src/test/resources/tpcds/queries/q15.sql new file mode 100644 index 0000000000000..4f07cab5a14c1 --- /dev/null +++ b/presto-native-execution/src/test/resources/tpcds/queries/q15.sql @@ -0,0 +1,19 @@ +SELECT + "ca_zip" +, "round"("sum"("cs_sales_price"), 2) +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" ASC +LIMIT 100 diff --git a/presto-native-execution/src/test/resources/tpcds/queries/q16.sql b/presto-native-execution/src/test/resources/tpcds/queries/q16.sql new file mode 100644 index 0000000000000..e887634fd99a3 --- /dev/null +++ b/presto-native-execution/src/test/resources/tpcds/queries/q16.sql @@ -0,0 +1,30 @@ +SELECT + "count"(DISTINCT "cs_order_number") "order count" +, "round"("sum"("cs_ext_ship_cost") "total shipping cost", 2) +, "round"("sum"("cs_net_profit") "total net profit", 2) +FROM + catalog_sales cs1 +, date_dim +, customer_address +, call_center +WHERE ("d_date" BETWEEN CAST('2002-2-01' AS DATE) AND (CAST('2002-2-01' AS DATE) + INTERVAL '60' DAY)) + 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") ASC +LIMIT 100 diff --git a/presto-native-execution/src/test/resources/tpcds/queries/q17.sql b/presto-native-execution/src/test/resources/tpcds/queries/q17.sql new file mode 100644 index 0000000000000..1a32200ebd5b1 --- /dev/null +++ b/presto-native-execution/src/test/resources/tpcds/queries/q17.sql @@ -0,0 +1,41 @@ +SELECT + "i_item_id" +, "i_item_desc" +, "s_state" +, "count"("ss_quantity") "store_sales_quantitycount" +, "round"("avg"("ss_quantity"), 2) "store_sales_quantityave" +, "stddev_samp"("ss_quantity") "store_sales_quantitystdev" +, "round"(("stddev_samp"("ss_quantity") / "avg"("ss_quantity")), 2) "store_sales_quantitycov" +, "count"("sr_return_quantity") "store_returns_quantitycount" +, "round"("avg"("sr_return_quantity"), 2) "store_returns_quantityave" +, "stddev_samp"("sr_return_quantity") "store_returns_quantitystdev" +, "round"(("stddev_samp"("sr_return_quantity") / "avg"("sr_return_quantity")), 2) "store_returns_quantitycov" +, "count"("cs_quantity") "catalog_sales_quantitycount" +, "round"("avg"("cs_quantity"), 2) "catalog_sales_quantityave" +, "stddev_samp"("cs_quantity") "catalog_sales_quantitystdev" +, "round"(("stddev_samp"("cs_quantity") / "avg"("cs_quantity")), 2) "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" ASC, "i_item_desc" ASC, "s_state" ASC +LIMIT 100 diff --git a/presto-native-execution/src/test/resources/tpcds/queries/q18.sql b/presto-native-execution/src/test/resources/tpcds/queries/q18.sql new file mode 100644 index 0000000000000..d85d22609f0ee --- /dev/null +++ b/presto-native-execution/src/test/resources/tpcds/queries/q18.sql @@ -0,0 +1,41 @@ +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" +, "round"("avg"(CAST("cs_quantity" AS double)), 2) "agg1" +, "round"("avg"(CAST("cs_list_price" AS double)), 2) "agg2" +, "round"("avg"(CAST("cs_coupon_amt" AS double)), 2) "agg3" +, "round"("avg"(CAST("cs_sales_price" AS double)), 2) "agg4" +, "round"("avg"(CAST("cs_net_profit" AS double)), 2) "agg5" +, "round"("avg"(CAST("c_birth_year" AS double)), 2) "agg6" +, "round"("avg"(CAST("cd1"."cd_dep_count" AS double)), 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" ASC, "ca_state" ASC, "ca_county" ASC, "i_item_id" ASC +LIMIT 100 diff --git a/presto-native-execution/src/test/resources/tpcds/queries/q19.sql b/presto-native-execution/src/test/resources/tpcds/queries/q19.sql new file mode 100644 index 0000000000000..765708bdd0993 --- /dev/null +++ b/presto-native-execution/src/test/resources/tpcds/queries/q19.sql @@ -0,0 +1,25 @@ +SELECT + "i_brand_id" "brand_id" +, "i_brand" "brand" +, "i_manufact_id" +, "i_manufact" +, "round"("sum"("ss_ext_sales_price"), 2) "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" ASC, "i_brand_id" ASC, "i_manufact_id" ASC, "i_manufact" ASC +LIMIT 100 diff --git a/presto-native-execution/src/test/resources/tpcds/queries/q20.sql b/presto-native-execution/src/test/resources/tpcds/queries/q20.sql new file mode 100644 index 0000000000000..f1dfbbc07c5f1 --- /dev/null +++ b/presto-native-execution/src/test/resources/tpcds/queries/q20.sql @@ -0,0 +1,19 @@ +SELECT + "i_item_id" +, "i_item_desc" +, "i_category" +, "i_class" +, "i_current_price" +, "round"("sum"("cs_ext_sales_price"), 2) "itemrevenue" +, "round"((("sum"("cs_ext_sales_price") * 100) / "sum"("sum"("cs_ext_sales_price")) OVER (PARTITION BY "i_class")), 2) "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 (CAST("d_date" AS DATE) BETWEEN CAST('1999-02-22' AS DATE) AND (CAST('1999-02-22' AS DATE) + INTERVAL '30' DAY)) +GROUP BY "i_item_id", "i_item_desc", "i_category", "i_class", "i_current_price" +ORDER BY "i_category" ASC, "i_class" ASC, "i_item_id" ASC, "i_item_desc" ASC, "revenueratio" ASC +LIMIT 100 diff --git a/presto-native-execution/src/test/resources/tpcds/queries/q21.sql b/presto-native-execution/src/test/resources/tpcds/queries/q21.sql new file mode 100644 index 0000000000000..46fd60a02f332 --- /dev/null +++ b/presto-native-execution/src/test/resources/tpcds/queries/q21.sql @@ -0,0 +1,25 @@ +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)) "inv_before" + , "sum"((CASE WHEN (CAST("d_date" AS DATE) >= CAST('2000-03-11' AS DATE)) THEN "inv_quantity_on_hand" ELSE 0 END)) "inv_after" + FROM + inventory + , warehouse + , item + , date_dim +-- WHERE ("i_current_price" BETWEEN DECIMAL '0.99' AND DECIMAL '1.49') + 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 (CAST('2000-03-11' AS DATE) - INTERVAL '30' DAY) AND (CAST('2000-03-11' AS DATE) + INTERVAL '30' DAY)) + GROUP BY "w_warehouse_name", "i_item_id" +) x +-- WHERE ((CASE WHEN ("inv_before" > 0) THEN (CAST("inv_after" AS DECIMAL(7,2)) / "inv_before") ELSE null END) BETWEEN (DECIMAL '2.00' / DECIMAL '3.00') AND (DECIMAL '3.00' / DECIMAL '2.00')) +WHERE ((CASE WHEN ("inv_before" > 0) THEN (CAST("inv_after" AS DOUBLE ) / "inv_before") ELSE null END) BETWEEN (2.00 / 3.00) AND (3.00 / 2.00)) +ORDER BY "w_warehouse_name" ASC, "i_item_id" ASC +LIMIT 100 diff --git a/presto-native-execution/src/test/resources/tpcds/queries/q22.sql b/presto-native-execution/src/test/resources/tpcds/queries/q22.sql new file mode 100644 index 0000000000000..ccd9d2f3147aa --- /dev/null +++ b/presto-native-execution/src/test/resources/tpcds/queries/q22.sql @@ -0,0 +1,16 @@ +SELECT + "i_product_name" +, "i_brand" +, "i_class" +, "i_category" +, "round"("avg"("inv_quantity_on_hand"), 2) "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" ASC, "i_product_name" ASC, "i_brand" ASC, "i_class" ASC, "i_category" ASC +LIMIT 100 diff --git a/presto-native-execution/src/test/resources/tpcds/queries/q23_1.sql b/presto-native-execution/src/test/resources/tpcds/queries/q23_1.sql new file mode 100644 index 0000000000000..ff2dac1c5b1e3 --- /dev/null +++ b/presto-native-execution/src/test/resources/tpcds/queries/q23_1.sql @@ -0,0 +1,88 @@ +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" + , "round"("sum"(("ss_quantity" * "ss_sales_price")), 2) "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" + , "round"("sum"(("ss_quantity" * "ss_sales_price")), 2) "ssales" + FROM + store_sales + , customer + WHERE ("ss_customer_sk" = "c_customer_sk") + GROUP BY "c_customer_sk" + HAVING ("round"("sum"(("ss_quantity" * "ss_sales_price")), 2) > ((50 / DECIMAL '100.0') * ( + SELECT * + FROM + max_store_sales + ))) +) +SELECT "round"("sum"("sales"), 2) +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 diff --git a/presto-native-execution/src/test/resources/tpcds/queries/q23_2.sql b/presto-native-execution/src/test/resources/tpcds/queries/q23_2.sql new file mode 100644 index 0000000000000..a4ffd8540966e --- /dev/null +++ b/presto-native-execution/src/test/resources/tpcds/queries/q23_2.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" + , "round"("sum"(("ss_quantity" * "ss_sales_price")), 2) "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" + , "round"("sum"(("ss_quantity" * "ss_sales_price")), 2) "ssales" + FROM + store_sales + , customer + WHERE ("ss_customer_sk" = "c_customer_sk") + GROUP BY "c_customer_sk" + HAVING ("round"("sum"(("ss_quantity" * "ss_sales_price")), 2) > ((50 / DECIMAL '100.0') * ( + SELECT * + FROM + max_store_sales + ))) +) +SELECT + "c_last_name" +, "c_first_name" +, "sales" +FROM + ( + SELECT + "c_last_name" + , "c_first_name" + , "round"("sum"(("cs_quantity" * "cs_list_price")), 2) "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" + , "round"("sum"(("ws_quantity" * "ws_list_price")), 2) "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" ASC, "c_first_name" ASC, "sales" ASC +LIMIT 100 diff --git a/presto-native-execution/src/test/resources/tpcds/queries/q24_1.sql b/presto-native-execution/src/test/resources/tpcds/queries/q24_1.sql new file mode 100644 index 0000000000000..bc997e6b11dd4 --- /dev/null +++ b/presto-native-execution/src/test/resources/tpcds/queries/q24_1.sql @@ -0,0 +1,45 @@ +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" + , "round"("sum"("ss_net_paid"), 2) "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_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" +, "round"("sum"("netpaid"), 2) "paid" +FROM + ssales +WHERE ("i_color" = 'pale') +GROUP BY "c_last_name", "c_first_name", "s_store_name" +HAVING ("round"("sum"("netpaid"), 2) > ( + SELECT (DECIMAL '0.05' * "avg"("netpaid")) + FROM + ssales + )) diff --git a/presto-native-execution/src/test/resources/tpcds/queries/q24_2.sql b/presto-native-execution/src/test/resources/tpcds/queries/q24_2.sql new file mode 100644 index 0000000000000..a090c5ab78a8a --- /dev/null +++ b/presto-native-execution/src/test/resources/tpcds/queries/q24_2.sql @@ -0,0 +1,45 @@ +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" + , "round"("sum"("ss_net_paid"), 2) "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_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" +, "round"("sum"("netpaid"), 2) "paid" +FROM + ssales +WHERE ("i_color" = 'chiffon') +GROUP BY "c_last_name", "c_first_name", "s_store_name" +HAVING ("round"("sum"("netpaid"), 2) > ( + SELECT (DECIMAL '0.05' * "avg"("netpaid")) + FROM + ssales + )) diff --git a/presto-native-execution/src/test/resources/tpcds/queries/q25.sql b/presto-native-execution/src/test/resources/tpcds/queries/q25.sql new file mode 100644 index 0000000000000..628b34fb1d0a0 --- /dev/null +++ b/presto-native-execution/src/test/resources/tpcds/queries/q25.sql @@ -0,0 +1,36 @@ +SELECT + "i_item_id" +, "i_item_desc" +, "s_store_id" +, "s_store_name" +, "round"("sum"("ss_net_profit"), 2) "store_sales_profit" +, "round"("sum"("sr_net_loss"), 2) "store_returns_loss" +, "round"("sum"("cs_net_profit"), 2) "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" ASC, "i_item_desc" ASC, "s_store_id" ASC, "s_store_name" ASC +LIMIT 100 diff --git a/presto-native-execution/src/test/resources/tpcds/queries/q26.sql b/presto-native-execution/src/test/resources/tpcds/queries/q26.sql new file mode 100644 index 0000000000000..44cf751b1b995 --- /dev/null +++ b/presto-native-execution/src/test/resources/tpcds/queries/q26.sql @@ -0,0 +1,25 @@ +SELECT + "i_item_id" +, "round"("avg"("cs_quantity"), 2) "agg1" +, "round"("avg"("cs_list_price"), 2) "agg2" +, "round"("avg"("cs_coupon_amt"), 2) "agg3" +, "round"("avg"("cs_sales_price"), 2) "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" ASC +LIMIT 100 diff --git a/presto-native-execution/src/test/resources/tpcds/queries/q27.sql b/presto-native-execution/src/test/resources/tpcds/queries/q27.sql new file mode 100644 index 0000000000000..1b674058dfc8c --- /dev/null +++ b/presto-native-execution/src/test/resources/tpcds/queries/q27.sql @@ -0,0 +1,32 @@ +SELECT + "i_item_id" +, "s_state" +, GROUPING ("s_state") "g_state" +, "round"("avg"("ss_quantity"), 2) "agg1" +, "round"("avg"("ss_list_price"), 2) "agg2" +, "round"("avg"("ss_coupon_amt"), 2) "agg3" +, "round"("avg"("ss_sales_price"), 2) "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" ASC, "s_state" ASC +LIMIT 100 diff --git a/presto-native-execution/src/test/resources/tpcds/queries/q28.sql b/presto-native-execution/src/test/resources/tpcds/queries/q28.sql new file mode 100644 index 0000000000000..933c9970ff8e3 --- /dev/null +++ b/presto-native-execution/src/test/resources/tpcds/queries/q28.sql @@ -0,0 +1,75 @@ +SELECT * +FROM + ( + SELECT + "round"("avg"("ss_list_price"), 2) "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 + "round"("avg"("ss_list_price"), 2) "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 + "round"("avg"("ss_list_price"), 2) "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 + "round"("avg"("ss_list_price"), 2) "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 + "round"("avg"("ss_list_price"), 2) "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 + "round"("avg"("ss_list_price"), 2) "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/presto-native-execution/src/test/resources/tpcds/queries/q29.sql b/presto-native-execution/src/test/resources/tpcds/queries/q29.sql new file mode 100644 index 0000000000000..7eedb2dfa1c2a --- /dev/null +++ b/presto-native-execution/src/test/resources/tpcds/queries/q29.sql @@ -0,0 +1,35 @@ +SELECT + "i_item_id" +, "i_item_desc" +, "s_store_id" +, "s_store_name" +, "round"("sum"("ss_quantity"), 2) "store_sales_quantity" +, "round"("sum"("sr_return_quantity"), 2) "store_returns_quantity" +, "round"("sum"("cs_quantity"), 2) "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" ASC, "i_item_desc" ASC, "s_store_id" ASC, "s_store_name" ASC +LIMIT 100 diff --git a/presto-native-execution/src/test/resources/tpcds/queries/q30.sql b/presto-native-execution/src/test/resources/tpcds/queries/q30.sql new file mode 100644 index 0000000000000..0a3ffb532098b --- /dev/null +++ b/presto-native-execution/src/test/resources/tpcds/queries/q30.sql @@ -0,0 +1,44 @@ +WITH + customer_total_return AS ( + SELECT + "wr_returning_customer_sk" "ctr_customer_sk" + , "ca_state" "ctr_state" + , "round"("sum"("wr_return_amt"), 2) "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_sk" +, "ctr_total_return" +FROM + customer_total_return ctr1 +, customer_address +, customer +WHERE ("ctr1"."ctr_total_return" > ( + SELECT "round"(("avg"("ctr_total_return") * DECIMAL '1.2'), 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" ASC, "c_salutation" ASC, "c_first_name" ASC, "c_last_name" ASC, "c_preferred_cust_flag" ASC, "c_birth_day" ASC, "c_birth_month" ASC, "c_birth_year" ASC, "c_birth_country" ASC, "c_login" ASC, "c_email_address" ASC, "c_last_review_date_sk" ASC, "ctr_total_return" ASC +LIMIT 100 diff --git a/presto-native-execution/src/test/resources/tpcds/queries/q31.sql b/presto-native-execution/src/test/resources/tpcds/queries/q31.sql new file mode 100644 index 0000000000000..58113c66ef546 --- /dev/null +++ b/presto-native-execution/src/test/resources/tpcds/queries/q31.sql @@ -0,0 +1,65 @@ +WITH + ss AS ( + SELECT + "ca_county" + , "d_qoy" + , "d_year" + , "round"("sum"("ss_ext_sales_price"), 2) "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" + , "round"("sum"("ws_ext_sales_price"), 2) "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 (CAST("ws2"."web_sales" AS DECIMAL(38,3)) / "ws1"."web_sales") ELSE null END) > (CASE WHEN ("ss1"."store_sales" > 0) THEN (CAST("ss2"."store_sales" AS DECIMAL(38,3)) / "ss1"."store_sales") ELSE null END)) +-- AND ((CASE WHEN ("ws2"."web_sales" > 0) THEN (CAST("ws3"."web_sales" AS DECIMAL(38,3)) / "ws2"."web_sales") ELSE null END) > (CASE WHEN ("ss2"."store_sales" > 0) THEN (CAST("ss3"."store_sales" AS DECIMAL(38,3)) / "ss2"."store_sales") ELSE null END)) + AND ((CASE WHEN ("ws1"."web_sales" > 0) THEN (CAST("ws2"."web_sales" AS DOUBLE) / "ws1"."web_sales") ELSE null END) > (CASE WHEN ("ss1"."store_sales" > 0) THEN (CAST("ss2"."store_sales" AS DOUBLE) / "ss1"."store_sales") ELSE null END)) + AND ((CASE WHEN ("ws2"."web_sales" > 0) THEN (CAST("ws3"."web_sales" AS DOUBLE) / "ws2"."web_sales") ELSE null END) > (CASE WHEN ("ss2"."store_sales" > 0) THEN (CAST("ss3"."store_sales" AS DOUBLE) / "ss2"."store_sales") ELSE null END)) +ORDER BY "ss1"."ca_county" ASC diff --git a/presto-native-execution/src/test/resources/tpcds/queries/q32.sql b/presto-native-execution/src/test/resources/tpcds/queries/q32.sql new file mode 100644 index 0000000000000..6a6df31c0401f --- /dev/null +++ b/presto-native-execution/src/test/resources/tpcds/queries/q32.sql @@ -0,0 +1,19 @@ +SELECT "round"("sum"("cs_ext_discount_amt"), 2) "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 CAST('2000-01-27' AS DATE) AND (CAST('2000-01-27' AS DATE) + INTERVAL '90' DAY)) + AND ("d_date_sk" = "cs_sold_date_sk") + AND ("cs_ext_discount_amt" > ( + SELECT (DECIMAL '1.3' * "avg"("cs_ext_discount_amt")) + FROM + catalog_sales + , date_dim + WHERE ("cs_item_sk" = "i_item_sk") + AND ("d_date" BETWEEN CAST('2000-01-27' AS DATE) AND (CAST('2000-01-27' AS DATE) + INTERVAL '90' DAY)) + AND ("d_date_sk" = "cs_sold_date_sk") + )) +LIMIT 100 diff --git a/presto-native-execution/src/test/resources/tpcds/queries/q33.sql b/presto-native-execution/src/test/resources/tpcds/queries/q33.sql new file mode 100644 index 0000000000000..c724b201e845a --- /dev/null +++ b/presto-native-execution/src/test/resources/tpcds/queries/q33.sql @@ -0,0 +1,88 @@ +WITH + ss AS ( + SELECT + "i_manufact_id" + , "round"("sum"("ss_ext_sales_price"), 2) "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" + , "round"("sum"("cs_ext_sales_price"), 2) "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" + , "round"("sum"("ws_ext_sales_price"), 2) "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" +, "round"("sum"("total_sales"), 2) "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" ASC +LIMIT 100 diff --git a/presto-native-execution/src/test/resources/tpcds/queries/q34.sql b/presto-native-execution/src/test/resources/tpcds/queries/q34.sql new file mode 100644 index 0000000000000..3f15eca0bc7a1 --- /dev/null +++ b/presto-native-execution/src/test/resources/tpcds/queries/q34.sql @@ -0,0 +1,36 @@ +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 (CAST("household_demographics"."hd_dep_count" AS DECIMAL(7,2)) / "household_demographics"."hd_vehicle_count") ELSE null END) > DECIMAL '1.2') + AND ((CASE WHEN ("household_demographics"."hd_vehicle_count" > 0) THEN (CAST("household_demographics"."hd_dep_count" AS double) / "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" ASC, "c_first_name" ASC, "c_salutation" ASC, "c_preferred_cust_flag" DESC, "ss_ticket_number" ASC diff --git a/presto-native-execution/src/test/resources/tpcds/queries/q35.sql b/presto-native-execution/src/test/resources/tpcds/queries/q35.sql new file mode 100644 index 0000000000000..529faf19ecd7e --- /dev/null +++ b/presto-native-execution/src/test/resources/tpcds/queries/q35.sql @@ -0,0 +1,58 @@ +SELECT + "ca_state" +, "cd_gender" +, "cd_marital_status" +, "cd_dep_count" +, "count"(*) "cnt1" +, "min"("cd_dep_count") +, "max"("cd_dep_count") +, "round"("avg"("cd_dep_count"), 2) +, "cd_dep_employed_count" +, "count"(*) "cnt2" +, "min"("cd_dep_employed_count") +, "max"("cd_dep_employed_count") +, "round"("avg"("cd_dep_employed_count"), 2) +, "cd_dep_college_count" +, "count"(*) "cnt3" +, "min"("cd_dep_college_count") +, "max"("cd_dep_college_count") +, "round"("avg"("cd_dep_college_count"), 2) +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" ASC, "cd_gender" ASC, "cd_marital_status" ASC, "cd_dep_count" ASC, "cd_dep_employed_count" ASC, "cd_dep_college_count" ASC +LIMIT 100 diff --git a/presto-native-execution/src/test/resources/tpcds/queries/q36.sql b/presto-native-execution/src/test/resources/tpcds/queries/q36.sql new file mode 100644 index 0000000000000..15fe375f0b35f --- /dev/null +++ b/presto-native-execution/src/test/resources/tpcds/queries/q36.sql @@ -0,0 +1,27 @@ +SELECT + "round"(("sum"("ss_net_profit") / "sum"("ss_ext_sales_price")), 2) "gross_margin" +, "i_category" +, "i_class" +, (GROUPING ("i_category") + GROUPING ("i_class")) "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) "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) ASC, "rank_within_parent" ASC, "i_category", "i_class" +LIMIT 100 diff --git a/presto-native-execution/src/test/resources/tpcds/queries/q37.sql b/presto-native-execution/src/test/resources/tpcds/queries/q37.sql new file mode 100644 index 0000000000000..5a6431e6d1ede --- /dev/null +++ b/presto-native-execution/src/test/resources/tpcds/queries/q37.sql @@ -0,0 +1,19 @@ +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 (CAST("d_date" AS DATE) BETWEEN CAST('2000-02-01' AS DATE) AND (CAST('2000-02-01' AS DATE) + INTERVAL '60' DAY)) + 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" ASC +LIMIT 100 diff --git a/presto-native-execution/src/test/resources/tpcds/queries/q38.sql b/presto-native-execution/src/test/resources/tpcds/queries/q38.sql new file mode 100644 index 0000000000000..bd70ca68f062c --- /dev/null +++ b/presto-native-execution/src/test/resources/tpcds/queries/q38.sql @@ -0,0 +1,38 @@ +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/presto-native-execution/src/test/resources/tpcds/queries/q39_1.sql b/presto-native-execution/src/test/resources/tpcds/queries/q39_1.sql new file mode 100644 index 0000000000000..57b4fa361b8dd --- /dev/null +++ b/presto-native-execution/src/test/resources/tpcds/queries/q39_1.sql @@ -0,0 +1,51 @@ +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" + , "round"("avg"("inv_quantity_on_hand"), 2) "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" +, "inv2"."i_item_sk" +, "inv2"."d_moy" +, "inv2"."mean" +, "inv2"."cov" +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" ASC, "inv1"."i_item_sk" ASC, "inv1"."d_moy" ASC, "inv1"."mean" ASC, "inv1"."cov" ASC, "inv2"."d_moy" ASC, "inv2"."mean" ASC, "inv2"."cov" ASC diff --git a/presto-native-execution/src/test/resources/tpcds/queries/q39_2.sql b/presto-native-execution/src/test/resources/tpcds/queries/q39_2.sql new file mode 100644 index 0000000000000..07c3f2b369c76 --- /dev/null +++ b/presto-native-execution/src/test/resources/tpcds/queries/q39_2.sql @@ -0,0 +1,52 @@ +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" + , "round"("avg"("inv_quantity_on_hand"), 2) "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" +, "inv2"."i_item_sk" +, "inv2"."d_moy" +, "inv2"."mean" +, "inv2"."cov" +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" > DECIMAL '1.5') +ORDER BY "inv1"."w_warehouse_sk" ASC, "inv1"."i_item_sk" ASC, "inv1"."d_moy" ASC, "inv1"."mean" ASC, "inv1"."cov" ASC, "inv2"."d_moy" ASC, "inv2"."mean" ASC, "inv2"."cov" ASC diff --git a/presto-native-execution/src/test/resources/tpcds/queries/q40.sql b/presto-native-execution/src/test/resources/tpcds/queries/q40.sql new file mode 100644 index 0000000000000..8371c944ca694 --- /dev/null +++ b/presto-native-execution/src/test/resources/tpcds/queries/q40.sql @@ -0,0 +1,20 @@ +SELECT + "w_state" +, "i_item_id" +, "round"("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)), 2) "sales_before" +, "round"("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)), 2) "sales_after" +FROM + (catalog_sales +LEFT 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 DECIMAL '0.99' AND DECIMAL '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 (CAST("d_date" AS DATE) BETWEEN (CAST('2000-03-11' AS DATE) - INTERVAL '30' DAY) AND (CAST('2000-03-11' AS DATE) + INTERVAL '30' DAY)) +GROUP BY "w_state", "i_item_id" +ORDER BY "w_state" ASC, "i_item_id" ASC +LIMIT 100 diff --git a/presto-native-execution/src/test/resources/tpcds/queries/q41.sql b/presto-native-execution/src/test/resources/tpcds/queries/q41.sql new file mode 100644 index 0000000000000..2ceedb3fa0837 --- /dev/null +++ b/presto-native-execution/src/test/resources/tpcds/queries/q41.sql @@ -0,0 +1,69 @@ +SELECT DISTINCT "i_product_name" +FROM + item i1 +WHERE ("i_manufact_id" BETWEEN 738 AND (738 + 40)) + AND (( + SELECT "count"(*) "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" ASC +LIMIT 100 diff --git a/presto-native-execution/src/test/resources/tpcds/queries/q42.sql b/presto-native-execution/src/test/resources/tpcds/queries/q42.sql new file mode 100644 index 0000000000000..12fc42b4916e1 --- /dev/null +++ b/presto-native-execution/src/test/resources/tpcds/queries/q42.sql @@ -0,0 +1,17 @@ +SELECT + "dt"."d_year" +, "item"."i_category_id" +, "item"."i_category" +, "round"("sum"("ss_ext_sales_price"), 2) +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" ASC, "item"."i_category_id" ASC, "item"."i_category" ASC +LIMIT 100 diff --git a/presto-native-execution/src/test/resources/tpcds/queries/q43.sql b/presto-native-execution/src/test/resources/tpcds/queries/q43.sql new file mode 100644 index 0000000000000..d9864245c49a6 --- /dev/null +++ b/presto-native-execution/src/test/resources/tpcds/queries/q43.sql @@ -0,0 +1,21 @@ +SELECT + "s_store_name" +, "s_store_id" +, "round"("sum"((CASE WHEN ("d_day_name" = 'Sunday') THEN "ss_sales_price" ELSE null END)), 2) "sun_sales" +, "round"("sum"((CASE WHEN ("d_day_name" = 'Monday') THEN "ss_sales_price" ELSE null END)), 2) "mon_sales" +, "round"("sum"((CASE WHEN ("d_day_name" = 'Tuesday') THEN "ss_sales_price" ELSE null END)), 2) "tue_sales" +, "round"("sum"((CASE WHEN ("d_day_name" = 'Wednesday') THEN "ss_sales_price" ELSE null END)), 2) "wed_sales" +, "round"("sum"((CASE WHEN ("d_day_name" = 'Thursday') THEN "ss_sales_price" ELSE null END)), 2) "thu_sales" +, "round"("sum"((CASE WHEN ("d_day_name" = 'Friday') THEN "ss_sales_price" ELSE null END)), 2) "fri_sales" +, "round"("sum"((CASE WHEN ("d_day_name" = 'Saturday') THEN "ss_sales_price" ELSE null END)), 2) "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" ASC, "s_store_id" ASC, "sun_sales" ASC, "mon_sales" ASC, "tue_sales" ASC, "wed_sales" ASC, "thu_sales" ASC, "fri_sales" ASC, "sat_sales" ASC +LIMIT 100 diff --git a/presto-native-execution/src/test/resources/tpcds/queries/q44.sql b/presto-native-execution/src/test/resources/tpcds/queries/q44.sql new file mode 100644 index 0000000000000..8f671863d60c2 --- /dev/null +++ b/presto-native-execution/src/test/resources/tpcds/queries/q44.sql @@ -0,0 +1,68 @@ +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" + , "round"("avg"("ss_net_profit"), 2) "rank_col" + FROM + store_sales ss1 + WHERE ("ss_store_sk" = 4) + GROUP BY "ss_item_sk" + HAVING ("round"("avg"("ss_net_profit"), 2) > (DECIMAL '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" + , "round"("avg"("ss_net_profit"), 2) "rank_col" + FROM + store_sales ss1 + WHERE ("ss_store_sk" = 4) + GROUP BY "ss_item_sk" + HAVING ("round"("avg"("ss_net_profit"), 2) > (DECIMAL '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" ASC +LIMIT 100 diff --git a/presto-native-execution/src/test/resources/tpcds/queries/q45.sql b/presto-native-execution/src/test/resources/tpcds/queries/q45.sql new file mode 100644 index 0000000000000..f3f72dfe5074e --- /dev/null +++ b/presto-native-execution/src/test/resources/tpcds/queries/q45.sql @@ -0,0 +1,26 @@ +SELECT + "ca_zip" +, "ca_city" +, "round"("sum"("ws_sales_price"), 2) +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" ASC, "ca_city" ASC +LIMIT 100 diff --git a/presto-native-execution/src/test/resources/tpcds/queries/q46.sql b/presto-native-execution/src/test/resources/tpcds/queries/q46.sql new file mode 100644 index 0000000000000..69b810d5564d9 --- /dev/null +++ b/presto-native-execution/src/test/resources/tpcds/queries/q46.sql @@ -0,0 +1,40 @@ +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" + , "round"("sum"("ss_coupon_amt"), 2) "amt" + , "round"("sum"("ss_net_profit"), 2) "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" ASC, "c_first_name" ASC, "ca_city" ASC, "bought_city" ASC, "ss_ticket_number" ASC +LIMIT 100 diff --git a/presto-native-execution/src/test/resources/tpcds/queries/q47.sql b/presto-native-execution/src/test/resources/tpcds/queries/q47.sql new file mode 100644 index 0000000000000..4328250ceccaa --- /dev/null +++ b/presto-native-execution/src/test/resources/tpcds/queries/q47.sql @@ -0,0 +1,62 @@ +WITH + v1 AS ( + SELECT + "i_category" + , "i_brand" + , "s_store_name" + , "s_company_name" + , "d_year" + , "d_moy" + , "round"("sum"("ss_sales_price"), 2) "sum_sales" + , "round"("avg"("sum"("ss_sales_price")), 2) 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" ASC, "d_moy" ASC) "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) > DECIMAL '0.1') +ORDER BY ("sum_sales" - "avg_monthly_sales") ASC, 3 ASC +LIMIT 100 diff --git a/presto-native-execution/src/test/resources/tpcds/queries/q48.sql b/presto-native-execution/src/test/resources/tpcds/queries/q48.sql new file mode 100644 index 0000000000000..f8443bef36779 --- /dev/null +++ b/presto-native-execution/src/test/resources/tpcds/queries/q48.sql @@ -0,0 +1,34 @@ +SELECT "round"("sum"("ss_quantity"), 2) +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 DECIMAL '100.00' AND DECIMAL '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 DECIMAL '50.00' AND DECIMAL '100.00')) + OR (("cd_demo_sk" = "ss_cdemo_sk") + AND ("cd_marital_status" = 'S') + AND ("cd_education_status" = 'College') + AND ("ss_sales_price" BETWEEN DECIMAL '150.00' AND DECIMAL '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/presto-native-execution/src/test/resources/tpcds/queries/q49.sql b/presto-native-execution/src/test/resources/tpcds/queries/q49.sql new file mode 100644 index 0000000000000..902899b037a7d --- /dev/null +++ b/presto-native-execution/src/test/resources/tpcds/queries/q49.sql @@ -0,0 +1,119 @@ +SELECT + 'web' "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" ASC) "return_rank" + , "rank"() OVER (ORDER BY "currency_ratio" ASC) "currency_rank" + FROM + ( + SELECT + "ws"."ws_item_sk" "item" + --, (CAST("sum"(COALESCE("wr"."wr_return_quantity", 0)) AS DECIMAL(15,4)) / CAST("sum"(COALESCE("ws"."ws_quantity", 0)) AS DECIMAL(15,4))) "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))) "currency_ratio" + , "round"((CAST("sum"(COALESCE("wr"."wr_return_quantity", 0)) AS double) / CAST("sum"(COALESCE("ws"."ws_quantity", 0)) AS double)), 2) "return_ratio" + , "round"((CAST("sum"(COALESCE("wr"."wr_return_amt", 0)) AS double) / CAST("sum"(COALESCE("ws"."ws_net_paid", 0)) AS double)), 2) "currency_ratio" + FROM + (web_sales ws + LEFT 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' "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" ASC) "return_rank" + , "rank"() OVER (ORDER BY "currency_ratio" ASC) "currency_rank" + FROM + ( + SELECT + "cs"."cs_item_sk" "item" + --, (CAST("sum"(COALESCE("cr"."cr_return_quantity", 0)) AS DECIMAL(15,4)) / CAST("sum"(COALESCE("cs"."cs_quantity", 0)) AS DECIMAL(15,4))) "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))) "currency_ratio" + , "round"((CAST("sum"(COALESCE("cr"."cr_return_quantity", 0)) AS double) / CAST("sum"(COALESCE("cs"."cs_quantity", 0)) AS double)), 2) "return_ratio" + , "round"((CAST("sum"(COALESCE("cr"."cr_return_amount", 0)) AS double) / CAST("sum"(COALESCE("cs"."cs_net_paid", 0)) AS double)), 2) "currency_ratio" + FROM + (catalog_sales cs + LEFT 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' "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" ASC) "return_rank" + , "rank"() OVER (ORDER BY "currency_ratio" ASC) "currency_rank" + FROM + ( + SELECT + "sts"."ss_item_sk" "item" + --, (CAST("sum"(COALESCE("sr"."sr_return_quantity", 0)) AS DECIMAL(15,4)) / CAST("sum"(COALESCE("sts"."ss_quantity", 0)) AS DECIMAL(15,4))) "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))) "currency_ratio" + , "round"((CAST("sum"(COALESCE("sr"."sr_return_quantity", 0)) AS double) / CAST("sum"(COALESCE("sts"."ss_quantity", 0)) AS double)), 2) "return_ratio" + , "round"((CAST("sum"(COALESCE("sr"."sr_return_amt", 0)) AS double) / CAST("sum"(COALESCE("sts"."ss_net_paid", 0)) AS double)), 2) "currency_ratio" + FROM + (store_sales sts + LEFT 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 ASC, 4 ASC, 5 ASC, 2 ASC +LIMIT 100 diff --git a/presto-native-execution/src/test/resources/tpcds/queries/q50.sql b/presto-native-execution/src/test/resources/tpcds/queries/q50.sql new file mode 100644 index 0000000000000..442390a150df4 --- /dev/null +++ b/presto-native-execution/src/test/resources/tpcds/queries/q50.sql @@ -0,0 +1,36 @@ +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" +, "round"("sum"((CASE WHEN (("sr_returned_date_sk" - "ss_sold_date_sk") <= 30) THEN 1 ELSE 0 END)), 2) "30 days" +, "round"("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)), 2) "31-60 days" +, "round"("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)), 2) "61-90 days" +, "round"("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)), 2) "91-120 days" +, "round"("sum"((CASE WHEN (("sr_returned_date_sk" - "ss_sold_date_sk") > 120) THEN 1 ELSE 0 END)), 2) ">120 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" ASC, "s_company_id" ASC, "s_street_number" ASC, "s_street_name" ASC, "s_street_type" ASC, "s_suite_number" ASC, "s_city" ASC, "s_county" ASC, "s_state" ASC, "s_zip" ASC +LIMIT 100 diff --git a/presto-native-execution/src/test/resources/tpcds/queries/q51.sql b/presto-native-execution/src/test/resources/tpcds/queries/q51.sql new file mode 100644 index 0000000000000..b85674b1f8f99 --- /dev/null +++ b/presto-native-execution/src/test/resources/tpcds/queries/q51.sql @@ -0,0 +1,53 @@ +WITH + web_v1 AS ( + SELECT + "ws_item_sk" "item_sk" + , "d_date" + , "round"("sum"("sum"("ws_sales_price")), 2) OVER (PARTITION BY "ws_item_sk" ORDER BY "d_date" ASC 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" + , "round"("sum"("sum"("ss_sales_price")), 2) OVER (PARTITION BY "ss_item_sk" ORDER BY "d_date" ASC 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" ASC ROWS BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW) "web_cumulative" + , "max"("store_sales") OVER (PARTITION BY "item_sk" ORDER BY "d_date" ASC 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 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" ASC, "d_date" ASC +LIMIT 100 diff --git a/presto-native-execution/src/test/resources/tpcds/queries/q52.sql b/presto-native-execution/src/test/resources/tpcds/queries/q52.sql new file mode 100644 index 0000000000000..b760ebafbd07d --- /dev/null +++ b/presto-native-execution/src/test/resources/tpcds/queries/q52.sql @@ -0,0 +1,17 @@ +SELECT + "dt"."d_year" +, "item"."i_brand_id" "brand_id" +, "item"."i_brand" "brand" +, "round"("sum"("ss_ext_sales_price"), 2) "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" ASC, "ext_price" DESC, "brand_id" ASC +LIMIT 100 diff --git a/presto-native-execution/src/test/resources/tpcds/queries/q53.sql b/presto-native-execution/src/test/resources/tpcds/queries/q53.sql new file mode 100644 index 0000000000000..d3c2ef7a8a091 --- /dev/null +++ b/presto-native-execution/src/test/resources/tpcds/queries/q53.sql @@ -0,0 +1,27 @@ +SELECT * +FROM + ( + SELECT + "i_manufact_id" + , "round"("sum"("ss_sales_price"), 2) "sum_sales" + , "round"("avg"("sum"("ss_sales_price")), 2) 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"((CAST("sum_sales" AS DECIMAL(38,4)) - "avg_quarterly_sales")) / "avg_quarterly_sales") ELSE null END) > DECIMAL '0.1') +ORDER BY "avg_quarterly_sales" ASC, "sum_sales" ASC, "i_manufact_id" ASC +LIMIT 100 diff --git a/presto-native-execution/src/test/resources/tpcds/queries/q54.sql b/presto-native-execution/src/test/resources/tpcds/queries/q54.sql new file mode 100644 index 0000000000000..3913fe000d3be --- /dev/null +++ b/presto-native-execution/src/test/resources/tpcds/queries/q54.sql @@ -0,0 +1,75 @@ +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" + , "round"("sum"("ss_ext_sales_price"), 2) "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 INTEGER) "segment" + FROM + my_revenue +) +SELECT + "segment" +, "count"(*) "num_customers" +, ("segment" * 50) "segment_base" +FROM + segments +GROUP BY "segment" +ORDER BY "segment" ASC, "num_customers" ASC +LIMIT 100 diff --git a/presto-native-execution/src/test/resources/tpcds/queries/q55.sql b/presto-native-execution/src/test/resources/tpcds/queries/q55.sql new file mode 100644 index 0000000000000..521c032295536 --- /dev/null +++ b/presto-native-execution/src/test/resources/tpcds/queries/q55.sql @@ -0,0 +1,16 @@ +SELECT + "i_brand_id" "brand_id" +, "i_brand" "brand" +, "round"("sum"("ss_ext_sales_price"), 2) "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" ASC +LIMIT 100 diff --git a/presto-native-execution/src/test/resources/tpcds/queries/q56.sql b/presto-native-execution/src/test/resources/tpcds/queries/q56.sql new file mode 100644 index 0000000000000..e8ff7f60e9dba --- /dev/null +++ b/presto-native-execution/src/test/resources/tpcds/queries/q56.sql @@ -0,0 +1,88 @@ +WITH + ss AS ( + SELECT + "i_item_id" + , "round"("sum"("ss_ext_sales_price"), 2) "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" + , "round"("sum"("cs_ext_sales_price"), 2) "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" + , "round"("sum"("ws_ext_sales_price"), 2) "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" +, "round"("sum"("total_sales"), 2) "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" ASC, "i_item_id" ASC +LIMIT 100 diff --git a/presto-native-execution/src/test/resources/tpcds/queries/q57.sql b/presto-native-execution/src/test/resources/tpcds/queries/q57.sql new file mode 100644 index 0000000000000..1db9d7fedaac3 --- /dev/null +++ b/presto-native-execution/src/test/resources/tpcds/queries/q57.sql @@ -0,0 +1,58 @@ +WITH + v1 AS ( + SELECT + "i_category" + , "i_brand" + , "cc_name" + , "d_year" + , "d_moy" + , "round"("sum"("cs_sales_price"), 2) "sum_sales" + , "round"("avg"("sum"("cs_sales_price")), 2) 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" ASC, "d_moy" ASC) "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) > DECIMAL '0.1') +ORDER BY ("sum_sales" - "avg_monthly_sales") ASC, 3 ASC +LIMIT 100 diff --git a/presto-native-execution/src/test/resources/tpcds/queries/q58.sql b/presto-native-execution/src/test/resources/tpcds/queries/q58.sql new file mode 100644 index 0000000000000..7eb6c7d4074a9 --- /dev/null +++ b/presto-native-execution/src/test/resources/tpcds/queries/q58.sql @@ -0,0 +1,98 @@ +WITH + ss_items AS ( + SELECT + "i_item_id" "item_id" + , "round"("sum"("ss_ext_sales_price"), 2) "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" = CAST('2000-01-03' AS DATE)) + )) + )) + AND ("ss_sold_date_sk" = "d_date_sk") + GROUP BY "i_item_id" +) +, cs_items AS ( + SELECT + "i_item_id" "item_id" + , "round"("sum"("cs_ext_sales_price"), 2) "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" = CAST('2000-01-03' AS DATE)) + )) + )) + AND ("cs_sold_date_sk" = "d_date_sk") + GROUP BY "i_item_id" +) +, ws_items AS ( + SELECT + "i_item_id" "item_id" + , "round"("sum"("ws_ext_sales_price"), 2) "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" = CAST('2000-01-03' AS DATE)) + )) + )) + AND ("ws_sold_date_sk" = "d_date_sk") + GROUP BY "i_item_id" +) +SELECT + "ss_items"."item_id" +, "ss_item_rev" +--, CAST(((("ss_item_rev" / ((CAST("ss_item_rev" AS DECIMAL(16,7)) + "cs_item_rev") + "ws_item_rev")) / 3) * 100) AS DECIMAL(7,2)) "ss_dev" +--, "cs_item_rev" +--, CAST(((("cs_item_rev" / ((CAST("ss_item_rev" AS DECIMAL(16,7)) + "cs_item_rev") + "ws_item_rev")) / 3) * 100) AS DECIMAL(7,2)) "cs_dev" +--, "ws_item_rev" +--, CAST(((("ws_item_rev" / ((CAST("ss_item_rev" AS DECIMAL(16,7)) + "cs_item_rev") + "ws_item_rev")) / 3) * 100) AS DECIMAL(7,2)) "ws_dev" +, CAST(((("ss_item_rev" / ((CAST("ss_item_rev" AS double) + "cs_item_rev") + "ws_item_rev")) / 3) * 100) AS double) "ss_dev" +, "cs_item_rev" +, CAST(((("cs_item_rev" / ((CAST("ss_item_rev" AS double) + "cs_item_rev") + "ws_item_rev")) / 3) * 100) AS double) "cs_dev" +, "ws_item_rev" +, CAST(((("ws_item_rev" / ((CAST("ss_item_rev" AS double) + "cs_item_rev") + "ws_item_rev")) / 3) * 100) AS double) "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 (DECIMAL '0.9' * "cs_item_rev") AND (DECIMAL '1.1' * "cs_item_rev")) + AND ("ss_item_rev" BETWEEN (DECIMAL '0.9' * "ws_item_rev") AND (DECIMAL '1.1' * "ws_item_rev")) + AND ("cs_item_rev" BETWEEN (DECIMAL '0.9' * "ss_item_rev") AND (DECIMAL '1.1' * "ss_item_rev")) + AND ("cs_item_rev" BETWEEN (DECIMAL '0.9' * "ws_item_rev") AND (DECIMAL '1.1' * "ws_item_rev")) + AND ("ws_item_rev" BETWEEN (DECIMAL '0.9' * "ss_item_rev") AND (DECIMAL '1.1' * "ss_item_rev")) + AND ("ws_item_rev" BETWEEN (DECIMAL '0.9' * "cs_item_rev") AND (DECIMAL '1.1' * "cs_item_rev")) +ORDER BY "ss_items"."item_id" ASC, "ss_item_rev" ASC +LIMIT 100 diff --git a/presto-native-execution/src/test/resources/tpcds/queries/q59.sql b/presto-native-execution/src/test/resources/tpcds/queries/q59.sql new file mode 100644 index 0000000000000..af56a1b2750c6 --- /dev/null +++ b/presto-native-execution/src/test/resources/tpcds/queries/q59.sql @@ -0,0 +1,74 @@ +WITH + wss AS ( + SELECT + "d_week_seq" + , "ss_store_sk" + , "round"("sum"((CASE WHEN ("d_day_name" = 'Sunday') THEN "ss_sales_price" ELSE null END)), 2) "sun_sales" + , "round"("sum"((CASE WHEN ("d_day_name" = 'Monday') THEN "ss_sales_price" ELSE null END)), 2) "mon_sales" + , "round"("sum"((CASE WHEN ("d_day_name" = 'Tuesday') THEN "ss_sales_price" ELSE null END)), 2) "tue_sales" + , "round"("sum"((CASE WHEN ("d_day_name" = 'Wednesday') THEN "ss_sales_price" ELSE null END)), 2) "wed_sales" + , "round"("sum"((CASE WHEN ("d_day_name" = 'Thursday') THEN "ss_sales_price" ELSE null END)), 2) "thu_sales" + , "round"("sum"((CASE WHEN ("d_day_name" = 'Friday') THEN "ss_sales_price" ELSE null END)), 2) "fri_sales" + , "round"("sum"((CASE WHEN ("d_day_name" = 'Saturday') THEN "ss_sales_price" ELSE null END)), 2) "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" ASC, "s_store_id1" ASC, "d_week_seq1" ASC +LIMIT 100 diff --git a/presto-native-execution/src/test/resources/tpcds/queries/q60.sql b/presto-native-execution/src/test/resources/tpcds/queries/q60.sql new file mode 100644 index 0000000000000..546997b6d7e86 --- /dev/null +++ b/presto-native-execution/src/test/resources/tpcds/queries/q60.sql @@ -0,0 +1,88 @@ +WITH + ss AS ( + SELECT + "i_item_id" + , "round"("sum"("ss_ext_sales_price"), 2) "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" + , "round"("sum"("cs_ext_sales_price"), 2) "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" + , "round"("sum"("ws_ext_sales_price"), 2) "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" +, "round"("sum"("total_sales"), 2) "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" ASC, "total_sales" ASC +LIMIT 100 diff --git a/presto-native-execution/src/test/resources/tpcds/queries/q61.sql b/presto-native-execution/src/test/resources/tpcds/queries/q61.sql new file mode 100644 index 0000000000000..3356a672431fc --- /dev/null +++ b/presto-native-execution/src/test/resources/tpcds/queries/q61.sql @@ -0,0 +1,53 @@ +SELECT + "promotions" +, "total" +--, ((CAST("promotions" AS DECIMAL(15,4)) / CAST("total" AS DECIMAL(15,4))) * 100) +, "round"(((CAST("promotions" AS double) / CAST("total" AS double)) * 100), 2) +FROM + ( + SELECT "round"("sum"("ss_ext_sales_price"), 2) "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 "round"("sum"("ss_ext_sales_price"), 2) "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" ASC, "total" ASC +LIMIT 100 diff --git a/presto-native-execution/src/test/resources/tpcds/queries/q62.sql b/presto-native-execution/src/test/resources/tpcds/queries/q62.sql new file mode 100644 index 0000000000000..4c457fa7fbf65 --- /dev/null +++ b/presto-native-execution/src/test/resources/tpcds/queries/q62.sql @@ -0,0 +1,26 @@ +SELECT + "substr"("w_warehouse_name", 1, 20) +, "sm_type" +, "web_name" +, "round"("sum"((CASE WHEN (("ws_ship_date_sk" - "ws_sold_date_sk") <= 30) THEN 1 ELSE 0 END)), 2) "30 days" +, "round"("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)), 2) "31-60 days" +, "round"("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)), 2) "61-90 days" +, "round"("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)), 2) "91-120 days" +, "round"("sum"((CASE WHEN (("ws_ship_date_sk" - "ws_sold_date_sk") > 120) THEN 1 ELSE 0 END)), 2) ">120 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) ASC, "sm_type" ASC, "web_name" ASC +LIMIT 100 diff --git a/presto-native-execution/src/test/resources/tpcds/queries/q63.sql b/presto-native-execution/src/test/resources/tpcds/queries/q63.sql new file mode 100644 index 0000000000000..ed006321d3217 --- /dev/null +++ b/presto-native-execution/src/test/resources/tpcds/queries/q63.sql @@ -0,0 +1,27 @@ +SELECT * +FROM + ( + SELECT + "i_manager_id" + , "round"("sum"("ss_sales_price"), 2) "sum_sales" + , "round"("avg"("sum"("ss_sales_price")), 2) 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' , 'refernece' , '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) > DECIMAL '0.1') +ORDER BY "i_manager_id" ASC, "avg_monthly_sales" ASC, "sum_sales" ASC +LIMIT 100 diff --git a/presto-native-execution/src/test/resources/tpcds/queries/q64.sql b/presto-native-execution/src/test/resources/tpcds/queries/q64.sql new file mode 100644 index 0000000000000..fcf6afb8e7410 --- /dev/null +++ b/presto-native-execution/src/test/resources/tpcds/queries/q64.sql @@ -0,0 +1,110 @@ +WITH + cs_ui AS ( + SELECT + "cs_item_sk" + , "round"("sum"("cs_ext_list_price"), 2) "sale" + , "round"("sum"((("cr_refunded_cash" + "cr_reversed_charge") + "cr_store_credit")), 2) "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 ("round"("sum"("cs_ext_list_price"), 2) > "round"((2 * "sum"((("cr_refunded_cash" + "cr_reversed_charge") + "cr_store_credit"))), 2)) +) +, 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" "syear" + , "d2"."d_year" "fsyear" + , "d3"."d_year" "s2year" + , "count"(*) "cnt" + , "round"("sum"("ss_wholesale_cost"), 2) "s1" + , "round"("sum"("ss_list_price"), 2) "s2" + , "round"("sum"("ss_coupon_amt"), 2) "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" "s11" +, "cs1"."s2" "s21" +, "cs1"."s3" "s31" +, "cs2"."s1" "s12" +, "cs2"."s2" "s22" +, "cs2"."s3" "s32" +, "cs2"."syear" +, "cs2"."cnt" +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" ASC, "cs1"."store_name" ASC, "cs2"."cnt" ASC, 14, 15, 16, 17, 18 diff --git a/presto-native-execution/src/test/resources/tpcds/queries/q65.sql b/presto-native-execution/src/test/resources/tpcds/queries/q65.sql new file mode 100644 index 0000000000000..d1b6770992feb --- /dev/null +++ b/presto-native-execution/src/test/resources/tpcds/queries/q65.sql @@ -0,0 +1,47 @@ +SELECT + "s_store_name" +, "i_item_desc" +, "sc"."revenue" +, "i_current_price" +, "i_wholesale_cost" +, "i_brand" +FROM + store +, item +, ( + SELECT + "ss_store_sk" + , "round"("avg"("revenue"), 2) "ave" + FROM + ( + SELECT + "ss_store_sk" + , "ss_item_sk" + , "round"("sum"("ss_sales_price"), 2) "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" + , "round"("sum"("ss_sales_price"), 2) "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" <= (DECIMAL '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" ASC, "i_item_desc" ASC +LIMIT 100 diff --git a/presto-native-execution/src/test/resources/tpcds/queries/q66.sql b/presto-native-execution/src/test/resources/tpcds/queries/q66.sql new file mode 100644 index 0000000000000..599362387ac6a --- /dev/null +++ b/presto-native-execution/src/test/resources/tpcds/queries/q66.sql @@ -0,0 +1,146 @@ +SELECT + "w_warehouse_name" +, "w_warehouse_sq_ft" +, "w_city" +, "w_county" +, "w_state" +, "w_country" +, "ship_carriers" +, "year" +, "round"("sum"("jan_sales"), 2) "jan_sales" +, "round"("sum"("feb_sales"), 2) "feb_sales" +, "round"("sum"("mar_sales"), 2) "mar_sales" +, "round"("sum"("apr_sales"), 2) "apr_sales" +, "round"("sum"("may_sales"), 2) "may_sales" +, "round"("sum"("jun_sales"), 2) "jun_sales" +, "round"("sum"("jul_sales"), 2) "jul_sales" +, "round"("sum"("aug_sales"), 2) "aug_sales" +, "round"("sum"("sep_sales"), 2) "sep_sales" +, "round"("sum"("oct_sales"), 2) "oct_sales" +, "round"("sum"("nov_sales"), 2) "nov_sales" +, "round"("sum"("dec_sales"), 2) "dec_sales" +, "round"("sum"(("jan_sales" / "w_warehouse_sq_ft")), 2) "jan_sales_per_sq_foot" +, "round"("sum"(("feb_sales" / "w_warehouse_sq_ft")), 2) "feb_sales_per_sq_foot" +, "round"("sum"(("mar_sales" / "w_warehouse_sq_ft")), 2) "mar_sales_per_sq_foot" +, "round"("sum"(("apr_sales" / "w_warehouse_sq_ft")), 2) "apr_sales_per_sq_foot" +, "round"("sum"(("may_sales" / "w_warehouse_sq_ft")), 2) "may_sales_per_sq_foot" +, "round"("sum"(("jun_sales" / "w_warehouse_sq_ft")), 2) "jun_sales_per_sq_foot" +, "round"("sum"(("jul_sales" / "w_warehouse_sq_ft")), 2) "jul_sales_per_sq_foot" +, "round"("sum"(("aug_sales" / "w_warehouse_sq_ft")), 2) "aug_sales_per_sq_foot" +, "round"("sum"(("sep_sales" / "w_warehouse_sq_ft")), 2) "sep_sales_per_sq_foot" +, "round"("sum"(("oct_sales" / "w_warehouse_sq_ft")), 2) "oct_sales_per_sq_foot" +, "round"("sum"(("nov_sales" / "w_warehouse_sq_ft")), 2) "nov_sales_per_sq_foot" +, "round"("sum"(("dec_sales" / "w_warehouse_sq_ft")), 2) "dec_sales_per_sq_foot" +, "round"("sum"("jan_net"), 2) "jan_net" +, "round"("sum"("feb_net"), 2) "feb_net" +, "round"("sum"("mar_net"), 2) "mar_net" +, "round"("sum"("apr_net"), 2) "apr_net" +, "round"("sum"("may_net"), 2) "may_net" +, "round"("sum"("jun_net"), 2) "jun_net" +, "round"("sum"("jul_net"), 2) "jul_net" +, "round"("sum"("aug_net"), 2) "aug_net" +, "round"("sum"("sep_net"), 2) "sep_net" +, "round"("sum"("oct_net"), 2) "oct_net" +, "round"("sum"("nov_net"), 2) "nov_net" +, "round"("sum"("dec_net"), 2) "dec_net" +FROM +( + SELECT + "w_warehouse_name" + , "w_warehouse_sq_ft" + , "w_city" + , "w_county" + , "w_state" + , "w_country" + , "concat"("concat"('DHL', ','), 'BARIAN') "ship_carriers" + , "d_year" "YEAR" + , "round"("sum"((CASE WHEN ("d_moy" = 1) THEN ("ws_ext_sales_price" * "ws_quantity") ELSE 0 END)), 2) "jan_sales" + , "round"("sum"((CASE WHEN ("d_moy" = 2) THEN ("ws_ext_sales_price" * "ws_quantity") ELSE 0 END)), 2) "feb_sales" + , "round"("sum"((CASE WHEN ("d_moy" = 3) THEN ("ws_ext_sales_price" * "ws_quantity") ELSE 0 END)), 2) "mar_sales" + , "round"("sum"((CASE WHEN ("d_moy" = 4) THEN ("ws_ext_sales_price" * "ws_quantity") ELSE 0 END)), 2) "apr_sales" + , "round"("sum"((CASE WHEN ("d_moy" = 5) THEN ("ws_ext_sales_price" * "ws_quantity") ELSE 0 END)), 2) "may_sales" + , "round"("sum"((CASE WHEN ("d_moy" = 6) THEN ("ws_ext_sales_price" * "ws_quantity") ELSE 0 END)), 2) "jun_sales" + , "round"("sum"((CASE WHEN ("d_moy" = 7) THEN ("ws_ext_sales_price" * "ws_quantity") ELSE 0 END)), 2) "jul_sales" + , "round"("sum"((CASE WHEN ("d_moy" = 8) THEN ("ws_ext_sales_price" * "ws_quantity") ELSE 0 END)), 2) "aug_sales" + , "round"("sum"((CASE WHEN ("d_moy" = 9) THEN ("ws_ext_sales_price" * "ws_quantity") ELSE 0 END)), 2) "sep_sales" + , "round"("sum"((CASE WHEN ("d_moy" = 10) THEN ("ws_ext_sales_price" * "ws_quantity") ELSE 0 END)), 2) "oct_sales" + , "round"("sum"((CASE WHEN ("d_moy" = 11) THEN ("ws_ext_sales_price" * "ws_quantity") ELSE 0 END)), 2) "nov_sales" + , "round"("sum"((CASE WHEN ("d_moy" = 12) THEN ("ws_ext_sales_price" * "ws_quantity") ELSE 0 END)), 2) "dec_sales" + , "round"("sum"((CASE WHEN ("d_moy" = 1) THEN ("ws_net_paid" * "ws_quantity") ELSE 0 END)), 2) "jan_net" + , "round"("sum"((CASE WHEN ("d_moy" = 2) THEN ("ws_net_paid" * "ws_quantity") ELSE 0 END)), 2) "feb_net" + , "round"("sum"((CASE WHEN ("d_moy" = 3) THEN ("ws_net_paid" * "ws_quantity") ELSE 0 END)), 2) "mar_net" + , "round"("sum"((CASE WHEN ("d_moy" = 4) THEN ("ws_net_paid" * "ws_quantity") ELSE 0 END)), 2) "apr_net" + , "round"("sum"((CASE WHEN ("d_moy" = 5) THEN ("ws_net_paid" * "ws_quantity") ELSE 0 END)), 2) "may_net" + , "round"("sum"((CASE WHEN ("d_moy" = 6) THEN ("ws_net_paid" * "ws_quantity") ELSE 0 END)), 2) "jun_net" + , "round"("sum"((CASE WHEN ("d_moy" = 7) THEN ("ws_net_paid" * "ws_quantity") ELSE 0 END)), 2)"jul_net" + , "round"("sum"((CASE WHEN ("d_moy" = 8) THEN ("ws_net_paid" * "ws_quantity") ELSE 0 END)), 2) "aug_net" + , "round"("sum"((CASE WHEN ("d_moy" = 9) THEN ("ws_net_paid" * "ws_quantity") ELSE 0 END)), 2) "sep_net" + , "round"("sum"((CASE WHEN ("d_moy" = 10) THEN ("ws_net_paid" * "ws_quantity") ELSE 0 END)), 2) "oct_net" + , "round"("sum"((CASE WHEN ("d_moy" = 11) THEN ("ws_net_paid" * "ws_quantity") ELSE 0 END)), 2) "nov_net" + , "round"("sum"((CASE WHEN ("d_moy" = 12) THEN ("ws_net_paid" * "ws_quantity") ELSE 0 END)), 2) "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"("concat"('DHL', ','), 'BARIAN') "ship_carriers" + , "d_year" "YEAR" + , "round"("sum"((CASE WHEN ("d_moy" = 1) THEN ("cs_sales_price" * "cs_quantity") ELSE 0 END)), 2) "jan_sales" + , "round"("sum"((CASE WHEN ("d_moy" = 2) THEN ("cs_sales_price" * "cs_quantity") ELSE 0 END)), 2) "feb_sales" + , "round"("sum"((CASE WHEN ("d_moy" = 3) THEN ("cs_sales_price" * "cs_quantity") ELSE 0 END)), 2) "mar_sales" + , "round"("sum"((CASE WHEN ("d_moy" = 4) THEN ("cs_sales_price" * "cs_quantity") ELSE 0 END)), 2) "apr_sales" + , "round"("sum"((CASE WHEN ("d_moy" = 5) THEN ("cs_sales_price" * "cs_quantity") ELSE 0 END)), 2) "may_sales" + , "round"("sum"((CASE WHEN ("d_moy" = 6) THEN ("cs_sales_price" * "cs_quantity") ELSE 0 END)), 2) "jun_sales" + , "round"("sum"((CASE WHEN ("d_moy" = 7) THEN ("cs_sales_price" * "cs_quantity") ELSE 0 END)), 2) "jul_sales" + , "round"("sum"((CASE WHEN ("d_moy" = 8) THEN ("cs_sales_price" * "cs_quantity") ELSE 0 END)), 2) "aug_sales" + , "round"("sum"((CASE WHEN ("d_moy" = 9) THEN ("cs_sales_price" * "cs_quantity") ELSE 0 END)), 2) "sep_sales" + , "round"("sum"((CASE WHEN ("d_moy" = 10) THEN ("cs_sales_price" * "cs_quantity") ELSE 0 END)), 2) "oct_sales" + , "round"("sum"((CASE WHEN ("d_moy" = 11) THEN ("cs_sales_price" * "cs_quantity") ELSE 0 END)), 2) "nov_sales" + , "round"("sum"((CASE WHEN ("d_moy" = 12) THEN ("cs_sales_price" * "cs_quantity") ELSE 0 END)), 2) "dec_sales" + , "round"("sum"((CASE WHEN ("d_moy" = 1) THEN ("cs_net_paid_inc_tax" * "cs_quantity") ELSE 0 END)), 2) "jan_net" + , "round"("sum"((CASE WHEN ("d_moy" = 2) THEN ("cs_net_paid_inc_tax" * "cs_quantity") ELSE 0 END)), 2) "feb_net" + , "round"("sum"((CASE WHEN ("d_moy" = 3) THEN ("cs_net_paid_inc_tax" * "cs_quantity") ELSE 0 END)), 2) "mar_net" + , "round"("sum"((CASE WHEN ("d_moy" = 4) THEN ("cs_net_paid_inc_tax" * "cs_quantity") ELSE 0 END)), 2) "apr_net" + , "round"("sum"((CASE WHEN ("d_moy" = 5) THEN ("cs_net_paid_inc_tax" * "cs_quantity") ELSE 0 END)), 2) "may_net" + , "round"("sum"((CASE WHEN ("d_moy" = 6) THEN ("cs_net_paid_inc_tax" * "cs_quantity") ELSE 0 END)), 2) "jun_net" + , "round"("sum"((CASE WHEN ("d_moy" = 7) THEN ("cs_net_paid_inc_tax" * "cs_quantity") ELSE 0 END)), 2) "jul_net" + , "round"("sum"((CASE WHEN ("d_moy" = 8) THEN ("cs_net_paid_inc_tax" * "cs_quantity") ELSE 0 END)), 2) "aug_net" + , "round"("sum"((CASE WHEN ("d_moy" = 9) THEN ("cs_net_paid_inc_tax" * "cs_quantity") ELSE 0 END)), 2) "sep_net" + , "round"("sum"((CASE WHEN ("d_moy" = 10) THEN ("cs_net_paid_inc_tax" * "cs_quantity") ELSE 0 END)), 2) "oct_net" + , "round"("sum"((CASE WHEN ("d_moy" = 11) THEN ("cs_net_paid_inc_tax" * "cs_quantity") ELSE 0 END)), 2) "nov_net" + , "round"("sum"((CASE WHEN ("d_moy" = 12) THEN ("cs_net_paid_inc_tax" * "cs_quantity") ELSE 0 END)), 2) "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" ASC +LIMIT 100 diff --git a/presto-native-execution/src/test/resources/tpcds/queries/q67.sql b/presto-native-execution/src/test/resources/tpcds/queries/q67.sql new file mode 100644 index 0000000000000..d9c480e490daf --- /dev/null +++ b/presto-native-execution/src/test/resources/tpcds/queries/q67.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" + , "round"("sum"(COALESCE(("ss_sales_price" * "ss_quantity"), 0)), 2) "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" ASC, "i_class" ASC, "i_brand" ASC, "i_product_name" ASC, "d_year" ASC, "d_qoy" ASC, "d_moy" ASC, "s_store_id" ASC, "sumsales" ASC, "rk" ASC +LIMIT 100 diff --git a/presto-native-execution/src/test/resources/tpcds/queries/q68.sql b/presto-native-execution/src/test/resources/tpcds/queries/q68.sql new file mode 100644 index 0000000000000..85f3b60a14c3c --- /dev/null +++ b/presto-native-execution/src/test/resources/tpcds/queries/q68.sql @@ -0,0 +1,42 @@ +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" + , "round"("sum"("ss_ext_sales_price"), 2) "extended_price" + , "round"("sum"("ss_ext_list_price"), 2) "list_price" + , "round"("sum"("ss_ext_tax"), 2) "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 ('Midway' , '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" ASC, "ss_ticket_number" ASC +LIMIT 100 diff --git a/presto-native-execution/src/test/resources/tpcds/queries/q69.sql b/presto-native-execution/src/test/resources/tpcds/queries/q69.sql new file mode 100644 index 0000000000000..404160e63d242 --- /dev/null +++ b/presto-native-execution/src/test/resources/tpcds/queries/q69.sql @@ -0,0 +1,49 @@ +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" ASC, "cd_marital_status" ASC, "cd_education_status" ASC, "cd_purchase_estimate" ASC, "cd_credit_rating" ASC +LIMIT 100 diff --git a/presto-native-execution/src/test/resources/tpcds/queries/q70.sql b/presto-native-execution/src/test/resources/tpcds/queries/q70.sql new file mode 100644 index 0000000000000..a569b4b60ba43 --- /dev/null +++ b/presto-native-execution/src/test/resources/tpcds/queries/q70.sql @@ -0,0 +1,34 @@ +SELECT + "round"("sum"("ss_net_profit"), 2) "total_sum" +, "s_state" +, "s_county" +, (GROUPING ("s_state") + GROUPING ("s_county")) "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) "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" "s_state" + , "rank"() OVER (PARTITION BY "s_state" ORDER BY "sum"("ss_net_profit") DESC) "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) ASC, "rank_within_parent" ASC +LIMIT 100 diff --git a/presto-native-execution/src/test/resources/tpcds/queries/q71.sql b/presto-native-execution/src/test/resources/tpcds/queries/q71.sql new file mode 100644 index 0000000000000..5a6a35da0b0c1 --- /dev/null +++ b/presto-native-execution/src/test/resources/tpcds/queries/q71.sql @@ -0,0 +1,51 @@ +SELECT + "i_brand_id" "brand_id" +, "i_brand" "brand" +, "t_hour" +, "t_minute" +, "round"("sum"("ext_price"), 2) "ext_price" +FROM + item +, ( + SELECT + "ws_ext_sales_price" "ext_price" + , "ws_sold_date_sk" "sold_date_sk" + , "ws_item_sk" "sold_item_sk" + , "ws_sold_time_sk" "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" "ext_price" + , "cs_sold_date_sk" "sold_date_sk" + , "cs_item_sk" "sold_item_sk" + , "cs_sold_time_sk" "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" "ext_price" + , "ss_sold_date_sk" "sold_date_sk" + , "ss_item_sk" "sold_item_sk" + , "ss_sold_time_sk" "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" ASC diff --git a/presto-native-execution/src/test/resources/tpcds/queries/q72.sql b/presto-native-execution/src/test/resources/tpcds/queries/q72.sql new file mode 100644 index 0000000000000..2b2f66436f2a8 --- /dev/null +++ b/presto-native-execution/src/test/resources/tpcds/queries/q72.sql @@ -0,0 +1,29 @@ +SELECT + "i_item_desc" +, "w_warehouse_name" +, "d1"."d_week_seq" +, "round"("sum"((CASE WHEN ("p_promo_sk" IS NULL) THEN 1 ELSE 0 END)), 2) "no_promo" +, "round"("sum"((CASE WHEN ("p_promo_sk" IS NOT NULL) THEN 1 ELSE 0 END)), 2) "promo" +, "count"(*) "total_cnt" +FROM + ((((((((((catalog_sales +INNER JOIN inventory ON ("cs_item_sk" = "inv_item_sk")) +INNER JOIN warehouse ON ("w_warehouse_sk" = "inv_warehouse_sk")) +INNER JOIN item ON ("i_item_sk" = "cs_item_sk")) +INNER JOIN customer_demographics ON ("cs_bill_cdemo_sk" = "cd_demo_sk")) +INNER JOIN household_demographics ON ("cs_bill_hdemo_sk" = "hd_demo_sk")) +INNER JOIN date_dim d1 ON ("cs_sold_date_sk" = "d1"."d_date_sk")) +INNER JOIN date_dim d2 ON ("inv_date_sk" = "d2"."d_date_sk")) +INNER JOIN date_dim d3 ON ("cs_ship_date_sk" = "d3"."d_date_sk")) +LEFT JOIN promotion ON ("cs_promo_sk" = "p_promo_sk")) +LEFT 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" > ("d1"."d_date" + INTERVAL '5' DAY)) + 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" ASC, "w_warehouse_name" ASC, "d1"."d_week_seq" ASC +LIMIT 100 diff --git a/presto-native-execution/src/test/resources/tpcds/queries/q73.sql b/presto-native-execution/src/test/resources/tpcds/queries/q73.sql new file mode 100644 index 0000000000000..672398e385726 --- /dev/null +++ b/presto-native-execution/src/test/resources/tpcds/queries/q73.sql @@ -0,0 +1,35 @@ +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 (CAST("household_demographics"."hd_dep_count" AS DECIMAL(7,2)) / "household_demographics"."hd_vehicle_count") ELSE null END) > 1) + AND ((CASE WHEN ("household_demographics"."hd_vehicle_count" > 0) THEN (CAST("household_demographics"."hd_dep_count" AS double) / "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/presto-native-execution/src/test/resources/tpcds/queries/q74.sql b/presto-native-execution/src/test/resources/tpcds/queries/q74.sql new file mode 100644 index 0000000000000..5cd8e2f382b53 --- /dev/null +++ b/presto-native-execution/src/test/resources/tpcds/queries/q74.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" "YEAR" + , "round"("sum"("ss_net_paid"), 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") + 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" "YEAR" + , "round"("sum"("ws_net_paid"), 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") + 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 ASC, 1 ASC, 1 ASC +LIMIT 100 diff --git a/presto-native-execution/src/test/resources/tpcds/queries/q75.sql b/presto-native-execution/src/test/resources/tpcds/queries/q75.sql new file mode 100644 index 0000000000000..3f2ce8e530b18 --- /dev/null +++ b/presto-native-execution/src/test/resources/tpcds/queries/q75.sql @@ -0,0 +1,84 @@ +WITH + all_sales AS ( + SELECT + "d_year" + , "i_brand_id" + , "i_class_id" + , "i_category_id" + , "i_manufact_id" + , "round"("sum"("sales_cnt"), 2) "sales_cnt" + , "round"("sum"("sales_amt"), 2) "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)) "sales_cnt" + , ("cs_ext_sales_price" - COALESCE("cr_return_amount", DECIMAL '0.0')) "sales_amt" + FROM + (((catalog_sales + INNER JOIN item ON ("i_item_sk" = "cs_item_sk")) + INNER 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)) "sales_cnt" + , ("ss_ext_sales_price" - COALESCE("sr_return_amt", DECIMAL '0.0')) "sales_amt" + FROM + (((store_sales + INNER JOIN item ON ("i_item_sk" = "ss_item_sk")) + INNER 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)) "sales_cnt" + , ("ws_ext_sales_price" - COALESCE("wr_return_amt", DECIMAL '0.0')) "sales_amt" + FROM + (((web_sales + INNER JOIN item ON ("i_item_sk" = "ws_item_sk")) + INNER 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" "prev_year" +, "curr_yr"."d_year" "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" "prev_yr_cnt" +, "curr_yr"."sales_cnt" "curr_yr_cnt" +, ("curr_yr"."sales_cnt" - "prev_yr"."sales_cnt") "sales_cnt_diff" +, ("curr_yr"."sales_amt" - "prev_yr"."sales_amt") "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))) < DECIMAL '0.9') + AND ((CAST("curr_yr"."sales_cnt" AS double) / CAST("prev_yr"."sales_cnt" AS double)) < 0.9) +ORDER BY "sales_cnt_diff" ASC, "sales_amt_diff" ASC +LIMIT 100 diff --git a/presto-native-execution/src/test/resources/tpcds/queries/q76.sql b/presto-native-execution/src/test/resources/tpcds/queries/q76.sql new file mode 100644 index 0000000000000..c7d78b0ee81cc --- /dev/null +++ b/presto-native-execution/src/test/resources/tpcds/queries/q76.sql @@ -0,0 +1,56 @@ +SELECT + "channel" +, "col_name" +, "d_year" +, "d_qoy" +, "i_category" +, "count"(*) "sales_cnt" +, "round"("sum"("ext_sales_price"), 2) "sales_amt" +FROM + ( + SELECT + 'store' "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' "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' "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" ASC, "col_name" ASC, "d_year" ASC, "d_qoy" ASC, "i_category" ASC +LIMIT 100 diff --git a/presto-native-execution/src/test/resources/tpcds/queries/q77.sql b/presto-native-execution/src/test/resources/tpcds/queries/q77.sql new file mode 100644 index 0000000000000..64a96671b4de2 --- /dev/null +++ b/presto-native-execution/src/test/resources/tpcds/queries/q77.sql @@ -0,0 +1,120 @@ +WITH + ss AS ( + SELECT + "s_store_sk" + , "round"("sum"("ss_ext_sales_price"), 2) "sales" + , "round"("sum"("ss_net_profit"), 2) "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 (CAST('2000-08-23' AS DATE) + INTERVAL '30' DAY)) + AND ("ss_store_sk" = "s_store_sk") + GROUP BY "s_store_sk" +) +, sr AS ( + SELECT + "s_store_sk" + , "round"("sum"("sr_return_amt"), 2) "returns" + , "round"("sum"("sr_net_loss"), 2) "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 (CAST('2000-08-23' AS DATE) + INTERVAL '30' DAY)) + AND ("sr_store_sk" = "s_store_sk") + GROUP BY "s_store_sk" +) +, cs AS ( + SELECT + "cs_call_center_sk" + , "round"("sum"("cs_ext_sales_price"), 2) "sales" + , "round"("sum"("cs_net_profit"), 2) "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 (CAST('2000-08-23' AS DATE) + INTERVAL '30' DAY)) + GROUP BY "cs_call_center_sk" +) +, cr AS ( + SELECT + "cr_call_center_sk" + , "round"("sum"("cr_return_amount"), 2) "returns" + , "round"("sum"("cr_net_loss"), 2) "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 (CAST('2000-08-23' AS DATE) + INTERVAL '30' DAY)) + GROUP BY "cr_call_center_sk" +) +, ws AS ( + SELECT + "wp_web_page_sk" + , "round"("sum"("ws_ext_sales_price"), 2) "sales" + , "round"("sum"("ws_net_profit"), 2) "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 (CAST('2000-08-23' AS DATE) + INTERVAL '30' DAY)) + AND ("ws_web_page_sk" = "wp_web_page_sk") + GROUP BY "wp_web_page_sk" +) +, wr AS ( + SELECT + "wp_web_page_sk" + , "round"("sum"("wr_return_amt"), 2) "returns" + , "round"("sum"("wr_net_loss"), 2) "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 (CAST('2000-08-23' AS DATE) + INTERVAL '30' DAY)) + AND ("wr_web_page_sk" = "wp_web_page_sk") + GROUP BY "wp_web_page_sk" +) +SELECT + "channel" +, "id" +, "round"("sum"("sales"), 2) "sales" +, "round"("sum"("returns"), 2) "returns" +, "round"("sum"("profit"), 2) "profit" +FROM + ( + SELECT + 'store channel' "channel" + , "ss"."s_store_sk" "id" + , "sales" + , COALESCE("returns", 0) "returns" + , ("profit" - COALESCE("profit_loss", 0)) "profit" + FROM + (ss + LEFT JOIN sr ON ("ss"."s_store_sk" = "sr"."s_store_sk")) +UNION ALL SELECT + 'catalog channel' "channel" + , "cs_call_center_sk" "id" + , "sales" + , "returns" + , ("profit" - "profit_loss") "profit" + FROM + cs + , cr +UNION ALL SELECT + 'web channel' "channel" + , "ws"."wp_web_page_sk" "id" + , "sales" + , COALESCE("returns", 0) "returns" + , ("profit" - COALESCE("profit_loss", 0)) "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" ASC, "id" ASC, "sales" ASC +LIMIT 100 diff --git a/presto-native-execution/src/test/resources/tpcds/queries/q78.sql b/presto-native-execution/src/test/resources/tpcds/queries/q78.sql new file mode 100644 index 0000000000000..1bd1ef6aa9277 --- /dev/null +++ b/presto-native-execution/src/test/resources/tpcds/queries/q78.sql @@ -0,0 +1,75 @@ +WITH + ws AS ( + SELECT + "d_year" "ws_sold_year" + , "ws_item_sk" + , "ws_bill_customer_sk" "ws_customer_sk" + , "round"("sum"("ws_quantity"), 2) "ws_qty" + , "round"("sum"("ws_wholesale_cost"), 2) "ws_wc" + , "round"("sum"("ws_sales_price"), 2) "ws_sp" + FROM + ((web_sales + LEFT JOIN web_returns ON ("wr_order_number" = "ws_order_number") + AND ("ws_item_sk" = "wr_item_sk")) + INNER 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" "cs_sold_year" + , "cs_item_sk" + , "cs_bill_customer_sk" "cs_customer_sk" + , "round"("sum"("cs_quantity"), 2) "cs_qty" + , "round"("sum"("cs_wholesale_cost"), 2) "cs_wc" + , "round"("sum"("cs_sales_price"), 2) "cs_sp" + FROM + ((catalog_sales + LEFT JOIN catalog_returns ON ("cr_order_number" = "cs_order_number") + AND ("cs_item_sk" = "cr_item_sk")) + INNER 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" "ss_sold_year" + , "ss_item_sk" + , "ss_customer_sk" + , "round"("sum"("ss_quantity"), 2) "ss_qty" + , "round"("sum"("ss_wholesale_cost"), 2) "ss_wc" + , "round"("sum"("ss_sales_price"), 2) "ss_sp" + FROM + ((store_sales + LEFT JOIN store_returns ON ("sr_ticket_number" = "ss_ticket_number") + AND ("ss_item_sk" = "sr_item_sk")) + INNER 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"((CAST("ss_qty" AS DECIMAL(10,2)) / COALESCE(("ws_qty" + "cs_qty"), 1)), 2) "ratio" +, "round"((CAST("ss_qty" AS double) / COALESCE(("ws_qty" + "cs_qty"), 1)), 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" = "cs_item_sk") + AND ("cs_customer_sk" = "ss_customer_sk")) +WHERE (COALESCE("ws_qty", 0) > 0) + AND (COALESCE("cs_qty", 0) > 0) + AND ("ss_sold_year" = 2000) +--ORDER BY "ss_sold_year" ASC, "ss_item_sk" ASC, "ss_customer_sk" ASC, "ss_qty" DESC, "ss_wc" DESC, "ss_sp" DESC, "other_chan_qty" ASC, "other_chan_wholesale_cost" ASC, "other_chan_sales_price" ASC, "round"((CAST("ss_qty" AS DECIMAL(10,2)) / COALESCE(("ws_qty" + "cs_qty"), 1)), 2) ASC +ORDER BY "ss_sold_year" ASC, "ss_item_sk" ASC, "ss_customer_sk" ASC, "ss_qty" DESC, "ss_wc" DESC, "ss_sp" DESC, "other_chan_qty" ASC, "other_chan_wholesale_cost" ASC, "other_chan_sales_price" ASC, "round"((CAST("ss_qty" AS double) / COALESCE(("ws_qty" + "cs_qty"), 1)), 2) ASC +LIMIT 100 diff --git a/presto-native-execution/src/test/resources/tpcds/queries/q79.sql b/presto-native-execution/src/test/resources/tpcds/queries/q79.sql new file mode 100644 index 0000000000000..26273c39a85f1 --- /dev/null +++ b/presto-native-execution/src/test/resources/tpcds/queries/q79.sql @@ -0,0 +1,34 @@ +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" + , "round"("sum"("ss_coupon_amt"), 2) "amt" + , "round"("sum"("ss_net_profit"), 2) "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" ASC, "c_first_name" ASC, "substr"("s_city", 1, 30) ASC, "profit" ASC +LIMIT 100 diff --git a/presto-native-execution/src/test/resources/tpcds/queries/q80.sql b/presto-native-execution/src/test/resources/tpcds/queries/q80.sql new file mode 100644 index 0000000000000..e45823d81addd --- /dev/null +++ b/presto-native-execution/src/test/resources/tpcds/queries/q80.sql @@ -0,0 +1,106 @@ +WITH + ssr AS ( + SELECT + "s_store_id" "store_id" + , "sum"("ss_ext_sales_price") "sales" + , "sum"(COALESCE("sr_return_amt", 0)) "returns" + , "sum"(("ss_net_profit" - COALESCE("sr_net_loss", 0))) "profit" + FROM + (store_sales + LEFT 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 (CAST("d_date" AS DATE) BETWEEN CAST('2000-08-23' AS DATE) AND (CAST('2000-08-23' AS DATE) + INTERVAL '30' DAY)) + 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" "catalog_page_id" + , "sum"("cs_ext_sales_price") "sales" + , "sum"(COALESCE("cr_return_amount", 0)) "returns" + , "sum"(("cs_net_profit" - COALESCE("cr_net_loss", 0))) "profit" + FROM + (catalog_sales + LEFT 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 (CAST("d_date" AS DATE) BETWEEN CAST('2000-08-23' AS DATE) AND (CAST('2000-08-23' AS DATE) + INTERVAL '30' DAY)) + 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") "sales" + , "sum"(COALESCE("wr_return_amt", 0)) "returns" + , "sum"(("ws_net_profit" - COALESCE("wr_net_loss", 0))) "profit" + FROM + (web_sales + LEFT 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 (CAST("d_date" AS DATE) BETWEEN CAST('2000-08-23' AS DATE) AND (CAST('2000-08-23' AS DATE) + INTERVAL '30' DAY)) + 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") "sales" +, "sum"("returns") "returns" +, "sum"("profit") "profit" +FROM + ( + SELECT + 'store channel' "channel" + , "concat"('store', "store_id") "id" + , "sales" + , "returns" + , "profit" + FROM + ssr +UNION ALL SELECT + 'catalog channel' "channel" + , "concat"('catalog_page', "catalog_page_id") "id" + , "sales" + , "returns" + , "profit" + FROM + csr +UNION ALL SELECT + 'web channel' "channel" + , "concat"('web_site', "web_site_id") "id" + , "sales" + , "returns" + , "profit" + FROM + wsr +) x +GROUP BY ROLLUP (channel, id) +ORDER BY "channel" ASC, "id" ASC +LIMIT 100 diff --git a/presto-native-execution/src/test/resources/tpcds/queries/q81.sql b/presto-native-execution/src/test/resources/tpcds/queries/q81.sql new file mode 100644 index 0000000000000..0edccc2fbc0aa --- /dev/null +++ b/presto-native-execution/src/test/resources/tpcds/queries/q81.sql @@ -0,0 +1,47 @@ +WITH + customer_total_return AS ( + SELECT + "cr_returning_customer_sk" "ctr_customer_sk" + , "ca_state" "ctr_state" + , "round"("sum"("cr_return_amt_inc_tax"), 2) "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 ("round"("avg"("ctr_total_return") * DECIMAL '1.2', 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" ASC, "c_salutation" ASC, "c_first_name" ASC, "c_last_name" ASC, "ca_street_number" ASC, "ca_street_name" ASC, "ca_street_type" ASC, "ca_suite_number" ASC, "ca_city" ASC, "ca_county" ASC, "ca_state" ASC, "ca_zip" ASC, "ca_country" ASC, "ca_gmt_offset" ASC, "ca_location_type" ASC, "ctr_total_return" ASC +LIMIT 100 diff --git a/presto-native-execution/src/test/resources/tpcds/queries/q82.sql b/presto-native-execution/src/test/resources/tpcds/queries/q82.sql new file mode 100644 index 0000000000000..2d03c91a3a181 --- /dev/null +++ b/presto-native-execution/src/test/resources/tpcds/queries/q82.sql @@ -0,0 +1,19 @@ +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 (CAST("d_date" AS DATE) BETWEEN CAST('2000-05-25' AS DATE) AND (CAST('2000-05-25' AS DATE) + INTERVAL '60' DAY)) + 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" ASC +LIMIT 100 diff --git a/presto-native-execution/src/test/resources/tpcds/queries/q83.sql b/presto-native-execution/src/test/resources/tpcds/queries/q83.sql new file mode 100644 index 0000000000000..30f7df36c361b --- /dev/null +++ b/presto-native-execution/src/test/resources/tpcds/queries/q83.sql @@ -0,0 +1,93 @@ +WITH + sr_items AS ( + SELECT + "i_item_id" "item_id" + , "round"("sum"("sr_return_quantity"), 2) "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 (CAST('2000-06-30' AS DATE) , CAST('2000-09-27' AS DATE) , CAST('2000-11-17' AS DATE))) + )) + )) + AND ("sr_returned_date_sk" = "d_date_sk") + GROUP BY "i_item_id" +) +, cr_items AS ( + SELECT + "i_item_id" "item_id" + , "round"("sum"("cr_return_quantity"), 2) "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 (CAST('2000-06-30' AS DATE) , CAST('2000-09-27' AS DATE) , CAST('2000-11-17' AS DATE))) + )) + )) + AND ("cr_returned_date_sk" = "d_date_sk") + GROUP BY "i_item_id" +) +, wr_items AS ( + SELECT + "i_item_id" "item_id" + , "round"("sum"("wr_return_quantity"), 2) "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 (CAST('2000-06-30' AS DATE) , CAST('2000-09-27' AS DATE) , CAST('2000-11-17' AS DATE))) + )) + )) + AND ("wr_returned_date_sk" = "d_date_sk") + GROUP BY "i_item_id" +) +SELECT + "sr_items"."item_id" +, "sr_item_qty" +--, CAST(((("sr_item_qty" / ((CAST("sr_item_qty" AS DECIMAL(9,4)) + "cr_item_qty") + "wr_item_qty")) / DECIMAL '3.0') * 100) AS DECIMAL(7,2)) "sr_dev" +--, "cr_item_qty" +--, CAST(((("cr_item_qty" / ((CAST("sr_item_qty" AS DECIMAL(9,4)) + "cr_item_qty") + "wr_item_qty")) / DECIMAL '3.0') * 100) AS DECIMAL(7,2)) "cr_dev" +--, "wr_item_qty" +--, CAST(((("wr_item_qty" / ((CAST("sr_item_qty" AS DECIMAL(9,4)) + "cr_item_qty") + "wr_item_qty")) / DECIMAL '3.0') * 100) AS DECIMAL(7,2)) "wr_dev" +--, ((("sr_item_qty" + "cr_item_qty") + "wr_item_qty") / DECIMAL '3.00') "average" +, CAST(((("sr_item_qty" / ((CAST("sr_item_qty" AS double) + "cr_item_qty") + "wr_item_qty")) / 3.0) * 100) AS double) "sr_dev" +, "cr_item_qty" +, CAST(((("cr_item_qty" / ((CAST("sr_item_qty" AS double) + "cr_item_qty") + "wr_item_qty")) / 3.0) * 100) AS double) "cr_dev" +, "wr_item_qty" +, CAST(((("wr_item_qty" / ((CAST("sr_item_qty" AS double) + "cr_item_qty") + "wr_item_qty")) / 3.0) * 100) AS double) "wr_dev" +, ((("sr_item_qty" + "cr_item_qty") + "wr_item_qty") / 3.00) "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" ASC, "sr_item_qty" ASC +LIMIT 100 diff --git a/presto-native-execution/src/test/resources/tpcds/queries/q84.sql b/presto-native-execution/src/test/resources/tpcds/queries/q84.sql new file mode 100644 index 0000000000000..fcc56b59ec6b9 --- /dev/null +++ b/presto-native-execution/src/test/resources/tpcds/queries/q84.sql @@ -0,0 +1,20 @@ +SELECT + "c_customer_id" "customer_id" +, "concat"("concat"("c_last_name", ', '), "c_first_name") "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" ASC +LIMIT 100 diff --git a/presto-native-execution/src/test/resources/tpcds/queries/q85.sql b/presto-native-execution/src/test/resources/tpcds/queries/q85.sql new file mode 100644 index 0000000000000..4e8dd4e3ddc3c --- /dev/null +++ b/presto-native-execution/src/test/resources/tpcds/queries/q85.sql @@ -0,0 +1,53 @@ +SELECT + "substr"("r_reason_desc", 1, 20) +, "round"("avg"("ws_quantity"), 2) +, "round"("avg"("wr_refunded_cash"), 2) +, "round"("avg"("wr_fee"), 2) +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 DECIMAL '100.00' AND DECIMAL '150.00')) + 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 DECIMAL '50.00' AND DECIMAL '100.00')) + 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 DECIMAL '150.00' AND DECIMAL '200.00'))) + 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) ASC, "round"("avg"("ws_quantity"), 2) ASC, "round"("avg"("wr_refunded_cash"), 2) ASC, "round"("avg"("wr_fee"), 2) ASC +LIMIT 100 diff --git a/presto-native-execution/src/test/resources/tpcds/queries/q86.sql b/presto-native-execution/src/test/resources/tpcds/queries/q86.sql new file mode 100644 index 0000000000000..dc7fc478d45e1 --- /dev/null +++ b/presto-native-execution/src/test/resources/tpcds/queries/q86.sql @@ -0,0 +1,16 @@ +SELECT + "round"("sum"("ws_net_paid"), 2) "total_sum" +, "i_category" +, "i_class" +, (GROUPING ("i_category") + GROUPING ("i_class")) "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) "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) ASC, "rank_within_parent" ASC +LIMIT 100 diff --git a/presto-native-execution/src/test/resources/tpcds/queries/q87.sql b/presto-native-execution/src/test/resources/tpcds/queries/q87.sql new file mode 100644 index 0000000000000..4bb3b47e29564 --- /dev/null +++ b/presto-native-execution/src/test/resources/tpcds/queries/q87.sql @@ -0,0 +1,40 @@ +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/presto-native-execution/src/test/resources/tpcds/queries/q88.sql b/presto-native-execution/src/test/resources/tpcds/queries/q88.sql new file mode 100644 index 0000000000000..7c14b44bafa48 --- /dev/null +++ b/presto-native-execution/src/test/resources/tpcds/queries/q88.sql @@ -0,0 +1,162 @@ +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/presto-native-execution/src/test/resources/tpcds/queries/q89.sql b/presto-native-execution/src/test/resources/tpcds/queries/q89.sql new file mode 100644 index 0000000000000..d4e2fc2d386e6 --- /dev/null +++ b/presto-native-execution/src/test/resources/tpcds/queries/q89.sql @@ -0,0 +1,30 @@ +SELECT * +FROM + ( + SELECT + "i_category" + , "i_class" + , "i_brand" + , "s_store_name" + , "s_company_name" + , "d_moy" + , "round"("sum"("ss_sales_price"), 2) "sum_sales" + , "round"("avg"("sum"("ss_sales_price")), 2) 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) > DECIMAL '0.1') +ORDER BY ("sum_sales" - "avg_monthly_sales") ASC, "s_store_name" ASC +LIMIT 100 diff --git a/presto-native-execution/src/test/resources/tpcds/queries/q90.sql b/presto-native-execution/src/test/resources/tpcds/queries/q90.sql new file mode 100644 index 0000000000000..2b314b8d876cf --- /dev/null +++ b/presto-native-execution/src/test/resources/tpcds/queries/q90.sql @@ -0,0 +1,33 @@ +--SELECT (CAST("amc" AS DECIMAL(15,4)) / CAST("pmc" AS DECIMAL(15,4))) "am_pm_ratio" +SELECT (CAST("amc" AS double) / CAST("pmc" AS double)) "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) +) "at" +, ( + 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" ASC +LIMIT 100 diff --git a/presto-native-execution/src/test/resources/tpcds/queries/q91.sql b/presto-native-execution/src/test/resources/tpcds/queries/q91.sql new file mode 100644 index 0000000000000..a4334c4790e82 --- /dev/null +++ b/presto-native-execution/src/test/resources/tpcds/queries/q91.sql @@ -0,0 +1,29 @@ +SELECT + "cc_call_center_id" "Call_Center" +, "cc_name" "Call_Center_Name" +, "cc_manager" "Manager" +, "round"("sum"("cr_net_loss"), 2) "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 "round"("sum"("cr_net_loss"), 2) DESC diff --git a/presto-native-execution/src/test/resources/tpcds/queries/q92.sql b/presto-native-execution/src/test/resources/tpcds/queries/q92.sql new file mode 100644 index 0000000000000..961e469c507f2 --- /dev/null +++ b/presto-native-execution/src/test/resources/tpcds/queries/q92.sql @@ -0,0 +1,20 @@ +SELECT "round"("sum"("ws_ext_discount_amt"), 2) "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 CAST('2000-01-27' AS DATE) AND (CAST('2000-01-27' AS DATE) + INTERVAL '90' DAY)) + AND ("d_date_sk" = "ws_sold_date_sk") + AND ("ws_ext_discount_amt" > ( + SELECT (DECIMAL '1.3' * "avg"("ws_ext_discount_amt")) + FROM + web_sales + , date_dim + WHERE ("ws_item_sk" = "i_item_sk") + AND ("d_date" BETWEEN CAST('2000-01-27' AS DATE) AND (CAST('2000-01-27' AS DATE) + INTERVAL '90' DAY)) + AND ("d_date_sk" = "ws_sold_date_sk") + )) +ORDER BY "round"("sum"("ws_ext_discount_amt"), 2) ASC +LIMIT 100 diff --git a/presto-native-execution/src/test/resources/tpcds/queries/q93.sql b/presto-native-execution/src/test/resources/tpcds/queries/q93.sql new file mode 100644 index 0000000000000..309994223003f --- /dev/null +++ b/presto-native-execution/src/test/resources/tpcds/queries/q93.sql @@ -0,0 +1,21 @@ +SELECT + "ss_customer_sk" +, "round"("sum"("act_sales"), 2) "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 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" ASC, "ss_customer_sk" ASC +LIMIT 100 diff --git a/presto-native-execution/src/test/resources/tpcds/queries/q94.sql b/presto-native-execution/src/test/resources/tpcds/queries/q94.sql new file mode 100644 index 0000000000000..eb217ac921506 --- /dev/null +++ b/presto-native-execution/src/test/resources/tpcds/queries/q94.sql @@ -0,0 +1,30 @@ +SELECT + "count"(DISTINCT "ws_order_number") "order count" +, "round"("sum"("ws_ext_ship_cost"), 2) "total shipping cost" +, "round"("sum"("ws_net_profit"), 2) "total net profit" +FROM + web_sales ws1 +, date_dim +, customer_address +, web_site +WHERE ("d_date" BETWEEN CAST('1999-2-01' AS DATE) AND (CAST('1999-2-01' AS DATE) + INTERVAL '60' DAY)) + 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") ASC +LIMIT 100 diff --git a/presto-native-execution/src/test/resources/tpcds/queries/q95.sql b/presto-native-execution/src/test/resources/tpcds/queries/q95.sql new file mode 100644 index 0000000000000..180ff20b01b4c --- /dev/null +++ b/presto-native-execution/src/test/resources/tpcds/queries/q95.sql @@ -0,0 +1,41 @@ +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") "order count" +, "round"("sum"("ws_ext_ship_cost"), 2) "total shipping cost" +, "round"("sum"("ws_net_profit"), 2) "total net profit" +FROM + web_sales ws1 +, date_dim +, customer_address +, web_site +WHERE (CAST("d_date" AS DATE) BETWEEN CAST('1999-2-01' AS DATE) AND (CAST('1999-2-01' AS DATE) + INTERVAL '60' DAY)) + 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") ASC +LIMIT 100 diff --git a/presto-native-execution/src/test/resources/tpcds/queries/q96.sql b/presto-native-execution/src/test/resources/tpcds/queries/q96.sql new file mode 100644 index 0000000000000..ce1373c8ad905 --- /dev/null +++ b/presto-native-execution/src/test/resources/tpcds/queries/q96.sql @@ -0,0 +1,15 @@ +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"(*) ASC +LIMIT 100 diff --git a/presto-native-execution/src/test/resources/tpcds/queries/q97.sql b/presto-native-execution/src/test/resources/tpcds/queries/q97.sql new file mode 100644 index 0000000000000..4b59efe523bf3 --- /dev/null +++ b/presto-native-execution/src/test/resources/tpcds/queries/q97.sql @@ -0,0 +1,35 @@ +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 + "round"("sum"((CASE WHEN ("ssci"."customer_sk" IS NOT NULL) + AND ("csci"."customer_sk" IS NULL) THEN 1 ELSE 0 END)), 2) "store_only" +, "round"("sum"((CASE WHEN ("ssci"."customer_sk" IS NULL) + AND ("csci"."customer_sk" IS NOT NULL) THEN 1 ELSE 0 END)), 2) "catalog_only" +, "round"("sum"((CASE WHEN ("ssci"."customer_sk" IS NOT NULL) + AND ("csci"."customer_sk" IS NOT NULL) THEN 1 ELSE 0 END)), 2) "store_and_catalog" +FROM + (ssci +FULL JOIN csci ON ("ssci"."customer_sk" = "csci"."customer_sk") + AND ("ssci"."item_sk" = "csci"."item_sk")) +LIMIT 100 diff --git a/presto-native-execution/src/test/resources/tpcds/queries/q98.sql b/presto-native-execution/src/test/resources/tpcds/queries/q98.sql new file mode 100644 index 0000000000000..66a38b671ed8a --- /dev/null +++ b/presto-native-execution/src/test/resources/tpcds/queries/q98.sql @@ -0,0 +1,18 @@ +SELECT + "i_item_id" +, "i_item_desc" +, "i_category" +, "i_class" +, "i_current_price" +, "sum"("ss_ext_sales_price") "itemrevenue" +, (("sum"("ss_ext_sales_price") * 100) / "sum"("sum"("ss_ext_sales_price")) OVER (PARTITION BY "i_class")) "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 (CAST("d_date" AS DATE) BETWEEN CAST('1999-02-22' AS DATE) AND (CAST('1999-02-22' AS DATE) + INTERVAL '30' DAY)) +GROUP BY "i_item_id", "i_item_desc", "i_category", "i_class", "i_current_price" +ORDER BY "i_category" ASC, "i_class" ASC, "i_item_id" ASC, "i_item_desc" ASC, "revenueratio" ASC diff --git a/presto-native-execution/src/test/resources/tpcds/queries/q99.sql b/presto-native-execution/src/test/resources/tpcds/queries/q99.sql new file mode 100644 index 0000000000000..336932c1b74ca --- /dev/null +++ b/presto-native-execution/src/test/resources/tpcds/queries/q99.sql @@ -0,0 +1,26 @@ +SELECT + "substr"("w_warehouse_name", 1, 20) +, "sm_type" +, "cc_name" +, "round"("sum"((CASE WHEN (("cs_ship_date_sk" - "cs_sold_date_sk") <= 30) THEN 1 ELSE 0 END)), 2) "30 days" +, "round"("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)), 2) "31-60 days" +, "round"("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)), 2) "61-90 days" +, "round"("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)), 2) "91-120 days" +, "round"("sum"((CASE WHEN (("cs_ship_date_sk" - "cs_sold_date_sk") > 120) THEN 1 ELSE 0 END)), 2) ">120 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) ASC, "sm_type" ASC, "cc_name" ASC +LIMIT 100 diff --git a/presto-tests/src/main/java/com/facebook/presto/tests/AbstractTestQueryFramework.java b/presto-tests/src/main/java/com/facebook/presto/tests/AbstractTestQueryFramework.java index 40063e267374c..9a23aa5ec5d9f 100644 --- a/presto-tests/src/main/java/com/facebook/presto/tests/AbstractTestQueryFramework.java +++ b/presto-tests/src/main/java/com/facebook/presto/tests/AbstractTestQueryFramework.java @@ -72,6 +72,9 @@ public abstract class AbstractTestQueryFramework { + static final String PARQUET_STORAGE_FORMAT = "PARQUET"; + static final String DWARF_STORAGE_FORMAT = "DWRF"; + private QueryRunner queryRunner; private ExpectedQueryRunner expectedQueryRunner; private SqlParser sqlParser;