diff --git a/pom.xml b/pom.xml
index 04377ca35d86..40051638767b 100644
--- a/pom.xml
+++ b/pom.xml
@@ -1262,6 +1262,12 @@
${hamcrest.version}
test
+
+ org.reflections
+ reflections
+ 0.9.12
+ test
+
pl.pragmatists
JUnitParams
diff --git a/processing/pom.xml b/processing/pom.xml
index 9abe06439e41..bc1365a6f138 100644
--- a/processing/pom.xml
+++ b/processing/pom.xml
@@ -380,7 +380,6 @@
org.reflections
reflections
- 0.9.12
test
diff --git a/sql/pom.xml b/sql/pom.xml
index a098c3d15bfb..d1d4e8afd8b9 100644
--- a/sql/pom.xml
+++ b/sql/pom.xml
@@ -262,6 +262,11 @@
jdbi
test
+
+ org.reflections
+ reflections
+ test
+
diff --git a/sql/src/main/java/org/apache/druid/sql/calcite/planner/CalciteRulesManager.java b/sql/src/main/java/org/apache/druid/sql/calcite/planner/CalciteRulesManager.java
index b15bb38fdcce..36279bcd8d17 100644
--- a/sql/src/main/java/org/apache/druid/sql/calcite/planner/CalciteRulesManager.java
+++ b/sql/src/main/java/org/apache/druid/sql/calcite/planner/CalciteRulesManager.java
@@ -248,20 +248,21 @@ public List programs(final PlannerContext plannerContext)
),
Programs.sequence(
druidPreProgram,
- buildBaseRuleSetProgram(plannerContext),
- new LoggingProgram("After baseRuleSet program", isDebug),
+ buildDecoupledLogicalOptimizationProgram(plannerContext),
+ new LoggingProgram("After DecoupledLogicalOptimizationProgram program", isDebug),
Programs.ofRules(logicalConventionRuleSet(plannerContext)),
new LoggingProgram("After logical volcano planner program", isDebug)
)
);
}
- private Program buildBaseRuleSetProgram(PlannerContext plannerContext)
+ private Program buildDecoupledLogicalOptimizationProgram(PlannerContext plannerContext)
{
final HepProgramBuilder builder = HepProgram.builder();
builder.addMatchLimit(CalciteRulesManager.HEP_DEFAULT_MATCH_LIMIT);
builder.addGroupBegin();
builder.addRuleCollection(baseRuleSet(plannerContext));
+ builder.addRuleInstance(CoreRules.UNION_MERGE);
builder.addGroupEnd();
return Programs.of(builder.build(), true, DefaultRelMetadataProvider.INSTANCE);
}
diff --git a/sql/src/main/java/org/apache/druid/sql/calcite/planner/DruidQueryGenerator.java b/sql/src/main/java/org/apache/druid/sql/calcite/planner/DruidQueryGenerator.java
deleted file mode 100644
index e9d6d62f72b3..000000000000
--- a/sql/src/main/java/org/apache/druid/sql/calcite/planner/DruidQueryGenerator.java
+++ /dev/null
@@ -1,354 +0,0 @@
-/*
- * 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.sql.calcite.planner;
-
-import com.google.common.collect.ImmutableList;
-import org.apache.calcite.plan.RelOptTable;
-import org.apache.calcite.rel.RelNode;
-import org.apache.calcite.rel.RelShuttleImpl;
-import org.apache.calcite.rel.core.Aggregate;
-import org.apache.calcite.rel.core.Filter;
-import org.apache.calcite.rel.core.Project;
-import org.apache.calcite.rel.core.Sort;
-import org.apache.calcite.rel.core.TableFunctionScan;
-import org.apache.calcite.rel.core.TableScan;
-import org.apache.calcite.rel.core.Window;
-import org.apache.calcite.rel.logical.LogicalAggregate;
-import org.apache.calcite.rel.logical.LogicalCorrelate;
-import org.apache.calcite.rel.logical.LogicalExchange;
-import org.apache.calcite.rel.logical.LogicalFilter;
-import org.apache.calcite.rel.logical.LogicalIntersect;
-import org.apache.calcite.rel.logical.LogicalJoin;
-import org.apache.calcite.rel.logical.LogicalMatch;
-import org.apache.calcite.rel.logical.LogicalMinus;
-import org.apache.calcite.rel.logical.LogicalProject;
-import org.apache.calcite.rel.logical.LogicalSort;
-import org.apache.calcite.rel.logical.LogicalUnion;
-import org.apache.calcite.rel.logical.LogicalValues;
-import org.apache.calcite.rex.RexLiteral;
-import org.apache.druid.java.util.common.ISE;
-import org.apache.druid.java.util.common.UOE;
-import org.apache.druid.query.InlineDataSource;
-import org.apache.druid.segment.column.RowSignature;
-import org.apache.druid.sql.calcite.rel.PartialDruidQuery;
-import org.apache.druid.sql.calcite.rel.logical.DruidTableScan;
-import org.apache.druid.sql.calcite.rule.DruidLogicalValuesRule;
-import org.apache.druid.sql.calcite.table.DruidTable;
-import org.apache.druid.sql.calcite.table.InlineTable;
-import org.apache.druid.sql.calcite.table.RowSignatures;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.stream.Collectors;
-
-
-/**
- * Converts a DAG of {@link org.apache.druid.sql.calcite.rel.logical.DruidLogicalNode} convention to a native
- * Druid query for execution. The convertion is done via a {@link org.apache.calcite.rel.RelShuttle} visitor
- * implementation.
- */
-public class DruidQueryGenerator extends RelShuttleImpl
-{
- private final List queryList = new ArrayList<>();
- private final List queryTables = new ArrayList<>();
- private final PlannerContext plannerContext;
- private PartialDruidQuery partialDruidQuery;
- private PartialDruidQuery.Stage currentStage = null;
- private DruidTable currentTable = null;
- private boolean isRoot = true;
-
- public DruidQueryGenerator(PlannerContext plannerContext)
- {
- this.plannerContext = plannerContext;
- }
-
- @Override
- public RelNode visit(TableScan scan)
- {
- if (!(scan instanceof DruidTableScan)) {
- throw new ISE("Planning hasn't converted logical table scan to druid convention");
- }
- DruidTableScan druidTableScan = (DruidTableScan) scan;
- isRoot = false;
- RelNode result = super.visit(scan);
- partialDruidQuery = PartialDruidQuery.create(scan);
- currentStage = PartialDruidQuery.Stage.SCAN;
- final RelOptTable table = scan.getTable();
- final DruidTable druidTable = table.unwrap(DruidTable.class);
- if (druidTable != null) {
- currentTable = druidTable;
- }
- if (druidTableScan.getProject() != null) {
- partialDruidQuery = partialDruidQuery.withSelectProject(druidTableScan.getProject());
- currentStage = PartialDruidQuery.Stage.SELECT_PROJECT;
- }
- return result;
- }
-
- @Override
- public RelNode visit(TableFunctionScan scan)
- {
- return null;
- }
-
- @Override
- public RelNode visit(LogicalValues values)
- {
- isRoot = false;
- RelNode result = super.visit(values);
- final List> tuples = values.getTuples();
- final List