AngersZhuuuu opened a new pull request #28107: [SPARK-31334][SQL] TypeCoercion 
should before then ResolveAggregateFunctions
URL: https://github.com/apache/spark/pull/28107
 
 
   ### What changes were proposed in this pull request?
   As I have show in https://issues.apache.org/jira/browse/SPARK-31334 's 
description,  same type of sql,  when one column type is different as string, 
catalyst can't analyze it right. 
   
   
   For test sql 
   ```
   test("xxxxxxxx") {
       Seq(
         ("1", "3"),
         ("2", "3"),
         ("3", "6"),
         ("4", "7"),
         ("5", "9"),
         ("6", "9")
       ).toDF("a", "b").createOrReplaceTempView("testData")
   
       val x = sql(
         """
           | SELECT b, sum(a) as a
           | FROM testData
           | GROUP BY b
           | HAVING sum(a) > 3
         """.stripMargin)
   
       x.explain()
       x.show()
     }
   ```
   When analyze having clause's condition  by ResolveAggregateFunctions 
   ```
   'Filter ('sum('a) > 3)
   +- Aggregate [b#181], [b#181, sum(a#180) AS a#184L]
      +- SubqueryAlias `testdata`
         +- Project [_1#177 AS a#180, _2#178 AS b#181]
            +- LocalRelation [_1#177, _2#178]
   ```
   Since `a` is StringType type and then aggregation's `agg` expression is 
unresolved (Sum. checkInputDataTypes()),  so  ResolveAggregateFunctions won't 
make a change on above logicalplan, then `sum(a)` in Filter condition will be 
resolved in ResolveReference and this a will be resolved as aggregation's 
output column a , then error happened .
   
   ### Why are the changes needed?
   Fix bug in analyzer
   
   ### Does this PR introduce any user-facing change?
   NO
   
   
   ### How was this patch tested?
   Added UT
   

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

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

Reply via email to