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 2015/02/18 22:19:38 UTC
incubator-calcite git commit: [CALCITE-593] Validator in Frameworks
should expand identifiers (Jinfeng Ni)
Repository: incubator-calcite
Updated Branches:
refs/heads/master 18d4f70a7 -> f9db1ee92
[CALCITE-593] Validator in Frameworks should expand identifiers (Jinfeng Ni)
Change SqlValidator in Frameworks to expand identifiers by default, the same behavior as CalcitePrepareImpl.
Close apache/incubator-calcite#51
Project: http://git-wip-us.apache.org/repos/asf/incubator-calcite/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-calcite/commit/f9db1ee9
Tree: http://git-wip-us.apache.org/repos/asf/incubator-calcite/tree/f9db1ee9
Diff: http://git-wip-us.apache.org/repos/asf/incubator-calcite/diff/f9db1ee9
Branch: refs/heads/master
Commit: f9db1ee9210a04f7a3ddae23e52e26be1669debb
Parents: 18d4f70
Author: Jinfeng Ni <jn...@apache.org>
Authored: Mon Feb 9 17:22:10 2015 -0800
Committer: julianhyde <jh...@apache.org>
Committed: Wed Feb 18 12:53:20 2015 -0800
----------------------------------------------------------------------
.../org/apache/calcite/prepare/PlannerImpl.java | 2 ++
.../apache/calcite/tools/FrameworksTest.java | 29 ++++++++++++++++++++
2 files changed, 31 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/f9db1ee9/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 accdbf3..aac0c9a 100644
--- a/core/src/main/java/org/apache/calcite/prepare/PlannerImpl.java
+++ b/core/src/main/java/org/apache/calcite/prepare/PlannerImpl.java
@@ -168,6 +168,7 @@ public class PlannerImpl implements Planner {
this.validator =
new CalciteSqlValidator(
operatorTable, createCatalogReader(), typeFactory);
+ this.validator.setIdentifierExpansion(true);
try {
validatedSqlNode = validator.validate(sqlNode);
} catch (RuntimeException e) {
@@ -210,6 +211,7 @@ public class PlannerImpl implements Planner {
createCatalogReader().withSchemaPath(schemaPath);
final SqlValidator validator = new CalciteSqlValidator(operatorTable,
catalogReader, typeFactory);
+ validator.setIdentifierExpansion(true);
final SqlNode validatedSqlNode = validator.validate(sqlNode);
final SqlToRelConverter sqlToRelConverter = new SqlToRelConverter(
http://git-wip-us.apache.org/repos/asf/incubator-calcite/blob/f9db1ee9/core/src/test/java/org/apache/calcite/tools/FrameworksTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/calcite/tools/FrameworksTest.java b/core/src/test/java/org/apache/calcite/tools/FrameworksTest.java
index 288adf3..48759a6 100644
--- a/core/src/test/java/org/apache/calcite/tools/FrameworksTest.java
+++ b/core/src/test/java/org/apache/calcite/tools/FrameworksTest.java
@@ -37,9 +37,12 @@ import org.apache.calcite.schema.SchemaPlus;
import org.apache.calcite.schema.Table;
import org.apache.calcite.schema.impl.AbstractTable;
import org.apache.calcite.server.CalciteServerStatement;
+import org.apache.calcite.sql.SqlDialect;
import org.apache.calcite.sql.SqlExplainLevel;
+import org.apache.calcite.sql.SqlNode;
import org.apache.calcite.sql.fun.SqlStdOperatorTable;
import org.apache.calcite.sql.type.SqlTypeName;
+import org.apache.calcite.test.CalciteAssert;
import org.apache.calcite.util.Util;
import org.junit.Test;
@@ -161,6 +164,32 @@ public class FrameworksTest {
});
}
+ /** Tests that the validator expands identifiers by default.
+ *
+ * <p>Test case for
+ * [<a href="https://issues.apache.org/jira/browse/CALCITE-593">CALCITE-593</a>]
+ * "Validator in Frameworks should expand identifiers".
+ */
+ @Test public void testFrameworksValidatorWithIdentifierExpansion()
+ throws Exception {
+ final SchemaPlus rootSchema = Frameworks.createRootSchema(true);
+ final FrameworkConfig config = Frameworks.newConfigBuilder()
+ .defaultSchema(
+ CalciteAssert.addSchema(rootSchema, CalciteAssert.SchemaSpec.HR))
+ .build();
+ final Planner planner = Frameworks.getPlanner(config);
+ SqlNode parse = planner.parse("select * from \"emps\" ");
+ SqlNode val = planner.validate(parse);
+
+ String valStr =
+ val.toSqlString(SqlDialect.DUMMY, false).getSql();
+
+ String expandedStr =
+ "SELECT `emps`.`empid`, `emps`.`deptno`, `emps`.`name`, `emps`.`salary`, `emps`.`commission`\n"
+ + "FROM `hr`.`emps` AS `emps`";
+ assertThat(valStr, equalTo(expandedStr));
+ }
+
/** Dummy type system, similar to Hive's, accessed via an INSTANCE member. */
public static class HiveLikeTypeSystem extends RelDataTypeSystemImpl {
public static final RelDataTypeSystem INSTANCE = new HiveLikeTypeSystem();