kennknowles commented on code in PR #31535: URL: https://github.com/apache/beam/pull/31535#discussion_r1630459765
########## runners/google-cloud-dataflow-java/src/main/java/org/apache/beam/runners/dataflow/RedistributeByKeyOverrideFactory.java: ########## @@ -0,0 +1,77 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.beam.runners.dataflow; + +import org.apache.beam.sdk.runners.AppliedPTransform; +import org.apache.beam.sdk.runners.PTransformOverrideFactory; +import org.apache.beam.sdk.transforms.PTransform; +import org.apache.beam.sdk.transforms.Redistribute.RedistributeByKey; +import org.apache.beam.sdk.util.construction.PTransformReplacements; +import org.apache.beam.sdk.util.construction.SingleInputOutputOverrideFactory; +import org.apache.beam.sdk.values.KV; +import org.apache.beam.sdk.values.PCollection; + +class RedistributeByKeyOverrideFactory<K, V> + extends SingleInputOutputOverrideFactory< + PCollection<KV<K, V>>, PCollection<KV<K, V>>, RedistributeByKey<K, V>> { + + private final DataflowRunner runner; + + RedistributeByKeyOverrideFactory(DataflowRunner runner) { + this.runner = runner; + } + + @Override + public PTransformReplacement<PCollection<KV<K, V>>, PCollection<KV<K, V>>> + getReplacementTransform( + AppliedPTransform<PCollection<KV<K, V>>, PCollection<KV<K, V>>, RedistributeByKey<K, V>> + transform) { + return PTransformOverrideFactory.PTransformReplacement.of( + PTransformReplacements.getSingletonMainInput(transform), + new DataflowRedistributeByKey<>( + runner, + transform.getTransform(), + PTransformReplacements.getSingletonMainOutput(transform))); + } + + /** Specialized implementation of {@link RedistributeByKey} for Dataflow pipelines. */ + private static class DataflowRedistributeByKey<K, V> + extends PTransform<PCollection<KV<K, V>>, PCollection<KV<K, V>>> { + + private final transient DataflowRunner runner; + private final RedistributeByKey<K, V> originalTransform; + private final transient PCollection<KV<K, V>> originalOutput; + + private DataflowRedistributeByKey( + DataflowRunner runner, + RedistributeByKey<K, V> originalTransform, + PCollection<KV<K, V>> originalOutput) { + this.runner = runner; + this.originalTransform = originalTransform; + this.originalOutput = originalOutput; + } + + @Override + public PCollection<KV<K, V>> expand(PCollection<KV<K, V>> input) { + if (originalTransform.getAllowDuplicates()) { + runner.maybeRecordPCollectionAllowDuplicates(originalOutput); + } + return input.apply(originalTransform); Review Comment: I suggest that you take the `expand` from the `ReshuffleOverrideFactory` and paste it here, then alter it to use a modified `DataflowRedistributeGroupByKey` transform that has an `allows_duplicates` field. Then in `DataflowPIpelineTranslator` you can add a registered translator for `DataflowRedistributeGroupByKey.class` that puts it into the v1beta3 proto. -- 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]
