the-other-tim-brown commented on code in PR #1014:
URL: https://github.com/apache/incubator-xtable/pull/1014#discussion_r4655960710
##########
xtable-core/src/test/java/org/apache/xtable/delta/TestDeltaStatsExtractor.java:
##########
@@ -220,6 +220,108 @@ void convertNullStatsToInternalRepresentation() {
assertEquals(0, actualNumRecords);
}
+ @Test
+ void convertStatsWithColumnMappingPhysicalNames() {
+ // With column mapping, the stats are keyed by physical name at every
level of nesting.
+ List<InternalField> fields =
+ Arrays.asList(
+ columnMappedField("top_level_string", "col-1f2e", null,
InternalType.STRING),
+ columnMappedField("nested", "col-3d4c", null, InternalType.RECORD),
+ columnMappedField("int_field", "col-5b6a", "nested",
InternalType.INT));
+ String stats =
+ "{\"numRecords\":100,"
+ +
"\"minValues\":{\"col-1f2e\":\"a\",\"col-3d4c\":{\"col-5b6a\":1}},"
+ +
"\"maxValues\":{\"col-1f2e\":\"b\",\"col-3d4c\":{\"col-5b6a\":2}},"
+ + "\"nullCount\":{\"col-1f2e\":3,\"col-3d4c\":{\"col-5b6a\":4}}}";
+ List<ColumnStat> expected =
+ Arrays.asList(
+ ColumnStat.builder()
+ .field(fields.get(0))
+ .numValues(100)
+ .numNulls(3L)
+ .range(Range.vector("a", "b"))
+ .build(),
+ ColumnStat.builder()
+ .field(fields.get(2))
+ .numValues(100)
+ .numNulls(4L)
+ .range(Range.vector(1, 2))
+ .build());
+ assertEquals(expected, extractColumnStats(stats, fields));
+ }
+
+ @Test
+ void convertStatsWithColumnMappingSwappedNames() {
+ // Column mapping enabled on an existing table keeps the old names as
physical names. After a
+ // and b swap names, each logical name is the other column's physical name.
+ List<InternalField> fields =
+ Arrays.asList(
+ columnMappedField("a", "b", null, InternalType.INT),
+ columnMappedField("b", "a", null, InternalType.INT));
+ String stats =
+ "{\"numRecords\":100,"
+ + "\"minValues\":{\"a\":1,\"b\":10},"
+ + "\"maxValues\":{\"a\":2,\"b\":20},"
+ + "\"nullCount\":{\"a\":0,\"b\":5}}";
+ List<ColumnStat> expected =
+ Arrays.asList(
+ ColumnStat.builder()
+ .field(fields.get(0))
+ .numValues(100)
+ .numNulls(5L)
+ .range(Range.vector(10, 20))
+ .build(),
+ ColumnStat.builder()
+ .field(fields.get(1))
+ .numValues(100)
+ .numNulls(0L)
+ .range(Range.vector(1, 2))
+ .build());
+ assertEquals(expected, extractColumnStats(stats, fields));
+ }
+
+ @Test
+ void convertStatsWithColumnMappingReAddedColumn() {
+ // After renaming a to a_old, a_old keeps physical name a and a re-added a
gets a new physical
+ // name. A file written before the re-add has stats keyed by a, but none
for the new a. The new
+ // a is a DATE, so the INT stats of a_old do not parse as its stats.
+ List<InternalField> fields =
+ Arrays.asList(
+ columnMappedField("a_old", "a", null, InternalType.INT),
+ columnMappedField("a", "col-1f2e", null, InternalType.DATE));
+ String stats =
+ "{\"numRecords\":100,"
+ + "\"minValues\":{\"a\":1},"
+ + "\"maxValues\":{\"a\":2},"
+ + "\"nullCount\":{\"a\":0}}";
+ List<ColumnStat> expected =
+ Collections.singletonList(
+ ColumnStat.builder()
+ .field(fields.get(0))
+ .numValues(100)
+ .numNulls(0L)
+ .range(Range.vector(1, 2))
+ .build());
+ assertEquals(expected, extractColumnStats(stats, fields));
+ }
+
+ private static List<ColumnStat> extractColumnStats(String stats,
List<InternalField> fields) {
Review Comment:
This helper is a great addition, can we have it return the `numRecords` as
well in a Pair/Tuple so we can reuse it in the existing tests as well?
--
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.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]