jiwen624 opened a new pull request, #58975:
URL: https://github.com/apache/spark/pull/58975

   ### What changes were proposed in this pull request?
   Handle `UserDefinedType` in `HashMapGenerator.genComputeHash` by hashing its 
`sqlType`.
   
   ### Why are the changes needed?
   `GROUP BY` / `DISTINCT` on a UDT column with a primitive `sqlType` fails by 
default:
   
   ```scala
   UDTRegistration.register(classOf[java.time.Year].getName, 
classOf[YearUDT].getName)
   Seq((Year.of(2024), 1), (Year.of(2025), 2)).toDF("y", 
"v").groupBy("y").count().collect()
   
   [INTERNAL_ERROR] ... Caused by: scala.MatchError: YearUDT@... (of class 
org.apache.spark.sql.YearUDT)
     at org.apache.spark.sql.execution.aggregate.HashMapGenerator.genComputeHash
   ```
   
   The fast hash map is enabled for such a column, since 
`CodeGenerator.javaType` unwraps the UDT, but `genComputeHash` had no UDT case. 
The failure happens during code generation, so codegen fallback does not apply. 
`genEqual` already handles UDTs, so only hashing was missing. Same fix shape as 
SPARK-35412, SPARK-46536 and SPARK-52626.
   
   ### Does this PR introduce _any_ user-facing change?
   Yes, the query above now returns the correct result instead of 
`INTERNAL_ERROR`.
   
   
   ### How was this patch tested?
   Added UT case.
   
   ### Was this patch authored or co-authored using generative AI tooling?
   Yes.


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

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


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

Reply via email to