mchades commented on code in PR #4746: URL: https://github.com/apache/gravitino/pull/4746#discussion_r1736330463
########## catalogs/catalog-lakehouse-hudi/src/main/java/org/apache/gravitino/catalog/hudi/HudiCatalogOperations.java: ########## @@ -0,0 +1,258 @@ +/* + * 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.gravitino.catalog.hudi; + +import java.util.Map; +import org.apache.gravitino.Catalog; +import org.apache.gravitino.NameIdentifier; +import org.apache.gravitino.Namespace; +import org.apache.gravitino.Schema; +import org.apache.gravitino.SchemaChange; +import org.apache.gravitino.catalog.hudi.backend.HudiCatalogBackend; +import org.apache.gravitino.catalog.hudi.ops.HudiCatalogOps; +import org.apache.gravitino.catalog.hudi.utils.CatalogUtils; +import org.apache.gravitino.connector.CatalogInfo; +import org.apache.gravitino.connector.CatalogOperations; +import org.apache.gravitino.connector.HasPropertyMetadata; +import org.apache.gravitino.connector.SupportsSchemas; +import org.apache.gravitino.exceptions.ConnectionFailedException; +import org.apache.gravitino.exceptions.NoSuchCatalogException; +import org.apache.gravitino.exceptions.NoSuchSchemaException; +import org.apache.gravitino.exceptions.NoSuchTableException; +import org.apache.gravitino.exceptions.NonEmptySchemaException; +import org.apache.gravitino.exceptions.SchemaAlreadyExistsException; +import org.apache.gravitino.exceptions.TableAlreadyExistsException; +import org.apache.gravitino.rel.Column; +import org.apache.gravitino.rel.Table; +import org.apache.gravitino.rel.TableCatalog; +import org.apache.gravitino.rel.TableChange; +import org.apache.gravitino.rel.expressions.distributions.Distribution; +import org.apache.gravitino.rel.expressions.sorts.SortOrder; +import org.apache.gravitino.rel.expressions.transforms.Transform; +import org.apache.gravitino.rel.indexes.Index; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** Operations for Interacting with Hudi Catalog. */ +public class HudiCatalogOperations implements CatalogOperations, SupportsSchemas, TableCatalog { + + private static final Logger LOG = LoggerFactory.getLogger(HudiCatalogOperations.class); + + private HudiCatalogOps hudiCatalogOps; + + /** + * Load the Hudi Catalog Backend and initialize the Hudi Catalog Operations. + * + * @param config The configuration of this Catalog. + * @param info The information of this Catalog. + * @param propertiesMetadata The properties metadata of this Catalog. + * @throws RuntimeException if failed to initialize the Hudi Catalog Operations. + */ + @Override + public void initialize( + Map<String, String> config, CatalogInfo info, HasPropertyMetadata propertiesMetadata) + throws RuntimeException { + HudiCatalogBackend hudiCatalogBackend = CatalogUtils.loadHudiCatalogBackend(config); + hudiCatalogOps = hudiCatalogBackend.catalogOps(); + } + + /** + * Performs `listSchemas` operation on the Hudi Catalog to test the catalog connection. + * + * @param catalogIdent the name of the catalog. + * @param type the type of the catalog. + * @param provider the provider of the catalog. + * @param comment the comment of the catalog. + * @param properties the properties of the catalog. + * @throws Exception if failed to run `listSchemas` operation on the Hudi Catalog. + */ + @Override + public void testConnection( + NameIdentifier catalogIdent, + Catalog.Type type, + String provider, + String comment, + Map<String, String> properties) + throws Exception { + try { + hudiCatalogOps.listSchemas(null); Review Comment: When the code reaches this here, `hudiCatalogOps` has already been initialized, but sometimes the actual connection is established when performing operations, so here use a real operation to test the connection. -- 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]
