the-other-tim-brown commented on code in PR #1016:
URL: https://github.com/apache/incubator-xtable/pull/1016#discussion_r4727475402
##########
xtable-core/src/test/java/org/apache/xtable/paimon/TestPaimonStatsExtractor.java:
##########
@@ -561,6 +706,43 @@ private void createPartitionedTable() {
paimonTable = testTable.getPaimonTable();
}
+ private Catalog createCatalog() {
+ return TestPaimonTable.createFilesystemCatalog(tempDir.toString(), new
Configuration());
+ }
+
+ private static FileStoreTable alterTable(
+ Catalog catalog, FileStoreTable table, SchemaChange change) throws
Exception {
+ Identifier identifier = Identifier.create("test_db", table.name());
+ catalog.alterTable(identifier, change, false);
+ return (FileStoreTable) catalog.getTable(identifier);
+ }
+
+ /** Writes one data file per call. Compaction would rewrite older files with
the new schema. */
+ private static void writeWithoutCompaction(FileStoreTable table,
List<GenericRow> rows)
+ throws Exception {
+ BatchWriteBuilder builder = table.newBatchWriteBuilder();
+ try (BatchTableWrite writer = builder.newWrite();
+ BatchTableCommit commit = builder.newCommit()) {
+ for (GenericRow row : rows) {
+ writer.write(row);
+ }
+ commit.commit(writer.prepareCommit());
+ }
+ }
Review Comment:
Can we move these utils to the `TestPaimonTable` so we can more easily reuse
them in other test classes in the future?
##########
xtable-core/src/test/java/org/apache/xtable/paimon/TestPaimonStatsExtractor.java:
##########
@@ -561,6 +706,43 @@ private void createPartitionedTable() {
paimonTable = testTable.getPaimonTable();
}
+ private Catalog createCatalog() {
+ return TestPaimonTable.createFilesystemCatalog(tempDir.toString(), new
Configuration());
+ }
+
+ private static FileStoreTable alterTable(
+ Catalog catalog, FileStoreTable table, SchemaChange change) throws
Exception {
+ Identifier identifier = Identifier.create("test_db", table.name());
+ catalog.alterTable(identifier, change, false);
+ return (FileStoreTable) catalog.getTable(identifier);
+ }
+
+ /** Writes one data file per call. Compaction would rewrite older files with
the new schema. */
+ private static void writeWithoutCompaction(FileStoreTable table,
List<GenericRow> rows)
+ throws Exception {
+ BatchWriteBuilder builder = table.newBatchWriteBuilder();
+ try (BatchTableWrite writer = builder.newWrite();
+ BatchTableCommit commit = builder.newCommit()) {
+ for (GenericRow row : rows) {
+ writer.write(row);
+ }
+ commit.commit(writer.prepareCommit());
+ }
+ }
+
+ private Map<Long, List<ColumnStat>> getStatsByRowCount(FileStoreTable table)
{
Review Comment:
Is there another key we could use here? It is a bit confusing to need keep
track of the row counts in my head when reading through the tests. Also, if two
files have the same number of rows, you won't be able to use the helper.
##########
xtable-core/src/main/java/org/apache/xtable/paimon/PaimonStatsExtractor.java:
##########
@@ -83,6 +94,36 @@ 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) {
+ if (fileSchema.equals(internalSchema)) {
+ return internalSchema.getFields().stream()
+ .collect(Collectors.toMap(InternalField::getName,
Function.identity()));
+ }
+ Map<Integer, InternalField> fieldsById =
+ internalSchema.getFields().stream()
+ .collect(Collectors.toMap(InternalField::getFieldId,
Function.identity()));
+ Map<String, InternalField> fieldsByFileColumnName = new HashMap<>();
+ for (InternalField fileField : fileSchema.getFields()) {
+ InternalField field = fieldsById.get(fileField.getFieldId());
+ if (field != null && hasSameType(fileField.getSchema(),
field.getSchema())) {
+ fieldsByFileColumnName.put(fileField.getName(), field);
+ }
+ }
+ return fieldsByFileColumnName;
+ }
+
+ private static boolean hasSameType(InternalSchema fileSchema, InternalSchema
schema) {
Review Comment:
Should we use the original Paimon types here? Paimon is a unique case where
there are multiple types for integers like `tinyint` and `smallint`.
Similarly, do we need to account for cases like widening decimals? Ex,
`DECIMAL(5,2)` to `DECIMAL(10,2)`
--
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]