Github user chenghao-intel commented on a diff in the pull request:

    https://github.com/apache/spark/pull/1055#discussion_r13784248
  
    --- Diff: sql/hive/src/main/scala/org/apache/spark/sql/hive/HiveQl.scala ---
    @@ -917,6 +919,19 @@ private[hive] object HiveQl {
         case Token(OR(), left :: right:: Nil) => Or(nodeToExpr(left), 
nodeToExpr(right))
         case Token(NOT(), child :: Nil) => Not(nodeToExpr(child))
     
    +    /* Case statements */
    +    case Token("TOK_FUNCTION", Token(WHEN(), Nil) :: branches) =>
    +      CaseWhen(branches.map(nodeToExpr))
    +    case Token("TOK_FUNCTION", Token(CASE(), Nil) :: branches) =>
    +      val transformed = branches.drop(1).sliding(2, 2).map {
    +        case Seq(condVal, value) =>
    +          // FIXME?: the key will get evaluated for multiple times in 
CaseWhen's eval(). Optimize?
    +          Seq(Equals(nodeToExpr(branches(0)), nodeToExpr(condVal)),
    --- End diff --
    
    Besides that can be optimized, it brings bug in some corner case. For 
example, if the first child expression is deterministic-less, ( e.g. UDF rand() 
), as computing it multiple times may get different values, which is not what 
we want here semantically. 
    Probably we need to create a new expression for wrapping common sub 
expression. I am OK to leave it for the further improving, but can you add more 
doc for this?


---
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.
---

Reply via email to