This is an automated email from the ASF dual-hosted git repository.

danny0405 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/calcite.git


The following commit(s) were added to refs/heads/master by this push:
     new c395c10  [CALCITE-3801] Deprecate 
SqlToRelConverter.Config#isConvertTableAccess
c395c10 is described below

commit c395c10b6efa781ecd33f49c6322d60579f78ac5
Author: yuzhao.cyz <[email protected]>
AuthorDate: Mon Feb 17 13:04:42 2020 +0800

    [CALCITE-3801] Deprecate SqlToRelConverter.Config#isConvertTableAccess
    
    Because of CALCITE-3769, this config option is actually useless now,
    we always return logical rel with method RelOptTable#toRel.
    
    Update the CalcitePrepareImpl to use VolcanoPlanner when analyzing the
    view because it can handle the traits correctly.
---
 .../apache/calcite/prepare/CalcitePrepareImpl.java |  8 ++-----
 .../org/apache/calcite/prepare/PlannerImpl.java    |  2 --
 .../apache/calcite/sql2rel/SqlToRelConverter.java  | 28 +++++++++-------------
 .../rel/logical/ToLogicalConverterTest.java        |  1 -
 .../calcite/rel/rel2sql/RelToSqlConverterTest.java |  2 --
 5 files changed, 13 insertions(+), 28 deletions(-)

diff --git 
a/core/src/main/java/org/apache/calcite/prepare/CalcitePrepareImpl.java 
b/core/src/main/java/org/apache/calcite/prepare/CalcitePrepareImpl.java
index 20d50cb..3118958 100644
--- a/core/src/main/java/org/apache/calcite/prepare/CalcitePrepareImpl.java
+++ b/core/src/main/java/org/apache/calcite/prepare/CalcitePrepareImpl.java
@@ -57,8 +57,6 @@ import org.apache.calcite.plan.RelOptPlanner;
 import org.apache.calcite.plan.RelOptRule;
 import org.apache.calcite.plan.RelOptTable;
 import org.apache.calcite.plan.RelOptUtil;
-import org.apache.calcite.plan.hep.HepPlanner;
-import org.apache.calcite.plan.hep.HepProgramBuilder;
 import org.apache.calcite.plan.volcano.VolcanoPlanner;
 import org.apache.calcite.rel.RelCollation;
 import org.apache.calcite.rel.RelCollationTraitDef;
@@ -214,14 +212,12 @@ public class CalcitePrepareImpl implements CalcitePrepare 
{
     final Convention resultConvention =
         enableBindable ? BindableConvention.INSTANCE
             : EnumerableConvention.INSTANCE;
-    final HepPlanner planner = new HepPlanner(new HepProgramBuilder().build());
+    // Use the Volcano because it can handle the traits.
+    final VolcanoPlanner planner = new VolcanoPlanner();
     planner.addRelTraitDef(ConventionTraitDef.INSTANCE);
 
     final SqlToRelConverter.ConfigBuilder configBuilder =
         SqlToRelConverter.configBuilder().withTrimUnusedFields(true);
-    if (analyze) {
-      configBuilder.withConvertTableAccess(false);
-    }
 
     final CalcitePreparingStmt preparingStmt =
         new CalcitePreparingStmt(this, context, catalogReader, typeFactory,
diff --git a/core/src/main/java/org/apache/calcite/prepare/PlannerImpl.java 
b/core/src/main/java/org/apache/calcite/prepare/PlannerImpl.java
index d884605..e76bb66 100644
--- a/core/src/main/java/org/apache/calcite/prepare/PlannerImpl.java
+++ b/core/src/main/java/org/apache/calcite/prepare/PlannerImpl.java
@@ -247,7 +247,6 @@ public class PlannerImpl implements Planner, ViewExpander {
     final SqlToRelConverter.Config config = SqlToRelConverter.configBuilder()
         .withConfig(sqlToRelConverterConfig)
         .withTrimUnusedFields(false)
-        .withConvertTableAccess(false)
         .build();
     final SqlToRelConverter sqlToRelConverter =
         new SqlToRelConverter(this, validator,
@@ -300,7 +299,6 @@ public class PlannerImpl implements Planner, ViewExpander {
         .configBuilder()
         .withConfig(sqlToRelConverterConfig)
         .withTrimUnusedFields(false)
-        .withConvertTableAccess(false)
         .build();
     final SqlToRelConverter sqlToRelConverter =
         new SqlToRelConverter(this, validator,
diff --git 
a/core/src/main/java/org/apache/calcite/sql2rel/SqlToRelConverter.java 
b/core/src/main/java/org/apache/calcite/sql2rel/SqlToRelConverter.java
index 84b8944..783e981 100644
--- a/core/src/main/java/org/apache/calcite/sql2rel/SqlToRelConverter.java
+++ b/core/src/main/java/org/apache/calcite/sql2rel/SqlToRelConverter.java
@@ -67,7 +67,6 @@ import org.apache.calcite.rel.logical.LogicalTableModify;
 import org.apache.calcite.rel.logical.LogicalTableScan;
 import org.apache.calcite.rel.logical.LogicalUnion;
 import org.apache.calcite.rel.logical.LogicalValues;
-import org.apache.calcite.rel.metadata.JaninoRelMetadataProvider;
 import org.apache.calcite.rel.metadata.RelColumnMapping;
 import org.apache.calcite.rel.metadata.RelMetadataQuery;
 import org.apache.calcite.rel.stream.Delta;
@@ -566,8 +565,6 @@ public class SqlToRelConverter {
       query = validator.validate(query);
     }
 
-    RelMetadataQuery.THREAD_PROVIDERS.set(
-        JaninoRelMetadataProvider.of(cluster.getMetadataProvider()));
     RelNode result = convertQueryRecursive(query, top, null).rel;
     if (top) {
       if (isStream(query)) {
@@ -2415,11 +2412,7 @@ public class SqlToRelConverter {
     final List<RelHint> hints = hintStrategies.apply(
         SqlUtil.getRelHint(hintStrategies, tableHints),
         LogicalTableScan.create(cluster, table, ImmutableList.of()));
-    if (config.isConvertTableAccess()) {
-      tableRel = toRel(table, hints);
-    } else {
-      tableRel = LogicalTableScan.create(cluster, table, hints);
-    }
+    tableRel = toRel(table, hints);
     bb.setRoot(tableRel, true);
     if (usedDataset[0]) {
       bb.setDataset(datasetName);
@@ -5792,7 +5785,12 @@ public class SqlToRelConverter {
      * optimizer doesn't like leaf rels to have {@link Convention#NONE}.
      * However, if we are doing further conversion passes (e.g.
      * {@link RelStructuredTypeFlattener}), then we may need to defer
-     * conversion. */
+     * conversion.
+     *
+     * @deprecated Table access references are always converted to
+     * logical relational expressions during sql-to-rel conversion.
+     * */
+    @Deprecated // to be removed before 1.23
     boolean isConvertTableAccess();
 
     /** Returns the {@code decorrelationEnabled} option. Controls whether to
@@ -5840,7 +5838,6 @@ public class SqlToRelConverter {
 
   /** Builder for a {@link Config}. */
   public static class ConfigBuilder {
-    private boolean convertTableAccess = true;
     private boolean decorrelationEnabled = true;
     private boolean trimUnusedFields = false;
     private boolean createValuesRel = true;
@@ -5854,7 +5851,6 @@ public class SqlToRelConverter {
 
     /** Sets configuration identical to a given {@link Config}. */
     public ConfigBuilder withConfig(Config config) {
-      this.convertTableAccess = config.isConvertTableAccess();
       this.decorrelationEnabled = config.isDecorrelationEnabled();
       this.trimUnusedFields = config.isTrimUnusedFields();
       this.createValuesRel = config.isCreateValuesRel();
@@ -5866,8 +5862,8 @@ public class SqlToRelConverter {
       return this;
     }
 
+    @Deprecated // to be removed before 1.23
     public ConfigBuilder withConvertTableAccess(boolean convertTableAccess) {
-      this.convertTableAccess = convertTableAccess;
       return this;
     }
 
@@ -5920,7 +5916,7 @@ public class SqlToRelConverter {
 
     /** Builds a {@link Config}. */
     public Config build() {
-      return new ConfigImpl(convertTableAccess, decorrelationEnabled,
+      return new ConfigImpl(decorrelationEnabled,
           trimUnusedFields, createValuesRel, explain, expand,
           inSubQueryThreshold, relBuilderFactory, hintStrategyTable);
     }
@@ -5929,7 +5925,6 @@ public class SqlToRelConverter {
   /** Implementation of {@link Config}.
    * Called by builder; all values are in private final fields. */
   private static class ConfigImpl implements Config {
-    private final boolean convertTableAccess;
     private final boolean decorrelationEnabled;
     private final boolean trimUnusedFields;
     private final boolean createValuesRel;
@@ -5939,12 +5934,11 @@ public class SqlToRelConverter {
     private final RelBuilderFactory relBuilderFactory;
     private final HintStrategyTable hintStrategyTable;
 
-    private ConfigImpl(boolean convertTableAccess, boolean 
decorrelationEnabled,
+    private ConfigImpl(boolean decorrelationEnabled,
         boolean trimUnusedFields, boolean createValuesRel, boolean explain,
         boolean expand, int inSubQueryThreshold,
         RelBuilderFactory relBuilderFactory,
         HintStrategyTable hintStrategyTable) {
-      this.convertTableAccess = convertTableAccess;
       this.decorrelationEnabled = decorrelationEnabled;
       this.trimUnusedFields = trimUnusedFields;
       this.createValuesRel = createValuesRel;
@@ -5956,7 +5950,7 @@ public class SqlToRelConverter {
     }
 
     public boolean isConvertTableAccess() {
-      return convertTableAccess;
+      return true;
     }
 
     public boolean isDecorrelationEnabled() {
diff --git 
a/core/src/test/java/org/apache/calcite/rel/logical/ToLogicalConverterTest.java 
b/core/src/test/java/org/apache/calcite/rel/logical/ToLogicalConverterTest.java
index 42a647c..5b4c05a 100644
--- 
a/core/src/test/java/org/apache/calcite/rel/logical/ToLogicalConverterTest.java
+++ 
b/core/src/test/java/org/apache/calcite/rel/logical/ToLogicalConverterTest.java
@@ -78,7 +78,6 @@ public class ToLogicalConverterTest {
   private static final SqlToRelConverter.Config DEFAULT_REL_CONFIG =
       SqlToRelConverter.configBuilder()
           .withTrimUnusedFields(false)
-          .withConvertTableAccess(false)
           .build();
 
   private static FrameworkConfig frameworkConfig() {
diff --git 
a/core/src/test/java/org/apache/calcite/rel/rel2sql/RelToSqlConverterTest.java 
b/core/src/test/java/org/apache/calcite/rel/rel2sql/RelToSqlConverterTest.java
index 507a459..c06f7ea 100644
--- 
a/core/src/test/java/org/apache/calcite/rel/rel2sql/RelToSqlConverterTest.java
+++ 
b/core/src/test/java/org/apache/calcite/rel/rel2sql/RelToSqlConverterTest.java
@@ -94,13 +94,11 @@ public class RelToSqlConverterTest {
   static final SqlToRelConverter.Config DEFAULT_REL_CONFIG =
       SqlToRelConverter.configBuilder()
           .withTrimUnusedFields(false)
-          .withConvertTableAccess(false)
           .build();
 
   static final SqlToRelConverter.Config NO_EXPAND_CONFIG =
       SqlToRelConverter.configBuilder()
           .withTrimUnusedFields(false)
-          .withConvertTableAccess(false)
           .withExpand(false)
           .build();
 

Reply via email to