Indian-boult commented on code in PR #1016:
URL: https://github.com/apache/incubator-xtable/pull/1016#discussion_r4698905469


##########
xtable-core/src/main/java/org/apache/xtable/paimon/PaimonDataFileExtractor.java:
##########
@@ -159,6 +173,14 @@ public InternalFilesDiff extractFilesDiff(
     return 
InternalFilesDiff.builder().filesAdded(addedFiles).filesRemoved(removedFiles).build();
   }
 
+  /** Returns a lookup of the table's schemas by id that reads each schema 
once. */
+  private Function<Long, InternalSchema> fileSchemaLookup(FileStoreTable 
table) {

Review Comment:
   The `Function` only hid the lazy load. ef61410 passes a map instead, filled 
as files are read.
   
   The size should not be a concern. It holds one schema per distinct schema id 
among the files being converted, and a Paimon schema id is only added by a 
schema change, so the map does not grow with commits or files. It lives for one 
snapshot read or one commit, and a commit in an incremental sync usually has 
files of a single schema. Loading every schema of the table up front is what 
would grow with its history, so I kept the lazy load.
   



##########
xtable-core/src/main/java/org/apache/xtable/paimon/PaimonStatsExtractor.java:
##########
@@ -83,6 +93,32 @@ public List<ColumnStat> extractColumnStats(DataFileMeta 
file, InternalSchema int
     return columnStats;
   }
 
+  /**
+   * Maps the column names of the file's schema to the fields of the schema 
the stats are reported
+   * in. Columns are matched by field id, since a column can be renamed, 
dropped or added after the
+   * file was written. A column whose type changed is left out, since the file 
stores its stats in
+   * the old type.
+   */
+  private static Map<String, InternalField> getFieldsByFileColumnName(
+      InternalSchema fileSchema, InternalSchema internalSchema) {
+    Map<Integer, InternalField> fieldsById =
+        internalSchema.getFields().stream()
+            .collect(Collectors.toMap(InternalField::getFieldId, f -> f));

Review Comment:
   Done in ef61410.
   



##########
xtable-core/src/main/java/org/apache/xtable/paimon/PaimonStatsExtractor.java:
##########
@@ -83,6 +93,32 @@ public List<ColumnStat> extractColumnStats(DataFileMeta 
file, InternalSchema int
     return columnStats;
   }
 
+  /**
+   * Maps the column names of the file's schema to the fields of the schema 
the stats are reported
+   * in. Columns are matched by field id, since a column can be renamed, 
dropped or added after the
+   * file was written. A column whose type changed is left out, since the file 
stores its stats in
+   * the old type.
+   */
+  private static Map<String, InternalField> getFieldsByFileColumnName(

Review Comment:
   Done in ef61410. When the two schemas are equal the loop is skipped and the 
fields are mapped by name. `getFileSchema` also reuses the `internalSchema` 
instance for an equal schema, so comparing them for each file is a reference 
check.
   
   Field ids are part of the equality, so a column dropped and added again 
under the same name does not take this path. 
`testStatsAfterDropAndAddColumnWithSameName` covers that.
   



-- 
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]

Reply via email to