You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@spark.apache.org by ma...@apache.org on 2015/01/21 21:59:50 UTC
spark git commit: [SPARK-5244] [SQL] add coalesce() in sql parser
Repository: spark
Updated Branches:
refs/heads/master 3ee3ab592 -> 812d3679f
[SPARK-5244] [SQL] add coalesce() in sql parser
Author: Daoyuan Wang <da...@intel.com>
Closes #4040 from adrian-wang/coalesce and squashes the following commits:
0ac8e8f [Daoyuan Wang] add coalesce() in sql parser
Project: http://git-wip-us.apache.org/repos/asf/spark/repo
Commit: http://git-wip-us.apache.org/repos/asf/spark/commit/812d3679
Tree: http://git-wip-us.apache.org/repos/asf/spark/tree/812d3679
Diff: http://git-wip-us.apache.org/repos/asf/spark/diff/812d3679
Branch: refs/heads/master
Commit: 812d3679f5f97df7b667cbc3365a49866ebc02d5
Parents: 3ee3ab5
Author: Daoyuan Wang <da...@intel.com>
Authored: Wed Jan 21 12:59:41 2015 -0800
Committer: Michael Armbrust <mi...@databricks.com>
Committed: Wed Jan 21 12:59:41 2015 -0800
----------------------------------------------------------------------
.../scala/org/apache/spark/sql/catalyst/SqlParser.scala | 2 ++
.../src/test/scala/org/apache/spark/sql/SQLQuerySuite.scala | 9 +++++++++
2 files changed, 11 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/spark/blob/812d3679/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/SqlParser.scala
----------------------------------------------------------------------
diff --git a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/SqlParser.scala b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/SqlParser.scala
index 0b36d8b..388e2f7 100755
--- a/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/SqlParser.scala
+++ b/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/SqlParser.scala
@@ -51,6 +51,7 @@ class SqlParser extends AbstractSparkSQLParser {
protected val CACHE = Keyword("CACHE")
protected val CASE = Keyword("CASE")
protected val CAST = Keyword("CAST")
+ protected val COALESCE = Keyword("COALESCE")
protected val COUNT = Keyword("COUNT")
protected val DECIMAL = Keyword("DECIMAL")
protected val DESC = Keyword("DESC")
@@ -306,6 +307,7 @@ class SqlParser extends AbstractSparkSQLParser {
{ case s ~ p => Substring(s, p, Literal(Integer.MAX_VALUE)) }
| (SUBSTR | SUBSTRING) ~ "(" ~> expression ~ ("," ~> expression) ~ ("," ~> expression) <~ ")" ^^
{ case s ~ p ~ l => Substring(s, p, l) }
+ | COALESCE ~ "(" ~> repsep(expression, ",") <~ ")" ^^ { case exprs => Coalesce(exprs) }
| SQRT ~ "(" ~> expression <~ ")" ^^ { case exp => Sqrt(exp) }
| ABS ~ "(" ~> expression <~ ")" ^^ { case exp => Abs(exp) }
| ident ~ ("(" ~> repsep(expression, ",")) <~ ")" ^^
http://git-wip-us.apache.org/repos/asf/spark/blob/812d3679/sql/core/src/test/scala/org/apache/spark/sql/SQLQuerySuite.scala
----------------------------------------------------------------------
diff --git a/sql/core/src/test/scala/org/apache/spark/sql/SQLQuerySuite.scala b/sql/core/src/test/scala/org/apache/spark/sql/SQLQuerySuite.scala
index 03b44ca..64648ba 100644
--- a/sql/core/src/test/scala/org/apache/spark/sql/SQLQuerySuite.scala
+++ b/sql/core/src/test/scala/org/apache/spark/sql/SQLQuerySuite.scala
@@ -86,6 +86,15 @@ class SQLQuerySuite extends QueryTest with BeforeAndAfterAll {
setConf(SQLConf.CODEGEN_ENABLED, originalValue.toString)
}
+ test("Add Parser of SQL COALESCE()") {
+ checkAnswer(
+ sql("""SELECT COALESCE(1, 2)"""),
+ 1)
+ checkAnswer(
+ sql("SELECT COALESCE(null, null, null)"),
+ null)
+ }
+
test("SPARK-3176 Added Parser of SQL LAST()") {
checkAnswer(
sql("SELECT LAST(n) FROM lowerCaseData"),
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@spark.apache.org
For additional commands, e-mail: commits-help@spark.apache.org