calcite-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jh...@apache.org
Subject [5/9] incubator-calcite git commit: [CALCITE-693] Allow clients to control creation of RelOptCluster
Date Sat, 25 Apr 2015 23:44:51 GMT
[CALCITE-693] Allow clients to control creation of RelOptCluster


Project: http://git-wip-us.apache.org/repos/asf/incubator-calcite/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-calcite/commit/bf88476b
Tree: http://git-wip-us.apache.org/repos/asf/incubator-calcite/tree/bf88476b
Diff: http://git-wip-us.apache.org/repos/asf/incubator-calcite/diff/bf88476b

Branch: refs/heads/master
Commit: bf88476b04595f16037733901ed8256324bac187
Parents: 9da7bc8
Author: Julian Hyde <jhyde@apache.org>
Authored: Wed Apr 22 18:03:55 2015 -0700
Committer: Julian Hyde <jhyde@apache.org>
Committed: Wed Apr 22 18:03:55 2015 -0700

----------------------------------------------------------------------
 .../calcite/prepare/CalcitePrepareImpl.java     | 20 ++++++++-------
 .../org/apache/calcite/prepare/PlannerImpl.java | 19 +++++++++-----
 .../calcite/sql2rel/SqlToRelConverter.java      | 26 +++++++++++++++++---
 .../apache/calcite/test/SqlToRelTestBase.java   | 16 ++++++------
 4 files changed, 55 insertions(+), 26 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/bf88476b/core/src/main/java/org/apache/calcite/prepare/CalcitePrepareImpl.java
----------------------------------------------------------------------
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 71d38c4..0c04802 100644
--- a/core/src/main/java/org/apache/calcite/prepare/CalcitePrepareImpl.java
+++ b/core/src/main/java/org/apache/calcite/prepare/CalcitePrepareImpl.java
@@ -285,6 +285,13 @@ public class CalcitePrepareImpl implements CalcitePrepare {
     return SqlParser.configBuilder();
   }
 
+  /** Factory method for cluster. */
+  protected RelOptCluster createCluster(RelOptPlanner planner,
+      RexBuilder rexBuilder) {
+    final RelOptQuery query = new RelOptQuery(planner);
+    return query.createCluster(rexBuilder.getTypeFactory(), rexBuilder);
+  }
+
   /** Creates a collection of planner factories.
    *
    * <p>The collection must have at least one factory, and each factory must
@@ -732,9 +739,7 @@ public class CalcitePrepareImpl implements CalcitePrepare {
         createPlanner(prepareContext,
             action.getConfig().getContext(),
             action.getConfig().getCostFactory());
-    final RelOptQuery query = new RelOptQuery(planner);
-    final RelOptCluster cluster =
-        query.createCluster(rexBuilder.getTypeFactory(), rexBuilder);
+    final RelOptCluster cluster = createCluster(planner, rexBuilder);
     return action.apply(cluster, catalogReader,
         prepareContext.getRootSchema().plus(), statement);
   }
@@ -780,10 +785,7 @@ public class CalcitePrepareImpl implements CalcitePrepare {
       Class runtimeContextClass = Object.class;
       init(runtimeContextClass);
 
-      final RelOptQuery query = new RelOptQuery(planner);
-      final RelOptCluster cluster =
-          query.createCluster(
-              rexBuilder.getTypeFactory(), rexBuilder);
+      final RelOptCluster cluster = prepare.createCluster(planner, rexBuilder);
 
       RelNode rootRel =
           new LixToRelTranslator(cluster, CalcitePreparingStmt.this)
@@ -822,9 +824,9 @@ public class CalcitePrepareImpl implements CalcitePrepare {
     @Override protected SqlToRelConverter getSqlToRelConverter(
         SqlValidator validator,
         CatalogReader catalogReader) {
+      final RelOptCluster cluster = prepare.createCluster(planner, rexBuilder);
       SqlToRelConverter sqlToRelConverter =
-          new SqlToRelConverter(
-              this, validator, catalogReader, planner, rexBuilder,
+          new SqlToRelConverter(this, validator, catalogReader, cluster,
               StandardConvertletTable.INSTANCE);
       sqlToRelConverter.setTrimUnusedFields(true);
       return sqlToRelConverter;

http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/bf88476b/core/src/main/java/org/apache/calcite/prepare/PlannerImpl.java
----------------------------------------------------------------------
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 aac0c9a..c078f4e 100644
--- a/core/src/main/java/org/apache/calcite/prepare/PlannerImpl.java
+++ b/core/src/main/java/org/apache/calcite/prepare/PlannerImpl.java
@@ -20,6 +20,7 @@ import org.apache.calcite.adapter.java.JavaTypeFactory;
 import org.apache.calcite.jdbc.CalciteSchema;
 import org.apache.calcite.plan.RelOptCluster;
 import org.apache.calcite.plan.RelOptPlanner;
+import org.apache.calcite.plan.RelOptQuery;
 import org.apache.calcite.plan.RelOptSchema;
 import org.apache.calcite.plan.RelOptTable.ViewExpander;
 import org.apache.calcite.plan.RelTraitDef;
@@ -181,10 +182,12 @@ public class PlannerImpl implements Planner {
   public RelNode convert(SqlNode sql) throws RelConversionException {
     ensure(State.STATE_4_VALIDATED);
     assert validatedSqlNode != null;
+    final RexBuilder rexBuilder = createRexBuilder();
+    final RelOptQuery query = new RelOptQuery(planner);
+    final RelOptCluster cluster = query.createCluster(typeFactory, rexBuilder);
     final SqlToRelConverter sqlToRelConverter =
-        new SqlToRelConverter(
-            new ViewExpanderImpl(), validator, createCatalogReader(), planner,
-            createRexBuilder(), convertletTable);
+        new SqlToRelConverter(new ViewExpanderImpl(), validator,
+            createCatalogReader(), cluster, convertletTable);
     sqlToRelConverter.setTrimUnusedFields(false);
     sqlToRelConverter.enableTableAccessConversion(false);
     rel = sqlToRelConverter.convertQuery(validatedSqlNode, false, true);
@@ -214,9 +217,13 @@ public class PlannerImpl implements Planner {
       validator.setIdentifierExpansion(true);
       final SqlNode validatedSqlNode = validator.validate(sqlNode);
 
-      final SqlToRelConverter sqlToRelConverter = new SqlToRelConverter(
-          null, validator, catalogReader, planner,
-          createRexBuilder(), convertletTable);
+      final RexBuilder rexBuilder = createRexBuilder();
+      final RelOptQuery query = new RelOptQuery(planner);
+      final RelOptCluster cluster =
+          query.createCluster(typeFactory, rexBuilder);
+      final SqlToRelConverter sqlToRelConverter =
+          new SqlToRelConverter(null, validator, catalogReader, cluster,
+              convertletTable);
       sqlToRelConverter.setTrimUnusedFields(false);
 
       return sqlToRelConverter.convertQuery(validatedSqlNode, true, false);

http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/bf88476b/core/src/main/java/org/apache/calcite/sql2rel/SqlToRelConverter.java
----------------------------------------------------------------------
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 4247083..31a02cc 100644
--- a/core/src/main/java/org/apache/calcite/sql2rel/SqlToRelConverter.java
+++ b/core/src/main/java/org/apache/calcite/sql2rel/SqlToRelConverter.java
@@ -142,6 +142,7 @@ import org.apache.calcite.util.mapping.Mappings;
 import org.apache.calcite.util.trace.CalciteTrace;
 
 import com.google.common.base.Function;
+import com.google.common.base.Preconditions;
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.ImmutableSet;
 import com.google.common.collect.Iterables;
@@ -247,6 +248,7 @@ public class SqlToRelConverter {
    * @param rexBuilder      Rex builder
    * @param convertletTable Expression converter
    */
+  @Deprecated // will be removed before 2.0
   public SqlToRelConverter(
       RelOptTable.ViewExpander viewExpander,
       SqlValidator validator,
@@ -254,6 +256,17 @@ public class SqlToRelConverter {
       RelOptPlanner planner,
       RexBuilder rexBuilder,
       SqlRexConvertletTable convertletTable) {
+    this(viewExpander, validator, catalogReader,
+        createCluster(rexBuilder, planner), convertletTable);
+  }
+
+  /* Creates a converter. */
+  public SqlToRelConverter(
+      RelOptTable.ViewExpander viewExpander,
+      SqlValidator validator,
+      Prepare.CatalogReader catalogReader,
+      RelOptCluster cluster,
+      SqlRexConvertletTable convertletTable) {
     this.viewExpander = viewExpander;
     this.opTab =
         (validator
@@ -263,10 +276,9 @@ public class SqlToRelConverter {
     this.catalogReader = catalogReader;
     this.defaultValueFactory = new NullDefaultValueFactory();
     this.subqueryConverter = new NoOpSubqueryConverter();
-    this.rexBuilder = rexBuilder;
+    this.rexBuilder = cluster.getRexBuilder();
     this.typeFactory = rexBuilder.getTypeFactory();
-    RelOptQuery query = new RelOptQuery(planner);
-    this.cluster = query.createCluster(typeFactory, rexBuilder);
+    this.cluster = Preconditions.checkNotNull(cluster);
     this.shouldConvertTableAccess = true;
     this.exprConverter =
         new SqlNodeToRexConverterImpl(convertletTable);
@@ -279,6 +291,14 @@ public class SqlToRelConverter {
 
   //~ Methods ----------------------------------------------------------------
 
+  // helper for constructor
+  private static RelOptCluster createCluster(RexBuilder rexBuilder,
+      RelOptPlanner planner) {
+    final RelDataTypeFactory typeFactory = rexBuilder.getTypeFactory();
+    RelOptQuery query = new RelOptQuery(planner);
+    return query.createCluster(typeFactory, rexBuilder);
+  }
+
   /**
    * @return the RelOptCluster in use.
    */

http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/bf88476b/core/src/test/java/org/apache/calcite/test/SqlToRelTestBase.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/calcite/test/SqlToRelTestBase.java b/core/src/test/java/org/apache/calcite/test/SqlToRelTestBase.java
index 5529a57..64b19ec 100644
--- a/core/src/test/java/org/apache/calcite/test/SqlToRelTestBase.java
+++ b/core/src/test/java/org/apache/calcite/test/SqlToRelTestBase.java
@@ -17,7 +17,9 @@
 package org.apache.calcite.test;
 
 import org.apache.calcite.linq4j.tree.Expression;
+import org.apache.calcite.plan.RelOptCluster;
 import org.apache.calcite.plan.RelOptPlanner;
+import org.apache.calcite.plan.RelOptQuery;
 import org.apache.calcite.plan.RelOptSchema;
 import org.apache.calcite.plan.RelOptSchemaWithSampling;
 import org.apache.calcite.plan.RelOptTable;
@@ -503,14 +505,12 @@ public abstract class SqlToRelTestBase {
         final SqlValidator validator,
         final Prepare.CatalogReader catalogReader,
         final RelDataTypeFactory typeFactory) {
-      return
-          new SqlToRelConverter(
-              null,
-              validator,
-              catalogReader,
-              getPlanner(),
-              new RexBuilder(typeFactory),
-              StandardConvertletTable.INSTANCE);
+      final RexBuilder rexBuilder = new RexBuilder(typeFactory);
+      final RelOptQuery query = new RelOptQuery(getPlanner());
+      final RelOptCluster cluster =
+          query.createCluster(typeFactory, rexBuilder);
+      return new SqlToRelConverter(null, validator, catalogReader, cluster,
+          StandardConvertletTable.INSTANCE);
     }
 
     protected final RelDataTypeFactory getTypeFactory() {


Mime
View raw message