advancedxy commented on code in PR #8259:
URL: https://github.com/apache/iceberg/pull/8259#discussion_r1296730292
##########
api/src/main/java/org/apache/iceberg/transforms/Bucket.java:
##########
@@ -265,4 +285,58 @@ protected int hash(BigDecimal value) {
return BucketUtil.hash(value);
}
}
+
+ private static class BucketStructLike extends Bucket<StructLike>
+ implements SerializableFunction<StructLike, Integer> {
+
+ private final Types.StructType type;
+
+ private BucketStructLike(int numBuckets, Types.StructType type) {
+ super(numBuckets);
+ this.type = type;
+ }
+
+ @Override
+ protected int hash(StructLike value) {
+ Hasher hasher = BucketUtil.hasher();
+ boolean isNull = true;
+ for (int i = 0; i < value.size(); i += 1) {
+ Type fieldType = type.fields().get(i).type();
+ Object val = value.get(i, fieldType.typeId().javaClass());
+ if (val == null) {
+ continue;
+ } else {
+ isNull = false;
+ }
+ switch (fieldType.typeId()) {
+ case INTEGER:
+ case DATE:
+ hasher.putLong((long) ((int) val));
+ break;
+ case LONG:
+ case TIME:
+ case TIMESTAMP:
+ hasher.putLong((long) val);
+ break;
+ case DECIMAL:
+ hasher.putBytes(((BigDecimal) val).unscaledValue().toByteArray());
+ break;
+ case STRING:
+ hasher.putString((CharSequence) val, StandardCharsets.UTF_8);
+ break;
+ case FIXED:
+ case BINARY:
+ hasher.putBytes((ByteBuffer) val);
+ break;
+ case UUID:
+ UUID uuid = (UUID) val;
+ hasher.putLong(Long.reverseBytes(uuid.getMostSignificantBits()));
+ hasher.putLong(Long.reverseBytes(uuid.getLeastSignificantBits()));
+ break;
+ }
+ }
+ Preconditions.checkArgument(!isNull, "All fields are null");
Review Comment:
just check here for now, if all fields are null, this bucket function should
produce null instead.
--
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]