kanterov commented on a change in pull request #11074: Store logical type
values in Row instead of base values
URL: https://github.com/apache/beam/pull/11074#discussion_r389645005
##########
File path:
sdks/java/core/src/test/java/org/apache/beam/sdk/schemas/transforms/GroupTest.java
##########
@@ -620,6 +531,88 @@ public void
testGloballyWithSchemaAggregateFnNestedFields() {
pipeline.run();
}
+ @DefaultSchema(AutoValueSchema.class)
+ @AutoValue
+ abstract static class BasicEnum {
+ enum Test {
+ ZERO,
+ ONE,
+ TWO
+ };
+
+ abstract String getKey();
+
+ abstract Test getEnumeration();
+
+ static BasicEnum of(String key, Test value) {
+ return new AutoValue_GroupTest_BasicEnum(key, value);
+ }
+ }
+
+ static final EnumerationType BASIC_ENUM_ENUMERATION =
+ EnumerationType.create("ZERO", "ONE", "TWO");
+ static final Schema BASIC_ENUM_SCHEMA =
+ Schema.builder()
+ .addStringField("key")
+ .addLogicalTypeField("enumeration", BASIC_ENUM_ENUMERATION)
+ .build();
+
+ @Test
+ @Category(NeedsRunner.class)
+ public void testAggregateBaseValuesGlobally() {
+ Collection<BasicEnum> elements =
+ Lists.newArrayList(
+ BasicEnum.of("a", BasicEnum.Test.ONE), BasicEnum.of("a",
BasicEnum.Test.TWO));
+
+ PCollection<Row> aggregate =
+ pipeline
+ .apply(Create.of(elements))
+ .apply(
+ Group.<BasicEnum>globally()
+ .aggregateFieldBaseValue("enumeration", Sum.ofIntegers(),
"enum_sum"));
+ Schema aggregateSchema =
Schema.builder().addInt32Field("enum_sum").build();
+ Row expectedRow = Row.withSchema(aggregateSchema).addValues(3).build();
+ PAssert.that(aggregate).containsInAnyOrder(expectedRow);
+
+ pipeline.run();
+ }
+
+ @Test
+ @Category(NeedsRunner.class)
+ public void testAggregateLogicalValuesGlobally() {
+ Collection<BasicEnum> elements =
+ Lists.newArrayList(
+ BasicEnum.of("a", BasicEnum.Test.ONE), BasicEnum.of("a",
BasicEnum.Test.TWO));
+
+ SampleAnyCombineFn<EnumerationType.Value> sampleAnyCombineFn = new
SampleAnyCombineFn<>(100);
Review comment:
Does it only work because of type erasure, or is it actually aggregating
`EnumerationType.Value` (not `Integer`)?
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services