Return-Path: X-Original-To: apmail-calcite-commits-archive@www.apache.org Delivered-To: apmail-calcite-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 50D9218180 for ; Thu, 21 Jan 2016 22:38:41 +0000 (UTC) Received: (qmail 29660 invoked by uid 500); 21 Jan 2016 22:38:41 -0000 Delivered-To: apmail-calcite-commits-archive@calcite.apache.org Received: (qmail 29531 invoked by uid 500); 21 Jan 2016 22:38:41 -0000 Mailing-List: contact commits-help@calcite.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@calcite.apache.org Delivered-To: mailing list commits@calcite.apache.org Received: (qmail 27555 invoked by uid 99); 21 Jan 2016 22:38:39 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 21 Jan 2016 22:38:39 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 8B213E0E4C; Thu, 21 Jan 2016 22:38:39 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: jhyde@apache.org To: commits@calcite.apache.org Date: Thu, 21 Jan 2016 22:39:14 -0000 Message-Id: In-Reply-To: <8889549472d644efb2cca8ab5f60484a@git.apache.org> References: <8889549472d644efb2cca8ab5f60484a@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [37/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/heads/branch-release Commit: 0045e01f6178df5bcc8caf780040f3cff159bb20 Parents: a67b4a9 Author: Jinfeng Ni Authored: Tue Apr 7 03:34:06 2015 -0700 Committer: Julian Hyde 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 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ç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 validateAndGetType(SqlNode sqlNode) throws ValidationException; + + /** * Converts a SQL parse tree into a tree of relational expressions. * *

You must call {@link #validate(org.apache.calcite.sql.SqlNode)} first.