/** {@link CombineFn} for MAX based on {@link Max} and {@link Combine.BinaryCombineFn}. */ static CombineFn createMax(Schema.TypeName fieldType) { switch (fieldType) { case BOOLEAN: case INT16: case BYTE: case FLOAT: case DATETIME: case DECIMAL: return new CustMax<>(); case INT32: return Max.ofIntegers(); case INT64: return Max.ofLongs(); case DOUBLE: return Max.ofDoubles(); default: throw new UnsupportedOperationException( String.format("[%s] is not support in MAX", fieldType)); } }
@Test public void testMaxIntegerFn() { testCombineFn(Max.ofIntegers(), Lists.newArrayList(1, 2, 3, 4), 4); }
@Test public void testDuplicatedTagsKeyed() { expectedException.expect(IllegalArgumentException.class); expectedException.expectMessage("it is already present in the composition"); TupleTag<Integer> tag = new TupleTag<>(); CombineFns.compose() .with(new GetIntegerFunction(), Max.ofIntegers(), tag) .with(new GetIntegerFunction(), Min.ofIntegers(), tag); }
@Test public void testDuplicatedTags() { expectedException.expect(IllegalArgumentException.class); expectedException.expectMessage("it is already present in the composition"); TupleTag<Integer> tag = new TupleTag<>(); CombineFns.compose() .with(new GetIntegerFunction(), Max.ofIntegers(), tag) .with(new GetIntegerFunction(), Min.ofIntegers(), tag); }
@Test public void testIntegerStats() { for (TestCase<Integer> t : INTEGER_CASES) { assertEquals(t.sum, Sum.ofIntegers().apply(t.data)); assertEquals(t.min, Min.ofIntegers().apply(t.data)); assertEquals(t.max, Max.ofIntegers().apply(t.data)); assertEquals(t.mean, Mean.<Integer>of().apply(t.data)); } }
@SuppressWarnings({"unchecked", "rawtypes"}) @Test public void testCombiningValueEquality() { Combine.BinaryCombineIntegerFn maxFn = Max.ofIntegers(); Coder<Integer> input1 = VarIntCoder.of(); Coder<Integer> input2 = BigEndianIntegerCoder.of();
Combine.globally( CombineFns.compose() .with(new GetIntegerFunction(), Max.ofIntegers(), maxIntTag) .with(new GetUserStringFunction(), new ConcatString(), concatStringTag))) .apply(WithKeys.of("global")) Combine.perKey( CombineFns.compose() .with(new GetIntegerFunction(), Max.ofIntegers(), maxIntTag) .with(new GetUserStringFunction(), new ConcatString(), concatStringTag))) .apply(
Combine.perKey( CombineFns.compose() .with(new GetIntegerFunction(), Max.ofIntegers(), maxIntTag) .with( new GetUserStringFunction(), new OutputNullString(), concatStringTag)))
Combine.globally( CombineFns.compose() .with(new GetIntegerFunction(), Max.ofIntegers(), maxIntTag) .with( new GetUserStringFunction(), Combine.<String, KV<Integer, UserString>, CoCombineResult>perKey( CombineFns.compose() .with(new GetIntegerFunction(), Max.ofIntegers(), maxIntTag) .with( new GetUserStringFunction(),
CoderRegistry registry = CoderRegistry.createDefault(); Combine.BinaryCombineIntegerFn maxFn = Max.ofIntegers(); Combine.BinaryCombineIntegerFn minFn = Min.ofIntegers();