diff --git a/extensions-core/multi-stage-query/pom.xml b/extensions-core/multi-stage-query/pom.xml
index ab23a26e36f..0c3bceb4ddb 100644
--- a/extensions-core/multi-stage-query/pom.xml
+++ b/extensions-core/multi-stage-query/pom.xml
@@ -213,6 +213,32 @@
junit
test
+
+ net.hydromatic
+ quidem
+ test
+
+
+ org.apache.calcite
+ calcite-testkit
+ ${calcite.version}
+
+
+ org.junit.jupiter
+ *
+
+
+ org.hamcrest
+ *
+
+
+ test
+
+
+ org.reflections
+ reflections
+ test
+
org.junit.jupiter
junit-jupiter-api
diff --git a/extensions-core/multi-stage-query/src/test/java/org/apache/druid/msq/exec/MSQQuidemTest.java b/extensions-core/multi-stage-query/src/test/java/org/apache/druid/msq/exec/MSQQuidemTest.java
new file mode 100644
index 00000000000..d63744015c5
--- /dev/null
+++ b/extensions-core/multi-stage-query/src/test/java/org/apache/druid/msq/exec/MSQQuidemTest.java
@@ -0,0 +1,48 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.druid.msq.exec;
+
+import org.apache.druid.common.config.NullHandling;
+import org.apache.druid.quidem.DruidQuidemTestBase;
+import org.apache.druid.quidem.ProjectPathUtils;
+import org.junit.jupiter.api.condition.EnabledIf;
+
+import java.io.File;
+
+@EnabledIf(value = "enabled", disabledReason = "These tests are only run in SqlCompatible mode!")
+public class MSQQuidemTest extends DruidQuidemTestBase
+{
+ public static boolean enabled()
+ {
+ NullHandling.initializeForTests();
+ return NullHandling.sqlCompatible();
+ }
+
+ public MSQQuidemTest()
+ {
+ super();
+ }
+
+ @Override
+ protected File getTestRoot()
+ {
+ return ProjectPathUtils.getPathFromProjectRoot("extensions-core/multi-stage-query/src/test/quidem/" + getClass().getName());
+ }
+}
diff --git a/extensions-core/multi-stage-query/src/test/quidem/org.apache.druid.msq.exec.MSQQuidemTest/decoupled.iq b/extensions-core/multi-stage-query/src/test/quidem/org.apache.druid.msq.exec.MSQQuidemTest/decoupled.iq
new file mode 100644
index 00000000000..eadd54fd69c
--- /dev/null
+++ b/extensions-core/multi-stage-query/src/test/quidem/org.apache.druid.msq.exec.MSQQuidemTest/decoupled.iq
@@ -0,0 +1,96 @@
+!set plannerStrategy DECOUPLED
+!use druidtest://?componentSupplier=DrillWindowQueryMSQComponentSupplier
+!set outputformat mysql
+
+select cityName, count(case when delta > 0 then channel end) as cnt, count(1) as aall
+from wikipedia
+where cityName in ('New York', 'Aarhus')
+group by 1
+order by 1;
++----------+-----+------+
+| cityName | cnt | aall |
++----------+-----+------+
+| Aarhus | 0 | 1 |
+| New York | 7 | 13 |
++----------+-----+------+
+(2 rows)
+
+!ok
+LogicalSort(sort0=[$0], dir0=[ASC])
+ LogicalAggregate(group=[{0}], cnt=[COUNT($1)], aall=[COUNT()])
+ LogicalProject(cityName=[$2], $f1=[CASE(>($17, 0), $1, null:VARCHAR)])
+ LogicalFilter(condition=[OR(=($2, 'New York'), =($2, 'Aarhus'))])
+ LogicalTableScan(table=[[druid, wikipedia]])
+
+!convertedPlan
+LogicalSort(sort0=[$0], dir0=[ASC])
+ LogicalAggregate(group=[{0}], cnt=[COUNT($1) FILTER $2], aall=[COUNT()])
+ LogicalProject(cityName=[$2], channel=[$1], $f3=[IS TRUE(>($17, 0))])
+ LogicalFilter(condition=[SEARCH($2, Sarg['Aarhus':VARCHAR(8), 'New York':VARCHAR(8)]:VARCHAR(8))])
+ LogicalTableScan(table=[[druid, wikipedia]])
+
+!logicalPlan
+DruidAggregate(group=[{0}], cnt=[COUNT($1) FILTER $2], aall=[COUNT()], druid=[logical])
+ DruidProject(cityName=[$2], channel=[$1], $f3=[IS TRUE(>($17, 0))], druid=[logical])
+ DruidFilter(condition=[SEARCH($2, Sarg['Aarhus':VARCHAR(8), 'New York':VARCHAR(8)]:VARCHAR(8))])
+ DruidTableScan(table=[[druid, wikipedia]], druid=[logical])
+
+!druidPlan
+{
+ "queryType" : "groupBy",
+ "dataSource" : {
+ "type" : "table",
+ "name" : "wikipedia"
+ },
+ "intervals" : {
+ "type" : "intervals",
+ "intervals" : [ "-146136543-09-08T08:23:32.096Z/146140482-04-24T15:36:27.903Z" ]
+ },
+ "filter" : {
+ "type" : "inType",
+ "column" : "cityName",
+ "matchValueType" : "STRING",
+ "sortedValues" : [ "Aarhus", "New York" ]
+ },
+ "granularity" : {
+ "type" : "all"
+ },
+ "dimensions" : [ {
+ "type" : "default",
+ "dimension" : "cityName",
+ "outputName" : "d0",
+ "outputType" : "STRING"
+ } ],
+ "aggregations" : [ {
+ "type" : "filtered",
+ "aggregator" : {
+ "type" : "count",
+ "name" : "a0"
+ },
+ "filter" : {
+ "type" : "and",
+ "fields" : [ {
+ "type" : "not",
+ "field" : {
+ "type" : "null",
+ "column" : "channel"
+ }
+ }, {
+ "type" : "range",
+ "column" : "delta",
+ "matchValueType" : "LONG",
+ "lower" : 0,
+ "lowerOpen" : true
+ } ]
+ },
+ "name" : "a0"
+ }, {
+ "type" : "count",
+ "name" : "a1"
+ } ],
+ "limitSpec" : {
+ "type" : "NoopLimitSpec"
+ }
+}
+!nativePlan
+
diff --git a/sql/src/main/java/org/apache/druid/sql/SqlToolbox.java b/sql/src/main/java/org/apache/druid/sql/SqlToolbox.java
index 6ba8b59e577..61d127f8fd3 100644
--- a/sql/src/main/java/org/apache/druid/sql/SqlToolbox.java
+++ b/sql/src/main/java/org/apache/druid/sql/SqlToolbox.java
@@ -51,6 +51,8 @@ public class SqlToolbox
)
{
this.engine = engine;
+ System.out.println("SqlToolbox.SqlToolbox");
+ System.out.println("engine = " + engine);
this.plannerFactory = plannerFactory;
this.emitter = emitter;
this.requestLogger = requestLogger;
diff --git a/sql/src/main/java/org/apache/druid/sql/calcite/planner/QueryHandler.java b/sql/src/main/java/org/apache/druid/sql/calcite/planner/QueryHandler.java
index 41b03760c1c..31b7d25404d 100644
--- a/sql/src/main/java/org/apache/druid/sql/calcite/planner/QueryHandler.java
+++ b/sql/src/main/java/org/apache/druid/sql/calcite/planner/QueryHandler.java
@@ -746,6 +746,7 @@ public abstract class QueryHandler extends SqlStatementHandler.BaseStatementHand
@Override
protected QueryMaker buildQueryMaker(final RelRoot rootQueryRel) throws ValidationException
{
+ System.out.println("SelectHandler.buildQueryMaker");
return handlerContext.engine().buildQueryMakerForSelect(
rootQueryRel,
handlerContext.plannerContext()
diff --git a/sql/src/test/java/org/apache/druid/quidem/DruidQuidemTestBase.java b/sql/src/test/java/org/apache/druid/quidem/DruidQuidemTestBase.java
index 650af0880f9..23a96ba6a0d 100644
--- a/sql/src/test/java/org/apache/druid/quidem/DruidQuidemTestBase.java
+++ b/sql/src/test/java/org/apache/druid/quidem/DruidQuidemTestBase.java
@@ -123,6 +123,7 @@ public abstract class DruidQuidemTestBase
File inFile = new File(getTestRoot(), testFileName);
final File outFile = new File(inFile.getParentFile(), inFile.getName() + ".out");
+ System.out.println("druidQuidemRunner = " + druidQuidemRunner);
druidQuidemRunner.run(inFile, outFile);
}
diff --git a/sql/src/test/java/org/apache/druid/sql/calcite/SqlTestFrameworkConfig.java b/sql/src/test/java/org/apache/druid/sql/calcite/SqlTestFrameworkConfig.java
index 1fc39d52ec5..5062ab3275d 100644
--- a/sql/src/test/java/org/apache/druid/sql/calcite/SqlTestFrameworkConfig.java
+++ b/sql/src/test/java/org/apache/druid/sql/calcite/SqlTestFrameworkConfig.java
@@ -527,6 +527,7 @@ public class SqlTestFrameworkConfig
Set> availableSuppliers = componentSupplierClassCache.get(pkg);
for (Class extends QueryComponentSupplier> cl : availableSuppliers) {
if (cl.getSimpleName().equals(name)) {
+ System.out.println("cl = " + cl);
return cl;
}
}
diff --git a/sql/src/test/java/org/apache/druid/sql/calcite/util/SqlTestFramework.java b/sql/src/test/java/org/apache/druid/sql/calcite/util/SqlTestFramework.java
index 4374f1e86e2..b61697458ce 100644
--- a/sql/src/test/java/org/apache/druid/sql/calcite/util/SqlTestFramework.java
+++ b/sql/src/test/java/org/apache/druid/sql/calcite/util/SqlTestFramework.java
@@ -688,6 +688,7 @@ public class SqlTestFramework
this.injector = serviceInjector.build();
this.engine = builder.componentSupplier.createEngine(queryLifecycleFactory(), queryJsonMapper(), injector);
+ System.out.println("engine = " + this.engine);
componentSupplier.configureJsonMapper(queryJsonMapper());
componentSupplier.finalizeTestFramework(this);
}