-
Notifications
You must be signed in to change notification settings - Fork 15
feat: add catalog namespace support and refactor adapter implementation #14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
112 changes: 112 additions & 0 deletions
112
...ava/org/apache/flink/connector/lance/catalog/namespace/AbstractLanceNamespaceAdapter.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,112 @@ | ||
| /* | ||
| * 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.flink.connector.lance.catalog.namespace; | ||
|
|
||
| import java.util.List; | ||
| import java.util.Map; | ||
|
|
||
| /** | ||
| * Abstract adapter interface for Lance Namespace operations. | ||
| * | ||
| * This interface defines the contract for implementing namespace-based catalog operations, | ||
| * allowing for different backend implementations (directory-based, REST-based, etc.). | ||
| */ | ||
| public interface AbstractLanceNamespaceAdapter extends AutoCloseable { | ||
|
|
||
| /** | ||
| * Initialize the adapter. | ||
| */ | ||
| void init(); | ||
|
|
||
| /** | ||
| * List all namespaces at root level. | ||
| */ | ||
| List<String> listNamespaces(); | ||
|
|
||
| /** | ||
| * List namespaces under a parent namespace. | ||
| */ | ||
| List<String> listNamespaces(String... parentNamespace); | ||
|
|
||
| /** | ||
| * Check if a namespace exists. | ||
| */ | ||
| boolean namespaceExists(String... namespaceId); | ||
|
|
||
| /** | ||
| * Create a namespace. | ||
| */ | ||
| void createNamespace(Map<String, String> properties, String... namespaceId); | ||
|
|
||
| /** | ||
| * Drop a namespace. | ||
| */ | ||
| void dropNamespace(boolean cascade, String... namespaceId); | ||
|
|
||
| /** | ||
| * Get namespace metadata. | ||
| */ | ||
| Map<String, String> getNamespaceMetadata(String... namespaceId); | ||
|
|
||
| /** | ||
| * List tables in a namespace. | ||
| */ | ||
| List<String> listTables(String... namespaceId); | ||
|
|
||
| /** | ||
| * Check if a table exists. | ||
| */ | ||
| boolean tableExists(String... tableId); | ||
|
|
||
| /** | ||
| * Create an empty table. | ||
| */ | ||
| void createEmptyTable(String location, Map<String, String> properties, String... tableId); | ||
|
|
||
| /** | ||
| * Drop a table. | ||
| */ | ||
| void dropTable(String... tableId); | ||
|
|
||
| /** | ||
| * Get table metadata. | ||
| */ | ||
| TableMetadata getTableMetadata(String... tableId); | ||
|
|
||
| /** | ||
| * Table metadata holder. | ||
| */ | ||
| class TableMetadata { | ||
| private final String location; | ||
| private final Map<String, String> storageOptions; | ||
|
|
||
| public TableMetadata(String location, Map<String, String> storageOptions) { | ||
| this.location = location; | ||
| this.storageOptions = storageOptions; | ||
| } | ||
|
|
||
| public String getLocation() { | ||
| return location; | ||
| } | ||
|
|
||
| public Map<String, String> getStorageOptions() { | ||
| return storageOptions; | ||
| } | ||
| } | ||
| } |
84 changes: 84 additions & 0 deletions
84
...in/java/org/apache/flink/connector/lance/catalog/namespace/BaseLanceNamespaceCatalog.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| /* | ||
| * 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.flink.connector.lance.catalog.namespace; | ||
|
|
||
| import org.apache.flink.table.catalog.AbstractCatalog; | ||
| import org.apache.flink.table.catalog.CatalogBaseTable; | ||
| import org.apache.flink.table.catalog.CatalogTable; | ||
| import org.apache.flink.table.catalog.ObjectPath; | ||
| import org.apache.flink.table.catalog.exceptions.CatalogException; | ||
|
|
||
| /** | ||
| * Base class for Lance Catalog implementation integrated with Lance Namespace. | ||
| * | ||
| * This class provides the foundation for catalog operations using a namespace adapter, | ||
| * supporting multi-level namespace hierarchies and flexible backend implementations. | ||
| */ | ||
| public abstract class BaseLanceNamespaceCatalog extends AbstractCatalog { | ||
|
|
||
| protected AbstractLanceNamespaceAdapter adapter; | ||
| protected LanceNamespaceConfig config; | ||
|
|
||
| public BaseLanceNamespaceCatalog(String catalogName, | ||
| AbstractLanceNamespaceAdapter adapter, | ||
| LanceNamespaceConfig config) { | ||
| super(catalogName, "default"); | ||
| this.adapter = adapter; | ||
| this.config = config; | ||
| } | ||
|
|
||
| /** | ||
| * Abstract method to be implemented by subclasses to create CatalogTable from metadata. | ||
| */ | ||
| protected abstract CatalogTable createCatalogTable( | ||
| String databaseName, | ||
| String tableName, | ||
| AbstractLanceNamespaceAdapter.TableMetadata metadata) throws CatalogException; | ||
|
|
||
| /** | ||
| * Transform database name to namespace path array. | ||
| */ | ||
| protected String[] transformDatabaseNameToNamespace(String databaseName) { | ||
| java.util.Optional<String[]> parentPrefix = config.getParentArray(); | ||
| java.util.Optional<String> extraLevel = config.getExtraLevel(); | ||
|
|
||
| if (parentPrefix.isPresent()) { | ||
| String[] parent = parentPrefix.get(); | ||
| String[] result = new String[parent.length + 1]; | ||
| System.arraycopy(parent, 0, result, 0, parent.length); | ||
| result[parent.length] = databaseName; | ||
| return result; | ||
| } else if (extraLevel.isPresent()) { | ||
| return new String[]{extraLevel.get(), databaseName}; | ||
| } else { | ||
| return new String[]{databaseName}; | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Transform table name to full table ID (namespace path + table name). | ||
| */ | ||
| protected String[] transformTableNameToId(String databaseName, String tableName) { | ||
| String[] dbPath = transformDatabaseNameToNamespace(databaseName); | ||
| String[] result = new String[dbPath.length + 1]; | ||
| System.arraycopy(dbPath, 0, result, 0, dbPath.length); | ||
| result[dbPath.length] = tableName; | ||
| return result; | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🔴 Blocking: No SPI wiring — this catalog can't be used from Flink SQL
This PR introduces
BaseLanceNamespaceCatalogbut doesn't:createCatalogTable(...)connector.lance.table.LanceCatalogFactoryto construct itCatalogFactorySPI +META-INF/servicesregistrationThat means
CREATE CATALOG xx WITH ('type'='lance-namespace', ...)in Flink SQL won't work at all — the catalog can only be instantiated by hand-written Java. Given the PR title is "add catalog namespace support", this is a significant gap.I (@fightBoxing) will pick up the SPI wiring as a follow-up once the structural items in comments #1 and #2 are settled, so you don't need to do this part — but please coordinate with me on the final shape of the catalog constructor signature so I can wire it in cleanly.
A few smaller issues on the class itself:
getTablereturn type narrowing: signature returnsCatalogTablebut the interface contract isCatalogBaseTable. This may not compile under some Flink minor versions and is fragile across upgrades — please widen.parentPrefixvsextraLevel: silently mutually exclusive withparentPrefixwinning. Please validate inLanceNamespaceConfigthat both aren't set simultaneously, otherwise misconfigurations are invisible.alterTable/renameTable/alterDatabase: silently log-only with no exception — callers think it succeeded. Please throwUnsupportedOperationException(or a specific Flink exception).CatalogExceptionfrompartitionExistswill break Flink planners that call it speculatively. Consider returningfalseforpartitionExistsand empty list forlistPartitionswhen the table has no partition spec.