wangyum commented on code in PR #38047:
URL: https://github.com/apache/spark/pull/38047#discussion_r1003326808


##########
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/TypeCoercion.scala:
##########
@@ -751,6 +753,49 @@ abstract class TypeCoercionBase {
     }
   }
 
+  /**
+   * Casts types according to bucket info for Equality expression.
+   */
+  object EqualityTypeCasts extends TypeCoercionRule {
+
+    private def isIntegralTypes(exprs: Seq[Expression]): Boolean = {
+      exprs.map(_.dataType).forall {
+        case _: IntegralType => true
+        case DecimalType.Fixed(_, 0) => true
+        case _ => false
+      }
+    }
+
+    override val transform: PartialFunction[Expression, Expression] = {
+      case b @ Equality(l: Attribute, r: Attribute)
+          if b.childrenResolved && l.dataType != r.dataType && 
isIntegralTypes(b.children) =>
+        // The result type is:
+        // 1. The attribute data type with larger bucket number.
+        // 2. The attribute data type with larger default size if it is not 
bucketed attribute.

Review Comment:
   That change is incorrect. For example:
   ```scala
   import org.apache.spark.sql.catalyst.expressions.{Cast, EmptyRow, Literal, 
Murmur3Hash, Pmod}
   import org.apache.spark.sql.types.LongType
   
   println(Pmod(new Murmur3Hash(Seq(Literal(100))), Literal(10)).eval(EmptyRow))
   println(Pmod(new Murmur3Hash(Seq(new Cast(Literal(100), LongType))), 
Literal(10)).eval(EmptyRow))
   ```
   
   Output:
   ```
   3
   0
   ```
   
   Related code:
   
https://github.com/apache/spark/blob/69aa727ff495f6698fe9b37e952dfaf36f1dd5eb/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/hash.scala#L505-L508
   



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