yuqi1129 commented on code in PR #15142: URL: https://github.com/apache/gravitino/pull/15142#discussion_r4637875450
########## api/src/main/java/org/apache/gravitino/rel/SupportsTableIdentifier.java: ########## @@ -0,0 +1,49 @@ +/* + * 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. + */ + +// Referred from Apache's connector/catalog implementation +// sql/catalyst/src/main/java/org/apache/spark/sql/connector/catalog/TableCatalog.java + +package org.apache.gravitino.rel; + +import javax.annotation.Nullable; +import org.apache.gravitino.NameIdentifier; +import org.apache.gravitino.annotation.Evolving; +import org.apache.gravitino.exceptions.NoSuchSchemaException; +import org.apache.gravitino.exceptions.NoSuchTableException; + +/** + * Optional table operations that resolve source identity without loading columns or constraints. + */ +@Evolving +public interface SupportsTableIdentifier extends TableCatalog { Review Comment: Could we keep this capability in `core/.../connector`, following `SupportsTableNameResolution`? The dispatcher is the only consumer and Hive already implements `TableCatalog`. Hive could implement a small standalone connector interface alongside it. That keeps the single HMS lookup and the dispatcher's identity-conflict handling without adding a type to the client-facing API module. ########## core/src/main/java/org/apache/gravitino/catalog/TableOperationDispatcher.java: ########## @@ -150,7 +151,21 @@ public boolean tableExists(NameIdentifier ident) { getCatalogIdentifier(ident), wrapper -> wrapper.doWithCatalog(catalog -> catalog.ops() instanceof TableCatalog), RuntimeException.class); - return supportsTables && TableDispatcher.super.tableExists(ident); + if (!supportsTables) { + return false; + } + try { + Boolean exists = + TreeLockUtils.doWithTreeLock(ident, LockType.READ, () -> probeImportedTable(ident)); Review Comment: Minor performance point: connectors without the probe now acquire a table read lock and enter another catalog callback before taking the ordinary load path. For a cold Hive table, both `probeImportedTable` and `loadAndImportTable` also read the same missing store entry. Could the existing catalog capability check select the fallback earlier, and could the probe share the registration read in the existing locked load path? The source should still be reread under the write lock when importing. ########## core/src/main/java/org/apache/gravitino/catalog/TableOperationDispatcher.java: ########## @@ -569,6 +584,43 @@ private Optional<TableEntity> getTableEntityBeforeRename(NameIdentifier ident) { } } + @Nullable + private Boolean probeImportedTable(NameIdentifier ident) { + return doWithCatalog( + getCatalogIdentifier(ident), + catalog -> { + if (isManagedEntity(catalog, Capability.Scope.TABLE)) { + return null; + } + return catalog.doWithTableOps( + ops -> { + if (!(ops instanceof SupportsTableIdentifier)) { + return null; + } + TableEntity stored = getEntity(ident, TABLE, TableEntity.class); + if (stored == null) { + return null; + } + String sourceId = ((SupportsTableIdentifier) ops).loadTableIdentifier(ident); + if (sourceId == null) { + // Sources without a persistent identifier use the same name-based identity as + // loadTable. + return true; + } + try { + return StringIdentifier.fromString(sourceId).id() == stored.id() Review Comment: A table can keep the same ID while its columns change in Hive. I reproduced this in a dispatcher test by adding a column directly through the source connector and then calling `tableExists`. On the base commit the new column had a stored ID after the check. On this head the check returned true, but the column only appeared after an explicit `loadTable`. This affects column tags: `MetadataObjectUtil.checkMetadataObject(COLUMN)` checks the parent table here, then the tag operation resolves the column ID from the store. Could we keep the fast path for table targets and refresh the parent for column targets? Please also cover a mixed batch ordered as [table, column]. `checkMetadataObjects` currently deduplicates by parent, so a successful table probe could suppress the refresh needed for the column. -- 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]
