@Override public Coder<Integer> getOutputCoder() { return BigEndianIntegerCoder.of(); } }
@Override public Coder<Integer> getOutputCoder() { return BigEndianIntegerCoder.of(); }
@Override public Coder<KV<Integer, BigDecimal>> getAccumulatorCoder( CoderRegistry registry, Coder<T> inputCoder) { return KvCoder.of(BigEndianIntegerCoder.of(), BigDecimalCoder.of()); }
public PCollection<KV<String, Integer>> createInputTable(Pipeline p) { return p.apply( "CreateInputTable", Create.of(Arrays.asList(TABLE)) .withCoder(KvCoder.of(StringUtf8Coder.of(), BigEndianIntegerCoder.of()))); }
@Test public void testCoderEquals() throws Exception { DelegateCoder.CodingFunction<Integer, Integer> identityFn = input -> input; Coder<Integer> varIntCoder1 = DelegateCoder.of(VarIntCoder.of(), identityFn, identityFn); Coder<Integer> varIntCoder2 = DelegateCoder.of(VarIntCoder.of(), identityFn, identityFn); Coder<Integer> bigEndianIntegerCoder = DelegateCoder.of(BigEndianIntegerCoder.of(), identityFn, identityFn); assertEquals(varIntCoder1, varIntCoder2); assertEquals(varIntCoder1.hashCode(), varIntCoder2.hashCode()); assertNotEquals(varIntCoder1, bigEndianIntegerCoder); assertNotEquals(varIntCoder1.hashCode(), bigEndianIntegerCoder.hashCode()); }
@Test public void testSourceSplit() throws Exception { CreateSource<Integer> source = CreateSource.fromIterable( ImmutableList.of(1, 2, 3, 4, 5, 6, 7, 8), BigEndianIntegerCoder.of()); PipelineOptions options = PipelineOptionsFactory.create(); List<? extends BoundedSource<Integer>> splitSources = source.split(12, options); assertThat(splitSources, hasSize(3)); SourceTestUtils.assertSourcesEqualReferenceSource(source, splitSources, options); }
private static PCollection<KV<String, Integer>> createInput( Pipeline p, List<KV<String, Integer>> table) { return p.apply( Create.of(table).withCoder(KvCoder.of(StringUtf8Coder.of(), BigEndianIntegerCoder.of()))); }
@Test(expected = IllegalArgumentException.class) public void testSampleAnyNegative() { pipeline.enableAbandonedNodeEnforcement(false); pipeline.apply(Create.empty(BigEndianIntegerCoder.of())).apply(Sample.any(-10)); }
@Test public void testComponentIncompatibility() throws Exception { thrown.expect(IncompatibleCoderException.class); thrown.expectMessage("component coder is incompatible"); CoderRegistry.verifyCompatible( ListCoder.of(BigEndianIntegerCoder.of()), new TypeDescriptor<List<String>>() {}.getType()); }
@Test public void testSourceSplitEmpty() throws Exception { CreateSource<Integer> source = CreateSource.fromIterable(ImmutableList.of(), BigEndianIntegerCoder.of()); PipelineOptions options = PipelineOptionsFactory.create(); List<? extends BoundedSource<Integer>> splitSources = source.split(12, options); SourceTestUtils.assertSourcesEqualReferenceSource(source, splitSources, options); }
@Test(expected = IllegalArgumentException.class) public void testSampleNegative() { pipeline.enableAbandonedNodeEnforcement(false); PCollection<Integer> input = pipeline.apply( Create.of(ImmutableList.copyOf(DATA)).withCoder(BigEndianIntegerCoder.of())); input.apply(Sample.fixedSizeGlobally(-1)); }
@Test @Category(ValidatesRunner.class) public void testKeys() { PCollection<KV<String, Integer>> input = p.apply( Create.of(Arrays.asList(TABLE)) .withCoder(KvCoder.of(StringUtf8Coder.of(), BigEndianIntegerCoder.of()))); PCollection<String> output = input.apply(Keys.create()); PAssert.that(output).containsInAnyOrder("one", "two", "three", "dup", "dup"); p.run(); }
@Test @Category(ValidatesRunner.class) public void testKeysEmpty() { PCollection<KV<String, Integer>> input = p.apply( Create.of(Arrays.asList(EMPTY_TABLE)) .withCoder(KvCoder.of(StringUtf8Coder.of(), BigEndianIntegerCoder.of()))); PCollection<String> output = input.apply(Keys.create()); PAssert.that(output).empty(); p.run(); } }
@Test @Category(NeedsRunner.class) public void testValues() { PCollection<KV<String, Integer>> input = p.apply( Create.of(Arrays.asList(TABLE)) .withCoder(KvCoder.of(StringUtf8Coder.of(), BigEndianIntegerCoder.of()))); PCollection<Integer> output = input.apply(Values.create()); PAssert.that(output).containsInAnyOrder(1, 2, 3, 4, 4); p.run(); }
@Test @Category(NeedsRunner.class) public void testValuesEmpty() { PCollection<KV<String, Integer>> input = p.apply( Create.of(Arrays.asList(EMPTY_TABLE)) .withCoder(KvCoder.of(StringUtf8Coder.of(), BigEndianIntegerCoder.of()))); PCollection<Integer> output = input.apply(Values.create()); PAssert.that(output).empty(); p.run(); }
@Test public void testValueEquality() { StateTag<?> fooVarInt1 = StateTags.value("foo", VarIntCoder.of()); StateTag<?> fooVarInt2 = StateTags.value("foo", VarIntCoder.of()); StateTag<?> fooBigEndian = StateTags.value("foo", BigEndianIntegerCoder.of()); StateTag<?> barVarInt = StateTags.value("bar", VarIntCoder.of()); assertEquals(fooVarInt1, fooVarInt2); assertNotEquals(fooVarInt1, fooBigEndian); assertNotEquals(fooVarInt1, barVarInt); }
@Test @Category(NeedsRunner.class) public void testSample() { PCollection<Integer> input = pipeline.apply( Create.of(ImmutableList.copyOf(DATA)).withCoder(BigEndianIntegerCoder.of())); PCollection<Iterable<Integer>> output = input.apply(Sample.fixedSizeGlobally(3)); PAssert.thatSingletonIterable(output).satisfies(new VerifyCorrectSample<>(3, DATA)); pipeline.run(); }
@Test @Category(NeedsRunner.class) public void testSampleZero() { PCollection<Integer> input = pipeline.apply( Create.of(ImmutableList.copyOf(DATA)).withCoder(BigEndianIntegerCoder.of())); PCollection<Iterable<Integer>> output = input.apply(Sample.fixedSizeGlobally(0)); PAssert.thatSingletonIterable(output).satisfies(new VerifyCorrectSample<>(0, DATA)); pipeline.run(); }
@Test @Category(NeedsRunner.class) public void testSampleMultiplicity() { PCollection<Integer> input = pipeline.apply( Create.of(ImmutableList.copyOf(REPEATED_DATA)).withCoder(BigEndianIntegerCoder.of())); // At least one value must be selected with multiplicity. PCollection<Iterable<Integer>> output = input.apply(Sample.fixedSizeGlobally(6)); PAssert.thatSingletonIterable(output).satisfies(new VerifyCorrectSample<>(6, REPEATED_DATA)); pipeline.run(); }
@Test @Category(NeedsRunner.class) public void testSampleAnyEmpty() { PCollection<Integer> input = pipeline.apply(Create.empty(BigEndianIntegerCoder.of())); PCollection<Integer> output = input .apply(Window.into(FixedWindows.of(Duration.standardSeconds(3)))) .apply(Sample.any(2)); PAssert.that(output).satisfies(new VerifyCorrectSample<>(0, EMPTY)); pipeline.run(); }