Github user ravipesala commented on a diff in the pull request:
https://github.com/apache/spark/pull/2678#discussion_r18471169
--- Diff:
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/SqlParser.scala ---
@@ -333,6 +338,24 @@ class SqlParser extends StandardTokenParsers with
PackratParsers {
IF ~> "(" ~> expression ~ "," ~ expression ~ "," ~ expression <~ ")"
^^ {
case c ~ "," ~ t ~ "," ~ f => If(c,t,f)
} |
+ CASE ~> opt(expression) ~ (WHEN ~ expression ~ THEN ~ expression).* ~
+ opt(ELSE ~> expression) <~ END ^^ {
+ case c ~ l ~ el =>
+ var caseWhenExpr = l.map{x =>
+ x match {
+ case w ~ we ~ t ~ te =>
+ c match {
+ case Some(e) => Seq(EqualTo(e, we), te)
+ case None => Seq(we, te)
+ }
+ }
+ }.toSeq.reduce(_ ++ _)
+ caseWhenExpr = el match {
+ case Some(e) => caseWhenExpr ++ Seq(e)
+ case None => caseWhenExpr
+ }
+ CaseWhen(caseWhenExpr)
+ } |
--- End diff --
Awesome! code is greatly simplified. Thank you for your comments. Updated
code as per your suggestions.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]