Skip to content
Merged
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 @@ -23,12 +23,13 @@
import java.util.Set;
import org.apache.beam.sdk.runners.AppliedPTransform;
import org.apache.beam.sdk.transforms.PTransform;
import org.apache.beam.sdk.util.Preconditions;
import org.apache.beam.sdk.values.PCollection;
import org.apache.beam.sdk.values.TupleTag;
import org.apache.beam.vendor.guava.v32_1_2_jre.com.google.common.collect.Iterables;
import org.checkerframework.checker.nullness.qual.Nullable;

/** Utilty class for PTransform replacements. */
@SuppressWarnings({"nullness", "keyfor"}) // TODO(https://github.com/apache/beam/issues/20497)
public class PTransformReplacements {
/**
* Gets the singleton input of an {@link AppliedPTransform}, ignoring any additional inputs
Expand All @@ -42,7 +43,7 @@ public static <T> PCollection<T> getSingletonMainInput(

private static <T> PCollection<T> getSingletonMainInput(
Map<TupleTag<?>, PCollection<?>> inputs, Set<TupleTag<?>> ignoredTags) {
PCollection<T> mainInput = null;
@Nullable PCollection<T> mainInput = null;
for (Map.Entry<TupleTag<?>, PCollection<?>> input : inputs.entrySet()) {
if (!ignoredTags.contains(input.getKey())) {
checkArgument(
Expand All @@ -58,16 +59,17 @@ private static <T> PCollection<T> getSingletonMainInput(
mainInput = (PCollection<T>) input.getValue();
}
}
checkArgument(
mainInput != null,
return Preconditions.checkArgumentNotNull(
mainInput,
"No main input found in inputs: Inputs %s, Side Input tags %s",
inputs,
ignoredTags);
return mainInput;
}

public static <T> PCollection<T> getSingletonMainOutput(
AppliedPTransform<?, PCollection<T>, ? extends PTransform<?, PCollection<T>>> transform) {
return (PCollection<T>) Iterables.getOnlyElement(transform.getOutputs().values());
return (PCollection<T>)
Preconditions.checkArgumentNotNull(
Iterables.getOnlyElement(transform.getOutputs().values()));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought it would throw NoSuchElementException if there was nothing.

}
}
Loading