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 2016/01/23 01:30:48 UTC

[30/50] [abbrv] calcite git commit: [CALCITE-975] Allow Planner to return validated row type together with SqlNode

[CALCITE-975] Allow Planner to return validated row type together with SqlNode

close apache/calcite#184


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

Branch: refs/remotes/julianhyde/master
Commit: 0045e01f6178df5bcc8caf780040f3cff159bb20
Parents: a67b4a9
Author: Jinfeng Ni <jn...@maprtech.com>
Authored: Tue Apr 7 03:34:06 2015 -0700
Committer: Julian Hyde <jh...@apache.org>
Committed: Tue Jan 12 10:22:09 2016 -0800

----------------------------------------------------------------------
 .../java/org/apache/calcite/prepare/PlannerImpl.java     |  9 +++++++++
 core/src/main/java/org/apache/calcite/tools/Planner.java | 11 +++++++++++
 2 files changed, 20 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/calcite/blob/0045e01f/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 d75d9c9..18d9746 100644
--- a/core/src/main/java/org/apache/calcite/prepare/PlannerImpl.java
+++ b/core/src/main/java/org/apache/calcite/prepare/PlannerImpl.java
@@ -44,6 +44,7 @@ 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.Pair;
 import org.apache.calcite.util.Util;
 
 import com.google.common.collect.ImmutableList;
@@ -180,6 +181,14 @@ public class PlannerImpl implements Planner {
     return validatedSqlNode;
   }
 
+  public Pair<SqlNode, RelDataType> validateAndGetType(SqlNode sqlNode)
+      throws ValidationException {
+    final SqlNode validatedNode = this.validate(sqlNode);
+    final RelDataType type =
+        this.validator.getValidatedNodeType(validatedNode);
+    return Pair.of(validatedNode, type);
+  }
+
   public final RelNode convert(SqlNode sql) throws RelConversionException {
     return rel(sql).rel;
   }

http://git-wip-us.apache.org/repos/asf/calcite/blob/0045e01f/core/src/main/java/org/apache/calcite/tools/Planner.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/calcite/tools/Planner.java b/core/src/main/java/org/apache/calcite/tools/Planner.java
index 73c8047..8b2b25d 100644
--- a/core/src/main/java/org/apache/calcite/tools/Planner.java
+++ b/core/src/main/java/org/apache/calcite/tools/Planner.java
@@ -19,9 +19,11 @@ package org.apache.calcite.tools;
 import org.apache.calcite.plan.RelTraitSet;
 import org.apache.calcite.rel.RelNode;
 import org.apache.calcite.rel.RelRoot;
+import org.apache.calcite.rel.type.RelDataType;
 import org.apache.calcite.rel.type.RelDataTypeFactory;
 import org.apache.calcite.sql.SqlNode;
 import org.apache.calcite.sql.parser.SqlParseException;
+import org.apache.calcite.util.Pair;
 
 /**
  * A fa&ccedil;ade that covers Calcite's query planning process: parse SQL,
@@ -53,6 +55,15 @@ public interface Planner {
   SqlNode validate(SqlNode sqlNode) throws ValidationException;
 
   /**
+   * Validates a SQL statement.
+   *
+   * @param sqlNode Root node of the SQL parse tree.
+   * @return Validated node and its validated type.
+   * @throws ValidationException if not valid
+   */
+  Pair<SqlNode, RelDataType> validateAndGetType(SqlNode sqlNode) throws ValidationException;
+
+  /**
    * Converts a SQL parse tree into a tree of relational expressions.
    *
    * <p>You must call {@link #validate(org.apache.calcite.sql.SqlNode)} first.