in xtable-hudi-support/xtable-hudi-support-extensions/src/main/java/org/apache/xtable/hudi/extensions/AddFieldIdsClientInitCallback.java [60:109]
public void call(BaseHoodieClient hoodieClient) {
HoodieWriteConfig config = hoodieClient.getConfig();
if (config.getSchema() != null || config.getWriteSchema() != null) {
try {
Option<Schema> currentSchema = Option.empty();
try {
Configuration hadoopConfiguration = hoodieClient.getEngineContext().getHadoopConf().get();
String tableBasePath = config.getBasePath();
FileSystem fs = FSUtils.getFs(tableBasePath, hadoopConfiguration);
if (FSUtils.isTableExists(config.getBasePath(), fs)) {
HoodieTableMetaClient metaClient =
HoodieTableMetaClient.builder()
.setConf(hadoopConfiguration)
.setBasePath(tableBasePath)
.build();
currentSchema =
new TableSchemaResolver(metaClient).getTableAvroSchemaFromLatestCommit(true);
}
} catch (Exception ex) {
log.warn("Unable to fetch current schema for fieldIds", ex);
}
if (config.getSchema() != null) {
Schema schema = new Schema.Parser().parse(config.getSchema());
if (schema.getType() != Schema.Type.NULL) {
Schema newSchema =
idTracker.addIdTracking(schema, currentSchema, config.populateMetaFields());
config.setSchema(newSchema.toString());
}
}
if (config.getProps().containsKey(HoodieWriteConfig.WRITE_SCHEMA_OVERRIDE.key())) {
Schema writeSchema = new Schema.Parser().parse(config.getWriteSchema());
if (writeSchema.getType() != Schema.Type.NULL) {
Schema newWriteSchema =
idTracker.addIdTracking(writeSchema, currentSchema, config.populateMetaFields());
config
.getProps()
.setProperty(
HoodieWriteConfig.WRITE_SCHEMA_OVERRIDE.key(), newWriteSchema.toString());
}
}
} catch (Exception ex) {
throw new HoodieException(
"Unable to initialize fieldIds schema "
+ config.getSchema()
+ " write "
+ config.getWriteSchema(),
ex);
}
}
}