From c893b3c3d038541098921ca95673697e6133ce57 Mon Sep 17 00:00:00 2001 From: "R. C. Howell" Date: Mon, 16 Oct 2023 10:36:34 -0700 Subject: [PATCH 1/3] Initializes testFixture inputs with planner cases --- .../resources/catalogs/{ => db}/aws/b/b.ion | 0 .../resources/catalogs/{ => db}/aws/ddb/b.ion | 0 .../catalogs/{ => db}/aws/ddb/pets.ion | 0 .../resources/catalogs/{ => db}/b/b/b.ion | 0 .../resources/catalogs/{ => db}/b/b/c.ion | 0 .../resources/catalogs/{ => db}/b/b/d.ion | 0 .../resources/catalogs/{ => db}/b/c/c.ion | 0 .../org/partiql/planner/PlannerTestCase.kt | 39 +++ .../org/partiql/planner/PlannerTestGroup.kt | 25 ++ .../org/partiql/planner/PlannerTestJunit.kt | 60 ++-- .../partiql/planner/PlannerTestProvider.kt | 25 ++ .../cases/schema_inferrencer/sanity.ion | 160 +++++++++ .../src/test/resources/cases/tpc_ds/.gitkeep | 0 .../src/test/resources/cases/tpc_h/.gitkeep | 0 .../org/partiql/planner/test/Parsing.kt | 194 ----------- .../partiql/planner/test/PartiQLTestCase.kt | 17 + .../partiql/planner/test/PartiQLTestGroup.kt | 47 +++ .../planner/test/PartiQLTestProvider.kt | 37 +++ .../org/partiql/planner/test/PlannerTest.kt | 28 -- .../partiql/planner/test/PlannerTestLog.kt | 28 -- .../planner/test/PlannerTestProvider.kt | 28 -- .../planner/test/PlannerTestSession.kt | 37 --- .../partiql/planner/test/PlannerTestSuite.kt | 37 --- .../partiql/planner/test/PlannerTestTarget.kt | 14 - .../src/testFixtures/resources/README.adoc | 139 ++++++++ .../resources/catalogs/default/db/aws/b/b.ion | 13 + .../catalogs/default/db/aws/ddb/b.ion | 13 + .../catalogs/default/db/aws/ddb/pets.ion | 17 + .../resources/catalogs/default/db/b/b/b.ion | 23 ++ .../resources/catalogs/default/db/b/b/c.ion | 1 + .../resources/catalogs/default/db/b/b/d.ion | 22 ++ .../resources/catalogs/default/db/b/c/c.ion | 1 + .../default/db/markets/order_info.ion | 19 ++ .../catalogs/default/db/markets/orders.ion | 21 ++ .../{default => }/tpc_ds/call_center.ion | 0 .../{default => }/tpc_ds/catalog_page.ion | 0 .../{default => }/tpc_ds/catalog_returns.ion | 0 .../{default => }/tpc_ds/catalog_sales.ion | 0 .../{default => }/tpc_ds/customer.ion | 0 .../{default => }/tpc_ds/customer_address.ion | 0 .../tpc_ds/customer_demographics.ion | 0 .../{default => }/tpc_ds/date_dim.ion | 0 .../{default => }/tpc_ds/dbgen_version.ion | 0 .../tpc_ds/household_demographics.ion | 0 .../{default => }/tpc_ds/income_band.ion | 0 .../{default => }/tpc_ds/inventory.ion | 0 .../catalogs/{default => }/tpc_ds/item.ion | 0 .../{default => }/tpc_ds/promotion.ion | 0 .../catalogs/{default => }/tpc_ds/reason.ion | 0 .../{default => }/tpc_ds/ship_mode.ion | 0 .../catalogs/{default => }/tpc_ds/store.ion | 0 .../{default => }/tpc_ds/store_returns.ion | 0 .../{default => }/tpc_ds/store_sales.ion | 0 .../{default => }/tpc_ds/time_dim.ion | 0 .../{default => }/tpc_ds/warehouse.ion | 0 .../{default => }/tpc_ds/web_page.ion | 0 .../{default => }/tpc_ds/web_returns.ion | 0 .../{default => }/tpc_ds/web_sales.ion | 0 .../{default => }/tpc_ds/web_site.ion | 0 .../resources/catalogs/tpc_h/.gitkeep | 0 .../inputs/schema_inferrencer/sanity.sql | 40 +++ .../resources/inputs/tpc_ds/query01.sql | 23 ++ .../resources/inputs/tpc_ds/query02.sql | 79 +++++ .../resources/inputs/tpc_ds/query03.sql | 19 ++ .../resources/inputs/tpc_ds/query04.sql | 152 +++++++++ .../resources/inputs/tpc_ds/query05.sql | 128 ++++++++ .../resources/inputs/tpc_ds/query06.sql | 23 ++ .../resources/inputs/tpc_ds/query07.sql | 24 ++ .../resources/inputs/tpc_ds/query08.sql | 227 +++++++++++++ .../resources/inputs/tpc_ds/query09.sql | 63 ++++ .../resources/inputs/tpc_ds/query10.sql | 62 ++++ .../resources/inputs/tpc_ds/query11.sql | 97 ++++++ .../resources/inputs/tpc_ds/query12.sql | 31 ++ .../resources/inputs/tpc_ds/query13.sql | 44 +++ .../resources/inputs/tpc_ds/query14.sql | 245 ++++++++++++++ .../resources/inputs/tpc_ds/query15.sql | 20 ++ .../resources/inputs/tpc_ds/query16.sql | 34 ++ .../resources/inputs/tpc_ds/query17.sql | 56 ++++ .../resources/inputs/tpc_ds/query18.sql | 38 +++ .../resources/inputs/tpc_ds/query19.sql | 31 ++ .../resources/inputs/tpc_ds/query20.sql | 31 ++ .../resources/inputs/tpc_ds/query21.sql | 39 +++ .../resources/inputs/tpc_ds/query22.sql | 21 ++ .../resources/inputs/tpc_ds/query23.sql | 136 ++++++++ .../resources/inputs/tpc_ds/query24.sql | 96 ++++++ .../resources/inputs/tpc_ds/query25.sql | 41 +++ .../resources/inputs/tpc_ds/query26.sql | 24 ++ .../resources/inputs/tpc_ds/query27.sql | 27 ++ .../resources/inputs/tpc_ds/query28.sql | 51 +++ .../resources/inputs/tpc_ds/query29.sql | 40 +++ .../resources/inputs/tpc_ds/query30.sql | 49 +++ .../resources/inputs/tpc_ds/query31.sql | 73 +++++ .../resources/inputs/tpc_ds/query32.sql | 22 ++ .../resources/inputs/tpc_ds/query33.sql | 65 ++++ .../resources/inputs/tpc_ds/query34.sql | 46 +++ .../resources/inputs/tpc_ds/query35.sql | 58 ++++ .../resources/inputs/tpc_ds/query36.sql | 31 ++ .../resources/inputs/tpc_ds/query37.sql | 23 ++ .../resources/inputs/tpc_ds/query38.sql | 32 ++ .../resources/inputs/tpc_ds/query39.sql | 117 +++++++ .../resources/inputs/tpc_ds/query40.sql | 36 +++ .../resources/inputs/tpc_ds/query41.sql | 66 ++++ .../resources/inputs/tpc_ds/query42.sql | 21 ++ .../resources/inputs/tpc_ds/query43.sql | 50 +++ .../resources/inputs/tpc_ds/query44.sql | 51 +++ .../resources/inputs/tpc_ds/query45.sql | 28 ++ .../resources/inputs/tpc_ds/query46.sql | 44 +++ .../resources/inputs/tpc_ds/query47.sql | 72 +++++ .../resources/inputs/tpc_ds/query48.sql | 34 ++ .../resources/inputs/tpc_ds/query49.sql | 133 ++++++++ .../resources/inputs/tpc_ds/query50.sql | 71 ++++ .../resources/inputs/tpc_ds/query51.sql | 55 ++++ .../resources/inputs/tpc_ds/query52.sql | 20 ++ .../resources/inputs/tpc_ds/query53.sql | 46 +++ .../resources/inputs/tpc_ds/query54.sql | 57 ++++ .../resources/inputs/tpc_ds/query55.sql | 17 + .../resources/inputs/tpc_ds/query56.sql | 68 ++++ .../resources/inputs/tpc_ds/query57.sql | 66 ++++ .../resources/inputs/tpc_ds/query58.sql | 72 +++++ .../resources/inputs/tpc_ds/query59.sql | 85 +++++ .../resources/inputs/tpc_ds/query60.sql | 66 ++++ .../resources/inputs/tpc_ds/query61.sql | 47 +++ .../resources/inputs/tpc_ds/query62.sql | 45 +++ .../resources/inputs/tpc_ds/query63.sql | 45 +++ .../resources/inputs/tpc_ds/query64.sql | 122 +++++++ .../resources/inputs/tpc_ds/query65.sql | 37 +++ .../resources/inputs/tpc_ds/query66.sql | 306 ++++++++++++++++++ .../resources/inputs/tpc_ds/query67.sql | 43 +++ .../resources/inputs/tpc_ds/query68.sql | 41 +++ .../resources/inputs/tpc_ds/query69.sql | 46 +++ .../resources/inputs/tpc_ds/query70.sql | 40 +++ .../resources/inputs/tpc_ds/query71.sql | 48 +++ .../resources/inputs/tpc_ds/query72.sql | 49 +++ .../resources/inputs/tpc_ds/query73.sql | 39 +++ .../resources/inputs/tpc_ds/query74.sql | 69 ++++ .../resources/inputs/tpc_ds/query75.sql | 93 ++++++ .../resources/inputs/tpc_ds/query76.sql | 57 ++++ .../resources/inputs/tpc_ds/query77.sql | 108 +++++++ .../resources/inputs/tpc_ds/query78.sql | 86 +++++ .../resources/inputs/tpc_ds/query79.sql | 35 ++ .../resources/inputs/tpc_ds/query80.sql | 106 ++++++ .../resources/inputs/tpc_ds/query81.sql | 56 ++++ .../resources/inputs/tpc_ds/query82.sql | 24 ++ .../resources/inputs/tpc_ds/query83.sql | 75 +++++ .../resources/inputs/tpc_ds/query84.sql | 21 ++ .../resources/inputs/tpc_ds/query85.sql | 52 +++ .../resources/inputs/tpc_ds/query86.sql | 24 ++ .../resources/inputs/tpc_ds/query87.sql | 22 ++ .../resources/inputs/tpc_ds/query88.sql | 93 ++++++ .../resources/inputs/tpc_ds/query89.sql | 40 +++ .../resources/inputs/tpc_ds/query90.sql | 28 ++ .../resources/inputs/tpc_ds/query91.sql | 32 ++ .../resources/inputs/tpc_ds/query92.sql | 23 ++ .../resources/inputs/tpc_ds/query93.sql | 22 ++ .../resources/inputs/tpc_ds/query94.sql | 30 ++ .../resources/inputs/tpc_ds/query95.sql | 38 +++ .../resources/inputs/tpc_ds/query96.sql | 15 + .../resources/inputs/tpc_ds/query97.sql | 40 +++ .../resources/inputs/tpc_ds/query98.sql | 29 ++ .../resources/inputs/tpc_ds/query99.sql | 47 +++ .../resources/inputs/tpc_h/query01.sql | 22 ++ .../resources/inputs/tpc_h/query02.sql | 44 +++ .../resources/inputs/tpc_h/query03.sql | 23 ++ .../resources/inputs/tpc_h/query04.sql | 22 ++ .../resources/inputs/tpc_h/query05.sql | 25 ++ .../resources/inputs/tpc_h/query06.sql | 16 + .../resources/inputs/tpc_h/query07.sql | 40 +++ .../resources/inputs/tpc_h/query08.sql | 39 +++ .../resources/inputs/tpc_h/query09.sql | 33 ++ .../resources/inputs/tpc_h/query10.sql | 32 ++ .../resources/inputs/tpc_h/query11.sql | 28 ++ .../resources/inputs/tpc_h/query12.sql | 29 ++ .../resources/inputs/tpc_h/query13.sql | 21 ++ .../resources/inputs/tpc_h/query14.sql | 14 + .../resources/inputs/tpc_h/query15.sql | 35 ++ .../resources/inputs/tpc_h/query16.sql | 31 ++ .../resources/inputs/tpc_h/query17.sql | 18 ++ .../resources/inputs/tpc_h/query18.sql | 33 ++ .../resources/inputs/tpc_h/query19.sql | 36 +++ .../resources/inputs/tpc_h/query20.sql | 38 +++ .../resources/inputs/tpc_h/query21.sql | 40 +++ .../resources/inputs/tpc_h/query22.sql | 38 +++ .../testFixtures/resources/tests/suite_00.ion | 152 --------- .../src/testFixtures/resources/todo.txt | 2 - 184 files changed, 7105 insertions(+), 540 deletions(-) rename partiql-lang/src/test/resources/catalogs/{ => db}/aws/b/b.ion (100%) rename partiql-lang/src/test/resources/catalogs/{ => db}/aws/ddb/b.ion (100%) rename partiql-lang/src/test/resources/catalogs/{ => db}/aws/ddb/pets.ion (100%) rename partiql-lang/src/test/resources/catalogs/{ => db}/b/b/b.ion (100%) rename partiql-lang/src/test/resources/catalogs/{ => db}/b/b/c.ion (100%) rename partiql-lang/src/test/resources/catalogs/{ => db}/b/b/d.ion (100%) rename partiql-lang/src/test/resources/catalogs/{ => db}/b/c/c.ion (100%) create mode 100644 partiql-planner/src/test/kotlin/org/partiql/planner/PlannerTestCase.kt create mode 100644 partiql-planner/src/test/kotlin/org/partiql/planner/PlannerTestGroup.kt create mode 100644 partiql-planner/src/test/kotlin/org/partiql/planner/PlannerTestProvider.kt create mode 100644 partiql-planner/src/test/resources/cases/schema_inferrencer/sanity.ion create mode 100644 partiql-planner/src/test/resources/cases/tpc_ds/.gitkeep create mode 100644 partiql-planner/src/test/resources/cases/tpc_h/.gitkeep delete mode 100644 partiql-planner/src/testFixtures/kotlin/org/partiql/planner/test/Parsing.kt create mode 100644 partiql-planner/src/testFixtures/kotlin/org/partiql/planner/test/PartiQLTestCase.kt create mode 100644 partiql-planner/src/testFixtures/kotlin/org/partiql/planner/test/PartiQLTestGroup.kt create mode 100644 partiql-planner/src/testFixtures/kotlin/org/partiql/planner/test/PartiQLTestProvider.kt delete mode 100644 partiql-planner/src/testFixtures/kotlin/org/partiql/planner/test/PlannerTest.kt delete mode 100644 partiql-planner/src/testFixtures/kotlin/org/partiql/planner/test/PlannerTestLog.kt delete mode 100644 partiql-planner/src/testFixtures/kotlin/org/partiql/planner/test/PlannerTestProvider.kt delete mode 100644 partiql-planner/src/testFixtures/kotlin/org/partiql/planner/test/PlannerTestSession.kt delete mode 100644 partiql-planner/src/testFixtures/kotlin/org/partiql/planner/test/PlannerTestSuite.kt delete mode 100644 partiql-planner/src/testFixtures/kotlin/org/partiql/planner/test/PlannerTestTarget.kt create mode 100644 partiql-planner/src/testFixtures/resources/README.adoc create mode 100644 partiql-planner/src/testFixtures/resources/catalogs/default/db/aws/b/b.ion create mode 100644 partiql-planner/src/testFixtures/resources/catalogs/default/db/aws/ddb/b.ion create mode 100644 partiql-planner/src/testFixtures/resources/catalogs/default/db/aws/ddb/pets.ion create mode 100644 partiql-planner/src/testFixtures/resources/catalogs/default/db/b/b/b.ion create mode 100644 partiql-planner/src/testFixtures/resources/catalogs/default/db/b/b/c.ion create mode 100644 partiql-planner/src/testFixtures/resources/catalogs/default/db/b/b/d.ion create mode 100644 partiql-planner/src/testFixtures/resources/catalogs/default/db/b/c/c.ion create mode 100644 partiql-planner/src/testFixtures/resources/catalogs/default/db/markets/order_info.ion create mode 100644 partiql-planner/src/testFixtures/resources/catalogs/default/db/markets/orders.ion rename partiql-planner/src/testFixtures/resources/catalogs/{default => }/tpc_ds/call_center.ion (100%) rename partiql-planner/src/testFixtures/resources/catalogs/{default => }/tpc_ds/catalog_page.ion (100%) rename partiql-planner/src/testFixtures/resources/catalogs/{default => }/tpc_ds/catalog_returns.ion (100%) rename partiql-planner/src/testFixtures/resources/catalogs/{default => }/tpc_ds/catalog_sales.ion (100%) rename partiql-planner/src/testFixtures/resources/catalogs/{default => }/tpc_ds/customer.ion (100%) rename partiql-planner/src/testFixtures/resources/catalogs/{default => }/tpc_ds/customer_address.ion (100%) rename partiql-planner/src/testFixtures/resources/catalogs/{default => }/tpc_ds/customer_demographics.ion (100%) rename partiql-planner/src/testFixtures/resources/catalogs/{default => }/tpc_ds/date_dim.ion (100%) rename partiql-planner/src/testFixtures/resources/catalogs/{default => }/tpc_ds/dbgen_version.ion (100%) rename partiql-planner/src/testFixtures/resources/catalogs/{default => }/tpc_ds/household_demographics.ion (100%) rename partiql-planner/src/testFixtures/resources/catalogs/{default => }/tpc_ds/income_band.ion (100%) rename partiql-planner/src/testFixtures/resources/catalogs/{default => }/tpc_ds/inventory.ion (100%) rename partiql-planner/src/testFixtures/resources/catalogs/{default => }/tpc_ds/item.ion (100%) rename partiql-planner/src/testFixtures/resources/catalogs/{default => }/tpc_ds/promotion.ion (100%) rename partiql-planner/src/testFixtures/resources/catalogs/{default => }/tpc_ds/reason.ion (100%) rename partiql-planner/src/testFixtures/resources/catalogs/{default => }/tpc_ds/ship_mode.ion (100%) rename partiql-planner/src/testFixtures/resources/catalogs/{default => }/tpc_ds/store.ion (100%) rename partiql-planner/src/testFixtures/resources/catalogs/{default => }/tpc_ds/store_returns.ion (100%) rename partiql-planner/src/testFixtures/resources/catalogs/{default => }/tpc_ds/store_sales.ion (100%) rename partiql-planner/src/testFixtures/resources/catalogs/{default => }/tpc_ds/time_dim.ion (100%) rename partiql-planner/src/testFixtures/resources/catalogs/{default => }/tpc_ds/warehouse.ion (100%) rename partiql-planner/src/testFixtures/resources/catalogs/{default => }/tpc_ds/web_page.ion (100%) rename partiql-planner/src/testFixtures/resources/catalogs/{default => }/tpc_ds/web_returns.ion (100%) rename partiql-planner/src/testFixtures/resources/catalogs/{default => }/tpc_ds/web_sales.ion (100%) rename partiql-planner/src/testFixtures/resources/catalogs/{default => }/tpc_ds/web_site.ion (100%) create mode 100644 partiql-planner/src/testFixtures/resources/catalogs/tpc_h/.gitkeep create mode 100644 partiql-planner/src/testFixtures/resources/inputs/schema_inferrencer/sanity.sql create mode 100644 partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query01.sql create mode 100644 partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query02.sql create mode 100644 partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query03.sql create mode 100644 partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query04.sql create mode 100644 partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query05.sql create mode 100644 partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query06.sql create mode 100644 partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query07.sql create mode 100644 partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query08.sql create mode 100644 partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query09.sql create mode 100644 partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query10.sql create mode 100644 partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query11.sql create mode 100644 partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query12.sql create mode 100644 partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query13.sql create mode 100644 partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query14.sql create mode 100644 partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query15.sql create mode 100644 partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query16.sql create mode 100644 partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query17.sql create mode 100644 partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query18.sql create mode 100644 partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query19.sql create mode 100644 partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query20.sql create mode 100644 partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query21.sql create mode 100644 partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query22.sql create mode 100644 partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query23.sql create mode 100644 partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query24.sql create mode 100644 partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query25.sql create mode 100644 partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query26.sql create mode 100644 partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query27.sql create mode 100644 partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query28.sql create mode 100644 partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query29.sql create mode 100644 partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query30.sql create mode 100644 partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query31.sql create mode 100644 partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query32.sql create mode 100644 partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query33.sql create mode 100644 partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query34.sql create mode 100644 partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query35.sql create mode 100644 partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query36.sql create mode 100644 partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query37.sql create mode 100644 partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query38.sql create mode 100644 partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query39.sql create mode 100644 partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query40.sql create mode 100644 partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query41.sql create mode 100644 partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query42.sql create mode 100644 partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query43.sql create mode 100644 partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query44.sql create mode 100644 partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query45.sql create mode 100644 partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query46.sql create mode 100644 partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query47.sql create mode 100644 partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query48.sql create mode 100644 partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query49.sql create mode 100644 partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query50.sql create mode 100644 partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query51.sql create mode 100644 partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query52.sql create mode 100644 partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query53.sql create mode 100644 partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query54.sql create mode 100644 partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query55.sql create mode 100644 partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query56.sql create mode 100644 partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query57.sql create mode 100644 partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query58.sql create mode 100644 partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query59.sql create mode 100644 partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query60.sql create mode 100644 partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query61.sql create mode 100644 partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query62.sql create mode 100644 partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query63.sql create mode 100644 partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query64.sql create mode 100644 partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query65.sql create mode 100644 partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query66.sql create mode 100644 partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query67.sql create mode 100644 partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query68.sql create mode 100644 partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query69.sql create mode 100644 partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query70.sql create mode 100644 partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query71.sql create mode 100644 partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query72.sql create mode 100644 partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query73.sql create mode 100644 partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query74.sql create mode 100644 partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query75.sql create mode 100644 partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query76.sql create mode 100644 partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query77.sql create mode 100644 partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query78.sql create mode 100644 partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query79.sql create mode 100644 partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query80.sql create mode 100644 partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query81.sql create mode 100644 partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query82.sql create mode 100644 partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query83.sql create mode 100644 partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query84.sql create mode 100644 partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query85.sql create mode 100644 partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query86.sql create mode 100644 partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query87.sql create mode 100644 partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query88.sql create mode 100644 partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query89.sql create mode 100644 partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query90.sql create mode 100644 partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query91.sql create mode 100644 partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query92.sql create mode 100644 partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query93.sql create mode 100644 partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query94.sql create mode 100644 partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query95.sql create mode 100644 partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query96.sql create mode 100644 partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query97.sql create mode 100644 partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query98.sql create mode 100644 partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query99.sql create mode 100644 partiql-planner/src/testFixtures/resources/inputs/tpc_h/query01.sql create mode 100644 partiql-planner/src/testFixtures/resources/inputs/tpc_h/query02.sql create mode 100644 partiql-planner/src/testFixtures/resources/inputs/tpc_h/query03.sql create mode 100644 partiql-planner/src/testFixtures/resources/inputs/tpc_h/query04.sql create mode 100644 partiql-planner/src/testFixtures/resources/inputs/tpc_h/query05.sql create mode 100644 partiql-planner/src/testFixtures/resources/inputs/tpc_h/query06.sql create mode 100644 partiql-planner/src/testFixtures/resources/inputs/tpc_h/query07.sql create mode 100644 partiql-planner/src/testFixtures/resources/inputs/tpc_h/query08.sql create mode 100644 partiql-planner/src/testFixtures/resources/inputs/tpc_h/query09.sql create mode 100644 partiql-planner/src/testFixtures/resources/inputs/tpc_h/query10.sql create mode 100644 partiql-planner/src/testFixtures/resources/inputs/tpc_h/query11.sql create mode 100644 partiql-planner/src/testFixtures/resources/inputs/tpc_h/query12.sql create mode 100644 partiql-planner/src/testFixtures/resources/inputs/tpc_h/query13.sql create mode 100644 partiql-planner/src/testFixtures/resources/inputs/tpc_h/query14.sql create mode 100644 partiql-planner/src/testFixtures/resources/inputs/tpc_h/query15.sql create mode 100644 partiql-planner/src/testFixtures/resources/inputs/tpc_h/query16.sql create mode 100644 partiql-planner/src/testFixtures/resources/inputs/tpc_h/query17.sql create mode 100644 partiql-planner/src/testFixtures/resources/inputs/tpc_h/query18.sql create mode 100644 partiql-planner/src/testFixtures/resources/inputs/tpc_h/query19.sql create mode 100644 partiql-planner/src/testFixtures/resources/inputs/tpc_h/query20.sql create mode 100644 partiql-planner/src/testFixtures/resources/inputs/tpc_h/query21.sql create mode 100644 partiql-planner/src/testFixtures/resources/inputs/tpc_h/query22.sql delete mode 100644 partiql-planner/src/testFixtures/resources/tests/suite_00.ion delete mode 100644 partiql-planner/src/testFixtures/resources/todo.txt diff --git a/partiql-lang/src/test/resources/catalogs/aws/b/b.ion b/partiql-lang/src/test/resources/catalogs/db/aws/b/b.ion similarity index 100% rename from partiql-lang/src/test/resources/catalogs/aws/b/b.ion rename to partiql-lang/src/test/resources/catalogs/db/aws/b/b.ion diff --git a/partiql-lang/src/test/resources/catalogs/aws/ddb/b.ion b/partiql-lang/src/test/resources/catalogs/db/aws/ddb/b.ion similarity index 100% rename from partiql-lang/src/test/resources/catalogs/aws/ddb/b.ion rename to partiql-lang/src/test/resources/catalogs/db/aws/ddb/b.ion diff --git a/partiql-lang/src/test/resources/catalogs/aws/ddb/pets.ion b/partiql-lang/src/test/resources/catalogs/db/aws/ddb/pets.ion similarity index 100% rename from partiql-lang/src/test/resources/catalogs/aws/ddb/pets.ion rename to partiql-lang/src/test/resources/catalogs/db/aws/ddb/pets.ion diff --git a/partiql-lang/src/test/resources/catalogs/b/b/b.ion b/partiql-lang/src/test/resources/catalogs/db/b/b/b.ion similarity index 100% rename from partiql-lang/src/test/resources/catalogs/b/b/b.ion rename to partiql-lang/src/test/resources/catalogs/db/b/b/b.ion diff --git a/partiql-lang/src/test/resources/catalogs/b/b/c.ion b/partiql-lang/src/test/resources/catalogs/db/b/b/c.ion similarity index 100% rename from partiql-lang/src/test/resources/catalogs/b/b/c.ion rename to partiql-lang/src/test/resources/catalogs/db/b/b/c.ion diff --git a/partiql-lang/src/test/resources/catalogs/b/b/d.ion b/partiql-lang/src/test/resources/catalogs/db/b/b/d.ion similarity index 100% rename from partiql-lang/src/test/resources/catalogs/b/b/d.ion rename to partiql-lang/src/test/resources/catalogs/db/b/b/d.ion diff --git a/partiql-lang/src/test/resources/catalogs/b/c/c.ion b/partiql-lang/src/test/resources/catalogs/db/b/c/c.ion similarity index 100% rename from partiql-lang/src/test/resources/catalogs/b/c/c.ion rename to partiql-lang/src/test/resources/catalogs/db/b/c/c.ion diff --git a/partiql-planner/src/test/kotlin/org/partiql/planner/PlannerTestCase.kt b/partiql-planner/src/test/kotlin/org/partiql/planner/PlannerTestCase.kt new file mode 100644 index 0000000000..271b1adcbb --- /dev/null +++ b/partiql-planner/src/test/kotlin/org/partiql/planner/PlannerTestCase.kt @@ -0,0 +1,39 @@ +package org.partiql.planner + +import com.amazon.ionelement.api.IonElement +import com.amazon.ionelement.api.ListElement +import com.amazon.ionelement.api.StringElement +import com.amazon.ionelement.api.StructElement +import org.partiql.plugins.local.getAngry +import org.partiql.plugins.local.toStaticType +import org.partiql.types.StaticType + +data class PlannerTestCase( + public val input: String, + public val catalog: String, + public val catalogPath: List, + public val schema: StaticType, +) { + + companion object { + + fun load(ion: StructElement): PlannerTestCase { + // Required + val input = ion.getAngry("input").textValue + val catalog = ion.getAngry("catalog").textValue + val schema = ion.getAngry("schema").toStaticType() + // Optional + val catalogPath = mutableListOf() + val pathArr = ion.getOptional("catalogPath") + if (pathArr != null && pathArr is ListElement) { + pathArr.asList().values.forEach { v -> + if (v !is StringElement) { + error("catalogPath must be a list of strings") + } + catalogPath.add((v as StringElement).textValue) + } + } + return PlannerTestCase(input, catalog, catalogPath, schema) + } + } +} diff --git a/partiql-planner/src/test/kotlin/org/partiql/planner/PlannerTestGroup.kt b/partiql-planner/src/test/kotlin/org/partiql/planner/PlannerTestGroup.kt new file mode 100644 index 0000000000..20db17ee63 --- /dev/null +++ b/partiql-planner/src/test/kotlin/org/partiql/planner/PlannerTestGroup.kt @@ -0,0 +1,25 @@ +package org.partiql.planner + +import com.amazon.ionelement.api.StructElement +import com.amazon.ionelement.api.loadAllElements +import java.io.File + +data class PlannerTestGroup( + public val name: String, + public val cases: List, +) { + + companion object { + + public fun load(dir: File): PlannerTestGroup { + val tests = dir.listFiles()!!.flatMap { loadAllTests(it) } + return PlannerTestGroup(dir.name, tests) + } + + public fun loadAllTests(file: File): List { + val text = file.readText() + val ion = loadAllElements(text) + return ion.map { PlannerTestCase.load(it as StructElement) } + } + } +} diff --git a/partiql-planner/src/test/kotlin/org/partiql/planner/PlannerTestJunit.kt b/partiql-planner/src/test/kotlin/org/partiql/planner/PlannerTestJunit.kt index e752ec0033..4556a31e58 100644 --- a/partiql-planner/src/test/kotlin/org/partiql/planner/PlannerTestJunit.kt +++ b/partiql-planner/src/test/kotlin/org/partiql/planner/PlannerTestJunit.kt @@ -14,26 +14,29 @@ import org.junit.jupiter.api.fail import org.partiql.errors.ProblemSeverity import org.partiql.parser.PartiQLParserBuilder import org.partiql.plan.Statement -import org.partiql.planner.test.PlannerTest -import org.partiql.planner.test.PlannerTestProvider -import org.partiql.planner.test.PlannerTestSuite -import org.partiql.planner.test.toIon +import org.partiql.planner.test.PartiQLTestCase +import org.partiql.planner.test.PartiQLTestProvider import org.partiql.plugins.local.LocalPlugin +import org.partiql.plugins.local.toIon import java.util.stream.Stream -import kotlin.io.path.pathString -import kotlin.io.path.toPath +/** + * PlannerTestJunit is responsible for constructing JUnit test suites from all input queries in the testFixtures. + * + * I believe this can be more generic and added to testFixtures; but that is outside the scope of current work. + */ class PlannerTestJunit { @TestFactory fun mapSuitesToJunitTests(): Stream { - val provider = PlannerTestProvider() - return provider.suites().map { suiteNode(it) } + val inputs = PartiQLTestProvider().inputs() + val cases = PlannerTestProvider().groups() + return cases.map { groupNode(it, inputs) } } companion object { - private val root = PlannerTest::class.java.getResource("/catalogs")!!.toURI().toPath().pathString + private val root = PartiQLTestProvider::class.java.getResource("/catalogs")!!.toURI().path private val parser = PartiQLParserBuilder.standard().build() @@ -42,35 +45,52 @@ class PlannerTestJunit { field("connector_name", ionString("local")), field("root", ionString("$root/default")), ), + "tpc_ds" to ionStructOf( + field("connector_name", ionString("local")), + field("root", ionString("$root/tpc_ds")), + ), ) - private fun suiteNode(suite: PlannerTestSuite): DynamicContainer { + private fun groupNode(group: PlannerTestGroup, inputs: Map): DynamicContainer { val plugin = LocalPlugin() val planner = PartiQLPlannerBuilder() .plugins(listOf(plugin)) .build() - val tests = suite.tests.map { (name, test) -> - val testName = "${suite.name}__$name" + // Map all cases to an input + val tests = group.cases.map { case -> + val key = "${group.name}__${case.input}" + val input = inputs[key] + // Report bad input mapping + if (input == null) { + return@map failTestNode(key, "Missing input for `$key`") + } val session = PartiQLPlanner.Session( - queryId = "q__$testName", + queryId = key, userId = "Planner_test_runner", - currentCatalog = suite.session.catalog, - currentDirectory = suite.session.path, + currentCatalog = case.catalog, + currentDirectory = case.catalogPath, catalogConfig = catalogConfig, ) - testNode(testName, planner, session, test) + testNode(key, planner, session, input.statement, case) + } + return dynamicContainer(group.name, tests.stream()) + } + + private fun failTestNode(id: String, message: String): DynamicTest { + return dynamicTest(id) { + fail { message } } - return dynamicContainer(suite.name, tests.stream()) } private fun testNode( displayName: String, planner: PartiQLPlanner, session: PartiQLPlanner.Session, - test: PlannerTest, + statement: String, + case: PlannerTestCase, ): DynamicTest { return dynamicTest(displayName) { - val ast = parser.parse(test.statement).root + val ast = parser.parse(statement).root val result = planner.plan(ast, session) for (problem in result.problems) { if (problem.details.severity == ProblemSeverity.ERROR) { @@ -81,7 +101,7 @@ class PlannerTestJunit { if (statement !is Statement.Query) { fail { "Expected plan statement to be a Statement.Query" } } - val expected = test.schema.toIon() + val expected = case.schema.toIon() val actual = statement.root.type.toIon() assertEquals(expected, actual) } diff --git a/partiql-planner/src/test/kotlin/org/partiql/planner/PlannerTestProvider.kt b/partiql-planner/src/test/kotlin/org/partiql/planner/PlannerTestProvider.kt new file mode 100644 index 0000000000..5c47db42ad --- /dev/null +++ b/partiql-planner/src/test/kotlin/org/partiql/planner/PlannerTestProvider.kt @@ -0,0 +1,25 @@ +package org.partiql.planner + +import java.util.stream.Stream +import kotlin.io.path.toPath + +/** + * TODO converge with PartiQLTestProvider. + */ +class PlannerTestProvider { + + private val groups: List + + init { + val default = PlannerTestProvider::class.java.getResource("/cases")!!.toURI().toPath() + val casesDir = default.toFile() + groups = casesDir.listFiles { f -> f.isDirectory }!!.map { PlannerTestGroup.load(it) } + } + + /** + * Return test cases associated by groups. + */ + public fun groups(): Stream { + return groups.stream() + } +} diff --git a/partiql-planner/src/test/resources/cases/schema_inferrencer/sanity.ion b/partiql-planner/src/test/resources/cases/schema_inferrencer/sanity.ion new file mode 100644 index 0000000000..b5936f76fa --- /dev/null +++ b/partiql-planner/src/test/resources/cases/schema_inferrencer/sanity.ion @@ -0,0 +1,160 @@ +case::{ + input: "sanity-01", + catalog: "tpc_ds", + schema: { + type: "bag", + items: { + type: "struct", + constraints: [ + closed, + unique, + ordered + ], + fields: [ + { + name: "ss_ticket_number", + type: "string", + }, + { + name: "ss_quantity", + type: [ + "int32", + "null" + ], + }, + { + name: "ss_sold_date_sk", + type: [ + "date", + "null" + ], + }, + ], + }, + } +} + +case::{ + input: "sanity-02", + catalog: "tpc_ds", + schema: { + type: "bag", + items: { + type: "struct", + constraints: [ + closed, + unique, + ordered + ], + fields: [ + { + name: "ss_ticket_number", + type: "string", + }, + { + name: "ss_quantity", + type: [ + "int32", + "null" + ], + }, + { + name: "ss_sold_date_sk", + type: [ + "date", + "null" + ], + }, + ], + }, + } +} + +case::{ + input: "sanity-03", + catalog: "tpc_ds", + schema: { + type: "bag", + items: { + type: "struct", + constraints: [ + closed, + unique, + ordered + ], + fields: [ + { + name: "x", + type: [ + "bool", + "null" + ], + }, + ], + }, + }, +} + +case::{ + input: "sanity-04", + catalog: "tpc_ds", + schema: { + type: "bag", + items: { + type: "struct", + constraints: [ + closed, + unique, + ordered + ], + fields: [ + { + name: "ss_quantity", + type: [ + "int32", + "null" + ] + }, + { + name: "ss_quantity_description_1", + type: "string" + }, + { + name: "ss_quantity_description_2", + type: [ + "string", + "decimal", + "int", + "null" + ] + }, + { + name: "ss_quantity_description_3", + type: "string" + }, + ] + } + } +} + +case::{ + input: "sanity-05", + catalog: "tpc_ds", + schema: { + type: "bag", + items: { + type: "struct", + constraints: [ + closed, + unique, + ordered + ], + fields: [ + { + name: "s_store_sk", + type: "string" + } + ] + } + } +} diff --git a/partiql-planner/src/test/resources/cases/tpc_ds/.gitkeep b/partiql-planner/src/test/resources/cases/tpc_ds/.gitkeep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/partiql-planner/src/test/resources/cases/tpc_h/.gitkeep b/partiql-planner/src/test/resources/cases/tpc_h/.gitkeep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/partiql-planner/src/testFixtures/kotlin/org/partiql/planner/test/Parsing.kt b/partiql-planner/src/testFixtures/kotlin/org/partiql/planner/test/Parsing.kt deleted file mode 100644 index 08d7894ac8..0000000000 --- a/partiql-planner/src/testFixtures/kotlin/org/partiql/planner/test/Parsing.kt +++ /dev/null @@ -1,194 +0,0 @@ -package org.partiql.planner.test - -import com.amazon.ionelement.api.IonElement -import com.amazon.ionelement.api.ListElement -import com.amazon.ionelement.api.StringElement -import com.amazon.ionelement.api.StructElement -import com.amazon.ionelement.api.ionListOf -import com.amazon.ionelement.api.ionString -import com.amazon.ionelement.api.ionStructOf -import org.partiql.types.AnyOfType -import org.partiql.types.AnyType -import org.partiql.types.BagType -import org.partiql.types.BlobType -import org.partiql.types.BoolType -import org.partiql.types.ClobType -import org.partiql.types.DateType -import org.partiql.types.DecimalType -import org.partiql.types.FloatType -import org.partiql.types.GraphType -import org.partiql.types.IntType -import org.partiql.types.ListType -import org.partiql.types.MissingType -import org.partiql.types.NullType -import org.partiql.types.SexpType -import org.partiql.types.StaticType -import org.partiql.types.StringType -import org.partiql.types.StructType -import org.partiql.types.SymbolType -import org.partiql.types.TimeType -import org.partiql.types.TimestampType - -// Use some generated serde eventually - -public inline fun StructElement.getAngry(name: String): T { - val f = getOptional(name) ?: error("Expected field `$name`") - if (f !is T) { - error("Expected field `name` to be of type ${T::class.simpleName}") - } - return f -} - -/** - * Parses an IonElement to a StaticType. - * - * The format used is effectively Avro JSON, but with PartiQL type names. - */ -public fun IonElement.toStaticType(): StaticType { - return when (this) { - is StringElement -> this.toStaticType() - is ListElement -> this.toStaticType() - is StructElement -> this.toStaticType() - else -> error("Invalid element, expected string, list, or struct") - } -} - -// Atomic type -public fun StringElement.toStaticType(): StaticType = when (textValue) { - "any" -> StaticType.ANY - "bool" -> StaticType.BOOL - "int8" -> error("`int8` is currently not supported") - "int16" -> StaticType.INT2 - "int32" -> StaticType.INT4 - "int64" -> StaticType.INT8 - "int" -> StaticType.INT - "decimal" -> StaticType.DECIMAL - "float32" -> StaticType.FLOAT - "float64" -> StaticType.FLOAT - "char" -> StaticType.CHAR - "string" -> StaticType.STRING - "symbol" -> StaticType.SYMBOL - "binary" -> error("`binary` is currently not supported") - "byte" -> error("`byte` is currently not supported") - "blob" -> StaticType.BLOB - "clob" -> StaticType.CLOB - "date" -> StaticType.DATE - "time" -> StaticType.TIME - "timestamp" -> StaticType.TIMESTAMP - "interval" -> error("`interval` is currently not supported") - "bag" -> error("`bag` is not an atomic type") - "list" -> error("`list` is not an atomic type") - "sexp" -> error("`sexp` is not an atomic type") - "struct" -> error("`struct` is not an atomic type") - "null" -> StaticType.NULL - "missing" -> StaticType.MISSING - else -> error("Invalid type `$textValue`") -} - -// Union type -public fun ListElement.toStaticType(): StaticType { - val types = values.map { it.toStaticType() }.toSet() - return StaticType.unionOf(types) -} - -// Complex type -public fun StructElement.toStaticType(): StaticType { - val type = getAngry("type").textValue - return when (type) { - "bag" -> toBagType() - "list" -> toListType() - "sexp" -> toSexpType() - "struct" -> toStructType() - else -> error("Unknown complex type $type") - } -} - -public fun StructElement.toBagType(): StaticType { - val items = getAngry("items").toStaticType() - return BagType(items) -} - -public fun StructElement.toListType(): StaticType { - val items = getAngry("items").toStaticType() - return ListType(items) -} - -public fun StructElement.toSexpType(): StaticType { - val items = getAngry("items").toStaticType() - return SexpType(items) -} - -public fun StructElement.toStructType(): StaticType { - val fieldsE = getAngry("fields") - val fields = fieldsE.values.map { - assert(it is StructElement) { "field definition must be as struct" } - it as StructElement - val name = it.getAngry("name").textValue - val type = it.getAngry("type").toStaticType() - StructType.Field(name, type) - } - return StructType(fields) -} - -public fun StaticType.toIon(): IonElement = when (this) { - is AnyOfType -> this.toIon() - is AnyType -> ionString("any") - is BlobType -> ionString("blob") - is BoolType -> ionString("bool") - is ClobType -> ionString("clob") - is BagType -> this.toIon() - is ListType -> this.toIon() - is SexpType -> this.toIon() - is DateType -> ionString("date") - is DecimalType -> ionString("decimal") - is FloatType -> ionString("float64") - is GraphType -> ionString("graph") - is IntType -> when (this.rangeConstraint) { - IntType.IntRangeConstraint.SHORT -> ionString("int16") - IntType.IntRangeConstraint.INT4 -> ionString("int32") - IntType.IntRangeConstraint.LONG -> ionString("int64") - IntType.IntRangeConstraint.UNCONSTRAINED -> ionString("int") - } - MissingType -> ionString("missing") - is NullType -> ionString("null") - is StringType -> ionString("string") // TODO char - is StructType -> this.toIon() - is SymbolType -> ionString("symbol") - is TimeType -> ionString("time") - is TimestampType -> ionString("timestamp") -} - -private fun AnyOfType.toIon(): IonElement { - // create some predictable ordering - val sorted = this.types.sortedWith { t1, t2 -> t1::class.java.simpleName.compareTo(t2::class.java.simpleName) } - val elements = sorted.map { it.toIon() } - return ionListOf(elements) -} - -private fun BagType.toIon(): IonElement = ionStructOf( - "type" to ionString("bag"), - "items" to elementType.toIon() -) - -private fun ListType.toIon(): IonElement = ionStructOf( - "type" to ionString("list"), - "items" to elementType.toIon() -) - -private fun SexpType.toIon(): IonElement = ionStructOf( - "type" to ionString("sexp"), - "items" to elementType.toIon() -) - -private fun StructType.toIon(): IonElement { - val fieldTypes = this.fields.map { - ionStructOf( - "name" to ionString(it.key), - "type" to it.value.toIon(), - ) - } - return ionStructOf( - "type" to ionString("struct"), - "fields" to ionListOf(fieldTypes) - ) -} diff --git a/partiql-planner/src/testFixtures/kotlin/org/partiql/planner/test/PartiQLTestCase.kt b/partiql-planner/src/testFixtures/kotlin/org/partiql/planner/test/PartiQLTestCase.kt new file mode 100644 index 0000000000..83bae26ae4 --- /dev/null +++ b/partiql-planner/src/testFixtures/kotlin/org/partiql/planner/test/PartiQLTestCase.kt @@ -0,0 +1,17 @@ +package org.partiql.planner.test + +/** + * Simple class to hold a test; for example, + * + * --#[example-test] + * SELECT * FROM example; + * + * PlannerTest( + * name = "example-test", + * statement = "SELECT * FROM example", + * ) + */ +public data class PartiQLTestCase( + public val id: String, + public val statement: String, +) diff --git a/partiql-planner/src/testFixtures/kotlin/org/partiql/planner/test/PartiQLTestGroup.kt b/partiql-planner/src/testFixtures/kotlin/org/partiql/planner/test/PartiQLTestGroup.kt new file mode 100644 index 0000000000..b273cdab08 --- /dev/null +++ b/partiql-planner/src/testFixtures/kotlin/org/partiql/planner/test/PartiQLTestGroup.kt @@ -0,0 +1,47 @@ +package org.partiql.planner.test + +import java.io.File + +public class PartiQLTestGroup( + public val name: String, + public val inputs: List, +) { + + companion object { + + public fun load(dir: File): PartiQLTestGroup { + val tests = dir.listFiles()!!.flatMap { loadAllTests(it) } + return PartiQLTestGroup(dir.name, tests) + } + + public fun loadAllTests(file: File): List { + val tests = mutableListOf() + var name = "" + val statement = StringBuilder() + for (line in file.readLines()) { + + // start of test + if (line.startsWith("--#[") and line.endsWith("]")) { + name = line.substring(4, line.length - 1) + statement.clear() + } + + if (name.isNotEmpty() && line.isNotBlank()) { + // accumulating test statement + statement.appendLine(line) + } else { + // skip these lines + continue + } + + // Finish & Reset + if (line.endsWith(";")) { + tests.add(PartiQLTestCase(name, statement.toString())) + name = "" + statement.clear() + } + } + return tests + } + } +} diff --git a/partiql-planner/src/testFixtures/kotlin/org/partiql/planner/test/PartiQLTestProvider.kt b/partiql-planner/src/testFixtures/kotlin/org/partiql/planner/test/PartiQLTestProvider.kt new file mode 100644 index 0000000000..627491db95 --- /dev/null +++ b/partiql-planner/src/testFixtures/kotlin/org/partiql/planner/test/PartiQLTestProvider.kt @@ -0,0 +1,37 @@ +package org.partiql.planner.test + +import java.nio.file.Path +import java.util.stream.Stream +import kotlin.io.path.toPath + +class PartiQLTestProvider(root: Path? = null) { + + private val groups: List + + init { + val default = PartiQLTestCase::class.java.getResource("/inputs")!!.toURI().toPath() + val inputsDir = (root ?: default).toFile() + groups = inputsDir.listFiles { f -> f.isDirectory }!!.map { PartiQLTestGroup.load(it) } + } + + /** + * Return test inputs associated by groups. + */ + public fun groups(): Stream { + return groups.stream() + } + + /** + * Return test inputs associated by test key __. + */ + public fun inputs(): Map { + val map = mutableMapOf() + for (group in groups) { + for (test in group.inputs) { + val key = "${group.name}__${test.id}" + map[key] = test + } + } + return map + } +} diff --git a/partiql-planner/src/testFixtures/kotlin/org/partiql/planner/test/PlannerTest.kt b/partiql-planner/src/testFixtures/kotlin/org/partiql/planner/test/PlannerTest.kt deleted file mode 100644 index debd1cb9c5..0000000000 --- a/partiql-planner/src/testFixtures/kotlin/org/partiql/planner/test/PlannerTest.kt +++ /dev/null @@ -1,28 +0,0 @@ -package org.partiql.planner.test - -import com.amazon.ionelement.api.IonElement -import com.amazon.ionelement.api.StringElement -import com.amazon.ionelement.api.StructElement -import org.partiql.types.StaticType - -/** - * TODO replace or improve [StaticType]. - */ -public class PlannerTest( - public val statement: String, - public val schema: StaticType, -) { - - companion object { - - fun load(ion: StructElement): PlannerTest { - // Load - val statementE = ion.getAngry("statement") - val schemaE = ion.getAngry("schema") - // Parse - val statement = statementE.textValue - val schema = schemaE.toStaticType() - return PlannerTest(statement, schema) - } - } -} diff --git a/partiql-planner/src/testFixtures/kotlin/org/partiql/planner/test/PlannerTestLog.kt b/partiql-planner/src/testFixtures/kotlin/org/partiql/planner/test/PlannerTestLog.kt deleted file mode 100644 index b4a471f0f8..0000000000 --- a/partiql-planner/src/testFixtures/kotlin/org/partiql/planner/test/PlannerTestLog.kt +++ /dev/null @@ -1,28 +0,0 @@ -package org.partiql.planner.test - -import java.io.PrintStream -import java.time.OffsetDateTime -import java.time.format.DateTimeFormatter - -/** - * Simple enough; raise an interface later. - * - * Consider formatting/color, DRY-ing this out, using an actual lib... - */ -public class PlannerTestLog(val out: PrintStream) { - - fun debug(message: String) { - val time = OffsetDateTime.now().format(DateTimeFormatter.ISO_LOCAL_TIME) - out.appendLine("DEBUG $time: $message") - } - - fun info(message: String) { - val time = OffsetDateTime.now().format(DateTimeFormatter.ISO_LOCAL_TIME) - out.appendLine("INFO $time: $message") - } - - fun error(message: String) { - val time = OffsetDateTime.now().format(DateTimeFormatter.ISO_LOCAL_TIME) - out.appendLine("ERROR $time: $message") - } -} diff --git a/partiql-planner/src/testFixtures/kotlin/org/partiql/planner/test/PlannerTestProvider.kt b/partiql-planner/src/testFixtures/kotlin/org/partiql/planner/test/PlannerTestProvider.kt deleted file mode 100644 index 6057fdb2e5..0000000000 --- a/partiql-planner/src/testFixtures/kotlin/org/partiql/planner/test/PlannerTestProvider.kt +++ /dev/null @@ -1,28 +0,0 @@ -package org.partiql.planner.test - -import com.amazon.ionelement.api.StructElement -import com.amazon.ionelement.api.loadSingleElement -import java.nio.file.Path -import java.util.stream.Stream -import kotlin.io.path.toPath - -class PlannerTestProvider(root: Path? = null) { - - private val suites: List - - init { - val default = PlannerTest::class.java.getResource("/tests")!!.toURI().toPath() - val testDir = (root ?: default).toFile() - val testFiles = testDir.listFiles()!! - suites = testFiles.map { - val text = it.readText() - val ion = loadSingleElement(text) - assert(ion is StructElement) { "Test suite file must be a single struct" } - PlannerTestSuite.load(ion as StructElement) - } - } - - public fun suites(): Stream { - return suites.stream() - } -} diff --git a/partiql-planner/src/testFixtures/kotlin/org/partiql/planner/test/PlannerTestSession.kt b/partiql-planner/src/testFixtures/kotlin/org/partiql/planner/test/PlannerTestSession.kt deleted file mode 100644 index 3137f41c26..0000000000 --- a/partiql-planner/src/testFixtures/kotlin/org/partiql/planner/test/PlannerTestSession.kt +++ /dev/null @@ -1,37 +0,0 @@ -package org.partiql.planner.test - -import com.amazon.ionelement.api.ListElement -import com.amazon.ionelement.api.StringElement -import com.amazon.ionelement.api.StructElement -import com.amazon.ionelement.api.TextElement - -/** - * PartiQL session information to be used across multiple tests. - * - * @property catalog Session catalog - * @property path Session search path - * @property vars Session variables - */ -public class PlannerTestSession( - public val catalog: String, - public val path: List, - public val vars: Map, -) { - - companion object { - - public fun load(ion: StructElement): PlannerTestSession { - // Load - val catalogE = ion.getAngry("catalog") - val pathE = ion.getAngry("path") - val varsE = ion.getAngry("vars") - // Parse - val catalog = catalogE.textValue - val path = pathE.values.map { (it as TextElement).textValue } - val vars = varsE.fields.associate { - it.name to (it.value as StringElement).textValue - } - return PlannerTestSession(catalog, path, vars) - } - } -} diff --git a/partiql-planner/src/testFixtures/kotlin/org/partiql/planner/test/PlannerTestSuite.kt b/partiql-planner/src/testFixtures/kotlin/org/partiql/planner/test/PlannerTestSuite.kt deleted file mode 100644 index dca64d7939..0000000000 --- a/partiql-planner/src/testFixtures/kotlin/org/partiql/planner/test/PlannerTestSuite.kt +++ /dev/null @@ -1,37 +0,0 @@ -package org.partiql.planner.test - -import com.amazon.ionelement.api.StringElement -import com.amazon.ionelement.api.StructElement - -/** - * Test names are the map key. - */ -private typealias PlannerTests = Map - -public class PlannerTestSuite( - public val name: String, - public val session: PlannerTestSession, - public val tests: PlannerTests, -) { - - companion object { - - /** - * Eventually replace with something more robust. - */ - public fun load(ion: StructElement): PlannerTestSuite { - // Load - val nameE = ion.getAngry("name") - val sessE = ion.getAngry("session") - val testsE = ion.getAngry("tests") - // Parse - val name = nameE.textValue - val session = PlannerTestSession.load(sessE) - val tests = testsE.fields.associate { - assert(it.value is StructElement) { "Test value must be an Ion struct" } - it.name to PlannerTest.load(it.value as StructElement) - } - return PlannerTestSuite(name, session, tests) - } - } -} diff --git a/partiql-planner/src/testFixtures/kotlin/org/partiql/planner/test/PlannerTestTarget.kt b/partiql-planner/src/testFixtures/kotlin/org/partiql/planner/test/PlannerTestTarget.kt deleted file mode 100644 index fd37db2e12..0000000000 --- a/partiql-planner/src/testFixtures/kotlin/org/partiql/planner/test/PlannerTestTarget.kt +++ /dev/null @@ -1,14 +0,0 @@ -package org.partiql.planner.test - -public abstract class PlannerTestTarget( - public val name: String, - public val suite: String, -) { - - /** - * Perform target-specific assertion. - * - * @param test - */ - public abstract fun assert(test: PlannerTest) -} diff --git a/partiql-planner/src/testFixtures/resources/README.adoc b/partiql-planner/src/testFixtures/resources/README.adoc new file mode 100644 index 0000000000..49ff686caa --- /dev/null +++ b/partiql-planner/src/testFixtures/resources/README.adoc @@ -0,0 +1,139 @@ += PartiQL Test Input Queries +:toc: + +This package contains many input queries to be used in various parts of testing — parsing, planning, transpiling, evaluation. + +== Structure + +Query inputs are grouped by some general category which makes up a "test group". There are many opportunities to add more structure, but the premise +is to simply have a list of input queries, each of which has a unique identifier which is the group name along with a +special pragma comment (ex: `--#[my-test-name]`) above the statement. File names don't matter, only a suite directory +name is used. All statements within a group a treated as one big list regardless of file structure. You may choose +to group multiple short statements in one file, or split each query into its own file. + +NOTE: I have not modified the generated TPC-DS schemas so everything is NULLABLE which isn't always the case. See +https://www.tpc.org/tpc_documents_current_versions/pdf/tpc-ds_v2.6.0.pdf + + +== Schemas + +Catalog and schema definition subject to change once PartiQL Value Schema is actually defined. The current version +is an iteration of John's initial work on the local plugin and Avro IDL. I'm finding it verbose which can make things +harder to read. Then again this is a plugin used for testing, so the input schema doesn't matter that much so long as +we can easily parse it. + +.Scalar Types +[source,ion] +---- +// absent +null +missing + +// boolean +bool + +// numeric +int8 +int16 +int32 +int64 +int +decimal +(decimal p s) +float32 +float64 + +// char strings +(char n) +string +(string n) + +// bit strings +(bit n) +binary +(binary n) + +// byte strings +(byte n) +blob +blob(n) + +// date/time types +date +time +(time p) +(time p z) +timestamp +(timestamp p) +(timestamp p z) +(interval p) +---- + +.Collection Types +[source,ion] +---- +bag::[type] // ex: bag::[int] +list::[type] +sexp::[type] +---- + +.Struct Type +[source,ion] +---- +{ f_1: t_1, ..., f_n, t_n } + +open::{ ... } +closed::{ ... } + +// Examples +{ a: int, b: string } + +bag::[ + closed::{ + x: int32, + y: int32, + } +] +---- + +.Union Types +[source,ion] +---- +(t1 | t2 | ... ) + +// Examples +(int32 | null) +---- + +You can place a list of constraints on a type by wrapping in an outer constraint container. + +.Constraints +[source,sql] +---- +CREATE TABLE foo ( + location STRING PRIMARY KEY + x INT + y INT +); +---- + +[source,ion] +---- +bag::[ + { + location: string, + x: int32, + y: int32, + }, + _::( + (primary_key location) + ) +] + +(define my_num + (int _::( + (min 1) + (max 1) + )) +) +---- diff --git a/partiql-planner/src/testFixtures/resources/catalogs/default/db/aws/b/b.ion b/partiql-planner/src/testFixtures/resources/catalogs/default/db/aws/b/b.ion new file mode 100644 index 0000000000..c6ac007345 --- /dev/null +++ b/partiql-planner/src/testFixtures/resources/catalogs/default/db/aws/b/b.ion @@ -0,0 +1,13 @@ +{ + type: "bag", + items: { + type: "struct", + constraints: [ closed, unique, ordered ], + fields: [ + { + name: "identifier", + type: "int", + } + ] + } +} diff --git a/partiql-planner/src/testFixtures/resources/catalogs/default/db/aws/ddb/b.ion b/partiql-planner/src/testFixtures/resources/catalogs/default/db/aws/ddb/b.ion new file mode 100644 index 0000000000..1ea09e58c9 --- /dev/null +++ b/partiql-planner/src/testFixtures/resources/catalogs/default/db/aws/ddb/b.ion @@ -0,0 +1,13 @@ +{ + type: "bag", + items: { + type: "struct", + constraints: [ closed, unique, ordered ], + fields: [ + { + name: "identifier", + type: "string", + } + ] + } +} diff --git a/partiql-planner/src/testFixtures/resources/catalogs/default/db/aws/ddb/pets.ion b/partiql-planner/src/testFixtures/resources/catalogs/default/db/aws/ddb/pets.ion new file mode 100644 index 0000000000..14f1c1f5e4 --- /dev/null +++ b/partiql-planner/src/testFixtures/resources/catalogs/default/db/aws/ddb/pets.ion @@ -0,0 +1,17 @@ +{ + type: "bag", + items: { + type: "struct", + constraints: [ closed, unique, ordered ], + fields: [ + { + name: "id", + type: "int", + }, + { + name: "breed", + type: "string", + } + ] + } +} diff --git a/partiql-planner/src/testFixtures/resources/catalogs/default/db/b/b/b.ion b/partiql-planner/src/testFixtures/resources/catalogs/default/db/b/b/b.ion new file mode 100644 index 0000000000..8508d37b63 --- /dev/null +++ b/partiql-planner/src/testFixtures/resources/catalogs/default/db/b/b/b.ion @@ -0,0 +1,23 @@ +{ + type: "struct", + constraints: [ closed, unique, ordered ], + fields: [ + { + name: "b", + type: { + type: "struct", + constraints: [ closed, unique, ordered ], + fields: [ + { + name: "b", + type: "int", + } + ] + } + }, + { + name: "c", + type: "int", + } + ] +} diff --git a/partiql-planner/src/testFixtures/resources/catalogs/default/db/b/b/c.ion b/partiql-planner/src/testFixtures/resources/catalogs/default/db/b/b/c.ion new file mode 100644 index 0000000000..a21274f547 --- /dev/null +++ b/partiql-planner/src/testFixtures/resources/catalogs/default/db/b/b/c.ion @@ -0,0 +1 @@ +"int" diff --git a/partiql-planner/src/testFixtures/resources/catalogs/default/db/b/b/d.ion b/partiql-planner/src/testFixtures/resources/catalogs/default/db/b/b/d.ion new file mode 100644 index 0000000000..c01b78f407 --- /dev/null +++ b/partiql-planner/src/testFixtures/resources/catalogs/default/db/b/b/d.ion @@ -0,0 +1,22 @@ +{ + type: "struct", + constraints: [ ordered ], + fields: [ + { + name: "e", + type: "int", + }, + { + name: "e", + type: { + type: "struct", + fields: [ + { + name: "f", + type: "int", + } + ] + } + } + ] +} diff --git a/partiql-planner/src/testFixtures/resources/catalogs/default/db/b/c/c.ion b/partiql-planner/src/testFixtures/resources/catalogs/default/db/b/c/c.ion new file mode 100644 index 0000000000..fcde59dd6f --- /dev/null +++ b/partiql-planner/src/testFixtures/resources/catalogs/default/db/b/c/c.ion @@ -0,0 +1 @@ +"decimal" diff --git a/partiql-planner/src/testFixtures/resources/catalogs/default/db/markets/order_info.ion b/partiql-planner/src/testFixtures/resources/catalogs/default/db/markets/order_info.ion new file mode 100644 index 0000000000..52fed9c74b --- /dev/null +++ b/partiql-planner/src/testFixtures/resources/catalogs/default/db/markets/order_info.ion @@ -0,0 +1,19 @@ +{ + name: "order_info", + constraints: [ closed, unique, ordered ], + type: "struct", + fields: [ + { + name: "customer_id", + type: "int", + }, + { + name: "marketplace_id", + type: "int", + }, + { + name: "ship_option", + type: "string", + } + ] +} \ No newline at end of file diff --git a/partiql-planner/src/testFixtures/resources/catalogs/default/db/markets/orders.ion b/partiql-planner/src/testFixtures/resources/catalogs/default/db/markets/orders.ion new file mode 100644 index 0000000000..f42abdb9cf --- /dev/null +++ b/partiql-planner/src/testFixtures/resources/catalogs/default/db/markets/orders.ion @@ -0,0 +1,21 @@ +{ + type: "bag", + items: { + type: "struct", + constraints: [ closed, unique, ordered ], + fields: [ + { + name: "customer_id", + type: "int", + }, + { + name: "marketplace_id", + type: "int", + }, + { + name: "ship_option", + type: "string", + } + ] + } +} diff --git a/partiql-planner/src/testFixtures/resources/catalogs/default/tpc_ds/call_center.ion b/partiql-planner/src/testFixtures/resources/catalogs/tpc_ds/call_center.ion similarity index 100% rename from partiql-planner/src/testFixtures/resources/catalogs/default/tpc_ds/call_center.ion rename to partiql-planner/src/testFixtures/resources/catalogs/tpc_ds/call_center.ion diff --git a/partiql-planner/src/testFixtures/resources/catalogs/default/tpc_ds/catalog_page.ion b/partiql-planner/src/testFixtures/resources/catalogs/tpc_ds/catalog_page.ion similarity index 100% rename from partiql-planner/src/testFixtures/resources/catalogs/default/tpc_ds/catalog_page.ion rename to partiql-planner/src/testFixtures/resources/catalogs/tpc_ds/catalog_page.ion diff --git a/partiql-planner/src/testFixtures/resources/catalogs/default/tpc_ds/catalog_returns.ion b/partiql-planner/src/testFixtures/resources/catalogs/tpc_ds/catalog_returns.ion similarity index 100% rename from partiql-planner/src/testFixtures/resources/catalogs/default/tpc_ds/catalog_returns.ion rename to partiql-planner/src/testFixtures/resources/catalogs/tpc_ds/catalog_returns.ion diff --git a/partiql-planner/src/testFixtures/resources/catalogs/default/tpc_ds/catalog_sales.ion b/partiql-planner/src/testFixtures/resources/catalogs/tpc_ds/catalog_sales.ion similarity index 100% rename from partiql-planner/src/testFixtures/resources/catalogs/default/tpc_ds/catalog_sales.ion rename to partiql-planner/src/testFixtures/resources/catalogs/tpc_ds/catalog_sales.ion diff --git a/partiql-planner/src/testFixtures/resources/catalogs/default/tpc_ds/customer.ion b/partiql-planner/src/testFixtures/resources/catalogs/tpc_ds/customer.ion similarity index 100% rename from partiql-planner/src/testFixtures/resources/catalogs/default/tpc_ds/customer.ion rename to partiql-planner/src/testFixtures/resources/catalogs/tpc_ds/customer.ion diff --git a/partiql-planner/src/testFixtures/resources/catalogs/default/tpc_ds/customer_address.ion b/partiql-planner/src/testFixtures/resources/catalogs/tpc_ds/customer_address.ion similarity index 100% rename from partiql-planner/src/testFixtures/resources/catalogs/default/tpc_ds/customer_address.ion rename to partiql-planner/src/testFixtures/resources/catalogs/tpc_ds/customer_address.ion diff --git a/partiql-planner/src/testFixtures/resources/catalogs/default/tpc_ds/customer_demographics.ion b/partiql-planner/src/testFixtures/resources/catalogs/tpc_ds/customer_demographics.ion similarity index 100% rename from partiql-planner/src/testFixtures/resources/catalogs/default/tpc_ds/customer_demographics.ion rename to partiql-planner/src/testFixtures/resources/catalogs/tpc_ds/customer_demographics.ion diff --git a/partiql-planner/src/testFixtures/resources/catalogs/default/tpc_ds/date_dim.ion b/partiql-planner/src/testFixtures/resources/catalogs/tpc_ds/date_dim.ion similarity index 100% rename from partiql-planner/src/testFixtures/resources/catalogs/default/tpc_ds/date_dim.ion rename to partiql-planner/src/testFixtures/resources/catalogs/tpc_ds/date_dim.ion diff --git a/partiql-planner/src/testFixtures/resources/catalogs/default/tpc_ds/dbgen_version.ion b/partiql-planner/src/testFixtures/resources/catalogs/tpc_ds/dbgen_version.ion similarity index 100% rename from partiql-planner/src/testFixtures/resources/catalogs/default/tpc_ds/dbgen_version.ion rename to partiql-planner/src/testFixtures/resources/catalogs/tpc_ds/dbgen_version.ion diff --git a/partiql-planner/src/testFixtures/resources/catalogs/default/tpc_ds/household_demographics.ion b/partiql-planner/src/testFixtures/resources/catalogs/tpc_ds/household_demographics.ion similarity index 100% rename from partiql-planner/src/testFixtures/resources/catalogs/default/tpc_ds/household_demographics.ion rename to partiql-planner/src/testFixtures/resources/catalogs/tpc_ds/household_demographics.ion diff --git a/partiql-planner/src/testFixtures/resources/catalogs/default/tpc_ds/income_band.ion b/partiql-planner/src/testFixtures/resources/catalogs/tpc_ds/income_band.ion similarity index 100% rename from partiql-planner/src/testFixtures/resources/catalogs/default/tpc_ds/income_band.ion rename to partiql-planner/src/testFixtures/resources/catalogs/tpc_ds/income_band.ion diff --git a/partiql-planner/src/testFixtures/resources/catalogs/default/tpc_ds/inventory.ion b/partiql-planner/src/testFixtures/resources/catalogs/tpc_ds/inventory.ion similarity index 100% rename from partiql-planner/src/testFixtures/resources/catalogs/default/tpc_ds/inventory.ion rename to partiql-planner/src/testFixtures/resources/catalogs/tpc_ds/inventory.ion diff --git a/partiql-planner/src/testFixtures/resources/catalogs/default/tpc_ds/item.ion b/partiql-planner/src/testFixtures/resources/catalogs/tpc_ds/item.ion similarity index 100% rename from partiql-planner/src/testFixtures/resources/catalogs/default/tpc_ds/item.ion rename to partiql-planner/src/testFixtures/resources/catalogs/tpc_ds/item.ion diff --git a/partiql-planner/src/testFixtures/resources/catalogs/default/tpc_ds/promotion.ion b/partiql-planner/src/testFixtures/resources/catalogs/tpc_ds/promotion.ion similarity index 100% rename from partiql-planner/src/testFixtures/resources/catalogs/default/tpc_ds/promotion.ion rename to partiql-planner/src/testFixtures/resources/catalogs/tpc_ds/promotion.ion diff --git a/partiql-planner/src/testFixtures/resources/catalogs/default/tpc_ds/reason.ion b/partiql-planner/src/testFixtures/resources/catalogs/tpc_ds/reason.ion similarity index 100% rename from partiql-planner/src/testFixtures/resources/catalogs/default/tpc_ds/reason.ion rename to partiql-planner/src/testFixtures/resources/catalogs/tpc_ds/reason.ion diff --git a/partiql-planner/src/testFixtures/resources/catalogs/default/tpc_ds/ship_mode.ion b/partiql-planner/src/testFixtures/resources/catalogs/tpc_ds/ship_mode.ion similarity index 100% rename from partiql-planner/src/testFixtures/resources/catalogs/default/tpc_ds/ship_mode.ion rename to partiql-planner/src/testFixtures/resources/catalogs/tpc_ds/ship_mode.ion diff --git a/partiql-planner/src/testFixtures/resources/catalogs/default/tpc_ds/store.ion b/partiql-planner/src/testFixtures/resources/catalogs/tpc_ds/store.ion similarity index 100% rename from partiql-planner/src/testFixtures/resources/catalogs/default/tpc_ds/store.ion rename to partiql-planner/src/testFixtures/resources/catalogs/tpc_ds/store.ion diff --git a/partiql-planner/src/testFixtures/resources/catalogs/default/tpc_ds/store_returns.ion b/partiql-planner/src/testFixtures/resources/catalogs/tpc_ds/store_returns.ion similarity index 100% rename from partiql-planner/src/testFixtures/resources/catalogs/default/tpc_ds/store_returns.ion rename to partiql-planner/src/testFixtures/resources/catalogs/tpc_ds/store_returns.ion diff --git a/partiql-planner/src/testFixtures/resources/catalogs/default/tpc_ds/store_sales.ion b/partiql-planner/src/testFixtures/resources/catalogs/tpc_ds/store_sales.ion similarity index 100% rename from partiql-planner/src/testFixtures/resources/catalogs/default/tpc_ds/store_sales.ion rename to partiql-planner/src/testFixtures/resources/catalogs/tpc_ds/store_sales.ion diff --git a/partiql-planner/src/testFixtures/resources/catalogs/default/tpc_ds/time_dim.ion b/partiql-planner/src/testFixtures/resources/catalogs/tpc_ds/time_dim.ion similarity index 100% rename from partiql-planner/src/testFixtures/resources/catalogs/default/tpc_ds/time_dim.ion rename to partiql-planner/src/testFixtures/resources/catalogs/tpc_ds/time_dim.ion diff --git a/partiql-planner/src/testFixtures/resources/catalogs/default/tpc_ds/warehouse.ion b/partiql-planner/src/testFixtures/resources/catalogs/tpc_ds/warehouse.ion similarity index 100% rename from partiql-planner/src/testFixtures/resources/catalogs/default/tpc_ds/warehouse.ion rename to partiql-planner/src/testFixtures/resources/catalogs/tpc_ds/warehouse.ion diff --git a/partiql-planner/src/testFixtures/resources/catalogs/default/tpc_ds/web_page.ion b/partiql-planner/src/testFixtures/resources/catalogs/tpc_ds/web_page.ion similarity index 100% rename from partiql-planner/src/testFixtures/resources/catalogs/default/tpc_ds/web_page.ion rename to partiql-planner/src/testFixtures/resources/catalogs/tpc_ds/web_page.ion diff --git a/partiql-planner/src/testFixtures/resources/catalogs/default/tpc_ds/web_returns.ion b/partiql-planner/src/testFixtures/resources/catalogs/tpc_ds/web_returns.ion similarity index 100% rename from partiql-planner/src/testFixtures/resources/catalogs/default/tpc_ds/web_returns.ion rename to partiql-planner/src/testFixtures/resources/catalogs/tpc_ds/web_returns.ion diff --git a/partiql-planner/src/testFixtures/resources/catalogs/default/tpc_ds/web_sales.ion b/partiql-planner/src/testFixtures/resources/catalogs/tpc_ds/web_sales.ion similarity index 100% rename from partiql-planner/src/testFixtures/resources/catalogs/default/tpc_ds/web_sales.ion rename to partiql-planner/src/testFixtures/resources/catalogs/tpc_ds/web_sales.ion diff --git a/partiql-planner/src/testFixtures/resources/catalogs/default/tpc_ds/web_site.ion b/partiql-planner/src/testFixtures/resources/catalogs/tpc_ds/web_site.ion similarity index 100% rename from partiql-planner/src/testFixtures/resources/catalogs/default/tpc_ds/web_site.ion rename to partiql-planner/src/testFixtures/resources/catalogs/tpc_ds/web_site.ion diff --git a/partiql-planner/src/testFixtures/resources/catalogs/tpc_h/.gitkeep b/partiql-planner/src/testFixtures/resources/catalogs/tpc_h/.gitkeep new file mode 100644 index 0000000000..e69de29bb2 diff --git a/partiql-planner/src/testFixtures/resources/inputs/schema_inferrencer/sanity.sql b/partiql-planner/src/testFixtures/resources/inputs/schema_inferrencer/sanity.sql new file mode 100644 index 0000000000..2e0352fafc --- /dev/null +++ b/partiql-planner/src/testFixtures/resources/inputs/schema_inferrencer/sanity.sql @@ -0,0 +1,40 @@ +--#[sanity-01] +SELECT ss_ticket_number, ss_quantity, ss_sold_date_sk +FROM store_sales; + +--#[sanity-02] +SELECT ss_ticket_number, ss_quantity, ss_sold_date_sk +FROM store_sales +WHERE ss_sold_date_sk > DATE_ADD(DAY, -30, UTCNOW()); + +--#[sanity-03] +SELECT (ss_wholesale_cost + 10 < ss_list_price) AS x +FROM store_sales; + +--#[sanity-04] +SELECT ss_quantity, -- This is a nullable int32 + CASE (ss_quantity) -- This case statement will always return a non-nullable string + WHEN 0 THEN 'Did not sell anything!' + WHEN 1 THEN 'Sold a single item!' + ELSE 'Sold multiple items!' + END AS ss_quantity_description_1, + CASE (ss_quantity) + WHEN 0 THEN 'Hello' -- sometimes STRING + WHEN 1 THEN 1.0 -- sometimes DECIMAL + WHEN 2 THEN 2 -- sometimes INT + -- There isn't an else here, so the output should be nullable as well. + END AS ss_quantity_description_2, + CASE (ss_quantity) + WHEN 0 THEN 'Hello' -- ss_quantity will be cast to an INT for comparison + WHEN 'not an int32' THEN 'not cast-able' -- cannot be cast! + ELSE 'fallback' + -- There is an ELSE here, so the output should NOT be nullable. + END AS ss_quantity_description_3 +FROM store_sales; + +--#[sanity-05] +SELECT s_store_sk +FROM tpc_ds.store AS store + LEFT JOIN + tpc_ds.store_returns AS returns + ON s_store_sk = sr_store_sk; diff --git a/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query01.sql b/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query01.sql new file mode 100644 index 0000000000..b3dd6eb5e9 --- /dev/null +++ b/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query01.sql @@ -0,0 +1,23 @@ +--#[tpc-ds-01] +WITH customer_total_return + AS (SELECT sr_customer_sk AS ctr_customer_sk, + sr_store_sk AS ctr_store_sk, + Sum(sr_return_amt) AS ctr_total_return + FROM store_returns, + date_dim + WHERE sr_returned_date_sk = d_date_sk + AND d_year = 2001 + GROUP BY sr_customer_sk, + sr_store_sk) +SELECT c_customer_id +FROM customer_total_return ctr1, + store, + customer +WHERE ctr1.ctr_total_return > (SELECT Avg(ctr_total_return) * 1.2 + FROM customer_total_return ctr2 + WHERE ctr1.ctr_store_sk = ctr2.ctr_store_sk) + AND s_store_sk = ctr1.ctr_store_sk + AND s_state = 'TN' + AND ctr1.ctr_customer_sk = c_customer_sk +ORDER BY c_customer_id +LIMIT 100; diff --git a/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query02.sql b/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query02.sql new file mode 100644 index 0000000000..65e82290ff --- /dev/null +++ b/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query02.sql @@ -0,0 +1,79 @@ +-- start query 2 in stream 0 using template query2.tpl +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 = 1998) 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 = 1998 + 1) z +WHERE d_week_seq1 = d_week_seq2 - 53 +ORDER BY d_week_seq1; diff --git a/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query03.sql b/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query03.sql new file mode 100644 index 0000000000..3b6f4f58f2 --- /dev/null +++ b/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query03.sql @@ -0,0 +1,19 @@ +-- start query 3 in stream 0 using template query3.tpl +SELECT dt.d_year, + item.i_brand_id brand_id, + item.i_brand brand, + Sum(ss_ext_discount_amt) 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 = 427 + AND dt.d_moy = 11 +GROUP BY dt.d_year, + item.i_brand, + item.i_brand_id +ORDER BY dt.d_year, + sum_agg DESC, + brand_id +LIMIT 100; diff --git a/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query04.sql b/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query04.sql new file mode 100644 index 0000000000..026a1bac9f --- /dev/null +++ b/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query04.sql @@ -0,0 +1,152 @@ +-- start query 4 in stream 0 using template query4.tpl +WITH year_total + AS (SELECT c_customer_id customer_id, + c_first_name customer_first_name, + c_last_name customer_last_name, + c_preferred_cust_flag customer_preferred_cust_flag + , + c_birth_country + customer_birth_country, + c_login customer_login, + c_email_address customer_email_address, + d_year dyear, + Sum(( ( ss_ext_list_price - ss_ext_wholesale_cost + - ss_ext_discount_amt + ) + + + ss_ext_sales_price ) / 2) year_total, + 's' sale_type + FROM customer, + store_sales, + date_dim + WHERE c_customer_sk = ss_customer_sk + AND ss_sold_date_sk = d_date_sk + GROUP BY c_customer_id, + c_first_name, + c_last_name, + c_preferred_cust_flag, + c_birth_country, + c_login, + c_email_address, + d_year + UNION ALL + SELECT c_customer_id customer_id, + c_first_name customer_first_name, + c_last_name customer_last_name, + c_preferred_cust_flag + customer_preferred_cust_flag, + c_birth_country customer_birth_country + , + c_login + customer_login, + c_email_address customer_email_address + , + d_year dyear + , + Sum(( ( ( cs_ext_list_price + - cs_ext_wholesale_cost + - cs_ext_discount_amt + ) + + cs_ext_sales_price ) / 2 )) year_total, + 'c' sale_type + FROM customer, + catalog_sales, + date_dim + WHERE c_customer_sk = cs_bill_customer_sk + AND cs_sold_date_sk = d_date_sk + GROUP BY c_customer_id, + c_first_name, + c_last_name, + c_preferred_cust_flag, + c_birth_country, + c_login, + c_email_address, + d_year + UNION ALL + SELECT c_customer_id customer_id, + c_first_name customer_first_name, + c_last_name customer_last_name, + c_preferred_cust_flag + customer_preferred_cust_flag, + c_birth_country customer_birth_country + , + c_login + customer_login, + c_email_address customer_email_address + , + d_year dyear + , + Sum(( ( ( ws_ext_list_price + - ws_ext_wholesale_cost + - ws_ext_discount_amt + ) + + ws_ext_sales_price ) / 2 )) year_total, + 'w' sale_type + FROM customer, + web_sales, + date_dim + WHERE c_customer_sk = ws_bill_customer_sk + AND ws_sold_date_sk = d_date_sk + GROUP BY c_customer_id, + c_first_name, + c_last_name, + c_preferred_cust_flag, + c_birth_country, + c_login, + c_email_address, + d_year) +SELECT t_s_secyear.customer_id, + t_s_secyear.customer_first_name, + t_s_secyear.customer_last_name, + t_s_secyear.customer_preferred_cust_flag +FROM year_total t_s_firstyear, + year_total t_s_secyear, + year_total t_c_firstyear, + year_total t_c_secyear, + year_total t_w_firstyear, + year_total t_w_secyear +WHERE t_s_secyear.customer_id = t_s_firstyear.customer_id + AND t_s_firstyear.customer_id = t_c_secyear.customer_id + AND t_s_firstyear.customer_id = t_c_firstyear.customer_id + AND t_s_firstyear.customer_id = t_w_firstyear.customer_id + AND t_s_firstyear.customer_id = t_w_secyear.customer_id + AND t_s_firstyear.sale_type = 's' + AND t_c_firstyear.sale_type = 'c' + AND t_w_firstyear.sale_type = 'w' + AND t_s_secyear.sale_type = 's' + AND t_c_secyear.sale_type = 'c' + AND t_w_secyear.sale_type = 'w' + AND t_s_firstyear.dyear = 2001 + AND t_s_secyear.dyear = 2001 + 1 + AND t_c_firstyear.dyear = 2001 + AND t_c_secyear.dyear = 2001 + 1 + AND t_w_firstyear.dyear = 2001 + AND t_w_secyear.dyear = 2001 + 1 + AND t_s_firstyear.year_total > 0 + AND t_c_firstyear.year_total > 0 + AND t_w_firstyear.year_total > 0 + AND CASE + WHEN t_c_firstyear.year_total > 0 THEN t_c_secyear.year_total / + t_c_firstyear.year_total + ELSE NULL + END > CASE + WHEN t_s_firstyear.year_total > 0 THEN + t_s_secyear.year_total / + t_s_firstyear.year_total + ELSE NULL + END + AND CASE + WHEN t_c_firstyear.year_total > 0 THEN t_c_secyear.year_total / + t_c_firstyear.year_total + ELSE NULL + END > CASE + WHEN t_w_firstyear.year_total > 0 THEN + t_w_secyear.year_total / + t_w_firstyear.year_total + ELSE NULL + END +ORDER BY t_s_secyear.customer_id, + t_s_secyear.customer_first_name, + t_s_secyear.customer_last_name, + t_s_secyear.customer_preferred_cust_flag +LIMIT 100; diff --git a/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query05.sql b/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query05.sql new file mode 100644 index 0000000000..0823a55072 --- /dev/null +++ b/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query05.sql @@ -0,0 +1,128 @@ +-- start query 5 in stream 0 using template query5.tpl +WITH ssr AS +( + SELECT s_store_id, + Sum(sales_price) AS sales, + Sum(profit) AS profit, + Sum(return_amt) AS returns1, + Sum(net_loss) AS profit_loss + FROM ( + SELECT ss_store_sk AS store_sk, + ss_sold_date_sk AS date_sk, + ss_ext_sales_price AS sales_price, + ss_net_profit AS profit, + Cast(0 AS DECIMAL(7,2)) AS return_amt, + Cast(0 AS DECIMAL(7,2)) AS net_loss + FROM store_sales + UNION ALL + SELECT sr_store_sk AS store_sk, + sr_returned_date_sk AS date_sk, + Cast(0 AS DECIMAL(7,2)) AS sales_price, + Cast(0 AS DECIMAL(7,2)) AS profit, + sr_return_amt AS return_amt, + sr_net_loss AS net_loss + FROM store_returns ) salesreturns, + date_dim, + store + WHERE date_sk = d_date_sk + AND d_date BETWEEN Cast('2002-08-22' AS DATE) AND ( + Cast('2002-08-22' AS DATE) + INTERVAL '14' day) + AND store_sk = s_store_sk + GROUP BY s_store_id) , csr AS +( + SELECT cp_catalog_page_id, + sum(sales_price) AS sales, + sum(profit) AS profit, + sum(return_amt) AS returns1, + sum(net_loss) AS profit_loss + FROM ( + SELECT cs_catalog_page_sk AS page_sk, + cs_sold_date_sk AS date_sk, + cs_ext_sales_price AS sales_price, + cs_net_profit AS profit, + cast(0 AS decimal(7,2)) AS return_amt, + cast(0 AS decimal(7,2)) AS net_loss + FROM catalog_sales + UNION ALL + SELECT cr_catalog_page_sk AS page_sk, + cr_returned_date_sk AS date_sk, + cast(0 AS decimal(7,2)) AS sales_price, + cast(0 AS decimal(7,2)) AS profit, + cr_return_amount AS return_amt, + cr_net_loss AS net_loss + FROM catalog_returns ) salesreturns, + date_dim, + catalog_page + WHERE date_sk = d_date_sk + AND d_date BETWEEN cast('2002-08-22' AS date) AND ( + cast('2002-08-22' AS date) + INTERVAL '14' day) + AND page_sk = cp_catalog_page_sk + GROUP BY cp_catalog_page_id) , wsr AS +( + SELECT web_site_id, + sum(sales_price) AS sales, + sum(profit) AS profit, + sum(return_amt) AS returns1, + sum(net_loss) AS profit_loss + FROM ( + SELECT ws_web_site_sk AS wsr_web_site_sk, + ws_sold_date_sk AS date_sk, + ws_ext_sales_price AS sales_price, + ws_net_profit AS profit, + cast(0 AS decimal(7,2)) AS return_amt, + cast(0 AS decimal(7,2)) AS net_loss + FROM web_sales + UNION ALL + SELECT ws_web_site_sk AS wsr_web_site_sk, + wr_returned_date_sk AS date_sk, + cast(0 AS decimal(7,2)) AS sales_price, + cast(0 AS decimal(7,2)) AS profit, + wr_return_amt AS return_amt, + wr_net_loss AS net_loss + FROM web_returns + LEFT OUTER 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('2002-08-22' AS date) AND ( + cast('2002-08-22' AS date) + INTERVAL '14' day) + AND wsr_web_site_sk = web_site_sk + GROUP BY web_site_id) +SELECT + channel , + id , + sum(sales) AS sales , + sum(returns1) AS returns1 , + sum(profit) AS profit +FROM ( + SELECT 'store channel' AS channel , + 'store' + || s_store_id AS id , + sales , + returns1 , + (profit - profit_loss) AS profit + FROM ssr + UNION ALL + SELECT 'catalog channel' AS channel , + 'catalog_page' + || cp_catalog_page_id AS id , + sales , + returns1 , + (profit - profit_loss) AS profit + FROM csr + UNION ALL + SELECT 'web channel' AS channel , + 'web_site' + || web_site_id AS id , + sales , + returns1 , + (profit - profit_loss) AS profit + FROM wsr ) x +GROUP BY rollup (channel, id) +ORDER BY channel , + id +LIMIT 100; + diff --git a/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query06.sql b/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query06.sql new file mode 100644 index 0000000000..1c53aa09f3 --- /dev/null +++ b/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query06.sql @@ -0,0 +1,23 @@ +-- start query 6 in stream 0 using template query6.tpl +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 = 1998 + AND d_moy = 7) + AND i.i_current_price > 1.2 * (SELECT Avg(j.i_current_price) + FROM item j + WHERE j.i_category = i.i_category) +GROUP BY a.ca_state +HAVING Count(*) >= 10 +ORDER BY cnt +LIMIT 100; diff --git a/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query07.sql b/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query07.sql new file mode 100644 index 0000000000..5408624f6e --- /dev/null +++ b/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query07.sql @@ -0,0 +1,24 @@ +-- start query 7 in stream 0 using template query7.tpl +SELECT i_item_id, + Avg(ss_quantity) agg1, + Avg(ss_list_price) agg2, + Avg(ss_coupon_amt) agg3, + Avg(ss_sales_price) agg4 +FROM store_sales, + customer_demographics, + date_dim, + item, + promotion +WHERE ss_sold_date_sk = d_date_sk + AND ss_item_sk = i_item_sk + AND ss_cdemo_sk = cd_demo_sk + AND ss_promo_sk = p_promo_sk + AND cd_gender = 'F' + AND cd_marital_status = 'W' + AND cd_education_status = '2 yr Degree' + AND ( p_channel_email = 'N' + OR p_channel_event = 'N' ) + AND d_year = 1998 +GROUP BY i_item_id +ORDER BY i_item_id +LIMIT 100; diff --git a/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query08.sql b/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query08.sql new file mode 100644 index 0000000000..88d2598805 --- /dev/null +++ b/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query08.sql @@ -0,0 +1,227 @@ +-- start query 8 in stream 0 using template query8.tpl +SELECT s_store_name, + Sum(ss_net_profit) +FROM store_sales, + date_dim, + store, + (SELECT ca_zip + FROM (SELECT Substr(ca_zip, 1, 5) ca_zip + FROM customer_address + WHERE Substr(ca_zip, 1, 5) IN ( '67436', '26121', '38443', + '63157', + '68856', '19485', '86425', + '26741', + '70991', '60899', '63573', + '47556', + '56193', '93314', '87827', + '62017', + '85067', '95390', '48091', + '10261', + '81845', '41790', '42853', + '24675', + '12840', '60065', '84430', + '57451', + '24021', '91735', '75335', + '71935', + '34482', '56943', '70695', + '52147', + '56251', '28411', '86653', + '23005', + '22478', '29031', '34398', + '15365', + '42460', '33337', '59433', + '73943', + '72477', '74081', '74430', + '64605', + '39006', '11226', '49057', + '97308', + '42663', '18187', '19768', + '43454', + '32147', '76637', '51975', + '11181', + '45630', '33129', '45995', + '64386', + '55522', '26697', '20963', + '35154', + '64587', '49752', '66386', + '30586', + '59286', '13177', '66646', + '84195', + '74316', '36853', '32927', + '12469', + '11904', '36269', '17724', + '55346', + '12595', '53988', '65439', + '28015', + '63268', '73590', '29216', + '82575', + '69267', '13805', '91678', + '79460', + '94152', '14961', '15419', + '48277', + '62588', '55493', '28360', + '14152', + '55225', '18007', '53705', + '56573', + '80245', '71769', '57348', + '36845', + '13039', '17270', '22363', + '83474', + '25294', '43269', '77666', + '15488', + '99146', '64441', '43338', + '38736', + '62754', '48556', '86057', + '23090', + '38114', '66061', '18910', + '84385', + '23600', '19975', '27883', + '65719', + '19933', '32085', '49731', + '40473', + '27190', '46192', '23949', + '44738', + '12436', '64794', '68741', + '15333', + '24282', '49085', '31844', + '71156', + '48441', '17100', '98207', + '44982', + '20277', '71496', '96299', + '37583', + '22206', '89174', '30589', + '61924', + '53079', '10976', '13104', + '42794', + '54772', '15809', '56434', + '39975', + '13874', '30753', '77598', + '78229', + '59478', '12345', '55547', + '57422', + '42600', '79444', '29074', + '29752', + '21676', '32096', '43044', + '39383', + '37296', '36295', '63077', + '16572', + '31275', '18701', '40197', + '48242', + '27219', '49865', '84175', + '30446', + '25165', '13807', '72142', + '70499', + '70464', '71429', '18111', + '70857', + '29545', '36425', '52706', + '36194', + '42963', '75068', '47921', + '74763', + '90990', '89456', '62073', + '88397', + '73963', '75885', '62657', + '12530', + '81146', '57434', '25099', + '41429', + '98441', '48713', '52552', + '31667', + '14072', '13903', '44709', + '85429', + '58017', '38295', '44875', + '73541', + '30091', '12707', '23762', + '62258', + '33247', '78722', '77431', + '14510', + '35656', '72428', '92082', + '35267', + '43759', '24354', '90952', + '11512', + '21242', '22579', '56114', + '32339', + '52282', '41791', '24484', + '95020', + '28408', '99710', '11899', + '43344', + '72915', '27644', '62708', + '74479', + '17177', '32619', '12351', + '91339', + '31169', '57081', '53522', + '16712', + '34419', '71779', '44187', + '46206', + '96099', '61910', '53664', + '12295', + '31837', '33096', '10813', + '63048', + '31732', '79118', '73084', + '72783', + '84952', '46965', '77956', + '39815', + '32311', '75329', '48156', + '30826', + '49661', '13736', '92076', + '74865', + '88149', '92397', '52777', + '68453', + '32012', '21222', '52721', + '24626', + '18210', '42177', '91791', + '75251', + '82075', '44372', '45542', + '20609', + '60115', '17362', '22750', + '90434', + '31852', '54071', '33762', + '14705', + '40718', '56433', '30996', + '40657', + '49056', '23585', '66455', + '41021', + '74736', '72151', '37007', + '21729', + '60177', '84558', '59027', + '93855', + '60022', '86443', '19541', + '86886', + '30532', '39062', '48532', + '34713', + '52077', '22564', '64638', + '15273', + '31677', '36138', '62367', + '60261', + '80213', '42818', '25113', + '72378', + '69802', '69096', '55443', + '28820', + '13848', '78258', '37490', + '30556', + '77380', '28447', '44550', + '26791', + '70609', '82182', '33306', + '43224', + '22322', '86959', '68519', + '14308', + '46501', '81131', '34056', + '61991', + '19896', '87804', '65774', + '92564' ) + 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 = 2000 + AND ( Substr(s_zip, 1, 2) = Substr(V1.ca_zip, 1, 2) ) +GROUP BY s_store_name +ORDER BY s_store_name +LIMIT 100; diff --git a/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query09.sql b/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query09.sql new file mode 100644 index 0000000000..729ac26ba1 --- /dev/null +++ b/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query09.sql @@ -0,0 +1,63 @@ +-- start query 9 in stream 0 using template query9.tpl +SELECT CASE + WHEN (SELECT Count(*) + FROM store_sales + WHERE ss_quantity BETWEEN 1 AND 20) > 3672 THEN + (SELECT Avg(ss_ext_list_price) + FROM store_sales + WHERE + ss_quantity BETWEEN 1 AND 20) + ELSE (SELECT Avg(ss_net_profit) + 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) > 3392 THEN + (SELECT Avg(ss_ext_list_price) + FROM store_sales + WHERE + ss_quantity BETWEEN 21 AND 40) + ELSE (SELECT Avg(ss_net_profit) + 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) > 32784 THEN + (SELECT Avg(ss_ext_list_price) + FROM store_sales + WHERE + ss_quantity BETWEEN 41 AND 60) + ELSE (SELECT Avg(ss_net_profit) + 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) > 26032 THEN + (SELECT Avg(ss_ext_list_price) + FROM store_sales + WHERE + ss_quantity BETWEEN 61 AND 80) + ELSE (SELECT Avg(ss_net_profit) + 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) > 23982 THEN + (SELECT Avg(ss_ext_list_price) + FROM store_sales + WHERE + ss_quantity BETWEEN 81 AND 100) + ELSE (SELECT Avg(ss_net_profit) + FROM store_sales + WHERE ss_quantity BETWEEN 81 AND 100) + END bucket5 +FROM reason +WHERE r_reason_sk = 1; diff --git a/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query10.sql b/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query10.sql new file mode 100644 index 0000000000..c01fa898fe --- /dev/null +++ b/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query10.sql @@ -0,0 +1,62 @@ +-- start query 10 in stream 0 using template query10.tpl +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 ( 'Lycoming County', 'Sheridan County', + 'Kandiyohi County', + 'Pike County', + 'Greene 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 4 AND 4 + 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 4 AND 4 + 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 4 AND 4 + 3) ) +GROUP BY cd_gender, + cd_marital_status, + cd_education_status, + cd_purchase_estimate, + cd_credit_rating, + cd_dep_count, + cd_dep_employed_count, + cd_dep_college_count +ORDER BY cd_gender, + cd_marital_status, + cd_education_status, + cd_purchase_estimate, + cd_credit_rating, + cd_dep_count, + cd_dep_employed_count, + cd_dep_college_count +LIMIT 100; diff --git a/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query11.sql b/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query11.sql new file mode 100644 index 0000000000..fe31ef50c8 --- /dev/null +++ b/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query11.sql @@ -0,0 +1,97 @@ +-- start query 11 in stream 0 using template query11.tpl +WITH year_total + AS (SELECT c_customer_id customer_id, + c_first_name customer_first_name + , + c_last_name + customer_last_name, + c_preferred_cust_flag + customer_preferred_cust_flag + , + c_birth_country + customer_birth_country, + c_login customer_login, + c_email_address + customer_email_address, + d_year dyear, + Sum(ss_ext_list_price - ss_ext_discount_amt) year_total, + 's' sale_type + FROM customer, + store_sales, + date_dim + WHERE c_customer_sk = ss_customer_sk + AND ss_sold_date_sk = d_date_sk + GROUP BY c_customer_id, + c_first_name, + c_last_name, + c_preferred_cust_flag, + c_birth_country, + c_login, + c_email_address, + d_year + UNION ALL + SELECT c_customer_id customer_id, + c_first_name customer_first_name + , + c_last_name + customer_last_name, + c_preferred_cust_flag + customer_preferred_cust_flag + , + c_birth_country + customer_birth_country, + c_login customer_login, + c_email_address + customer_email_address, + d_year dyear, + Sum(ws_ext_list_price - ws_ext_discount_amt) year_total, + 'w' sale_type + FROM customer, + web_sales, + date_dim + WHERE c_customer_sk = ws_bill_customer_sk + AND ws_sold_date_sk = d_date_sk + GROUP BY c_customer_id, + c_first_name, + c_last_name, + c_preferred_cust_flag, + c_birth_country, + c_login, + c_email_address, + d_year) +SELECT t_s_secyear.customer_id, + t_s_secyear.customer_first_name, + t_s_secyear.customer_last_name, + t_s_secyear.customer_birth_country +FROM year_total t_s_firstyear, + year_total t_s_secyear, + year_total t_w_firstyear, + year_total t_w_secyear +WHERE t_s_secyear.customer_id = t_s_firstyear.customer_id + AND t_s_firstyear.customer_id = t_w_secyear.customer_id + AND t_s_firstyear.customer_id = t_w_firstyear.customer_id + AND t_s_firstyear.sale_type = 's' + AND t_w_firstyear.sale_type = 'w' + AND t_s_secyear.sale_type = 's' + AND t_w_secyear.sale_type = 'w' + AND t_s_firstyear.dyear = 2001 + AND t_s_secyear.dyear = 2001 + 1 + AND t_w_firstyear.dyear = 2001 + AND t_w_secyear.dyear = 2001 + 1 + AND t_s_firstyear.year_total > 0 + AND t_w_firstyear.year_total > 0 + AND CASE + WHEN t_w_firstyear.year_total > 0 THEN t_w_secyear.year_total / + t_w_firstyear.year_total + ELSE 0.0 + END > CASE + WHEN t_s_firstyear.year_total > 0 THEN + t_s_secyear.year_total / + t_s_firstyear.year_total + ELSE 0.0 + END +ORDER BY t_s_secyear.customer_id, + t_s_secyear.customer_first_name, + t_s_secyear.customer_last_name, + t_s_secyear.customer_birth_country +LIMIT 100; diff --git a/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query12.sql b/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query12.sql new file mode 100644 index 0000000000..fe325087b0 --- /dev/null +++ b/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query12.sql @@ -0,0 +1,31 @@ +-- start query 12 in stream 0 using template query12.tpl +SELECT + i_item_id , + i_item_desc , + i_category , + i_class , + i_current_price , + Sum(ws_ext_sales_price) AS itemrevenue , + Sum(ws_ext_sales_price)*100/Sum(Sum(ws_ext_sales_price)) OVER (partition BY i_class) AS revenueratio +FROM web_sales , + item , + date_dim +WHERE ws_item_sk = i_item_sk +AND i_category IN ('Home', + 'Men', + 'Women') +AND ws_sold_date_sk = d_date_sk +AND d_date BETWEEN Cast('2000-05-11' AS DATE) AND ( + Cast('2000-05-11' AS DATE) + INTERVAL '30' day) +GROUP BY i_item_id , + i_item_desc , + i_category , + i_class , + i_current_price +ORDER BY i_category , + i_class , + i_item_id , + i_item_desc , + revenueratio +LIMIT 100; + diff --git a/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query13.sql b/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query13.sql new file mode 100644 index 0000000000..c445aa9df3 --- /dev/null +++ b/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query13.sql @@ -0,0 +1,44 @@ +-- start query 13 in stream 0 using template query13.tpl +SELECT Avg(ss_quantity), + Avg(ss_ext_sales_price), + Avg(ss_ext_wholesale_cost), + Sum(ss_ext_wholesale_cost) +FROM store_sales, + store, + customer_demographics, + household_demographics, + customer_address, + date_dim +WHERE s_store_sk = ss_store_sk + AND ss_sold_date_sk = d_date_sk + AND d_year = 2001 + AND ( ( ss_hdemo_sk = hd_demo_sk + AND cd_demo_sk = ss_cdemo_sk + AND cd_marital_status = 'U' + AND cd_education_status = 'Advanced Degree' + AND ss_sales_price BETWEEN 100.00 AND 150.00 + AND hd_dep_count = 3 ) + OR ( ss_hdemo_sk = hd_demo_sk + AND cd_demo_sk = ss_cdemo_sk + AND cd_marital_status = 'M' + AND cd_education_status = 'Primary' + AND ss_sales_price BETWEEN 50.00 AND 100.00 + AND hd_dep_count = 1 ) + OR ( ss_hdemo_sk = hd_demo_sk + AND cd_demo_sk = ss_cdemo_sk + AND cd_marital_status = 'D' + AND cd_education_status = 'Secondary' + AND ss_sales_price BETWEEN 150.00 AND 200.00 + AND hd_dep_count = 1 ) ) + AND ( ( ss_addr_sk = ca_address_sk + AND ca_country = 'United States' + AND ca_state IN ( 'AZ', 'NE', 'IA' ) + AND ss_net_profit BETWEEN 100 AND 200 ) + OR ( ss_addr_sk = ca_address_sk + AND ca_country = 'United States' + AND ca_state IN ( 'MS', 'CA', 'NV' ) + AND ss_net_profit BETWEEN 150 AND 300 ) + OR ( ss_addr_sk = ca_address_sk + AND ca_country = 'United States' + AND ca_state IN ( 'GA', 'TX', 'NJ' ) + AND ss_net_profit BETWEEN 50 AND 250 ) ); diff --git a/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query14.sql b/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query14.sql new file mode 100644 index 0000000000..40467ce397 --- /dev/null +++ b/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query14.sql @@ -0,0 +1,245 @@ +-- start query 14 in stream 0 using template query14.tpl +WITH cross_items + AS (SELECT i_item_sk ss_item_sk + FROM item, + (SELECT iss.i_brand_id brand_id, + iss.i_class_id class_id, + iss.i_category_id category_id + FROM store_sales, + item iss, + date_dim d1 + WHERE ss_item_sk = iss.i_item_sk + AND ss_sold_date_sk = d1.d_date_sk + AND d1.d_year BETWEEN 1999 AND 1999 + 2 + INTERSECT + SELECT ics.i_brand_id, + ics.i_class_id, + ics.i_category_id + FROM catalog_sales, + item ics, + date_dim d2 + WHERE cs_item_sk = ics.i_item_sk + AND cs_sold_date_sk = d2.d_date_sk + AND d2.d_year BETWEEN 1999 AND 1999 + 2 + INTERSECT + SELECT iws.i_brand_id, + iws.i_class_id, + iws.i_category_id + FROM web_sales, + item iws, + date_dim d3 + WHERE ws_item_sk = iws.i_item_sk + AND ws_sold_date_sk = d3.d_date_sk + AND d3.d_year BETWEEN 1999 AND 1999 + 2) + WHERE i_brand_id = brand_id + AND i_class_id = class_id + AND i_category_id = category_id), + avg_sales + AS (SELECT Avg(quantity * list_price) average_sales + FROM (SELECT ss_quantity quantity, + ss_list_price list_price + FROM store_sales, + date_dim + WHERE ss_sold_date_sk = d_date_sk + AND d_year BETWEEN 1999 AND 1999 + 2 + UNION ALL + SELECT cs_quantity quantity, + cs_list_price list_price + FROM catalog_sales, + date_dim + WHERE cs_sold_date_sk = d_date_sk + AND d_year BETWEEN 1999 AND 1999 + 2 + UNION ALL + SELECT ws_quantity quantity, + ws_list_price list_price + FROM web_sales, + date_dim + WHERE ws_sold_date_sk = d_date_sk + AND d_year BETWEEN 1999 AND 1999 + 2) x) +SELECT channel, + i_brand_id, + i_class_id, + i_category_id, + Sum(sales), + Sum(number_sales) +FROM (SELECT 'store' channel, + i_brand_id, + i_class_id, + i_category_id, + Sum(ss_quantity * ss_list_price) sales, + Count(*) number_sales + FROM store_sales, + item, + date_dim + WHERE ss_item_sk IN (SELECT ss_item_sk + FROM cross_items) + AND ss_item_sk = i_item_sk + AND ss_sold_date_sk = d_date_sk + AND d_year = 1999 + 2 + AND d_moy = 11 + GROUP BY i_brand_id, + i_class_id, + i_category_id + HAVING Sum(ss_quantity * ss_list_price) > (SELECT average_sales + FROM avg_sales) + UNION ALL + SELECT 'catalog' channel, + i_brand_id, + i_class_id, + i_category_id, + Sum(cs_quantity * cs_list_price) sales, + Count(*) number_sales + FROM catalog_sales, + item, + date_dim + WHERE cs_item_sk IN (SELECT ss_item_sk + FROM cross_items) + AND cs_item_sk = i_item_sk + AND cs_sold_date_sk = d_date_sk + AND d_year = 1999 + 2 + AND d_moy = 11 + GROUP BY i_brand_id, + i_class_id, + i_category_id + HAVING Sum(cs_quantity * cs_list_price) > (SELECT average_sales + FROM avg_sales) + UNION ALL + SELECT 'web' channel, + i_brand_id, + i_class_id, + i_category_id, + Sum(ws_quantity * ws_list_price) sales, + Count(*) number_sales + FROM web_sales, + item, + date_dim + WHERE ws_item_sk IN (SELECT ss_item_sk + FROM cross_items) + AND ws_item_sk = i_item_sk + AND ws_sold_date_sk = d_date_sk + AND d_year = 1999 + 2 + AND d_moy = 11 + GROUP BY i_brand_id, + i_class_id, + i_category_id + HAVING Sum(ws_quantity * ws_list_price) > (SELECT average_sales + FROM avg_sales)) y +GROUP BY rollup ( channel, i_brand_id, i_class_id, i_category_id ) +ORDER BY channel, + i_brand_id, + i_class_id, + i_category_id +LIMIT 100; + +WITH cross_items + AS (SELECT i_item_sk ss_item_sk + FROM item, + (SELECT iss.i_brand_id brand_id, + iss.i_class_id class_id, + iss.i_category_id category_id + FROM store_sales, + item iss, + date_dim d1 + WHERE ss_item_sk = iss.i_item_sk + AND ss_sold_date_sk = d1.d_date_sk + AND d1.d_year BETWEEN 1999 AND 1999 + 2 + INTERSECT + SELECT ics.i_brand_id, + ics.i_class_id, + ics.i_category_id + FROM catalog_sales, + item ics, + date_dim d2 + WHERE cs_item_sk = ics.i_item_sk + AND cs_sold_date_sk = d2.d_date_sk + AND d2.d_year BETWEEN 1999 AND 1999 + 2 + INTERSECT + SELECT iws.i_brand_id, + iws.i_class_id, + iws.i_category_id + FROM web_sales, + item iws, + date_dim d3 + WHERE ws_item_sk = iws.i_item_sk + AND ws_sold_date_sk = d3.d_date_sk + AND d3.d_year BETWEEN 1999 AND 1999 + 2) x + WHERE i_brand_id = brand_id + AND i_class_id = class_id + AND i_category_id = category_id), + avg_sales + AS (SELECT Avg(quantity * list_price) average_sales + FROM (SELECT ss_quantity quantity, + ss_list_price list_price + FROM store_sales, + date_dim + WHERE ss_sold_date_sk = d_date_sk + AND d_year BETWEEN 1999 AND 1999 + 2 + UNION ALL + SELECT cs_quantity quantity, + cs_list_price list_price + FROM catalog_sales, + date_dim + WHERE cs_sold_date_sk = d_date_sk + AND d_year BETWEEN 1999 AND 1999 + 2 + UNION ALL + SELECT ws_quantity quantity, + ws_list_price list_price + FROM web_sales, + date_dim + WHERE ws_sold_date_sk = d_date_sk + AND d_year BETWEEN 1999 AND 1999 + 2) x) +SELECT * +FROM (SELECT 'store' channel, + i_brand_id, + i_class_id, + i_category_id, + Sum(ss_quantity * ss_list_price) sales, + Count(*) number_sales + FROM store_sales, + item, + date_dim + WHERE ss_item_sk IN (SELECT ss_item_sk + FROM cross_items) + AND ss_item_sk = i_item_sk + AND ss_sold_date_sk = d_date_sk + AND d_week_seq = (SELECT d_week_seq + FROM date_dim + WHERE d_year = 1999 + 1 + AND d_moy = 12 + AND d_dom = 25) + GROUP BY i_brand_id, + i_class_id, + i_category_id + HAVING Sum(ss_quantity * ss_list_price) > (SELECT average_sales + FROM avg_sales)) this_year, + (SELECT 'store' channel, + i_brand_id, + i_class_id, + i_category_id, + Sum(ss_quantity * ss_list_price) sales, + Count(*) number_sales + FROM store_sales, + item, + date_dim + WHERE ss_item_sk IN (SELECT ss_item_sk + FROM cross_items) + AND ss_item_sk = i_item_sk + AND ss_sold_date_sk = d_date_sk + AND d_week_seq = (SELECT d_week_seq + FROM date_dim + WHERE d_year = 1999 + AND d_moy = 12 + AND d_dom = 25) + GROUP BY i_brand_id, + i_class_id, + i_category_id + HAVING Sum(ss_quantity * ss_list_price) > (SELECT average_sales + FROM avg_sales)) last_year +WHERE this_year.i_brand_id = last_year.i_brand_id + 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, + this_year.i_brand_id, + this_year.i_class_id, + this_year.i_category_id +LIMIT 100; diff --git a/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query15.sql b/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query15.sql new file mode 100644 index 0000000000..89f956ee28 --- /dev/null +++ b/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query15.sql @@ -0,0 +1,20 @@ +-- start query 15 in stream 0 using template query15.tpl +SELECT ca_zip, + Sum(cs_sales_price) +FROM catalog_sales, + customer, + customer_address, + date_dim +WHERE cs_bill_customer_sk = c_customer_sk + AND c_current_addr_sk = ca_address_sk + AND ( Substr(ca_zip, 1, 5) IN ( '85669', '86197', '88274', '83405', + '86475', '85392', '85460', '80348', + '81792' ) + OR ca_state IN ( 'CA', 'WA', 'GA' ) + OR cs_sales_price > 500 ) + AND cs_sold_date_sk = d_date_sk + AND d_qoy = 1 + AND d_year = 1998 +GROUP BY ca_zip +ORDER BY ca_zip +LIMIT 100; diff --git a/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query16.sql b/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query16.sql new file mode 100644 index 0000000000..c21fd95fac --- /dev/null +++ b/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query16.sql @@ -0,0 +1,34 @@ +-- start query 16 in stream 0 using template query16.tpl +SELECT + Count(DISTINCT cs_order_number) AS `order count` , + Sum(cs_ext_ship_cost) AS `total shipping cost` , + Sum(cs_net_profit) AS `total net profit` +FROM catalog_sales cs1 , + date_dim , + customer_address , + call_center +WHERE d_date BETWEEN '2002-3-01' AND ( + Cast('2002-3-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 = 'IA' +AND cs1.cs_call_center_sk = cc_call_center_sk +AND cc_county IN ('Williamson County', + 'Williamson County', + 'Williamson County', + 'Williamson County', + 'Williamson County' ) +AND EXISTS + ( + SELECT * + FROM catalog_sales cs2 + WHERE cs1.cs_order_number = cs2.cs_order_number + AND cs1.cs_warehouse_sk <> cs2.cs_warehouse_sk) +AND NOT EXISTS + ( + SELECT * + FROM catalog_returns cr1 + WHERE cs1.cs_order_number = cr1.cr_order_number) +ORDER BY count(DISTINCT cs_order_number) +LIMIT 100; + diff --git a/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query17.sql b/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query17.sql new file mode 100644 index 0000000000..9871fae663 --- /dev/null +++ b/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query17.sql @@ -0,0 +1,56 @@ +-- start query 17 in stream 0 using template query17.tpl +SELECT i_item_id, + i_item_desc, + s_state, + Count(ss_quantity) AS + store_sales_quantitycount, + Avg(ss_quantity) AS + store_sales_quantityave, + Stddev_samp(ss_quantity) AS + store_sales_quantitystdev, + Stddev_samp(ss_quantity) / Avg(ss_quantity) AS + store_sales_quantitycov, + Count(sr_return_quantity) AS + store_returns_quantitycount, + Avg(sr_return_quantity) AS + store_returns_quantityave, + Stddev_samp(sr_return_quantity) AS + store_returns_quantitystdev, + Stddev_samp(sr_return_quantity) / Avg(sr_return_quantity) AS + store_returns_quantitycov, + Count(cs_quantity) AS + catalog_sales_quantitycount, + Avg(cs_quantity) AS + catalog_sales_quantityave, + Stddev_samp(cs_quantity) / Avg(cs_quantity) AS + catalog_sales_quantitystdev, + Stddev_samp(cs_quantity) / Avg(cs_quantity) AS + catalog_sales_quantitycov +FROM store_sales, + store_returns, + catalog_sales, + date_dim d1, + date_dim d2, + date_dim d3, + store, + item +WHERE d1.d_quarter_name = '1999Q1' + 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 ( '1999Q1', '1999Q2', '1999Q3' ) + 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 ( '1999Q1', '1999Q2', '1999Q3' ) +GROUP BY i_item_id, + i_item_desc, + s_state +ORDER BY i_item_id, + i_item_desc, + s_state +LIMIT 100; diff --git a/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query18.sql b/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query18.sql new file mode 100644 index 0000000000..d94c680153 --- /dev/null +++ b/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query18.sql @@ -0,0 +1,38 @@ +-- start query 18 in stream 0 using template query18.tpl +SELECT i_item_id, + ca_country, + ca_state, + ca_county, + Avg(Cast(cs_quantity AS NUMERIC(12, 2))) agg1, + Avg(Cast(cs_list_price AS NUMERIC(12, 2))) agg2, + Avg(Cast(cs_coupon_amt AS NUMERIC(12, 2))) agg3, + Avg(Cast(cs_sales_price AS NUMERIC(12, 2))) agg4, + Avg(Cast(cs_net_profit AS NUMERIC(12, 2))) agg5, + Avg(Cast(c_birth_year AS NUMERIC(12, 2))) agg6, + Avg(Cast(cd1.cd_dep_count AS NUMERIC(12, 2))) agg7 +FROM catalog_sales, + customer_demographics cd1, + customer_demographics cd2, + customer, + customer_address, + date_dim, + item +WHERE cs_sold_date_sk = d_date_sk + AND cs_item_sk = i_item_sk + AND cs_bill_cdemo_sk = cd1.cd_demo_sk + AND cs_bill_customer_sk = c_customer_sk + AND cd1.cd_gender = 'F' + AND cd1.cd_education_status = 'Secondary' + AND c_current_cdemo_sk = cd2.cd_demo_sk + AND c_current_addr_sk = ca_address_sk + AND c_birth_month IN ( 8, 4, 2, 5, + 11, 9 ) + AND d_year = 2001 + AND ca_state IN ( 'KS', 'IA', 'AL', 'UT', + 'VA', 'NC', 'TX' ) +GROUP BY rollup ( i_item_id, ca_country, ca_state, ca_county ) +ORDER BY ca_country, + ca_state, + ca_county, + i_item_id +LIMIT 100; diff --git a/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query19.sql b/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query19.sql new file mode 100644 index 0000000000..d053670b41 --- /dev/null +++ b/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query19.sql @@ -0,0 +1,31 @@ +-- start query 19 in stream 0 using template query19.tpl +SELECT i_brand_id brand_id, + i_brand brand, + i_manufact_id, + i_manufact, + Sum(ss_ext_sales_price) ext_price +FROM date_dim, + store_sales, + item, + customer, + customer_address, + store +WHERE d_date_sk = ss_sold_date_sk + AND ss_item_sk = i_item_sk + AND i_manager_id = 38 + AND d_moy = 12 + AND d_year = 1998 + AND ss_customer_sk = c_customer_sk + AND c_current_addr_sk = ca_address_sk + AND Substr(ca_zip, 1, 5) <> Substr(s_zip, 1, 5) + AND ss_store_sk = s_store_sk +GROUP BY i_brand, + i_brand_id, + i_manufact_id, + i_manufact +ORDER BY ext_price DESC, + i_brand, + i_brand_id, + i_manufact_id, + i_manufact +LIMIT 100; diff --git a/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query20.sql b/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query20.sql new file mode 100644 index 0000000000..b5d060d1a6 --- /dev/null +++ b/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query20.sql @@ -0,0 +1,31 @@ +-- start query 20 in stream 0 using template query20.tpl +SELECT + i_item_id , + i_item_desc , + i_category , + i_class , + i_current_price , + Sum(cs_ext_sales_price) AS itemrevenue , + Sum(cs_ext_sales_price)*100/Sum(Sum(cs_ext_sales_price)) OVER (partition BY i_class) AS revenueratio +FROM catalog_sales , + item , + date_dim +WHERE cs_item_sk = i_item_sk +AND i_category IN ('Children', + 'Women', + 'Electronics') +AND cs_sold_date_sk = d_date_sk +AND d_date BETWEEN Cast('2001-02-03' AS DATE) AND ( + Cast('2001-02-03' AS DATE) + INTERVAL '30' day) +GROUP BY i_item_id , + i_item_desc , + i_category , + i_class , + i_current_price +ORDER BY i_category , + i_class , + i_item_id , + i_item_desc , + revenueratio +LIMIT 100; + diff --git a/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query21.sql b/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query21.sql new file mode 100644 index 0000000000..1efc3b3207 --- /dev/null +++ b/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query21.sql @@ -0,0 +1,39 @@ +-- start query 21 in stream 0 using template query21.tpl +SELECT + * +FROM ( + SELECT w_warehouse_name , + i_item_id , + Sum( + CASE + WHEN ( + Cast(d_date AS DATE) < Cast ('2000-05-13' AS DATE)) THEN inv_quantity_on_hand + ELSE 0 + END) AS inv_before , + Sum( + CASE + WHEN ( + Cast(d_date AS DATE) >= Cast ('2000-05-13' AS DATE)) THEN inv_quantity_on_hand + ELSE 0 + END) AS inv_after + FROM inventory , + warehouse , + item , + date_dim + WHERE i_current_price BETWEEN 0.99 AND 1.49 + AND i_item_sk = inv_item_sk + AND inv_warehouse_sk = w_warehouse_sk + AND inv_date_sk = d_date_sk + AND d_date BETWEEN (Cast ('2000-05-13' AS DATE) - INTERVAL '30' day) AND ( + cast ('2000-05-13' AS date) + INTERVAL '30' day) + GROUP BY w_warehouse_name, + i_item_id) x +WHERE ( + CASE + WHEN inv_before > 0 THEN inv_after / inv_before + ELSE NULL + END) BETWEEN 2.0/3.0 AND 3.0/2.0 +ORDER BY w_warehouse_name , + i_item_id +LIMIT 100; + diff --git a/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query22.sql b/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query22.sql new file mode 100644 index 0000000000..b3e566fc32 --- /dev/null +++ b/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query22.sql @@ -0,0 +1,21 @@ +-- start query 22 in stream 0 using template query22.tpl +SELECT i_product_name, + i_brand, + i_class, + i_category, + Avg(inv_quantity_on_hand) qoh +FROM inventory, + date_dim, + item, + warehouse +WHERE inv_date_sk = d_date_sk + AND inv_item_sk = i_item_sk + AND inv_warehouse_sk = w_warehouse_sk + AND d_month_seq BETWEEN 1205 AND 1205 + 11 +GROUP BY rollup( i_product_name, i_brand, i_class, i_category ) +ORDER BY qoh, + i_product_name, + i_brand, + i_class, + i_category +LIMIT 100; diff --git a/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query23.sql b/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query23.sql new file mode 100644 index 0000000000..9e0ef707fd --- /dev/null +++ b/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query23.sql @@ -0,0 +1,136 @@ +-- start query 23 in stream 0 using template query23.tpl +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 ( 1998, 1998 + 1, 1998 + 2, 1998 + 3 ) + GROUP BY Substr(i_item_desc, 1, 30), + i_item_sk, + d_date + HAVING Count(*) > 4), + max_store_sales + AS (SELECT Max(csales) tpcds_cmax + FROM (SELECT c_customer_sk, + Sum(ss_quantity * ss_sales_price) csales + FROM store_sales, + customer, + date_dim + WHERE ss_customer_sk = c_customer_sk + AND ss_sold_date_sk = d_date_sk + AND d_year IN ( 1998, 1998 + 1, 1998 + 2, 1998 + 3 ) + GROUP BY c_customer_sk)), + best_ss_customer + AS (SELECT c_customer_sk, + Sum(ss_quantity * ss_sales_price) ssales + FROM store_sales, + customer + WHERE ss_customer_sk = c_customer_sk + GROUP BY c_customer_sk + HAVING Sum(ss_quantity * ss_sales_price) > + ( 95 / 100.0 ) * (SELECT * + FROM max_store_sales)) +SELECT Sum(sales) +FROM (SELECT cs_quantity * cs_list_price sales + FROM catalog_sales, + date_dim + WHERE d_year = 1998 + AND d_moy = 6 + 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 = 1998 + AND d_moy = 6 + AND ws_sold_date_sk = d_date_sk + AND ws_item_sk IN (SELECT item_sk + FROM frequent_ss_items) + AND ws_bill_customer_sk IN (SELECT c_customer_sk + FROM best_ss_customer)) LIMIT 100; + +WITH frequent_ss_items + AS (SELECT Substr(i_item_desc, 1, 30) itemdesc, + i_item_sk item_sk, + d_date solddate, + Count(*) cnt + FROM store_sales, + date_dim, + item + WHERE ss_sold_date_sk = d_date_sk + AND ss_item_sk = i_item_sk + AND d_year IN ( 1998, 1998 + 1, 1998 + 2, 1998 + 3 ) + GROUP BY Substr(i_item_desc, 1, 30), + i_item_sk, + d_date + HAVING Count(*) > 4), + max_store_sales + AS (SELECT Max(csales) tpcds_cmax + FROM (SELECT c_customer_sk, + Sum(ss_quantity * ss_sales_price) csales + FROM store_sales, + customer, + date_dim + WHERE ss_customer_sk = c_customer_sk + AND ss_sold_date_sk = d_date_sk + AND d_year IN ( 1998, 1998 + 1, 1998 + 2, 1998 + 3 ) + GROUP BY c_customer_sk)), + best_ss_customer + AS (SELECT c_customer_sk, + Sum(ss_quantity * ss_sales_price) ssales + FROM store_sales, + customer + WHERE ss_customer_sk = c_customer_sk + GROUP BY c_customer_sk + HAVING Sum(ss_quantity * ss_sales_price) > + ( 95 / 100.0 ) * (SELECT * + FROM max_store_sales)) +SELECT c_last_name, + c_first_name, + sales +FROM (SELECT c_last_name, + c_first_name, + Sum(cs_quantity * cs_list_price) sales + FROM catalog_sales, + customer, + date_dim + WHERE d_year = 1998 + AND d_moy = 6 + AND cs_sold_date_sk = d_date_sk + AND cs_item_sk IN (SELECT item_sk + FROM frequent_ss_items) + AND cs_bill_customer_sk IN (SELECT c_customer_sk + FROM best_ss_customer) + AND cs_bill_customer_sk = c_customer_sk + GROUP BY c_last_name, + c_first_name + UNION ALL + SELECT c_last_name, + c_first_name, + Sum(ws_quantity * ws_list_price) sales + FROM web_sales, + customer, + date_dim + WHERE d_year = 1998 + AND d_moy = 6 + AND ws_sold_date_sk = d_date_sk + AND ws_item_sk IN (SELECT item_sk + FROM frequent_ss_items) + AND ws_bill_customer_sk IN (SELECT c_customer_sk + FROM best_ss_customer) + AND ws_bill_customer_sk = c_customer_sk + GROUP BY c_last_name, + c_first_name) +ORDER BY c_last_name, + c_first_name, + sales +LIMIT 100; diff --git a/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query24.sql b/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query24.sql new file mode 100644 index 0000000000..c3922ccdd1 --- /dev/null +++ b/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query24.sql @@ -0,0 +1,96 @@ +-- start query 24 in stream 0 using template query24.tpl +WITH ssales + AS (SELECT c_last_name, + c_first_name, + s_store_name, + ca_state, + s_state, + i_color, + i_current_price, + i_manager_id, + i_units, + i_size, + Sum(ss_net_profit) 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 = 6 + GROUP BY c_last_name, + c_first_name, + s_store_name, + ca_state, + s_state, + i_color, + i_current_price, + i_manager_id, + i_units, + i_size) +SELECT c_last_name, + c_first_name, + s_store_name, + Sum(netpaid) paid +FROM ssales +WHERE i_color = 'papaya' +GROUP BY c_last_name, + c_first_name, + s_store_name +HAVING Sum(netpaid) > (SELECT 0.05 * Avg(netpaid) + FROM ssales); + +WITH ssales + AS (SELECT c_last_name, + c_first_name, + s_store_name, + ca_state, + s_state, + i_color, + i_current_price, + i_manager_id, + i_units, + i_size, + Sum(ss_net_profit) 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 = 6 + GROUP BY c_last_name, + c_first_name, + s_store_name, + ca_state, + s_state, + i_color, + i_current_price, + i_manager_id, + i_units, + i_size) +SELECT c_last_name, + c_first_name, + s_store_name, + Sum(netpaid) paid +FROM ssales +WHERE i_color = 'chartreuse' +GROUP BY c_last_name, + c_first_name, + s_store_name +HAVING Sum(netpaid) > (SELECT 0.05 * Avg(netpaid) + FROM ssales); diff --git a/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query25.sql b/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query25.sql new file mode 100644 index 0000000000..1d52c6ef83 --- /dev/null +++ b/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query25.sql @@ -0,0 +1,41 @@ +-- start query 25 in stream 0 using template query25.tpl +SELECT i_item_id, + i_item_desc, + s_store_id, + s_store_name, + Max(ss_net_profit) AS store_sales_profit, + Max(sr_net_loss) AS store_returns_loss, + Max(cs_net_profit) AS catalog_sales_profit +FROM store_sales, + store_returns, + catalog_sales, + date_dim d1, + date_dim d2, + date_dim d3, + store, + item +WHERE d1.d_moy = 4 + AND d1.d_year = 2001 + AND d1.d_date_sk = ss_sold_date_sk + AND i_item_sk = ss_item_sk + AND s_store_sk = ss_store_sk + AND ss_customer_sk = sr_customer_sk + AND ss_item_sk = sr_item_sk + AND ss_ticket_number = sr_ticket_number + AND sr_returned_date_sk = d2.d_date_sk + AND d2.d_moy BETWEEN 4 AND 10 + AND d2.d_year = 2001 + AND sr_customer_sk = cs_bill_customer_sk + AND sr_item_sk = cs_item_sk + AND cs_sold_date_sk = d3.d_date_sk + AND d3.d_moy BETWEEN 4 AND 10 + AND d3.d_year = 2001 +GROUP BY i_item_id, + i_item_desc, + s_store_id, + s_store_name +ORDER BY i_item_id, + i_item_desc, + s_store_id, + s_store_name +LIMIT 100; diff --git a/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query26.sql b/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query26.sql new file mode 100644 index 0000000000..8bf38fa042 --- /dev/null +++ b/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query26.sql @@ -0,0 +1,24 @@ +-- start query 26 in stream 0 using template query26.tpl +SELECT i_item_id, + Avg(cs_quantity) agg1, + Avg(cs_list_price) agg2, + Avg(cs_coupon_amt) agg3, + Avg(cs_sales_price) agg4 +FROM catalog_sales, + customer_demographics, + date_dim, + item, + promotion +WHERE cs_sold_date_sk = d_date_sk + AND cs_item_sk = i_item_sk + AND cs_bill_cdemo_sk = cd_demo_sk + AND cs_promo_sk = p_promo_sk + AND cd_gender = 'F' + AND cd_marital_status = 'W' + AND cd_education_status = 'Secondary' + AND ( p_channel_email = 'N' + OR p_channel_event = 'N' ) + AND d_year = 2000 +GROUP BY i_item_id +ORDER BY i_item_id +LIMIT 100; diff --git a/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query27.sql b/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query27.sql new file mode 100644 index 0000000000..1cc646391d --- /dev/null +++ b/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query27.sql @@ -0,0 +1,27 @@ +-- start query 27 in stream 0 using template query27.tpl +SELECT i_item_id, + s_state, + Grouping(s_state) g_state, + Avg(ss_quantity) agg1, + Avg(ss_list_price) agg2, + Avg(ss_coupon_amt) agg3, + Avg(ss_sales_price) agg4 +FROM store_sales, + customer_demographics, + date_dim, + store, + item +WHERE ss_sold_date_sk = d_date_sk + AND ss_item_sk = i_item_sk + AND ss_store_sk = s_store_sk + AND ss_cdemo_sk = cd_demo_sk + AND cd_gender = 'M' + AND cd_marital_status = 'D' + AND cd_education_status = 'College' + AND d_year = 2000 + AND s_state IN ( 'TN', 'TN', 'TN', 'TN', + 'TN', 'TN' ) +GROUP BY rollup ( i_item_id, s_state ) +ORDER BY i_item_id, + s_state +LIMIT 100; diff --git a/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query28.sql b/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query28.sql new file mode 100644 index 0000000000..ff014304b5 --- /dev/null +++ b/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query28.sql @@ -0,0 +1,51 @@ +-- start query 28 in stream 0 using template query28.tpl +SELECT * +FROM (SELECT Avg(ss_list_price) B1_LP, + Count(ss_list_price) B1_CNT, + Count(DISTINCT ss_list_price) B1_CNTD + FROM store_sales + WHERE ss_quantity BETWEEN 0 AND 5 + AND ( ss_list_price BETWEEN 18 AND 18 + 10 + OR ss_coupon_amt BETWEEN 1939 AND 1939 + 1000 + OR ss_wholesale_cost BETWEEN 34 AND 34 + 20 )) B1, + (SELECT Avg(ss_list_price) B2_LP, + Count(ss_list_price) B2_CNT, + Count(DISTINCT ss_list_price) B2_CNTD + FROM store_sales + WHERE ss_quantity BETWEEN 6 AND 10 + AND ( ss_list_price BETWEEN 1 AND 1 + 10 + OR ss_coupon_amt BETWEEN 35 AND 35 + 1000 + OR ss_wholesale_cost BETWEEN 50 AND 50 + 20 )) B2, + (SELECT Avg(ss_list_price) B3_LP, + Count(ss_list_price) B3_CNT, + Count(DISTINCT ss_list_price) B3_CNTD + FROM store_sales + WHERE ss_quantity BETWEEN 11 AND 15 + AND ( ss_list_price BETWEEN 91 AND 91 + 10 + OR ss_coupon_amt BETWEEN 1412 AND 1412 + 1000 + OR ss_wholesale_cost BETWEEN 17 AND 17 + 20 )) B3, + (SELECT Avg(ss_list_price) B4_LP, + Count(ss_list_price) B4_CNT, + Count(DISTINCT ss_list_price) B4_CNTD + FROM store_sales + WHERE ss_quantity BETWEEN 16 AND 20 + AND ( ss_list_price BETWEEN 9 AND 9 + 10 + OR ss_coupon_amt BETWEEN 5270 AND 5270 + 1000 + OR ss_wholesale_cost BETWEEN 29 AND 29 + 20 )) B4, + (SELECT Avg(ss_list_price) B5_LP, + Count(ss_list_price) B5_CNT, + Count(DISTINCT ss_list_price) B5_CNTD + FROM store_sales + WHERE ss_quantity BETWEEN 21 AND 25 + AND ( ss_list_price BETWEEN 45 AND 45 + 10 + OR ss_coupon_amt BETWEEN 826 AND 826 + 1000 + OR ss_wholesale_cost BETWEEN 5 AND 5 + 20 )) B5, + (SELECT Avg(ss_list_price) B6_LP, + Count(ss_list_price) B6_CNT, + Count(DISTINCT ss_list_price) B6_CNTD + FROM store_sales + WHERE ss_quantity BETWEEN 26 AND 30 + AND ( ss_list_price BETWEEN 174 AND 174 + 10 + OR ss_coupon_amt BETWEEN 5548 AND 5548 + 1000 + OR ss_wholesale_cost BETWEEN 42 AND 42 + 20 )) B6 +LIMIT 100; diff --git a/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query29.sql b/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query29.sql new file mode 100644 index 0000000000..537076927d --- /dev/null +++ b/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query29.sql @@ -0,0 +1,40 @@ +-- start query 29 in stream 0 using template query29.tpl +SELECT i_item_id, + i_item_desc, + s_store_id, + s_store_name, + Avg(ss_quantity) AS store_sales_quantity, + Avg(sr_return_quantity) AS store_returns_quantity, + Avg(cs_quantity) AS catalog_sales_quantity +FROM store_sales, + store_returns, + catalog_sales, + date_dim d1, + date_dim d2, + date_dim d3, + store, + item +WHERE d1.d_moy = 4 + AND d1.d_year = 1998 + 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 4 + 3 + AND d2.d_year = 1998 + 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 ( 1998, 1998 + 1, 1998 + 2 ) +GROUP BY i_item_id, + i_item_desc, + s_store_id, + s_store_name +ORDER BY i_item_id, + i_item_desc, + s_store_id, + s_store_name +LIMIT 100; diff --git a/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query30.sql b/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query30.sql new file mode 100644 index 0000000000..c4ef74cc75 --- /dev/null +++ b/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query30.sql @@ -0,0 +1,49 @@ +-- start query 30 in stream 0 using template query30.tpl +WITH customer_total_return + AS (SELECT wr_returning_customer_sk AS ctr_customer_sk, + ca_state AS ctr_state, + Sum(wr_return_amt) AS ctr_total_return + FROM web_returns, + date_dim, + customer_address + WHERE wr_returned_date_sk = d_date_sk + AND d_year = 2000 + AND wr_returning_addr_sk = ca_address_sk + GROUP BY wr_returning_customer_sk, + ca_state) +SELECT c_customer_id, + c_salutation, + c_first_name, + c_last_name, + c_preferred_cust_flag, + c_birth_day, + c_birth_month, + c_birth_year, + c_birth_country, + c_login, + c_email_address, + c_last_review_date, + ctr_total_return +FROM customer_total_return ctr1, + customer_address, + customer +WHERE ctr1.ctr_total_return > (SELECT Avg(ctr_total_return) * 1.2 + FROM customer_total_return ctr2 + WHERE ctr1.ctr_state = ctr2.ctr_state) + AND ca_address_sk = c_current_addr_sk + AND ca_state = 'IN' + AND ctr1.ctr_customer_sk = c_customer_sk +ORDER BY c_customer_id, + c_salutation, + c_first_name, + c_last_name, + c_preferred_cust_flag, + c_birth_day, + c_birth_month, + c_birth_year, + c_birth_country, + c_login, + c_email_address, + c_last_review_date, + ctr_total_return +LIMIT 100; diff --git a/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query31.sql b/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query31.sql new file mode 100644 index 0000000000..66e428fc74 --- /dev/null +++ b/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query31.sql @@ -0,0 +1,73 @@ +-- start query 31 in stream 0 using template query31.tpl +WITH ss + AS (SELECT ca_county, + d_qoy, + d_year, + Sum(ss_ext_sales_price) AS store_sales + FROM store_sales, + date_dim, + customer_address + WHERE ss_sold_date_sk = d_date_sk + AND ss_addr_sk = ca_address_sk + GROUP BY ca_county, + d_qoy, + d_year), + ws + AS (SELECT ca_county, + d_qoy, + d_year, + Sum(ws_ext_sales_price) AS web_sales + FROM web_sales, + date_dim, + customer_address + WHERE ws_sold_date_sk = d_date_sk + AND ws_bill_addr_sk = ca_address_sk + GROUP BY ca_county, + d_qoy, + d_year) +SELECT ss1.ca_county, + ss1.d_year, + ws2.web_sales / ws1.web_sales web_q1_q2_increase, + ss2.store_sales / ss1.store_sales store_q1_q2_increase, + ws3.web_sales / ws2.web_sales web_q2_q3_increase, + ss3.store_sales / ss2.store_sales store_q2_q3_increase +FROM ss ss1, + ss ss2, + ss ss3, + ws ws1, + ws ws2, + ws ws3 +WHERE ss1.d_qoy = 1 + AND ss1.d_year = 2001 + AND ss1.ca_county = ss2.ca_county + AND ss2.d_qoy = 2 + AND ss2.d_year = 2001 + AND ss2.ca_county = ss3.ca_county + AND ss3.d_qoy = 3 + AND ss3.d_year = 2001 + AND ss1.ca_county = ws1.ca_county + AND ws1.d_qoy = 1 + AND ws1.d_year = 2001 + AND ws1.ca_county = ws2.ca_county + AND ws2.d_qoy = 2 + AND ws2.d_year = 2001 + AND ws1.ca_county = ws3.ca_county + AND ws3.d_qoy = 3 + AND ws3.d_year = 2001 + AND CASE + WHEN ws1.web_sales > 0 THEN ws2.web_sales / ws1.web_sales + ELSE NULL + END > CASE + WHEN ss1.store_sales > 0 THEN + ss2.store_sales / ss1.store_sales + ELSE NULL + END + AND CASE + WHEN ws2.web_sales > 0 THEN ws3.web_sales / ws2.web_sales + ELSE NULL + END > CASE + WHEN ss2.store_sales > 0 THEN + ss3.store_sales / ss2.store_sales + ELSE NULL + END +ORDER BY ss1.d_year; diff --git a/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query32.sql b/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query32.sql new file mode 100644 index 0000000000..fbbf771f25 --- /dev/null +++ b/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query32.sql @@ -0,0 +1,22 @@ +-- start query 32 in stream 0 using template query32.tpl +SELECT + Sum(cs_ext_discount_amt) AS `excess discount amount` +FROM catalog_sales , + item , + date_dim +WHERE i_manufact_id = 610 +AND i_item_sk = cs_item_sk +AND d_date BETWEEN '2001-03-04' AND ( + Cast('2001-03-04' AS DATE) + INTERVAL '90' day) +AND d_date_sk = cs_sold_date_sk +AND cs_ext_discount_amt > + ( + SELECT 1.3 * avg(cs_ext_discount_amt) + FROM catalog_sales , + date_dim + WHERE cs_item_sk = i_item_sk + AND d_date BETWEEN '2001-03-04' AND ( + cast('2001-03-04' AS date) + INTERVAL '90' day) + AND d_date_sk = cs_sold_date_sk ) +LIMIT 100; + diff --git a/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query33.sql b/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query33.sql new file mode 100644 index 0000000000..1b6fcdc790 --- /dev/null +++ b/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query33.sql @@ -0,0 +1,65 @@ +-- start query 33 in stream 0 using template query33.tpl +WITH ss + AS (SELECT i_manufact_id, + Sum(ss_ext_sales_price) total_sales + FROM store_sales, + date_dim, + customer_address, + item + WHERE i_manufact_id IN (SELECT i_manufact_id + FROM item + WHERE i_category IN ( 'Books' )) + AND ss_item_sk = i_item_sk + AND ss_sold_date_sk = d_date_sk + AND d_year = 1999 + AND d_moy = 3 + AND ss_addr_sk = ca_address_sk + AND ca_gmt_offset = -5 + GROUP BY i_manufact_id), + cs + AS (SELECT i_manufact_id, + Sum(cs_ext_sales_price) total_sales + FROM catalog_sales, + date_dim, + customer_address, + item + WHERE i_manufact_id IN (SELECT i_manufact_id + FROM item + WHERE i_category IN ( 'Books' )) + AND cs_item_sk = i_item_sk + AND cs_sold_date_sk = d_date_sk + AND d_year = 1999 + AND d_moy = 3 + AND cs_bill_addr_sk = ca_address_sk + AND ca_gmt_offset = -5 + GROUP BY i_manufact_id), + ws + AS (SELECT i_manufact_id, + Sum(ws_ext_sales_price) total_sales + FROM web_sales, + date_dim, + customer_address, + item + WHERE i_manufact_id IN (SELECT i_manufact_id + FROM item + WHERE i_category IN ( 'Books' )) + AND ws_item_sk = i_item_sk + AND ws_sold_date_sk = d_date_sk + AND d_year = 1999 + AND d_moy = 3 + AND ws_bill_addr_sk = ca_address_sk + AND ca_gmt_offset = -5 + GROUP BY i_manufact_id) +SELECT i_manufact_id, + Sum(total_sales) total_sales +FROM (SELECT * + FROM ss + UNION ALL + SELECT * + FROM cs + UNION ALL + SELECT * + FROM ws) tmp1 +GROUP BY i_manufact_id +ORDER BY total_sales +LIMIT 100; diff --git a/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query34.sql b/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query34.sql new file mode 100644 index 0000000000..7b5d954df6 --- /dev/null +++ b/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query34.sql @@ -0,0 +1,46 @@ +-- start query 34 in stream 0 using template query34.tpl +SELECT c_last_name, + c_first_name, + c_salutation, + c_preferred_cust_flag, + ss_ticket_number, + cnt +FROM (SELECT ss_ticket_number, + ss_customer_sk, + Count(*) cnt + FROM store_sales, + date_dim, + store, + household_demographics + WHERE store_sales.ss_sold_date_sk = date_dim.d_date_sk + AND store_sales.ss_store_sk = store.s_store_sk + AND store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk + AND ( date_dim.d_dom BETWEEN 1 AND 3 + OR date_dim.d_dom BETWEEN 25 AND 28 ) + AND ( household_demographics.hd_buy_potential = '>10000' + OR household_demographics.hd_buy_potential = 'unknown' ) + AND household_demographics.hd_vehicle_count > 0 + AND ( CASE + WHEN household_demographics.hd_vehicle_count > 0 THEN + household_demographics.hd_dep_count / + household_demographics.hd_vehicle_count + ELSE NULL + END ) > 1.2 + AND date_dim.d_year IN ( 1999, 1999 + 1, 1999 + 2 ) + AND store.s_county IN ( 'Williamson County', 'Williamson County', + 'Williamson County', + 'Williamson County' + , + 'Williamson County', 'Williamson County', + 'Williamson County', + 'Williamson County' + ) + GROUP BY ss_ticket_number, + ss_customer_sk) dn, + customer +WHERE ss_customer_sk = c_customer_sk + AND cnt BETWEEN 15 AND 20 +ORDER BY c_last_name, + c_first_name, + c_salutation, + c_preferred_cust_flag DESC; diff --git a/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query35.sql b/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query35.sql new file mode 100644 index 0000000000..7d1ce6ae73 --- /dev/null +++ b/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query35.sql @@ -0,0 +1,58 @@ +-- start query 35 in stream 0 using template query35.tpl +SELECT ca_state, + cd_gender, + cd_marital_status, + cd_dep_count, + Count(*) cnt1, + Stddev_samp(cd_dep_count), + Avg(cd_dep_count), + Max(cd_dep_count), + cd_dep_employed_count, + Count(*) cnt2, + Stddev_samp(cd_dep_employed_count), + Avg(cd_dep_employed_count), + Max(cd_dep_employed_count), + cd_dep_college_count, + Count(*) cnt3, + Stddev_samp(cd_dep_college_count), + Avg(cd_dep_college_count), + Max(cd_dep_college_count) +FROM customer c, + customer_address ca, + customer_demographics +WHERE c.c_current_addr_sk = ca.ca_address_sk + AND cd_demo_sk = c.c_current_cdemo_sk + AND EXISTS (SELECT * + FROM store_sales, + date_dim + WHERE c.c_customer_sk = ss_customer_sk + AND ss_sold_date_sk = d_date_sk + AND d_year = 2001 + 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 = 2001 + 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 = 2001 + AND d_qoy < 4) ) +GROUP BY ca_state, + cd_gender, + cd_marital_status, + cd_dep_count, + cd_dep_employed_count, + cd_dep_college_count +ORDER BY ca_state, + cd_gender, + cd_marital_status, + cd_dep_count, + cd_dep_employed_count, + cd_dep_college_count +LIMIT 100; diff --git a/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query36.sql b/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query36.sql new file mode 100644 index 0000000000..300a445bc2 --- /dev/null +++ b/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query36.sql @@ -0,0 +1,31 @@ +-- start query 36 in stream 0 using template query36.tpl +SELECT Sum(ss_net_profit) / Sum(ss_ext_sales_price) AS + gross_margin, + i_category, + i_class, + Grouping(i_category) + Grouping(i_class) AS + lochierarchy, + Rank() + OVER ( + partition BY Grouping(i_category)+Grouping(i_class), CASE + WHEN Grouping( + i_class) = 0 THEN i_category END + ORDER BY Sum(ss_net_profit)/Sum(ss_ext_sales_price) ASC) AS + rank_within_parent +FROM store_sales, + date_dim d1, + item, + store +WHERE d1.d_year = 2000 + AND d1.d_date_sk = ss_sold_date_sk + AND i_item_sk = ss_item_sk + AND s_store_sk = ss_store_sk + AND s_state IN ( 'TN', 'TN', 'TN', 'TN', + 'TN', 'TN', 'TN', 'TN' ) +GROUP BY rollup( i_category, i_class ) +ORDER BY lochierarchy DESC, + CASE + WHEN lochierarchy = 0 THEN i_category + END, + rank_within_parent +LIMIT 100; diff --git a/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query37.sql b/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query37.sql new file mode 100644 index 0000000000..b6b6be029f --- /dev/null +++ b/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query37.sql @@ -0,0 +1,23 @@ +-- start query 37 in stream 0 using template query37.tpl +SELECT + i_item_id , + i_item_desc , + i_current_price +FROM item, + inventory, + date_dim, + catalog_sales +WHERE i_current_price BETWEEN 20 AND 20 + 30 +AND inv_item_sk = i_item_sk +AND d_date_sk=inv_date_sk +AND d_date BETWEEN Cast('1999-03-06' AS DATE) AND ( + Cast('1999-03-06' AS DATE) + INTERVAL '60' day) +AND i_manufact_id IN (843,815,850,840) +AND inv_quantity_on_hand BETWEEN 100 AND 500 +AND cs_item_sk = i_item_sk +GROUP BY i_item_id, + i_item_desc, + i_current_price +ORDER BY i_item_id +LIMIT 100; + diff --git a/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query38.sql b/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query38.sql new file mode 100644 index 0000000000..1e657d5721 --- /dev/null +++ b/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query38.sql @@ -0,0 +1,32 @@ +-- start query 38 in stream 0 using template query38.tpl +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 1188 AND 1188 + 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 1188 AND 1188 + 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 1188 AND 1188 + 11) hot_cust +LIMIT 100; diff --git a/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query39.sql b/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query39.sql new file mode 100644 index 0000000000..8625b9889d --- /dev/null +++ b/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query39.sql @@ -0,0 +1,117 @@ +-- start query 39 in stream 0 using template query39.tpl +WITH inv + AS (SELECT w_warehouse_name, + w_warehouse_sk, + i_item_sk, + d_moy, + stdev, + mean, + CASE mean + WHEN 0 THEN NULL + ELSE stdev / mean + END cov + FROM (SELECT w_warehouse_name, + w_warehouse_sk, + i_item_sk, + d_moy, + Stddev_samp(inv_quantity_on_hand) stdev, + Avg(inv_quantity_on_hand) mean + FROM inventory, + item, + warehouse, + date_dim + WHERE inv_item_sk = i_item_sk + AND inv_warehouse_sk = w_warehouse_sk + AND inv_date_sk = d_date_sk + AND d_year = 2002 + 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, + inv1.i_item_sk, + inv1.d_moy, + inv1.mean, + inv1.cov, + inv2.d_moy, + inv2.mean, + inv2.cov; + +WITH inv + AS (SELECT w_warehouse_name, + w_warehouse_sk, + i_item_sk, + d_moy, + stdev, + mean, + CASE mean + WHEN 0 THEN NULL + ELSE stdev / mean + END cov + FROM (SELECT w_warehouse_name, + w_warehouse_sk, + i_item_sk, + d_moy, + Stddev_samp(inv_quantity_on_hand) stdev, + Avg(inv_quantity_on_hand) mean + FROM inventory, + item, + warehouse, + date_dim + WHERE inv_item_sk = i_item_sk + AND inv_warehouse_sk = w_warehouse_sk + AND inv_date_sk = d_date_sk + AND d_year = 2002 + 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 > 1.5 +ORDER BY inv1.w_warehouse_sk, + inv1.i_item_sk, + inv1.d_moy, + inv1.mean, + inv1.cov, + inv2.d_moy, + inv2.mean, + inv2.cov; diff --git a/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query40.sql b/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query40.sql new file mode 100644 index 0000000000..ed4a5aab8f --- /dev/null +++ b/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query40.sql @@ -0,0 +1,36 @@ +-- start query 40 in stream 0 using template query40.tpl +SELECT + w_state , + i_item_id , + Sum( + CASE + WHEN ( + Cast(d_date AS DATE) < Cast ('2002-06-01' AS DATE)) THEN cs_sales_price - COALESCE(cr_refunded_cash,0) + ELSE 0 + END) AS sales_before , + Sum( + CASE + WHEN ( + Cast(d_date AS DATE) >= Cast ('2002-06-01' AS DATE)) THEN cs_sales_price - COALESCE(cr_refunded_cash,0) + ELSE 0 + END) AS sales_after +FROM catalog_sales +LEFT OUTER JOIN catalog_returns +ON ( + cs_order_number = cr_order_number + AND cs_item_sk = cr_item_sk) , + warehouse , + item , + date_dim +WHERE i_current_price BETWEEN 0.99 AND 1.49 +AND i_item_sk = cs_item_sk +AND cs_warehouse_sk = w_warehouse_sk +AND cs_sold_date_sk = d_date_sk +AND d_date BETWEEN (Cast ('2002-06-01' AS DATE) - INTERVAL '30' day) AND ( + cast ('2002-06-01' AS date) + INTERVAL '30' day) +GROUP BY w_state, + i_item_id +ORDER BY w_state, + i_item_id +LIMIT 100; + diff --git a/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query41.sql b/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query41.sql new file mode 100644 index 0000000000..8fb9149ea8 --- /dev/null +++ b/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query41.sql @@ -0,0 +1,66 @@ +-- start query 41 in stream 0 using template query41.tpl +SELECT Distinct(i_product_name) +FROM item i1 +WHERE i_manufact_id BETWEEN 765 AND 765 + 40 + AND (SELECT Count(*) AS item_cnt + FROM item + WHERE ( i_manufact = i1.i_manufact + AND ( ( i_category = 'Women' + AND ( i_color = 'dim' + OR i_color = 'green' ) + AND ( i_units = 'Gross' + OR i_units = 'Dozen' ) + AND ( i_size = 'economy' + OR i_size = 'petite' ) ) + OR ( i_category = 'Women' + AND ( i_color = 'navajo' + OR i_color = 'aquamarine' ) + AND ( i_units = 'Case' + OR i_units = 'Unknown' ) + AND ( i_size = 'large' + OR i_size = 'N/A' ) ) + OR ( i_category = 'Men' + AND ( i_color = 'indian' + OR i_color = 'dark' ) + AND ( i_units = 'Oz' + OR i_units = 'Lb' ) + AND ( i_size = 'extra large' + OR i_size = 'small' ) ) + OR ( i_category = 'Men' + AND ( i_color = 'peach' + OR i_color = 'purple' ) + AND ( i_units = 'Tbl' + OR i_units = 'Bunch' ) + AND ( i_size = 'economy' + OR i_size = 'petite' ) ) ) ) + OR ( i_manufact = i1.i_manufact + AND ( ( i_category = 'Women' + AND ( i_color = 'orchid' + OR i_color = 'peru' ) + AND ( i_units = 'Carton' + OR i_units = 'Cup' ) + AND ( i_size = 'economy' + OR i_size = 'petite' ) ) + OR ( i_category = 'Women' + AND ( i_color = 'violet' + OR i_color = 'papaya' ) + AND ( i_units = 'Ounce' + OR i_units = 'Box' ) + AND ( i_size = 'large' + OR i_size = 'N/A' ) ) + OR ( i_category = 'Men' + AND ( i_color = 'drab' + OR i_color = 'grey' ) + AND ( i_units = 'Each' + OR i_units = 'N/A' ) + AND ( i_size = 'extra large' + OR i_size = 'small' ) ) + OR ( i_category = 'Men' + AND ( i_color = 'chocolate' + OR i_color = 'antique' ) + AND ( i_units = 'Dram' + OR i_units = 'Gram' ) + AND ( i_size = 'economy' + OR i_size = 'petite' ) ) ) )) > 0 +ORDER BY i_product_name +LIMIT 100; diff --git a/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query42.sql b/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query42.sql new file mode 100644 index 0000000000..47dab17171 --- /dev/null +++ b/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query42.sql @@ -0,0 +1,21 @@ +-- start query 42 in stream 0 using template query42.tpl +SELECT dt.d_year, + item.i_category_id, + item.i_category, + Sum(ss_ext_sales_price) +FROM date_dim dt, + store_sales, + item +WHERE dt.d_date_sk = store_sales.ss_sold_date_sk + AND store_sales.ss_item_sk = item.i_item_sk + AND item.i_manager_id = 1 + AND dt.d_moy = 12 + AND dt.d_year = 2000 +GROUP BY dt.d_year, + item.i_category_id, + item.i_category +ORDER BY Sum(ss_ext_sales_price) DESC, + dt.d_year, + item.i_category_id, + item.i_category +LIMIT 100; diff --git a/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query43.sql b/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query43.sql new file mode 100644 index 0000000000..dbb40165ed --- /dev/null +++ b/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query43.sql @@ -0,0 +1,50 @@ +-- start query 43 in stream 0 using template query43.tpl +SELECT s_store_name, + s_store_id, + Sum(CASE + WHEN ( d_day_name = 'Sunday' ) THEN ss_sales_price + ELSE NULL + END) sun_sales, + Sum(CASE + WHEN ( d_day_name = 'Monday' ) THEN ss_sales_price + ELSE NULL + END) mon_sales, + Sum(CASE + WHEN ( d_day_name = 'Tuesday' ) THEN ss_sales_price + ELSE NULL + END) tue_sales, + Sum(CASE + WHEN ( d_day_name = 'Wednesday' ) THEN ss_sales_price + ELSE NULL + END) wed_sales, + Sum(CASE + WHEN ( d_day_name = 'Thursday' ) THEN ss_sales_price + ELSE NULL + END) thu_sales, + Sum(CASE + WHEN ( d_day_name = 'Friday' ) THEN ss_sales_price + ELSE NULL + END) fri_sales, + Sum(CASE + WHEN ( d_day_name = 'Saturday' ) THEN ss_sales_price + ELSE NULL + END) sat_sales +FROM date_dim, + store_sales, + store +WHERE d_date_sk = ss_sold_date_sk + AND s_store_sk = ss_store_sk + AND s_gmt_offset = -5 + AND d_year = 2002 +GROUP BY s_store_name, + s_store_id +ORDER BY s_store_name, + s_store_id, + sun_sales, + mon_sales, + tue_sales, + wed_sales, + thu_sales, + fri_sales, + sat_sales +LIMIT 100; diff --git a/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query44.sql b/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query44.sql new file mode 100644 index 0000000000..fb8bd520e0 --- /dev/null +++ b/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query44.sql @@ -0,0 +1,51 @@ +-- start query 44 in stream 0 using template query44.tpl +SELECT asceding.rnk, + i1.i_product_name best_performing, + i2.i_product_name worst_performing +FROM (SELECT * + FROM (SELECT item_sk, + Rank() + OVER ( + ORDER BY rank_col ASC) rnk + FROM (SELECT ss_item_sk item_sk, + Avg(ss_net_profit) rank_col + FROM store_sales ss1 + WHERE ss_store_sk = 4 + GROUP BY ss_item_sk + HAVING Avg(ss_net_profit) > 0.9 * + (SELECT Avg(ss_net_profit) + rank_col + FROM store_sales + WHERE ss_store_sk = 4 + AND ss_cdemo_sk IS + NULL + GROUP BY ss_store_sk))V1) + V11 + WHERE rnk < 11) asceding, + (SELECT * + FROM (SELECT item_sk, + Rank() + OVER ( + ORDER BY rank_col DESC) rnk + FROM (SELECT ss_item_sk item_sk, + Avg(ss_net_profit) rank_col + FROM store_sales ss1 + WHERE ss_store_sk = 4 + GROUP BY ss_item_sk + HAVING Avg(ss_net_profit) > 0.9 * + (SELECT Avg(ss_net_profit) + rank_col + FROM store_sales + WHERE ss_store_sk = 4 + AND ss_cdemo_sk IS + NULL + GROUP BY ss_store_sk))V2) + V21 + WHERE rnk < 11) descending, + item i1, + item i2 +WHERE asceding.rnk = descending.rnk + AND i1.i_item_sk = asceding.item_sk + AND i2.i_item_sk = descending.item_sk +ORDER BY asceding.rnk +LIMIT 100; diff --git a/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query45.sql b/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query45.sql new file mode 100644 index 0000000000..90454bc211 --- /dev/null +++ b/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query45.sql @@ -0,0 +1,28 @@ +-- start query 45 in stream 0 using template query45.tpl +SELECT ca_zip, + ca_state, + Sum(ws_sales_price) +FROM web_sales, + customer, + customer_address, + date_dim, + item +WHERE ws_bill_customer_sk = c_customer_sk + AND c_current_addr_sk = ca_address_sk + AND ws_item_sk = i_item_sk + AND ( Substr(ca_zip, 1, 5) IN ( '85669', '86197', '88274', '83405', + '86475', '85392', '85460', '80348', + '81792' ) + OR i_item_id IN (SELECT i_item_id + FROM item + WHERE i_item_sk IN ( 2, 3, 5, 7, + 11, 13, 17, 19, + 23, 29 )) ) + AND ws_sold_date_sk = d_date_sk + AND d_qoy = 1 + AND d_year = 2000 +GROUP BY ca_zip, + ca_state +ORDER BY ca_zip, + ca_state +LIMIT 100; diff --git a/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query46.sql b/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query46.sql new file mode 100644 index 0000000000..3562694eda --- /dev/null +++ b/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query46.sql @@ -0,0 +1,44 @@ +-- start query 46 in stream 0 using template query46.tpl +SELECT c_last_name, + c_first_name, + ca_city, + bought_city, + ss_ticket_number, + amt, + profit +FROM (SELECT ss_ticket_number, + ss_customer_sk, + ca_city bought_city, + Sum(ss_coupon_amt) amt, + Sum(ss_net_profit) profit + FROM store_sales, + date_dim, + store, + household_demographics, + customer_address + WHERE store_sales.ss_sold_date_sk = date_dim.d_date_sk + AND store_sales.ss_store_sk = store.s_store_sk + AND store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk + AND store_sales.ss_addr_sk = customer_address.ca_address_sk + AND ( household_demographics.hd_dep_count = 6 + OR household_demographics.hd_vehicle_count = 0 ) + AND date_dim.d_dow IN ( 6, 0 ) + AND date_dim.d_year IN ( 2000, 2000 + 1, 2000 + 2 ) + AND store.s_city IN ( 'Midway', 'Fairview', 'Fairview', + 'Fairview', + 'Fairview' ) + GROUP BY ss_ticket_number, + ss_customer_sk, + ss_addr_sk, + ca_city) dn, + customer, + customer_address current_addr +WHERE ss_customer_sk = c_customer_sk + AND customer.c_current_addr_sk = current_addr.ca_address_sk + AND current_addr.ca_city <> bought_city +ORDER BY c_last_name, + c_first_name, + ca_city, + bought_city, + ss_ticket_number +LIMIT 100; diff --git a/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query47.sql b/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query47.sql new file mode 100644 index 0000000000..07e18cb3c7 --- /dev/null +++ b/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query47.sql @@ -0,0 +1,72 @@ +-- start query 47 in stream 0 using template query47.tpl +WITH v1 + AS (SELECT i_category, + i_brand, + s_store_name, + s_company_name, + d_year, + d_moy, + Sum(ss_sales_price) sum_sales, + Avg(Sum(ss_sales_price)) + OVER ( + partition BY i_category, i_brand, s_store_name, + s_company_name, + d_year) + avg_monthly_sales, + Rank() + OVER ( + partition BY i_category, i_brand, s_store_name, + s_company_name + ORDER BY d_year, d_moy) rn + FROM item, + store_sales, + date_dim, + store + WHERE ss_item_sk = i_item_sk + AND ss_sold_date_sk = d_date_sk + AND ss_store_sk = s_store_sk + AND ( d_year = 1999 + OR ( d_year = 1999 - 1 + AND d_moy = 12 ) + OR ( d_year = 1999 + 1 + AND d_moy = 1 ) ) + GROUP BY i_category, + i_brand, + s_store_name, + s_company_name, + d_year, + d_moy), + v2 + AS (SELECT v1.i_category, + v1.d_year, + v1.d_moy, + v1.avg_monthly_sales, + v1.sum_sales, + v1_lag.sum_sales psum, + v1_lead.sum_sales nsum + FROM v1, + v1 v1_lag, + v1 v1_lead + WHERE v1.i_category = v1_lag.i_category + AND v1.i_category = v1_lead.i_category + AND v1.i_brand = v1_lag.i_brand + AND v1.i_brand = v1_lead.i_brand + AND v1.s_store_name = v1_lag.s_store_name + AND v1.s_store_name = v1_lead.s_store_name + AND v1.s_company_name = v1_lag.s_company_name + AND v1.s_company_name = v1_lead.s_company_name + AND v1.rn = v1_lag.rn + 1 + AND v1.rn = v1_lead.rn - 1) +SELECT * +FROM v2 +WHERE d_year = 1999 + AND avg_monthly_sales > 0 + AND CASE + WHEN avg_monthly_sales > 0 THEN Abs(sum_sales - avg_monthly_sales) + / + avg_monthly_sales + ELSE NULL + END > 0.1 +ORDER BY sum_sales - avg_monthly_sales, + 3 +LIMIT 100; diff --git a/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query48.sql b/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query48.sql new file mode 100644 index 0000000000..a28febaf6a --- /dev/null +++ b/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query48.sql @@ -0,0 +1,34 @@ +-- start query 48 in stream 0 using template query48.tpl +SELECT Sum (ss_quantity) +FROM store_sales, + store, + customer_demographics, + customer_address, + date_dim +WHERE s_store_sk = ss_store_sk + AND ss_sold_date_sk = d_date_sk + AND d_year = 1999 + AND ( ( cd_demo_sk = ss_cdemo_sk + AND cd_marital_status = 'W' + AND cd_education_status = 'Secondary' + AND ss_sales_price BETWEEN 100.00 AND 150.00 ) + OR ( cd_demo_sk = ss_cdemo_sk + AND cd_marital_status = 'M' + AND cd_education_status = 'Advanced Degree' + AND ss_sales_price BETWEEN 50.00 AND 100.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 150.00 AND 200.00 ) ) + AND ( ( ss_addr_sk = ca_address_sk + AND ca_country = 'United States' + AND ca_state IN ( 'TX', 'NE', 'MO' ) + AND ss_net_profit BETWEEN 0 AND 2000 ) + OR ( ss_addr_sk = ca_address_sk + AND ca_country = 'United States' + AND ca_state IN ( 'CO', 'TN', 'ND' ) + AND ss_net_profit BETWEEN 150 AND 3000 ) + OR ( ss_addr_sk = ca_address_sk + AND ca_country = 'United States' + AND ca_state IN ( 'OK', 'PA', 'CA' ) + AND ss_net_profit BETWEEN 50 AND 25000 ) ); diff --git a/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query49.sql b/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query49.sql new file mode 100644 index 0000000000..81cf939432 --- /dev/null +++ b/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query49.sql @@ -0,0 +1,133 @@ +-- start query 49 in stream 0 using template query49.tpl +SELECT 'web' AS channel, + web.item, + web.return_ratio, + web.return_rank, + web.currency_rank +FROM (SELECT item, + return_ratio, + currency_ratio, + Rank() + OVER ( + ORDER BY return_ratio) AS return_rank, + Rank() + OVER ( + ORDER BY currency_ratio) AS currency_rank + FROM (SELECT ws.ws_item_sk AS + item, + ( Cast(Sum(COALESCE(wr.wr_return_quantity, 0)) AS DEC(15, + 4)) / + Cast( + Sum(COALESCE(ws.ws_quantity, 0)) AS DEC(15, 4)) ) AS + return_ratio, + ( Cast(Sum(COALESCE(wr.wr_return_amt, 0)) AS DEC(15, 4)) + / Cast( + Sum( + COALESCE(ws.ws_net_paid, 0)) AS DEC(15, + 4)) ) AS + currency_ratio + FROM web_sales ws + LEFT OUTER JOIN web_returns wr + ON ( ws.ws_order_number = wr.wr_order_number + AND ws.ws_item_sk = wr.wr_item_sk ), + date_dim + WHERE wr.wr_return_amt > 10000 + AND ws.ws_net_profit > 1 + AND ws.ws_net_paid > 0 + AND ws.ws_quantity > 0 + AND ws_sold_date_sk = d_date_sk + AND d_year = 1999 + AND d_moy = 12 + GROUP BY ws.ws_item_sk) in_web) web +WHERE ( web.return_rank <= 10 + OR web.currency_rank <= 10 ) +UNION +SELECT 'catalog' AS channel, + catalog.item, + catalog.return_ratio, + catalog.return_rank, + catalog.currency_rank +FROM (SELECT item, + return_ratio, + currency_ratio, + Rank() + OVER ( + ORDER BY return_ratio) AS return_rank, + Rank() + OVER ( + ORDER BY currency_ratio) AS currency_rank + FROM (SELECT cs.cs_item_sk AS + item, + ( Cast(Sum(COALESCE(cr.cr_return_quantity, 0)) AS DEC(15, + 4)) / + Cast( + Sum(COALESCE(cs.cs_quantity, 0)) AS DEC(15, 4)) ) AS + return_ratio, + ( Cast(Sum(COALESCE(cr.cr_return_amount, 0)) AS DEC(15, 4 + )) / + Cast(Sum( + COALESCE(cs.cs_net_paid, 0)) AS DEC( + 15, 4)) ) AS + currency_ratio + FROM catalog_sales cs + LEFT OUTER JOIN catalog_returns cr + ON ( cs.cs_order_number = cr.cr_order_number + AND cs.cs_item_sk = cr.cr_item_sk ), + date_dim + WHERE cr.cr_return_amount > 10000 + AND cs.cs_net_profit > 1 + AND cs.cs_net_paid > 0 + AND cs.cs_quantity > 0 + AND cs_sold_date_sk = d_date_sk + AND d_year = 1999 + AND d_moy = 12 + GROUP BY cs.cs_item_sk) in_cat) catalog +WHERE ( catalog.return_rank <= 10 + OR catalog.currency_rank <= 10 ) +UNION +SELECT 'store' AS channel, + store.item, + store.return_ratio, + store.return_rank, + store.currency_rank +FROM (SELECT item, + return_ratio, + currency_ratio, + Rank() + OVER ( + ORDER BY return_ratio) AS return_rank, + Rank() + OVER ( + ORDER BY currency_ratio) AS currency_rank + FROM (SELECT sts.ss_item_sk AS + item, + ( Cast(Sum(COALESCE(sr.sr_return_quantity, 0)) AS DEC(15, + 4)) / + Cast( + Sum(COALESCE(sts.ss_quantity, 0)) AS DEC(15, 4)) ) AS + return_ratio, + ( Cast(Sum(COALESCE(sr.sr_return_amt, 0)) AS DEC(15, 4)) + / Cast( + Sum( + COALESCE(sts.ss_net_paid, 0)) AS DEC(15, 4)) ) AS + currency_ratio + FROM store_sales sts + LEFT OUTER JOIN store_returns sr + ON ( sts.ss_ticket_number = + sr.sr_ticket_number + AND sts.ss_item_sk = sr.sr_item_sk ), + date_dim + WHERE sr.sr_return_amt > 10000 + AND sts.ss_net_profit > 1 + AND sts.ss_net_paid > 0 + AND sts.ss_quantity > 0 + AND ss_sold_date_sk = d_date_sk + AND d_year = 1999 + AND d_moy = 12 + GROUP BY sts.ss_item_sk) in_store) store +WHERE ( store.return_rank <= 10 + OR store.currency_rank <= 10 ) +ORDER BY 1, + 4, + 5 +LIMIT 100; diff --git a/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query50.sql b/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query50.sql new file mode 100644 index 0000000000..fd4bbc7994 --- /dev/null +++ b/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query50.sql @@ -0,0 +1,71 @@ +-- start query 50 in stream 0 using template query50.tpl +SELECT s_store_name, + s_company_id, + s_street_number, + s_street_name, + s_street_type, + s_suite_number, + s_city, + s_county, + s_state, + s_zip, + Sum(CASE + WHEN ( sr_returned_date_sk - ss_sold_date_sk <= 30 ) THEN 1 + ELSE 0 + END) AS `30 days`, + Sum(CASE + WHEN ( sr_returned_date_sk - ss_sold_date_sk > 30 ) + AND ( sr_returned_date_sk - ss_sold_date_sk <= 60 ) + THEN 1 + ELSE 0 + END) AS `31-60 days`, + Sum(CASE + WHEN ( sr_returned_date_sk - ss_sold_date_sk > 60 ) + AND ( sr_returned_date_sk - ss_sold_date_sk <= 90 ) + THEN 1 + ELSE 0 + END) AS `61-90 days`, + Sum(CASE + WHEN ( sr_returned_date_sk - ss_sold_date_sk > 90 ) + AND ( sr_returned_date_sk - ss_sold_date_sk <= 120 ) + THEN 1 + ELSE 0 + END) AS `91-120 days`, + Sum(CASE + WHEN ( sr_returned_date_sk - ss_sold_date_sk > 120 ) THEN 1 + ELSE 0 + END) AS `>120 days` +FROM store_sales, + store_returns, + store, + date_dim d1, + date_dim d2 +WHERE d2.d_year = 2002 + AND d2.d_moy = 9 + AND ss_ticket_number = sr_ticket_number + AND ss_item_sk = sr_item_sk + AND ss_sold_date_sk = d1.d_date_sk + AND sr_returned_date_sk = d2.d_date_sk + AND ss_customer_sk = sr_customer_sk + AND ss_store_sk = s_store_sk +GROUP BY s_store_name, + s_company_id, + s_street_number, + s_street_name, + s_street_type, + s_suite_number, + s_city, + s_county, + s_state, + s_zip +ORDER BY s_store_name, + s_company_id, + s_street_number, + s_street_name, + s_street_type, + s_suite_number, + s_city, + s_county, + s_state, + s_zip +LIMIT 100; diff --git a/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query51.sql b/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query51.sql new file mode 100644 index 0000000000..2f84ca3fab --- /dev/null +++ b/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query51.sql @@ -0,0 +1,55 @@ +-- start query 51 in stream 0 using template query51.tpl +WITH web_v1 AS +( + SELECT ws_item_sk item_sk, + d_date, + sum(Sum(ws_sales_price)) OVER (partition BY ws_item_sk ORDER BY d_date rows BETWEEN UNBOUNDED PRECEDING AND CURRENT row) cume_sales + FROM web_sales , + date_dim + WHERE ws_sold_date_sk=d_date_sk + AND d_month_seq BETWEEN 1192 AND 1192+11 + AND ws_item_sk IS NOT NULL + GROUP BY ws_item_sk, + d_date), store_v1 AS +( + SELECT ss_item_sk item_sk, + d_date, + sum(sum(ss_sales_price)) OVER (partition BY ss_item_sk ORDER BY d_date rows BETWEEN UNBOUNDED PRECEDING AND CURRENT row) cume_sales + FROM store_sales , + date_dim + WHERE ss_sold_date_sk=d_date_sk + AND d_month_seq BETWEEN 1192 AND 1192+11 + AND ss_item_sk IS NOT NULL + GROUP BY ss_item_sk, + d_date) +SELECT + * +FROM ( + SELECT item_sk , + d_date , + web_sales , + store_sales , + max(web_sales) OVER (partition BY item_sk ORDER BY d_date rows BETWEEN UNBOUNDED PRECEDING AND CURRENT row) web_cumulative , + max(store_sales) OVER (partition BY item_sk ORDER BY d_date rows BETWEEN UNBOUNDED PRECEDING AND CURRENT row) store_cumulative + FROM ( + SELECT + CASE + WHEN web.item_sk IS NOT NULL THEN web.item_sk + ELSE store.item_sk + END item_sk , + CASE + WHEN web.d_date IS NOT NULL THEN web.d_date + ELSE store.d_date + END d_date , + web.cume_sales web_sales , + store.cume_sales store_sales + FROM web_v1 web + FULL OUTER JOIN store_v1 store + ON ( + web.item_sk = store.item_sk + AND web.d_date = store.d_date) )x )y +WHERE web_cumulative > store_cumulative +ORDER BY item_sk , + d_date +LIMIT 100; + diff --git a/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query52.sql b/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query52.sql new file mode 100644 index 0000000000..685cc9e002 --- /dev/null +++ b/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query52.sql @@ -0,0 +1,20 @@ +-- start query 52 in stream 0 using template query52.tpl +SELECT dt.d_year, + item.i_brand_id brand_id, + item.i_brand brand, + Sum(ss_ext_sales_price) ext_price +FROM date_dim dt, + store_sales, + item +WHERE dt.d_date_sk = store_sales.ss_sold_date_sk + AND store_sales.ss_item_sk = item.i_item_sk + AND item.i_manager_id = 1 + AND dt.d_moy = 11 + AND dt.d_year = 1999 +GROUP BY dt.d_year, + item.i_brand, + item.i_brand_id +ORDER BY dt.d_year, + ext_price DESC, + brand_id +LIMIT 100; diff --git a/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query53.sql b/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query53.sql new file mode 100644 index 0000000000..5bd5ff047b --- /dev/null +++ b/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query53.sql @@ -0,0 +1,46 @@ +-- start query 53 in stream 0 using template query53.tpl +SELECT * +FROM (SELECT i_manufact_id, + Sum(ss_sales_price) sum_sales, + Avg(Sum(ss_sales_price)) + OVER ( + partition BY i_manufact_id) avg_quarterly_sales + FROM item, + store_sales, + date_dim, + store + WHERE ss_item_sk = i_item_sk + AND ss_sold_date_sk = d_date_sk + AND ss_store_sk = s_store_sk + AND d_month_seq IN ( 1199, 1199 + 1, 1199 + 2, 1199 + 3, + 1199 + 4, 1199 + 5, 1199 + 6, 1199 + 7, + 1199 + 8, 1199 + 9, 1199 + 10, 1199 + 11 ) + AND ( ( i_category IN ( 'Books', 'Children', 'Electronics' ) + AND i_class IN ( 'personal', 'portable', 'reference', + 'self-help' ) + AND i_brand IN ( 'scholaramalgamalg #14', + 'scholaramalgamalg #7' + , + 'exportiunivamalg #9', + 'scholaramalgamalg #9' ) + ) + OR ( i_category IN ( 'Women', 'Music', 'Men' ) + AND i_class IN ( 'accessories', 'classical', + 'fragrances', + 'pants' ) + AND i_brand IN ( 'amalgimporto #1', + 'edu packscholar #1', + 'exportiimporto #1', + 'importoamalg #1' ) ) ) + GROUP BY i_manufact_id, + d_qoy) tmp1 +WHERE CASE + WHEN avg_quarterly_sales > 0 THEN Abs (sum_sales - avg_quarterly_sales) + / + avg_quarterly_sales + ELSE NULL + END > 0.1 +ORDER BY avg_quarterly_sales, + sum_sales, + i_manufact_id +LIMIT 100; diff --git a/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query54.sql b/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query54.sql new file mode 100644 index 0000000000..951c5dd677 --- /dev/null +++ b/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query54.sql @@ -0,0 +1,57 @@ +-- start query 54 in stream 0 using template query54.tpl +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 = 'Sports' + AND i_class = 'fitness' + AND c_customer_sk = cs_or_ws_sales.customer_sk + AND d_moy = 5 + AND d_year = 2000), + my_revenue + AS (SELECT c_customer_sk, + Sum(ss_ext_sales_price) AS revenue + FROM my_customers, + store_sales, + customer_address, + store, + date_dim + WHERE c_current_addr_sk = ca_address_sk + AND ca_county = s_county + AND ca_state = s_state + AND ss_sold_date_sk = d_date_sk + AND c_customer_sk = ss_customer_sk + AND d_month_seq BETWEEN (SELECT DISTINCT d_month_seq + 1 + FROM date_dim + WHERE d_year = 2000 + AND d_moy = 5) AND + (SELECT DISTINCT + d_month_seq + 3 + FROM date_dim + WHERE d_year = 2000 + AND d_moy = 5) + GROUP BY c_customer_sk), + segments + AS (SELECT Cast(( revenue / 50 ) AS INT) AS segment + FROM my_revenue) +SELECT segment, + Count(*) AS num_customers, + segment * 50 AS segment_base +FROM segments +GROUP BY segment +ORDER BY segment, + num_customers +LIMIT 100; diff --git a/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query55.sql b/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query55.sql new file mode 100644 index 0000000000..0746ad4ee6 --- /dev/null +++ b/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query55.sql @@ -0,0 +1,17 @@ +-- start query 55 in stream 0 using template query55.tpl +SELECT i_brand_id brand_id, + i_brand brand, + Sum(ss_ext_sales_price) ext_price +FROM date_dim, + store_sales, + item +WHERE d_date_sk = ss_sold_date_sk + AND ss_item_sk = i_item_sk + AND i_manager_id = 33 + AND d_moy = 12 + AND d_year = 1998 +GROUP BY i_brand, + i_brand_id +ORDER BY ext_price DESC, + i_brand_id +LIMIT 100; diff --git a/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query56.sql b/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query56.sql new file mode 100644 index 0000000000..617c209ebf --- /dev/null +++ b/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query56.sql @@ -0,0 +1,68 @@ +-- start query 56 in stream 0 using template query56.tpl +WITH ss + AS (SELECT i_item_id, + Sum(ss_ext_sales_price) total_sales + FROM store_sales, + date_dim, + customer_address, + item + WHERE i_item_id IN (SELECT i_item_id + FROM item + WHERE i_color IN ( 'firebrick', 'rosy', 'white' ) + ) + AND ss_item_sk = i_item_sk + AND ss_sold_date_sk = d_date_sk + AND d_year = 1998 + AND d_moy = 3 + AND ss_addr_sk = ca_address_sk + AND ca_gmt_offset = -6 + GROUP BY i_item_id), + cs + AS (SELECT i_item_id, + Sum(cs_ext_sales_price) total_sales + FROM catalog_sales, + date_dim, + customer_address, + item + WHERE i_item_id IN (SELECT i_item_id + FROM item + WHERE i_color IN ( 'firebrick', 'rosy', 'white' ) + ) + AND cs_item_sk = i_item_sk + AND cs_sold_date_sk = d_date_sk + AND d_year = 1998 + AND d_moy = 3 + AND cs_bill_addr_sk = ca_address_sk + AND ca_gmt_offset = -6 + GROUP BY i_item_id), + ws + AS (SELECT i_item_id, + Sum(ws_ext_sales_price) total_sales + FROM web_sales, + date_dim, + customer_address, + item + WHERE i_item_id IN (SELECT i_item_id + FROM item + WHERE i_color IN ( 'firebrick', 'rosy', 'white' ) + ) + AND ws_item_sk = i_item_sk + AND ws_sold_date_sk = d_date_sk + AND d_year = 1998 + AND d_moy = 3 + AND ws_bill_addr_sk = ca_address_sk + AND ca_gmt_offset = -6 + GROUP BY i_item_id) +SELECT i_item_id, + Sum(total_sales) total_sales +FROM (SELECT * + FROM ss + UNION ALL + SELECT * + FROM cs + UNION ALL + SELECT * + FROM ws) tmp1 +GROUP BY i_item_id +ORDER BY total_sales +LIMIT 100; diff --git a/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query57.sql b/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query57.sql new file mode 100644 index 0000000000..578d15c7e2 --- /dev/null +++ b/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query57.sql @@ -0,0 +1,66 @@ +-- start query 57 in stream 0 using template query57.tpl +WITH v1 + AS (SELECT i_category, + i_brand, + cc_name, + d_year, + d_moy, + Sum(cs_sales_price) sum_sales + , + Avg(Sum(cs_sales_price)) + OVER ( + partition BY i_category, i_brand, cc_name, d_year) + avg_monthly_sales + , + Rank() + OVER ( + partition BY i_category, i_brand, cc_name + ORDER BY d_year, d_moy) rn + FROM item, + catalog_sales, + date_dim, + call_center + WHERE cs_item_sk = i_item_sk + AND cs_sold_date_sk = d_date_sk + AND cc_call_center_sk = cs_call_center_sk + AND ( d_year = 2000 + OR ( d_year = 2000 - 1 + AND d_moy = 12 ) + OR ( d_year = 2000 + 1 + AND d_moy = 1 ) ) + GROUP BY i_category, + i_brand, + cc_name, + d_year, + d_moy), + v2 + AS (SELECT v1.i_brand, + v1.d_year, + 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 = 2000 + AND avg_monthly_sales > 0 + AND CASE + WHEN avg_monthly_sales > 0 THEN Abs(sum_sales - avg_monthly_sales) + / + avg_monthly_sales + ELSE NULL + END > 0.1 +ORDER BY sum_sales - avg_monthly_sales, + 3 +LIMIT 100; diff --git a/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query58.sql b/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query58.sql new file mode 100644 index 0000000000..1fb22afc43 --- /dev/null +++ b/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query58.sql @@ -0,0 +1,72 @@ +-- start query 58 in stream 0 using template query58.tpl +WITH ss_items + AS (SELECT i_item_id item_id, + Sum(ss_ext_sales_price) ss_item_rev + FROM store_sales, + item, + date_dim + WHERE ss_item_sk = i_item_sk + AND d_date IN (SELECT d_date + FROM date_dim + WHERE d_week_seq = (SELECT d_week_seq + FROM date_dim + WHERE d_date = '2002-02-25' + )) + AND ss_sold_date_sk = d_date_sk + GROUP BY i_item_id), + cs_items + AS (SELECT i_item_id item_id, + Sum(cs_ext_sales_price) cs_item_rev + FROM catalog_sales, + item, + date_dim + WHERE cs_item_sk = i_item_sk + AND d_date IN (SELECT d_date + FROM date_dim + WHERE d_week_seq = (SELECT d_week_seq + FROM date_dim + WHERE d_date = '2002-02-25' + )) + AND cs_sold_date_sk = d_date_sk + GROUP BY i_item_id), + ws_items + AS (SELECT i_item_id item_id, + Sum(ws_ext_sales_price) ws_item_rev + FROM web_sales, + item, + date_dim + WHERE ws_item_sk = i_item_sk + AND d_date IN (SELECT d_date + FROM date_dim + WHERE d_week_seq = (SELECT d_week_seq + FROM date_dim + WHERE d_date = '2002-02-25' + )) + AND ws_sold_date_sk = d_date_sk + GROUP BY i_item_id) +SELECT ss_items.item_id, + ss_item_rev, + ss_item_rev / ( ss_item_rev + cs_item_rev + ws_item_rev ) / 3 * + 100 ss_dev, + cs_item_rev, + cs_item_rev / ( ss_item_rev + cs_item_rev + ws_item_rev ) / 3 * + 100 cs_dev, + ws_item_rev, + ws_item_rev / ( ss_item_rev + cs_item_rev + ws_item_rev ) / 3 * + 100 ws_dev, + ( ss_item_rev + cs_item_rev + ws_item_rev ) / 3 + average +FROM ss_items, + cs_items, + ws_items +WHERE ss_items.item_id = cs_items.item_id + AND ss_items.item_id = ws_items.item_id + AND ss_item_rev BETWEEN 0.9 * cs_item_rev AND 1.1 * cs_item_rev + AND ss_item_rev BETWEEN 0.9 * ws_item_rev AND 1.1 * ws_item_rev + AND cs_item_rev BETWEEN 0.9 * ss_item_rev AND 1.1 * ss_item_rev + AND cs_item_rev BETWEEN 0.9 * ws_item_rev AND 1.1 * ws_item_rev + AND ws_item_rev BETWEEN 0.9 * ss_item_rev AND 1.1 * ss_item_rev + AND ws_item_rev BETWEEN 0.9 * cs_item_rev AND 1.1 * cs_item_rev +ORDER BY item_id, + ss_item_rev +LIMIT 100; diff --git a/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query59.sql b/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query59.sql new file mode 100644 index 0000000000..baf7a08865 --- /dev/null +++ b/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query59.sql @@ -0,0 +1,85 @@ +-- start query 59 in stream 0 using template query59.tpl +WITH wss + AS (SELECT d_week_seq, + ss_store_sk, + Sum(CASE + WHEN ( d_day_name = 'Sunday' ) THEN ss_sales_price + ELSE NULL + END) sun_sales, + Sum(CASE + WHEN ( d_day_name = 'Monday' ) THEN ss_sales_price + ELSE NULL + END) mon_sales, + Sum(CASE + WHEN ( d_day_name = 'Tuesday' ) THEN ss_sales_price + ELSE NULL + END) tue_sales, + Sum(CASE + WHEN ( d_day_name = 'Wednesday' ) THEN ss_sales_price + ELSE NULL + END) wed_sales, + Sum(CASE + WHEN ( d_day_name = 'Thursday' ) THEN ss_sales_price + ELSE NULL + END) thu_sales, + Sum(CASE + WHEN ( d_day_name = 'Friday' ) THEN ss_sales_price + ELSE NULL + END) fri_sales, + Sum(CASE + WHEN ( d_day_name = 'Saturday' ) THEN ss_sales_price + ELSE NULL + END) sat_sales + FROM store_sales, + date_dim + WHERE d_date_sk = ss_sold_date_sk + GROUP BY d_week_seq, + ss_store_sk) +SELECT s_store_name1, + s_store_id1, + d_week_seq1, + sun_sales1 / sun_sales2, + mon_sales1 / mon_sales2, + tue_sales1 / tue_sales2, + wed_sales1 / wed_sales2, + thu_sales1 / thu_sales2, + fri_sales1 / fri_sales2, + sat_sales1 / sat_sales2 +FROM (SELECT s_store_name s_store_name1, + wss.d_week_seq d_week_seq1, + s_store_id s_store_id1, + sun_sales sun_sales1, + mon_sales mon_sales1, + tue_sales tue_sales1, + wed_sales wed_sales1, + thu_sales thu_sales1, + fri_sales fri_sales1, + sat_sales sat_sales1 + FROM wss, + store, + date_dim d + WHERE d.d_week_seq = wss.d_week_seq + AND ss_store_sk = s_store_sk + AND d_month_seq BETWEEN 1196 AND 1196 + 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 1196 + 12 AND 1196 + 23) x +WHERE s_store_id1 = s_store_id2 + AND d_week_seq1 = d_week_seq2 - 52 +ORDER BY s_store_name1, + s_store_id1, + d_week_seq1 +LIMIT 100; diff --git a/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query60.sql b/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query60.sql new file mode 100644 index 0000000000..a7f480b8a7 --- /dev/null +++ b/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query60.sql @@ -0,0 +1,66 @@ +-- start query 60 in stream 0 using template query60.tpl +WITH ss + AS (SELECT i_item_id, + Sum(ss_ext_sales_price) total_sales + FROM store_sales, + date_dim, + customer_address, + item + WHERE i_item_id IN (SELECT i_item_id + FROM item + WHERE i_category IN ( 'Jewelry' )) + AND ss_item_sk = i_item_sk + AND ss_sold_date_sk = d_date_sk + AND d_year = 1999 + AND d_moy = 8 + AND ss_addr_sk = ca_address_sk + AND ca_gmt_offset = -6 + GROUP BY i_item_id), + cs + AS (SELECT i_item_id, + Sum(cs_ext_sales_price) total_sales + FROM catalog_sales, + date_dim, + customer_address, + item + WHERE i_item_id IN (SELECT i_item_id + FROM item + WHERE i_category IN ( 'Jewelry' )) + AND cs_item_sk = i_item_sk + AND cs_sold_date_sk = d_date_sk + AND d_year = 1999 + AND d_moy = 8 + AND cs_bill_addr_sk = ca_address_sk + AND ca_gmt_offset = -6 + GROUP BY i_item_id), + ws + AS (SELECT i_item_id, + Sum(ws_ext_sales_price) total_sales + FROM web_sales, + date_dim, + customer_address, + item + WHERE i_item_id IN (SELECT i_item_id + FROM item + WHERE i_category IN ( 'Jewelry' )) + AND ws_item_sk = i_item_sk + AND ws_sold_date_sk = d_date_sk + AND d_year = 1999 + AND d_moy = 8 + AND ws_bill_addr_sk = ca_address_sk + AND ca_gmt_offset = -6 + GROUP BY i_item_id) +SELECT i_item_id, + Sum(total_sales) total_sales +FROM (SELECT * + FROM ss + UNION ALL + SELECT * + FROM cs + UNION ALL + SELECT * + FROM ws) tmp1 +GROUP BY i_item_id +ORDER BY i_item_id, + total_sales +LIMIT 100; diff --git a/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query61.sql b/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query61.sql new file mode 100644 index 0000000000..bd9c4cd5e8 --- /dev/null +++ b/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query61.sql @@ -0,0 +1,47 @@ +-- start query 61 in stream 0 using template query61.tpl +SELECT promotions, + total, + Cast(promotions AS DECIMAL(15, 4)) / + Cast(total AS DECIMAL(15, 4)) * 100 +FROM (SELECT Sum(ss_ext_sales_price) promotions + FROM store_sales, + store, + promotion, + date_dim, + customer, + customer_address, + item + WHERE ss_sold_date_sk = d_date_sk + AND ss_store_sk = s_store_sk + AND ss_promo_sk = p_promo_sk + AND ss_customer_sk = c_customer_sk + AND ca_address_sk = c_current_addr_sk + AND ss_item_sk = i_item_sk + AND ca_gmt_offset = -7 + AND i_category = 'Books' + AND ( p_channel_dmail = 'Y' + OR p_channel_email = 'Y' + OR p_channel_tv = 'Y' ) + AND s_gmt_offset = -7 + AND d_year = 2001 + AND d_moy = 12) promotional_sales, + (SELECT Sum(ss_ext_sales_price) total + FROM store_sales, + store, + date_dim, + customer, + customer_address, + item + WHERE ss_sold_date_sk = d_date_sk + AND ss_store_sk = s_store_sk + AND ss_customer_sk = c_customer_sk + AND ca_address_sk = c_current_addr_sk + AND ss_item_sk = i_item_sk + AND ca_gmt_offset = -7 + AND i_category = 'Books' + AND s_gmt_offset = -7 + AND d_year = 2001 + AND d_moy = 12) all_sales +ORDER BY promotions, + total +LIMIT 100; diff --git a/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query62.sql b/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query62.sql new file mode 100644 index 0000000000..6b84399205 --- /dev/null +++ b/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query62.sql @@ -0,0 +1,45 @@ +-- start query 62 in stream 0 using template query62.tpl +SELECT Substr(w_warehouse_name, 1, 20), + sm_type, + web_name, + Sum(CASE + WHEN ( ws_ship_date_sk - ws_sold_date_sk <= 30 ) THEN 1 + ELSE 0 + END) AS `30 days`, + Sum(CASE + WHEN ( ws_ship_date_sk - ws_sold_date_sk > 30 ) + AND ( ws_ship_date_sk - ws_sold_date_sk <= 60 ) THEN 1 + ELSE 0 + END) AS `31-60 days`, + Sum(CASE + WHEN ( ws_ship_date_sk - ws_sold_date_sk > 60 ) + AND ( ws_ship_date_sk - ws_sold_date_sk <= 90 ) THEN 1 + ELSE 0 + END) AS `61-90 days`, + Sum(CASE + WHEN ( ws_ship_date_sk - ws_sold_date_sk > 90 ) + AND ( ws_ship_date_sk - ws_sold_date_sk <= 120 ) THEN + 1 + ELSE 0 + END) AS `91-120 days`, + Sum(CASE + WHEN ( ws_ship_date_sk - ws_sold_date_sk > 120 ) THEN 1 + ELSE 0 + END) AS `>120 days` +FROM web_sales, + warehouse, + ship_mode, + web_site, + date_dim +WHERE d_month_seq BETWEEN 1222 AND 1222 + 11 + AND ws_ship_date_sk = d_date_sk + AND ws_warehouse_sk = w_warehouse_sk + AND ws_ship_mode_sk = sm_ship_mode_sk + AND ws_web_site_sk = web_site_sk +GROUP BY Substr(w_warehouse_name, 1, 20), + sm_type, + web_name +ORDER BY Substr(w_warehouse_name, 1, 20), + sm_type, + web_name +LIMIT 100; diff --git a/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query63.sql b/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query63.sql new file mode 100644 index 0000000000..3ebb7e7269 --- /dev/null +++ b/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query63.sql @@ -0,0 +1,45 @@ +-- start query 63 in stream 0 using template query63.tpl +SELECT * +FROM (SELECT i_manager_id, + Sum(ss_sales_price) sum_sales, + Avg(Sum(ss_sales_price)) + OVER ( + partition BY i_manager_id) avg_monthly_sales + FROM item, + store_sales, + date_dim, + store + WHERE ss_item_sk = i_item_sk + AND ss_sold_date_sk = d_date_sk + AND ss_store_sk = s_store_sk + AND d_month_seq IN ( 1200, 1200 + 1, 1200 + 2, 1200 + 3, + 1200 + 4, 1200 + 5, 1200 + 6, 1200 + 7, + 1200 + 8, 1200 + 9, 1200 + 10, 1200 + 11 ) + AND ( ( i_category IN ( 'Books', 'Children', 'Electronics' ) + AND i_class IN ( 'personal', 'portable', 'reference', + 'self-help' ) + AND i_brand IN ( 'scholaramalgamalg #14', + 'scholaramalgamalg #7' + , + 'exportiunivamalg #9', + 'scholaramalgamalg #9' ) + ) + OR ( i_category IN ( 'Women', 'Music', 'Men' ) + AND i_class IN ( 'accessories', 'classical', + 'fragrances', + 'pants' ) + AND i_brand IN ( 'amalgimporto #1', + 'edu packscholar #1', + 'exportiimporto #1', + 'importoamalg #1' ) ) ) + GROUP BY i_manager_id, + d_moy) tmp1 +WHERE CASE + WHEN avg_monthly_sales > 0 THEN Abs (sum_sales - avg_monthly_sales) / + avg_monthly_sales + ELSE NULL + END > 0.1 +ORDER BY i_manager_id, + avg_monthly_sales, + sum_sales +LIMIT 100; diff --git a/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query64.sql b/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query64.sql new file mode 100644 index 0000000000..e883b64205 --- /dev/null +++ b/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query64.sql @@ -0,0 +1,122 @@ +-- start query 64 in stream 0 using template query64.tpl +WITH cs_ui + AS (SELECT cs_item_sk, + Sum(cs_ext_list_price) AS sale, + Sum(cr_refunded_cash + cr_reversed_charge + + cr_store_credit) AS refund + FROM catalog_sales, + catalog_returns + WHERE cs_item_sk = cr_item_sk + AND cs_order_number = cr_order_number + GROUP BY cs_item_sk + HAVING Sum(cs_ext_list_price) > 2 * Sum( + cr_refunded_cash + cr_reversed_charge + + cr_store_credit)), + cross_sales + AS (SELECT i_product_name product_name, + i_item_sk item_sk, + s_store_name store_name, + s_zip store_zip, + ad1.ca_street_number b_street_number, + ad1.ca_street_name b_streen_name, + ad1.ca_city b_city, + ad1.ca_zip b_zip, + ad2.ca_street_number c_street_number, + ad2.ca_street_name c_street_name, + ad2.ca_city c_city, + ad2.ca_zip c_zip, + d1.d_year AS syear, + d2.d_year AS fsyear, + d3.d_year s2year, + Count(*) cnt, + Sum(ss_wholesale_cost) s1, + Sum(ss_list_price) s2, + Sum(ss_coupon_amt) s3 + FROM store_sales, + store_returns, + cs_ui, + date_dim d1, + date_dim d2, + date_dim d3, + store, + customer, + customer_demographics cd1, + customer_demographics cd2, + promotion, + household_demographics hd1, + household_demographics hd2, + customer_address ad1, + customer_address ad2, + income_band ib1, + income_band ib2, + item + WHERE ss_store_sk = s_store_sk + AND ss_sold_date_sk = d1.d_date_sk + AND ss_customer_sk = c_customer_sk + AND ss_cdemo_sk = cd1.cd_demo_sk + AND ss_hdemo_sk = hd1.hd_demo_sk + AND ss_addr_sk = ad1.ca_address_sk + AND ss_item_sk = i_item_sk + AND ss_item_sk = sr_item_sk + AND ss_ticket_number = sr_ticket_number + AND ss_item_sk = cs_ui.cs_item_sk + AND c_current_cdemo_sk = cd2.cd_demo_sk + AND c_current_hdemo_sk = hd2.hd_demo_sk + AND c_current_addr_sk = ad2.ca_address_sk + AND c_first_sales_date_sk = d2.d_date_sk + AND c_first_shipto_date_sk = d3.d_date_sk + AND ss_promo_sk = p_promo_sk + AND hd1.hd_income_band_sk = ib1.ib_income_band_sk + AND hd2.hd_income_band_sk = ib2.ib_income_band_sk + AND cd1.cd_marital_status <> cd2.cd_marital_status + AND i_color IN ( 'cyan', 'peach', 'blush', 'frosted', + 'powder', 'orange' ) + AND i_current_price BETWEEN 58 AND 58 + 10 + AND i_current_price BETWEEN 58 + 1 AND 58 + 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_streen_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, + cs1.s2, + cs1.s3, + cs2.s1, + cs2.s2, + cs2.s3, + cs2.syear, + cs2.cnt +FROM cross_sales cs1, + cross_sales cs2 +WHERE cs1.item_sk = cs2.item_sk + AND cs1.syear = 2001 + AND cs2.syear = 2001 + 1 + AND cs2.cnt <= cs1.cnt + AND cs1.store_name = cs2.store_name + AND cs1.store_zip = cs2.store_zip +ORDER BY cs1.product_name, + cs1.store_name, + cs2.cnt; diff --git a/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query65.sql b/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query65.sql new file mode 100644 index 0000000000..bf4ea2ce01 --- /dev/null +++ b/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query65.sql @@ -0,0 +1,37 @@ +-- start query 65 in stream 0 using template query65.tpl +SELECT s_store_name, + i_item_desc, + sc.revenue, + i_current_price, + i_wholesale_cost, + i_brand +FROM store, + item, + (SELECT ss_store_sk, + Avg(revenue) AS ave + FROM (SELECT ss_store_sk, + ss_item_sk, + Sum(ss_sales_price) AS revenue + FROM store_sales, + date_dim + WHERE ss_sold_date_sk = d_date_sk + AND d_month_seq BETWEEN 1199 AND 1199 + 11 + GROUP BY ss_store_sk, + ss_item_sk) sa + GROUP BY ss_store_sk) sb, + (SELECT ss_store_sk, + ss_item_sk, + Sum(ss_sales_price) AS revenue + FROM store_sales, + date_dim + WHERE ss_sold_date_sk = d_date_sk + AND d_month_seq BETWEEN 1199 AND 1199 + 11 + GROUP BY ss_store_sk, + ss_item_sk) sc +WHERE sb.ss_store_sk = sc.ss_store_sk + AND sc.revenue <= 0.1 * sb.ave + AND s_store_sk = sc.ss_store_sk + AND i_item_sk = sc.ss_item_sk +ORDER BY s_store_name, + i_item_desc +LIMIT 100; diff --git a/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query66.sql b/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query66.sql new file mode 100644 index 0000000000..5e46266f16 --- /dev/null +++ b/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query66.sql @@ -0,0 +1,306 @@ +-- start query 66 in stream 0 using template query66.tpl +SELECT w_warehouse_name, + w_warehouse_sq_ft, + w_city, + w_county, + w_state, + w_country, + ship_carriers, + year1, + Sum(jan_sales) AS jan_sales, + Sum(feb_sales) AS feb_sales, + Sum(mar_sales) AS mar_sales, + Sum(apr_sales) AS apr_sales, + Sum(may_sales) AS may_sales, + Sum(jun_sales) AS jun_sales, + Sum(jul_sales) AS jul_sales, + Sum(aug_sales) AS aug_sales, + Sum(sep_sales) AS sep_sales, + Sum(oct_sales) AS oct_sales, + Sum(nov_sales) AS nov_sales, + Sum(dec_sales) AS dec_sales, + Sum(jan_sales / w_warehouse_sq_ft) AS jan_sales_per_sq_foot, + Sum(feb_sales / w_warehouse_sq_ft) AS feb_sales_per_sq_foot, + Sum(mar_sales / w_warehouse_sq_ft) AS mar_sales_per_sq_foot, + Sum(apr_sales / w_warehouse_sq_ft) AS apr_sales_per_sq_foot, + Sum(may_sales / w_warehouse_sq_ft) AS may_sales_per_sq_foot, + Sum(jun_sales / w_warehouse_sq_ft) AS jun_sales_per_sq_foot, + Sum(jul_sales / w_warehouse_sq_ft) AS jul_sales_per_sq_foot, + Sum(aug_sales / w_warehouse_sq_ft) AS aug_sales_per_sq_foot, + Sum(sep_sales / w_warehouse_sq_ft) AS sep_sales_per_sq_foot, + Sum(oct_sales / w_warehouse_sq_ft) AS oct_sales_per_sq_foot, + Sum(nov_sales / w_warehouse_sq_ft) AS nov_sales_per_sq_foot, + Sum(dec_sales / w_warehouse_sq_ft) AS dec_sales_per_sq_foot, + Sum(jan_net) AS jan_net, + Sum(feb_net) AS feb_net, + Sum(mar_net) AS mar_net, + Sum(apr_net) AS apr_net, + Sum(may_net) AS may_net, + Sum(jun_net) AS jun_net, + Sum(jul_net) AS jul_net, + Sum(aug_net) AS aug_net, + Sum(sep_net) AS sep_net, + Sum(oct_net) AS oct_net, + Sum(nov_net) AS nov_net, + Sum(dec_net) AS dec_net +FROM (SELECT w_warehouse_name, + w_warehouse_sq_ft, + w_city, + w_county, + w_state, + w_country, + 'ZOUROS' + || ',' + || 'ZHOU' AS ship_carriers, + d_year AS year1, + Sum(CASE + WHEN d_moy = 1 THEN ws_ext_sales_price * ws_quantity + ELSE 0 + END) AS jan_sales, + Sum(CASE + WHEN d_moy = 2 THEN ws_ext_sales_price * ws_quantity + ELSE 0 + END) AS feb_sales, + Sum(CASE + WHEN d_moy = 3 THEN ws_ext_sales_price * ws_quantity + ELSE 0 + END) AS mar_sales, + Sum(CASE + WHEN d_moy = 4 THEN ws_ext_sales_price * ws_quantity + ELSE 0 + END) AS apr_sales, + Sum(CASE + WHEN d_moy = 5 THEN ws_ext_sales_price * ws_quantity + ELSE 0 + END) AS may_sales, + Sum(CASE + WHEN d_moy = 6 THEN ws_ext_sales_price * ws_quantity + ELSE 0 + END) AS jun_sales, + Sum(CASE + WHEN d_moy = 7 THEN ws_ext_sales_price * ws_quantity + ELSE 0 + END) AS jul_sales, + Sum(CASE + WHEN d_moy = 8 THEN ws_ext_sales_price * ws_quantity + ELSE 0 + END) AS aug_sales, + Sum(CASE + WHEN d_moy = 9 THEN ws_ext_sales_price * ws_quantity + ELSE 0 + END) AS sep_sales, + Sum(CASE + WHEN d_moy = 10 THEN ws_ext_sales_price * ws_quantity + ELSE 0 + END) AS oct_sales, + Sum(CASE + WHEN d_moy = 11 THEN ws_ext_sales_price * ws_quantity + ELSE 0 + END) AS nov_sales, + Sum(CASE + WHEN d_moy = 12 THEN ws_ext_sales_price * ws_quantity + ELSE 0 + END) AS dec_sales, + Sum(CASE + WHEN d_moy = 1 THEN ws_net_paid_inc_ship * ws_quantity + ELSE 0 + END) AS jan_net, + Sum(CASE + WHEN d_moy = 2 THEN ws_net_paid_inc_ship * ws_quantity + ELSE 0 + END) AS feb_net, + Sum(CASE + WHEN d_moy = 3 THEN ws_net_paid_inc_ship * ws_quantity + ELSE 0 + END) AS mar_net, + Sum(CASE + WHEN d_moy = 4 THEN ws_net_paid_inc_ship * ws_quantity + ELSE 0 + END) AS apr_net, + Sum(CASE + WHEN d_moy = 5 THEN ws_net_paid_inc_ship * ws_quantity + ELSE 0 + END) AS may_net, + Sum(CASE + WHEN d_moy = 6 THEN ws_net_paid_inc_ship * ws_quantity + ELSE 0 + END) AS jun_net, + Sum(CASE + WHEN d_moy = 7 THEN ws_net_paid_inc_ship * ws_quantity + ELSE 0 + END) AS jul_net, + Sum(CASE + WHEN d_moy = 8 THEN ws_net_paid_inc_ship * ws_quantity + ELSE 0 + END) AS aug_net, + Sum(CASE + WHEN d_moy = 9 THEN ws_net_paid_inc_ship * ws_quantity + ELSE 0 + END) AS sep_net, + Sum(CASE + WHEN d_moy = 10 THEN ws_net_paid_inc_ship * ws_quantity + ELSE 0 + END) AS oct_net, + Sum(CASE + WHEN d_moy = 11 THEN ws_net_paid_inc_ship * ws_quantity + ELSE 0 + END) AS nov_net, + Sum(CASE + WHEN d_moy = 12 THEN ws_net_paid_inc_ship * ws_quantity + ELSE 0 + END) AS dec_net + FROM web_sales, + warehouse, + date_dim, + time_dim, + ship_mode + WHERE ws_warehouse_sk = w_warehouse_sk + AND ws_sold_date_sk = d_date_sk + AND ws_sold_time_sk = t_time_sk + AND ws_ship_mode_sk = sm_ship_mode_sk + AND d_year = 1998 + AND t_time BETWEEN 7249 AND 7249 + 28800 + AND sm_carrier IN ( 'ZOUROS', 'ZHOU' ) + 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, + 'ZOUROS' + || ',' + || 'ZHOU' AS ship_carriers, + d_year AS year1, + Sum(CASE + WHEN d_moy = 1 THEN cs_ext_sales_price * cs_quantity + ELSE 0 + END) AS jan_sales, + Sum(CASE + WHEN d_moy = 2 THEN cs_ext_sales_price * cs_quantity + ELSE 0 + END) AS feb_sales, + Sum(CASE + WHEN d_moy = 3 THEN cs_ext_sales_price * cs_quantity + ELSE 0 + END) AS mar_sales, + Sum(CASE + WHEN d_moy = 4 THEN cs_ext_sales_price * cs_quantity + ELSE 0 + END) AS apr_sales, + Sum(CASE + WHEN d_moy = 5 THEN cs_ext_sales_price * cs_quantity + ELSE 0 + END) AS may_sales, + Sum(CASE + WHEN d_moy = 6 THEN cs_ext_sales_price * cs_quantity + ELSE 0 + END) AS jun_sales, + Sum(CASE + WHEN d_moy = 7 THEN cs_ext_sales_price * cs_quantity + ELSE 0 + END) AS jul_sales, + Sum(CASE + WHEN d_moy = 8 THEN cs_ext_sales_price * cs_quantity + ELSE 0 + END) AS aug_sales, + Sum(CASE + WHEN d_moy = 9 THEN cs_ext_sales_price * cs_quantity + ELSE 0 + END) AS sep_sales, + Sum(CASE + WHEN d_moy = 10 THEN cs_ext_sales_price * cs_quantity + ELSE 0 + END) AS oct_sales, + Sum(CASE + WHEN d_moy = 11 THEN cs_ext_sales_price * cs_quantity + ELSE 0 + END) AS nov_sales, + Sum(CASE + WHEN d_moy = 12 THEN cs_ext_sales_price * cs_quantity + ELSE 0 + END) AS dec_sales, + Sum(CASE + WHEN d_moy = 1 THEN cs_net_paid * cs_quantity + ELSE 0 + END) AS jan_net, + Sum(CASE + WHEN d_moy = 2 THEN cs_net_paid * cs_quantity + ELSE 0 + END) AS feb_net, + Sum(CASE + WHEN d_moy = 3 THEN cs_net_paid * cs_quantity + ELSE 0 + END) AS mar_net, + Sum(CASE + WHEN d_moy = 4 THEN cs_net_paid * cs_quantity + ELSE 0 + END) AS apr_net, + Sum(CASE + WHEN d_moy = 5 THEN cs_net_paid * cs_quantity + ELSE 0 + END) AS may_net, + Sum(CASE + WHEN d_moy = 6 THEN cs_net_paid * cs_quantity + ELSE 0 + END) AS jun_net, + Sum(CASE + WHEN d_moy = 7 THEN cs_net_paid * cs_quantity + ELSE 0 + END) AS jul_net, + Sum(CASE + WHEN d_moy = 8 THEN cs_net_paid * cs_quantity + ELSE 0 + END) AS aug_net, + Sum(CASE + WHEN d_moy = 9 THEN cs_net_paid * cs_quantity + ELSE 0 + END) AS sep_net, + Sum(CASE + WHEN d_moy = 10 THEN cs_net_paid * cs_quantity + ELSE 0 + END) AS oct_net, + Sum(CASE + WHEN d_moy = 11 THEN cs_net_paid * cs_quantity + ELSE 0 + END) AS nov_net, + Sum(CASE + WHEN d_moy = 12 THEN cs_net_paid * cs_quantity + ELSE 0 + END) AS dec_net + FROM catalog_sales, + warehouse, + date_dim, + time_dim, + ship_mode + WHERE cs_warehouse_sk = w_warehouse_sk + AND cs_sold_date_sk = d_date_sk + AND cs_sold_time_sk = t_time_sk + AND cs_ship_mode_sk = sm_ship_mode_sk + AND d_year = 1998 + AND t_time BETWEEN 7249 AND 7249 + 28800 + AND sm_carrier IN ( 'ZOUROS', 'ZHOU' ) + 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, + year1 +ORDER BY w_warehouse_name +LIMIT 100; diff --git a/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query67.sql b/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query67.sql new file mode 100644 index 0000000000..fd137cfb37 --- /dev/null +++ b/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query67.sql @@ -0,0 +1,43 @@ +-- start query 67 in stream 0 using template query67.tpl +select top 100 * +from (select i_category + ,i_class + ,i_brand + ,i_product_name + ,d_year + ,d_qoy + ,d_moy + ,s_store_id + ,sumsales + ,rank() over (partition by i_category order by sumsales desc) rk + from (select i_category + ,i_class + ,i_brand + ,i_product_name + ,d_year + ,d_qoy + ,d_moy + ,s_store_id + ,sum(coalesce(ss_sales_price*ss_quantity,0)) sumsales + from store_sales + ,date_dim + ,store + ,item + where ss_sold_date_sk=d_date_sk + and ss_item_sk=i_item_sk + and ss_store_sk = s_store_sk + and d_month_seq between 1181 and 1181+11 + group by rollup(i_category, i_class, i_brand, i_product_name, d_year, d_qoy, d_moy,s_store_id))dw1) dw2 +where rk <= 100 +order by i_category + ,i_class + ,i_brand + ,i_product_name + ,d_year + ,d_qoy + ,d_moy + ,s_store_id + ,sumsales + ,rk +; + diff --git a/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query68.sql b/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query68.sql new file mode 100644 index 0000000000..ce217e5acb --- /dev/null +++ b/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query68.sql @@ -0,0 +1,41 @@ +-- start query 68 in stream 0 using template query68.tpl +SELECT c_last_name, + c_first_name, + ca_city, + bought_city, + ss_ticket_number, + extended_price, + extended_tax, + list_price +FROM (SELECT ss_ticket_number, + ss_customer_sk, + ca_city bought_city, + Sum(ss_ext_sales_price) extended_price, + Sum(ss_ext_list_price) list_price, + Sum(ss_ext_tax) extended_tax + FROM store_sales, + date_dim, + store, + household_demographics, + customer_address + WHERE store_sales.ss_sold_date_sk = date_dim.d_date_sk + AND store_sales.ss_store_sk = store.s_store_sk + AND store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk + AND store_sales.ss_addr_sk = customer_address.ca_address_sk + AND date_dim.d_dom BETWEEN 1 AND 2 + AND ( household_demographics.hd_dep_count = 8 + OR household_demographics.hd_vehicle_count = 3 ) + AND date_dim.d_year IN ( 1998, 1998 + 1, 1998 + 2 ) + AND store.s_city IN ( 'Fairview', 'Midway' ) + GROUP BY ss_ticket_number, + ss_customer_sk, + ss_addr_sk, + ca_city) dn, + customer, + customer_address current_addr +WHERE ss_customer_sk = c_customer_sk + AND customer.c_current_addr_sk = current_addr.ca_address_sk + AND current_addr.ca_city <> bought_city +ORDER BY c_last_name, + ss_ticket_number +LIMIT 100; diff --git a/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query69.sql b/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query69.sql new file mode 100644 index 0000000000..997f073c11 --- /dev/null +++ b/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query69.sql @@ -0,0 +1,46 @@ +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 ( 'KS', 'AZ', 'NE' ) + 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 = 2004 + AND d_moy BETWEEN 3 AND 3 + 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 = 2004 + AND d_moy BETWEEN 3 AND 3 + 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 = 2004 + AND d_moy BETWEEN 3 AND 3 + 2) ) +GROUP BY cd_gender, + cd_marital_status, + cd_education_status, + cd_purchase_estimate, + cd_credit_rating +ORDER BY cd_gender, + cd_marital_status, + cd_education_status, + cd_purchase_estimate, + cd_credit_rating +LIMIT 100; diff --git a/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query70.sql b/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query70.sql new file mode 100644 index 0000000000..bf0884e169 --- /dev/null +++ b/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query70.sql @@ -0,0 +1,40 @@ +-- start query 70 in stream 0 using template query70.tpl +SELECT Sum(ss_net_profit) AS total_sum, + s_state, + s_county, + Grouping(s_state) + Grouping(s_county) AS lochierarchy, + Rank() + OVER ( + partition BY Grouping(s_state)+Grouping(s_county), CASE WHEN + Grouping( + s_county) = 0 THEN s_state END + ORDER BY Sum(ss_net_profit) DESC) AS rank_within_parent +FROM store_sales, + date_dim d1, + store +WHERE d1.d_month_seq BETWEEN 1200 AND 1200 + 11 + AND d1.d_date_sk = ss_sold_date_sk + AND s_store_sk = ss_store_sk + AND s_state IN (SELECT s_state + FROM (SELECT s_state AS + s_state, + Rank() + OVER ( + partition BY s_state + ORDER BY Sum(ss_net_profit) DESC) AS + ranking + FROM store_sales, + store, + date_dim + WHERE d_month_seq BETWEEN 1200 AND 1200 + 11 + AND d_date_sk = ss_sold_date_sk + AND s_store_sk = ss_store_sk + GROUP BY s_state) tmp1 + WHERE ranking <= 5) +GROUP BY rollup( s_state, s_county ) +ORDER BY lochierarchy DESC, + CASE + WHEN lochierarchy = 0 THEN s_state + END, + rank_within_parent +LIMIT 100; diff --git a/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query71.sql b/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query71.sql new file mode 100644 index 0000000000..43b40bfff2 --- /dev/null +++ b/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query71.sql @@ -0,0 +1,48 @@ +-- start query 71 in stream 0 using template query71.tpl +SELECT i_brand_id brand_id, + i_brand brand, + t_hour, + t_minute, + Sum(ext_price) ext_price +FROM item, + (SELECT ws_ext_sales_price AS ext_price, + ws_sold_date_sk AS sold_date_sk, + ws_item_sk AS sold_item_sk, + ws_sold_time_sk AS time_sk + FROM web_sales, + date_dim + WHERE d_date_sk = ws_sold_date_sk + AND d_moy = 11 + AND d_year = 2001 + UNION ALL + SELECT cs_ext_sales_price AS ext_price, + cs_sold_date_sk AS sold_date_sk, + cs_item_sk AS sold_item_sk, + cs_sold_time_sk AS time_sk + FROM catalog_sales, + date_dim + WHERE d_date_sk = cs_sold_date_sk + AND d_moy = 11 + AND d_year = 2001 + UNION ALL + SELECT ss_ext_sales_price AS ext_price, + ss_sold_date_sk AS sold_date_sk, + ss_item_sk AS sold_item_sk, + ss_sold_time_sk AS time_sk + FROM store_sales, + date_dim + WHERE d_date_sk = ss_sold_date_sk + AND d_moy = 11 + AND d_year = 2001) AS tmp, + time_dim +WHERE sold_item_sk = i_item_sk + AND i_manager_id = 1 + AND time_sk = t_time_sk + AND ( t_meal_time = 'breakfast' + OR t_meal_time = 'dinner' ) +GROUP BY i_brand, + i_brand_id, + t_hour, + t_minute +ORDER BY ext_price DESC, + i_brand_id; diff --git a/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query72.sql b/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query72.sql new file mode 100644 index 0000000000..05e5f09578 --- /dev/null +++ b/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query72.sql @@ -0,0 +1,49 @@ +-- start query 72 in stream 0 using template query72.tpl +SELECT i_item_desc, + w_warehouse_name, + d1.d_week_seq, + Sum(CASE + WHEN p_promo_sk IS NULL THEN 1 + ELSE 0 + END) no_promo, + Sum(CASE + WHEN p_promo_sk IS NOT NULL THEN 1 + ELSE 0 + END) promo, + Count(*) total_cnt +FROM catalog_sales + JOIN inventory + ON ( cs_item_sk = inv_item_sk ) + JOIN warehouse + ON ( w_warehouse_sk = inv_warehouse_sk ) + JOIN item + ON ( i_item_sk = cs_item_sk ) + JOIN customer_demographics + ON ( cs_bill_cdemo_sk = cd_demo_sk ) + JOIN household_demographics + ON ( cs_bill_hdemo_sk = hd_demo_sk ) + JOIN date_dim d1 + ON ( cs_sold_date_sk = d1.d_date_sk ) + JOIN date_dim d2 + ON ( inv_date_sk = d2.d_date_sk ) + JOIN date_dim d3 + ON ( cs_ship_date_sk = d3.d_date_sk ) + LEFT OUTER JOIN promotion + ON ( cs_promo_sk = p_promo_sk ) + LEFT OUTER JOIN catalog_returns + ON ( cr_item_sk = cs_item_sk + AND cr_order_number = cs_order_number ) +WHERE d1.d_week_seq = d2.d_week_seq + AND inv_quantity_on_hand < cs_quantity + AND d3.d_date > d1.d_date + INTERVAL '5' day + AND hd_buy_potential = '501-1000' + AND d1.d_year = 2002 + AND cd_marital_status = 'M' +GROUP BY i_item_desc, + w_warehouse_name, + d1.d_week_seq +ORDER BY total_cnt DESC, + i_item_desc, + w_warehouse_name, + d_week_seq +LIMIT 100; diff --git a/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query73.sql b/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query73.sql new file mode 100644 index 0000000000..47b7788fcf --- /dev/null +++ b/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query73.sql @@ -0,0 +1,39 @@ +-- start query 73 in stream 0 using template query73.tpl +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 = '0-500' ) + AND household_demographics.hd_vehicle_count > 0 + AND CASE + WHEN household_demographics.hd_vehicle_count > 0 THEN + household_demographics.hd_dep_count / + household_demographics.hd_vehicle_count + ELSE NULL + END > 1 + AND date_dim.d_year IN ( 2000, 2000 + 1, 2000 + 2 ) + AND store.s_county IN ( 'Williamson County', 'Williamson County', + 'Williamson County', + 'Williamson 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/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query74.sql b/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query74.sql new file mode 100644 index 0000000000..5603c8dc86 --- /dev/null +++ b/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query74.sql @@ -0,0 +1,69 @@ +-- start query 74 in stream 0 using template query74.tpl +WITH year_total + AS (SELECT c_customer_id customer_id, + c_first_name customer_first_name, + c_last_name customer_last_name, + d_year AS year1, + Sum(ss_net_paid) year_total, + 's' sale_type + FROM customer, + store_sales, + date_dim + WHERE c_customer_sk = ss_customer_sk + AND ss_sold_date_sk = d_date_sk + AND d_year IN ( 1999, 1999 + 1 ) + GROUP BY c_customer_id, + c_first_name, + c_last_name, + d_year + UNION ALL + SELECT c_customer_id customer_id, + c_first_name customer_first_name, + c_last_name customer_last_name, + d_year AS year1, + Sum(ws_net_paid) year_total, + 'w' sale_type + FROM customer, + web_sales, + date_dim + WHERE c_customer_sk = ws_bill_customer_sk + AND ws_sold_date_sk = d_date_sk + AND d_year IN ( 1999, 1999 + 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.year1 = 1999 + AND t_s_secyear.year1 = 1999 + 1 + AND t_w_firstyear.year1 = 1999 + AND t_w_secyear.year1 = 1999 + 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, + 2, + 3 +LIMIT 100; diff --git a/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query75.sql b/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query75.sql new file mode 100644 index 0000000000..653741a504 --- /dev/null +++ b/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query75.sql @@ -0,0 +1,93 @@ +-- start query 75 in stream 0 using template query75.tpl +WITH all_sales + AS (SELECT d_year, + i_brand_id, + i_class_id, + i_category_id, + i_manufact_id, + Sum(sales_cnt) AS sales_cnt, + Sum(sales_amt) AS sales_amt + FROM (SELECT d_year, + i_brand_id, + i_class_id, + i_category_id, + i_manufact_id, + cs_quantity - COALESCE(cr_return_quantity, 0) AS + sales_cnt, + cs_ext_sales_price - COALESCE(cr_return_amount, 0.0) AS + sales_amt + FROM catalog_sales + JOIN item + ON i_item_sk = cs_item_sk + JOIN date_dim + ON d_date_sk = cs_sold_date_sk + LEFT JOIN catalog_returns + ON ( cs_order_number = cr_order_number + AND cs_item_sk = cr_item_sk ) + WHERE i_category = 'Men' + UNION + SELECT d_year, + i_brand_id, + i_class_id, + i_category_id, + i_manufact_id, + ss_quantity - COALESCE(sr_return_quantity, 0) AS + sales_cnt, + ss_ext_sales_price - COALESCE(sr_return_amt, 0.0) AS + sales_amt + FROM store_sales + JOIN item + ON i_item_sk = ss_item_sk + JOIN date_dim + ON d_date_sk = ss_sold_date_sk + LEFT JOIN store_returns + ON ( ss_ticket_number = sr_ticket_number + AND ss_item_sk = sr_item_sk ) + WHERE i_category = 'Men' + UNION + SELECT d_year, + i_brand_id, + i_class_id, + i_category_id, + i_manufact_id, + ws_quantity - COALESCE(wr_return_quantity, 0) AS + sales_cnt, + ws_ext_sales_price - COALESCE(wr_return_amt, 0.0) AS + sales_amt + FROM web_sales + JOIN item + ON i_item_sk = ws_item_sk + JOIN date_dim + ON d_date_sk = ws_sold_date_sk + LEFT JOIN web_returns + ON ( ws_order_number = wr_order_number + AND ws_item_sk = wr_item_sk ) + WHERE i_category = 'Men') sales_detail + GROUP BY d_year, + i_brand_id, + i_class_id, + i_category_id, + i_manufact_id) +SELECT prev_yr.d_year AS prev_year, + curr_yr.d_year AS year1, + curr_yr.i_brand_id, + curr_yr.i_class_id, + curr_yr.i_category_id, + curr_yr.i_manufact_id, + prev_yr.sales_cnt AS prev_yr_cnt, + curr_yr.sales_cnt AS curr_yr_cnt, + curr_yr.sales_cnt - prev_yr.sales_cnt AS sales_cnt_diff, + curr_yr.sales_amt - prev_yr.sales_amt AS sales_amt_diff +FROM all_sales curr_yr, + all_sales prev_yr +WHERE curr_yr.i_brand_id = prev_yr.i_brand_id + AND curr_yr.i_class_id = prev_yr.i_class_id + AND curr_yr.i_category_id = prev_yr.i_category_id + AND curr_yr.i_manufact_id = prev_yr.i_manufact_id + AND curr_yr.d_year = 2002 + AND prev_yr.d_year = 2002 - 1 + AND Cast(curr_yr.sales_cnt AS DECIMAL(17, 2)) / Cast(prev_yr.sales_cnt AS + DECIMAL(17, 2)) + < 0.9 +ORDER BY sales_cnt_diff +LIMIT 100; diff --git a/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query76.sql b/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query76.sql new file mode 100644 index 0000000000..ebee4a6125 --- /dev/null +++ b/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query76.sql @@ -0,0 +1,57 @@ +-- start query 76 in stream 0 using template query76.tpl +SELECT channel, + col_name, + d_year, + d_qoy, + i_category, + Count(*) sales_cnt, + Sum(ext_sales_price) sales_amt +FROM (SELECT 'store' AS channel, + 'ss_hdemo_sk' col_name, + d_year, + d_qoy, + i_category, + ss_ext_sales_price ext_sales_price + FROM store_sales, + item, + date_dim + WHERE ss_hdemo_sk IS NULL + AND ss_sold_date_sk = d_date_sk + AND ss_item_sk = i_item_sk + UNION ALL + SELECT 'web' AS channel, + 'ws_ship_hdemo_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_hdemo_sk IS NULL + AND ws_sold_date_sk = d_date_sk + AND ws_item_sk = i_item_sk + UNION ALL + SELECT 'catalog' AS channel, + 'cs_warehouse_sk' col_name, + d_year, + d_qoy, + i_category, + cs_ext_sales_price ext_sales_price + FROM catalog_sales, + item, + date_dim + WHERE cs_warehouse_sk IS NULL + AND cs_sold_date_sk = d_date_sk + AND cs_item_sk = i_item_sk) foo +GROUP BY channel, + col_name, + d_year, + d_qoy, + i_category +ORDER BY channel, + col_name, + d_year, + d_qoy, + i_category +LIMIT 100; diff --git a/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query77.sql b/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query77.sql new file mode 100644 index 0000000000..4e38de926c --- /dev/null +++ b/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query77.sql @@ -0,0 +1,108 @@ + +-- start query 77 in stream 0 using template query77.tpl +WITH ss AS +( + SELECT s_store_sk, + Sum(ss_ext_sales_price) AS sales, + Sum(ss_net_profit) AS profit + FROM store_sales, + date_dim, + store + WHERE ss_sold_date_sk = d_date_sk + AND d_date BETWEEN Cast('2001-08-16' AS DATE) AND ( + Cast('2001-08-16' AS DATE) + INTERVAL '30' day) + AND ss_store_sk = s_store_sk + GROUP BY s_store_sk) , sr AS +( + SELECT s_store_sk, + sum(sr_return_amt) AS returns1, + sum(sr_net_loss) AS profit_loss + FROM store_returns, + date_dim, + store + WHERE sr_returned_date_sk = d_date_sk + AND d_date BETWEEN cast('2001-08-16' AS date) AND ( + cast('2001-08-16' AS date) + INTERVAL '30' day) + AND sr_store_sk = s_store_sk + GROUP BY s_store_sk), cs AS +( + SELECT cs_call_center_sk, + sum(cs_ext_sales_price) AS sales, + sum(cs_net_profit) AS profit + FROM catalog_sales, + date_dim + WHERE cs_sold_date_sk = d_date_sk + AND d_date BETWEEN cast('2001-08-16' AS date) AND ( + cast('2001-08-16' AS date) + INTERVAL '30' day) + GROUP BY cs_call_center_sk ), cr AS +( + SELECT cr_call_center_sk, + sum(cr_return_amount) AS returns1, + sum(cr_net_loss) AS profit_loss + FROM catalog_returns, + date_dim + WHERE cr_returned_date_sk = d_date_sk + AND d_date BETWEEN cast('2001-08-16' AS date) AND ( + cast('2001-08-16' AS date) + INTERVAL '30' day) + GROUP BY cr_call_center_sk ), ws AS +( + SELECT wp_web_page_sk, + sum(ws_ext_sales_price) AS sales, + sum(ws_net_profit) AS profit + FROM web_sales, + date_dim, + web_page + WHERE ws_sold_date_sk = d_date_sk + AND d_date BETWEEN cast('2001-08-16' AS date) AND ( + cast('2001-08-16' 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, + sum(wr_return_amt) AS returns1, + sum(wr_net_loss) AS profit_loss + FROM web_returns, + date_dim, + web_page + WHERE wr_returned_date_sk = d_date_sk + AND d_date BETWEEN cast('2001-08-16' AS date) AND ( + cast('2001-08-16' AS date) + INTERVAL '30' day) + AND wr_web_page_sk = wp_web_page_sk + GROUP BY wp_web_page_sk) +SELECT + channel , + id , + sum(sales) AS sales , + sum(returns1) AS returns1 , + sum(profit) AS profit +FROM ( + SELECT 'store channel' AS channel , + ss.s_store_sk AS id , + sales , + COALESCE(returns1, 0) AS returns1 , + (profit - COALESCE(profit_loss,0)) AS profit + FROM ss + LEFT JOIN sr + ON ss.s_store_sk = sr.s_store_sk + UNION ALL + SELECT 'catalog channel' AS channel , + cs_call_center_sk AS id , + sales , + returns1 , + (profit - profit_loss) AS profit + FROM cs , + cr + UNION ALL + SELECT 'web channel' AS channel , + ws.wp_web_page_sk AS id , + sales , + COALESCE(returns1, 0) returns1 , + (profit - COALESCE(profit_loss,0)) AS profit + FROM ws + LEFT JOIN wr + ON ws.wp_web_page_sk = wr.wp_web_page_sk ) x +GROUP BY rollup (channel, id) +ORDER BY channel , + id +LIMIT 100; + diff --git a/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query78.sql b/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query78.sql new file mode 100644 index 0000000000..ef577b59a4 --- /dev/null +++ b/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query78.sql @@ -0,0 +1,86 @@ +-- start query 78 in stream 0 using template query78.tpl +WITH ws + AS (SELECT d_year AS ws_sold_year, + ws_item_sk, + ws_bill_customer_sk ws_customer_sk, + Sum(ws_quantity) ws_qty, + Sum(ws_wholesale_cost) ws_wc, + Sum(ws_sales_price) ws_sp + FROM web_sales + LEFT JOIN web_returns + ON wr_order_number = ws_order_number + AND ws_item_sk = wr_item_sk + JOIN date_dim + ON ws_sold_date_sk = d_date_sk + WHERE wr_order_number IS NULL + GROUP BY d_year, + ws_item_sk, + ws_bill_customer_sk), + cs + AS (SELECT d_year AS cs_sold_year, + cs_item_sk, + cs_bill_customer_sk cs_customer_sk, + Sum(cs_quantity) cs_qty, + Sum(cs_wholesale_cost) cs_wc, + Sum(cs_sales_price) cs_sp + FROM catalog_sales + LEFT JOIN catalog_returns + ON cr_order_number = cs_order_number + AND cs_item_sk = cr_item_sk + JOIN date_dim + ON cs_sold_date_sk = d_date_sk + WHERE cr_order_number IS NULL + GROUP BY d_year, + cs_item_sk, + cs_bill_customer_sk), + ss + AS (SELECT d_year AS ss_sold_year, + ss_item_sk, + ss_customer_sk, + Sum(ss_quantity) ss_qty, + Sum(ss_wholesale_cost) ss_wc, + Sum(ss_sales_price) ss_sp + FROM store_sales + LEFT JOIN store_returns + ON sr_ticket_number = ss_ticket_number + AND ss_item_sk = sr_item_sk + JOIN date_dim + ON ss_sold_date_sk = d_date_sk + WHERE sr_ticket_number IS NULL + GROUP BY d_year, + ss_item_sk, + ss_customer_sk) +SELECT ss_item_sk, + Round(ss_qty / ( 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 = 1999 +ORDER BY ss_item_sk, + ss_qty DESC, + ss_wc DESC, + ss_sp DESC, + other_chan_qty, + other_chan_wholesale_cost, + other_chan_sales_price, + Round(ss_qty / ( COALESCE(ws_qty + cs_qty, 1) ), 2) +LIMIT 100; diff --git a/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query79.sql b/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query79.sql new file mode 100644 index 0000000000..07c4dbda4a --- /dev/null +++ b/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query79.sql @@ -0,0 +1,35 @@ +-- start query 79 in stream 0 using template query79.tpl +SELECT c_last_name, + c_first_name, + Substr(s_city, 1, 30), + ss_ticket_number, + amt, + profit +FROM (SELECT ss_ticket_number, + ss_customer_sk, + store.s_city, + Sum(ss_coupon_amt) amt, + Sum(ss_net_profit) profit + FROM store_sales, + date_dim, + store, + household_demographics + WHERE store_sales.ss_sold_date_sk = date_dim.d_date_sk + AND store_sales.ss_store_sk = store.s_store_sk + AND store_sales.ss_hdemo_sk = household_demographics.hd_demo_sk + AND ( household_demographics.hd_dep_count = 8 + OR household_demographics.hd_vehicle_count > 4 ) + AND date_dim.d_dow = 1 + AND date_dim.d_year IN ( 2000, 2000 + 1, 2000 + 2 ) + AND store.s_number_employees BETWEEN 200 AND 295 + GROUP BY ss_ticket_number, + ss_customer_sk, + ss_addr_sk, + store.s_city) ms, + customer +WHERE ss_customer_sk = c_customer_sk +ORDER BY c_last_name, + c_first_name, + Substr(s_city, 1, 30), + profit +LIMIT 100; diff --git a/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query80.sql b/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query80.sql new file mode 100644 index 0000000000..37774cef3a --- /dev/null +++ b/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query80.sql @@ -0,0 +1,106 @@ +-- start query 80 in stream 0 using template query80.tpl +WITH ssr AS +( + SELECT s_store_id AS store_id, + Sum(ss_ext_sales_price) AS sales, + Sum(COALESCE(sr_return_amt, 0)) AS returns1, + Sum(ss_net_profit - COALESCE(sr_net_loss, 0)) AS profit + FROM store_sales + LEFT OUTER JOIN store_returns + ON ( + ss_item_sk = sr_item_sk + AND ss_ticket_number = sr_ticket_number), + date_dim, + store, + item, + promotion + WHERE ss_sold_date_sk = d_date_sk + AND d_date BETWEEN Cast('2000-08-26' AS DATE) AND ( + Cast('2000-08-26' 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 AS catalog_page_id, + sum(cs_ext_sales_price) AS sales, + sum(COALESCE(cr_return_amount, 0)) AS returns1, + sum(cs_net_profit - COALESCE(cr_net_loss, 0)) AS profit + FROM catalog_sales + LEFT OUTER JOIN catalog_returns + ON ( + cs_item_sk = cr_item_sk + AND cs_order_number = cr_order_number), + date_dim, + catalog_page, + item, + promotion + WHERE cs_sold_date_sk = d_date_sk + AND d_date BETWEEN cast('2000-08-26' AS date) AND ( + cast('2000-08-26' 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) AS sales, + sum(COALESCE(wr_return_amt, 0)) AS returns1, + sum(ws_net_profit - COALESCE(wr_net_loss, 0)) AS profit + FROM web_sales + LEFT OUTER JOIN web_returns + ON ( + ws_item_sk = wr_item_sk + AND ws_order_number = wr_order_number), + date_dim, + web_site, + item, + promotion + WHERE ws_sold_date_sk = d_date_sk + AND d_date BETWEEN cast('2000-08-26' AS date) AND ( + cast('2000-08-26' 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) AS sales , + sum(returns1) AS returns1 , + sum(profit) AS profit +FROM ( + SELECT 'store channel' AS channel , + 'store' + || store_id AS id , + sales , + returns1 , + profit + FROM ssr + UNION ALL + SELECT 'catalog channel' AS channel , + 'catalog_page' + || catalog_page_id AS id , + sales , + returns1 , + profit + FROM csr + UNION ALL + SELECT 'web channel' AS channel , + 'web_site' + || web_site_id AS id , + sales , + returns1 , + profit + FROM wsr ) x +GROUP BY rollup (channel, id) +ORDER BY channel , + id +LIMIT 100; + diff --git a/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query81.sql b/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query81.sql new file mode 100644 index 0000000000..e596c591a2 --- /dev/null +++ b/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query81.sql @@ -0,0 +1,56 @@ + +-- start query 81 in stream 0 using template query81.tpl +WITH customer_total_return + AS (SELECT cr_returning_customer_sk AS ctr_customer_sk, + ca_state AS ctr_state, + Sum(cr_return_amt_inc_tax) AS ctr_total_return + FROM catalog_returns, + date_dim, + customer_address + WHERE cr_returned_date_sk = d_date_sk + AND d_year = 1999 + AND cr_returning_addr_sk = ca_address_sk + GROUP BY cr_returning_customer_sk, + ca_state) +SELECT c_customer_id, + c_salutation, + c_first_name, + c_last_name, + ca_street_number, + ca_street_name, + ca_street_type, + ca_suite_number, + ca_city, + ca_county, + ca_state, + ca_zip, + ca_country, + ca_gmt_offset, + ca_location_type, + ctr_total_return +FROM customer_total_return ctr1, + customer_address, + customer +WHERE ctr1.ctr_total_return > (SELECT Avg(ctr_total_return) * 1.2 + FROM customer_total_return ctr2 + WHERE ctr1.ctr_state = ctr2.ctr_state) + AND ca_address_sk = c_current_addr_sk + AND ca_state = 'TX' + AND ctr1.ctr_customer_sk = c_customer_sk +ORDER BY c_customer_id, + c_salutation, + c_first_name, + c_last_name, + ca_street_number, + ca_street_name, + ca_street_type, + ca_suite_number, + ca_city, + ca_county, + ca_state, + ca_zip, + ca_country, + ca_gmt_offset, + ca_location_type, + ctr_total_return +LIMIT 100; diff --git a/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query82.sql b/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query82.sql new file mode 100644 index 0000000000..1a8d9126df --- /dev/null +++ b/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query82.sql @@ -0,0 +1,24 @@ + +-- start query 82 in stream 0 using template query82.tpl +SELECT + i_item_id , + i_item_desc , + i_current_price +FROM item, + inventory, + date_dim, + store_sales +WHERE i_current_price BETWEEN 63 AND 63+30 +AND inv_item_sk = i_item_sk +AND d_date_sk=inv_date_sk +AND d_date BETWEEN Cast('1998-04-27' AS DATE) AND ( + Cast('1998-04-27' AS DATE) + INTERVAL '60' day) +AND i_manufact_id IN (57,293,427,320) +AND inv_quantity_on_hand BETWEEN 100 AND 500 +AND ss_item_sk = i_item_sk +GROUP BY i_item_id, + i_item_desc, + i_current_price +ORDER BY i_item_id +LIMIT 100; + diff --git a/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query83.sql b/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query83.sql new file mode 100644 index 0000000000..380dfd9fd2 --- /dev/null +++ b/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query83.sql @@ -0,0 +1,75 @@ +-- start query 83 in stream 0 using template query83.tpl +WITH sr_items + AS (SELECT i_item_id item_id, + Sum(sr_return_quantity) sr_item_qty + FROM store_returns, + item, + date_dim + WHERE sr_item_sk = i_item_sk + AND d_date IN (SELECT d_date + FROM date_dim + WHERE d_week_seq IN (SELECT d_week_seq + FROM date_dim + WHERE + d_date IN ( '1999-06-30', + '1999-08-28', + '1999-11-18' + ))) + AND sr_returned_date_sk = d_date_sk + GROUP BY i_item_id), + cr_items + AS (SELECT i_item_id item_id, + Sum(cr_return_quantity) cr_item_qty + FROM catalog_returns, + item, + date_dim + WHERE cr_item_sk = i_item_sk + AND d_date IN (SELECT d_date + FROM date_dim + WHERE d_week_seq IN (SELECT d_week_seq + FROM date_dim + WHERE + d_date IN ( '1999-06-30', + '1999-08-28', + '1999-11-18' + ))) + AND cr_returned_date_sk = d_date_sk + GROUP BY i_item_id), + wr_items + AS (SELECT i_item_id item_id, + Sum(wr_return_quantity) wr_item_qty + FROM web_returns, + item, + date_dim + WHERE wr_item_sk = i_item_sk + AND d_date IN (SELECT d_date + FROM date_dim + WHERE d_week_seq IN (SELECT d_week_seq + FROM date_dim + WHERE + d_date IN ( '1999-06-30', + '1999-08-28', + '1999-11-18' + ))) + AND wr_returned_date_sk = d_date_sk + GROUP BY i_item_id) +SELECT sr_items.item_id, + sr_item_qty, + sr_item_qty / ( sr_item_qty + cr_item_qty + wr_item_qty ) / 3.0 * + 100 sr_dev, + cr_item_qty, + cr_item_qty / ( sr_item_qty + cr_item_qty + wr_item_qty ) / 3.0 * + 100 cr_dev, + wr_item_qty, + wr_item_qty / ( sr_item_qty + cr_item_qty + wr_item_qty ) / 3.0 * + 100 wr_dev, + ( sr_item_qty + cr_item_qty + wr_item_qty ) / 3.0 + average +FROM sr_items, + cr_items, + wr_items +WHERE sr_items.item_id = cr_items.item_id + AND sr_items.item_id = wr_items.item_id +ORDER BY sr_items.item_id, + sr_item_qty +LIMIT 100; diff --git a/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query84.sql b/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query84.sql new file mode 100644 index 0000000000..f073403ef6 --- /dev/null +++ b/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query84.sql @@ -0,0 +1,21 @@ +-- start query 84 in stream 0 using template query84.tpl +SELECT c_customer_id AS customer_id, + c_last_name + || ', ' + || c_first_name AS customername +FROM customer, + customer_address, + customer_demographics, + household_demographics, + income_band, + store_returns +WHERE ca_city = 'Green Acres' + AND c_current_addr_sk = ca_address_sk + AND ib_lower_bound >= 54986 + AND ib_upper_bound <= 54986 + 50000 + AND ib_income_band_sk = hd_income_band_sk + AND cd_demo_sk = c_current_cdemo_sk + AND hd_demo_sk = c_current_hdemo_sk + AND sr_cdemo_sk = cd_demo_sk +ORDER BY c_customer_id +LIMIT 100; diff --git a/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query85.sql b/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query85.sql new file mode 100644 index 0000000000..b821e8aa87 --- /dev/null +++ b/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query85.sql @@ -0,0 +1,52 @@ +-- start query 85 in stream 0 using template query85.tpl +SELECT Substr(r_reason_desc, 1, 20), + Avg(ws_quantity), + Avg(wr_refunded_cash), + Avg(wr_fee) +FROM web_sales, + web_returns, + web_page, + customer_demographics cd1, + customer_demographics cd2, + customer_address, + date_dim, + reason +WHERE ws_web_page_sk = wp_web_page_sk + AND ws_item_sk = wr_item_sk + AND ws_order_number = wr_order_number + AND ws_sold_date_sk = d_date_sk + AND d_year = 2001 + 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 = 'W' + AND cd1.cd_marital_status = cd2.cd_marital_status + AND cd1.cd_education_status = 'Primary' + AND cd1.cd_education_status = cd2.cd_education_status + AND ws_sales_price BETWEEN 100.00 AND 150.00 ) + OR ( cd1.cd_marital_status = 'D' + AND cd1.cd_marital_status = cd2.cd_marital_status + AND cd1.cd_education_status = 'Secondary' + AND cd1.cd_education_status = cd2.cd_education_status + AND ws_sales_price BETWEEN 50.00 AND 100.00 ) + OR ( 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 150.00 AND 200.00 ) ) + AND ( ( ca_country = 'United States' + AND ca_state IN ( 'KY', 'ME', 'IL' ) + AND ws_net_profit BETWEEN 100 AND 200 ) + OR ( ca_country = 'United States' + AND ca_state IN ( 'OK', 'NE', 'MN' ) + AND ws_net_profit BETWEEN 150 AND 300 ) + OR ( ca_country = 'United States' + AND ca_state IN ( 'FL', 'WI', 'KS' ) + AND ws_net_profit BETWEEN 50 AND 250 ) ) +GROUP BY r_reason_desc +ORDER BY Substr(r_reason_desc, 1, 20), + Avg(ws_quantity), + Avg(wr_refunded_cash), + Avg(wr_fee) +LIMIT 100; diff --git a/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query86.sql b/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query86.sql new file mode 100644 index 0000000000..511b33fb29 --- /dev/null +++ b/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query86.sql @@ -0,0 +1,24 @@ +-- start query 86 in stream 0 using template query86.tpl +SELECT Sum(ws_net_paid) AS total_sum, + i_category, + i_class, + Grouping(i_category) + Grouping(i_class) AS lochierarchy, + Rank() + OVER ( + partition BY Grouping(i_category)+Grouping(i_class), CASE + WHEN Grouping( + i_class) = 0 THEN i_category END + ORDER BY Sum(ws_net_paid) DESC) AS rank_within_parent +FROM web_sales, + date_dim d1, + item +WHERE d1.d_month_seq BETWEEN 1183 AND 1183 + 11 + AND d1.d_date_sk = ws_sold_date_sk + AND i_item_sk = ws_item_sk +GROUP BY rollup( i_category, i_class ) +ORDER BY lochierarchy DESC, + CASE + WHEN lochierarchy = 0 THEN i_category + END, + rank_within_parent +LIMIT 100; diff --git a/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query87.sql b/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query87.sql new file mode 100644 index 0000000000..49c99464d9 --- /dev/null +++ b/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query87.sql @@ -0,0 +1,22 @@ +-- start query 87 in stream 0 using template query87.tpl +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 1188 and 1188+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 1188 and 1188+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 1188 and 1188+11) +) cool_cust +; + diff --git a/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query88.sql b/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query88.sql new file mode 100644 index 0000000000..1f77fe1fd8 --- /dev/null +++ b/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query88.sql @@ -0,0 +1,93 @@ +-- start query 88 in stream 0 using template query88.tpl +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 = -1 and household_demographics.hd_vehicle_count<=-1+2) or + (household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2) or + (household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+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 = -1 and household_demographics.hd_vehicle_count<=-1+2) or + (household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2) or + (household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+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 = -1 and household_demographics.hd_vehicle_count<=-1+2) or + (household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2) or + (household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+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 = -1 and household_demographics.hd_vehicle_count<=-1+2) or + (household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2) or + (household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+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 = -1 and household_demographics.hd_vehicle_count<=-1+2) or + (household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2) or + (household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+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 = -1 and household_demographics.hd_vehicle_count<=-1+2) or + (household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2) or + (household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+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 = -1 and household_demographics.hd_vehicle_count<=-1+2) or + (household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2) or + (household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+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 = -1 and household_demographics.hd_vehicle_count<=-1+2) or + (household_demographics.hd_dep_count = 2 and household_demographics.hd_vehicle_count<=2+2) or + (household_demographics.hd_dep_count = 3 and household_demographics.hd_vehicle_count<=3+2)) + and store.s_store_name = 'ese') s8 +; + diff --git a/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query89.sql b/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query89.sql new file mode 100644 index 0000000000..2004a4fe26 --- /dev/null +++ b/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query89.sql @@ -0,0 +1,40 @@ +-- start query 89 in stream 0 using template query89.tpl +SELECT * +FROM (SELECT i_category, + i_class, + i_brand, + s_store_name, + s_company_name, + d_moy, + Sum(ss_sales_price) sum_sales, + Avg(Sum(ss_sales_price)) + OVER ( + partition BY i_category, i_brand, s_store_name, s_company_name + ) + avg_monthly_sales + FROM item, + store_sales, + date_dim, + store + WHERE ss_item_sk = i_item_sk + AND ss_sold_date_sk = d_date_sk + AND ss_store_sk = s_store_sk + AND d_year IN ( 2002 ) + AND ( ( i_category IN ( 'Home', 'Men', 'Sports' ) + AND i_class IN ( 'paint', 'accessories', 'fitness' ) ) + OR ( i_category IN ( 'Shoes', 'Jewelry', 'Women' ) + AND i_class IN ( 'mens', 'pendants', 'swimwear' ) ) ) + GROUP BY i_category, + i_class, + i_brand, + s_store_name, + s_company_name, + d_moy) tmp1 +WHERE CASE + WHEN ( avg_monthly_sales <> 0 ) THEN ( + Abs(sum_sales - avg_monthly_sales) / avg_monthly_sales ) + ELSE NULL + END > 0.1 +ORDER BY sum_sales - avg_monthly_sales, + s_store_name +LIMIT 100; diff --git a/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query90.sql b/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query90.sql new file mode 100644 index 0000000000..5a4778b1b8 --- /dev/null +++ b/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query90.sql @@ -0,0 +1,28 @@ + +-- start query 90 in stream 0 using template query90.tpl +SELECT Cast(amc AS DECIMAL(15, 4)) / Cast(pmc AS DECIMAL(15, 4)) + am_pm_ratio +FROM (SELECT Count(*) amc + FROM web_sales, + household_demographics, + time_dim, + web_page + WHERE ws_sold_time_sk = time_dim.t_time_sk + AND ws_ship_hdemo_sk = household_demographics.hd_demo_sk + AND ws_web_page_sk = web_page.wp_web_page_sk + AND time_dim.t_hour BETWEEN 12 AND 12 + 1 + AND household_demographics.hd_dep_count = 8 + AND web_page.wp_char_count BETWEEN 5000 AND 5200) at1, + (SELECT Count(*) pmc + FROM web_sales, + household_demographics, + time_dim, + web_page + WHERE ws_sold_time_sk = time_dim.t_time_sk + AND ws_ship_hdemo_sk = household_demographics.hd_demo_sk + AND ws_web_page_sk = web_page.wp_web_page_sk + AND time_dim.t_hour BETWEEN 20 AND 20 + 1 + AND household_demographics.hd_dep_count = 8 + AND web_page.wp_char_count BETWEEN 5000 AND 5200) pt +ORDER BY am_pm_ratio +LIMIT 100; diff --git a/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query91.sql b/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query91.sql new file mode 100644 index 0000000000..1462192de0 --- /dev/null +++ b/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query91.sql @@ -0,0 +1,32 @@ +-- start query 91 in stream 0 using template query91.tpl +SELECT cc_call_center_id Call_Center, + cc_name Call_Center_Name, + cc_manager Manager, + Sum(cr_net_loss) Returns_Loss +FROM call_center, + catalog_returns, + date_dim, + customer, + customer_address, + customer_demographics, + household_demographics +WHERE cr_call_center_sk = cc_call_center_sk + AND cr_returned_date_sk = d_date_sk + AND cr_returning_customer_sk = c_customer_sk + AND cd_demo_sk = c_current_cdemo_sk + AND hd_demo_sk = c_current_hdemo_sk + AND ca_address_sk = c_current_addr_sk + AND d_year = 1999 + AND d_moy = 12 + AND ( ( cd_marital_status = 'M' + AND cd_education_status = 'Unknown' ) + OR ( cd_marital_status = 'W' + AND cd_education_status = 'Advanced Degree' ) ) + AND hd_buy_potential LIKE 'Unknown%' + AND ca_gmt_offset = -7 +GROUP BY cc_call_center_id, + cc_name, + cc_manager, + cd_marital_status, + cd_education_status +ORDER BY Sum(cr_net_loss) DESC; diff --git a/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query92.sql b/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query92.sql new file mode 100644 index 0000000000..ddbf2e152c --- /dev/null +++ b/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query92.sql @@ -0,0 +1,23 @@ +-- start query 92 in stream 0 using template query92.tpl +SELECT + Sum(ws_ext_discount_amt) AS `Excess Discount Amount` +FROM web_sales , + item , + date_dim +WHERE i_manufact_id = 718 +AND i_item_sk = ws_item_sk +AND d_date BETWEEN '2002-03-29' AND ( + Cast('2002-03-29' AS DATE) + INTERVAL '90' day) +AND d_date_sk = ws_sold_date_sk +AND ws_ext_discount_amt > + ( + SELECT 1.3 * avg(ws_ext_discount_amt) + FROM web_sales , + date_dim + WHERE ws_item_sk = i_item_sk + AND d_date BETWEEN '2002-03-29' AND ( + cast('2002-03-29' AS date) + INTERVAL '90' day) + AND d_date_sk = ws_sold_date_sk ) +ORDER BY sum(ws_ext_discount_amt) +LIMIT 100; + diff --git a/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query93.sql b/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query93.sql new file mode 100644 index 0000000000..1a5aeb81ca --- /dev/null +++ b/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query93.sql @@ -0,0 +1,22 @@ +-- start query 93 in stream 0 using template query93.tpl +SELECT ss_customer_sk, + Sum(act_sales) sumsales +FROM (SELECT ss_item_sk, + ss_ticket_number, + ss_customer_sk, + CASE + WHEN sr_return_quantity IS NOT NULL THEN + ( ss_quantity - sr_return_quantity ) * ss_sales_price + ELSE ( ss_quantity * ss_sales_price ) + END act_sales + FROM store_sales + LEFT OUTER JOIN store_returns + ON ( sr_item_sk = ss_item_sk + AND sr_ticket_number = ss_ticket_number ), + reason + WHERE sr_reason_sk = r_reason_sk + AND r_reason_desc = 'reason 38') t +GROUP BY ss_customer_sk +ORDER BY sumsales, + ss_customer_sk +LIMIT 100; diff --git a/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query94.sql b/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query94.sql new file mode 100644 index 0000000000..18cc4c0e25 --- /dev/null +++ b/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query94.sql @@ -0,0 +1,30 @@ +-- start query 94 in stream 0 using template query94.tpl +SELECT + Count(DISTINCT ws_order_number) AS `order count` , + Sum(ws_ext_ship_cost) AS `total shipping cost` , + Sum(ws_net_profit) AS `total net profit` +FROM web_sales ws1 , + date_dim , + customer_address , + web_site +WHERE d_date BETWEEN '2000-3-01' AND ( + Cast('2000-3-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 = 'MT' +AND ws1.ws_web_site_sk = web_site_sk +AND web_company_name = 'pri' +AND EXISTS + ( + SELECT * + FROM web_sales ws2 + WHERE ws1.ws_order_number = ws2.ws_order_number + AND ws1.ws_warehouse_sk <> ws2.ws_warehouse_sk) +AND NOT EXISTS + ( + SELECT * + FROM web_returns wr1 + WHERE ws1.ws_order_number = wr1.wr_order_number) +ORDER BY count(DISTINCT ws_order_number) +LIMIT 100; + diff --git a/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query95.sql b/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query95.sql new file mode 100644 index 0000000000..099c9d2f60 --- /dev/null +++ b/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query95.sql @@ -0,0 +1,38 @@ +-- start query 95 in stream 0 using template query95.tpl +WITH ws_wh AS +( + SELECT ws1.ws_order_number, + ws1.ws_warehouse_sk wh1, + ws2.ws_warehouse_sk wh2 + FROM web_sales ws1, + web_sales ws2 + WHERE ws1.ws_order_number = ws2.ws_order_number + AND ws1.ws_warehouse_sk <> ws2.ws_warehouse_sk) +SELECT + Count(DISTINCT ws_order_number) AS `order count` , + Sum(ws_ext_ship_cost) AS `total shipping cost` , + Sum(ws_net_profit) AS `total net profit` +FROM web_sales ws1 , + date_dim , + customer_address , + web_site +WHERE d_date BETWEEN '2000-4-01' AND ( + Cast('2000-4-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 = 'IN' +AND ws1.ws_web_site_sk = web_site_sk +AND web_company_name = 'pri' +AND ws1.ws_order_number IN + ( + SELECT ws_order_number + FROM ws_wh) +AND ws1.ws_order_number IN + ( + SELECT wr_order_number + FROM web_returns, + ws_wh + WHERE wr_order_number = ws_wh.ws_order_number) +ORDER BY count(DISTINCT ws_order_number) +LIMIT 100; + diff --git a/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query96.sql b/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query96.sql new file mode 100644 index 0000000000..25bc83e01a --- /dev/null +++ b/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query96.sql @@ -0,0 +1,15 @@ +-- start query 96 in stream 0 using template query96.tpl +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 = 15 + AND time_dim.t_minute >= 30 + AND household_demographics.hd_dep_count = 7 + AND store.s_store_name = 'ese' +ORDER BY Count(*) +LIMIT 100; diff --git a/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query97.sql b/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query97.sql new file mode 100644 index 0000000000..58d95211c1 --- /dev/null +++ b/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query97.sql @@ -0,0 +1,40 @@ + +-- start query 97 in stream 0 using template query97.tpl +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 1196 AND 1196 + 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 1196 AND 1196 + 11 + GROUP BY cs_bill_customer_sk, + cs_item_sk) +SELECT Sum(CASE + WHEN ssci.customer_sk IS NOT NULL + AND csci.customer_sk IS NULL THEN 1 + ELSE 0 + END) store_only, + Sum(CASE + WHEN ssci.customer_sk IS NULL + AND csci.customer_sk IS NOT NULL THEN 1 + ELSE 0 + END) catalog_only, + Sum(CASE + WHEN ssci.customer_sk IS NOT NULL + AND csci.customer_sk IS NOT NULL THEN 1 + ELSE 0 + END) store_and_catalog +FROM ssci + FULL OUTER JOIN csci + ON ( ssci.customer_sk = csci.customer_sk + AND ssci.item_sk = csci.item_sk ) +LIMIT 100; diff --git a/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query98.sql b/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query98.sql new file mode 100644 index 0000000000..cfd04a601e --- /dev/null +++ b/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query98.sql @@ -0,0 +1,29 @@ + +-- start query 98 in stream 0 using template query98.tpl +SELECT i_item_id, + i_item_desc, + i_category, + i_class, + i_current_price, + Sum(ss_ext_sales_price) AS itemrevenue, + Sum(ss_ext_sales_price) * 100 / Sum(Sum(ss_ext_sales_price)) + OVER ( + PARTITION BY i_class) AS revenueratio +FROM store_sales, + item, + date_dim +WHERE ss_item_sk = i_item_sk + AND i_category IN ( 'Men', 'Home', 'Electronics' ) + AND ss_sold_date_sk = d_date_sk + AND d_date BETWEEN CAST('2000-05-18' AS DATE) AND ( + CAST('2000-05-18' AS DATE) + INTERVAL '30' DAY ) +GROUP BY i_item_id, + i_item_desc, + i_category, + i_class, + i_current_price +ORDER BY i_category, + i_class, + i_item_id, + i_item_desc, + revenueratio; diff --git a/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query99.sql b/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query99.sql new file mode 100644 index 0000000000..3acbf53481 --- /dev/null +++ b/partiql-planner/src/testFixtures/resources/inputs/tpc_ds/query99.sql @@ -0,0 +1,47 @@ + + +-- start query 99 in stream 0 using template query99.tpl +SELECT Substr(w_warehouse_name, 1, 20), + sm_type, + cc_name, + Sum(CASE + WHEN ( cs_ship_date_sk - cs_sold_date_sk <= 30 ) THEN 1 + ELSE 0 + END) AS `30 days`, + Sum(CASE + WHEN ( cs_ship_date_sk - cs_sold_date_sk > 30 ) + AND ( cs_ship_date_sk - cs_sold_date_sk <= 60 ) THEN 1 + ELSE 0 + END) AS `31-60 days`, + Sum(CASE + WHEN ( cs_ship_date_sk - cs_sold_date_sk > 60 ) + AND ( cs_ship_date_sk - cs_sold_date_sk <= 90 ) THEN 1 + ELSE 0 + END) AS `61-90 days`, + Sum(CASE + WHEN ( cs_ship_date_sk - cs_sold_date_sk > 90 ) + AND ( cs_ship_date_sk - cs_sold_date_sk <= 120 ) THEN + 1 + ELSE 0 + END) AS `91-120 days`, + Sum(CASE + WHEN ( cs_ship_date_sk - cs_sold_date_sk > 120 ) THEN 1 + ELSE 0 + END) AS `>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), + sm_type, + cc_name +LIMIT 100; diff --git a/partiql-planner/src/testFixtures/resources/inputs/tpc_h/query01.sql b/partiql-planner/src/testFixtures/resources/inputs/tpc_h/query01.sql new file mode 100644 index 0000000000..a388f00f34 --- /dev/null +++ b/partiql-planner/src/testFixtures/resources/inputs/tpc_h/query01.sql @@ -0,0 +1,22 @@ +--#[tpc-h-01] +select + l_returnflag, + l_linestatus, + sum(l_quantity) as sum_qty, + sum(l_extendedprice) as sum_base_price, + sum(l_extendedprice * (1 - l_discount)) as sum_disc_price, + sum(l_extendedprice * (1 - l_discount) * (1 + l_tax)) as sum_charge, + avg(l_quantity) as avg_qty, + avg(l_extendedprice) as avg_price, + avg(l_discount) as avg_disc, + count(*) as count_order +from + lineitem +where + l_shipdate <= date '1998-12-01' - interval ':1' day (3) +group by + l_returnflag, + l_linestatus +order by + l_returnflag, + l_linestatus; diff --git a/partiql-planner/src/testFixtures/resources/inputs/tpc_h/query02.sql b/partiql-planner/src/testFixtures/resources/inputs/tpc_h/query02.sql new file mode 100644 index 0000000000..0d4080ada1 --- /dev/null +++ b/partiql-planner/src/testFixtures/resources/inputs/tpc_h/query02.sql @@ -0,0 +1,44 @@ +--#[tpc-h-02] +select + s_acctbal, + s_name, + n_name, + p_partkey, + p_mfgr, + s_address, + s_phone, + s_comment +from + part, + supplier, + partsupp, + nation, + region +where + p_partkey = ps_partkey + and s_suppkey = ps_suppkey + and p_size = :1 + and p_type like '%:2' + and s_nationkey = n_nationkey + and n_regionkey = r_regionkey + and r_name = ':3' + and ps_supplycost = ( + select + min(ps_supplycost) + from + partsupp, + supplier, + nation, + region + where + p_partkey = ps_partkey + and s_suppkey = ps_suppkey + and s_nationkey = n_nationkey + and n_regionkey = r_regionkey + and r_name = ':3' + ) +order by + s_acctbal desc, + n_name, + s_name, + p_partkey; diff --git a/partiql-planner/src/testFixtures/resources/inputs/tpc_h/query03.sql b/partiql-planner/src/testFixtures/resources/inputs/tpc_h/query03.sql new file mode 100644 index 0000000000..611bb9d30b --- /dev/null +++ b/partiql-planner/src/testFixtures/resources/inputs/tpc_h/query03.sql @@ -0,0 +1,23 @@ +--#[tpc-h-03] +select + l_orderkey, + sum(l_extendedprice * (1 - l_discount)) as revenue, + o_orderdate, + o_shippriority +from + customer, + orders, + lineitem +where + c_mktsegment = ':1' + and c_custkey = o_custkey + and l_orderkey = o_orderkey + and o_orderdate < date ':2' + and l_shipdate > date ':2' +group by + l_orderkey, + o_orderdate, + o_shippriority +order by + revenue desc, + o_orderdate; diff --git a/partiql-planner/src/testFixtures/resources/inputs/tpc_h/query04.sql b/partiql-planner/src/testFixtures/resources/inputs/tpc_h/query04.sql new file mode 100644 index 0000000000..4104fbd6b4 --- /dev/null +++ b/partiql-planner/src/testFixtures/resources/inputs/tpc_h/query04.sql @@ -0,0 +1,22 @@ +--#[tpc-h-04] +select + o_orderpriority, + count(*) as order_count +from + orders +where + o_orderdate >= date ':1' + and o_orderdate < date ':1' + interval '3' month + and exists ( + select + * + from + lineitem + where + l_orderkey = o_orderkey + and l_commitdate < l_receiptdate + ) +group by + o_orderpriority +order by + o_orderpriority; diff --git a/partiql-planner/src/testFixtures/resources/inputs/tpc_h/query05.sql b/partiql-planner/src/testFixtures/resources/inputs/tpc_h/query05.sql new file mode 100644 index 0000000000..bca162d1ec --- /dev/null +++ b/partiql-planner/src/testFixtures/resources/inputs/tpc_h/query05.sql @@ -0,0 +1,25 @@ +--#[tpc-h-05] +select + n_name, + sum(l_extendedprice * (1 - l_discount)) as revenue +from + customer, + orders, + lineitem, + supplier, + nation, + region +where + c_custkey = o_custkey + and l_orderkey = o_orderkey + and l_suppkey = s_suppkey + and c_nationkey = s_nationkey + and s_nationkey = n_nationkey + and n_regionkey = r_regionkey + and r_name = ':1' + and o_orderdate >= date ':2' + and o_orderdate < date ':2' + interval '1' year +group by + n_name +order by + revenue desc; diff --git a/partiql-planner/src/testFixtures/resources/inputs/tpc_h/query06.sql b/partiql-planner/src/testFixtures/resources/inputs/tpc_h/query06.sql new file mode 100644 index 0000000000..8698a28a40 --- /dev/null +++ b/partiql-planner/src/testFixtures/resources/inputs/tpc_h/query06.sql @@ -0,0 +1,16 @@ +-- $ID$ +-- TPC-H/TPC-R Forecasting Revenue Change Query (Q6) +-- Functional Query Definition +-- Approved February 1998 +:x +:o +select + sum(l_extendedprice * l_discount) as revenue +from + lineitem +where + l_shipdate >= date ':1' + and l_shipdate < date ':1' + interval '1' year + and l_discount between :2 - 0.01 and :2 + 0.01 + and l_quantity < :3; +:n -1 diff --git a/partiql-planner/src/testFixtures/resources/inputs/tpc_h/query07.sql b/partiql-planner/src/testFixtures/resources/inputs/tpc_h/query07.sql new file mode 100644 index 0000000000..624f6bc4e6 --- /dev/null +++ b/partiql-planner/src/testFixtures/resources/inputs/tpc_h/query07.sql @@ -0,0 +1,40 @@ +--#[tpc-h-07] +select + supp_nation, + cust_nation, + l_year, + sum(volume) as revenue +from + ( + select + n1.n_name as supp_nation, + n2.n_name as cust_nation, + extract(year from l_shipdate) as l_year, + l_extendedprice * (1 - l_discount) as volume + from + supplier, + lineitem, + orders, + customer, + nation n1, + nation n2 + where + s_suppkey = l_suppkey + and o_orderkey = l_orderkey + and c_custkey = o_custkey + and s_nationkey = n1.n_nationkey + and c_nationkey = n2.n_nationkey + and ( + (n1.n_name = ':1' and n2.n_name = ':2') + or (n1.n_name = ':2' and n2.n_name = ':1') + ) + and l_shipdate between date '1995-01-01' and date '1996-12-31' + ) as shipping +group by + supp_nation, + cust_nation, + l_year +order by + supp_nation, + cust_nation, + l_year; diff --git a/partiql-planner/src/testFixtures/resources/inputs/tpc_h/query08.sql b/partiql-planner/src/testFixtures/resources/inputs/tpc_h/query08.sql new file mode 100644 index 0000000000..b1c30c27c3 --- /dev/null +++ b/partiql-planner/src/testFixtures/resources/inputs/tpc_h/query08.sql @@ -0,0 +1,39 @@ +--#[tpc-h-08] +select + o_year, + sum(case + when nation = ':1' then volume + else 0 + end) / sum(volume) as mkt_share +from + ( + select + extract(year from o_orderdate) as o_year, + l_extendedprice * (1 - l_discount) as volume, + n2.n_name as nation + from + part, + supplier, + lineitem, + orders, + customer, + nation n1, + nation n2, + region + where + p_partkey = l_partkey + and s_suppkey = l_suppkey + and l_orderkey = o_orderkey + and o_custkey = c_custkey + and c_nationkey = n1.n_nationkey + and n1.n_regionkey = r_regionkey + and r_name = ':2' + and s_nationkey = n2.n_nationkey + and o_orderdate between date '1995-01-01' and date '1996-12-31' + and p_type = ':3' + ) as all_nations +group by + o_year +order by + o_year; +:n -1 diff --git a/partiql-planner/src/testFixtures/resources/inputs/tpc_h/query09.sql b/partiql-planner/src/testFixtures/resources/inputs/tpc_h/query09.sql new file mode 100644 index 0000000000..58dcbe7f7a --- /dev/null +++ b/partiql-planner/src/testFixtures/resources/inputs/tpc_h/query09.sql @@ -0,0 +1,33 @@ +--#[tpc-h-09] +select + nation, + o_year, + sum(amount) as sum_profit +from + ( + select + n_name as nation, + extract(year from o_orderdate) as o_year, + l_extendedprice * (1 - l_discount) - ps_supplycost * l_quantity as amount + from + part, + supplier, + lineitem, + partsupp, + orders, + nation + where + s_suppkey = l_suppkey + and ps_suppkey = l_suppkey + and ps_partkey = l_partkey + and p_partkey = l_partkey + and o_orderkey = l_orderkey + and s_nationkey = n_nationkey + and p_name like '%:1%' + ) as profit +group by + nation, + o_year +order by + nation, + o_year desc; diff --git a/partiql-planner/src/testFixtures/resources/inputs/tpc_h/query10.sql b/partiql-planner/src/testFixtures/resources/inputs/tpc_h/query10.sql new file mode 100644 index 0000000000..300192480e --- /dev/null +++ b/partiql-planner/src/testFixtures/resources/inputs/tpc_h/query10.sql @@ -0,0 +1,32 @@ +--#[tpc-h-10] +select + c_custkey, + c_name, + sum(l_extendedprice * (1 - l_discount)) as revenue, + c_acctbal, + n_name, + c_address, + c_phone, + c_comment +from + customer, + orders, + lineitem, + nation +where + c_custkey = o_custkey + and l_orderkey = o_orderkey + and o_orderdate >= date ':1' + and o_orderdate < date ':1' + interval '3' month + and l_returnflag = 'R' + and c_nationkey = n_nationkey +group by + c_custkey, + c_name, + c_acctbal, + c_phone, + n_name, + c_address, + c_comment +order by + revenue desc; diff --git a/partiql-planner/src/testFixtures/resources/inputs/tpc_h/query11.sql b/partiql-planner/src/testFixtures/resources/inputs/tpc_h/query11.sql new file mode 100644 index 0000000000..54820dfcdd --- /dev/null +++ b/partiql-planner/src/testFixtures/resources/inputs/tpc_h/query11.sql @@ -0,0 +1,28 @@ +--#[tpch-h-11] +select + ps_partkey, + sum(ps_supplycost * ps_availqty) as value +from + partsupp, + supplier, + nation +where + ps_suppkey = s_suppkey + and s_nationkey = n_nationkey + and n_name = ':1' +group by + ps_partkey having + sum(ps_supplycost * ps_availqty) > ( + select + sum(ps_supplycost * ps_availqty) * :2 + from + partsupp, + supplier, + nation + where + ps_suppkey = s_suppkey + and s_nationkey = n_nationkey + and n_name = ':1' + ) +order by + value desc; diff --git a/partiql-planner/src/testFixtures/resources/inputs/tpc_h/query12.sql b/partiql-planner/src/testFixtures/resources/inputs/tpc_h/query12.sql new file mode 100644 index 0000000000..5515ddbc2a --- /dev/null +++ b/partiql-planner/src/testFixtures/resources/inputs/tpc_h/query12.sql @@ -0,0 +1,29 @@ +--#[tpc-h-12] +select + l_shipmode, + sum(case + when o_orderpriority = '1-URGENT' + or o_orderpriority = '2-HIGH' + then 1 + else 0 + end) as high_line_count, + sum(case + when o_orderpriority <> '1-URGENT' + and o_orderpriority <> '2-HIGH' + then 1 + else 0 + end) as low_line_count +from + orders, + lineitem +where + o_orderkey = l_orderkey + and l_shipmode in (':1', ':2') + and l_commitdate < l_receiptdate + and l_shipdate < l_commitdate + and l_receiptdate >= date ':3' + and l_receiptdate < date ':3' + interval '1' year +group by + l_shipmode +order by + l_shipmode; diff --git a/partiql-planner/src/testFixtures/resources/inputs/tpc_h/query13.sql b/partiql-planner/src/testFixtures/resources/inputs/tpc_h/query13.sql new file mode 100644 index 0000000000..adf10eb539 --- /dev/null +++ b/partiql-planner/src/testFixtures/resources/inputs/tpc_h/query13.sql @@ -0,0 +1,21 @@ +--#[tpc-h-13] +select + c_count, + count(*) as custdist +from + ( + select + c_custkey, + count(o_orderkey) + from + customer left outer join orders on + c_custkey = o_custkey + and o_comment not like '%:1%:2%' + group by + c_custkey + ) as c_orders (c_custkey, c_count) +group by + c_count +order by + custdist desc, + c_count desc; diff --git a/partiql-planner/src/testFixtures/resources/inputs/tpc_h/query14.sql b/partiql-planner/src/testFixtures/resources/inputs/tpc_h/query14.sql new file mode 100644 index 0000000000..e7b50f537d --- /dev/null +++ b/partiql-planner/src/testFixtures/resources/inputs/tpc_h/query14.sql @@ -0,0 +1,14 @@ +--#[tpc-h-14] +select + 100.00 * sum(case + when p_type like 'PROMO%' + then l_extendedprice * (1 - l_discount) + else 0 + end) / sum(l_extendedprice * (1 - l_discount)) as promo_revenue +from + lineitem, + part +where + l_partkey = p_partkey + and l_shipdate >= date ':1' + and l_shipdate < date ':1' + interval '1' month; diff --git a/partiql-planner/src/testFixtures/resources/inputs/tpc_h/query15.sql b/partiql-planner/src/testFixtures/resources/inputs/tpc_h/query15.sql new file mode 100644 index 0000000000..bafd089f2f --- /dev/null +++ b/partiql-planner/src/testFixtures/resources/inputs/tpc_h/query15.sql @@ -0,0 +1,35 @@ +--#[tpch-h-15] +create view revenue:s (supplier_no, total_revenue) as + select + l_suppkey, + sum(l_extendedprice * (1 - l_discount)) + from + lineitem + where + l_shipdate >= date ':1' + and l_shipdate < date ':1' + interval '3' month + group by + l_suppkey; + +:o +select + s_suppkey, + s_name, + s_address, + s_phone, + total_revenue +from + supplier, + revenue:s +where + s_suppkey = supplier_no + and total_revenue = ( + select + max(total_revenue) + from + revenue:s + ) +order by + s_suppkey; + +drop view revenue:s; diff --git a/partiql-planner/src/testFixtures/resources/inputs/tpc_h/query16.sql b/partiql-planner/src/testFixtures/resources/inputs/tpc_h/query16.sql new file mode 100644 index 0000000000..75f9ccfbf0 --- /dev/null +++ b/partiql-planner/src/testFixtures/resources/inputs/tpc_h/query16.sql @@ -0,0 +1,31 @@ +--#[tpc-h-16] +select + p_brand, + p_type, + p_size, + count(distinct ps_suppkey) as supplier_cnt +from + partsupp, + part +where + p_partkey = ps_partkey + and p_brand <> ':1' + and p_type not like ':2%' + and p_size in (:3, :4, :5, :6, :7, :8, :9, :10) + and ps_suppkey not in ( + select + s_suppkey + from + supplier + where + s_comment like '%Customer%Complaints%' + ) +group by + p_brand, + p_type, + p_size +order by + supplier_cnt desc, + p_brand, + p_type, + p_size; diff --git a/partiql-planner/src/testFixtures/resources/inputs/tpc_h/query17.sql b/partiql-planner/src/testFixtures/resources/inputs/tpc_h/query17.sql new file mode 100644 index 0000000000..f999a6b3ec --- /dev/null +++ b/partiql-planner/src/testFixtures/resources/inputs/tpc_h/query17.sql @@ -0,0 +1,18 @@ +--#[tpc-h-17] +select + sum(l_extendedprice) / 7.0 as avg_yearly +from + lineitem, + part +where + p_partkey = l_partkey + and p_brand = ':1' + and p_container = ':2' + and l_quantity < ( + select + 0.2 * avg(l_quantity) + from + lineitem + where + l_partkey = p_partkey + ); diff --git a/partiql-planner/src/testFixtures/resources/inputs/tpc_h/query18.sql b/partiql-planner/src/testFixtures/resources/inputs/tpc_h/query18.sql new file mode 100644 index 0000000000..3aab619d1a --- /dev/null +++ b/partiql-planner/src/testFixtures/resources/inputs/tpc_h/query18.sql @@ -0,0 +1,33 @@ +--#[tpc-h-18] +select + c_name, + c_custkey, + o_orderkey, + o_orderdate, + o_totalprice, + sum(l_quantity) +from + customer, + orders, + lineitem +where + o_orderkey in ( + select + l_orderkey + from + lineitem + group by + l_orderkey having + sum(l_quantity) > :1 + ) + and c_custkey = o_custkey + and o_orderkey = l_orderkey +group by + c_name, + c_custkey, + o_orderkey, + o_orderdate, + o_totalprice +order by + o_totalprice desc, + o_orderdate; diff --git a/partiql-planner/src/testFixtures/resources/inputs/tpc_h/query19.sql b/partiql-planner/src/testFixtures/resources/inputs/tpc_h/query19.sql new file mode 100644 index 0000000000..abd8dc0517 --- /dev/null +++ b/partiql-planner/src/testFixtures/resources/inputs/tpc_h/query19.sql @@ -0,0 +1,36 @@ +--#[tpc-h-19] +select + sum(l_extendedprice* (1 - l_discount)) as revenue +from + lineitem, + part +where + ( + p_partkey = l_partkey + and p_brand = ':1' + and p_container in ('SM CASE', 'SM BOX', 'SM PACK', 'SM PKG') + and l_quantity >= :4 and l_quantity <= :4 + 10 + and p_size between 1 and 5 + and l_shipmode in ('AIR', 'AIR REG') + and l_shipinstruct = 'DELIVER IN PERSON' + ) + or + ( + p_partkey = l_partkey + and p_brand = ':2' + and p_container in ('MED BAG', 'MED BOX', 'MED PKG', 'MED PACK') + and l_quantity >= :5 and l_quantity <= :5 + 10 + and p_size between 1 and 10 + and l_shipmode in ('AIR', 'AIR REG') + and l_shipinstruct = 'DELIVER IN PERSON' + ) + or + ( + p_partkey = l_partkey + and p_brand = ':3' + and p_container in ('LG CASE', 'LG BOX', 'LG PACK', 'LG PKG') + and l_quantity >= :6 and l_quantity <= :6 + 10 + and p_size between 1 and 15 + and l_shipmode in ('AIR', 'AIR REG') + and l_shipinstruct = 'DELIVER IN PERSON' + ); diff --git a/partiql-planner/src/testFixtures/resources/inputs/tpc_h/query20.sql b/partiql-planner/src/testFixtures/resources/inputs/tpc_h/query20.sql new file mode 100644 index 0000000000..3bd75d6cf2 --- /dev/null +++ b/partiql-planner/src/testFixtures/resources/inputs/tpc_h/query20.sql @@ -0,0 +1,38 @@ +--#[tpc-h-20] +select + s_name, + s_address +from + supplier, + nation +where + s_suppkey in ( + select + ps_suppkey + from + partsupp + where + ps_partkey in ( + select + p_partkey + from + part + where + p_name like ':1%' + ) + and ps_availqty > ( + select + 0.5 * sum(l_quantity) + from + lineitem + where + l_partkey = ps_partkey + and l_suppkey = ps_suppkey + and l_shipdate >= date ':2' + and l_shipdate < date ':2' + interval '1' year + ) + ) + and s_nationkey = n_nationkey + and n_name = ':3' +order by + s_name; diff --git a/partiql-planner/src/testFixtures/resources/inputs/tpc_h/query21.sql b/partiql-planner/src/testFixtures/resources/inputs/tpc_h/query21.sql new file mode 100644 index 0000000000..86e9bbcb76 --- /dev/null +++ b/partiql-planner/src/testFixtures/resources/inputs/tpc_h/query21.sql @@ -0,0 +1,40 @@ +--#[tpc-h-21] +select + s_name, + count(*) as numwait +from + supplier, + lineitem l1, + orders, + nation +where + s_suppkey = l1.l_suppkey + and o_orderkey = l1.l_orderkey + and o_orderstatus = 'F' + and l1.l_receiptdate > l1.l_commitdate + and exists ( + select + * + from + lineitem l2 + where + l2.l_orderkey = l1.l_orderkey + and l2.l_suppkey <> l1.l_suppkey + ) + and not exists ( + select + * + from + lineitem l3 + where + l3.l_orderkey = l1.l_orderkey + and l3.l_suppkey <> l1.l_suppkey + and l3.l_receiptdate > l3.l_commitdate + ) + and s_nationkey = n_nationkey + and n_name = ':1' +group by + s_name +order by + numwait desc, + s_name; diff --git a/partiql-planner/src/testFixtures/resources/inputs/tpc_h/query22.sql b/partiql-planner/src/testFixtures/resources/inputs/tpc_h/query22.sql new file mode 100644 index 0000000000..ed010b2a21 --- /dev/null +++ b/partiql-planner/src/testFixtures/resources/inputs/tpc_h/query22.sql @@ -0,0 +1,38 @@ +--#[tpc-h-22] +select + cntrycode, + count(*) as numcust, + sum(c_acctbal) as totacctbal +from + ( + select + substring(c_phone from 1 for 2) as cntrycode, + c_acctbal + from + customer + where + substring(c_phone from 1 for 2) in + (':1', ':2', ':3', ':4', ':5', ':6', ':7') + and c_acctbal > ( + select + avg(c_acctbal) + from + customer + where + c_acctbal > 0.00 + and substring(c_phone from 1 for 2) in + (':1', ':2', ':3', ':4', ':5', ':6', ':7') + ) + and not exists ( + select + * + from + orders + where + o_custkey = c_custkey + ) + ) as custsale +group by + cntrycode +order by + cntrycode; diff --git a/partiql-planner/src/testFixtures/resources/tests/suite_00.ion b/partiql-planner/src/testFixtures/resources/tests/suite_00.ion deleted file mode 100644 index cf073b32cb..0000000000 --- a/partiql-planner/src/testFixtures/resources/tests/suite_00.ion +++ /dev/null @@ -1,152 +0,0 @@ -suite::{ - name: "suite_00", - session: { - catalog: "default", // session catalog - path: ["tpc_ds"], // session path - vars: {}, // session variables - }, - tests: { - '0000': { - statement: ''' - SELECT ss_ticket_number, ss_quantity, ss_sold_date_sk - FROM store_sales - ''', - schema: { - type: "bag", - items: { - type: "struct", - fields: [ - { - name: "ss_ticket_number", - type: "string", - }, - { - name: "ss_quantity", - type: ["int32", "null"], - }, - { - name: "ss_sold_date_sk", - type: ["date", "null"], - }, - ], - }, - }, - }, - '0001': { - statement: ''' - SELECT ss_ticket_number, ss_quantity, ss_sold_date_sk - FROM store_sales - WHERE ss_sold_date_sk > DATE_ADD(DAY, -30, UTCNOW()) - ''', - schema: { - type: "bag", - items: { - type: "struct", - fields: [ - { - name: "ss_ticket_number", - type: "string", - }, - { - name: "ss_quantity", - type: ["int32", "null"], - }, - { - name: "ss_sold_date_sk", - type: ["date", "null"], - }, - ], - }, - }, - }, - '0002': { - statement: ''' - SELECT (ss_wholesale_cost + 10 < ss_list_price) AS x - FROM store_sales - ''', - schema: { - type: "bag", - items: { - type: "struct", - fields: [ - { - name: "x", - type: ["bool", "null"], - }, - ], - }, - }, - }, - '0003': { - statement: ''' - SELECT - ss_quantity, -- This is a nullable int32 - CASE (ss_quantity) -- This case statement will always return a non-nullable string - WHEN 0 THEN 'Did not sell anything!' - WHEN 1 THEN 'Sold a single item!' - ELSE 'Sold multiple items!' - END AS ss_quantity_description_1, - CASE (ss_quantity) - WHEN 0 THEN 'Hello' -- sometimes STRING - WHEN 1 THEN 1.0 -- sometimes DECIMAL - WHEN 2 THEN 2 -- sometimes INT - -- There isn't an else here, so the output should be nullable as well. - END AS ss_quantity_description_2, - CASE (ss_quantity) - WHEN 0 THEN 'Hello' -- ss_quantity will be cast to an INT for comparison - WHEN 'not an int32' THEN 'not cast-able' -- cannot be cast! - ELSE 'fallback' - -- There is an ELSE here, so the output should NOT be nullable. - END AS ss_quantity_description_3 - FROM store_sales; - ''', - schema: { - type: "bag", - items: { - type: "struct", - fields: [ - { - name: "ss_quantity", - type: ["int32", "null"] - }, - { - name: "ss_quantity_description_1", - type: "string" - }, - { - name: "ss_quantity_description_2", - type: ["string", "decimal", "int", "null"] - }, - { - name: "ss_quantity_description_3", - type: "string" - }, - ] - } - } - }, - // TODO: Add support for SELECT * so we can assert on the schema - '0004': { - statement: ''' - SELECT s_store_sk - FROM - tpc_ds.store AS store - LEFT JOIN - tpc_ds.store_returns AS returns - ON s_store_sk = sr_store_sk - ''', - schema: { - type: "bag", - items: { - type: "struct", - fields: [ - { - name:"s_store_sk", - type:"string" - } - ] - } - } - }, - }, -} diff --git a/partiql-planner/src/testFixtures/resources/todo.txt b/partiql-planner/src/testFixtures/resources/todo.txt deleted file mode 100644 index b4bcea038b..0000000000 --- a/partiql-planner/src/testFixtures/resources/todo.txt +++ /dev/null @@ -1,2 +0,0 @@ -I have not modified the generated TPC-DS schemas so everything is NULLABLE which isn't always the case. See -https://www.tpc.org/tpc_documents_current_versions/pdf/tpc-ds_v2.6.0.pdf From 543c28132cf96fdff305fada98fc51dc7b1e8a29 Mon Sep 17 00:00:00 2001 From: "R. C. Howell" Date: Mon, 16 Oct 2023 12:37:57 -0700 Subject: [PATCH 2/3] Port some of the PartiQLSchemaInferencer tests to PlannerTests --- .../PartiQLSchemaInferencerTests.kt | 22 + .../cases/schema_inferencer/collections.ion | 66 + .../cases/schema_inferencer/exclude.ion | 1714 +++++++++++++++++ .../cases/schema_inferencer/joins.ion | 177 ++ .../cases/schema_inferencer/order_by.ion | 77 + .../sanity.ion | 0 .../inputs/schema_inferencer/collections.sql | 23 + .../inputs/schema_inferencer/exclude.sql | 461 +++++ .../inputs/schema_inferencer/joins.sql | 24 + .../inputs/schema_inferencer/order_by.sql | 8 + .../sanity.sql | 0 11 files changed, 2572 insertions(+) create mode 100644 partiql-planner/src/test/resources/cases/schema_inferencer/collections.ion create mode 100644 partiql-planner/src/test/resources/cases/schema_inferencer/exclude.ion create mode 100644 partiql-planner/src/test/resources/cases/schema_inferencer/joins.ion create mode 100644 partiql-planner/src/test/resources/cases/schema_inferencer/order_by.ion rename partiql-planner/src/test/resources/cases/{schema_inferrencer => schema_inferencer}/sanity.ion (100%) create mode 100644 partiql-planner/src/testFixtures/resources/inputs/schema_inferencer/collections.sql create mode 100644 partiql-planner/src/testFixtures/resources/inputs/schema_inferencer/exclude.sql create mode 100644 partiql-planner/src/testFixtures/resources/inputs/schema_inferencer/joins.sql create mode 100644 partiql-planner/src/testFixtures/resources/inputs/schema_inferencer/order_by.sql rename partiql-planner/src/testFixtures/resources/inputs/{schema_inferrencer => schema_inferencer}/sanity.sql (100%) diff --git a/partiql-lang/src/test/kotlin/org/partiql/lang/planner/transforms/PartiQLSchemaInferencerTests.kt b/partiql-lang/src/test/kotlin/org/partiql/lang/planner/transforms/PartiQLSchemaInferencerTests.kt index 827fd006b3..459f6dd661 100644 --- a/partiql-lang/src/test/kotlin/org/partiql/lang/planner/transforms/PartiQLSchemaInferencerTests.kt +++ b/partiql-lang/src/test/kotlin/org/partiql/lang/planner/transforms/PartiQLSchemaInferencerTests.kt @@ -93,6 +93,28 @@ class PartiQLSchemaInferencerTests { @Execution(ExecutionMode.CONCURRENT) fun testOrderBy(tc: TestCase) = runTest(tc) + // @Test + // @Disabled + // fun testPrint() { + // val cases = orderByCases() + // val prefix = "orderByCases" + // cases.forEachIndexed { i, t -> + // val name = "$prefix-${"%02d".format(i + 1)}" + // println("--#[$name]") + // println(t.query + ";") + // println() + // } + // cases.forEachIndexed { i, t -> + // val name = "$prefix-${"%02d".format(i + 1)}" + // println("case::{") + // println(" input: \"$name\",") + // println(" catalog: \"default\",") + // println(" schema: ${t.expected.toIon()}") + // println("}") + // println() + // } + // } + companion object { private val root = this::class.java.getResource("/catalogs")!!.toURI().toPath().pathString diff --git a/partiql-planner/src/test/resources/cases/schema_inferencer/collections.ion b/partiql-planner/src/test/resources/cases/schema_inferencer/collections.ion new file mode 100644 index 0000000000..e75dbdc986 --- /dev/null +++ b/partiql-planner/src/test/resources/cases/schema_inferencer/collections.ion @@ -0,0 +1,66 @@ +case::{ + input: "collections-01", + catalog: "default", + schema: { + type: "bag", + items: "int", + } +} + +case::{ + input: "collections-02", + catalog: "default", + schema: { + type: "list", + items: "int", + } +} + +case::{ + input: "collections-03", + catalog: "default", + schema: { + type: "list", + items: "int", + } +} + +case::{ + input: "collections-04", + catalog: "default", + schema: { + type: "sexp", + items: "int", + } +} + +case::{ + input: "collections-05", + catalog: "default", + schema: { + type: "bag", + items: "int", + } +} + +case::{ + input: "collections-06", + catalog: "default", + schema: { + type: "bag", + items: { + type: "struct", + constraints: [ + closed, + unique, + ordered + ], + fields: [ + { + name: "x", + type: "int", + } + ] + } + } +} diff --git a/partiql-planner/src/test/resources/cases/schema_inferencer/exclude.ion b/partiql-planner/src/test/resources/cases/schema_inferencer/exclude.ion new file mode 100644 index 0000000000..c7823e36a0 --- /dev/null +++ b/partiql-planner/src/test/resources/cases/schema_inferencer/exclude.ion @@ -0,0 +1,1714 @@ +case::{ + input: "exclude-01", + catalog: "default", + schema: { + type: "bag", + items: { + type: "struct", + fields: [ + { + name: "name", + type: "string" + }, + { + name: "custId", + type: "int" + }, + { + name: "address", + type: { + type: "struct", + fields: [ + { + name: "city", + type: "string" + }, + { + name: "zipcode", + type: "int" + }, + { + name: "street", + type: "string" + } + ], + constraints: [ + closed, + unique + ] + } + } + ], + constraints: [ + closed, + unique, + ordered + ] + } + } +} + +case::{ + input: "exclude-02", + catalog: "default", + schema: { + type: "bag", + items: { + type: "struct", + fields: [ + { + name: "name", + type: "string" + }, + { + name: "custId", + type: "int" + }, + { + name: "address", + type: { + type: "struct", + fields: [ + { + name: "city", + type: "string" + }, + { + name: "zipcode", + type: "int" + } + ], + constraints: [ + closed, + unique + ] + } + } + ], + constraints: [ + closed, + unique, + ordered + ] + } + } +} + +case::{ + input: "exclude-03", + catalog: "default", + schema: { + type: "bag", + items: { + type: "struct", + fields: [ + { + name: "a", + type: { + type: "struct", + fields: [ + { + name: "b", + type: { + type: "struct", + fields: [ + { + name: "c", + type: { + type: "list", + items: { + type: "struct", + fields: [ + { + name: "field", + type: [ + "int", + "missing" + ] + } + ], + constraints: [ + closed, + unique + ] + } + } + } + ], + constraints: [ + closed, + unique + ] + } + } + ], + constraints: [ + closed, + unique + ] + } + }, + { + name: "foo", + type: "string" + } + ], + constraints: [ + closed, + unique, + ordered + ] + } + } +} + +case::{ + input: "exclude-04", + catalog: "default", + schema: { + type: "bag", + items: { + type: "struct", + fields: [ + { + name: "a", + type: { + type: "struct", + fields: [ + { + name: "b", + type: { + type: "struct", + fields: [ + { + name: "c", + type: { + type: "list", + items: "int" + } + } + ], + constraints: [ + closed, + unique + ] + } + } + ], + constraints: [ + closed, + unique + ] + } + }, + { + name: "foo", + type: "string" + } + ], + constraints: [ + closed, + unique, + ordered + ] + } + } +} + +case::{ + input: "exclude-05", + catalog: "default", + schema: { + type: "bag", + items: { + type: "struct", + fields: [ + { + name: "a", + type: { + type: "list", + items: "int" + } + } + ], + constraints: [ + closed, + unique, + ordered + ] + } + } +} + +case::{ + input: "exclude-06", + catalog: "default", + schema: { + type: "bag", + items: { + type: "struct", + fields: [ + { + name: "a", + type: { + type: "struct", + fields: [ + { + name: "b", + type: { + type: "struct", + fields: [ + { + name: "c", + type: { + type: "list", + items: { + type: "struct", + fields: [ + { + name: "field_y", + type: "int" + } + ], + constraints: [ + closed, + unique + ] + } + } + } + ], + constraints: [ + closed, + unique + ] + } + } + ], + constraints: [ + closed, + unique + ] + } + }, + { + name: "foo", + type: "string" + } + ], + constraints: [ + closed, + unique, + ordered + ] + } + } +} + +case::{ + input: "exclude-07", + catalog: "default", + schema: { + type: "bag", + items: { + type: "struct", + fields: [ + { + name: "a", + type: { + type: "struct", + fields: [ + { + name: "b", + type: { + type: "struct", + fields: [ + { + name: "c", + type: { + type: "list", + items: { + type: "struct", + fields: [], + constraints: [ + closed, + unique + ] + } + } + } + ], + constraints: [ + closed, + unique + ] + } + } + ], + constraints: [ + closed, + unique + ] + } + }, + { + name: "foo", + type: "string" + } + ], + constraints: [ + closed, + unique, + ordered + ] + } + } +} + +case::{ + input: "exclude-08", + catalog: "default", + schema: { + type: "list", + items: { + type: "struct", + fields: [ + { + name: "foo", + type: "string" + } + ], + constraints: [ + closed, + unique, + ordered + ] + } + } +} + +case::{ + input: "exclude-09", + catalog: "default", + schema: { + type: "bag", + items: { + type: "struct", + fields: [ + { + name: "a", + type: "int" + }, + { + name: "b", + type: "int" + }, + { + name: "c", + type: "int" + } + ], + constraints: [ + closed, + unique, + ordered + ] + } + } +} + +case::{ + input: "exclude-10", + catalog: "default", + schema: { + type: "bag", + items: { + type: "struct", + fields: [ + { + name: "b", + type: { + type: "list", + items: { + type: "struct", + fields: [ + { + name: "b_2", + type: "int" + } + ], + constraints: [ + closed, + unique + ] + } + } + } + ], + constraints: [ + closed, + unique, + ordered + ] + } + } +} + +case::{ + input: "exclude-11", + catalog: "default", + schema: { + type: "bag", + items: { + type: "struct", + fields: [ + { + name: "a", + type: { + type: "struct", + fields: [ + { + name: "a_1", + type: "int" + }, + { + name: "a_2", + type: "int" + } + ], + constraints: [ + closed, + unique + ] + } + }, + { + name: "b", + type: { + type: "list", + items: { + type: "struct", + fields: [ + { + name: "b_2", + type: "int" + } + ], + constraints: [ + closed, + unique + ] + } + } + }, + { + name: "c", + type: "int" + }, + { + name: "d", + type: "int" + } + ], + constraints: [ + closed, + unique, + ordered + ] + } + } +} + +case::{ + input: "exclude-12", + catalog: "default", + schema: { + type: "bag", + items: { + type: "list", + items: { + type: "struct", + fields: [ + { + name: "b_2", + type: "int" + } + ], + constraints: [ + closed, + unique + ] + } + } + } +} + +case::{ + input: "exclude-13", + catalog: "default", + schema: { + type: "bag", + items: { + type: "struct", + fields: [ + { + name: "a", + type: { + type: "list", + items: { + type: "struct", + fields: [ + { + name: "b", + type: { + type: "struct", + fields: [ + { + name: "d", + type: "string" + } + ], + constraints: [ + closed, + unique + ] + } + } + ], + constraints: [ + closed, + unique + ] + } + } + } + ], + constraints: [ + closed, + unique, + ordered + ] + } + } +} + +case::{ + input: "exclude-14", + catalog: "default", + schema: { + type: "bag", + items: { + type: "struct", + fields: [ + { + name: "a", + type: { + type: "list", + items: { + type: "struct", + fields: [ + { + name: "b", + type: { + type: "struct", + fields: [ + { + name: "c", + type: [ + "int", + "missing" + ] + }, + { + name: "d", + type: "string" + } + ], + constraints: [ + closed, + unique + ] + } + } + ], + constraints: [ + closed, + unique + ] + } + } + } + ], + constraints: [ + closed, + unique, + ordered + ] + } + } +} + +case::{ + input: "exclude-15", + catalog: "default", + schema: { + type: "bag", + items: { + type: "struct", + fields: [ + { + name: "a", + type: { + type: "list", + items: { + type: "struct", + fields: [ + { + name: "b", + type: { + type: "struct", + fields: [], + constraints: [ + closed, + unique + ] + } + } + ], + constraints: [ + closed, + unique + ] + } + } + } + ], + constraints: [ + closed, + unique, + ordered + ] + } + } +} + +case::{ + input: "exclude-16", + catalog: "default", + schema: { + type: "bag", + items: { + type: "struct", + fields: [ + { + name: "a", + type: { + type: "list", + items: { + type: "struct", + fields: [ + { + name: "b", + type: { + type: "struct", + fields: [ + { + name: "c", + type: [ + "int", + "missing" + ] + }, + { + name: "d", + type: [ + "missing", + "string" + ] + } + ], + constraints: [ + closed, + unique + ] + } + } + ], + constraints: [ + closed, + unique + ] + } + } + } + ], + constraints: [ + closed, + unique, + ordered + ] + } + } +} + +case::{ + input: "exclude-17", + catalog: "default", + schema: { + type: "bag", + items: { + type: "struct", + fields: [ + { + name: "a", + type: { + type: "list", + items: { + type: "struct", + fields: [ + { + name: "b", + type: { + type: "struct", + fields: [ + { + name: "c", + type: "int" + }, + { + name: "d", + type: { + type: "list", + items: { + type: "struct", + fields: [ + { + name: "f", + type: "bool" + } + ], + constraints: [ + closed, + unique + ] + } + } + } + ], + constraints: [ + closed, + unique + ] + } + } + ], + constraints: [ + closed, + unique + ] + } + } + } + ], + constraints: [ + closed, + unique, + ordered + ] + } + } +} + +case::{ + input: "exclude-18", + catalog: "default", + schema: { + type: "bag", + items: { + type: "struct", + fields: [ + { + name: "a", + type: { + type: "list", + items: { + type: "struct", + fields: [ + { + name: "b", + type: { + type: "struct", + fields: [ + { + name: "c", + type: "int" + }, + { + name: "d", + type: { + type: "list", + items: { + type: "struct", + fields: [ + { + name: "e", + type: [ + "missing", + "string" + ] + }, + { + name: "f", + type: "bool" + } + ], + constraints: [ + closed, + unique + ] + } + } + } + ], + constraints: [ + closed, + unique + ] + } + } + ], + constraints: [ + closed, + unique + ] + } + } + } + ], + constraints: [ + closed, + unique, + ordered + ] + } + } +} + +case::{ + input: "exclude-19", + catalog: "default", + schema: { + type: "bag", + items: { + type: "struct", + fields: [ + { + name: "a", + type: { + type: "list", + items: { + type: "struct", + fields: [ + { + name: "b", + type: { + type: "struct", + fields: [ + { + name: "c", + type: "int" + }, + { + name: "d", + type: { + type: "list", + items: { + type: "struct", + fields: [ + { + name: "e", + type: [ + "missing", + "string" + ] + }, + { + name: "f", + type: "bool" + } + ], + constraints: [ + closed, + unique + ] + } + } + } + ], + constraints: [ + closed, + unique + ] + } + } + ], + constraints: [ + closed, + unique + ] + } + } + } + ], + constraints: [ + closed, + unique, + ordered + ] + } + } +} + +case::{ + input: "exclude-20", + catalog: "default", + schema: { + type: "bag", + items: { + type: "struct", + fields: [ + { + name: "a", + type: { + type: "struct", + fields: [ + { + name: "B", + type: { + type: "struct", + fields: [ + { + name: "d", + type: "string" + } + ], + constraints: [ + closed, + unique + ] + } + } + ], + constraints: [ + closed, + unique + ] + } + } + ], + constraints: [ + closed, + unique, + ordered + ] + } + } +} + +case::{ + input: "exclude-21", + catalog: "default", + schema: { + type: "bag", + items: { + type: "struct", + fields: [ + { + name: "a", + type: { + type: "struct", + fields: [ + { + name: "B", + type: { + type: "struct", + fields: [ + { + name: "C", + type: "bool" + }, + { + name: "d", + type: "string" + } + ], + constraints: [ + closed, + unique + ] + } + } + ], + constraints: [ + closed, + unique + ] + } + } + ], + constraints: [ + closed, + unique, + ordered + ] + } + } +} + +case::{ + input: "exclude-22", + catalog: "default", + schema: { + type: "bag", + items: { + type: "struct", + fields: [ + { + name: "a", + type: { + type: "struct", + fields: [ + { + name: "B", + type: { + type: "struct", + fields: [ + { + name: "d", + type: "string" + } + ], + constraints: [ + closed, + unique + ] + } + } + ], + constraints: [ + closed, + unique + ] + } + } + ], + constraints: [ + closed, + unique, + ordered + ] + } + } +} + +case::{ + input: "exclude-23", + catalog: "default", + schema: { + type: "bag", + items: { + type: "struct", + fields: [ + { + name: "a", + type: { + type: "struct", + fields: [ + { + name: "B", + type: { + type: "struct", + fields: [ + { + name: "d", + type: "string" + } + ], + constraints: [ + closed, + unique + ] + } + } + ], + constraints: [ + closed, + unique + ] + } + } + ], + constraints: [ + closed, + unique, + ordered + ] + } + } +} + +case::{ + input: "exclude-24", + catalog: "default", + schema: { + type: "bag", + items: { + type: "struct", + fields: [ + { + name: "c", + type: "int" + } + ], + constraints: [ + closed, + unique, + ordered + ] + } + } +} + +case::{ + input: "exclude-25", + catalog: "default", + schema: { + type: "bag", + items: { + type: "struct", + fields: [ + { + name: "a", + type: "int" + } + ], + constraints: [ + closed, + unique, + ordered + ] + } + } +} + +case::{ + input: "exclude-26", + catalog: "default", + schema: { + type: "bag", + items: { + type: "struct", + fields: [ + { + name: "t", + type: [ + { + type: "struct", + fields: [ + { + name: "a", + type: { + type: "struct", + fields: [ + { + name: "c", + type: "string" + } + ], + constraints: [ + closed, + unique + ] + } + } + ], + constraints: [ + closed, + unique + ] + }, + { + type: "struct", + fields: [ + { + name: "a", + type: "null" + } + ], + constraints: [ + closed, + unique + ] + } + ] + } + ], + constraints: [ + closed, + unique, + ordered + ] + } + } +} + +case::{ + input: "exclude-27", + catalog: "default", + schema: { + type: "bag", + items: { + type: "struct", + fields: [ + { + name: "t", + type: [ + { + type: "struct", + fields: [ + { + name: "a", + type: { + type: "struct", + fields: [ + { + name: "c", + type: "string" + } + ], + constraints: [ + closed, + unique + ] + } + } + ], + constraints: [ + closed, + unique + ] + }, + { + type: "struct", + fields: [ + { + name: "a", + type: { + type: "struct", + fields: [ + { + name: "c", + type: "null" + } + ], + constraints: [ + closed, + unique + ] + } + } + ], + constraints: [ + closed, + unique + ] + } + ] + } + ], + constraints: [ + closed, + unique, + ordered + ] + } + } +} + +case::{ + input: "exclude-28", + catalog: "default", + schema: { + type: "bag", + items: { + type: "struct", + fields: [ + { + name: "t", + type: { + type: "struct", + fields: [ + { + name: "a", + type: { + type: "struct", + fields: [ + { + name: "b", + type: "int" + } + ], + constraints: [ + closed, + unique + ] + } + } + ], + constraints: [ + closed, + unique + ] + } + } + ], + constraints: [ + closed, + unique, + ordered + ] + } + } +} + +case::{ + input: "exclude-29", + catalog: "default", + schema: { + type: "bag", + items: { + type: "struct", + fields: [ + { + name: "a", + type: { + type: "struct", + fields: [ + { + name: "b", + type: { + type: "struct", + fields: [ + { + name: "c", + type: "int" + }, + { + name: "d", + type: "string" + } + ], + constraints: [ + closed, + unique + ] + } + } + ], + constraints: [ + closed, + unique + ] + } + } + ], + constraints: [ + closed, + unique, + ordered + ] + } + } +} + +case::{ + input: "exclude-30", + catalog: "default", + schema: { + type: "bag", + items: { + type: "struct", + fields: [ + { + name: "a", + type: { + type: "struct", + fields: [ + { + name: "b", + type: { + type: "struct", + fields: [ + { + name: "c", + type: "int" + }, + { + name: "d", + type: "string" + } + ], + constraints: [ + closed, + unique + ] + } + } + ], + constraints: [ + closed, + unique + ] + } + } + ], + constraints: [ + closed, + unique, + ordered + ] + } + } +} + +case::{ + input: "exclude-31", + catalog: "default", + schema: { + type: "bag", + items: { + type: "struct", + fields: [ + { + name: "a", + type: { + type: "list", + items: { + type: "struct", + fields: [ + { + name: "b", + type: "int" + } + ], + constraints: [ + closed, + unique + ] + } + } + } + ], + constraints: [ + closed, + unique, + ordered + ] + } + } +} + +case::{ + input: "exclude-32", + catalog: "default", + schema: { + type: "bag", + items: { + type: "struct", + fields: [ + { + name: "a", + type: { + type: "list", + items: { + type: "struct", + fields: [ + { + name: "b", + type: "int" + } + ], + constraints: [ + closed, + unique + ] + } + } + } + ], + constraints: [ + closed, + unique, + ordered + ] + } + } +} + +case::{ + input: "exclude-33", + catalog: "default", + schema: { + type: "bag", + items: { + type: "struct", + fields: [ + { + name: "a", + type: { + type: "bag", + items: { + type: "struct", + fields: [ + { + name: "b", + type: "int" + } + ], + constraints: [ + closed, + unique + ] + } + } + } + ], + constraints: [ + closed, + unique, + ordered + ] + } + } +} + +case::{ + input: "exclude-34", + catalog: "default", + schema: { + type: "bag", + items: { + type: "struct", + fields: [ + { + name: "a", + type: { + type: "list", + items: [ + { + type: "struct", + fields: [ + { + name: "b", + type: "int" + }, + { + name: "c", + type: [ + "int", + "missing" + ] + } + ], + constraints: [ + closed, + unique + ] + }, + { + type: "struct", + fields: [ + { + name: "b", + type: "int" + }, + { + name: "c", + type: [ + "missing", + "null" + ] + } + ], + constraints: [ + closed, + unique + ] + }, + { + type: "struct", + fields: [ + { + name: "b", + type: "int" + }, + { + name: "c", + type: [ + "decimal", + "missing" + ] + } + ], + constraints: [ + closed, + unique + ] + } + ] + } + } + ], + constraints: [ + closed, + unique, + ordered + ] + } + } +} + +case::{ + input: "exclude-35", + catalog: "default", + schema: { + type: "bag", + items: { + type: "struct", + fields: [ + { + name: "b", + type: { + type: "struct", + fields: [ + { + name: "b", + type: "int" + } + ], + constraints: [ + closed, + unique, + ordered + ] + } + } + ], + constraints: [ + closed, + unique, + ordered + ] + } + } +} diff --git a/partiql-planner/src/test/resources/cases/schema_inferencer/joins.ion b/partiql-planner/src/test/resources/cases/schema_inferencer/joins.ion new file mode 100644 index 0000000000..8dff4f9e5c --- /dev/null +++ b/partiql-planner/src/test/resources/cases/schema_inferencer/joins.ion @@ -0,0 +1,177 @@ +case::{ + input: "join-01", + catalog: "default", + schema: { + type: "bag", + items: { + type: "struct", + fields: [ + { + name: "a", + type: "int" + }, + { + name: "b", + type: "decimal" + } + ], + constraints: [ + closed, + unique, + ordered + ] + } + } +} + +case::{ + input: "join-02", + catalog: "default", + schema: { + type: "bag", + items: { + type: "struct", + fields: [ + { + name: "a", + type: "int" + }, + { + name: "b", + type: [ + "decimal", + "null" + ] + } + ], + constraints: [ + closed, + unique, + ordered + ] + } + } +} + +case::{ + input: "join-03", + catalog: "default", + schema: { + type: "bag", + items: { + type: "struct", + fields: [ + { + name: "b", + type: [ + "decimal", + "null" + ] + }, + { + name: "a", + type: "int" + } + ], + constraints: [ + closed, + unique, + ordered + ] + } + } +} + +case::{ + input: "join-04", + catalog: "default", + schema: { + type: "bag", + items: { + type: "struct", + fields: [ + { + name: "a", + type: "int" + }, + { + name: "a", + type: [ + "decimal", + "null" + ] + } + ], + constraints: [ + closed, + unique, + ordered + ] + } + } +} + +case::{ + input: "join-05", + catalog: "default", + schema: { + type: "bag", + items: { + type: "struct", + fields: [ + { + name: "a", + type: "int" + }, + { + name: "a", + type: [ + "decimal", + "null" + ] + } + ], + constraints: [ + closed, + unique, + ordered + ] + } + } +} + +case::{ + input: "join-06", + catalog: "default", + schema: { + type: "bag", + items: { + type: "struct", + fields: [ + { + name: "a", + type: "int" + }, + { + name: "a", + type: [ + "decimal", + "null" + ] + }, + { + name: "a", + type: [ + "null", + "string" + ] + } + ], + constraints: [ + closed, + unique, + ordered + ] + } + } +} diff --git a/partiql-planner/src/test/resources/cases/schema_inferencer/order_by.ion b/partiql-planner/src/test/resources/cases/schema_inferencer/order_by.ion new file mode 100644 index 0000000000..341d5b82ab --- /dev/null +++ b/partiql-planner/src/test/resources/cases/schema_inferencer/order_by.ion @@ -0,0 +1,77 @@ +case::{ + input: "order_by-01", + catalog: "default", + schema: { + type: "list", + items: { + type: "struct", + fields: [ + { + name: "id", + type: "int" + }, + { + name: "breed", + type: "string" + } + ], + constraints: [ + closed, + unique, + ordered + ] + } + } +} + +case::{ + input: "order_by-02", + catalog: "default", + schema: { + type: "list", + items: { + type: "struct", + fields: [ + { + name: "id", + type: "int" + }, + { + name: "breed", + type: "string" + } + ], + constraints: [ + closed, + unique, + ordered + ] + } + } +} + +case::{ + input: "order_by-03", + catalog: "default", + schema: { + type: "list", + items: { + type: "struct", + fields: [ + { + name: "id", + type: "int" + }, + { + name: "breed", + type: "string" + } + ], + constraints: [ + closed, + unique, + ordered + ] + } + } +} diff --git a/partiql-planner/src/test/resources/cases/schema_inferrencer/sanity.ion b/partiql-planner/src/test/resources/cases/schema_inferencer/sanity.ion similarity index 100% rename from partiql-planner/src/test/resources/cases/schema_inferrencer/sanity.ion rename to partiql-planner/src/test/resources/cases/schema_inferencer/sanity.ion diff --git a/partiql-planner/src/testFixtures/resources/inputs/schema_inferencer/collections.sql b/partiql-planner/src/testFixtures/resources/inputs/schema_inferencer/collections.sql new file mode 100644 index 0000000000..d06e6be9d2 --- /dev/null +++ b/partiql-planner/src/testFixtures/resources/inputs/schema_inferencer/collections.sql @@ -0,0 +1,23 @@ +--#[collections-01] +-- Collection BAG +<< 1, 2, 3 >>; + +--#[collections-02] +-- Collection LIST +[ 1, 2, 3 ]; + +--#[collections-03] +-- Collection LIST +( 1, 2, 3 ); + +--#[collections-04] +-- Collection SEXP +SEXP ( 1, 2, 3 ); + +--#[collections-05] +--SELECT VALUE from array +SELECT VALUE x FROM [ 1, 2, 3 ] as x; + +--#[collections-06] +--SELECT from array +SELECT x FROM [ 1, 2, 3 ] as x; diff --git a/partiql-planner/src/testFixtures/resources/inputs/schema_inferencer/exclude.sql b/partiql-planner/src/testFixtures/resources/inputs/schema_inferencer/exclude.sql new file mode 100644 index 0000000000..5d44ff83f0 --- /dev/null +++ b/partiql-planner/src/testFixtures/resources/inputs/schema_inferencer/exclude.sql @@ -0,0 +1,461 @@ +--#[exclude-01] +SELECT * EXCLUDE c.ssn FROM [ + { + 'name': 'Alan', + 'custId': 1, + 'address': { + 'city': 'Seattle', + 'zipcode': 98109, + 'street': '123 Seaplane Dr.' + }, + 'ssn': 123456789 + }] AS c; + +--#[exclude-02] +SELECT * EXCLUDE c.ssn, c.address.street FROM [ + { + 'name': 'Alan', + 'custId': 1, + 'address': { + 'city': 'Seattle', + 'zipcode': 98109, + 'street': '123 Seaplane Dr.' + }, + 'ssn': 123456789 + }] AS c; + +--#[exclude-03] +SELECT * EXCLUDE t.a.b.c[0], t.a.b.c[1].field +FROM [{ + 'a': { + 'b': { + 'c': [ + { + 'field': 0 -- c[0] + }, + { + 'field': 1 -- c[1] + }, + { + 'field': 2 -- c[2] + } + ] + } + }, + 'foo': 'bar' + }] AS t; + +--#[exclude-04] +SELECT * + EXCLUDE + t.a.b.c[0] +FROM [{ + 'a': { + 'b': { + 'c': [0, 1, 2] + } + }, + 'foo': 'bar' + }] AS t; + +--#[exclude-05] +SELECT * + EXCLUDE + t.a[*] +FROM [{ + 'a': [0, 1, 2] + }] AS t; + +--#[exclude-06] +SELECT * + EXCLUDE + t.a.b.c[*].field_x +FROM [{ + 'a': { + 'b': { + 'c': [ + { -- c[0] + 'field_x': 0, + 'field_y': 0 + }, + { -- c[1] + 'field_x': 1, + 'field_y': 1 + }, + { -- c[2] + 'field_x': 2, + 'field_y': 2 + } + ] + } + }, + 'foo': 'bar' + }] AS t; + +--#[exclude-07] +SELECT * + EXCLUDE + t.a.b.c[*].* +FROM [{ + 'a': { + 'b': { + 'c': [ + { -- c[0] + 'field_x': 0, + 'field_y': 0 + }, + { -- c[1] + 'field_x': 1, + 'field_y': 1 + }, + { -- c[2] + 'field_x': 2, + 'field_y': 2 + } + ] + } + }, + 'foo': 'bar' + }] AS t; + +--#[exclude-08] +SELECT * + EXCLUDE + t.a +FROM [ + { + 'a': 2, + 'foo': 'bar2' + }, + { + 'a': 1, + 'foo': 'bar1' + }, + { + 'a': 3, + 'foo': 'bar3' + } + ] AS t +ORDER BY t.a; + +--#[exclude-09] +SELECT * + EXCLUDE bar.d +FROM + << + {'a': 1, 'b': 11}, + {'a': 2, 'b': 22} + >> AS foo, + << + {'c': 3, 'd': 33}, + {'c': 4, 'd': 44} + >> AS bar; + +--#[exclude-10] +SELECT t.b EXCLUDE t.b[*].b_1 +FROM << + { + 'a': {'a_1':1,'a_2':2}, + 'b': [ {'b_1':3,'b_2':4}, {'b_1':5,'b_2':6} ], + 'c': 7, + 'd': 8 + } >> AS t; + +--#[exclude-11] +SELECT * EXCLUDE t.b[*].b_1 +FROM << + { + 'a': {'a_1':1,'a_2':2}, + 'b': [ {'b_1':3,'b_2':4}, {'b_1':5,'b_2':6} ], + 'c': 7, + 'd': 8 + } >> AS t; + +--#[exclude-12] +SELECT VALUE t.b EXCLUDE t.b[*].b_1 +FROM << + { + 'a': {'a_1':1,'a_2':2}, + 'b': [ {'b_1':3,'b_2':4}, {'b_1':5,'b_2':6} ], + 'c': 7, + 'd': 8 + } >> AS t; + +--#[exclude-13] +SELECT * EXCLUDE t.a[*].b.c +FROM << + { + 'a': [ + { 'b': { 'c': 0, 'd': 'zero' } }, + { 'b': { 'c': 1, 'd': 'one' } }, + { 'b': { 'c': 2, 'd': 'two' } } + ] + } + >> AS t; + +--#[exclude-14] +SELECT * EXCLUDE t.a[1].b.c +FROM << + { + 'a': [ + { 'b': { 'c': 0, 'd': 'zero' } }, + { 'b': { 'c': 1, 'd': 'one' } }, + { 'b': { 'c': 2, 'd': 'two' } } + ] + } + >> AS t; + +--#[exclude-15] +SELECT * EXCLUDE t.a[*].b.* +FROM << + { + 'a': [ + { 'b': { 'c': 0, 'd': 'zero' } }, + { 'b': { 'c': 1, 'd': 'one' } }, + { 'b': { 'c': 2, 'd': 'two' } } + ] + } + >> AS t; + +--#[exclude-16] +SELECT * EXCLUDE t.a[1].b.* +FROM << + { + 'a': [ + { 'b': { 'c': 0, 'd': 'zero' } }, + { 'b': { 'c': 1, 'd': 'one' } }, + { 'b': { 'c': 2, 'd': 'two' } } + ] + } + >> AS t; + +--#[exclude-17] +SELECT * EXCLUDE t.a[*].b.d[*].e +FROM << + { + 'a': [ + { 'b': { 'c': 0, 'd': [{'e': 'zero', 'f': true}] } }, + { 'b': { 'c': 1, 'd': [{'e': 'one', 'f': true}] } }, + { 'b': { 'c': 2, 'd': [{'e': 'two', 'f': true}] } } + ] + } + >> AS t; + +--#[exclude-18] +SELECT * EXCLUDE t.a[1].b.d[*].e +FROM << + { + 'a': [ + { 'b': { 'c': 0, 'd': [{'e': 'zero', 'f': true}] } }, + { 'b': { 'c': 1, 'd': [{'e': 'one', 'f': true}] } }, + { 'b': { 'c': 2, 'd': [{'e': 'two', 'f': true}] } } + ] + } + >> AS t; + +--#[exclude-19] +SELECT * EXCLUDE t.a[1].b.d[0].e +FROM << + { + 'a': [ + { 'b': { 'c': 0, 'd': [{'e': 'zero', 'f': true}] } }, + { 'b': { 'c': 1, 'd': [{'e': 'one', 'f': true}] } }, + { 'b': { 'c': 2, 'd': [{'e': 'two', 'f': true}] } } + ] + } + >> AS t; + +--#[exclude-20] +SELECT * EXCLUDE t."a".b['c'] +FROM << + { + 'a': { + 'B': { + 'c': 0, + 'd': 'foo' + } + } + } + >> AS t; + +--#[exclude-21] +SELECT * EXCLUDE t."a".b['c'] +FROM << + { + 'a': { + 'B': { + 'c': 0, + 'C': true, + 'd': 'foo' + } + } + } + >> AS t; + +--#[exclude-22] +SELECT * EXCLUDE t."a".b.c +FROM << + { + 'a': { + 'B': { -- both 'c' and 'C' to be removed + 'c': 0, + 'C': true, + 'd': 'foo' + } + } + } + >> AS t; + +--#[exclude-23] +SELECT * EXCLUDE t."a".b.c +FROM << + { + 'a': { + 'B': { + 'c': 0, + 'c': true, + 'd': 'foo' + } + } + } + >> AS t; + +--#[exclude-24] +SELECT * EXCLUDE t.a, t.a.b FROM << { 'a': { 'b': 1 }, 'c': 2 } >> AS t; + +--#[exclude-25] +SELECT * EXCLUDE t.attr_does_not_exist FROM << { 'a': 1 } >> AS t; + +--#[exclude-26] +SELECT t EXCLUDE t.a.b +FROM << + { + 'a': { + 'b': 1, -- `b` to be excluded + 'c': 'foo' + } + }, + { + 'a': NULL + } + >> AS t; + +--#[exclude-27] +SELECT t EXCLUDE t.a.b +FROM << + { + 'a': { + 'b': 1, -- `b` to be excluded + 'c': 'foo' + } + }, + { + 'a': { + 'b': 1, -- `b` to be excluded + 'c': NULL + } + } + >> AS t; + +--#[exclude-28] +SELECT t EXCLUDE t.a.c +FROM << + { + 'a': { + 'b': 1, + 'c': 'foo' -- `c` to be excluded + } + }, + { + 'a': { + 'b': 1, + 'c': NULL -- `c` to be excluded + } + } + >> AS t; + +--#[exclude-29] +SELECT * EXCLUDE t.a[*] +FROM << + { + 'a': { + 'b': { + 'c': 0, + 'd': 'foo' + } + } + } + >> AS t; + +--#[exclude-30] +SELECT * EXCLUDE t.a[1] +FROM << + { + 'a': { + 'b': { + 'c': 0, + 'd': 'foo' + } + } + } + >> AS t; + +--#[exclude-31] +SELECT * EXCLUDE t.a.b +FROM << + { + 'a': [ + { 'b': 0 }, + { 'b': 1 }, + { 'b': 2 } + ] + } + >> AS t; + +--#[exclude-32] +SELECT * EXCLUDE t.a.* +FROM << + { + 'a': [ + { 'b': 0 }, + { 'b': 1 }, + { 'b': 2 } + ] + } + >> AS t; + +--#[exclude-33] +SELECT * EXCLUDE t.b -- `t.b` does not exist +FROM << + { + 'a': << + { 'b': 0 }, + { 'b': 1 }, + { 'b': 2 } + >> + } + >> AS t; + +--#[exclude-34] +SELECT * EXCLUDE t.a[0].c -- `c`'s type to be unioned with `MISSING` +FROM << + { + 'a': [ + { + 'b': 0, + 'c': 0 + }, + { + 'b': 1, + 'c': NULL + }, + { + 'b': 2, + 'c': 0.1 + } + ] + } + >> AS t; + +--#[exclude-35] +SELECT * EXCLUDE t.c FROM b.b.b AS t; \ No newline at end of file diff --git a/partiql-planner/src/testFixtures/resources/inputs/schema_inferencer/joins.sql b/partiql-planner/src/testFixtures/resources/inputs/schema_inferencer/joins.sql new file mode 100644 index 0000000000..5f8c8b4eca --- /dev/null +++ b/partiql-planner/src/testFixtures/resources/inputs/schema_inferencer/joins.sql @@ -0,0 +1,24 @@ +--#[join-01] +SELECT * FROM <<{ 'a': 1 }>> AS t1, <<{ 'b': 2.0 }>> AS t2; + +--#[join-02] +SELECT * FROM <<{ 'a': 1 }>> AS t1 LEFT JOIN <<{ 'b': 2.0 }>> AS t2 ON TRUE; + +--#[join-03] +SELECT b, a FROM <<{ 'a': 1 }>> AS t1 LEFT JOIN <<{ 'b': 2.0 }>> AS t2 ON TRUE; + +--#[join-04] +SELECT t1.a, t2.a FROM <<{ 'a': 1 }>> AS t1 LEFT JOIN <<{ 'a': 2.0 }>> AS t2 ON t1.a = t2.a; + +--#[join-05] +SELECT * FROM <<{ 'a': 1 }>> AS t1 LEFT JOIN <<{ 'a': 2.0 }>> AS t2 ON t1.a = t2.a; + +--#[join-06] +SELECT * FROM + <<{ 'a': 1 }>> AS t1 + LEFT JOIN + <<{ 'a': 2.0 }>> AS t2 + ON t1.a = t2.a + LEFT JOIN + <<{ 'a': 'hello, world' }>> AS t3 + ON t3.a = 'hello'; diff --git a/partiql-planner/src/testFixtures/resources/inputs/schema_inferencer/order_by.sql b/partiql-planner/src/testFixtures/resources/inputs/schema_inferencer/order_by.sql new file mode 100644 index 0000000000..1fa842ed18 --- /dev/null +++ b/partiql-planner/src/testFixtures/resources/inputs/schema_inferencer/order_by.sql @@ -0,0 +1,8 @@ +--#[order_by-01] +SELECT * FROM pets ORDER BY id; + +--#[order_by-02] +SELECT * FROM pets ORDER BY breed; + +--#[order_by-03] +SELECT * FROM pets ORDER BY unknown_col; diff --git a/partiql-planner/src/testFixtures/resources/inputs/schema_inferrencer/sanity.sql b/partiql-planner/src/testFixtures/resources/inputs/schema_inferencer/sanity.sql similarity index 100% rename from partiql-planner/src/testFixtures/resources/inputs/schema_inferrencer/sanity.sql rename to partiql-planner/src/testFixtures/resources/inputs/schema_inferencer/sanity.sql From f12f1da42afdea4887357f35701bd639e1d4601c Mon Sep 17 00:00:00 2001 From: "R. C. Howell" Date: Tue, 17 Oct 2023 14:31:49 -0700 Subject: [PATCH 3/3] Extract PartiQLSchemaInferencerTest inputs; onboard some tests --- partiql-lang/build.gradle.kts | 5 + .../PartiQLSchemaInferencerTests.kt | 576 +----- .../catalogs/db/markets/order_info.ion | 19 - .../resources/catalogs/db/markets/orders.ion | 21 - .../org/partiql/planner/PlannerTestCase.kt | 39 - .../org/partiql/planner/PlannerTestGroup.kt | 25 - .../org/partiql/planner/PlannerTestJunit.kt | 4 +- .../partiql/planner/PlannerTestProvider.kt | 25 - .../cases/schema_inferencer/collections.ion | 66 - .../cases/schema_inferencer/exclude.ion | 1714 ----------------- .../cases/schema_inferencer/joins.ion | 177 -- .../cases/schema_inferencer/order_by.ion | 77 - .../cases/schema_inferencer/sanity.ion | 160 -- .../src/test/resources/cases/tpc_ds/.gitkeep | 0 .../src/test/resources/cases/tpc_h/.gitkeep | 0 .../org/partiql/planner/test/PartiQLTest.kt | 38 + .../partiql/planner/test/PartiQLTestCase.kt | 17 - .../partiql/planner/test/PartiQLTestGroup.kt | 47 - .../planner/test/PartiQLTestProvider.kt | 100 +- .../resources/catalogs/default}/aws/b/b.ion | 0 .../resources/catalogs/default}/aws/ddb/b.ion | 0 .../catalogs/default}/aws/ddb/pets.ion | 0 .../resources/catalogs/default}/b/b/b.ion | 0 .../resources/catalogs/default}/b/b/c.ion | 0 .../resources/catalogs/default}/b/b/d.ion | 0 .../resources/catalogs/default}/b/c/c.ion | 0 .../resources/catalogs/default/db/aws/b/b.ion | 13 - .../catalogs/default/db/aws/ddb/b.ion | 13 - .../catalogs/default/db/aws/ddb/pets.ion | 17 - .../resources/catalogs/default/db/b/b/b.ion | 23 - .../resources/catalogs/default/db/b/b/c.ion | 1 - .../resources/catalogs/default/db/b/b/d.ion | 22 - .../resources/catalogs/default/db/b/c/c.ion | 1 - .../inputs/schema_inferencer/exclude.sql | 14 +- 34 files changed, 245 insertions(+), 2969 deletions(-) delete mode 100644 partiql-lang/src/test/resources/catalogs/db/markets/order_info.ion delete mode 100644 partiql-lang/src/test/resources/catalogs/db/markets/orders.ion delete mode 100644 partiql-planner/src/test/kotlin/org/partiql/planner/PlannerTestCase.kt delete mode 100644 partiql-planner/src/test/kotlin/org/partiql/planner/PlannerTestGroup.kt delete mode 100644 partiql-planner/src/test/kotlin/org/partiql/planner/PlannerTestProvider.kt delete mode 100644 partiql-planner/src/test/resources/cases/schema_inferencer/collections.ion delete mode 100644 partiql-planner/src/test/resources/cases/schema_inferencer/exclude.ion delete mode 100644 partiql-planner/src/test/resources/cases/schema_inferencer/joins.ion delete mode 100644 partiql-planner/src/test/resources/cases/schema_inferencer/order_by.ion delete mode 100644 partiql-planner/src/test/resources/cases/schema_inferencer/sanity.ion delete mode 100644 partiql-planner/src/test/resources/cases/tpc_ds/.gitkeep delete mode 100644 partiql-planner/src/test/resources/cases/tpc_h/.gitkeep create mode 100644 partiql-planner/src/testFixtures/kotlin/org/partiql/planner/test/PartiQLTest.kt delete mode 100644 partiql-planner/src/testFixtures/kotlin/org/partiql/planner/test/PartiQLTestCase.kt delete mode 100644 partiql-planner/src/testFixtures/kotlin/org/partiql/planner/test/PartiQLTestGroup.kt rename {partiql-lang/src/test/resources/catalogs/db => partiql-planner/src/testFixtures/resources/catalogs/default}/aws/b/b.ion (100%) rename {partiql-lang/src/test/resources/catalogs/db => partiql-planner/src/testFixtures/resources/catalogs/default}/aws/ddb/b.ion (100%) rename {partiql-lang/src/test/resources/catalogs/db => partiql-planner/src/testFixtures/resources/catalogs/default}/aws/ddb/pets.ion (100%) rename {partiql-lang/src/test/resources/catalogs/db => partiql-planner/src/testFixtures/resources/catalogs/default}/b/b/b.ion (100%) rename {partiql-lang/src/test/resources/catalogs/db => partiql-planner/src/testFixtures/resources/catalogs/default}/b/b/c.ion (100%) rename {partiql-lang/src/test/resources/catalogs/db => partiql-planner/src/testFixtures/resources/catalogs/default}/b/b/d.ion (100%) rename {partiql-lang/src/test/resources/catalogs/db => partiql-planner/src/testFixtures/resources/catalogs/default}/b/c/c.ion (100%) delete mode 100644 partiql-planner/src/testFixtures/resources/catalogs/default/db/aws/b/b.ion delete mode 100644 partiql-planner/src/testFixtures/resources/catalogs/default/db/aws/ddb/b.ion delete mode 100644 partiql-planner/src/testFixtures/resources/catalogs/default/db/aws/ddb/pets.ion delete mode 100644 partiql-planner/src/testFixtures/resources/catalogs/default/db/b/b/b.ion delete mode 100644 partiql-planner/src/testFixtures/resources/catalogs/default/db/b/b/c.ion delete mode 100644 partiql-planner/src/testFixtures/resources/catalogs/default/db/b/b/d.ion delete mode 100644 partiql-planner/src/testFixtures/resources/catalogs/default/db/b/c/c.ion diff --git a/partiql-lang/build.gradle.kts b/partiql-lang/build.gradle.kts index cdd480271f..37172a1a12 100644 --- a/partiql-lang/build.gradle.kts +++ b/partiql-lang/build.gradle.kts @@ -39,6 +39,7 @@ dependencies { implementation(Deps.csv) implementation(Deps.kotlinReflect) + testImplementation(testFixtures(project(":partiql-planner"))) testImplementation(project(":plugins:partiql-local")) testImplementation(project(":lib:isl")) testImplementation(Deps.assertj) @@ -73,3 +74,7 @@ tasks.processResources { include("partiql.ion") } } + +tasks.processTestResources { + from("${project(":partiql-planner").buildDir}/resources/testFixtures") +} diff --git a/partiql-lang/src/test/kotlin/org/partiql/lang/planner/transforms/PartiQLSchemaInferencerTests.kt b/partiql-lang/src/test/kotlin/org/partiql/lang/planner/transforms/PartiQLSchemaInferencerTests.kt index 459f6dd661..ca45507490 100644 --- a/partiql-lang/src/test/kotlin/org/partiql/lang/planner/transforms/PartiQLSchemaInferencerTests.kt +++ b/partiql-lang/src/test/kotlin/org/partiql/lang/planner/transforms/PartiQLSchemaInferencerTests.kt @@ -23,6 +23,8 @@ import org.partiql.lang.planner.transforms.PartiQLSchemaInferencerTests.TestCase import org.partiql.plan.debug.PlanPrinter import org.partiql.planner.PartiQLPlanner import org.partiql.planner.PlanningProblemDetails +import org.partiql.planner.test.PartiQLTest +import org.partiql.planner.test.PartiQLTestProvider import org.partiql.plugins.local.LocalPlugin import org.partiql.types.AnyOfType import org.partiql.types.AnyType @@ -49,6 +51,13 @@ import kotlin.test.assertTrue class PartiQLSchemaInferencerTests { + private val provider = PartiQLTestProvider() + + init { + // load test inputs + provider.load() + } + @ParameterizedTest @ArgumentsSource(TestProvider::class) fun test(tc: TestCase) = runTest(tc) @@ -93,31 +102,9 @@ class PartiQLSchemaInferencerTests { @Execution(ExecutionMode.CONCURRENT) fun testOrderBy(tc: TestCase) = runTest(tc) - // @Test - // @Disabled - // fun testPrint() { - // val cases = orderByCases() - // val prefix = "orderByCases" - // cases.forEachIndexed { i, t -> - // val name = "$prefix-${"%02d".format(i + 1)}" - // println("--#[$name]") - // println(t.query + ";") - // println() - // } - // cases.forEachIndexed { i, t -> - // val name = "$prefix-${"%02d".format(i + 1)}" - // println("case::{") - // println(" input: \"$name\",") - // println(" catalog: \"default\",") - // println(" schema: ${t.expected.toIon()}") - // println("}") - // println() - // } - // } - companion object { - private val root = this::class.java.getResource("/catalogs")!!.toURI().toPath().pathString + private val root = this::class.java.getResource("/catalogs/default")!!.toURI().toPath().pathString private val PLUGINS = listOf(LocalPlugin()) @@ -227,36 +214,38 @@ class PartiQLSchemaInferencerTests { // Tests + private fun key(name: String) = PartiQLTest.Key("schema_inferencer", name) + @JvmStatic fun collections() = listOf( SuccessTestCase( name = "Collection BAG", - query = "<< 1, 2, 3 >>", + key = key("collections-01"), expected = BagType(INT), ), SuccessTestCase( name = "Collection LIST", - query = "[ 1, 2, 3 ]", + key = key("collections-02"), expected = ListType(INT), ), SuccessTestCase( name = "Collection LIST", - query = "( 1, 2, 3 )", + key = key("collections-03"), expected = ListType(INT), ), SuccessTestCase( name = "Collection SEXP", - query = "SEXP ( 1, 2, 3 )", + key = key("collections-04"), expected = SexpType(INT), ), SuccessTestCase( name = "SELECT from array", - query = "SELECT VALUE x FROM [ 1, 2, 3 ] as x", + key = key("collections-05"), expected = BagType(INT), ), SuccessTestCase( name = "SELECT from array", - query = "SELECT x FROM [ 1, 2, 3 ] as x", + key = key("collections-06"), expected = BagType( StructType( fields = listOf(StructType.Field("x", INT)), @@ -572,18 +561,7 @@ class PartiQLSchemaInferencerTests { fun excludeCases() = listOf( SuccessTestCase( name = "EXCLUDE SELECT star", - query = """SELECT * EXCLUDE c.ssn FROM [ - { - 'name': 'Alan', - 'custId': 1, - 'address': { - 'city': 'Seattle', - 'zipcode': 98109, - 'street': '123 Seaplane Dr.' - }, - 'ssn': 123456789 - } - ] AS c""", + key = key("exclude-01"), expected = BagType( StructType( fields = mapOf( @@ -610,18 +588,7 @@ class PartiQLSchemaInferencerTests { ), SuccessTestCase( name = "EXCLUDE SELECT star multiple paths", - query = """SELECT * EXCLUDE c.ssn, c.address.street FROM [ - { - 'name': 'Alan', - 'custId': 1, - 'address': { - 'city': 'Seattle', - 'zipcode': 98109, - 'street': '123 Seaplane Dr.' - }, - 'ssn': 123456789 - } - ] AS c""", + key = key("exclude-02"), expected = BagType( StructType( fields = mapOf( @@ -647,28 +614,7 @@ class PartiQLSchemaInferencerTests { ), SuccessTestCase( name = "EXCLUDE SELECT star list index and list index field", - query = """SELECT * - EXCLUDE - t.a.b.c[0], - t.a.b.c[1].field - FROM [{ - 'a': { - 'b': { - 'c': [ - { - 'field': 0 -- c[0] - }, - { - 'field': 1 -- c[1] - }, - { - 'field': 2 -- c[2] - } - ] - } - }, - 'foo': 'bar' - }] AS t""", + key = key("exclude-03"), expected = BagType( StructType( fields = mapOf( @@ -717,17 +663,7 @@ class PartiQLSchemaInferencerTests { ), SuccessTestCase( name = "EXCLUDE SELECT star collection index as last step", - query = """SELECT * - EXCLUDE - t.a.b.c[0] - FROM [{ - 'a': { - 'b': { - 'c': [0, 1, 2] - } - }, - 'foo': 'bar' - }] AS t""", + key = key("exclude-04"), expected = BagType( StructType( fields = mapOf( @@ -763,12 +699,7 @@ class PartiQLSchemaInferencerTests { // EXCLUDE regression test (behavior subject to change pending RFC) SuccessTestCase( name = "EXCLUDE SELECT star collection wildcard as last step", - query = """SELECT * - EXCLUDE - t.a[*] - FROM [{ - 'a': [0, 1, 2] - }] AS t""", + key = key("exclude-05"), expected = BagType( StructType( fields = mapOf( @@ -787,30 +718,7 @@ class PartiQLSchemaInferencerTests { ), SuccessTestCase( name = "EXCLUDE SELECT star list wildcard", - query = """SELECT * - EXCLUDE - t.a.b.c[*].field_x - FROM [{ - 'a': { - 'b': { - 'c': [ - { -- c[0] - 'field_x': 0, - 'field_y': 0 - }, - { -- c[1] - 'field_x': 1, - 'field_y': 1 - }, - { -- c[2] - 'field_x': 2, - 'field_y': 2 - } - ] - } - }, - 'foo': 'bar' - }] AS t""", + key = key("exclude-06"), expected = BagType( StructType( fields = mapOf( @@ -854,30 +762,7 @@ class PartiQLSchemaInferencerTests { ), SuccessTestCase( name = "EXCLUDE SELECT star list tuple wildcard", - query = """SELECT * - EXCLUDE - t.a.b.c[*].* - FROM [{ - 'a': { - 'b': { - 'c': [ - { -- c[0] - 'field_x': 0, - 'field_y': 0 - }, - { -- c[1] - 'field_x': 1, - 'field_y': 1 - }, - { -- c[2] - 'field_x': 2, - 'field_y': 2 - } - ] - } - }, - 'foo': 'bar' - }] AS t""", + key = key("exclude-07"), expected = BagType( StructType( fields = mapOf( @@ -921,24 +806,7 @@ class PartiQLSchemaInferencerTests { ), SuccessTestCase( name = "EXCLUDE SELECT star order by", - query = """SELECT * - EXCLUDE - t.a - FROM [ - { - 'a': 2, - 'foo': 'bar2' - }, - { - 'a': 1, - 'foo': 'bar1' - }, - { - 'a': 3, - 'foo': 'bar3' - } - ] AS t - ORDER BY t.a""", + key = key("exclude-08"), expected = ListType( StructType( fields = mapOf( @@ -955,17 +823,7 @@ class PartiQLSchemaInferencerTests { ), SuccessTestCase( name = "EXCLUDE SELECT star with JOINs", - query = """SELECT * - EXCLUDE bar.d - FROM - << - {'a': 1, 'b': 11}, - {'a': 2, 'b': 22} - >> AS foo, - << - {'c': 3, 'd': 33}, - {'c': 4, 'd': 44} - >> AS bar""", + key = key("exclude-09"), expected = BagType( StructType( fields = mapOf( @@ -984,14 +842,7 @@ class PartiQLSchemaInferencerTests { ), SuccessTestCase( name = "SELECT t.b EXCLUDE ex 1", - query = """SELECT t.b EXCLUDE t.b[*].b_1 - FROM << - { - 'a': {'a_1':1,'a_2':2}, - 'b': [ {'b_1':3,'b_2':4}, {'b_1':5,'b_2':6} ], - 'c': 7, - 'd': 8 - } >> AS t""", + key = key("exclude-10"), expected = BagType( StructType( fields = mapOf( @@ -1016,14 +867,7 @@ class PartiQLSchemaInferencerTests { ), SuccessTestCase( name = "SELECT * EXCLUDE ex 2", - query = """SELECT * EXCLUDE t.b[*].b_1 - FROM << - { - 'a': {'a_1':1,'a_2':2}, - 'b': [ {'b_1':3,'b_2':4}, {'b_1':5,'b_2':6} ], - 'c': 7, - 'd': 8 - } >> AS t""", + key = key("exclude-11"), expected = BagType( StructType( fields = mapOf( @@ -1058,14 +902,7 @@ class PartiQLSchemaInferencerTests { ), SuccessTestCase( name = "SELECT VALUE t.b EXCLUDE", - query = """SELECT VALUE t.b EXCLUDE t.b[*].b_1 - FROM << - { - 'a': {'a_1':1,'a_2':2}, - 'b': [ {'b_1':3,'b_2':4}, {'b_1':5,'b_2':6} ], - 'c': 7, - 'd': 8 - } >> AS t""", + key = key("exclude-12"), expected = BagType( ListType( elementType = StructType( @@ -1080,16 +917,7 @@ class PartiQLSchemaInferencerTests { ), SuccessTestCase( name = "SELECT * EXCLUDE collection wildcard and nested tuple attr", - query = """SELECT * EXCLUDE t.a[*].b.c - FROM << - { - 'a': [ - { 'b': { 'c': 0, 'd': 'zero' } }, - { 'b': { 'c': 1, 'd': 'one' } }, - { 'b': { 'c': 2, 'd': 'two' } } - ] - } - >> AS t""", + key = key("exclude-13"), expected = BagType( StructType( fields = mapOf( @@ -1123,16 +951,7 @@ class PartiQLSchemaInferencerTests { ), SuccessTestCase( name = "SELECT * EXCLUDE collection index and nested tuple attr", - query = """SELECT * EXCLUDE t.a[1].b.c - FROM << - { - 'a': [ - { 'b': { 'c': 0, 'd': 'zero' } }, - { 'b': { 'c': 1, 'd': 'one' } }, - { 'b': { 'c': 2, 'd': 'two' } } - ] - } - >> AS t""", + key = key("exclude-14"), expected = BagType( StructType( fields = mapOf( @@ -1167,16 +986,7 @@ class PartiQLSchemaInferencerTests { ), SuccessTestCase( name = "SELECT * EXCLUDE collection wildcard and nested tuple wildcard", - query = """SELECT * EXCLUDE t.a[*].b.* - FROM << - { - 'a': [ - { 'b': { 'c': 0, 'd': 'zero' } }, - { 'b': { 'c': 1, 'd': 'one' } }, - { 'b': { 'c': 2, 'd': 'two' } } - ] - } - >> AS t""", + key = key("exclude-15"), expected = BagType( StructType( fields = mapOf( @@ -1208,16 +1018,7 @@ class PartiQLSchemaInferencerTests { ), SuccessTestCase( name = "SELECT * EXCLUDE collection index and nested tuple wildcard", - query = """SELECT * EXCLUDE t.a[1].b.* - FROM << - { - 'a': [ - { 'b': { 'c': 0, 'd': 'zero' } }, - { 'b': { 'c': 1, 'd': 'one' } }, - { 'b': { 'c': 2, 'd': 'two' } } - ] - } - >> AS t""", + key = key("exclude-16"), expected = BagType( StructType( fields = mapOf( @@ -1252,16 +1053,7 @@ class PartiQLSchemaInferencerTests { ), SuccessTestCase( name = "SELECT * EXCLUDE collection wildcard and nested collection wildcard", - query = """SELECT * EXCLUDE t.a[*].b.d[*].e - FROM << - { - 'a': [ - { 'b': { 'c': 0, 'd': [{'e': 'zero', 'f': true}] } }, - { 'b': { 'c': 1, 'd': [{'e': 'one', 'f': true}] } }, - { 'b': { 'c': 2, 'd': [{'e': 'two', 'f': true}] } } - ] - } - >> AS t""", + key = key("exclude-17"), expected = BagType( StructType( fields = mapOf( @@ -1307,16 +1099,7 @@ class PartiQLSchemaInferencerTests { ), SuccessTestCase( name = "SELECT * EXCLUDE collection index and nested collection wildcard", - query = """SELECT * EXCLUDE t.a[1].b.d[*].e - FROM << - { - 'a': [ - { 'b': { 'c': 0, 'd': [{'e': 'zero', 'f': true}] } }, - { 'b': { 'c': 1, 'd': [{'e': 'one', 'f': true}] } }, - { 'b': { 'c': 2, 'd': [{'e': 'two', 'f': true}] } } - ] - } - >> AS t""", + key = key("exclude-18"), expected = BagType( StructType( fields = mapOf( @@ -1363,16 +1146,7 @@ class PartiQLSchemaInferencerTests { ), SuccessTestCase( name = "SELECT * EXCLUDE collection index and nested collection index", - query = """SELECT * EXCLUDE t.a[1].b.d[0].e - FROM << - { - 'a': [ - { 'b': { 'c': 0, 'd': [{'e': 'zero', 'f': true}] } }, - { 'b': { 'c': 1, 'd': [{'e': 'one', 'f': true}] } }, - { 'b': { 'c': 2, 'd': [{'e': 'two', 'f': true}] } } - ] - } - >> AS t""", + key = key("exclude-19"), expected = BagType( StructType( fields = mapOf( @@ -1419,17 +1193,7 @@ class PartiQLSchemaInferencerTests { ), SuccessTestCase( name = "EXCLUDE case sensitive lookup", - query = """SELECT * EXCLUDE t."a".b['c'] - FROM << - { - 'a': { - 'B': { - 'c': 0, - 'd': 'foo' - } - } - } - >> AS t""", + key = key("exclude-20"), expected = BagType( StructType( fields = mapOf( @@ -1461,18 +1225,7 @@ class PartiQLSchemaInferencerTests { ), SuccessTestCase( name = "EXCLUDE case sensitive lookup with capitalized and uncapitalized attr", - query = """SELECT * EXCLUDE t."a".b['c'] - FROM << - { - 'a': { - 'B': { - 'c': 0, - 'C': true, - 'd': 'foo' - } - } - } - >> AS t""", + key = key("exclude-21"), expected = BagType( StructType( fields = mapOf( @@ -1505,18 +1258,7 @@ class PartiQLSchemaInferencerTests { ), SuccessTestCase( name = "EXCLUDE case sensitive lookup with both capitalized and uncapitalized removed", - query = """SELECT * EXCLUDE t."a".b.c - FROM << - { - 'a': { - 'B': { -- both 'c' and 'C' to be removed - 'c': 0, - 'C': true, - 'd': 'foo' - } - } - } - >> AS t""", + key = key("exclude-22"), expected = BagType( StructType( fields = mapOf( @@ -1548,18 +1290,7 @@ class PartiQLSchemaInferencerTests { ), SuccessTestCase( name = "EXCLUDE with both duplicates", - query = """SELECT * EXCLUDE t."a".b.c - FROM << - { - 'a': { - 'B': { - 'c': 0, - 'c': true, - 'd': 'foo' - } - } - } - >> AS t""", + key = key("exclude-23"), expected = BagType( StructType( fields = mapOf( @@ -1593,7 +1324,7 @@ class PartiQLSchemaInferencerTests { // EXCLUDE regression test (behavior subject to change pending RFC) SuccessTestCase( name = "EXCLUDE with removed attribute later referenced", - query = "SELECT * EXCLUDE t.a, t.a.b FROM << { 'a': { 'b': 1 }, 'c': 2 } >> AS t", + key = key("exclude-24"), expected = BagType( StructType( fields = mapOf( @@ -1611,7 +1342,7 @@ class PartiQLSchemaInferencerTests { // EXCLUDE regression test (behavior subject to change pending RFC) SuccessTestCase( name = "EXCLUDE with non-existent attribute reference", - query = "SELECT * EXCLUDE t.attr_does_not_exist FROM << { 'a': 1 } >> AS t", + key = key("exclude-25"), expected = BagType( StructType( fields = mapOf( @@ -1629,18 +1360,7 @@ class PartiQLSchemaInferencerTests { // EXCLUDE regression test (behavior subject to change pending RFC); could give error/warning SuccessTestCase( name = "exclude union of types", - query = """SELECT t EXCLUDE t.a.b - FROM << - { - 'a': { - 'b': 1, -- `b` to be excluded - 'c': 'foo' - } - }, - { - 'a': NULL - } - >> AS t""", + key = key("exclude-26"), expected = BagType( StructType( fields = mapOf( @@ -1681,21 +1401,7 @@ class PartiQLSchemaInferencerTests { ), SuccessTestCase( name = "exclude union of types exclude same type", - query = """SELECT t EXCLUDE t.a.b - FROM << - { - 'a': { - 'b': 1, -- `b` to be excluded - 'c': 'foo' - } - }, - { - 'a': { - 'b': 1, -- `b` to be excluded - 'c': NULL - } - } - >> AS t""", + key = key("exclude-27"), expected = BagType( StructType( fields = mapOf( @@ -1745,21 +1451,7 @@ class PartiQLSchemaInferencerTests { ), SuccessTestCase( name = "exclude union of types exclude different type", - query = """SELECT t EXCLUDE t.a.c - FROM << - { - 'a': { - 'b': 1, - 'c': 'foo' -- `c` to be excluded - } - }, - { - 'a': { - 'b': 1, - 'c': NULL -- `c` to be excluded - } - } - >> AS t""", + key = key("exclude-28"), expected = BagType( StructType( fields = mapOf( @@ -1792,17 +1484,7 @@ class PartiQLSchemaInferencerTests { // EXCLUDE regression test (behavior subject to change pending RFC); could give error/warning SuccessTestCase( name = "invalid exclude collection wildcard", - query = """SELECT * EXCLUDE t.a[*] - FROM << - { - 'a': { - 'b': { - 'c': 0, - 'd': 'foo' - } - } - } - >> AS t""", + key = key("exclude-29"), expected = BagType( elementType = StructType( fields = mapOf( @@ -1836,17 +1518,7 @@ class PartiQLSchemaInferencerTests { // EXCLUDE regression test (behavior subject to change pending RFC); could give error/warning SuccessTestCase( name = "invalid exclude collection index", - query = """SELECT * EXCLUDE t.a[1] - FROM << - { - 'a': { - 'b': { - 'c': 0, - 'd': 'foo' - } - } - } - >> AS t""", + key = key("exclude-30"), expected = BagType( elementType = StructType( fields = mapOf( @@ -1880,16 +1552,7 @@ class PartiQLSchemaInferencerTests { // EXCLUDE regression test (behavior subject to change pending RFC); could give error/warning SuccessTestCase( name = "invalid exclude tuple attr", - query = """SELECT * EXCLUDE t.a.b - FROM << - { - 'a': [ - { 'b': 0 }, - { 'b': 1 }, - { 'b': 2 } - ] - } - >> AS t""", + key = key("exclude-31"), expected = BagType( elementType = StructType( fields = mapOf( @@ -1915,16 +1578,7 @@ class PartiQLSchemaInferencerTests { // EXCLUDE regression test (behavior subject to change pending RFC); could give error/warning SuccessTestCase( name = "invalid exclude tuple wildcard", - query = """SELECT * EXCLUDE t.a.* - FROM << - { - 'a': [ - { 'b': 0 }, - { 'b': 1 }, - { 'b': 2 } - ] - } - >> AS t""", + key = key("exclude-32"), expected = BagType( elementType = StructType( fields = mapOf( @@ -1950,16 +1604,7 @@ class PartiQLSchemaInferencerTests { // EXCLUDE regression test (behavior subject to change pending RFC); could give error/warning SuccessTestCase( name = "invalid exclude tuple attr step", - query = """SELECT * EXCLUDE t.b -- `t.b` does not exist - FROM << - { - 'a': << - { 'b': 0 }, - { 'b': 1 }, - { 'b': 2 } - >> - } - >> AS t""", + key = key("exclude-33"), expected = BagType( elementType = StructType( fields = mapOf( @@ -1983,68 +1628,41 @@ class PartiQLSchemaInferencerTests { ) ), // EXCLUDE regression test (behavior subject to change pending RFC); could give error/warning - // ErrorTestCase( - // name = "invalid exclude root", - // query = """SELECT * EXCLUDE nonsense.b -- `nonsense` does not exist in binding tuples - // FROM << - // { - // 'a': << - // { 'b': 0 }, - // { 'b': 1 }, - // { 'b': 2 } - // >> - // } - // >> AS t""", - // expected = BagType( - // elementType = StructType( - // fields = mapOf( - // "a" to BagType( - // elementType = StructType( - // fields = mapOf( - // "b" to StaticType.INT - // ), - // contentClosed = true, - // constraints = setOf(TupleConstraint.Open(false), TupleConstraint.UniqueAttrs(true)) - // ) - // ) - // ), - // contentClosed = true, - // constraints = setOf( - // TupleConstraint.Open(false), - // TupleConstraint.UniqueAttrs(true), - // TupleConstraint.Ordered - // ) - // ) - // ), - // problemHandler = assertProblemExists { - // Problem( - // UNKNOWN_PROBLEM_LOCATION, - // PlanningProblemDetails.UnresolvedExcludeExprRoot("nonsense") - // ) - // } - // ), + ErrorTestCase( + name = "invalid exclude root", + key = key("exclude-34"), + expected = BagType( + elementType = StructType( + fields = mapOf( + "a" to BagType( + elementType = StructType( + fields = mapOf( + "b" to StaticType.INT + ), + contentClosed = true, + constraints = setOf(TupleConstraint.Open(false), TupleConstraint.UniqueAttrs(true)) + ) + ) + ), + contentClosed = true, + constraints = setOf( + TupleConstraint.Open(false), + TupleConstraint.UniqueAttrs(true), + TupleConstraint.Ordered + ) + ) + ), + problemHandler = assertProblemExists { + Problem( + UNKNOWN_PROBLEM_LOCATION, + PlanningProblemDetails.UnresolvedExcludeExprRoot("nonsense") + ) + } + ), // EXCLUDE regression test (behavior subject to change pending RFC); could give error/warning SuccessTestCase( name = "exclude with unions and last step collection index", - query = """SELECT * EXCLUDE t.a[0].c -- `c`'s type to be unioned with `MISSING` - FROM << - { - 'a': [ - { - 'b': 0, - 'c': 0 - }, - { - 'b': 1, - 'c': NULL - }, - { - 'b': 2, - 'c': 0.1 - } - ] - } - >> AS t""", + key = key("exclude-35"), expected = BagType( elementType = StructType( fields = mapOf( @@ -2098,7 +1716,7 @@ class PartiQLSchemaInferencerTests { SuccessTestCase( name = "EXCLUDE using a catalog", catalog = CATALOG_B, - query = "SELECT * EXCLUDE t.c FROM b.b.b AS t", + key = key("exclude-36"), expected = BagType( elementType = StructType( fields = mapOf( @@ -2152,9 +1770,11 @@ class PartiQLSchemaInferencerTests { } sealed class TestCase { + class SuccessTestCase( val name: String, - val query: String, + val key: PartiQLTest.Key? = null, + val query: String? = null, val catalog: String? = null, val catalogPath: List = emptyList(), val expected: StaticType, @@ -2164,7 +1784,8 @@ class PartiQLSchemaInferencerTests { class ErrorTestCase( val name: String, - val query: String, + val key: PartiQLTest.Key? = null, + val query: String? = null, val catalog: String? = null, val catalogPath: List = emptyList(), val note: String? = null, @@ -2911,8 +2532,15 @@ class PartiQLSchemaInferencerTests { ) val collector = ProblemCollector() val ctx = PartiQLSchemaInferencer.Context(session, PLUGINS, collector) - val result = PartiQLSchemaInferencer.inferInternal(tc.query, ctx) + val hasQuery = tc.query != null + val hasKey = tc.key != null + if (hasQuery == hasKey) { + error("Test must have one of either `query` or `key`") + } + val input = tc.query ?: provider[tc.key!!]!!.statement + + val result = PartiQLSchemaInferencer.inferInternal(input, ctx) assert(collector.problems.isEmpty()) { collector.problems.toString() } @@ -2940,7 +2568,15 @@ class PartiQLSchemaInferencerTests { ) val collector = ProblemCollector() val ctx = PartiQLSchemaInferencer.Context(session, PLUGINS, collector) - val result = PartiQLSchemaInferencer.inferInternal(tc.query, ctx) + + val hasQuery = tc.query != null + val hasKey = tc.key != null + if (hasQuery == hasKey) { + error("Test must have one of either `query` or `key`") + } + val input = tc.query ?: provider[tc.key!!]!!.statement + val result = PartiQLSchemaInferencer.inferInternal(input, ctx) + assert(collector.problems.isNotEmpty()) { buildString { appendLine("Expected to find problems, but none were found.") diff --git a/partiql-lang/src/test/resources/catalogs/db/markets/order_info.ion b/partiql-lang/src/test/resources/catalogs/db/markets/order_info.ion deleted file mode 100644 index 52fed9c74b..0000000000 --- a/partiql-lang/src/test/resources/catalogs/db/markets/order_info.ion +++ /dev/null @@ -1,19 +0,0 @@ -{ - name: "order_info", - constraints: [ closed, unique, ordered ], - type: "struct", - fields: [ - { - name: "customer_id", - type: "int", - }, - { - name: "marketplace_id", - type: "int", - }, - { - name: "ship_option", - type: "string", - } - ] -} \ No newline at end of file diff --git a/partiql-lang/src/test/resources/catalogs/db/markets/orders.ion b/partiql-lang/src/test/resources/catalogs/db/markets/orders.ion deleted file mode 100644 index f42abdb9cf..0000000000 --- a/partiql-lang/src/test/resources/catalogs/db/markets/orders.ion +++ /dev/null @@ -1,21 +0,0 @@ -{ - type: "bag", - items: { - type: "struct", - constraints: [ closed, unique, ordered ], - fields: [ - { - name: "customer_id", - type: "int", - }, - { - name: "marketplace_id", - type: "int", - }, - { - name: "ship_option", - type: "string", - } - ] - } -} diff --git a/partiql-planner/src/test/kotlin/org/partiql/planner/PlannerTestCase.kt b/partiql-planner/src/test/kotlin/org/partiql/planner/PlannerTestCase.kt deleted file mode 100644 index 271b1adcbb..0000000000 --- a/partiql-planner/src/test/kotlin/org/partiql/planner/PlannerTestCase.kt +++ /dev/null @@ -1,39 +0,0 @@ -package org.partiql.planner - -import com.amazon.ionelement.api.IonElement -import com.amazon.ionelement.api.ListElement -import com.amazon.ionelement.api.StringElement -import com.amazon.ionelement.api.StructElement -import org.partiql.plugins.local.getAngry -import org.partiql.plugins.local.toStaticType -import org.partiql.types.StaticType - -data class PlannerTestCase( - public val input: String, - public val catalog: String, - public val catalogPath: List, - public val schema: StaticType, -) { - - companion object { - - fun load(ion: StructElement): PlannerTestCase { - // Required - val input = ion.getAngry("input").textValue - val catalog = ion.getAngry("catalog").textValue - val schema = ion.getAngry("schema").toStaticType() - // Optional - val catalogPath = mutableListOf() - val pathArr = ion.getOptional("catalogPath") - if (pathArr != null && pathArr is ListElement) { - pathArr.asList().values.forEach { v -> - if (v !is StringElement) { - error("catalogPath must be a list of strings") - } - catalogPath.add((v as StringElement).textValue) - } - } - return PlannerTestCase(input, catalog, catalogPath, schema) - } - } -} diff --git a/partiql-planner/src/test/kotlin/org/partiql/planner/PlannerTestGroup.kt b/partiql-planner/src/test/kotlin/org/partiql/planner/PlannerTestGroup.kt deleted file mode 100644 index 20db17ee63..0000000000 --- a/partiql-planner/src/test/kotlin/org/partiql/planner/PlannerTestGroup.kt +++ /dev/null @@ -1,25 +0,0 @@ -package org.partiql.planner - -import com.amazon.ionelement.api.StructElement -import com.amazon.ionelement.api.loadAllElements -import java.io.File - -data class PlannerTestGroup( - public val name: String, - public val cases: List, -) { - - companion object { - - public fun load(dir: File): PlannerTestGroup { - val tests = dir.listFiles()!!.flatMap { loadAllTests(it) } - return PlannerTestGroup(dir.name, tests) - } - - public fun loadAllTests(file: File): List { - val text = file.readText() - val ion = loadAllElements(text) - return ion.map { PlannerTestCase.load(it as StructElement) } - } - } -} diff --git a/partiql-planner/src/test/kotlin/org/partiql/planner/PlannerTestJunit.kt b/partiql-planner/src/test/kotlin/org/partiql/planner/PlannerTestJunit.kt index 4556a31e58..187bc1d8bc 100644 --- a/partiql-planner/src/test/kotlin/org/partiql/planner/PlannerTestJunit.kt +++ b/partiql-planner/src/test/kotlin/org/partiql/planner/PlannerTestJunit.kt @@ -14,7 +14,7 @@ import org.junit.jupiter.api.fail import org.partiql.errors.ProblemSeverity import org.partiql.parser.PartiQLParserBuilder import org.partiql.plan.Statement -import org.partiql.planner.test.PartiQLTestCase +import org.partiql.planner.test.PartiQLTest import org.partiql.planner.test.PartiQLTestProvider import org.partiql.plugins.local.LocalPlugin import org.partiql.plugins.local.toIon @@ -51,7 +51,7 @@ class PlannerTestJunit { ), ) - private fun groupNode(group: PlannerTestGroup, inputs: Map): DynamicContainer { + private fun groupNode(group: PlannerTestGroup, inputs: Map): DynamicContainer { val plugin = LocalPlugin() val planner = PartiQLPlannerBuilder() .plugins(listOf(plugin)) diff --git a/partiql-planner/src/test/kotlin/org/partiql/planner/PlannerTestProvider.kt b/partiql-planner/src/test/kotlin/org/partiql/planner/PlannerTestProvider.kt deleted file mode 100644 index 5c47db42ad..0000000000 --- a/partiql-planner/src/test/kotlin/org/partiql/planner/PlannerTestProvider.kt +++ /dev/null @@ -1,25 +0,0 @@ -package org.partiql.planner - -import java.util.stream.Stream -import kotlin.io.path.toPath - -/** - * TODO converge with PartiQLTestProvider. - */ -class PlannerTestProvider { - - private val groups: List - - init { - val default = PlannerTestProvider::class.java.getResource("/cases")!!.toURI().toPath() - val casesDir = default.toFile() - groups = casesDir.listFiles { f -> f.isDirectory }!!.map { PlannerTestGroup.load(it) } - } - - /** - * Return test cases associated by groups. - */ - public fun groups(): Stream { - return groups.stream() - } -} diff --git a/partiql-planner/src/test/resources/cases/schema_inferencer/collections.ion b/partiql-planner/src/test/resources/cases/schema_inferencer/collections.ion deleted file mode 100644 index e75dbdc986..0000000000 --- a/partiql-planner/src/test/resources/cases/schema_inferencer/collections.ion +++ /dev/null @@ -1,66 +0,0 @@ -case::{ - input: "collections-01", - catalog: "default", - schema: { - type: "bag", - items: "int", - } -} - -case::{ - input: "collections-02", - catalog: "default", - schema: { - type: "list", - items: "int", - } -} - -case::{ - input: "collections-03", - catalog: "default", - schema: { - type: "list", - items: "int", - } -} - -case::{ - input: "collections-04", - catalog: "default", - schema: { - type: "sexp", - items: "int", - } -} - -case::{ - input: "collections-05", - catalog: "default", - schema: { - type: "bag", - items: "int", - } -} - -case::{ - input: "collections-06", - catalog: "default", - schema: { - type: "bag", - items: { - type: "struct", - constraints: [ - closed, - unique, - ordered - ], - fields: [ - { - name: "x", - type: "int", - } - ] - } - } -} diff --git a/partiql-planner/src/test/resources/cases/schema_inferencer/exclude.ion b/partiql-planner/src/test/resources/cases/schema_inferencer/exclude.ion deleted file mode 100644 index c7823e36a0..0000000000 --- a/partiql-planner/src/test/resources/cases/schema_inferencer/exclude.ion +++ /dev/null @@ -1,1714 +0,0 @@ -case::{ - input: "exclude-01", - catalog: "default", - schema: { - type: "bag", - items: { - type: "struct", - fields: [ - { - name: "name", - type: "string" - }, - { - name: "custId", - type: "int" - }, - { - name: "address", - type: { - type: "struct", - fields: [ - { - name: "city", - type: "string" - }, - { - name: "zipcode", - type: "int" - }, - { - name: "street", - type: "string" - } - ], - constraints: [ - closed, - unique - ] - } - } - ], - constraints: [ - closed, - unique, - ordered - ] - } - } -} - -case::{ - input: "exclude-02", - catalog: "default", - schema: { - type: "bag", - items: { - type: "struct", - fields: [ - { - name: "name", - type: "string" - }, - { - name: "custId", - type: "int" - }, - { - name: "address", - type: { - type: "struct", - fields: [ - { - name: "city", - type: "string" - }, - { - name: "zipcode", - type: "int" - } - ], - constraints: [ - closed, - unique - ] - } - } - ], - constraints: [ - closed, - unique, - ordered - ] - } - } -} - -case::{ - input: "exclude-03", - catalog: "default", - schema: { - type: "bag", - items: { - type: "struct", - fields: [ - { - name: "a", - type: { - type: "struct", - fields: [ - { - name: "b", - type: { - type: "struct", - fields: [ - { - name: "c", - type: { - type: "list", - items: { - type: "struct", - fields: [ - { - name: "field", - type: [ - "int", - "missing" - ] - } - ], - constraints: [ - closed, - unique - ] - } - } - } - ], - constraints: [ - closed, - unique - ] - } - } - ], - constraints: [ - closed, - unique - ] - } - }, - { - name: "foo", - type: "string" - } - ], - constraints: [ - closed, - unique, - ordered - ] - } - } -} - -case::{ - input: "exclude-04", - catalog: "default", - schema: { - type: "bag", - items: { - type: "struct", - fields: [ - { - name: "a", - type: { - type: "struct", - fields: [ - { - name: "b", - type: { - type: "struct", - fields: [ - { - name: "c", - type: { - type: "list", - items: "int" - } - } - ], - constraints: [ - closed, - unique - ] - } - } - ], - constraints: [ - closed, - unique - ] - } - }, - { - name: "foo", - type: "string" - } - ], - constraints: [ - closed, - unique, - ordered - ] - } - } -} - -case::{ - input: "exclude-05", - catalog: "default", - schema: { - type: "bag", - items: { - type: "struct", - fields: [ - { - name: "a", - type: { - type: "list", - items: "int" - } - } - ], - constraints: [ - closed, - unique, - ordered - ] - } - } -} - -case::{ - input: "exclude-06", - catalog: "default", - schema: { - type: "bag", - items: { - type: "struct", - fields: [ - { - name: "a", - type: { - type: "struct", - fields: [ - { - name: "b", - type: { - type: "struct", - fields: [ - { - name: "c", - type: { - type: "list", - items: { - type: "struct", - fields: [ - { - name: "field_y", - type: "int" - } - ], - constraints: [ - closed, - unique - ] - } - } - } - ], - constraints: [ - closed, - unique - ] - } - } - ], - constraints: [ - closed, - unique - ] - } - }, - { - name: "foo", - type: "string" - } - ], - constraints: [ - closed, - unique, - ordered - ] - } - } -} - -case::{ - input: "exclude-07", - catalog: "default", - schema: { - type: "bag", - items: { - type: "struct", - fields: [ - { - name: "a", - type: { - type: "struct", - fields: [ - { - name: "b", - type: { - type: "struct", - fields: [ - { - name: "c", - type: { - type: "list", - items: { - type: "struct", - fields: [], - constraints: [ - closed, - unique - ] - } - } - } - ], - constraints: [ - closed, - unique - ] - } - } - ], - constraints: [ - closed, - unique - ] - } - }, - { - name: "foo", - type: "string" - } - ], - constraints: [ - closed, - unique, - ordered - ] - } - } -} - -case::{ - input: "exclude-08", - catalog: "default", - schema: { - type: "list", - items: { - type: "struct", - fields: [ - { - name: "foo", - type: "string" - } - ], - constraints: [ - closed, - unique, - ordered - ] - } - } -} - -case::{ - input: "exclude-09", - catalog: "default", - schema: { - type: "bag", - items: { - type: "struct", - fields: [ - { - name: "a", - type: "int" - }, - { - name: "b", - type: "int" - }, - { - name: "c", - type: "int" - } - ], - constraints: [ - closed, - unique, - ordered - ] - } - } -} - -case::{ - input: "exclude-10", - catalog: "default", - schema: { - type: "bag", - items: { - type: "struct", - fields: [ - { - name: "b", - type: { - type: "list", - items: { - type: "struct", - fields: [ - { - name: "b_2", - type: "int" - } - ], - constraints: [ - closed, - unique - ] - } - } - } - ], - constraints: [ - closed, - unique, - ordered - ] - } - } -} - -case::{ - input: "exclude-11", - catalog: "default", - schema: { - type: "bag", - items: { - type: "struct", - fields: [ - { - name: "a", - type: { - type: "struct", - fields: [ - { - name: "a_1", - type: "int" - }, - { - name: "a_2", - type: "int" - } - ], - constraints: [ - closed, - unique - ] - } - }, - { - name: "b", - type: { - type: "list", - items: { - type: "struct", - fields: [ - { - name: "b_2", - type: "int" - } - ], - constraints: [ - closed, - unique - ] - } - } - }, - { - name: "c", - type: "int" - }, - { - name: "d", - type: "int" - } - ], - constraints: [ - closed, - unique, - ordered - ] - } - } -} - -case::{ - input: "exclude-12", - catalog: "default", - schema: { - type: "bag", - items: { - type: "list", - items: { - type: "struct", - fields: [ - { - name: "b_2", - type: "int" - } - ], - constraints: [ - closed, - unique - ] - } - } - } -} - -case::{ - input: "exclude-13", - catalog: "default", - schema: { - type: "bag", - items: { - type: "struct", - fields: [ - { - name: "a", - type: { - type: "list", - items: { - type: "struct", - fields: [ - { - name: "b", - type: { - type: "struct", - fields: [ - { - name: "d", - type: "string" - } - ], - constraints: [ - closed, - unique - ] - } - } - ], - constraints: [ - closed, - unique - ] - } - } - } - ], - constraints: [ - closed, - unique, - ordered - ] - } - } -} - -case::{ - input: "exclude-14", - catalog: "default", - schema: { - type: "bag", - items: { - type: "struct", - fields: [ - { - name: "a", - type: { - type: "list", - items: { - type: "struct", - fields: [ - { - name: "b", - type: { - type: "struct", - fields: [ - { - name: "c", - type: [ - "int", - "missing" - ] - }, - { - name: "d", - type: "string" - } - ], - constraints: [ - closed, - unique - ] - } - } - ], - constraints: [ - closed, - unique - ] - } - } - } - ], - constraints: [ - closed, - unique, - ordered - ] - } - } -} - -case::{ - input: "exclude-15", - catalog: "default", - schema: { - type: "bag", - items: { - type: "struct", - fields: [ - { - name: "a", - type: { - type: "list", - items: { - type: "struct", - fields: [ - { - name: "b", - type: { - type: "struct", - fields: [], - constraints: [ - closed, - unique - ] - } - } - ], - constraints: [ - closed, - unique - ] - } - } - } - ], - constraints: [ - closed, - unique, - ordered - ] - } - } -} - -case::{ - input: "exclude-16", - catalog: "default", - schema: { - type: "bag", - items: { - type: "struct", - fields: [ - { - name: "a", - type: { - type: "list", - items: { - type: "struct", - fields: [ - { - name: "b", - type: { - type: "struct", - fields: [ - { - name: "c", - type: [ - "int", - "missing" - ] - }, - { - name: "d", - type: [ - "missing", - "string" - ] - } - ], - constraints: [ - closed, - unique - ] - } - } - ], - constraints: [ - closed, - unique - ] - } - } - } - ], - constraints: [ - closed, - unique, - ordered - ] - } - } -} - -case::{ - input: "exclude-17", - catalog: "default", - schema: { - type: "bag", - items: { - type: "struct", - fields: [ - { - name: "a", - type: { - type: "list", - items: { - type: "struct", - fields: [ - { - name: "b", - type: { - type: "struct", - fields: [ - { - name: "c", - type: "int" - }, - { - name: "d", - type: { - type: "list", - items: { - type: "struct", - fields: [ - { - name: "f", - type: "bool" - } - ], - constraints: [ - closed, - unique - ] - } - } - } - ], - constraints: [ - closed, - unique - ] - } - } - ], - constraints: [ - closed, - unique - ] - } - } - } - ], - constraints: [ - closed, - unique, - ordered - ] - } - } -} - -case::{ - input: "exclude-18", - catalog: "default", - schema: { - type: "bag", - items: { - type: "struct", - fields: [ - { - name: "a", - type: { - type: "list", - items: { - type: "struct", - fields: [ - { - name: "b", - type: { - type: "struct", - fields: [ - { - name: "c", - type: "int" - }, - { - name: "d", - type: { - type: "list", - items: { - type: "struct", - fields: [ - { - name: "e", - type: [ - "missing", - "string" - ] - }, - { - name: "f", - type: "bool" - } - ], - constraints: [ - closed, - unique - ] - } - } - } - ], - constraints: [ - closed, - unique - ] - } - } - ], - constraints: [ - closed, - unique - ] - } - } - } - ], - constraints: [ - closed, - unique, - ordered - ] - } - } -} - -case::{ - input: "exclude-19", - catalog: "default", - schema: { - type: "bag", - items: { - type: "struct", - fields: [ - { - name: "a", - type: { - type: "list", - items: { - type: "struct", - fields: [ - { - name: "b", - type: { - type: "struct", - fields: [ - { - name: "c", - type: "int" - }, - { - name: "d", - type: { - type: "list", - items: { - type: "struct", - fields: [ - { - name: "e", - type: [ - "missing", - "string" - ] - }, - { - name: "f", - type: "bool" - } - ], - constraints: [ - closed, - unique - ] - } - } - } - ], - constraints: [ - closed, - unique - ] - } - } - ], - constraints: [ - closed, - unique - ] - } - } - } - ], - constraints: [ - closed, - unique, - ordered - ] - } - } -} - -case::{ - input: "exclude-20", - catalog: "default", - schema: { - type: "bag", - items: { - type: "struct", - fields: [ - { - name: "a", - type: { - type: "struct", - fields: [ - { - name: "B", - type: { - type: "struct", - fields: [ - { - name: "d", - type: "string" - } - ], - constraints: [ - closed, - unique - ] - } - } - ], - constraints: [ - closed, - unique - ] - } - } - ], - constraints: [ - closed, - unique, - ordered - ] - } - } -} - -case::{ - input: "exclude-21", - catalog: "default", - schema: { - type: "bag", - items: { - type: "struct", - fields: [ - { - name: "a", - type: { - type: "struct", - fields: [ - { - name: "B", - type: { - type: "struct", - fields: [ - { - name: "C", - type: "bool" - }, - { - name: "d", - type: "string" - } - ], - constraints: [ - closed, - unique - ] - } - } - ], - constraints: [ - closed, - unique - ] - } - } - ], - constraints: [ - closed, - unique, - ordered - ] - } - } -} - -case::{ - input: "exclude-22", - catalog: "default", - schema: { - type: "bag", - items: { - type: "struct", - fields: [ - { - name: "a", - type: { - type: "struct", - fields: [ - { - name: "B", - type: { - type: "struct", - fields: [ - { - name: "d", - type: "string" - } - ], - constraints: [ - closed, - unique - ] - } - } - ], - constraints: [ - closed, - unique - ] - } - } - ], - constraints: [ - closed, - unique, - ordered - ] - } - } -} - -case::{ - input: "exclude-23", - catalog: "default", - schema: { - type: "bag", - items: { - type: "struct", - fields: [ - { - name: "a", - type: { - type: "struct", - fields: [ - { - name: "B", - type: { - type: "struct", - fields: [ - { - name: "d", - type: "string" - } - ], - constraints: [ - closed, - unique - ] - } - } - ], - constraints: [ - closed, - unique - ] - } - } - ], - constraints: [ - closed, - unique, - ordered - ] - } - } -} - -case::{ - input: "exclude-24", - catalog: "default", - schema: { - type: "bag", - items: { - type: "struct", - fields: [ - { - name: "c", - type: "int" - } - ], - constraints: [ - closed, - unique, - ordered - ] - } - } -} - -case::{ - input: "exclude-25", - catalog: "default", - schema: { - type: "bag", - items: { - type: "struct", - fields: [ - { - name: "a", - type: "int" - } - ], - constraints: [ - closed, - unique, - ordered - ] - } - } -} - -case::{ - input: "exclude-26", - catalog: "default", - schema: { - type: "bag", - items: { - type: "struct", - fields: [ - { - name: "t", - type: [ - { - type: "struct", - fields: [ - { - name: "a", - type: { - type: "struct", - fields: [ - { - name: "c", - type: "string" - } - ], - constraints: [ - closed, - unique - ] - } - } - ], - constraints: [ - closed, - unique - ] - }, - { - type: "struct", - fields: [ - { - name: "a", - type: "null" - } - ], - constraints: [ - closed, - unique - ] - } - ] - } - ], - constraints: [ - closed, - unique, - ordered - ] - } - } -} - -case::{ - input: "exclude-27", - catalog: "default", - schema: { - type: "bag", - items: { - type: "struct", - fields: [ - { - name: "t", - type: [ - { - type: "struct", - fields: [ - { - name: "a", - type: { - type: "struct", - fields: [ - { - name: "c", - type: "string" - } - ], - constraints: [ - closed, - unique - ] - } - } - ], - constraints: [ - closed, - unique - ] - }, - { - type: "struct", - fields: [ - { - name: "a", - type: { - type: "struct", - fields: [ - { - name: "c", - type: "null" - } - ], - constraints: [ - closed, - unique - ] - } - } - ], - constraints: [ - closed, - unique - ] - } - ] - } - ], - constraints: [ - closed, - unique, - ordered - ] - } - } -} - -case::{ - input: "exclude-28", - catalog: "default", - schema: { - type: "bag", - items: { - type: "struct", - fields: [ - { - name: "t", - type: { - type: "struct", - fields: [ - { - name: "a", - type: { - type: "struct", - fields: [ - { - name: "b", - type: "int" - } - ], - constraints: [ - closed, - unique - ] - } - } - ], - constraints: [ - closed, - unique - ] - } - } - ], - constraints: [ - closed, - unique, - ordered - ] - } - } -} - -case::{ - input: "exclude-29", - catalog: "default", - schema: { - type: "bag", - items: { - type: "struct", - fields: [ - { - name: "a", - type: { - type: "struct", - fields: [ - { - name: "b", - type: { - type: "struct", - fields: [ - { - name: "c", - type: "int" - }, - { - name: "d", - type: "string" - } - ], - constraints: [ - closed, - unique - ] - } - } - ], - constraints: [ - closed, - unique - ] - } - } - ], - constraints: [ - closed, - unique, - ordered - ] - } - } -} - -case::{ - input: "exclude-30", - catalog: "default", - schema: { - type: "bag", - items: { - type: "struct", - fields: [ - { - name: "a", - type: { - type: "struct", - fields: [ - { - name: "b", - type: { - type: "struct", - fields: [ - { - name: "c", - type: "int" - }, - { - name: "d", - type: "string" - } - ], - constraints: [ - closed, - unique - ] - } - } - ], - constraints: [ - closed, - unique - ] - } - } - ], - constraints: [ - closed, - unique, - ordered - ] - } - } -} - -case::{ - input: "exclude-31", - catalog: "default", - schema: { - type: "bag", - items: { - type: "struct", - fields: [ - { - name: "a", - type: { - type: "list", - items: { - type: "struct", - fields: [ - { - name: "b", - type: "int" - } - ], - constraints: [ - closed, - unique - ] - } - } - } - ], - constraints: [ - closed, - unique, - ordered - ] - } - } -} - -case::{ - input: "exclude-32", - catalog: "default", - schema: { - type: "bag", - items: { - type: "struct", - fields: [ - { - name: "a", - type: { - type: "list", - items: { - type: "struct", - fields: [ - { - name: "b", - type: "int" - } - ], - constraints: [ - closed, - unique - ] - } - } - } - ], - constraints: [ - closed, - unique, - ordered - ] - } - } -} - -case::{ - input: "exclude-33", - catalog: "default", - schema: { - type: "bag", - items: { - type: "struct", - fields: [ - { - name: "a", - type: { - type: "bag", - items: { - type: "struct", - fields: [ - { - name: "b", - type: "int" - } - ], - constraints: [ - closed, - unique - ] - } - } - } - ], - constraints: [ - closed, - unique, - ordered - ] - } - } -} - -case::{ - input: "exclude-34", - catalog: "default", - schema: { - type: "bag", - items: { - type: "struct", - fields: [ - { - name: "a", - type: { - type: "list", - items: [ - { - type: "struct", - fields: [ - { - name: "b", - type: "int" - }, - { - name: "c", - type: [ - "int", - "missing" - ] - } - ], - constraints: [ - closed, - unique - ] - }, - { - type: "struct", - fields: [ - { - name: "b", - type: "int" - }, - { - name: "c", - type: [ - "missing", - "null" - ] - } - ], - constraints: [ - closed, - unique - ] - }, - { - type: "struct", - fields: [ - { - name: "b", - type: "int" - }, - { - name: "c", - type: [ - "decimal", - "missing" - ] - } - ], - constraints: [ - closed, - unique - ] - } - ] - } - } - ], - constraints: [ - closed, - unique, - ordered - ] - } - } -} - -case::{ - input: "exclude-35", - catalog: "default", - schema: { - type: "bag", - items: { - type: "struct", - fields: [ - { - name: "b", - type: { - type: "struct", - fields: [ - { - name: "b", - type: "int" - } - ], - constraints: [ - closed, - unique, - ordered - ] - } - } - ], - constraints: [ - closed, - unique, - ordered - ] - } - } -} diff --git a/partiql-planner/src/test/resources/cases/schema_inferencer/joins.ion b/partiql-planner/src/test/resources/cases/schema_inferencer/joins.ion deleted file mode 100644 index 8dff4f9e5c..0000000000 --- a/partiql-planner/src/test/resources/cases/schema_inferencer/joins.ion +++ /dev/null @@ -1,177 +0,0 @@ -case::{ - input: "join-01", - catalog: "default", - schema: { - type: "bag", - items: { - type: "struct", - fields: [ - { - name: "a", - type: "int" - }, - { - name: "b", - type: "decimal" - } - ], - constraints: [ - closed, - unique, - ordered - ] - } - } -} - -case::{ - input: "join-02", - catalog: "default", - schema: { - type: "bag", - items: { - type: "struct", - fields: [ - { - name: "a", - type: "int" - }, - { - name: "b", - type: [ - "decimal", - "null" - ] - } - ], - constraints: [ - closed, - unique, - ordered - ] - } - } -} - -case::{ - input: "join-03", - catalog: "default", - schema: { - type: "bag", - items: { - type: "struct", - fields: [ - { - name: "b", - type: [ - "decimal", - "null" - ] - }, - { - name: "a", - type: "int" - } - ], - constraints: [ - closed, - unique, - ordered - ] - } - } -} - -case::{ - input: "join-04", - catalog: "default", - schema: { - type: "bag", - items: { - type: "struct", - fields: [ - { - name: "a", - type: "int" - }, - { - name: "a", - type: [ - "decimal", - "null" - ] - } - ], - constraints: [ - closed, - unique, - ordered - ] - } - } -} - -case::{ - input: "join-05", - catalog: "default", - schema: { - type: "bag", - items: { - type: "struct", - fields: [ - { - name: "a", - type: "int" - }, - { - name: "a", - type: [ - "decimal", - "null" - ] - } - ], - constraints: [ - closed, - unique, - ordered - ] - } - } -} - -case::{ - input: "join-06", - catalog: "default", - schema: { - type: "bag", - items: { - type: "struct", - fields: [ - { - name: "a", - type: "int" - }, - { - name: "a", - type: [ - "decimal", - "null" - ] - }, - { - name: "a", - type: [ - "null", - "string" - ] - } - ], - constraints: [ - closed, - unique, - ordered - ] - } - } -} diff --git a/partiql-planner/src/test/resources/cases/schema_inferencer/order_by.ion b/partiql-planner/src/test/resources/cases/schema_inferencer/order_by.ion deleted file mode 100644 index 341d5b82ab..0000000000 --- a/partiql-planner/src/test/resources/cases/schema_inferencer/order_by.ion +++ /dev/null @@ -1,77 +0,0 @@ -case::{ - input: "order_by-01", - catalog: "default", - schema: { - type: "list", - items: { - type: "struct", - fields: [ - { - name: "id", - type: "int" - }, - { - name: "breed", - type: "string" - } - ], - constraints: [ - closed, - unique, - ordered - ] - } - } -} - -case::{ - input: "order_by-02", - catalog: "default", - schema: { - type: "list", - items: { - type: "struct", - fields: [ - { - name: "id", - type: "int" - }, - { - name: "breed", - type: "string" - } - ], - constraints: [ - closed, - unique, - ordered - ] - } - } -} - -case::{ - input: "order_by-03", - catalog: "default", - schema: { - type: "list", - items: { - type: "struct", - fields: [ - { - name: "id", - type: "int" - }, - { - name: "breed", - type: "string" - } - ], - constraints: [ - closed, - unique, - ordered - ] - } - } -} diff --git a/partiql-planner/src/test/resources/cases/schema_inferencer/sanity.ion b/partiql-planner/src/test/resources/cases/schema_inferencer/sanity.ion deleted file mode 100644 index b5936f76fa..0000000000 --- a/partiql-planner/src/test/resources/cases/schema_inferencer/sanity.ion +++ /dev/null @@ -1,160 +0,0 @@ -case::{ - input: "sanity-01", - catalog: "tpc_ds", - schema: { - type: "bag", - items: { - type: "struct", - constraints: [ - closed, - unique, - ordered - ], - fields: [ - { - name: "ss_ticket_number", - type: "string", - }, - { - name: "ss_quantity", - type: [ - "int32", - "null" - ], - }, - { - name: "ss_sold_date_sk", - type: [ - "date", - "null" - ], - }, - ], - }, - } -} - -case::{ - input: "sanity-02", - catalog: "tpc_ds", - schema: { - type: "bag", - items: { - type: "struct", - constraints: [ - closed, - unique, - ordered - ], - fields: [ - { - name: "ss_ticket_number", - type: "string", - }, - { - name: "ss_quantity", - type: [ - "int32", - "null" - ], - }, - { - name: "ss_sold_date_sk", - type: [ - "date", - "null" - ], - }, - ], - }, - } -} - -case::{ - input: "sanity-03", - catalog: "tpc_ds", - schema: { - type: "bag", - items: { - type: "struct", - constraints: [ - closed, - unique, - ordered - ], - fields: [ - { - name: "x", - type: [ - "bool", - "null" - ], - }, - ], - }, - }, -} - -case::{ - input: "sanity-04", - catalog: "tpc_ds", - schema: { - type: "bag", - items: { - type: "struct", - constraints: [ - closed, - unique, - ordered - ], - fields: [ - { - name: "ss_quantity", - type: [ - "int32", - "null" - ] - }, - { - name: "ss_quantity_description_1", - type: "string" - }, - { - name: "ss_quantity_description_2", - type: [ - "string", - "decimal", - "int", - "null" - ] - }, - { - name: "ss_quantity_description_3", - type: "string" - }, - ] - } - } -} - -case::{ - input: "sanity-05", - catalog: "tpc_ds", - schema: { - type: "bag", - items: { - type: "struct", - constraints: [ - closed, - unique, - ordered - ], - fields: [ - { - name: "s_store_sk", - type: "string" - } - ] - } - } -} diff --git a/partiql-planner/src/test/resources/cases/tpc_ds/.gitkeep b/partiql-planner/src/test/resources/cases/tpc_ds/.gitkeep deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/partiql-planner/src/test/resources/cases/tpc_h/.gitkeep b/partiql-planner/src/test/resources/cases/tpc_h/.gitkeep deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/partiql-planner/src/testFixtures/kotlin/org/partiql/planner/test/PartiQLTest.kt b/partiql-planner/src/testFixtures/kotlin/org/partiql/planner/test/PartiQLTest.kt new file mode 100644 index 0000000000..0e8f762a2d --- /dev/null +++ b/partiql-planner/src/testFixtures/kotlin/org/partiql/planner/test/PartiQLTest.kt @@ -0,0 +1,38 @@ +/* + * Copyright 2019 Amazon.com, Inc. or its affiliates. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"). + * You may not use this file except in compliance with the License. + * A copy of the License is located at: + * + * http://aws.amazon.com/apache2.0/ + * + * or in the "license" file accompanying this file. This file 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 org.partiql.planner.test + +/** + * Holding class for test input. + * + * --#[example-test] + * SELECT * FROM example; + */ +public data class PartiQLTest( + public val key: Key, + public val statement: String, +) { + + /** + * Unique test identifier. + * + * @property group + * @property name + */ + public data class Key( + public val group: String, + public val name: String, + ) +} diff --git a/partiql-planner/src/testFixtures/kotlin/org/partiql/planner/test/PartiQLTestCase.kt b/partiql-planner/src/testFixtures/kotlin/org/partiql/planner/test/PartiQLTestCase.kt deleted file mode 100644 index 83bae26ae4..0000000000 --- a/partiql-planner/src/testFixtures/kotlin/org/partiql/planner/test/PartiQLTestCase.kt +++ /dev/null @@ -1,17 +0,0 @@ -package org.partiql.planner.test - -/** - * Simple class to hold a test; for example, - * - * --#[example-test] - * SELECT * FROM example; - * - * PlannerTest( - * name = "example-test", - * statement = "SELECT * FROM example", - * ) - */ -public data class PartiQLTestCase( - public val id: String, - public val statement: String, -) diff --git a/partiql-planner/src/testFixtures/kotlin/org/partiql/planner/test/PartiQLTestGroup.kt b/partiql-planner/src/testFixtures/kotlin/org/partiql/planner/test/PartiQLTestGroup.kt deleted file mode 100644 index b273cdab08..0000000000 --- a/partiql-planner/src/testFixtures/kotlin/org/partiql/planner/test/PartiQLTestGroup.kt +++ /dev/null @@ -1,47 +0,0 @@ -package org.partiql.planner.test - -import java.io.File - -public class PartiQLTestGroup( - public val name: String, - public val inputs: List, -) { - - companion object { - - public fun load(dir: File): PartiQLTestGroup { - val tests = dir.listFiles()!!.flatMap { loadAllTests(it) } - return PartiQLTestGroup(dir.name, tests) - } - - public fun loadAllTests(file: File): List { - val tests = mutableListOf() - var name = "" - val statement = StringBuilder() - for (line in file.readLines()) { - - // start of test - if (line.startsWith("--#[") and line.endsWith("]")) { - name = line.substring(4, line.length - 1) - statement.clear() - } - - if (name.isNotEmpty() && line.isNotBlank()) { - // accumulating test statement - statement.appendLine(line) - } else { - // skip these lines - continue - } - - // Finish & Reset - if (line.endsWith(";")) { - tests.add(PartiQLTestCase(name, statement.toString())) - name = "" - statement.clear() - } - } - return tests - } - } -} diff --git a/partiql-planner/src/testFixtures/kotlin/org/partiql/planner/test/PartiQLTestProvider.kt b/partiql-planner/src/testFixtures/kotlin/org/partiql/planner/test/PartiQLTestProvider.kt index 627491db95..3237359710 100644 --- a/partiql-planner/src/testFixtures/kotlin/org/partiql/planner/test/PartiQLTestProvider.kt +++ b/partiql-planner/src/testFixtures/kotlin/org/partiql/planner/test/PartiQLTestProvider.kt @@ -1,37 +1,99 @@ +/* + * Copyright 2019 Amazon.com, Inc. or its affiliates. All rights reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"). + * You may not use this file except in compliance with the License. + * A copy of the License is located at: + * + * http://aws.amazon.com/apache2.0/ + * + * or in the "license" file accompanying this file. This file 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 org.partiql.planner.test +import java.io.File import java.nio.file.Path -import java.util.stream.Stream import kotlin.io.path.toPath -class PartiQLTestProvider(root: Path? = null) { +/** + * The PartiQLTestProvider is a simple utility for indexing SQL statements within files for re-use across library tests. + */ +class PartiQLTestProvider { - private val groups: List + /** + * Backing map for test input lookup. + */ + private val map: MutableMap = mutableMapOf() - init { - val default = PartiQLTestCase::class.java.getResource("/inputs")!!.toURI().toPath() - val inputsDir = (root ?: default).toFile() - groups = inputsDir.listFiles { f -> f.isDirectory }!!.map { PartiQLTestGroup.load(it) } - } + /** + * Default database of test inputs. + */ + private val default = this::class.java.getResource("/inputs")!!.toURI().toPath() /** - * Return test inputs associated by groups. + * Load test groups from a directory. */ - public fun groups(): Stream { - return groups.stream() + public fun load(root: Path? = null) { + val dir = (root ?: default).toFile() + dir.listFiles { f -> f.isDirectory }!!.map { + for (test in load(it)) { + map[test.key] = test + } + } } /** - * Return test inputs associated by test key __. + * Lookup a test by key + * + * @param key + * @return + */ + public operator fun get(key: PartiQLTest.Key): PartiQLTest? = map[key] + + /** + * Lookup a test by key parts + * + * @param group + * @param name + * @return */ - public fun inputs(): Map { - val map = mutableMapOf() - for (group in groups) { - for (test in group.inputs) { - val key = "${group.name}__${test.id}" - map[key] = test + public fun get(group: String, name: String): PartiQLTest? = get(PartiQLTest.Key(group, name)) + + // load all tests in a directory + private fun load(dir: File) = dir.listFiles()!!.flatMap { load(dir.name, it) } + + // load all tests in a file + private fun load(group: String, file: File): List { + val tests = mutableListOf() + var name = "" + val statement = StringBuilder() + for (line in file.readLines()) { + + // start of test + if (line.startsWith("--#[") and line.endsWith("]")) { + name = line.substring(4, line.length - 1) + statement.clear() + } + + if (name.isNotEmpty() && line.isNotBlank()) { + // accumulating test statement + statement.appendLine(line) + } else { + // skip these lines + continue + } + + // Finish & Reset + if (line.endsWith(";")) { + val key = PartiQLTest.Key(group, name) + tests.add(PartiQLTest(key, statement.toString())) + name = "" + statement.clear() } } - return map + return tests } } diff --git a/partiql-lang/src/test/resources/catalogs/db/aws/b/b.ion b/partiql-planner/src/testFixtures/resources/catalogs/default/aws/b/b.ion similarity index 100% rename from partiql-lang/src/test/resources/catalogs/db/aws/b/b.ion rename to partiql-planner/src/testFixtures/resources/catalogs/default/aws/b/b.ion diff --git a/partiql-lang/src/test/resources/catalogs/db/aws/ddb/b.ion b/partiql-planner/src/testFixtures/resources/catalogs/default/aws/ddb/b.ion similarity index 100% rename from partiql-lang/src/test/resources/catalogs/db/aws/ddb/b.ion rename to partiql-planner/src/testFixtures/resources/catalogs/default/aws/ddb/b.ion diff --git a/partiql-lang/src/test/resources/catalogs/db/aws/ddb/pets.ion b/partiql-planner/src/testFixtures/resources/catalogs/default/aws/ddb/pets.ion similarity index 100% rename from partiql-lang/src/test/resources/catalogs/db/aws/ddb/pets.ion rename to partiql-planner/src/testFixtures/resources/catalogs/default/aws/ddb/pets.ion diff --git a/partiql-lang/src/test/resources/catalogs/db/b/b/b.ion b/partiql-planner/src/testFixtures/resources/catalogs/default/b/b/b.ion similarity index 100% rename from partiql-lang/src/test/resources/catalogs/db/b/b/b.ion rename to partiql-planner/src/testFixtures/resources/catalogs/default/b/b/b.ion diff --git a/partiql-lang/src/test/resources/catalogs/db/b/b/c.ion b/partiql-planner/src/testFixtures/resources/catalogs/default/b/b/c.ion similarity index 100% rename from partiql-lang/src/test/resources/catalogs/db/b/b/c.ion rename to partiql-planner/src/testFixtures/resources/catalogs/default/b/b/c.ion diff --git a/partiql-lang/src/test/resources/catalogs/db/b/b/d.ion b/partiql-planner/src/testFixtures/resources/catalogs/default/b/b/d.ion similarity index 100% rename from partiql-lang/src/test/resources/catalogs/db/b/b/d.ion rename to partiql-planner/src/testFixtures/resources/catalogs/default/b/b/d.ion diff --git a/partiql-lang/src/test/resources/catalogs/db/b/c/c.ion b/partiql-planner/src/testFixtures/resources/catalogs/default/b/c/c.ion similarity index 100% rename from partiql-lang/src/test/resources/catalogs/db/b/c/c.ion rename to partiql-planner/src/testFixtures/resources/catalogs/default/b/c/c.ion diff --git a/partiql-planner/src/testFixtures/resources/catalogs/default/db/aws/b/b.ion b/partiql-planner/src/testFixtures/resources/catalogs/default/db/aws/b/b.ion deleted file mode 100644 index c6ac007345..0000000000 --- a/partiql-planner/src/testFixtures/resources/catalogs/default/db/aws/b/b.ion +++ /dev/null @@ -1,13 +0,0 @@ -{ - type: "bag", - items: { - type: "struct", - constraints: [ closed, unique, ordered ], - fields: [ - { - name: "identifier", - type: "int", - } - ] - } -} diff --git a/partiql-planner/src/testFixtures/resources/catalogs/default/db/aws/ddb/b.ion b/partiql-planner/src/testFixtures/resources/catalogs/default/db/aws/ddb/b.ion deleted file mode 100644 index 1ea09e58c9..0000000000 --- a/partiql-planner/src/testFixtures/resources/catalogs/default/db/aws/ddb/b.ion +++ /dev/null @@ -1,13 +0,0 @@ -{ - type: "bag", - items: { - type: "struct", - constraints: [ closed, unique, ordered ], - fields: [ - { - name: "identifier", - type: "string", - } - ] - } -} diff --git a/partiql-planner/src/testFixtures/resources/catalogs/default/db/aws/ddb/pets.ion b/partiql-planner/src/testFixtures/resources/catalogs/default/db/aws/ddb/pets.ion deleted file mode 100644 index 14f1c1f5e4..0000000000 --- a/partiql-planner/src/testFixtures/resources/catalogs/default/db/aws/ddb/pets.ion +++ /dev/null @@ -1,17 +0,0 @@ -{ - type: "bag", - items: { - type: "struct", - constraints: [ closed, unique, ordered ], - fields: [ - { - name: "id", - type: "int", - }, - { - name: "breed", - type: "string", - } - ] - } -} diff --git a/partiql-planner/src/testFixtures/resources/catalogs/default/db/b/b/b.ion b/partiql-planner/src/testFixtures/resources/catalogs/default/db/b/b/b.ion deleted file mode 100644 index 8508d37b63..0000000000 --- a/partiql-planner/src/testFixtures/resources/catalogs/default/db/b/b/b.ion +++ /dev/null @@ -1,23 +0,0 @@ -{ - type: "struct", - constraints: [ closed, unique, ordered ], - fields: [ - { - name: "b", - type: { - type: "struct", - constraints: [ closed, unique, ordered ], - fields: [ - { - name: "b", - type: "int", - } - ] - } - }, - { - name: "c", - type: "int", - } - ] -} diff --git a/partiql-planner/src/testFixtures/resources/catalogs/default/db/b/b/c.ion b/partiql-planner/src/testFixtures/resources/catalogs/default/db/b/b/c.ion deleted file mode 100644 index a21274f547..0000000000 --- a/partiql-planner/src/testFixtures/resources/catalogs/default/db/b/b/c.ion +++ /dev/null @@ -1 +0,0 @@ -"int" diff --git a/partiql-planner/src/testFixtures/resources/catalogs/default/db/b/b/d.ion b/partiql-planner/src/testFixtures/resources/catalogs/default/db/b/b/d.ion deleted file mode 100644 index c01b78f407..0000000000 --- a/partiql-planner/src/testFixtures/resources/catalogs/default/db/b/b/d.ion +++ /dev/null @@ -1,22 +0,0 @@ -{ - type: "struct", - constraints: [ ordered ], - fields: [ - { - name: "e", - type: "int", - }, - { - name: "e", - type: { - type: "struct", - fields: [ - { - name: "f", - type: "int", - } - ] - } - } - ] -} diff --git a/partiql-planner/src/testFixtures/resources/catalogs/default/db/b/c/c.ion b/partiql-planner/src/testFixtures/resources/catalogs/default/db/b/c/c.ion deleted file mode 100644 index fcde59dd6f..0000000000 --- a/partiql-planner/src/testFixtures/resources/catalogs/default/db/b/c/c.ion +++ /dev/null @@ -1 +0,0 @@ -"decimal" diff --git a/partiql-planner/src/testFixtures/resources/inputs/schema_inferencer/exclude.sql b/partiql-planner/src/testFixtures/resources/inputs/schema_inferencer/exclude.sql index 5d44ff83f0..3c862dd791 100644 --- a/partiql-planner/src/testFixtures/resources/inputs/schema_inferencer/exclude.sql +++ b/partiql-planner/src/testFixtures/resources/inputs/schema_inferencer/exclude.sql @@ -437,6 +437,18 @@ FROM << >> AS t; --#[exclude-34] +-- EXCLUDE regression test (behavior subject to change pending RFC); could give error/warning +SELECT * EXCLUDE nonsense.b -- `nonsense` does not exist in binding tuples +FROM << + { 'a': << + { 'b': 0 }, + { 'b': 1 }, + { 'b': 2 } + >> + } +>> AS t; + +--#[exclude-35] SELECT * EXCLUDE t.a[0].c -- `c`'s type to be unioned with `MISSING` FROM << { @@ -457,5 +469,5 @@ FROM << } >> AS t; ---#[exclude-35] +--#[exclude-36] SELECT * EXCLUDE t.c FROM b.b.b AS t; \ No newline at end of file