1
0

Fix NPE when offline compaction could not find schema from data file

This commit is contained in:
v-zhangjc9
2022-04-13 09:51:10 +08:00
parent 32f7e323dc
commit 0ac43017cb

View File

@@ -127,10 +127,14 @@ public class CompactionUtil {
* @param conf The configuration
*/
public static void inferChangelogMode(Configuration conf, HoodieTableMetaClient metaClient) throws Exception {
TableSchemaResolver tableSchemaResolver = new TableSchemaResolver(metaClient);
Schema tableAvroSchema = tableSchemaResolver.getTableAvroSchemaFromDataFile();
if (tableAvroSchema.getField(HoodieRecord.OPERATION_METADATA_FIELD) != null) {
conf.setBoolean(FlinkOptions.CHANGELOG_ENABLED, true);
try {
TableSchemaResolver tableSchemaResolver = new TableSchemaResolver(metaClient);
Schema tableAvroSchema = tableSchemaResolver.getTableAvroSchemaFromDataFile();
if (tableAvroSchema.getField(HoodieRecord.OPERATION_METADATA_FIELD) != null) {
conf.setBoolean(FlinkOptions.CHANGELOG_ENABLED, true);
}
} catch (Exception e) {
LOG.warn("Could not get schema from data file, CHANGELOG_ENABLE is set to default", e);
}
}