/** * Returns a {@link PTransform} identical to this, but with the specified side inputs to use in * {@link CombineFnWithContext}. */ public Globally<InputT, OutputT> withSideInputs(PCollectionView<?>... sideInputs) { return withSideInputs(Arrays.asList(sideInputs)); }
@Test public void testWithDefaultsPreservesSideInputs() { final PCollectionView<Integer> view = pipeline.apply(Create.of(1)).apply(Sum.integersGlobally().asSingletonView()); Combine.Globally<Integer, String> combine = Combine.globally(new TestCombineFnWithContext(view)) .withSideInputs(view) .withoutDefaults(); assertEquals(Collections.singletonList(view), combine.getSideInputs()); }
@Test public void testWithFanoutPreservesSideInputs() { final PCollectionView<Integer> view = pipeline.apply(Create.of(1)).apply(Sum.integersGlobally().asSingletonView()); Combine.Globally<Integer, String> combine = Combine.globally(new TestCombineFnWithContext(view)).withSideInputs(view).withFanout(1); assertEquals(Collections.singletonList(view), combine.getSideInputs()); } }
concatStringTag)) .withoutDefaults() .withSideInputs(ImmutableList.of(view))) .apply(WithKeys.of("global")) .apply(
Combine.globally(new TestCombineFnWithContext(globallySumView)) .withoutDefaults() .withSideInputs(globallySumView));
Combine.globally(new TestCombineFnWithContext(globallyFixedWindowsView)) .withoutDefaults() .withSideInputs(globallyFixedWindowsView));
input.apply(Combine.globally(combineFn).withSideInputs(sideInputs).withoutDefaults()); final AtomicReference<AppliedPTransform<?, ?, Combine.PerKey<?, ?, ?>>> combine = new AtomicReference<>();
Combine.globally(new TestCombineFnWithContext(globallySumView)) .withoutDefaults() .withSideInputs(globallySumView));
protected void runTestSimpleCombineWithContext( List<KV<String, Integer>> table, int globalSum, List<KV<String, String>> perKeyCombines, String[] globallyCombines) { PCollection<KV<String, Integer>> perKeyInput = createInput(pipeline, table); PCollection<Integer> globallyInput = perKeyInput.apply(Values.create()); PCollection<Integer> sum = globallyInput.apply("Sum", Combine.globally(new SumInts())); PCollectionView<Integer> globallySumView = sum.apply(View.asSingleton()); PCollection<KV<String, String>> combinePerKey = perKeyInput.apply( Combine.<String, Integer, String>perKey(new TestCombineFnWithContext(globallySumView)) .withSideInputs(globallySumView)); PCollection<String> combineGlobally = globallyInput.apply( Combine.globally(new TestCombineFnWithContext(globallySumView)) .withoutDefaults() .withSideInputs(globallySumView)); PAssert.that(sum).containsInAnyOrder(globalSum); PAssert.that(combinePerKey).containsInAnyOrder(perKeyCombines); PAssert.that(combineGlobally).containsInAnyOrder(globallyCombines); pipeline.run(); }