danny0405 commented on code in PR #10494:
URL: https://github.com/apache/hudi/pull/10494#discussion_r1454427215
##########
hudi-flink-datasource/hudi-flink/src/main/java/org/apache/hudi/table/catalog/HoodieCatalogUtil.java:
##########
@@ -172,4 +196,94 @@ public static List<String> getOrderedPartitionValues(
return values;
}
+
+ protected static void alterTable(
+ AbstractCatalog catalog,
+ ObjectPath tablePath,
+ CatalogBaseTable newCatalogTable,
+ List tableChanges,
+ boolean ignoreIfNotExists,
+ org.apache.hadoop.conf.Configuration hadoopConf,
+ BiFunction<ObjectPath, CatalogBaseTable, String> inferTablePathFunc,
+ BiConsumer<ObjectPath, CatalogBaseTable> postAlterTableFunc) throws
TableNotExistException, CatalogException {
+ checkNotNull(tablePath, "Table path cannot be null");
+ checkNotNull(newCatalogTable, "New catalog table cannot be null");
+
+ if (!isUpdatePermissible(catalog, tablePath, newCatalogTable,
ignoreIfNotExists)) {
+ return;
+ }
+ if (!tableChanges.isEmpty()) {
+ CatalogBaseTable oldTable = catalog.getTable(tablePath);
+ HoodieFlinkWriteClient<?> writeClient = createWriteClient(tablePath,
oldTable, hadoopConf, inferTablePathFunc);
+ Pair<InternalSchema, HoodieTableMetaClient> pair =
writeClient.getInternalSchemaAndMetaClient();
+ InternalSchema oldSchema = pair.getLeft();
+ Function<LogicalType, Type> convertFunc = (LogicalType logicalType) ->
AvroInternalSchemaConverter.convertToField(AvroSchemaConverter.convertToSchema(logicalType));
+ InternalSchema newSchema = Utils.applyTableChange(oldSchema,
tableChanges, convertFunc);
+ if (!oldSchema.equals(newSchema)) {
+ writeClient.setOperationType(WriteOperationType.ALTER_SCHEMA);
+ writeClient.commitTableChange(newSchema, pair.getRight());
+ }
+ }
+ postAlterTableFunc.accept(tablePath, newCatalogTable);
+ }
+
+ protected static HoodieFlinkWriteClient<?> createWriteClient(
+ ObjectPath tablePath,
+ CatalogBaseTable table,
+ org.apache.hadoop.conf.Configuration hadoopConf,
+ BiFunction<ObjectPath, CatalogBaseTable, String> inferTablePathFunc) {
+ Map<String, String> options = table.getOptions();
+ String tablePathStr = inferTablePathFunc.apply(tablePath, table);
+ return createWriteClient(options, tablePathStr, tablePath, hadoopConf);
+ }
+
+ protected static HoodieFlinkWriteClient<?> createWriteClient(
+ Map<String, String> options,
+ String tablePathStr,
+ ObjectPath tablePath,
+ org.apache.hadoop.conf.Configuration hadoopConf) {
+ // enable auto-commit though ~
+ options.put(HoodieWriteConfig.AUTO_COMMIT_ENABLE.key(), "true");
Review Comment:
Not sure whether this is needed for all the scenarios?
--
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]