You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@iceberg.apache.org by "huaxingao (via GitHub)" <gi...@apache.org> on 2025/05/30 06:26:18 UTC

Re: [PR] spark 4.0: SPJ: add bucket reducer using gcd [iceberg]

huaxingao commented on code in PR #13167:
URL: https://github.com/apache/iceberg/pull/13167#discussion_r2115224408


##########
spark/v4.0/spark/src/main/java/org/apache/iceberg/spark/functions/BucketFunction.java:
##########
@@ -128,6 +133,23 @@ public String name() {
     public DataType resultType() {
       return DataTypes.IntegerType;
     }
+
+    public int gcd(int num1, int num2) {
+      return BigInteger.valueOf(num1).gcd(BigInteger.valueOf(num2)).intValueExact();
+    }
+
+    @Override
+    public Reducer<Integer, Integer> reducer(
+        int thisNumBuckets, ReducibleFunction<?, ?> otherBucketFunction, int otherNumBuckets) {
+
+      if (otherBucketFunction instanceof BucketBase) {
+        int commonDivisor = gcd(thisNumBuckets, otherNumBuckets);
+        if (commonDivisor > 1 && commonDivisor != thisNumBuckets) {
+          return new BucketReducer(commonDivisor);
+        }
+      }

Review Comment:
   nit: can we add an empty line in between?



-- 
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: issues-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org