Skip to content

Commit

Permalink
Simplify bucket reducer logic
Browse files Browse the repository at this point in the history
  • Loading branch information
szehon-ho committed Apr 3, 2024
1 parent ad61b0c commit 0356f9e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 +568,8 @@ case class EnsureRequirements(
child, values, joinKeyPositions, reducers, applyPartialClustering, replicatePartitions))
}

private def reduceCommonPartValues(commonPartValues: Seq[(InternalRow, Int)],
private def reduceCommonPartValues(
commonPartValues: Seq[(InternalRow, Int)],
expressions: Seq[Expression],
reducers: Option[Seq[Option[Reducer[_, _]]]]) = {
reducers match {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,20 +92,12 @@ object BucketFunction extends ScalarFunction[Int] with ReducibleFunction[Int, In
otherNumBuckets: Int): Reducer[Int, Int] = {

if (otherFunc == BucketFunction) {
if ((thisNumBuckets > otherNumBuckets)
&& (thisNumBuckets % otherNumBuckets == 0)) {
BucketReducer(thisNumBuckets, otherNumBuckets)
} else {
val gcd = this.gcd(thisNumBuckets, otherNumBuckets)
if (gcd != thisNumBuckets) {
BucketReducer(thisNumBuckets, gcd)
} else {
null
}
val gcd = this.gcd(thisNumBuckets, otherNumBuckets)
if (gcd != thisNumBuckets) {
return BucketReducer(thisNumBuckets, gcd)
}
} else {
null
}
null
}

private def gcd(a: Int, b: Int): Int = BigInt(a).gcd(BigInt(b)).toInt
Expand Down

0 comments on commit 0356f9e

Please sign in to comment.