use of org.apache.beam.sdk.transforms.Max in project beam by apache.
the class TypedCombineFnDelegateTest method testParameterExtractionFromCombineFn_CombineFnDelegate_WithListInsteadOfArray.
@Test
public void testParameterExtractionFromCombineFn_CombineFnDelegate_WithListInsteadOfArray() {
Combine.BinaryCombineFn<List<List<String>>> max = Max.of((Comparator<List<List<String>>> & Serializable) (a, b) -> Integer.compare(a.get(0).get(0).length(), b.get(0).get(0).length()));
UdafImpl<List<List<String>>, Combine.Holder<List<List<String>>>, List<List<String>>> udaf = new UdafImpl<>(new TypedCombineFnDelegate<List<List<String>>, Combine.Holder<List<List<String>>>, List<List<String>>>(max) {
});
RelDataTypeFactory typeFactory = new JavaTypeFactoryImpl(RelDataTypeSystem.DEFAULT);
List<FunctionParameter> parameters = udaf.getParameters();
assertEquals(1, parameters.size());
assertEquals(SqlTypeName.ARRAY, parameters.get(0).getType(typeFactory).getSqlTypeName());
}
use of org.apache.beam.sdk.transforms.Max in project beam by apache.
the class TypedCombineFnDelegateTest method testParameterExtractionFromCombineFn_CombineFnDelegate.
@Test
public void testParameterExtractionFromCombineFn_CombineFnDelegate() {
Combine.BinaryCombineFn<String> max = Max.of((Comparator<String> & Serializable) (a, b) -> Integer.compare(a.length(), b.length()));
UdafImpl<String, Combine.Holder<String>, String> udaf = new UdafImpl<>(new TypedCombineFnDelegate<String, Combine.Holder<String>, String>(max) {
});
RelDataTypeFactory typeFactory = new JavaTypeFactoryImpl(RelDataTypeSystem.DEFAULT);
List<FunctionParameter> parameters = udaf.getParameters();
assertEquals(1, parameters.size());
assertEquals(SqlTypeName.VARCHAR, parameters.get(0).getType(typeFactory).getSqlTypeName());
}
use of org.apache.beam.sdk.transforms.Max in project beam by apache.
the class TypedCombineFnDelegateTest method testParameterExtractionFromCombineFn_CombineFnDelegate_WithGenericArray.
@Test
public void testParameterExtractionFromCombineFn_CombineFnDelegate_WithGenericArray() {
Combine.BinaryCombineFn<List<String>[]> max = Max.of((Comparator<List<String>[]> & Serializable) (a, b) -> Integer.compare(a[0].get(0).length(), b[0].get(0).length()));
UdafImpl<List<String>[], Combine.Holder<List<String>[]>, List<String>[]> udaf = new UdafImpl<>(new TypedCombineFnDelegate<List<String>[], Combine.Holder<List<String>[]>, List<String>[]>(max) {
});
exceptions.expect(IllegalArgumentException.class);
RelDataTypeFactory typeFactory = new JavaTypeFactoryImpl(RelDataTypeSystem.DEFAULT);
udaf.getParameters().get(0).getType(typeFactory);
}
use of org.apache.beam.sdk.transforms.Max in project beam by apache.
the class MongoDBGridFSIOTest method testReadWithParser.
@Test
public void testReadWithParser() {
PCollection<KV<String, Integer>> output = pipeline.apply(MongoDbGridFSIO.read().withUri("mongodb://localhost:" + port).withDatabase(DATABASE).withBucket("mapBucket").<KV<String, Integer>>withParser((input, callback) -> {
try (final BufferedReader reader = new BufferedReader(new InputStreamReader(input.getInputStream(), StandardCharsets.UTF_8))) {
String line = reader.readLine();
while (line != null) {
try (Scanner scanner = new Scanner(line.trim())) {
scanner.useDelimiter("\\t");
long timestamp = scanner.nextLong();
String name = scanner.next();
int score = scanner.nextInt();
callback.output(KV.of(name, score), new Instant(timestamp));
}
line = reader.readLine();
}
}
}).withSkew(Duration.millis(3610000L)).withCoder(KvCoder.of(StringUtf8Coder.of(), VarIntCoder.of())));
PAssert.thatSingleton(output.apply("Count All", Count.globally())).isEqualTo(50100L);
PAssert.that(output.apply("Max PerElement", Max.integersPerKey())).satisfies(input -> {
for (KV<String, Integer> element : input) {
assertEquals(101, element.getValue().longValue());
}
return null;
});
pipeline.run();
}
Aggregations