peter-toth commented on code in PR #54182:
URL: https://github.com/apache/spark/pull/54182#discussion_r2779109324
##########
sql/catalyst/src/test/scala/org/apache/spark/sql/connector/catalog/InMemoryBaseTable.scala:
##########
@@ -236,15 +236,26 @@ abstract class InMemoryBaseTable(
case (v, t) =>
throw new IllegalArgumentException(s"Match: unsupported
argument(s) type - ($v, $t)")
}
+ // the result should be consistent with BucketFunctions defined at
transformFunctions.scala
case BucketTransform(numBuckets, cols, _) =>
- val valueTypePairs = cols.map(col => extractor(col.fieldNames,
cleanedSchema, row))
- var valueHashCode = 0
- valueTypePairs.foreach( pair =>
- if ( pair._1 != null) valueHashCode += pair._1.hashCode()
- )
- var dataTypeHashCode = 0
- valueTypePairs.foreach(dataTypeHashCode += _._2.hashCode())
- ((valueHashCode + 31 * dataTypeHashCode) & Integer.MAX_VALUE) %
numBuckets
+ val hash: Long = cols.foldLeft(0L) { (acc, col) =>
+ val valueHash = extractor(col.fieldNames, cleanedSchema, row) match {
+ case (value: Byte, _: ByteType) => value.toLong
+ case (value: Short, _: ShortType) => value.toLong
+ case (value: Int, _: IntegerType) => value.toLong
+ case (value: Long, _: LongType) => value
+ case (value: Long, _: TimestampType) => value
+ case (value: Long, _: TimestampNTZType) => value
+ case (value: UTF8String, _: StringType) =>
+ value.hashCode.toLong
+ case (value: Array[Byte], BinaryType) =>
+ util.Arrays.hashCode(value).toLong
+ case (v, t) =>
+ throw new IllegalArgumentException(s"Match: unsupported
argument(s) type - ($v, $t)")
+ }
+ (acc + valueHash) & 0xFFFFFFFFFFFFL
Review Comment:
Ah, this is needed because `% N` can return negative results, isn't it? That
seems like problem at both places as bucket N should return max N different
values.
--
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]