@Override public int hashCode() { return Objects.hash(this.pipeline, this.getAll()); } }
@Override public PCollection<T> expand(PCollectionList<T> input) { Map<PCollection<T>, Integer> instances = new HashMap<>(); for (PCollection<T> pCollection : input.getAll()) { int existing = instances.get(pCollection) == null ? 0 : instances.get(pCollection); instances.put(pCollection, existing + 1); } PCollectionList<T> output = PCollectionList.empty(input.getPipeline()); for (Map.Entry<PCollection<T>, Integer> instanceEntry : instances.entrySet()) { if (instanceEntry.getValue().equals(1)) { output = output.and(instanceEntry.getKey()); } else { String duplicationName = String.format("Multiply %s", instanceEntry.getKey().getName()); PCollection<T> duplicated = instanceEntry .getKey() .apply(duplicationName, ParDo.of(new DuplicateFn<>(instanceEntry.getValue()))); output = output.and(duplicated); } } return output.apply(Flatten.pCollections()); } }
WindowingStrategy<?, ?> windowingStrategy; IsBounded isBounded = IsBounded.BOUNDED; if (!inputs.getAll().isEmpty()) { windowingStrategy = inputs.get(0).getWindowingStrategy(); for (PCollection<?> input : inputs.getAll()) { WindowingStrategy<?, ?> other = input.getWindowingStrategy(); if (!windowingStrategy.getWindowFn().isCompatible(other.getWindowFn())) { isBounded, inputs.getAll().isEmpty() ? null : inputs.get(0).getCoder());
@Test public void getInputEmptySucceeds() { PTransformReplacement<PCollectionList<Long>, PCollection<Long>> replacement = factory.getReplacementTransform( AppliedPTransform.of( "nonEmptyInput", Collections.emptyMap(), Collections.emptyMap(), Flatten.pCollections(), pipeline)); assertThat(replacement.getInput().getAll(), emptyIterable()); }
assertThat(pcList.getAll(), contains(boundedCount, maxReadTimeCount, unboundedCount)); withOneCreate.getAll(), contains(boundedCount, maxReadTimeCount, unboundedCount, createTwo)); .and(ImmutableList.of(boundedCount, maxReadTimeCount)); assertThat( fromEmpty.getAll(), contains(unboundedCount, createOne, boundedCount, maxReadTimeCount));
@Test @Category(NeedsRunner.class) public void testDroppedPartition() { // Compute the set of integers either 1 or 2 mod 3, the hard way. PCollectionList<Integer> outputs = pipeline .apply(Create.of(2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12)) .apply(Partition.of(3, new ModFn())); List<PCollection<Integer>> outputsList = new ArrayList<>(outputs.getAll()); outputsList.remove(0); outputs = PCollectionList.of(outputsList); assertTrue(outputs.size() == 2); PCollection<Integer> output = outputs.apply(Flatten.pCollections()); PAssert.that(output).containsInAnyOrder(2, 4, 5, 7, 8, 10, 11); pipeline.run(); }