Github user gatorsmile commented on a diff in the pull request:

    https://github.com/apache/spark/pull/19559#discussion_r147318831
  
    --- Diff: 
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/Analyzer.scala
 ---
    @@ -783,6 +783,37 @@ class Analyzer(
           }
         }
     
    +    /**
    +     * Literal functions do not require the user to specify braces when 
calling them
    +     * When an attributes is not resolvable, we try to resolve it as a 
literal function.
    +     */
    +    private def resolveAsLiteralFunctions(
    +        nameParts: Seq[String],
    +        attribute: UnresolvedAttribute,
    +        plan: LogicalPlan): Option[Expression] = {
    +      if (nameParts.length != 1) {
    +        return None
    +      }
    +      val isNamedExpression = plan match {
    +        case a @ Aggregate(_, aggs, _) if (aggs.contains(attribute)) =>
    +          true
    +        case p @ Project(projList, _) if (projList.contains(attribute)) =>
    +          true
    +        case _ =>
    +          false
    +      }
    +      val wrapper: Expression => Expression = if (isNamedExpression) {
    +        f => Alias(f, toPrettySQL(f))()
    +      } else {
    +        f => f
    +      }
    --- End diff --
    
    ```Scala
          if (nameParts.length != 1) return None
          val isNamedExpression = plan match {
            case Aggregate(_, aggs, _) => aggs.contains(attribute)
            case Project(projList, _) => projList.contains(attribute)
            case Window(windowExpressions, _, _, _) => 
windowExpressions.contains(attribute)
            case _ => false
          }
          val wrapper: Expression => Expression =
            if (isNamedExpression) f => Alias(f, usePrettyExpression(f).sql)() 
else identity
    ```


---

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to