rdblue commented on code in PR #5601:
URL: https://github.com/apache/iceberg/pull/5601#discussion_r954333720


##########
api/src/main/java/org/apache/iceberg/transforms/Truncate.java:
##########
@@ -71,16 +120,55 @@ public boolean preservesOrder() {
     return true;
   }
 
-  private static class TruncateInteger extends Truncate<Integer> {
-    private final int width;
+  @Override
+  public boolean satisfiesOrderOf(Transform<?, ?> other) {
+    if (this == other) {
+      return true;
+    }
+
+    if (!(other instanceof Truncate)) {
+      return false;
+    }
+
+    Truncate<?> otherTrunc = (Truncate<?>) other;
+    return otherTrunc.width <= width;
+  }
+
+  @Override
+  public boolean equals(Object o) {
+    if (this == o) {
+      return true;
+    } else if (!(o instanceof Truncate)) {
+      return false;
+    }
+
+    Truncate<?> that = (Truncate<?>) o;
+    return width == that.width;
+  }
+
+  @Override
+  public int hashCode() {
+    return Objects.hashCode(width);
+  }
 
+  @Override
+  public String toString() {
+    return "truncate[" + width + "]";
+  }
+
+  private static class TruncateInteger extends Truncate<Integer>
+      implements Function<Integer, Integer> {
     private TruncateInteger(int width) {
-      this.width = width;
+      super(width);
     }
 
     @Override
-    public Integer width() {
-      return width;
+    public Function<Integer, Integer> bind(Type type) {
+      if (type.typeId() == Type.TypeID.INTEGER) {
+        return this;
+      } else {
+        return null;

Review Comment:
   Fixed.



##########
api/src/main/java/org/apache/iceberg/transforms/Bucket.java:
##########
@@ -159,111 +172,53 @@ public Type getResultType(Type sourceType) {
     return Types.IntegerType.get();
   }
 
-  private static class BucketInteger extends Bucket<Integer> {
+  private static class BucketInteger extends Bucket<Integer> implements 
Function<Integer, Integer> {
     private BucketInteger(int numBuckets) {
       super(numBuckets);
     }
 
     @Override
-    public int hash(Integer value) {
+    protected int hash(Integer value) {
       return BucketUtil.hash(value);
     }
-
-    @Override
-    public boolean canTransform(Type type) {
-      return type.typeId() == TypeID.INTEGER || type.typeId() == TypeID.DATE;
-    }
   }
 
-  private static class BucketLong extends Bucket<Long> {
+  private static class BucketLong extends Bucket<Long> implements 
Function<Long, Integer> {
     private BucketLong(int numBuckets) {
       super(numBuckets);
     }
 
     @Override
-    public int hash(Long value) {
+    protected int hash(Long value) {
       return BucketUtil.hash(value);
     }
-
-    @Override
-    public boolean canTransform(Type type) {
-      return type.typeId() == TypeID.LONG
-          || type.typeId() == TypeID.TIME
-          || type.typeId() == TypeID.TIMESTAMP;
-    }
   }
 
-  // bucketing by Double is not allowed by the spec, but this has the float 
hash implementation
-  static class BucketFloat extends Bucket<Float> {
-    // used by tests because the factory method will not instantiate a bucket 
function for floats
-    BucketFloat(int numBuckets) {
-      super(numBuckets);
-    }
-
-    @Override
-    public int hash(Float value) {
-      return BucketUtil.hash(value);
-    }
-
-    @Override
-    public boolean canTransform(Type type) {
-      return type.typeId() == TypeID.FLOAT;
-    }
-  }
-
-  // bucketing by Double is not allowed by the spec, but this has the double 
hash implementation
-  static class BucketDouble extends Bucket<Double> {
-    // used by tests because the factory method will not instantiate a bucket 
function for doubles
-    BucketDouble(int numBuckets) {
-      super(numBuckets);
-    }
-
-    @Override
-    public int hash(Double value) {
-      return BucketUtil.hash(value);
-    }
-
-    @Override
-    public boolean canTransform(Type type) {
-      return type.typeId() == TypeID.DOUBLE;
-    }
-  }
-
-  private static class BucketString extends Bucket<CharSequence> {
+  private static class BucketString extends Bucket<CharSequence>
+      implements Function<CharSequence, Integer> {

Review Comment:
   Adding these.



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