Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}
}
}
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 {

Copy link
Copy Markdown
Collaborator

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 BaseLanceNamespaceCatalog but doesn't:

  • provide a concrete subclass that implements createCatalogTable(...)
  • extend the existing connector.lance.table.LanceCatalogFactory to construct it
  • add a new CatalogFactory SPI + META-INF/services registration

That 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:

  • getTable return type narrowing: signature returns CatalogTable but the interface contract is CatalogBaseTable. This may not compile under some Flink minor versions and is fragile across upgrades — please widen.
  • parentPrefix vs extraLevel: silently mutually exclusive with parentPrefix winning. Please validate in LanceNamespaceConfig that both aren't set simultaneously, otherwise misconfigurations are invisible.
  • alterTable / renameTable / alterDatabase: silently log-only with no exception — callers think it succeeded. Please throw UnsupportedOperationException (or a specific Flink exception).
  • All "Partition operations are not supported" methods: throwing CatalogException from partitionExists will break Flink planners that call it speculatively. Consider returning false for partitionExists and empty list for listPartitions when the table has no partition spec.


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;
}
}
Loading