danny0405 commented on code in PR #10426: URL: https://github.com/apache/hudi/pull/10426#discussion_r1438950480
########## hudi-flink-datasource/hudi-flink1.18.x/src/main/java/org/apache/hudi/adapter/HoodieHiveCatalogAdapter.java: ########## @@ -0,0 +1,138 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.hudi.adapter; + +import org.apache.hudi.common.util.collection.Pair; +import org.apache.hudi.exception.HoodieNotSupportedException; +import org.apache.hudi.internal.schema.InternalSchema; +import org.apache.hudi.internal.schema.Type; +import org.apache.hudi.internal.schema.action.InternalSchemaChangeApplier; + +import org.apache.flink.table.catalog.Catalog; +import org.apache.flink.table.catalog.CatalogBaseTable; +import org.apache.flink.table.catalog.Column; +import org.apache.flink.table.catalog.ObjectPath; +import org.apache.flink.table.catalog.TableChange; +import org.apache.flink.table.catalog.exceptions.CatalogException; +import org.apache.flink.table.catalog.exceptions.TableNotExistException; +import org.apache.flink.table.types.logical.LogicalType; + +import java.util.List; + +import static org.apache.flink.util.Preconditions.checkNotNull; +import static org.apache.hudi.internal.schema.action.TableChange.ColumnPositionChange.ColumnPositionType.AFTER; +import static org.apache.hudi.internal.schema.action.TableChange.ColumnPositionChange.ColumnPositionType.FIRST; +import static org.apache.hudi.internal.schema.action.TableChange.ColumnPositionChange.ColumnPositionType.NO_OPERATION; + +/** + * Adapter clazz for {@code HoodieHiveCatalog}. + */ +public interface HoodieHiveCatalogAdapter extends Catalog { + + default void alterTable(ObjectPath tablePath, CatalogBaseTable newCatalogTable, List<TableChange> tableChanges, + boolean ignoreIfNotExists) throws TableNotExistException, CatalogException { + checkNotNull(tablePath, "Table path cannot be null"); + checkNotNull(newCatalogTable, "New catalog table cannot be null"); + + if (!isUpdateAllow(tablePath, newCatalogTable, ignoreIfNotExists)) { + return; + } + InternalSchema oldSchema = getInternalSchema(tablePath); + InternalSchema newSchema = oldSchema; + for (TableChange tableChange : tableChanges) { + newSchema = applyTableChange(newSchema, tableChange); + } + if (!oldSchema.equals(newSchema)) { + alterHoodieTableSchema(tablePath, newSchema); + } + refreshHMSTable(tablePath, newCatalogTable); + } + + boolean isUpdateAllow(ObjectPath tablePath, CatalogBaseTable newCatalogTable, boolean ignoreIfNotExists) throws TableNotExistException; + + InternalSchema getInternalSchema(ObjectPath tablePath) throws TableNotExistException, CatalogException; Review Comment: This method is not related specific to catalog, should we make it an interface? ########## hudi-flink-datasource/hudi-flink1.18.x/src/main/java/org/apache/hudi/adapter/HoodieHiveCatalogAdapter.java: ########## @@ -0,0 +1,138 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.hudi.adapter; + +import org.apache.hudi.common.util.collection.Pair; +import org.apache.hudi.exception.HoodieNotSupportedException; +import org.apache.hudi.internal.schema.InternalSchema; +import org.apache.hudi.internal.schema.Type; +import org.apache.hudi.internal.schema.action.InternalSchemaChangeApplier; + +import org.apache.flink.table.catalog.Catalog; +import org.apache.flink.table.catalog.CatalogBaseTable; +import org.apache.flink.table.catalog.Column; +import org.apache.flink.table.catalog.ObjectPath; +import org.apache.flink.table.catalog.TableChange; +import org.apache.flink.table.catalog.exceptions.CatalogException; +import org.apache.flink.table.catalog.exceptions.TableNotExistException; +import org.apache.flink.table.types.logical.LogicalType; + +import java.util.List; + +import static org.apache.flink.util.Preconditions.checkNotNull; +import static org.apache.hudi.internal.schema.action.TableChange.ColumnPositionChange.ColumnPositionType.AFTER; +import static org.apache.hudi.internal.schema.action.TableChange.ColumnPositionChange.ColumnPositionType.FIRST; +import static org.apache.hudi.internal.schema.action.TableChange.ColumnPositionChange.ColumnPositionType.NO_OPERATION; + +/** + * Adapter clazz for {@code HoodieHiveCatalog}. + */ +public interface HoodieHiveCatalogAdapter extends Catalog { + + default void alterTable(ObjectPath tablePath, CatalogBaseTable newCatalogTable, List<TableChange> tableChanges, + boolean ignoreIfNotExists) throws TableNotExistException, CatalogException { + checkNotNull(tablePath, "Table path cannot be null"); + checkNotNull(newCatalogTable, "New catalog table cannot be null"); + + if (!isUpdateAllow(tablePath, newCatalogTable, ignoreIfNotExists)) { + return; + } + InternalSchema oldSchema = getInternalSchema(tablePath); + InternalSchema newSchema = oldSchema; + for (TableChange tableChange : tableChanges) { + newSchema = applyTableChange(newSchema, tableChange); + } + if (!oldSchema.equals(newSchema)) { + alterHoodieTableSchema(tablePath, newSchema); + } + refreshHMSTable(tablePath, newCatalogTable); + } + + boolean isUpdateAllow(ObjectPath tablePath, CatalogBaseTable newCatalogTable, boolean ignoreIfNotExists) throws TableNotExistException; + + InternalSchema getInternalSchema(ObjectPath tablePath) throws TableNotExistException, CatalogException; + + void refreshHMSTable(ObjectPath tablePath, CatalogBaseTable newCatalogTable); + + void alterHoodieTableSchema(ObjectPath tablePath, InternalSchema newSchema) throws TableNotExistException, CatalogException; + + Type convertToInternalType(LogicalType logicalType); Review Comment: This method is not related specific to catalog, should we make it an interface? -- 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]
