luoyuxia commented on code in PR #3395: URL: https://github.com/apache/fluss/pull/3395#discussion_r3348039223
########## fluss-lake/fluss-lake-hudi/src/main/java/org/apache/fluss/lake/hudi/HudiLakeCatalog.java: ########## @@ -0,0 +1,277 @@ +/* + * 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.fluss.lake.hudi; + +import org.apache.fluss.annotation.VisibleForTesting; +import org.apache.fluss.config.Configuration; +import org.apache.fluss.lake.hudi.utils.HudiConversions; +import org.apache.fluss.lake.hudi.utils.catalog.HudiCatalogUtils; +import org.apache.fluss.lake.lakestorage.LakeCatalog; +import org.apache.fluss.metadata.TableChange; +import org.apache.fluss.metadata.TableDescriptor; +import org.apache.fluss.metadata.TablePath; +import org.apache.fluss.utils.IOUtils; + +import org.apache.flink.table.api.DataTypes; +import org.apache.flink.table.api.Schema; +import org.apache.flink.table.catalog.Catalog; +import org.apache.flink.table.catalog.CatalogBaseTable; +import org.apache.flink.table.catalog.CatalogDatabase; +import org.apache.flink.table.catalog.CatalogTable; +import org.apache.flink.table.catalog.Column; +import org.apache.flink.table.catalog.ObjectPath; +import org.apache.flink.table.catalog.ResolvedCatalogBaseTable; +import org.apache.flink.table.catalog.ResolvedSchema; +import org.apache.flink.table.catalog.exceptions.DatabaseAlreadyExistException; +import org.apache.flink.table.catalog.exceptions.DatabaseNotExistException; +import org.apache.flink.table.catalog.exceptions.TableNotExistException; +import org.apache.flink.table.types.AbstractDataType; +import org.apache.flink.table.types.DataType; +import org.apache.flink.table.types.logical.LogicalType; +import org.apache.hudi.table.catalog.CatalogOptions; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Objects; + +import static org.apache.fluss.lake.hudi.utils.catalog.HudiCatalogUtils.HIVE_META_STORE_TYPE; +import static org.apache.fluss.lake.hudi.utils.catalog.HudiCatalogUtils.HUDI_CATALOG_DEFAULT_NAME; +import static org.apache.fluss.metadata.TableDescriptor.BUCKET_COLUMN_NAME; +import static org.apache.fluss.metadata.TableDescriptor.OFFSET_COLUMN_NAME; +import static org.apache.fluss.metadata.TableDescriptor.TIMESTAMP_COLUMN_NAME; + +/** Implementation of {@link LakeCatalog} for Hudi. */ +public class HudiLakeCatalog implements LakeCatalog { + + private static final Logger LOG = LoggerFactory.getLogger(HudiLakeCatalog.class); + + public static final LinkedHashMap<String, DataType> SYSTEM_COLUMNS = new LinkedHashMap<>(); + + static { + SYSTEM_COLUMNS.put(BUCKET_COLUMN_NAME, DataTypes.INT()); + SYSTEM_COLUMNS.put(OFFSET_COLUMN_NAME, DataTypes.BIGINT()); + SYSTEM_COLUMNS.put(TIMESTAMP_COLUMN_NAME, DataTypes.TIMESTAMP(6)); + } + + private final Catalog hudiCatalog; + private final String catalogMode; + + public HudiLakeCatalog(Configuration configuration) { + this.catalogMode = + configuration.toMap().getOrDefault(CatalogOptions.MODE.key(), HIVE_META_STORE_TYPE); + this.hudiCatalog = HudiCatalogUtils.createHudiCatalog(configuration); + this.hudiCatalog.open(); + } + + @VisibleForTesting + protected Catalog getHudiCatalog() { + return hudiCatalog; + } + + @Override + public void createTable(TablePath tablePath, TableDescriptor tableDescriptor, Context context) + throws org.apache.fluss.exception.TableAlreadyExistException { + LOG.info("create the lake table for : {} with props: {}", tablePath, tableDescriptor); + + ObjectPath objectPath = HudiConversions.toHudiObjectPath(tablePath); + + boolean isPkTable = tableDescriptor.getSchema().getPrimaryKeyIndexes().length > 0; + + // Create Hudi catalog table Review Comment: Update: after disucss with author offline, unlike Iceberg and Paimon which provide their own catalog abstractions, Hudi does not have a standalone catalog API. We convert to a Flink catalog table and delegate to the Flink catalog to create the Hudi table. -- 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]
