You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@calcite.apache.org by jh...@apache.org on 2014/11/14 22:32:47 UTC
[39/58] [abbrv] [partial] incubator-calcite git commit: [CALCITE-306]
Standardize code style for "import package.*; "
http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/a0ba73cd/core/src/main/java/org/apache/calcite/plan/volcano/package-info.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/plan/volcano/package-info.java b/core/src/main/java/org/apache/calcite/plan/volcano/package-info.java
index 0e6a0fc..482a3ee 100644
--- a/core/src/main/java/org/apache/calcite/plan/volcano/package-info.java
+++ b/core/src/main/java/org/apache/calcite/plan/volcano/package-info.java
@@ -22,18 +22,18 @@
*
* <p>A <dfn>planner</dfn> (also known as an <dfn>optimizer</dfn>) finds the
* most efficient implementation of a
- * {@link org.eigenbase.rel.RelNode relational expression}.</p>
+ * {@link org.apache.calcite.rel.RelNode relational expression}.</p>
*
- * <p>Interface {@link org.eigenbase.relopt.RelOptPlanner} defines a planner,
- * and class {@link org.eigenbase.relopt.volcano.VolcanoPlanner} is an
+ * <p>Interface {@link org.apache.calcite.plan.RelOptPlanner} defines a planner,
+ * and class {@link org.apache.calcite.plan.volcano.VolcanoPlanner} is an
* implementation which uses a dynamic programming technique. It is based upon
* the Volcano optimizer [<a href="#graefe93">1</a>].</p>
*
- * <p>Interface {@link org.eigenbase.relopt.RelOptCost} defines a cost
- * model; class {@link org.eigenbase.relopt.volcano.VolcanoCost} is
+ * <p>Interface {@link org.apache.calcite.plan.RelOptCost} defines a cost
+ * model; class {@link org.apache.calcite.plan.volcano.VolcanoCost} is
* the implementation for a <code>VolcanoPlanner</code>.</p>
*
- * <p>A {@link org.eigenbase.relopt.volcano.RelSet} is a set of equivalent
+ * <p>A {@link org.apache.calcite.plan.volcano.RelSet} is a set of equivalent
* relational expressions. They are equivalent because they will produce the
* same result for any set of input data. It is an equivalence class: two
* expressions are in the same set if and only if they are in the same
@@ -42,25 +42,25 @@
* <p>One of the unique features of the optimizer is that expressions can take
* on a variety of physical traits. Each relational expression has a set of
* traits. Each trait is described by an implementation of
- * {@link org.eigenbase.relopt.RelTraitDef}. Manifestations of the trait
- * implement {@link org.eigenbase.relopt.RelTrait}. The most common example of a
- * trait is calling convention: the protocol used to receive and transmit
- * data. {@link org.eigenbase.relopt.ConventionTraitDef} defines the trait and
- * {@link org.eigenbase.relopt.Convention} enumerates the protocols. Every
- * relational expression has a single calling convention by which it returns its
- * results. Some examples:</p>
+ * {@link org.apache.calcite.plan.RelTraitDef}. Manifestations of the trait
+ * implement {@link org.apache.calcite.plan.RelTrait}. The most common example
+ * of a trait is calling convention: the protocol used to receive and transmit
+ * data. {@link org.apache.calcite.plan.ConventionTraitDef} defines the trait
+ * and {@link org.apache.calcite.plan.Convention} enumerates the
+ * protocols. Every relational expression has a single calling convention by
+ * which it returns its results. Some examples:</p>
*
* <ul>
- * <li>{@link net.hydromatic.optiq.impl.jdbc.JdbcConvention} is a fairly
+ * <li>{@link org.apache.calcite.adapter.jdbc.JdbcConvention} is a fairly
* conventional convention; the results are rows from a
* {@link java.sql.ResultSet JDBC result set}.
* </li>
- * <li>{@link org.eigenbase.relopt.Convention#NONE} means that a
+ * <li>{@link org.apache.calcite.plan.Convention#NONE} means that a
* relational
* expression cannot be implemented; typically there are rules which can
* transform it to equivalent, implementable expressions.
* </li>
- * <li>{@link net.hydromatic.optiq.rules.java.EnumerableConvention}
+ * <li>{@link org.apache.calcite.adapter.enumerable.EnumerableConvention}
* implements the expression by
* generating Java code. The code places the current row in a Java
* variable, then
@@ -80,41 +80,40 @@
*
* <p>New traits are added to the planner in one of two ways:</p>
* <ol>
- * <li>If the new trait is integral to Calcite, then each and every
- * implementation of {@link org.eigenbase.rel.RelNode} should include
- * its manifestation of the trait as part of the
- * {@link org.eigenbase.relopt.RelTraitSet} passed to
- * {@link org.eigenbase.rel.AbstractRelNode}'s constructor. It may be
- * useful to provide alternate <code>AbstractRelNode</code> constructors
- * if most relational expressions use a single manifestation of the
- * trait.</li>
- *
- * <li>If the new trait describes some aspect of a Farrago extension, then
- * the RelNodes passed to
- * {@link org.eigenbase.relopt.volcano.VolcanoPlanner#setRoot(org.eigenbase.rel.RelNode)}
- * should have their trait sets expanded before the
- * <code>setRoot(RelNode)</code> call.</li>
+ * <li>If the new trait is integral to Calcite, then each and every
+ * implementation of {@link org.apache.calcite.rel.RelNode} should include
+ * its manifestation of the trait as part of the
+ * {@link org.apache.calcite.plan.RelTraitSet} passed to
+ * {@link org.apache.calcite.rel.AbstractRelNode}'s constructor. It may be
+ * useful to provide alternate <code>AbstractRelNode</code> constructors
+ * if most relational expressions use a single manifestation of the
+ * trait.</li>
+ *
+ * <li>If the new trait describes some aspect of a Farrago extension, then
+ * the RelNodes passed to
+ * {@link org.apache.calcite.plan.volcano.VolcanoPlanner#setRoot(org.apache.calcite.rel.RelNode)}
+ * should have their trait sets expanded before the
+ * <code>setRoot(RelNode)</code> call.</li>
*
* </ol>
*
- * <p>The second trait extension mechanism requires that implementations of {@link
- * org.eigenbase.rel.AbstractRelNode#clone()} must not assume the type and
- * quantity of traits in
- * their trait set. In either case, the new <code>RelTraitDef</code>
- * implementation must be
- * {@link org.eigenbase.relopt.volcano.VolcanoPlanner#addRelTraitDef(org.eigenbase.relopt.RelTraitDef)}
- * registered with the planner.</p>
+ * <p>The second trait extension mechanism requires that implementations of
+ * {@link org.apache.calcite.rel.AbstractRelNode#clone()} must not assume the
+ * type and quantity of traits in their trait set. In either case, the new
+ * <code>RelTraitDef</code> implementation must be
+ * {@link org.apache.calcite.plan.volcano.VolcanoPlanner#addRelTraitDef(org.apache.calcite.plan.RelTraitDef)}
+ * registered with the planner.</p>
*
- * <p>A {@link org.eigenbase.relopt.volcano.RelSubset} is a subset of a <code>RelSet</code>
- * containing expressions which are equivalent and which have the same
- * <code>Convention</code>. Like <code>RelSet</code>, it is an equivalence
- * class.</p>
+ * <p>A {@link org.apache.calcite.plan.volcano.RelSubset} is a subset of a
+ * <code>RelSet</code> containing expressions which are equivalent and which
+ * have the same <code>Convention</code>. Like <code>RelSet</code>, it is an
+ * equivalence class.</p>
*
* <h2>Related packages</h2>
* <ul>
- * <li>{@code <a href="../rel/package-summary.html">org.eigenbase.rel</a>}
- * defines {@link org.eigenbase.rel.RelNode relational expressions}.
- * </li>
+ * <li>{@code <a href="../rel/package-summary.html">org.apache.calcite.rel</a>}
+ * defines {@link org.apache.calcite.rel.RelNode relational expressions}.
+ * </li>
* </ul>
*
* <h2>Details</h2>
@@ -269,6 +268,6 @@
* McKenna
* (1993)</a>.</p>
*/
-package org.eigenbase.relopt.volcano;
+package org.apache.calcite.plan.volcano;
// End package-info.java
http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/a0ba73cd/core/src/main/java/org/apache/calcite/prepare/CalciteCatalogReader.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/prepare/CalciteCatalogReader.java b/core/src/main/java/org/apache/calcite/prepare/CalciteCatalogReader.java
index a000b3a..0f4b4f5 100644
--- a/core/src/main/java/org/apache/calcite/prepare/CalciteCatalogReader.java
+++ b/core/src/main/java/org/apache/calcite/prepare/CalciteCatalogReader.java
@@ -14,40 +14,69 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package net.hydromatic.optiq.prepare;
+package org.apache.calcite.prepare;
-import net.hydromatic.optiq.*;
-import net.hydromatic.optiq.Function;
-import net.hydromatic.optiq.Table;
-import net.hydromatic.optiq.impl.java.JavaTypeFactory;
-import net.hydromatic.optiq.jdbc.OptiqSchema;
+import org.apache.calcite.adapter.java.JavaTypeFactory;
+import org.apache.calcite.jdbc.CalciteSchema;
+import org.apache.calcite.plan.RelOptPlanner;
+import org.apache.calcite.rel.type.RelDataType;
+import org.apache.calcite.rel.type.RelDataTypeFactory;
+import org.apache.calcite.rel.type.RelDataTypeFactoryImpl;
+import org.apache.calcite.rel.type.RelDataTypeField;
+import org.apache.calcite.schema.AggregateFunction;
+import org.apache.calcite.schema.Function;
+import org.apache.calcite.schema.FunctionParameter;
+import org.apache.calcite.schema.ScalarFunction;
+import org.apache.calcite.schema.Schemas;
+import org.apache.calcite.schema.Table;
+import org.apache.calcite.schema.TableFunction;
+import org.apache.calcite.schema.TableMacro;
+import org.apache.calcite.sql.SqlFunctionCategory;
+import org.apache.calcite.sql.SqlIdentifier;
+import org.apache.calcite.sql.SqlOperator;
+import org.apache.calcite.sql.SqlOperatorTable;
+import org.apache.calcite.sql.SqlSyntax;
+import org.apache.calcite.sql.type.InferTypes;
+import org.apache.calcite.sql.type.OperandTypes;
+import org.apache.calcite.sql.type.ReturnTypes;
+import org.apache.calcite.sql.type.SqlTypeFamily;
+import org.apache.calcite.sql.type.SqlTypeName;
+import org.apache.calcite.sql.validate.SqlMoniker;
+import org.apache.calcite.sql.validate.SqlMonikerImpl;
+import org.apache.calcite.sql.validate.SqlMonikerType;
+import org.apache.calcite.sql.validate.SqlUserDefinedAggFunction;
+import org.apache.calcite.sql.validate.SqlUserDefinedFunction;
+import org.apache.calcite.sql.validate.SqlUserDefinedTableFunction;
+import org.apache.calcite.sql.validate.SqlUserDefinedTableMacro;
+import org.apache.calcite.sql.validate.SqlValidatorUtil;
+import org.apache.calcite.util.Pair;
+import org.apache.calcite.util.Util;
-import org.eigenbase.relopt.RelOptPlanner;
-import org.eigenbase.reltype.*;
-import org.eigenbase.sql.*;
-import org.eigenbase.sql.type.*;
-import org.eigenbase.sql.validate.*;
-import org.eigenbase.util.Pair;
-import org.eigenbase.util.Util;
+import com.google.common.collect.Collections2;
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.Iterables;
+import com.google.common.collect.Lists;
-import com.google.common.collect.*;
-
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+import java.util.NavigableSet;
/**
- * Implementation of {@link net.hydromatic.optiq.prepare.Prepare.CatalogReader}
- * and also {@link org.eigenbase.sql.SqlOperatorTable} based on tables and
+ * Implementation of {@link org.apache.calcite.prepare.Prepare.CatalogReader}
+ * and also {@link org.apache.calcite.sql.SqlOperatorTable} based on tables and
* functions defined schemas.
*/
-public class OptiqCatalogReader implements Prepare.CatalogReader,
+public class CalciteCatalogReader implements Prepare.CatalogReader,
SqlOperatorTable {
- final OptiqSchema rootSchema;
+ final CalciteSchema rootSchema;
final JavaTypeFactory typeFactory;
private final List<String> defaultSchema;
private final boolean caseSensitive;
- public OptiqCatalogReader(
- OptiqSchema rootSchema,
+ public CalciteCatalogReader(
+ CalciteSchema rootSchema,
boolean caseSensitive,
List<String> defaultSchema,
JavaTypeFactory typeFactory) {
@@ -59,8 +88,8 @@ public class OptiqCatalogReader implements Prepare.CatalogReader,
this.typeFactory = typeFactory;
}
- public OptiqCatalogReader withSchemaPath(List<String> schemaPath) {
- return new OptiqCatalogReader(rootSchema, caseSensitive, schemaPath,
+ public CalciteCatalogReader withSchemaPath(List<String> schemaPath) {
+ return new CalciteCatalogReader(rootSchema, caseSensitive, schemaPath,
typeFactory);
}
@@ -78,7 +107,7 @@ public class OptiqCatalogReader implements Prepare.CatalogReader,
private RelOptTableImpl getTableFrom(List<String> names,
List<String> schemaNames) {
- OptiqSchema schema =
+ CalciteSchema schema =
getSchema(Iterables.concat(schemaNames, Util.skipLast(names)));
if (schema == null) {
return null;
@@ -104,7 +133,7 @@ public class OptiqCatalogReader implements Prepare.CatalogReader,
// If name is qualified, ignore path.
schemaNameList = ImmutableList.of(ImmutableList.<String>of());
} else {
- OptiqSchema schema = getSchema(defaultSchema);
+ CalciteSchema schema = getSchema(defaultSchema);
if (schema == null) {
schemaNameList = ImmutableList.of();
} else {
@@ -112,7 +141,7 @@ public class OptiqCatalogReader implements Prepare.CatalogReader,
}
}
for (List<String> schemaNames : schemaNameList) {
- OptiqSchema schema =
+ CalciteSchema schema =
getSchema(Iterables.concat(schemaNames, Util.skipLast(names)));
if (schema != null) {
final String name = Util.last(names);
@@ -122,8 +151,8 @@ public class OptiqCatalogReader implements Prepare.CatalogReader,
return functions2;
}
- private OptiqSchema getSchema(Iterable<String> schemaNames) {
- OptiqSchema schema = rootSchema;
+ private CalciteSchema getSchema(Iterable<String> schemaNames) {
+ CalciteSchema schema = rootSchema;
for (String schemaName : schemaNames) {
schema = schema.getSubSchema(schemaName, caseSensitive);
if (schema == null) {
@@ -138,12 +167,12 @@ public class OptiqCatalogReader implements Prepare.CatalogReader,
}
public List<SqlMoniker> getAllSchemaObjectNames(List<String> names) {
- final OptiqSchema schema = getSchema(names);
+ final CalciteSchema schema = getSchema(names);
if (schema == null) {
return ImmutableList.of();
}
final List<SqlMoniker> result = new ArrayList<SqlMoniker>();
- final Map<String, OptiqSchema> schemaMap = schema.getSubSchemaMap();
+ final Map<String, CalciteSchema> schemaMap = schema.getSubSchemaMap();
for (String subSchema : schemaMap.keySet()) {
result.add(
@@ -271,4 +300,4 @@ public class OptiqCatalogReader implements Prepare.CatalogReader,
}
}
-// End OptiqCatalogReader.java
+// End CalciteCatalogReader.java
http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/a0ba73cd/core/src/main/java/org/apache/calcite/prepare/CalciteMaterializer.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/prepare/CalciteMaterializer.java b/core/src/main/java/org/apache/calcite/prepare/CalciteMaterializer.java
index b089432..118214e 100644
--- a/core/src/main/java/org/apache/calcite/prepare/CalciteMaterializer.java
+++ b/core/src/main/java/org/apache/calcite/prepare/CalciteMaterializer.java
@@ -14,33 +14,49 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package net.hydromatic.optiq.prepare;
-
-import net.hydromatic.optiq.*;
-import net.hydromatic.optiq.impl.StarTable;
-import net.hydromatic.optiq.jdbc.OptiqPrepare;
-import net.hydromatic.optiq.jdbc.OptiqSchema;
-import net.hydromatic.optiq.rules.java.EnumerableConvention;
-import net.hydromatic.optiq.rules.java.EnumerableRel;
-
-import org.eigenbase.rel.*;
-import org.eigenbase.relopt.*;
-import org.eigenbase.sql.SqlNode;
-import org.eigenbase.sql.parser.SqlParseException;
-import org.eigenbase.sql.parser.SqlParser;
-import org.eigenbase.sql2rel.SqlToRelConverter;
+package org.apache.calcite.prepare;
+
+import org.apache.calcite.adapter.enumerable.EnumerableConvention;
+import org.apache.calcite.adapter.enumerable.EnumerableRel;
+import org.apache.calcite.jdbc.CalcitePrepare;
+import org.apache.calcite.jdbc.CalciteSchema;
+import org.apache.calcite.plan.RelOptMaterialization;
+import org.apache.calcite.plan.RelOptPlanner;
+import org.apache.calcite.plan.RelOptTable;
+import org.apache.calcite.plan.RelOptUtil;
+import org.apache.calcite.rel.RelNode;
+import org.apache.calcite.rel.RelShuttle;
+import org.apache.calcite.rel.core.Correlator;
+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.logical.LogicalAggregate;
+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.LogicalMinus;
+import org.apache.calcite.rel.logical.LogicalProject;
+import org.apache.calcite.rel.logical.LogicalUnion;
+import org.apache.calcite.rel.logical.LogicalValues;
+import org.apache.calcite.schema.Schemas;
+import org.apache.calcite.schema.Table;
+import org.apache.calcite.schema.impl.StarTable;
+import org.apache.calcite.sql.SqlNode;
+import org.apache.calcite.sql.parser.SqlParseException;
+import org.apache.calcite.sql.parser.SqlParser;
+import org.apache.calcite.sql2rel.SqlToRelConverter;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;
-import java.util.*;
+import java.util.List;
/**
* Context for populating a {@link Materialization}.
*/
-class OptiqMaterializer extends OptiqPrepareImpl.OptiqPreparingStmt {
- public OptiqMaterializer(OptiqPrepare.Context context,
- CatalogReader catalogReader, OptiqSchema schema,
+class CalciteMaterializer extends CalcitePrepareImpl.CalcitePreparingStmt {
+ public CalciteMaterializer(CalcitePrepare.Context context,
+ CatalogReader catalogReader, CalciteSchema schema,
RelOptPlanner planner) {
super(context, catalogReader, catalogReader.getTypeFactory(), schema,
EnumerableRel.Prefer.ANY, planner, EnumerableConvention.INSTANCE);
@@ -81,11 +97,11 @@ class OptiqMaterializer extends OptiqPrepareImpl.OptiqPreparingStmt {
/** Converts a relational expression to use a
* {@link StarTable} defined in {@code schema}.
* Uses the first star table that fits. */
- private void useStar(OptiqSchema schema, Materialization materialization) {
+ private void useStar(CalciteSchema schema, Materialization materialization) {
for (Callback x : useStar(schema, materialization.queryRel)) {
// Success -- we found a star table that matches.
materialization.materialize(x.rel, x.starRelOptTable);
- if (OptiqPrepareImpl.DEBUG) {
+ if (CalcitePrepareImpl.DEBUG) {
System.out.println("Materialization "
+ materialization.materializedTable + " matched star table "
+ x.starTable + "; query after re-write: "
@@ -95,10 +111,10 @@ class OptiqMaterializer extends OptiqPrepareImpl.OptiqPreparingStmt {
}
/** Converts a relational expression to use a
- * {@link net.hydromatic.optiq.impl.StarTable} defined in {@code schema}.
+ * {@link org.apache.calcite.schema.impl.StarTable} defined in {@code schema}.
* Uses the first star table that fits. */
- private Iterable<Callback> useStar(OptiqSchema schema, RelNode queryRel) {
- List<OptiqSchema.TableEntry> starTables =
+ private Iterable<Callback> useStar(CalciteSchema schema, RelNode queryRel) {
+ List<CalciteSchema.TableEntry> starTables =
Schemas.getStarTables(schema.root());
if (starTables.isEmpty()) {
// Don't waste effort converting to leaf-join form.
@@ -107,7 +123,7 @@ class OptiqMaterializer extends OptiqPrepareImpl.OptiqPreparingStmt {
final List<Callback> list = Lists.newArrayList();
final RelNode rel2 =
RelOptMaterialization.toLeafJoinForm(queryRel);
- for (OptiqSchema.TableEntry starTable : starTables) {
+ for (CalciteSchema.TableEntry starTable : starTables) {
final Table table = starTable.getTable();
assert table instanceof StarTable;
RelOptTableImpl starRelOptTable =
@@ -125,40 +141,40 @@ class OptiqMaterializer extends OptiqPrepareImpl.OptiqPreparingStmt {
/** Implementation of {@link RelShuttle} that returns each relational
* expression unchanged. It does not visit children. */
static class RelNullShuttle implements RelShuttle {
- public RelNode visit(TableAccessRelBase scan) {
+ public RelNode visit(TableScan scan) {
return scan;
}
- public RelNode visit(TableFunctionRelBase scan) {
+ public RelNode visit(TableFunctionScan scan) {
return scan;
}
- public RelNode visit(ValuesRel values) {
+ public RelNode visit(LogicalValues values) {
return values;
}
- public RelNode visit(FilterRel filter) {
+ public RelNode visit(LogicalFilter filter) {
return filter;
}
- public RelNode visit(ProjectRel project) {
+ public RelNode visit(LogicalProject project) {
return project;
}
- public RelNode visit(JoinRel join) {
+ public RelNode visit(LogicalJoin join) {
return join;
}
- public RelNode visit(CorrelatorRel correlator) {
+ public RelNode visit(Correlator correlator) {
return correlator;
}
- public RelNode visit(UnionRel union) {
+ public RelNode visit(LogicalUnion union) {
return union;
}
- public RelNode visit(IntersectRel intersect) {
+ public RelNode visit(LogicalIntersect intersect) {
return intersect;
}
- public RelNode visit(MinusRel minus) {
+ public RelNode visit(LogicalMinus minus) {
return minus;
}
- public RelNode visit(AggregateRel aggregate) {
+ public RelNode visit(LogicalAggregate aggregate) {
return aggregate;
}
- public RelNode visit(SortRel sort) {
+ public RelNode visit(Sort sort) {
return sort;
}
public RelNode visit(RelNode other) {
@@ -169,11 +185,11 @@ class OptiqMaterializer extends OptiqPrepareImpl.OptiqPreparingStmt {
/** Called when we discover a star table that matches. */
static class Callback {
public final RelNode rel;
- public final OptiqSchema.TableEntry starTable;
+ public final CalciteSchema.TableEntry starTable;
public final RelOptTableImpl starRelOptTable;
Callback(RelNode rel,
- OptiqSchema.TableEntry starTable,
+ CalciteSchema.TableEntry starTable,
RelOptTableImpl starRelOptTable) {
this.rel = rel;
this.starTable = starTable;
@@ -182,4 +198,4 @@ class OptiqMaterializer extends OptiqPrepareImpl.OptiqPreparingStmt {
}
}
-// End OptiqMaterializer.java
+// End CalciteMaterializer.java
http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/a0ba73cd/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 130638e..bdfba29 100644
--- a/core/src/main/java/org/apache/calcite/prepare/CalcitePrepareImpl.java
+++ b/core/src/main/java/org/apache/calcite/prepare/CalcitePrepareImpl.java
@@ -14,48 +14,106 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package net.hydromatic.optiq.prepare;
-
-import net.hydromatic.avatica.AvaticaParameter;
-import net.hydromatic.avatica.ColumnMetaData;
-import net.hydromatic.avatica.Helper;
-
-import net.hydromatic.linq4j.*;
-import net.hydromatic.linq4j.expressions.*;
-import net.hydromatic.linq4j.function.Function1;
-
-import net.hydromatic.optiq.*;
-import net.hydromatic.optiq.config.OptiqConnectionConfig;
-import net.hydromatic.optiq.impl.java.JavaTypeFactory;
-import net.hydromatic.optiq.jdbc.OptiqPrepare;
-import net.hydromatic.optiq.jdbc.OptiqSchema;
-import net.hydromatic.optiq.materialize.MaterializationService;
-import net.hydromatic.optiq.rules.java.*;
-import net.hydromatic.optiq.runtime.*;
-import net.hydromatic.optiq.server.OptiqServerStatement;
-import net.hydromatic.optiq.tools.Frameworks;
-
-import org.eigenbase.rel.*;
-import org.eigenbase.rel.rules.*;
-import org.eigenbase.relopt.*;
-import org.eigenbase.relopt.hep.*;
-import org.eigenbase.relopt.volcano.VolcanoPlanner;
-import org.eigenbase.reltype.*;
-import org.eigenbase.rex.RexBuilder;
-import org.eigenbase.rex.RexNode;
-import org.eigenbase.sql.*;
-import org.eigenbase.sql.fun.SqlStdOperatorTable;
-import org.eigenbase.sql.parser.SqlParseException;
-import org.eigenbase.sql.parser.SqlParser;
-import org.eigenbase.sql.parser.impl.SqlParserImpl;
-import org.eigenbase.sql.type.*;
-import org.eigenbase.sql.util.ChainedSqlOperatorTable;
-import org.eigenbase.sql.validate.*;
-import org.eigenbase.sql2rel.SqlToRelConverter;
-import org.eigenbase.sql2rel.StandardConvertletTable;
-import org.eigenbase.util.Util;
-
-import com.google.common.collect.*;
+package org.apache.calcite.prepare;
+
+import org.apache.calcite.DataContext;
+import org.apache.calcite.adapter.enumerable.EnumerableConvention;
+import org.apache.calcite.adapter.enumerable.EnumerableRel;
+import org.apache.calcite.adapter.enumerable.EnumerableRelImplementor;
+import org.apache.calcite.adapter.enumerable.EnumerableRules;
+import org.apache.calcite.adapter.enumerable.RexToLixTranslator;
+import org.apache.calcite.adapter.java.JavaTypeFactory;
+import org.apache.calcite.avatica.AvaticaParameter;
+import org.apache.calcite.avatica.ColumnMetaData;
+import org.apache.calcite.avatica.Helper;
+import org.apache.calcite.config.CalciteConnectionConfig;
+import org.apache.calcite.jdbc.CalcitePrepare;
+import org.apache.calcite.jdbc.CalciteSchema;
+import org.apache.calcite.linq4j.Enumerable;
+import org.apache.calcite.linq4j.Linq4j;
+import org.apache.calcite.linq4j.Ord;
+import org.apache.calcite.linq4j.Queryable;
+import org.apache.calcite.linq4j.function.Function1;
+import org.apache.calcite.linq4j.tree.BinaryExpression;
+import org.apache.calcite.linq4j.tree.BlockStatement;
+import org.apache.calcite.linq4j.tree.Blocks;
+import org.apache.calcite.linq4j.tree.ClassDeclaration;
+import org.apache.calcite.linq4j.tree.ConstantExpression;
+import org.apache.calcite.linq4j.tree.Expression;
+import org.apache.calcite.linq4j.tree.Expressions;
+import org.apache.calcite.linq4j.tree.MemberExpression;
+import org.apache.calcite.linq4j.tree.MethodCallExpression;
+import org.apache.calcite.linq4j.tree.NewExpression;
+import org.apache.calcite.linq4j.tree.ParameterExpression;
+import org.apache.calcite.materialize.MaterializationService;
+import org.apache.calcite.plan.Contexts;
+import org.apache.calcite.plan.Convention;
+import org.apache.calcite.plan.ConventionTraitDef;
+import org.apache.calcite.plan.RelOptCluster;
+import org.apache.calcite.plan.RelOptCostFactory;
+import org.apache.calcite.plan.RelOptPlanner;
+import org.apache.calcite.plan.RelOptQuery;
+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.RelCollationTraitDef;
+import org.apache.calcite.rel.RelNode;
+import org.apache.calcite.rel.rules.AggregateExpandDistinctAggregatesRule;
+import org.apache.calcite.rel.rules.AggregateReduceFunctionsRule;
+import org.apache.calcite.rel.rules.AggregateStarTableRule;
+import org.apache.calcite.rel.rules.FilterAggregateTransposeRule;
+import org.apache.calcite.rel.rules.FilterJoinRule;
+import org.apache.calcite.rel.rules.FilterProjectTransposeRule;
+import org.apache.calcite.rel.rules.FilterTableRule;
+import org.apache.calcite.rel.rules.JoinAssociateRule;
+import org.apache.calcite.rel.rules.JoinCommuteRule;
+import org.apache.calcite.rel.rules.JoinPushThroughJoinRule;
+import org.apache.calcite.rel.rules.ProjectFilterTransposeRule;
+import org.apache.calcite.rel.rules.ProjectMergeRule;
+import org.apache.calcite.rel.rules.ProjectTableRule;
+import org.apache.calcite.rel.rules.ReduceExpressionsRule;
+import org.apache.calcite.rel.rules.SortProjectTransposeRule;
+import org.apache.calcite.rel.rules.TableScanRule;
+import org.apache.calcite.rel.rules.ValuesReduceRule;
+import org.apache.calcite.rel.type.RelDataType;
+import org.apache.calcite.rel.type.RelDataTypeFactory;
+import org.apache.calcite.rel.type.RelDataTypeFactoryImpl;
+import org.apache.calcite.rel.type.RelDataTypeField;
+import org.apache.calcite.rex.RexBuilder;
+import org.apache.calcite.rex.RexNode;
+import org.apache.calcite.runtime.Bindable;
+import org.apache.calcite.runtime.Hook;
+import org.apache.calcite.runtime.Spaces;
+import org.apache.calcite.runtime.Typed;
+import org.apache.calcite.runtime.Utilities;
+import org.apache.calcite.schema.Schemas;
+import org.apache.calcite.server.CalciteServerStatement;
+import org.apache.calcite.sql.SqlBinaryOperator;
+import org.apache.calcite.sql.SqlExplainLevel;
+import org.apache.calcite.sql.SqlKind;
+import org.apache.calcite.sql.SqlNode;
+import org.apache.calcite.sql.SqlOperator;
+import org.apache.calcite.sql.fun.SqlStdOperatorTable;
+import org.apache.calcite.sql.parser.SqlParseException;
+import org.apache.calcite.sql.parser.SqlParser;
+import org.apache.calcite.sql.parser.impl.SqlParserImpl;
+import org.apache.calcite.sql.type.SqlTypeName;
+import org.apache.calcite.sql.util.ChainedSqlOperatorTable;
+import org.apache.calcite.sql.validate.SqlConformance;
+import org.apache.calcite.sql.validate.SqlValidator;
+import org.apache.calcite.sql.validate.SqlValidatorImpl;
+import org.apache.calcite.sql2rel.SqlToRelConverter;
+import org.apache.calcite.sql2rel.StandardConvertletTable;
+import org.apache.calcite.tools.Frameworks;
+import org.apache.calcite.util.Util;
+
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableMap;
+import com.google.common.collect.ImmutableSet;
+import com.google.common.collect.Maps;
import org.codehaus.commons.compiler.CompileException;
import org.codehaus.commons.compiler.CompilerFactoryFactory;
@@ -69,7 +127,11 @@ import java.io.StringReader;
import java.lang.reflect.Type;
import java.math.BigDecimal;
import java.sql.DatabaseMetaData;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
/**
* Shit just got real.
@@ -78,7 +140,7 @@ import java.util.*;
* and server can fine-tune preferences. However, this class and its methods are
* subject to change without notice.</p>
*/
-public class OptiqPrepareImpl implements OptiqPrepare {
+public class CalcitePrepareImpl implements CalcitePrepare {
public static final boolean DEBUG =
"true".equals(System.getProperties().getProperty("calcite.debug"));
@@ -104,43 +166,43 @@ public class OptiqPrepareImpl implements OptiqPrepare {
private static final List<RelOptRule> DEFAULT_RULES =
ImmutableList.of(
- JavaRules.ENUMERABLE_JOIN_RULE,
- JavaRules.ENUMERABLE_SEMI_JOIN_RULE,
- JavaRules.ENUMERABLE_PROJECT_RULE,
- JavaRules.ENUMERABLE_FILTER_RULE,
- JavaRules.ENUMERABLE_AGGREGATE_RULE,
- JavaRules.ENUMERABLE_SORT_RULE,
- JavaRules.ENUMERABLE_LIMIT_RULE,
- JavaRules.ENUMERABLE_COLLECT_RULE,
- JavaRules.ENUMERABLE_UNCOLLECT_RULE,
- JavaRules.ENUMERABLE_UNION_RULE,
- JavaRules.ENUMERABLE_INTERSECT_RULE,
- JavaRules.ENUMERABLE_MINUS_RULE,
- JavaRules.ENUMERABLE_TABLE_MODIFICATION_RULE,
- JavaRules.ENUMERABLE_VALUES_RULE,
- JavaRules.ENUMERABLE_WINDOW_RULE,
- JavaRules.ENUMERABLE_ONE_ROW_RULE,
- JavaRules.ENUMERABLE_EMPTY_RULE,
- JavaRules.ENUMERABLE_TABLE_FUNCTION_RULE,
+ EnumerableRules.ENUMERABLE_JOIN_RULE,
+ EnumerableRules.ENUMERABLE_SEMI_JOIN_RULE,
+ EnumerableRules.ENUMERABLE_PROJECT_RULE,
+ EnumerableRules.ENUMERABLE_FILTER_RULE,
+ EnumerableRules.ENUMERABLE_AGGREGATE_RULE,
+ EnumerableRules.ENUMERABLE_SORT_RULE,
+ EnumerableRules.ENUMERABLE_LIMIT_RULE,
+ EnumerableRules.ENUMERABLE_COLLECT_RULE,
+ EnumerableRules.ENUMERABLE_UNCOLLECT_RULE,
+ EnumerableRules.ENUMERABLE_UNION_RULE,
+ EnumerableRules.ENUMERABLE_INTERSECT_RULE,
+ EnumerableRules.ENUMERABLE_MINUS_RULE,
+ EnumerableRules.ENUMERABLE_TABLE_MODIFICATION_RULE,
+ EnumerableRules.ENUMERABLE_VALUES_RULE,
+ EnumerableRules.ENUMERABLE_WINDOW_RULE,
+ EnumerableRules.ENUMERABLE_ONE_ROW_RULE,
+ EnumerableRules.ENUMERABLE_EMPTY_RULE,
+ EnumerableRules.ENUMERABLE_TABLE_FUNCTION_SCAN_RULE,
AggregateStarTableRule.INSTANCE,
AggregateStarTableRule.INSTANCE2,
- TableAccessRule.INSTANCE,
+ TableScanRule.INSTANCE,
COMMUTE
- ? CommutativeJoinRule.INSTANCE
- : MergeProjectRule.INSTANCE,
+ ? JoinAssociateRule.INSTANCE
+ : ProjectMergeRule.INSTANCE,
FilterTableRule.INSTANCE,
ProjectTableRule.INSTANCE,
ProjectTableRule.INSTANCE2,
- PushProjectPastFilterRule.INSTANCE,
- PushFilterPastProjectRule.INSTANCE,
- PushFilterPastJoinRule.FILTER_ON_JOIN,
- RemoveDistinctAggregateRule.INSTANCE,
- ReduceAggregatesRule.INSTANCE,
+ ProjectFilterTransposeRule.INSTANCE,
+ FilterProjectTransposeRule.INSTANCE,
+ FilterJoinRule.FILTER_ON_JOIN,
+ AggregateExpandDistinctAggregatesRule.INSTANCE,
+ AggregateReduceFunctionsRule.INSTANCE,
FilterAggregateTransposeRule.INSTANCE,
- SwapJoinRule.INSTANCE,
- PushJoinThroughJoinRule.RIGHT,
- PushJoinThroughJoinRule.LEFT,
- PushSortPastProjectRule.INSTANCE);
+ JoinCommuteRule.INSTANCE,
+ JoinPushThroughJoinRule.RIGHT,
+ JoinPushThroughJoinRule.LEFT,
+ SortProjectTransposeRule.INSTANCE);
private static final List<RelOptRule> CONSTANT_REDUCTION_RULES =
ImmutableList.of(
@@ -148,11 +210,11 @@ public class OptiqPrepareImpl implements OptiqPrepare {
ReduceExpressionsRule.FILTER_INSTANCE,
ReduceExpressionsRule.CALC_INSTANCE,
ReduceExpressionsRule.JOIN_INSTANCE,
- ReduceValuesRule.FILTER_INSTANCE,
- ReduceValuesRule.PROJECT_FILTER_INSTANCE,
- ReduceValuesRule.PROJECT_INSTANCE);
+ ValuesReduceRule.FILTER_INSTANCE,
+ ValuesReduceRule.PROJECT_FILTER_INSTANCE,
+ ValuesReduceRule.PROJECT_INSTANCE);
- public OptiqPrepareImpl() {
+ public CalcitePrepareImpl() {
}
public ParseResult parse(
@@ -167,8 +229,8 @@ public class OptiqPrepareImpl implements OptiqPrepare {
/** Shared implementation for {@link #parse} and {@link #convert}. */
private ParseResult parse_(Context context, String sql, boolean convert) {
final JavaTypeFactory typeFactory = context.getTypeFactory();
- OptiqCatalogReader catalogReader =
- new OptiqCatalogReader(
+ CalciteCatalogReader catalogReader =
+ new CalciteCatalogReader(
context.getRootSchema(),
context.config().caseSensitive(),
context.getDefaultSchemaPath(),
@@ -181,15 +243,15 @@ public class OptiqPrepareImpl implements OptiqPrepare {
throw new RuntimeException("parse failed", e);
}
final SqlValidator validator =
- new OptiqSqlValidator(
+ new CalciteSqlValidator(
SqlStdOperatorTable.instance(), catalogReader, typeFactory);
SqlNode sqlNode1 = validator.validate(sqlNode);
if (!convert) {
return new ParseResult(this, validator, sql, sqlNode1,
validator.getValidatedNodeType(sqlNode1));
}
- final OptiqPreparingStmt preparingStmt =
- new OptiqPreparingStmt(
+ final CalcitePreparingStmt preparingStmt =
+ new CalcitePreparingStmt(
context,
catalogReader,
typeFactory,
@@ -215,7 +277,7 @@ public class OptiqPrepareImpl implements OptiqPrepare {
* complex planner for complex and costly queries.</p>
*
* <p>The default implementation returns a factory that calls
- * {@link #createPlanner(net.hydromatic.optiq.jdbc.OptiqPrepare.Context)}.</p>
+ * {@link #createPlanner(org.apache.calcite.jdbc.CalcitePrepare.Context)}.</p>
*/
protected List<Function1<Context, RelOptPlanner>> createPlannerFactories() {
return Collections.<Function1<Context, RelOptPlanner>>singletonList(
@@ -228,15 +290,15 @@ public class OptiqPrepareImpl implements OptiqPrepare {
/** Creates a query planner and initializes it with a default set of
* rules. */
- protected RelOptPlanner createPlanner(OptiqPrepare.Context prepareContext) {
+ protected RelOptPlanner createPlanner(CalcitePrepare.Context prepareContext) {
return createPlanner(prepareContext, null, null);
}
/** Creates a query planner and initializes it with a default set of
* rules. */
protected RelOptPlanner createPlanner(
- final OptiqPrepare.Context prepareContext,
- org.eigenbase.relopt.Context externalContext,
+ final CalcitePrepare.Context prepareContext,
+ org.apache.calcite.plan.Context externalContext,
RelOptCostFactory costFactory) {
if (externalContext == null) {
externalContext = Contexts.withConfig(prepareContext.config());
@@ -301,8 +363,8 @@ public class OptiqPrepareImpl implements OptiqPrepare {
return simplePrepare(context, sql);
}
final JavaTypeFactory typeFactory = context.getTypeFactory();
- OptiqCatalogReader catalogReader =
- new OptiqCatalogReader(
+ CalciteCatalogReader catalogReader =
+ new CalciteCatalogReader(
context.getRootSchema(),
context.config().caseSensitive(),
context.getDefaultSchemaPath(),
@@ -319,8 +381,7 @@ public class OptiqPrepareImpl implements OptiqPrepare {
throw new AssertionError("factory returned null planner");
}
try {
- return prepare2_(
- context, sql, queryable, elementType, maxRowCount,
+ return prepare2_(context, sql, queryable, elementType, maxRowCount,
catalogReader, planner);
} catch (RelOptPlanner.CannotPlanException e) {
exception = e;
@@ -361,7 +422,7 @@ public class OptiqPrepareImpl implements OptiqPrepare {
Queryable<T> queryable,
Type elementType,
int maxRowCount,
- OptiqCatalogReader catalogReader,
+ CalciteCatalogReader catalogReader,
RelOptPlanner planner) {
final JavaTypeFactory typeFactory = context.getTypeFactory();
final EnumerableRel.Prefer prefer;
@@ -370,8 +431,8 @@ public class OptiqPrepareImpl implements OptiqPrepare {
} else {
prefer = EnumerableRel.Prefer.CUSTOM;
}
- final OptiqPreparingStmt preparingStmt =
- new OptiqPreparingStmt(
+ final CalcitePreparingStmt preparingStmt =
+ new CalcitePreparingStmt(
context,
catalogReader,
typeFactory,
@@ -384,7 +445,7 @@ public class OptiqPrepareImpl implements OptiqPrepare {
final Prepare.PreparedResult preparedResult;
if (sql != null) {
assert queryable == null;
- final OptiqConnectionConfig config = context.config();
+ final CalciteConnectionConfig config = context.config();
SqlParser parser = SqlParser.create(SqlParserImpl.FACTORY, sql,
config.quoting(), config.unquotedCasing(), config.quotedCasing());
SqlNode sqlNode;
@@ -397,12 +458,12 @@ public class OptiqPrepareImpl implements OptiqPrepare {
Hook.PARSE_TREE.run(new Object[] {sql, sqlNode});
- final OptiqSchema rootSchema = context.getRootSchema();
+ final CalciteSchema rootSchema = context.getRootSchema();
final ChainedSqlOperatorTable opTab =
new ChainedSqlOperatorTable(
ImmutableList.of(SqlStdOperatorTable.instance(), catalogReader));
final SqlValidator validator =
- new OptiqSqlValidator(opTab, catalogReader, typeFactory);
+ new CalciteSqlValidator(opTab, catalogReader, typeFactory);
validator.setIdentifierExpansion(true);
final List<Prepare.Materialization> materializations =
@@ -412,7 +473,7 @@ public class OptiqPrepareImpl implements OptiqPrepare {
for (Prepare.Materialization materialization : materializations) {
populateMaterializations(context, planner, materialization);
}
- final List<OptiqSchema.LatticeEntry> lattices =
+ final List<CalciteSchema.LatticeEntry> lattices =
Schemas.getLatticeEntries(rootSchema);
preparedResult = preparingStmt.prepareSql(
sqlNode, Object.class, validator, true, materializations, lattices);
@@ -573,15 +634,15 @@ public class OptiqPrepareImpl implements OptiqPrepare {
// REVIEW: initialize queryRel and tableRel inside MaterializationService,
// not here?
try {
- final OptiqSchema schema = materialization.materializedTable.schema;
- OptiqCatalogReader catalogReader =
- new OptiqCatalogReader(
+ final CalciteSchema schema = materialization.materializedTable.schema;
+ CalciteCatalogReader catalogReader =
+ new CalciteCatalogReader(
schema.root(),
context.config().caseSensitive(),
Util.skipLast(materialization.materializedTable.path()),
context.getTypeFactory());
- final OptiqMaterializer materializer =
- new OptiqMaterializer(context, catalogReader, schema, planner);
+ final CalciteMaterializer materializer =
+ new CalciteMaterializer(context, catalogReader, schema, planner);
materializer.populate(materialization);
} catch (Exception e) {
throw new RuntimeException("While populating materialization "
@@ -599,13 +660,13 @@ public class OptiqPrepareImpl implements OptiqPrepare {
}
/** Executes a prepare action. */
- public <R> R perform(OptiqServerStatement statement,
+ public <R> R perform(CalciteServerStatement statement,
Frameworks.PrepareAction<R> action) {
- final OptiqPrepare.Context prepareContext =
+ final CalcitePrepare.Context prepareContext =
statement.createPrepareContext();
final JavaTypeFactory typeFactory = prepareContext.getTypeFactory();
- OptiqCatalogReader catalogReader =
- new OptiqCatalogReader(prepareContext.getRootSchema(),
+ CalciteCatalogReader catalogReader =
+ new CalciteCatalogReader(prepareContext.getRootSchema(),
prepareContext.config().caseSensitive(),
prepareContext.getDefaultSchemaPath(),
typeFactory);
@@ -621,11 +682,12 @@ public class OptiqPrepareImpl implements OptiqPrepare {
prepareContext.getRootSchema().plus(), statement);
}
- static class OptiqPreparingStmt extends Prepare
+ /** Holds state for the process of preparing a SQL statement. */
+ static class CalcitePreparingStmt extends Prepare
implements RelOptTable.ViewExpander {
private final RelOptPlanner planner;
private final RexBuilder rexBuilder;
- protected final OptiqSchema schema;
+ protected final CalciteSchema schema;
protected final RelDataTypeFactory typeFactory;
private final EnumerableRel.Prefer prefer;
private final Map<String, Object> internalParameters =
@@ -633,10 +695,10 @@ public class OptiqPrepareImpl implements OptiqPrepare {
private int expansionDepth;
private SqlValidator sqlValidator;
- public OptiqPreparingStmt(Context context,
+ public CalcitePreparingStmt(Context context,
CatalogReader catalogReader,
RelDataTypeFactory typeFactory,
- OptiqSchema schema,
+ CalciteSchema schema,
EnumerableRel.Prefer prefer,
RelOptPlanner planner,
Convention resultConvention) {
@@ -648,8 +710,7 @@ public class OptiqPrepareImpl implements OptiqPrepare {
this.rexBuilder = new RexBuilder(typeFactory);
}
- @Override
- protected void init(Class runtimeContextClass) {
+ @Override protected void init(Class runtimeContextClass) {
}
public PreparedResult prepareQueryable(
@@ -665,7 +726,7 @@ public class OptiqPrepareImpl implements OptiqPrepare {
rexBuilder.getTypeFactory(), rexBuilder);
RelNode rootRel =
- new LixToRelTranslator(cluster, OptiqPreparingStmt.this)
+ new LixToRelTranslator(cluster, CalcitePreparingStmt.this)
.translate(queryable);
if (timingTracer != null) {
@@ -685,7 +746,7 @@ public class OptiqPrepareImpl implements OptiqPrepare {
rootRel = trimUnusedFields(rootRel);
final List<Materialization> materializations = ImmutableList.of();
- final List<OptiqSchema.LatticeEntry> lattices = ImmutableList.of();
+ final List<CalciteSchema.LatticeEntry> lattices = ImmutableList.of();
rootRel = optimize(resultType, rootRel, materializations, lattices);
if (timingTracer != null) {
@@ -698,8 +759,7 @@ public class OptiqPrepareImpl implements OptiqPrepare {
SqlKind.SELECT);
}
- @Override
- protected SqlToRelConverter getSqlToRelConverter(
+ @Override protected SqlToRelConverter getSqlToRelConverter(
SqlValidator validator,
CatalogReader catalogReader) {
SqlToRelConverter sqlToRelConverter =
@@ -710,19 +770,16 @@ public class OptiqPrepareImpl implements OptiqPrepare {
return sqlToRelConverter;
}
- @Override
- protected EnumerableRelImplementor getRelImplementor(
+ @Override protected EnumerableRelImplementor getRelImplementor(
RexBuilder rexBuilder) {
return new EnumerableRelImplementor(rexBuilder, internalParameters);
}
- @Override
- protected boolean shouldAlwaysWriteJavaFile() {
+ @Override protected boolean shouldAlwaysWriteJavaFile() {
return false;
}
- @Override
- public RelNode flattenTypes(
+ @Override public RelNode flattenTypes(
RelNode rootRel,
boolean restructure) {
final SparkHandler spark = context.spark();
@@ -771,27 +828,24 @@ public class OptiqPrepareImpl implements OptiqPrepare {
rexBuilder.getTypeFactory(), SqlConformance.DEFAULT) { };
}
- @Override
- protected SqlValidator getSqlValidator() {
+ @Override protected SqlValidator getSqlValidator() {
if (sqlValidator == null) {
sqlValidator = createSqlValidator(catalogReader);
}
return sqlValidator;
}
- @Override
- protected PreparedResult createPreparedExplanation(
+ @Override protected PreparedResult createPreparedExplanation(
RelDataType resultType,
RelDataType parameterRowType,
RelNode rootRel,
boolean explainAsXml,
SqlExplainLevel detailLevel) {
- return new OptiqPreparedExplain(
+ return new CalcitePreparedExplain(
resultType, parameterRowType, rootRel, explainAsXml, detailLevel);
}
- @Override
- protected PreparedResult implement(
+ @Override protected PreparedResult implement(
RelDataType rowType,
RelNode rootRel,
SqlKind sqlKind) {
@@ -897,8 +951,9 @@ public class OptiqPrepareImpl implements OptiqPrepare {
}
}
- private static class OptiqPreparedExplain extends Prepare.PreparedExplain {
- public OptiqPreparedExplain(
+ /** An {@code EXPLAIN} statement, prepared and ready to execute. */
+ private static class CalcitePreparedExplain extends Prepare.PreparedExplain {
+ public CalcitePreparedExplain(
RelDataType resultType,
RelDataType parameterRowType,
RelNode rootRel,
@@ -907,7 +962,6 @@ public class OptiqPrepareImpl implements OptiqPrepare {
super(resultType, parameterRowType, rootRel, explainAsXml, detailLevel);
}
- @Override
public Bindable getBindable() {
final String explanation = getCode();
return new Bindable() {
@@ -918,14 +972,16 @@ public class OptiqPrepareImpl implements OptiqPrepare {
}
}
+ /** Translator from Java AST to {@link RexNode}. */
interface ScalarTranslator {
RexNode toRex(BlockStatement statement);
List<RexNode> toRexList(BlockStatement statement);
RexNode toRex(Expression expression);
- ScalarTranslator bind(
- List<ParameterExpression> parameterList, List<RexNode> values);
+ ScalarTranslator bind(List<ParameterExpression> parameterList,
+ List<RexNode> values);
}
+ /** Basic translator. */
static class EmptyScalarTranslator implements ScalarTranslator {
private final RexBuilder rexBuilder;
@@ -1047,6 +1103,7 @@ public class OptiqPrepareImpl implements OptiqPrepare {
}
}
+ /** Translator that looks for parameters. */
private static class LambdaScalarTranslator extends EmptyScalarTranslator {
private final List<ParameterExpression> parameterList;
private final List<RexNode> values;
@@ -1070,4 +1127,4 @@ public class OptiqPrepareImpl implements OptiqPrepare {
}
}
-// End OptiqPrepareImpl.java
+// End CalcitePrepareImpl.java
http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/a0ba73cd/core/src/main/java/org/apache/calcite/prepare/CalciteSqlValidator.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/prepare/CalciteSqlValidator.java b/core/src/main/java/org/apache/calcite/prepare/CalciteSqlValidator.java
index 6236a29..63670ad 100644
--- a/core/src/main/java/org/apache/calcite/prepare/CalciteSqlValidator.java
+++ b/core/src/main/java/org/apache/calcite/prepare/CalciteSqlValidator.java
@@ -14,36 +14,33 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package net.hydromatic.optiq.prepare;
+package org.apache.calcite.prepare;
-import net.hydromatic.optiq.impl.java.JavaTypeFactory;
-
-import org.eigenbase.reltype.RelDataType;
-import org.eigenbase.sql.SqlInsert;
-import org.eigenbase.sql.SqlOperatorTable;
-import org.eigenbase.sql.validate.SqlConformance;
-import org.eigenbase.sql.validate.SqlValidatorImpl;
+import org.apache.calcite.adapter.java.JavaTypeFactory;
+import org.apache.calcite.rel.type.RelDataType;
+import org.apache.calcite.sql.SqlInsert;
+import org.apache.calcite.sql.SqlOperatorTable;
+import org.apache.calcite.sql.validate.SqlConformance;
+import org.apache.calcite.sql.validate.SqlValidatorImpl;
/** Validator. */
-class OptiqSqlValidator extends SqlValidatorImpl {
- public OptiqSqlValidator(
+class CalciteSqlValidator extends SqlValidatorImpl {
+ public CalciteSqlValidator(
SqlOperatorTable opTab,
- OptiqCatalogReader catalogReader,
+ CalciteCatalogReader catalogReader,
JavaTypeFactory typeFactory) {
super(opTab, catalogReader, typeFactory, SqlConformance.DEFAULT);
}
- @Override
- protected RelDataType getLogicalSourceRowType(
+ @Override protected RelDataType getLogicalSourceRowType(
RelDataType sourceRowType, SqlInsert insert) {
return ((JavaTypeFactory) typeFactory).toSql(sourceRowType);
}
- @Override
- protected RelDataType getLogicalTargetRowType(
+ @Override protected RelDataType getLogicalTargetRowType(
RelDataType targetRowType, SqlInsert insert) {
return ((JavaTypeFactory) typeFactory).toSql(targetRowType);
}
}
-// End OptiqSqlValidator.java
+// End CalciteSqlValidator.java
http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/a0ba73cd/core/src/main/java/org/apache/calcite/prepare/LixToRelTranslator.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/prepare/LixToRelTranslator.java b/core/src/main/java/org/apache/calcite/prepare/LixToRelTranslator.java
index dde0295..35b43cb 100644
--- a/core/src/main/java/org/apache/calcite/prepare/LixToRelTranslator.java
+++ b/core/src/main/java/org/apache/calcite/prepare/LixToRelTranslator.java
@@ -14,20 +14,27 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package net.hydromatic.optiq.prepare;
-
-import net.hydromatic.linq4j.Queryable;
-import net.hydromatic.linq4j.expressions.*;
-
-import net.hydromatic.optiq.*;
-import net.hydromatic.optiq.impl.java.JavaTypeFactory;
-
-import org.eigenbase.rel.*;
-import org.eigenbase.relopt.RelOptCluster;
-import org.eigenbase.relopt.RelOptTable;
-import org.eigenbase.reltype.RelDataType;
-import org.eigenbase.rex.RexBuilder;
-import org.eigenbase.rex.RexNode;
+package org.apache.calcite.prepare;
+
+import org.apache.calcite.adapter.java.JavaTypeFactory;
+import org.apache.calcite.linq4j.Queryable;
+import org.apache.calcite.linq4j.tree.Blocks;
+import org.apache.calcite.linq4j.tree.ConstantExpression;
+import org.apache.calcite.linq4j.tree.Expression;
+import org.apache.calcite.linq4j.tree.FunctionExpression;
+import org.apache.calcite.linq4j.tree.MethodCallExpression;
+import org.apache.calcite.linq4j.tree.NewExpression;
+import org.apache.calcite.linq4j.tree.Types;
+import org.apache.calcite.plan.RelOptCluster;
+import org.apache.calcite.plan.RelOptTable;
+import org.apache.calcite.rel.RelNode;
+import org.apache.calcite.rel.logical.LogicalFilter;
+import org.apache.calcite.rel.logical.LogicalProject;
+import org.apache.calcite.rel.logical.LogicalTableScan;
+import org.apache.calcite.rel.type.RelDataType;
+import org.apache.calcite.rex.RexBuilder;
+import org.apache.calcite.rex.RexNode;
+import org.apache.calcite.util.BuiltInMethod;
import com.google.common.collect.ImmutableList;
@@ -70,7 +77,7 @@ class LixToRelTranslator implements RelOptTable.ToRelContext {
public RelNode translate(Expression expression) {
if (expression instanceof MethodCallExpression) {
final MethodCallExpression call = (MethodCallExpression) expression;
- BuiltinMethod method = BuiltinMethod.MAP.get(call.method);
+ BuiltInMethod method = BuiltInMethod.MAP.get(call.method);
if (method == null) {
throw new UnsupportedOperationException(
"unknown method " + call.method);
@@ -79,18 +86,18 @@ class LixToRelTranslator implements RelOptTable.ToRelContext {
switch (method) {
case SELECT:
child = translate(call.targetExpression);
- return new ProjectRel(
+ return new LogicalProject(
cluster,
child,
toRex(
child,
(FunctionExpression) call.expressions.get(0)),
null,
- ProjectRel.Flags.BOXED);
+ LogicalProject.Flags.BOXED);
case WHERE:
child = translate(call.targetExpression);
- return new FilterRel(
+ return new LogicalFilter(
cluster,
child,
toRex(
@@ -98,7 +105,7 @@ class LixToRelTranslator implements RelOptTable.ToRelContext {
child));
case AS_QUERYABLE:
- return new TableAccessRel(
+ return new LogicalTableScan(
cluster,
RelOptTableImpl.create(
null,
@@ -109,7 +116,7 @@ class LixToRelTranslator implements RelOptTable.ToRelContext {
call.targetExpression));
case SCHEMA_GET_TABLE:
- return new TableAccessRel(
+ return new LogicalTableScan(
cluster,
RelOptTableImpl.create(
null,
@@ -133,8 +140,8 @@ class LixToRelTranslator implements RelOptTable.ToRelContext {
List<RexNode> list =
Collections.singletonList(
rexBuilder.makeRangeReference(child));
- OptiqPrepareImpl.ScalarTranslator translator =
- OptiqPrepareImpl.EmptyScalarTranslator
+ CalcitePrepareImpl.ScalarTranslator translator =
+ CalcitePrepareImpl.EmptyScalarTranslator
.empty(rexBuilder)
.bind(expression.parameterList, list);
final List<RexNode> rexList = new ArrayList<RexNode>();
@@ -163,7 +170,7 @@ class LixToRelTranslator implements RelOptTable.ToRelContext {
for (RelNode input : inputs) {
list.add(rexBuilder.makeRangeReference(input));
}
- return OptiqPrepareImpl.EmptyScalarTranslator.empty(rexBuilder)
+ return CalcitePrepareImpl.EmptyScalarTranslator.empty(rexBuilder)
.bind(expression.parameterList, list)
.toRexList(expression.body);
}
@@ -176,7 +183,7 @@ class LixToRelTranslator implements RelOptTable.ToRelContext {
for (RelNode input : inputs) {
list.add(rexBuilder.makeRangeReference(input));
}
- return OptiqPrepareImpl.EmptyScalarTranslator.empty(rexBuilder)
+ return CalcitePrepareImpl.EmptyScalarTranslator.empty(rexBuilder)
.bind(expression.parameterList, list)
.toRex(expression.body);
}
http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/a0ba73cd/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 4dc5124..278ba11 100644
--- a/core/src/main/java/org/apache/calcite/prepare/PlannerImpl.java
+++ b/core/src/main/java/org/apache/calcite/prepare/PlannerImpl.java
@@ -14,35 +14,43 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package net.hydromatic.optiq.prepare;
-
-import net.hydromatic.optiq.SchemaPlus;
-import net.hydromatic.optiq.config.Lex;
-import net.hydromatic.optiq.impl.java.JavaTypeFactory;
-import net.hydromatic.optiq.jdbc.OptiqSchema;
-import net.hydromatic.optiq.tools.*;
-
-import org.eigenbase.rel.RelNode;
-import org.eigenbase.relopt.*;
-import org.eigenbase.relopt.RelOptTable.ViewExpander;
-import org.eigenbase.reltype.RelDataType;
-import org.eigenbase.rex.RexBuilder;
-import org.eigenbase.sql.SqlNode;
-import org.eigenbase.sql.SqlOperatorTable;
-import org.eigenbase.sql.parser.SqlParseException;
-import org.eigenbase.sql.parser.SqlParser;
-import org.eigenbase.sql.parser.SqlParserImplFactory;
-import org.eigenbase.sql.validate.SqlValidator;
-import org.eigenbase.sql2rel.RelDecorrelator;
-import org.eigenbase.sql2rel.SqlRexConvertletTable;
-import org.eigenbase.sql2rel.SqlToRelConverter;
-import org.eigenbase.util.Util;
+package org.apache.calcite.prepare;
+
+import org.apache.calcite.adapter.java.JavaTypeFactory;
+import org.apache.calcite.config.Lex;
+import org.apache.calcite.jdbc.CalciteSchema;
+import org.apache.calcite.plan.RelOptCluster;
+import org.apache.calcite.plan.RelOptPlanner;
+import org.apache.calcite.plan.RelOptSchema;
+import org.apache.calcite.plan.RelOptTable.ViewExpander;
+import org.apache.calcite.plan.RelTraitDef;
+import org.apache.calcite.plan.RelTraitSet;
+import org.apache.calcite.rel.RelNode;
+import org.apache.calcite.rel.type.RelDataType;
+import org.apache.calcite.rex.RexBuilder;
+import org.apache.calcite.schema.SchemaPlus;
+import org.apache.calcite.sql.SqlNode;
+import org.apache.calcite.sql.SqlOperatorTable;
+import org.apache.calcite.sql.parser.SqlParseException;
+import org.apache.calcite.sql.parser.SqlParser;
+import org.apache.calcite.sql.parser.SqlParserImplFactory;
+import org.apache.calcite.sql.validate.SqlValidator;
+import org.apache.calcite.sql2rel.RelDecorrelator;
+import org.apache.calcite.sql2rel.SqlRexConvertletTable;
+import org.apache.calcite.sql2rel.SqlToRelConverter;
+import org.apache.calcite.tools.FrameworkConfig;
+import org.apache.calcite.tools.Frameworks;
+import org.apache.calcite.tools.Planner;
+import org.apache.calcite.tools.Program;
+import org.apache.calcite.tools.RelConversionException;
+import org.apache.calcite.tools.ValidationException;
+import org.apache.calcite.util.Util;
import com.google.common.collect.ImmutableList;
import java.util.List;
-/** Implementation of {@link net.hydromatic.optiq.tools.Planner}. */
+/** Implementation of {@link org.apache.calcite.tools.Planner}. */
public class PlannerImpl implements Planner {
private final SqlOperatorTable operatorTable;
private final ImmutableList<Program> programs;
@@ -69,14 +77,14 @@ public class PlannerImpl implements Planner {
private RelOptPlanner planner;
// set in STATE_4_VALIDATE
- private OptiqSqlValidator validator;
+ private CalciteSqlValidator validator;
private SqlNode validatedSqlNode;
// set in STATE_5_CONVERT
private RelNode rel;
/** Creates a planner. Not a public API; call
- * {@link net.hydromatic.optiq.tools.Frameworks#getPlanner} instead. */
+ * {@link org.apache.calcite.tools.Frameworks#getPlanner} instead. */
public PlannerImpl(FrameworkConfig config) {
this.config = config;
this.defaultSchema = config.getDefaultSchema();
@@ -166,7 +174,7 @@ public class PlannerImpl implements Planner {
public SqlNode validate(SqlNode sqlNode) throws ValidationException {
ensure(State.STATE_3_PARSED);
this.validator =
- new OptiqSqlValidator(
+ new CalciteSqlValidator(
operatorTable, createCatalogReader(), typeFactory);
try {
validatedSqlNode = validator.validate(sqlNode);
@@ -193,8 +201,8 @@ public class PlannerImpl implements Planner {
return rel;
}
- /** Implements {@link org.eigenbase.relopt.RelOptTable.ViewExpander}
- * interface for {@link net.hydromatic.optiq.tools.Planner}. */
+ /** Implements {@link org.apache.calcite.plan.RelOptTable.ViewExpander}
+ * interface for {@link org.apache.calcite.tools.Planner}. */
public class ViewExpanderImpl implements ViewExpander {
public RelNode expandView(RelDataType rowType, String queryString,
List<String> schemaPath) {
@@ -207,9 +215,9 @@ public class PlannerImpl implements Planner {
throw new RuntimeException("parse failed", e);
}
- final OptiqCatalogReader catalogReader =
+ final CalciteCatalogReader catalogReader =
createCatalogReader().withSchemaPath(schemaPath);
- final SqlValidator validator = new OptiqSqlValidator(operatorTable,
+ final SqlValidator validator = new CalciteSqlValidator(operatorTable,
catalogReader, typeFactory);
final SqlNode validatedSqlNode = validator.validate(sqlNode);
@@ -222,13 +230,13 @@ public class PlannerImpl implements Planner {
}
}
- // OptiqCatalogReader is stateless; no need to store one
- private OptiqCatalogReader createCatalogReader() {
+ // CalciteCatalogReader is stateless; no need to store one
+ private CalciteCatalogReader createCatalogReader() {
SchemaPlus rootSchema = rootSchema(defaultSchema);
- return new OptiqCatalogReader(
- OptiqSchema.from(rootSchema),
+ return new CalciteCatalogReader(
+ CalciteSchema.from(rootSchema),
caseSensitive,
- OptiqSchema.from(defaultSchema).path(null),
+ CalciteSchema.from(defaultSchema).path(null),
typeFactory);
}
@@ -260,21 +268,18 @@ public class PlannerImpl implements Planner {
/** Stage of a statement in the query-preparation lifecycle. */
private enum State {
STATE_0_CLOSED {
- @Override
- void from(PlannerImpl planner) {
+ @Override void from(PlannerImpl planner) {
planner.close();
}
},
STATE_1_RESET {
- @Override
- void from(PlannerImpl planner) {
+ @Override void from(PlannerImpl planner) {
planner.ensure(STATE_0_CLOSED);
planner.reset();
}
},
STATE_2_READY {
- @Override
- void from(PlannerImpl planner) {
+ @Override void from(PlannerImpl planner) {
STATE_1_RESET.from(planner);
planner.ready();
}
http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/a0ba73cd/core/src/main/java/org/apache/calcite/prepare/Prepare.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/prepare/Prepare.java b/core/src/main/java/org/apache/calcite/prepare/Prepare.java
index 310c219..5f33120 100644
--- a/core/src/main/java/org/apache/calcite/prepare/Prepare.java
+++ b/core/src/main/java/org/apache/calcite/prepare/Prepare.java
@@ -14,36 +14,50 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package net.hydromatic.optiq.prepare;
-
-import net.hydromatic.optiq.DataContext;
-import net.hydromatic.optiq.impl.StarTable;
-import net.hydromatic.optiq.impl.java.JavaTypeFactory;
-import net.hydromatic.optiq.jdbc.OptiqPrepare;
-import net.hydromatic.optiq.jdbc.OptiqSchema;
-import net.hydromatic.optiq.runtime.Bindable;
-import net.hydromatic.optiq.runtime.Hook;
-import net.hydromatic.optiq.runtime.Typed;
-import net.hydromatic.optiq.tools.Program;
-import net.hydromatic.optiq.tools.Programs;
-
-import org.eigenbase.rel.*;
-import org.eigenbase.relopt.*;
-import org.eigenbase.reltype.RelDataType;
-import org.eigenbase.rex.RexBuilder;
-import org.eigenbase.rex.RexExecutorImpl;
-import org.eigenbase.sql.*;
-import org.eigenbase.sql.validate.*;
-import org.eigenbase.sql2rel.SqlToRelConverter;
-import org.eigenbase.trace.EigenbaseTimingTracer;
-import org.eigenbase.trace.EigenbaseTrace;
-import org.eigenbase.util.Holder;
-import org.eigenbase.util.Pair;
+package org.apache.calcite.prepare;
+
+import org.apache.calcite.DataContext;
+import org.apache.calcite.adapter.java.JavaTypeFactory;
+import org.apache.calcite.jdbc.CalcitePrepare;
+import org.apache.calcite.jdbc.CalciteSchema;
+import org.apache.calcite.plan.Convention;
+import org.apache.calcite.plan.RelImplementor;
+import org.apache.calcite.plan.RelOptLattice;
+import org.apache.calcite.plan.RelOptMaterialization;
+import org.apache.calcite.plan.RelOptPlanner;
+import org.apache.calcite.plan.RelOptSchema;
+import org.apache.calcite.plan.RelOptTable;
+import org.apache.calcite.plan.RelOptUtil;
+import org.apache.calcite.plan.RelTraitSet;
+import org.apache.calcite.rel.RelNode;
+import org.apache.calcite.rel.logical.LogicalTableModify;
+import org.apache.calcite.rel.type.RelDataType;
+import org.apache.calcite.rex.RexBuilder;
+import org.apache.calcite.rex.RexExecutorImpl;
+import org.apache.calcite.runtime.Bindable;
+import org.apache.calcite.runtime.Hook;
+import org.apache.calcite.runtime.Typed;
+import org.apache.calcite.schema.impl.StarTable;
+import org.apache.calcite.sql.SqlExplain;
+import org.apache.calcite.sql.SqlExplainLevel;
+import org.apache.calcite.sql.SqlKind;
+import org.apache.calcite.sql.SqlNode;
+import org.apache.calcite.sql.validate.SqlValidator;
+import org.apache.calcite.sql.validate.SqlValidatorCatalogReader;
+import org.apache.calcite.sql.validate.SqlValidatorTable;
+import org.apache.calcite.sql2rel.SqlToRelConverter;
+import org.apache.calcite.tools.Program;
+import org.apache.calcite.tools.Programs;
+import org.apache.calcite.util.Holder;
+import org.apache.calcite.util.Pair;
+import org.apache.calcite.util.trace.CalciteTimingTracer;
+import org.apache.calcite.util.trace.CalciteTrace;
import com.google.common.collect.ImmutableList;
import java.lang.reflect.Type;
-import java.util.*;
+import java.util.Collections;
+import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
@@ -52,16 +66,16 @@ import java.util.logging.Logger;
* the process of preparing and executing SQL expressions.
*/
public abstract class Prepare {
- protected static final Logger LOGGER = EigenbaseTrace.getStatementTracer();
+ protected static final Logger LOGGER = CalciteTrace.getStatementTracer();
- protected final OptiqPrepare.Context context;
+ protected final CalcitePrepare.Context context;
protected final CatalogReader catalogReader;
protected String queryString = null;
/**
* Convention via which results should be returned by execution.
*/
protected final Convention resultConvention;
- protected EigenbaseTimingTracer timingTracer;
+ protected CalciteTimingTracer timingTracer;
protected List<List<String>> fieldOrigins;
protected RelDataType parameterRowType;
@@ -73,7 +87,7 @@ public abstract class Prepare {
}
};
- public Prepare(OptiqPrepare.Context context, CatalogReader catalogReader,
+ public Prepare(CalcitePrepare.Context context, CatalogReader catalogReader,
Convention resultConvention) {
assert context != null;
this.context = context;
@@ -101,7 +115,7 @@ public abstract class Prepare {
*/
protected RelNode optimize(RelDataType logicalRowType, final RelNode rootRel,
final List<Materialization> materializations,
- final List<OptiqSchema.LatticeEntry> lattices) {
+ final List<CalciteSchema.LatticeEntry> lattices) {
final RelOptPlanner planner = rootRel.getCluster().getPlanner();
planner.setRoot(rootRel);
@@ -119,8 +133,8 @@ public abstract class Prepare {
materialization.starRelOptTable));
}
- for (OptiqSchema.LatticeEntry lattice : lattices) {
- final OptiqSchema.TableEntry starTable = lattice.getStarTable();
+ for (CalciteSchema.LatticeEntry lattice : lattices) {
+ final CalciteSchema.TableEntry starTable = lattice.getStarTable();
final JavaTypeFactory typeFactory = context.getTypeFactory();
final RelOptTableImpl starRelOptTable =
RelOptTableImpl.create(catalogReader,
@@ -174,7 +188,7 @@ public abstract class Prepare {
SqlValidator validator,
boolean needsValidation,
List<Materialization> materializations,
- List<OptiqSchema.LatticeEntry> lattices) {
+ List<CalciteSchema.LatticeEntry> lattices) {
return prepareSql(
sqlQuery,
sqlQuery,
@@ -192,7 +206,7 @@ public abstract class Prepare {
SqlValidator validator,
boolean needsValidation,
List<Materialization> materializations,
- List<OptiqSchema.LatticeEntry> lattices) {
+ List<CalciteSchema.LatticeEntry> lattices) {
queryString = sqlQuery.toString();
init(runtimeContextClass);
@@ -285,20 +299,20 @@ public abstract class Prepare {
kind);
}
- protected TableModificationRel.Operation mapTableModOp(
+ protected LogicalTableModify.Operation mapTableModOp(
boolean isDml, SqlKind sqlKind) {
if (!isDml) {
return null;
}
switch (sqlKind) {
case INSERT:
- return TableModificationRel.Operation.INSERT;
+ return LogicalTableModify.Operation.INSERT;
case DELETE:
- return TableModificationRel.Operation.DELETE;
+ return LogicalTableModify.Operation.DELETE;
case MERGE:
- return TableModificationRel.Operation.MERGE;
+ return LogicalTableModify.Operation.MERGE;
case UPDATE:
- return TableModificationRel.Operation.UPDATE;
+ return LogicalTableModify.Operation.UPDATE;
default:
return null;
}
@@ -329,7 +343,7 @@ public abstract class Prepare {
/**
* Walks over a tree of relational expressions, replacing each
- * {@link org.eigenbase.rel.RelNode} with a 'slimmed down' relational
+ * {@link org.apache.calcite.rel.RelNode} with a 'slimmed down' relational
* expression that projects
* only the columns required by its consumer.
*
@@ -429,7 +443,7 @@ public abstract class Prepare {
return false;
}
- public TableModificationRel.Operation getTableModOp() {
+ public LogicalTableModify.Operation getTableModOp() {
return null;
}
@@ -465,7 +479,7 @@ public abstract class Prepare {
* Returns the table modification operation corresponding to this
* statement if it is a table modification statement; otherwise null.
*/
- TableModificationRel.Operation getTableModOp();
+ LogicalTableModify.Operation getTableModOp();
/**
* Returns a list describing, for each result field, the origin of the
@@ -495,7 +509,7 @@ public abstract class Prepare {
protected final RelDataType parameterRowType;
protected final RelDataType rowType;
protected final boolean isDml;
- protected final TableModificationRel.Operation tableModOp;
+ protected final LogicalTableModify.Operation tableModOp;
protected final List<List<String>> fieldOrigins;
public PreparedResultImpl(
@@ -503,7 +517,7 @@ public abstract class Prepare {
RelDataType parameterRowType,
List<List<String>> fieldOrigins,
RelNode rootRel,
- TableModificationRel.Operation tableModOp,
+ LogicalTableModify.Operation tableModOp,
boolean isDml) {
assert rowType != null;
assert parameterRowType != null;
@@ -521,7 +535,7 @@ public abstract class Prepare {
return isDml;
}
- public TableModificationRel.Operation getTableModOp() {
+ public LogicalTableModify.Operation getTableModOp() {
return tableModOp;
}
@@ -556,18 +570,18 @@ public abstract class Prepare {
* process. */
public static class Materialization {
/** The table that holds the materialized data. */
- final OptiqSchema.TableEntry materializedTable;
+ final CalciteSchema.TableEntry materializedTable;
/** The query that derives the data. */
final String sql;
/** Relational expression for the table. Usually a
- * {@link TableAccessRel}. */
+ * {@link org.apache.calcite.rel.logical.LogicalTableScan}. */
RelNode tableRel;
/** Relational expression for the query to populate the table. */
RelNode queryRel;
/** Star table identified. */
private RelOptTable starRelOptTable;
- public Materialization(OptiqSchema.TableEntry materializedTable,
+ public Materialization(CalciteSchema.TableEntry materializedTable,
String sql) {
assert materializedTable != null;
assert sql != null;
http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/a0ba73cd/core/src/main/java/org/apache/calcite/prepare/QueryableRelBuilder.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/prepare/QueryableRelBuilder.java b/core/src/main/java/org/apache/calcite/prepare/QueryableRelBuilder.java
index d410b92..c2e4d14 100644
--- a/core/src/main/java/org/apache/calcite/prepare/QueryableRelBuilder.java
+++ b/core/src/main/java/org/apache/calcite/prepare/QueryableRelBuilder.java
@@ -14,19 +14,40 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package net.hydromatic.optiq.prepare;
-
-import net.hydromatic.linq4j.*;
-import net.hydromatic.linq4j.expressions.FunctionExpression;
-import net.hydromatic.linq4j.function.*;
-
-import net.hydromatic.optiq.QueryableTable;
-import net.hydromatic.optiq.TranslatableTable;
-import net.hydromatic.optiq.impl.AbstractTableQueryable;
-import net.hydromatic.optiq.jdbc.OptiqSchema;
-
-import org.eigenbase.rel.*;
-import org.eigenbase.rex.RexNode;
+package org.apache.calcite.prepare;
+
+import org.apache.calcite.jdbc.CalciteSchema;
+import org.apache.calcite.linq4j.Enumerable;
+import org.apache.calcite.linq4j.Grouping;
+import org.apache.calcite.linq4j.OrderedQueryable;
+import org.apache.calcite.linq4j.Queryable;
+import org.apache.calcite.linq4j.QueryableDefaults;
+import org.apache.calcite.linq4j.QueryableFactory;
+import org.apache.calcite.linq4j.function.BigDecimalFunction1;
+import org.apache.calcite.linq4j.function.DoubleFunction1;
+import org.apache.calcite.linq4j.function.EqualityComparer;
+import org.apache.calcite.linq4j.function.FloatFunction1;
+import org.apache.calcite.linq4j.function.Function1;
+import org.apache.calcite.linq4j.function.Function2;
+import org.apache.calcite.linq4j.function.IntegerFunction1;
+import org.apache.calcite.linq4j.function.LongFunction1;
+import org.apache.calcite.linq4j.function.NullableBigDecimalFunction1;
+import org.apache.calcite.linq4j.function.NullableDoubleFunction1;
+import org.apache.calcite.linq4j.function.NullableFloatFunction1;
+import org.apache.calcite.linq4j.function.NullableIntegerFunction1;
+import org.apache.calcite.linq4j.function.NullableLongFunction1;
+import org.apache.calcite.linq4j.function.Predicate1;
+import org.apache.calcite.linq4j.function.Predicate2;
+import org.apache.calcite.linq4j.tree.FunctionExpression;
+import org.apache.calcite.rel.RelNode;
+import org.apache.calcite.rel.core.Project;
+import org.apache.calcite.rel.logical.LogicalFilter;
+import org.apache.calcite.rel.logical.LogicalProject;
+import org.apache.calcite.rel.logical.LogicalTableScan;
+import org.apache.calcite.rex.RexNode;
+import org.apache.calcite.schema.QueryableTable;
+import org.apache.calcite.schema.TranslatableTable;
+import org.apache.calcite.schema.impl.AbstractTableQueryable;
import java.math.BigDecimal;
import java.util.Comparator;
@@ -42,7 +63,7 @@ import java.util.List;
* {@link #setRel} to assign the root of that tree to the {@link #rel} member
* variable.</p>
*
- * <p>To comply with the {@link net.hydromatic.linq4j.QueryableFactory}
+ * <p>To comply with the {@link org.apache.calcite.linq4j.QueryableFactory}
* interface, which is after all a factory, each method returns a dummy result
* such as {@code null} or {@code 0}.
* The caller will not use the result.
@@ -72,8 +93,8 @@ class QueryableRelBuilder<T> implements QueryableFactory<T> {
final AbstractTableQueryable tableQueryable =
(AbstractTableQueryable) queryable;
final QueryableTable table = tableQueryable.table;
- final OptiqSchema.TableEntry tableEntry =
- OptiqSchema.from(tableQueryable.schema)
+ final CalciteSchema.TableEntry tableEntry =
+ CalciteSchema.from(tableQueryable.schema)
.add(tableQueryable.tableName, tableQueryable.table);
final RelOptTableImpl relOptTable =
RelOptTableImpl.create(null, table.getRowType(translator.typeFactory),
@@ -81,7 +102,7 @@ class QueryableRelBuilder<T> implements QueryableFactory<T> {
if (table instanceof TranslatableTable) {
return ((TranslatableTable) table).toRel(translator, relOptTable);
} else {
- return new TableAccessRel(translator.cluster, relOptTable);
+ return new LogicalTableScan(translator.cluster, relOptTable);
}
}
return translator.translate(queryable.getExpression());
@@ -490,12 +511,12 @@ class QueryableRelBuilder<T> implements QueryableFactory<T> {
RelNode child = toRel(source);
List<RexNode> nodes = translator.toRexList(selector, child);
setRel(
- new ProjectRel(
+ new LogicalProject(
translator.cluster,
child,
nodes,
null,
- ProjectRelBase.Flags.BOXED));
+ Project.Flags.BOXED));
return null;
}
@@ -702,7 +723,7 @@ class QueryableRelBuilder<T> implements QueryableFactory<T> {
FunctionExpression<? extends Predicate1<T>> predicate) {
RelNode child = toRel(source);
RexNode node = translator.toRex(predicate, child);
- setRel(new FilterRel(translator.cluster, child, node));
+ setRel(new LogicalFilter(translator.cluster, child, node));
return source;
}
http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/a0ba73cd/core/src/main/java/org/apache/calcite/prepare/RelOptTableImpl.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/prepare/RelOptTableImpl.java b/core/src/main/java/org/apache/calcite/prepare/RelOptTableImpl.java
index 21b3dbf..a3377a0 100644
--- a/core/src/main/java/org/apache/calcite/prepare/RelOptTableImpl.java
+++ b/core/src/main/java/org/apache/calcite/prepare/RelOptTableImpl.java
@@ -14,23 +14,28 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package net.hydromatic.optiq.prepare;
-
-import net.hydromatic.linq4j.expressions.Expression;
-
-import net.hydromatic.optiq.*;
-import net.hydromatic.optiq.jdbc.OptiqSchema;
-import net.hydromatic.optiq.rules.java.EnumerableConvention;
-import net.hydromatic.optiq.rules.java.JavaRules;
-
-import org.eigenbase.rel.RelCollation;
-import org.eigenbase.rel.RelNode;
-import org.eigenbase.relopt.RelOptCluster;
-import org.eigenbase.relopt.RelOptSchema;
-import org.eigenbase.reltype.RelDataType;
-import org.eigenbase.sql.SqlAccessType;
-import org.eigenbase.sql.validate.SqlMonotonicity;
-import org.eigenbase.util.Util;
+package org.apache.calcite.prepare;
+
+import org.apache.calcite.adapter.enumerable.EnumerableConvention;
+import org.apache.calcite.adapter.enumerable.EnumerableInterpreter;
+import org.apache.calcite.adapter.enumerable.EnumerableTableScan;
+import org.apache.calcite.jdbc.CalciteSchema;
+import org.apache.calcite.linq4j.tree.Expression;
+import org.apache.calcite.plan.RelOptCluster;
+import org.apache.calcite.plan.RelOptSchema;
+import org.apache.calcite.rel.RelCollation;
+import org.apache.calcite.rel.RelNode;
+import org.apache.calcite.rel.type.RelDataType;
+import org.apache.calcite.schema.FilterableTable;
+import org.apache.calcite.schema.ProjectableFilterableTable;
+import org.apache.calcite.schema.QueryableTable;
+import org.apache.calcite.schema.ScannableTable;
+import org.apache.calcite.schema.Schemas;
+import org.apache.calcite.schema.Table;
+import org.apache.calcite.schema.TranslatableTable;
+import org.apache.calcite.sql.SqlAccessType;
+import org.apache.calcite.sql.validate.SqlMonotonicity;
+import org.apache.calcite.util.Util;
import com.google.common.base.Function;
import com.google.common.base.Functions;
@@ -42,7 +47,7 @@ import java.util.Collections;
import java.util.List;
/**
- * Implementation of {@link org.eigenbase.relopt.RelOptTable}.
+ * Implementation of {@link org.apache.calcite.plan.RelOptTable}.
*/
public class RelOptTableImpl implements Prepare.PreparingTable {
private final RelOptSchema schema;
@@ -90,7 +95,7 @@ public class RelOptTableImpl implements Prepare.PreparingTable {
}
public static RelOptTableImpl create(RelOptSchema schema, RelDataType rowType,
- final OptiqSchema.TableEntry tableEntry, Double rowCount) {
+ final CalciteSchema.TableEntry tableEntry, Double rowCount) {
Function<Class, Expression> expressionFunction;
final Table table = tableEntry.getTable();
if (table instanceof QueryableTable) {
@@ -143,9 +148,9 @@ public class RelOptTableImpl implements Prepare.PreparingTable {
if (clazz.isInstance(table)) {
return clazz.cast(table);
}
- if (clazz == OptiqSchema.class) {
+ if (clazz == CalciteSchema.class) {
return clazz.cast(
- Schemas.subSchema(((OptiqCatalogReader) schema).rootSchema,
+ Schemas.subSchema(((CalciteCatalogReader) schema).rootSchema,
Util.skipLast(getQualifiedName())));
}
return null;
@@ -178,11 +183,11 @@ public class RelOptTableImpl implements Prepare.PreparingTable {
}
RelOptCluster cluster = context.getCluster();
Class elementType = deduceElementType();
- final RelNode scan = new JavaRules.EnumerableTableAccessRel(cluster,
+ final RelNode scan = new EnumerableTableScan(cluster,
cluster.traitSetOf(EnumerableConvention.INSTANCE), this, elementType);
if (table instanceof FilterableTable
|| table instanceof ProjectableFilterableTable) {
- return new JavaRules.EnumerableInterpreterRel(cluster, scan.getTraitSet(),
+ return new EnumerableInterpreter(cluster, scan.getTraitSet(),
scan, 1d);
}
return scan;
http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/a0ba73cd/core/src/main/java/org/apache/calcite/prepare/package-info.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/prepare/package-info.java b/core/src/main/java/org/apache/calcite/prepare/package-info.java
index 88efbe3..0d4dd6e 100644
--- a/core/src/main/java/org/apache/calcite/prepare/package-info.java
+++ b/core/src/main/java/org/apache/calcite/prepare/package-info.java
@@ -18,6 +18,6 @@
/**
* Preparation of queries (parsing, planning and implementation).
*/
-package net.hydromatic.optiq.prepare;
+package org.apache.calcite.prepare;
// End package-info.java