spark git commit: [SPARK-20311][SQL] Support aliases for table value functions
Repository: spark Updated Branches: refs/heads/master b4c99f436 -> 8c67aa7f0 [SPARK-20311][SQL] Support aliases for table value functions ## What changes were proposed in this pull request? This pr added parsing rules to support aliases in table value functions. The previous pr (#17666) has been reverted because of the regression. This new pr fixed the regression and add tests in `SQLQueryTestSuite`. ## How was this patch tested? Added tests in `PlanParserSuite` and `SQLQueryTestSuite`. Author: Takeshi YamamuroCloses #17928 from maropu/SPARK-20311-3. Project: http://git-wip-us.apache.org/repos/asf/spark/repo Commit: http://git-wip-us.apache.org/repos/asf/spark/commit/8c67aa7f Tree: http://git-wip-us.apache.org/repos/asf/spark/tree/8c67aa7f Diff: http://git-wip-us.apache.org/repos/asf/spark/diff/8c67aa7f Branch: refs/heads/master Commit: 8c67aa7f00e0186abe05a1628faf2232b364a61f Parents: b4c99f4 Author: Takeshi Yamamuro Authored: Thu May 11 18:09:31 2017 +0800 Committer: Wenchen Fan Committed: Thu May 11 18:09:31 2017 +0800 -- .../apache/spark/sql/catalyst/parser/SqlBase.g4 | 20 .../analysis/ResolveTableValuedFunctions.scala | 22 -- .../sql/catalyst/analysis/unresolved.scala | 10 -- .../spark/sql/catalyst/parser/AstBuilder.scala | 17 --- .../sql/catalyst/analysis/AnalysisSuite.scala | 14 - .../sql/catalyst/parser/PlanParserSuite.scala | 13 +++- .../resources/sql-tests/inputs/inline-table.sql | 3 ++ .../sql-tests/inputs/table-valued-functions.sql | 3 ++ .../sql-tests/results/inline-table.sql.out | 32 +++- .../results/table-valued-functions.sql.out | 32 +++- 10 files changed, 147 insertions(+), 19 deletions(-) -- http://git-wip-us.apache.org/repos/asf/spark/blob/8c67aa7f/sql/catalyst/src/main/antlr4/org/apache/spark/sql/catalyst/parser/SqlBase.g4 -- diff --git a/sql/catalyst/src/main/antlr4/org/apache/spark/sql/catalyst/parser/SqlBase.g4 b/sql/catalyst/src/main/antlr4/org/apache/spark/sql/catalyst/parser/SqlBase.g4 index 14c511f..ed5450b 100644 --- a/sql/catalyst/src/main/antlr4/org/apache/spark/sql/catalyst/parser/SqlBase.g4 +++ b/sql/catalyst/src/main/antlr4/org/apache/spark/sql/catalyst/parser/SqlBase.g4 @@ -472,15 +472,23 @@ identifierComment ; relationPrimary -: tableIdentifier sample? (AS? strictIdentifier)? #tableName -| '(' queryNoWith ')' sample? (AS? strictIdentifier)? #aliasedQuery -| '(' relation ')' sample? (AS? strictIdentifier)? #aliasedRelation -| inlineTable #inlineTableDefault2 -| identifier '(' (expression (',' expression)*)? ')' #tableValuedFunction +: tableIdentifier sample? (AS? strictIdentifier)? #tableName +| '(' queryNoWith ')' sample? (AS? strictIdentifier)? #aliasedQuery +| '(' relation ')' sample? (AS? strictIdentifier)? #aliasedRelation +| inlineTable #inlineTableDefault2 +| functionTable#tableValuedFunction ; inlineTable -: VALUES expression (',' expression)* (AS? identifier identifierList?)? +: VALUES expression (',' expression)* tableAlias +; + +functionTable +: identifier '(' (expression (',' expression)*)? ')' tableAlias +; + +tableAlias +: (AS? strictIdentifier identifierList?)? ; rowFormat http://git-wip-us.apache.org/repos/asf/spark/blob/8c67aa7f/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/ResolveTableValuedFunctions.scala -- diff --git a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/ResolveTableValuedFunctions.scala b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/ResolveTableValuedFunctions.scala index de6de24..dad1340 100644 --- a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/ResolveTableValuedFunctions.scala +++ b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/ResolveTableValuedFunctions.scala @@ -19,8 +19,8 @@ package org.apache.spark.sql.catalyst.analysis import java.util.Locale -import org.apache.spark.sql.catalyst.expressions.Expression -import org.apache.spark.sql.catalyst.plans.logical.{LogicalPlan, Range} +import org.apache.spark.sql.catalyst.expressions.{Alias, Expression} +import org.apache.spark.sql.catalyst.plans.logical.{LogicalPlan, Project, Range} import org.apache.spark.sql.catalyst.rules._ import org.apache.spark.sql.types.{DataType, IntegerType, LongType} @@ -105,7 +105,7 @@ object
spark git commit: [SPARK-20311][SQL] Support aliases for table value functions
Repository: spark Updated Branches: refs/heads/branch-2.2 b3309676b -> 272d2a10d [SPARK-20311][SQL] Support aliases for table value functions ## What changes were proposed in this pull request? This pr added parsing rules to support aliases in table value functions. ## How was this patch tested? Added tests in `PlanParserSuite`. Author: Takeshi YamamuroCloses #17666 from maropu/SPARK-20311. (cherry picked from commit 714811d0b5bcb5d47c39782ff74f898d276ecc59) Signed-off-by: Wenchen Fan Project: http://git-wip-us.apache.org/repos/asf/spark/repo Commit: http://git-wip-us.apache.org/repos/asf/spark/commit/272d2a10 Tree: http://git-wip-us.apache.org/repos/asf/spark/tree/272d2a10 Diff: http://git-wip-us.apache.org/repos/asf/spark/diff/272d2a10 Branch: refs/heads/branch-2.2 Commit: 272d2a10d70588e1f80cc6579d4ec3c44b5bbfc2 Parents: b330967 Author: Takeshi Yamamuro Authored: Tue May 9 20:22:51 2017 +0800 Committer: Wenchen Fan Committed: Tue May 9 20:23:53 2017 +0800 -- .../apache/spark/sql/catalyst/parser/SqlBase.g4 | 20 -- .../analysis/ResolveTableValuedFunctions.scala | 22 +--- .../sql/catalyst/analysis/unresolved.scala | 10 +++-- .../spark/sql/catalyst/parser/AstBuilder.scala | 17 +++ .../sql/catalyst/analysis/AnalysisSuite.scala | 14 - .../sql/catalyst/parser/PlanParserSuite.scala | 13 +++- 6 files changed, 79 insertions(+), 17 deletions(-) -- http://git-wip-us.apache.org/repos/asf/spark/blob/272d2a10/sql/catalyst/src/main/antlr4/org/apache/spark/sql/catalyst/parser/SqlBase.g4 -- diff --git a/sql/catalyst/src/main/antlr4/org/apache/spark/sql/catalyst/parser/SqlBase.g4 b/sql/catalyst/src/main/antlr4/org/apache/spark/sql/catalyst/parser/SqlBase.g4 index 1ecb3d1..15e4dd4 100644 --- a/sql/catalyst/src/main/antlr4/org/apache/spark/sql/catalyst/parser/SqlBase.g4 +++ b/sql/catalyst/src/main/antlr4/org/apache/spark/sql/catalyst/parser/SqlBase.g4 @@ -472,15 +472,23 @@ identifierComment ; relationPrimary -: tableIdentifier sample? (AS? strictIdentifier)? #tableName -| '(' queryNoWith ')' sample? (AS? strictIdentifier)? #aliasedQuery -| '(' relation ')' sample? (AS? strictIdentifier)? #aliasedRelation -| inlineTable #inlineTableDefault2 -| identifier '(' (expression (',' expression)*)? ')' #tableValuedFunction +: tableIdentifier sample? (AS? strictIdentifier)? #tableName +| '(' queryNoWith ')' sample? (AS? strictIdentifier)? #aliasedQuery +| '(' relation ')' sample? (AS? strictIdentifier)? #aliasedRelation +| inlineTable #inlineTableDefault2 +| functionTable#tableValuedFunction ; inlineTable -: VALUES expression (',' expression)* (AS? identifier identifierList?)? +: VALUES expression (',' expression)* tableAlias +; + +functionTable +: identifier '(' (expression (',' expression)*)? ')' tableAlias +; + +tableAlias +: (AS? identifier identifierList?)? ; rowFormat http://git-wip-us.apache.org/repos/asf/spark/blob/272d2a10/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/ResolveTableValuedFunctions.scala -- diff --git a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/ResolveTableValuedFunctions.scala b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/ResolveTableValuedFunctions.scala index de6de24..dad1340 100644 --- a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/ResolveTableValuedFunctions.scala +++ b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/ResolveTableValuedFunctions.scala @@ -19,8 +19,8 @@ package org.apache.spark.sql.catalyst.analysis import java.util.Locale -import org.apache.spark.sql.catalyst.expressions.Expression -import org.apache.spark.sql.catalyst.plans.logical.{LogicalPlan, Range} +import org.apache.spark.sql.catalyst.expressions.{Alias, Expression} +import org.apache.spark.sql.catalyst.plans.logical.{LogicalPlan, Project, Range} import org.apache.spark.sql.catalyst.rules._ import org.apache.spark.sql.types.{DataType, IntegerType, LongType} @@ -105,7 +105,7 @@ object ResolveTableValuedFunctions extends Rule[LogicalPlan] { override def apply(plan: LogicalPlan): LogicalPlan = plan resolveOperators { case u: UnresolvedTableValuedFunction if u.functionArgs.forall(_.resolved) => - builtinFunctions.get(u.functionName.toLowerCase(Locale.ROOT))
spark git commit: [SPARK-20311][SQL] Support aliases for table value functions
Repository: spark Updated Branches: refs/heads/master 0d00c768a -> 714811d0b [SPARK-20311][SQL] Support aliases for table value functions ## What changes were proposed in this pull request? This pr added parsing rules to support aliases in table value functions. ## How was this patch tested? Added tests in `PlanParserSuite`. Author: Takeshi YamamuroCloses #17666 from maropu/SPARK-20311. Project: http://git-wip-us.apache.org/repos/asf/spark/repo Commit: http://git-wip-us.apache.org/repos/asf/spark/commit/714811d0 Tree: http://git-wip-us.apache.org/repos/asf/spark/tree/714811d0 Diff: http://git-wip-us.apache.org/repos/asf/spark/diff/714811d0 Branch: refs/heads/master Commit: 714811d0b5bcb5d47c39782ff74f898d276ecc59 Parents: 0d00c76 Author: Takeshi Yamamuro Authored: Tue May 9 20:22:51 2017 +0800 Committer: Wenchen Fan Committed: Tue May 9 20:22:51 2017 +0800 -- .../apache/spark/sql/catalyst/parser/SqlBase.g4 | 20 -- .../analysis/ResolveTableValuedFunctions.scala | 22 +--- .../sql/catalyst/analysis/unresolved.scala | 10 +++-- .../spark/sql/catalyst/parser/AstBuilder.scala | 17 +++ .../sql/catalyst/analysis/AnalysisSuite.scala | 14 - .../sql/catalyst/parser/PlanParserSuite.scala | 13 +++- 6 files changed, 79 insertions(+), 17 deletions(-) -- http://git-wip-us.apache.org/repos/asf/spark/blob/714811d0/sql/catalyst/src/main/antlr4/org/apache/spark/sql/catalyst/parser/SqlBase.g4 -- diff --git a/sql/catalyst/src/main/antlr4/org/apache/spark/sql/catalyst/parser/SqlBase.g4 b/sql/catalyst/src/main/antlr4/org/apache/spark/sql/catalyst/parser/SqlBase.g4 index 14c511f..41daf58 100644 --- a/sql/catalyst/src/main/antlr4/org/apache/spark/sql/catalyst/parser/SqlBase.g4 +++ b/sql/catalyst/src/main/antlr4/org/apache/spark/sql/catalyst/parser/SqlBase.g4 @@ -472,15 +472,23 @@ identifierComment ; relationPrimary -: tableIdentifier sample? (AS? strictIdentifier)? #tableName -| '(' queryNoWith ')' sample? (AS? strictIdentifier)? #aliasedQuery -| '(' relation ')' sample? (AS? strictIdentifier)? #aliasedRelation -| inlineTable #inlineTableDefault2 -| identifier '(' (expression (',' expression)*)? ')' #tableValuedFunction +: tableIdentifier sample? (AS? strictIdentifier)? #tableName +| '(' queryNoWith ')' sample? (AS? strictIdentifier)? #aliasedQuery +| '(' relation ')' sample? (AS? strictIdentifier)? #aliasedRelation +| inlineTable #inlineTableDefault2 +| functionTable#tableValuedFunction ; inlineTable -: VALUES expression (',' expression)* (AS? identifier identifierList?)? +: VALUES expression (',' expression)* tableAlias +; + +functionTable +: identifier '(' (expression (',' expression)*)? ')' tableAlias +; + +tableAlias +: (AS? identifier identifierList?)? ; rowFormat http://git-wip-us.apache.org/repos/asf/spark/blob/714811d0/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/ResolveTableValuedFunctions.scala -- diff --git a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/ResolveTableValuedFunctions.scala b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/ResolveTableValuedFunctions.scala index de6de24..dad1340 100644 --- a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/ResolveTableValuedFunctions.scala +++ b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/ResolveTableValuedFunctions.scala @@ -19,8 +19,8 @@ package org.apache.spark.sql.catalyst.analysis import java.util.Locale -import org.apache.spark.sql.catalyst.expressions.Expression -import org.apache.spark.sql.catalyst.plans.logical.{LogicalPlan, Range} +import org.apache.spark.sql.catalyst.expressions.{Alias, Expression} +import org.apache.spark.sql.catalyst.plans.logical.{LogicalPlan, Project, Range} import org.apache.spark.sql.catalyst.rules._ import org.apache.spark.sql.types.{DataType, IntegerType, LongType} @@ -105,7 +105,7 @@ object ResolveTableValuedFunctions extends Rule[LogicalPlan] { override def apply(plan: LogicalPlan): LogicalPlan = plan resolveOperators { case u: UnresolvedTableValuedFunction if u.functionArgs.forall(_.resolved) => - builtinFunctions.get(u.functionName.toLowerCase(Locale.ROOT)) match { + val resolvedFunc = builtinFunctions.get(u.functionName.toLowerCase(Locale.ROOT)) match { case Some(tvf)