Indian-boult commented on code in PR #1014:
URL: https://github.com/apache/incubator-xtable/pull/1014#discussion_r4638042622
##########
xtable-core/src/main/java/org/apache/xtable/delta/DeltaStatsUtils.java:
##########
@@ -179,6 +180,24 @@ public static FileStats parseColumnStatsFromJson(String
statsJson, List<Internal
}
}
+ /**
+ * Maps each field's path to the path its stats are keyed by. With column
mapping, Delta keys the
+ * stats by physical name, so a path segment is the field's storage name
when one is set. There is
+ * no fallback to the logical name, which can be another column's physical
name after renames.
+ * Parents must come before their children, as in {@link
InternalSchema#getAllFields()}.
+ */
+ private static Map<String, String> getPhysicalPaths(List<InternalField>
fields) {
+ Map<String, String> physicalPaths = new HashMap<>();
+ for (InternalField field : fields) {
+ String name = field.getStorageName() != null ? field.getStorageName() :
field.getName();
+ String parentPath = field.getParentPath();
Review Comment:
Without column mapping, nested stats are handled today. Delta writes them as
nested JSON (`{"s":{"x":10}}`), `flattenStatMap` turns that into `s.x`, and
that is the field's logical path. The Standalone source has passed nested
fields to the parser since #769.
With column mapping they were not. `main` looked nested stats up by logical
path, the same as top-level ones, but Delta keys them by physical path at every
level. This line builds a child's physical path from its parent's physical path.
I added `getCurrentSnapshotColumnMappingNestedStatsTest` to
`ITDeltaConversionSource`. It creates a table with `s STRUCT<x INT, y STRING>`
and checks the nested stats before column mapping. Then it enables column
mapping, renames `s.x` to `x_old`, re-adds `s.x`, inserts again, and checks the
stats of both files. Last, it renames `s` and checks them again. On `main`:
- After the nested rename, `s.x_old` has no stats in the first file, and the
re-added `s.x`, which is null in every row there, gets the range of `x_old`
[10, 20] with 0 nulls.
- After renaming `s`, no nested field has stats. Only `id` does.
With this PR the test passes.
The Kernel source does not read nested stats at all, with or without column
mapping, because it passes only top-level fields to the stats parser. I have a
separate fix for that ready and will open it as its own PR.
--
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]