Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup context from fanout API #4873

Merged
merged 1 commit into from
Jun 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class PairSCollectionFunctions[K, V](val self: SCollection[(K, V)]) {
* intermediate node.
*/
def withHotKeyFanout(hotKeyFanout: K => Int): SCollectionWithHotKeyFanout[K, V] =
new SCollectionWithHotKeyFanout(context, this, Left(hotKeyFanout))
new SCollectionWithHotKeyFanout(this, Left(hotKeyFanout))

/**
* Convert this SCollection to an [[SCollectionWithHotKeyFanout]] that uses an intermediate node
Expand All @@ -98,7 +98,7 @@ class PairSCollectionFunctions[K, V](val self: SCollection[(K, V)]) {
* constant value for every key
*/
def withHotKeyFanout(hotKeyFanout: Int): SCollectionWithHotKeyFanout[K, V] =
new SCollectionWithHotKeyFanout(context, this, Right(hotKeyFanout))
new SCollectionWithHotKeyFanout(this, Right(hotKeyFanout))

// =======================================================================
// CoGroups
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,11 @@ import org.apache.beam.sdk.transforms.{Combine, SerializableFunction}
* performing the full combine.
*/
class SCollectionWithHotKeyFanout[K, V] private[values] (
private val context: ScioContext,
private val self: PairSCollectionFunctions[K, V],
private val hotKeyFanout: Either[K => Int, Int]
) extends TransformNameable {

private[this] val context: ScioContext = self.self.context
implicit private[this] val valueCoder: Coder[V] = self.valueCoder

private def withFanout[K0, I, O](
Expand Down Expand Up @@ -73,7 +74,7 @@ class SCollectionWithHotKeyFanout[K, V] private[values] (
def aggregateByKey[A: Coder, U: Coder](aggregator: Aggregator[V, A, U]): SCollection[(K, U)] =
self.self.transform { in =>
val a = aggregator // defeat closure
new SCollectionWithHotKeyFanout(context, in.mapValues(a.prepare), hotKeyFanout)
new SCollectionWithHotKeyFanout(in.mapValues(a.prepare), hotKeyFanout)
.sumByKey(a.semigroup)
.mapValues(a.present)
}
Expand All @@ -87,7 +88,7 @@ class SCollectionWithHotKeyFanout[K, V] private[values] (
): SCollection[(K, U)] = {
self.self.transform { in =>
val a = aggregator // defeat closure
new SCollectionWithHotKeyFanout(context, in.mapValues(a.prepare), hotKeyFanout)
new SCollectionWithHotKeyFanout(in.mapValues(a.prepare), hotKeyFanout)
.foldByKey(a.monoid)
.mapValues(a.present)
}
Expand Down