Skip to content

Commit 10363c1

Browse files
authored
[HUDI-4132] Fixing determining target table schema for delta sync with empty batch (#5648)
1 parent 0caa55e commit 10363c1

File tree

1 file changed

+9
-2
lines changed
  • hudi-utilities/src/main/java/org/apache/hudi/utilities/deltastreamer

1 file changed

+9
-2
lines changed

hudi-utilities/src/main/java/org/apache/hudi/utilities/deltastreamer/DeltaSync.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -840,8 +840,15 @@ private Schema getSchemaForWriteConfig(Schema targetSchema) {
840840
&& SchemaCompatibility.checkReaderWriterCompatibility(InputBatch.NULL_SCHEMA, targetSchema).getType() == SchemaCompatibility.SchemaCompatibilityType.COMPATIBLE) {
841841
// target schema is null. fetch schema from commit metadata and use it
842842
HoodieTableMetaClient meta = HoodieTableMetaClient.builder().setConf(new Configuration(fs.getConf())).setBasePath(cfg.targetBasePath).setPayloadClassName(cfg.payloadClassName).build();
843-
TableSchemaResolver schemaResolver = new TableSchemaResolver(meta);
844-
newWriteSchema = schemaResolver.getTableAvroSchema(false);
843+
int totalCompleted = meta.getActiveTimeline().getCommitsTimeline().filterCompletedInstants().countInstants();
844+
if (totalCompleted > 0) {
845+
try {
846+
TableSchemaResolver schemaResolver = new TableSchemaResolver(meta);
847+
newWriteSchema = schemaResolver.getTableAvroSchema(false);
848+
} catch (IllegalArgumentException e) {
849+
LOG.warn("Could not fetch schema from table. Falling back to using target schema from schema provider");
850+
}
851+
}
845852
}
846853
}
847854
return newWriteSchema;

0 commit comments

Comments
 (0)