Skip to content

Add the Directory entity, REST endpoints and DirectoryScanService SPI - #5928

Open
jbonofre wants to merge 2 commits into
apache:mainfrom
jbonofre:directory-entity-spi
Open

jbonofre wants to merge 2 commits into
apache:mainfrom
jbonofre:directory-entity-spi

Conversation

@jbonofre

@jbonofre jbonofre commented Oct 30, 2026 •

Copy link
Copy Markdown
Member

This is the second of three PRs split from #4613:

  1. Add the Directories REST API specification and documentation #5927: OpenAPI specification and documentation
  2. This PR: Directory entity, REST endpoints and DirectoryScanService SPI
  3. Add a simple directory scan service #5929: simple directory scan service

It is stacked on #5927: until that one is merged, this PR also shows its commit. Only the last commit (Add the Directory entity, REST endpoints and DirectoryScanService SPI) belongs to this PR.

Changes

  • Entity and persistence: new DIRECTORY table-like sub-type and DirectoryEntity (base location, include/exclude filters, scan schedule), with its NoSQL mapping (DirectoryObj). The relational persistence needs no schema change.
  • REST endpoints: list, create, load and drop directories (DirectoryCatalogAdapter, DirectoryCatalogHandler, PolarisDirectoryCatalog), with the corresponding events (new DIRECTORY event category). Creating a directory also creates its Iceberg inventory table with a predefined schema. The table is named <directory>__inventory, because a directory and a table cannot share a name in a namespace (both are table-like entities). Dropping the directory drops the table.
  • Location validation: base_location is validated like a table location: it must be within the catalog's allowed locations, and within the namespace location unless polaris.config.allow.unstructured.table.location is true on the catalog. It must not overlap the location of a sibling table, view, directory or namespace. Filters must be valid regular expressions.
  • DirectoryScanService SPI: POST .../directories/{directory}/scan authorizes the request (UPDATE_TABLE on the directory), vends read/list credentials scoped to base_location, and then calls the DirectoryScanService bean. An extension can provide its own bean. In this PR, the default bean (DefaultDirectoryScanService, a @DefaultBean) rejects the scan. The next PR replaces it with the simple scan service.
  • Feature flags: ENABLE_DIRECTORIES (default true) enables the directory endpoints. ENABLE_DIRECTORY_SCAN (default false) enables the scan endpoint: when disabled, the endpoint is rejected and not advertised in the catalog config. Because ENABLE_DIRECTORIES defaults to true, every catalog config now lists the four directory endpoints, hence the regtest reference updates.

Tests

  • AbstractPolarisDirectoryCatalogTest (relational and NoSQL in-memory), PolarisDirectoryCatalogHandlerAuthzTest, DirectoryConfigEndpointsTest, PolarisResourcePathsTest, TestTableLikeMapping.
  • DirectoryServiceIntegrationTest: end-to-end REST test on a file-based catalog (create/load/list/drop, location validation, read-only principal cannot scan or drop).

Notes for reviewers

Checklist

@orca-review-bot orca-review-bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice split. The adapter → handler → catalog stack follows the generic-table pattern, and the scan SPI being off by default matches the dev-list plan.

Main thing: existing directories are invisible to the location-overlap check. PolarisEntityUtils.asLocationBasedEntity has no DIRECTORY case, so the list-based sibling check resolves a sibling directory and then drops it. As a result, two directories, or a new table and an existing directory, can overlap. I left the details on the overlap call in the handler.

Tests to add: directory-vs-directory and table-vs-directory overlap, create when <name>__inventory already exists, and a base_location that contains the namespace location, so the inventory table sits inside the scanned prefix.

I also checked that a pre-existing __inventory table makes create fail and roll back the directory entity, which is the right behavior.

🤖 AI-generated review comment — agents make mistakes, so please verify before acting on it.

realmConfig(), identifier, Set.of(baseLocation), resolvedParent);
// The scan exposes the names and sizes of the objects under the base location: it must not
// overlap the location of a sibling table, view, directory or namespace
((LocalIcebergCatalog) icebergCatalog)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment promises no overlap with a sibling directory, but existing directories never get checked. The sibling loop in LocalIcebergCatalog resolves them and then passes them through PolarisEntityUtils.asLocationBasedEntity, which has no DIRECTORY case and returns empty. So directory B can sit under directory A, and its scan would list A's objects. The same gap lets a new Iceberg table land inside an existing directory. Can we add case DIRECTORY -> DirectoryEntity.of(entity) there and add a test for both cases?

🤖 AI-generated review comment — agents make mistakes, so please verify before acting on it.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. This comment is helpful but cant solve not sufficient on its own. ModelEntity.fromEntity only sets location_without_scheme for Iceberg table/view and namespace — not DIRECTORY:

ModelEntity.java

if (entity.getType() == PolarisEntityType.TABLE_LIKE) {
  if (entity.getSubType() == PolarisEntitySubType.ICEBERG_TABLE
      || entity.getSubType() == PolarisEntitySubType.ICEBERG_VIEW) {
    builder.locationWithoutScheme(
        StorageLocation.of(
                entity.getPropertiesAsMap().get(PolarisEntityConstants.ENTITY_BASE_LOCATION))
            .withoutScheme());
  }
}
if (entity.getType() == PolarisEntityType.NAMESPACE) {

Directories store base_location in internal props (DirectoryEntity.BASE_LOCATION_KEY), not location like Iceberg entities. So generateOverlapQuery may never see them even if asLocationBasedEntity is fixed.

  1. MutationAttempt.updateLocationsIndex only reads ENTITY_BASE_LOCATION ("location") from obj properties. Directories use baseLocation on DirectoryObj / base_location in internal props. Same overlap gap on NoSQL backends.

try {
this.icebergCatalog.createTable(tableId, DIRECTORY_TABLE_SCHEMA);
LOGGER.debug("Created associated Iceberg table {} for directory {}", tableId, identifier);
} catch (RuntimeException e) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This catches every RuntimeException, CommitStateUnknownException included. If the inventory commit actually succeeded, we drop the directory but leave <name>__inventory behind. Every later create of that name then fails on the leftover table. Should we skip the rollback (or check tableExists) when the commit state is unknown?

🤖 AI-generated review comment — agents make mistakes, so please verify before acting on it.

public interface DirectoryScanService {

/**
* @param identifier the directory identifier, also the identifier of its inventory table

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The inventory table is <name>__inventory, so it isn't the same identifier as the directory. Can we fix this so SPI implementers don't write to the wrong table?

🤖 AI-generated review comment — agents make mistakes, so please verify before acting on it.

.defaultValue(true)
.buildFeatureConfiguration();

public static final FeatureConfiguration<Boolean> ENABLE_DIRECTORIES =

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Defaulting a beta feature to on means every catalog's config response changes on upgrade (hence all the regtest ref churn). Was default-true agreed for 1.9.0, or should this be false like ENABLE_DIRECTORY_SCAN?

🤖 AI-generated review comment — agents make mistakes, so please verify before acting on it.

String prefix,
String namespace,
CreateDirectoryRequest createDirectoryRequest,
List<String> polarisDirectoryAccessDelegation,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

polarisDirectoryAccessDelegation is accepted but never read, so clients can send the header and nothing happens. Can we drop it from the spec until it's wired through, or pass it to the handler?

🤖 AI-generated review comment — agents make mistakes, so please verify before acting on it.

@ArnabKarmakar1108 ArnabKarmakar1108 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for working on this!

realmConfig(), identifier, Set.of(baseLocation), resolvedParent);
// The scan exposes the names and sizes of the objects under the base location: it must not
// overlap the location of a sibling table, view, directory or namespace
((LocalIcebergCatalog) icebergCatalog)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. This comment is helpful but cant solve not sufficient on its own. ModelEntity.fromEntity only sets location_without_scheme for Iceberg table/view and namespace — not DIRECTORY:

ModelEntity.java

if (entity.getType() == PolarisEntityType.TABLE_LIKE) {
  if (entity.getSubType() == PolarisEntitySubType.ICEBERG_TABLE
      || entity.getSubType() == PolarisEntitySubType.ICEBERG_VIEW) {
    builder.locationWithoutScheme(
        StorageLocation.of(
                entity.getPropertiesAsMap().get(PolarisEntityConstants.ENTITY_BASE_LOCATION))
            .withoutScheme());
  }
}
if (entity.getType() == PolarisEntityType.NAMESPACE) {

Directories store base_location in internal props (DirectoryEntity.BASE_LOCATION_KEY), not location like Iceberg entities. So generateOverlapQuery may never see them even if asLocationBasedEntity is fixed.

  1. MutationAttempt.updateLocationsIndex only reads ENTITY_BASE_LOCATION ("location") from obj properties. Directories use baseLocation on DirectoryObj / base_location in internal props. Same overlap gap on NoSQL backends.

}

@Test
public void testInventoryTableCoexistsWithDirectory() {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are only covering inventory created after the directory, not create-directory when __inventory already exists at the handler layer. I think adding a case for that would improve the coverage.

if (targetLocation.isChildOf(siblingLocation)
|| siblingLocation.isChildOf(targetLocation)) {
throw new ForbiddenException(
"Unable to create entity at location '%s' because it conflicts with existing table or namespace at "

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the message should also mention directories. Same for line 1709.

federatedCatalog =
federatedCatalogFactory
.get()
.createDirectoryCatalog(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After ENABLE_CATALOG_FEDERATION, createDirectoryCatalog defaults to UnsupportedOperationException. Directories enabled on a federated catalog fail at runtime with a generic unsupported error. Rejecting earlier with a clear message would be clearer or we can document “internal catalog only”.


@QuarkusTest
@TestProfile(Profiles.PolarisAuthzBaseProfile.class)
public class PolarisDirectoryCatalogHandlerAuthzTest extends PolarisAuthzTestBase {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are covering list/create/load/drop but no scanDirectory matrix.

* drop flow goes through the REST layer, including authorization and location validation.
*/
@ExtendWith(PolarisIntegrationTestExtension.class)
public class PolarisDirectoryServiceIntegrationTest {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we are missing cases where directory exists then overlapping table, two overlapping directories.

@adutra

adutra commented Nov 17, 2026

Copy link
Copy Markdown
Contributor

Heads-up: #5967 has been merged, so CHANGELOG.md is no longer edited directly. Changelog entries now go in a fragment file under changelog.d/, which avoids merge conflicts on CHANGELOG.md. See changelog.d/README.md for the format.

Could you rebase onto main, revert your changes to CHANGELOG.md, and add a fragment file instead if your change needs a changelog entry? A fragment is only needed for things worth calling out in release notes, such as breaking changes, metastore schema changes, or changes that require manual steps during an upgrade. Thanks!

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants