JingsongLi commented on code in PR #5140: URL: https://github.com/apache/paimon/pull/5140#discussion_r1967725910
########## paimon-spark/paimon-spark-common/src/main/java/org/apache/paimon/spark/procedure/RemoveNonExistingTableProcedure.java: ########## @@ -0,0 +1,157 @@ +/* + * 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.paimon.spark.procedure; + +import org.apache.paimon.catalog.CachingCatalog; +import org.apache.paimon.catalog.Catalog; +import org.apache.paimon.hive.HiveCatalog; +import org.apache.paimon.spark.catalog.WithPaimonCatalog; +import org.apache.paimon.utils.Preconditions; + +import org.apache.hadoop.hive.metastore.api.NoSuchObjectException; +import org.apache.spark.sql.catalyst.InternalRow; +import org.apache.spark.sql.connector.catalog.TableCatalog; +import org.apache.spark.sql.types.DataTypes; +import org.apache.spark.sql.types.Metadata; +import org.apache.spark.sql.types.StructField; +import org.apache.spark.sql.types.StructType; +import org.apache.thrift.TException; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** Procedure to remove table in metastore but does not exist in file system. */ +public class RemoveNonExistingTableProcedure extends BaseProcedure { + + private static final Logger LOG = + LoggerFactory.getLogger(RemoveNonExistingTableProcedure.class); + + private static final ProcedureParameter[] PARAMETERS = + new ProcedureParameter[] {ProcedureParameter.required("table", DataTypes.StringType)}; + + private static final StructType OUTPUT_TYPE = + new StructType( + new StructField[] { + new StructField("result", DataTypes.BooleanType, true, Metadata.empty()) + }); + + private RemoveNonExistingTableProcedure(TableCatalog tableCatalog) { + super(tableCatalog); + } + + @Override + public ProcedureParameter[] parameters() { + return PARAMETERS; + } + + @Override + public StructType outputType() { + return OUTPUT_TYPE; + } + + @Override + public InternalRow[] call(InternalRow args) { + String tableName = args.getString(0); + Preconditions.checkArgument( + tableName != null && !tableName.isEmpty(), + "Cannot drop table in metastore with empty tableName for argument %s", + tableName); + org.apache.paimon.catalog.Identifier identifier = + org.apache.paimon.catalog.Identifier.fromString( + toIdentifier(args.getString(0), PARAMETERS[0].name()).toString()); + LOG.info("identifier in RemoveNonExistingTableProcedure is {}.", identifier); + + Catalog paimonCatalog = ((WithPaimonCatalog) tableCatalog()).paimonCatalog(); + Catalog wrappedCatalog; + if (paimonCatalog instanceof CachingCatalog) { + wrappedCatalog = ((CachingCatalog) paimonCatalog).wrapped(); + } else { + wrappedCatalog = paimonCatalog; + } + if (!(wrappedCatalog instanceof HiveCatalog)) { + throw new IllegalArgumentException( + "Only support Hive Catalog in RemoveNonExistingTableProcedure"); Review Comment: Actually, this procedure is just for `HiveCatalog`, it is `remove_non_existing_table_for_hive_catalog`. If this is not a commonly used procedure, I suggest not pushing it forward. -- 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: issues-unsubscr...@paimon.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org