Skip to content

Add Directories feature for managing objects (including unstructured data) on object stores - #4613

Open
jbonofre wants to merge 14 commits into
apache:mainfrom
jbonofre:directory
Open

jbonofre wants to merge 14 commits into
apache:mainfrom
jbonofre:directory

Conversation

@jbonofre

@jbonofre jbonofre commented Jun 4, 2026 •

Copy link
Copy Markdown
Member

Directories allow users to point Polaris at a location/prefix on an object store (S3, GCS, Azure) containing objects (including unstructured data like images, videos, documents) and automatically track the objects via an Iceberg table with object-level metadata (location, size, content type, checksum, last modified, etc.).

When a directory is created, Polaris stores the directory configuration (name, location, scan filters, scan schedule) as a DIRECTORY entity and also creates an associated Iceberg inventory table with the 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).

Location validation

base_location is validated like a table location, on creation and again before each scan: 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.

Scan service

A simple scan endpoint populates the directory table:
POST /v1/{prefix}/namespaces/{namespace}/directories/{directory}/scan

  • Lists the objects under base_location (with read/list credentials scoped to that location), applies the include/exclude filters, and replaces the table content with a Parquet data file in a single overwrite commit. A failed scan leaves the table unchanged; if the commit state is unknown, the new data file is kept, as the commit may have landed.
  • Fills file_uri, content_type (guessed from the file name), size and last_modified; the other columns are left empty.
  • Requires UPDATE_TABLE on the directory and a FileIO that supports listing a prefix.
  • Disabled by default, enabled with the new ENABLE_DIRECTORY_SCAN feature flag: the scan is synchronous and keeps the listing in memory, so it is not suited to large directories yet. When disabled, the endpoint is rejected and not advertised in the catalog config.
  • Runs on demand only: scan-schedule stays informational, so periodic scans are left to the caller or an external scheduler.
  • The scan is pluggable through the DirectoryScanService SPI: the built-in implementation is a @DefaultBean, and an extension can replace it with its own CDI bean (for example to compute checksums or update the table incrementally).
  • Adds iceberg-data, iceberg-parquet and parquet-hadoop (same Parquet version already on the runtime classpath) to the runtime service.

Notes for reviewers

  • Scanner behavior is covered by unit tests on an in-memory file system, and the REST create/scan/drop flow and location validation by an end-to-end test on a file-based catalog (DirectoryServiceIntegrationTest). It was also tested manually on S3. It has not been tested on GCS or Azure yet.
  • The scan endpoint emits no Polaris events yet.
  • Credential vending for the remote files themselves is not addressed here: reading the inventory does not give access to the objects, as documented in directories.md.

Checklist

  • 🛡️ Don't disclose security issues! (contact [email protected])
  • 🔗 Clearly explained why the changes are needed, or linked related issues: Fixes #
  • 🧪 Added/updated tests with good coverage, or manually tested (and explained how)
  • 💡 Added comments for complex logic
  • 🧾 Updated CHANGELOG.md (if needed)
  • 📚 Updated documentation in site/content/in-dev/unreleased (if needed)

@github-project-automation github-project-automation Bot moved this to PRs In Progress in Basic Kanban Board Jun 4, 2026
@jbonofre
jbonofre marked this pull request as draft June 4, 2026 09:49
Comment on lines +199 to +205
schema:
type: string
enum:
- vended-credentials
style: simple
explode: false
example: "vended-credentials"

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.

Suggested change
schema:
type: string
enum:
- vended-credentials
style: simple
explode: false
example: "vended-credentials"
schema:
type: array
items:
type: string
enum:
- vended-credentials
example: "vended-credentials"

Storage configurations required to access the directory, encompassing both credentials and other necessary
settings for storage access, such as the client region for S3.
items:
$ref: './generic-tables-api.yaml#/components/schemas/StorageAccessConfig'

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.

Would be worthwhile extracting this schema to a common set of schemas for various APIs, rather than referencing the generic-tables API spec directly?


### Credential vending

The directory table might contain additional fields for credential vending.

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 would like to understand how we envision credential vending.

Right now, if the spec was live, clients could request vended credentials for the inventory table, but would necessarily have to be in possession of their own storage credentials, in order to access the actual data.

I think it would be a real added-value if Polaris could also be the governing entity that grants access to the remote files, via some form of credential vending.

It's too soon to sort out the details, but my gut feeling is that we'll need a form of "fast authz checks", similar to what was proposed in #3995 for remote signing. In which case, it's likely that the inventory table would have to store some encrypted payload that will be used later for generating the storage credentials.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I added a note related to credential vending in the description for now.

@github-actions github-actions Bot added the stale label Jul 12, 2026
@snazy snazy removed the stale label Jul 13, 2026
@github-actions github-actions Bot added the stale label Aug 13, 2026
@snazy snazy removed the stale label Aug 17, 2026
@github-actions github-actions Bot added the stale label Sep 20, 2026
@jbonofre jbonofre removed the stale label Sep 23, 2026
@jbonofre
jbonofre force-pushed the directory branch 2 times, most recently from 4400916 to 2a5338b Compare October 6, 2026 05:19
@jbonofre jbonofre added this to the 1.9.0 milestone Oct 6, 2026
@apache apache deleted a comment from github-actions Bot Oct 8, 2026
@apache apache deleted a comment from github-actions Bot Oct 8, 2026
@apache apache deleted a comment from github-actions Bot Oct 8, 2026
@jbonofre
jbonofre marked this pull request as ready for review October 16, 2026 03:57
@jbonofre jbonofre changed the title Add Directories feature for managing objects (including unstructured data) on object stores Add Directory feature for managing objects (including unstructured data) on object stores Oct 18, 2026
@jbonofre jbonofre changed the title Add Directory feature for managing objects (including unstructured data) on object stores Add Directories feature for managing objects (including unstructured data) on object stores Oct 18, 2026

@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 to see this follow the generic-table path closely, with scan off by default and replaceable through an SPI. Main asks are inline: the drop authz target, the SPI default method, pagination, and the inventory files ending up in their own scan.

Unanchored items:

  • Tests: no handler authz test like GenericTableCatalogHandlerAuthzTest. Can we add allow/deny cases for each directory op, plus a read-only principal getting 403 on scan/drop in PolarisDirectoryServiceIntegrationTest?
  • Tests: can we cover ENABLE_DIRECTORY_SCAN=false (scan rejected, not in /v1/config) and ENABLE_DIRECTORIES=false?
  • CHANGELOG: can we mark Directories as beta and say ENABLE_DIRECTORIES defaults to true, since every catalog config now lists the endpoints?
  • PR metadata: can we add a feat: title prefix and link an issue or the dev-list thread?
  • Docs: can directories.md say that dropping or writing the inventory table through the Iceberg API breaks the directory?

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

public boolean dropDirectory(TableIdentifier identifier) {
this.inventoryTable = inventoryTableIdentifier(identifier);
PolarisAuthorizableOperation op = PolarisAuthorizableOperation.DROP_TABLE_WITHOUT_PURGE;
authorizeCreateTableLikeUnderNamespaceOperationOrThrow(op, identifier);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Drop checks DROP_TABLE_WITHOUT_PURGE on the parent namespace, not on the directory. Generic tables check the leaf (resolveAndAuthorizeBasicTableLikeOperationOrThrow in GenericTableCatalogHandler). Two effects: a TABLE_DROP grant on the directory itself does nothing, and an external authorizer sees a namespace target, so a per-directory deny won't apply. Can we switch to the leaf helper with PolarisEntitySubType.DIRECTORY?

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

* @return the initialized catalog
* @throws IllegalStateException if the connection configuration is invalid
*/
DirectoryCatalog createDirectoryCatalog(

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Adding an abstract method to this SPI breaks every out-of-tree FederatedCatalogFactory at compile time. Every in-tree implementation just throws UnsupportedOperationException anyway. Can this be a default method that throws, so we can drop the three overrides and their TODOs?

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

public Response listDirectories(
String prefix,
String namespace,
String pageToken,

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

pageToken/pageSize are accepted here but never passed down, and PolarisDirectoryCatalog always uses PageToken.readEverything(). So a namespace with many directories returns one unbounded page. Can we follow GenericTableCatalogHandler.listGenericTables (PageToken.build + rejectIncompleteListing + setNextPageToken)?

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

List<Pattern> excludePatterns = compile(exclude);

List<Record> records = new ArrayList<>();
for (FileInfo file : prefixIO.listPrefix(baseLocation)) {

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 lists everything under the base location, including the inventory table's own files when they live under it. That happens with allow.unstructured.table.location=true and a base location above the namespace location. Old data files stay on storage after an overwrite, so each rescan also indexes the Parquet and metadata files from earlier scans. Can we skip table.location() here, or reject that layout at create time?

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

throw new NoSuchNamespaceException("Namespace does not exist: %s", identifier.namespace());
}
// The base location is read with vended credentials: it must be within the allowed locations
CatalogUtils.validateLocationsForTableLike(

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Unlike table create, this doesn't run the location-overlap check (LocalIcebergCatalog.validateNoLocationOverlap, gated by ALLOW_TABLE_LOCATION_OVERLAP). So a directory can point at a sibling table's location, and a scan writes that table's file names and sizes into an inventory the caller can read. Is that intended, or should directories get the same overlap check?

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

this.icebergCatalog.dropTable(tableId, false);
LOGGER.debug("Dropped associated Iceberg table {} for directory {}", tableId, identifier);
} catch (Exception e) {
LOGGER.error("Failed to drop associated Iceberg table for directory {}", identifier, 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.

Log-then-rethrow: the exception gets logged here and again by the framework. Can we drop the try/catch?

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


// Check that the inventory table name does not collide with an existing entity
TableIdentifier tableId = inventoryTableIdentifier(identifier);
if (this.icebergCatalog.tableExists(tableId)) {

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 pre-check races with a concurrent createTable of <dir>__inventory. The rollback below already handles the case where createTable fails. Can we drop the pre-check and rely on the AlreadyExistsException from createTable?

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

}
}

private static List<Pattern> compile(List<String> regexes) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Filters are only compiled at scan time, so a bad regex is accepted on create and only fails on the first scan. Can we compile them in createDirectory and reject bad ones there? Capping pattern count and length would also limit backtracking cost.

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

Comment thread CHANGELOG.md Resolved
…data) on object stores

Directories allow users to point Polaris at a location/prefix on an object store
(S3, GCS, Azure) containing objects (including unstructured data like images, videos, documents)
and automatically track the objects via an Iceberg table with objecr-level
metadata (location, size, content type, checksum, last modified, etc.).

When a directory is created, Polaris stores the directory configuration
(name, location, scan filters, scan schedule) as a DIRECTORY entity
and also creates an associated Iceberg table with the predefined schema.
jbonofre and others added 7 commits October 29, 2026 15:00
- Name the inventory table <directory>__inventory: a directory and a table
  cannot share a name, so creating the table always failed and rolled back
- Register the inventory table as a passthrough resolution path
- Validate base_location against the allowed locations on create and scan
- Let the scan use FileIO wrapped by ExceptionMappingFileIO
- Add a REST end-to-end test for the directory create, scan and drop flow
When the overwrite commit fails with CommitStateUnknownException, the
commit may have landed: deleting the new Parquet file could leave the
inventory snapshot pointing to a missing file, breaking every read of the
inventory. Rethrow the exception without deleting the file, as Iceberg's
SnapshotProducer does.
The built-in scan is synchronous: it runs inside the request and keeps the
listing in memory, so it is not suited to large directories yet.
ENABLE_DIRECTORY_SCAN is now false by default, so users who enable it know
they run a synchronous scan.

The directory integration test enables the scan with a dedicated test
profile, and the regtests no longer expect the scan endpoint in the
catalog configuration.
Replace the speculative credential vending section with the current
behavior: the directory table lists the objects but does not give access
to them. Vended credentials are scoped to the directory table location,
privileges on the directory or its table don't cover the base location,
and the scan credentials never leave the server.
Authorize directory drop on the directory itself, paginate directory listing, validate filter regexes on creation, skip the inventory table files during a scan, make FederatedCatalogFactory.createDirectoryCatalog a default method, and add authorization, endpoint and read-only principal tests. Mark Directories as beta.
… schema

Apply the sibling location overlap check to the directory base location on creation, and move StorageAccessConfig to a common schemas file referenced by the generic tables and directories specs.
@jbonofre

Copy link
Copy Markdown
Member Author

As discussed during the Community Meeting, I will split this in three PRs:

  • PR1: only the spec change
  • PR2: entity + SPI
  • PR3: simple scanner service

@dimas-b dimas-b 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.

Reviewing only the API part since, as we discussed, in the community sync today, this PR is going to be split, I think.

The API LGTM with some minor comments below 👍

paths:
/polaris/v1/{prefix}/namespaces/{namespace}/directories:
parameters:
- $ref: '../iceberg-rest-catalog-open-api.yaml#/components/parameters/prefix'

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.

non-blocking: I do not think yaml cross-references are convenience for downstream users. If someone wants to copy this API definition to generate clients, the IRC spec has to be copied too, but the IRC spec does not appear to be a conceptual prerequisite to the Directories spec.

Also (perhaps more critical): changes to IRC spec do not have to automatically trickle down to the directories spec, IMHO. It may be a weak point with respect to these two parameters, but in general I think it makes sense 🤔

operationId: listDirectories
parameters:
- $ref: '../iceberg-rest-catalog-open-api.yaml#/components/parameters/page-token'
- $ref: '../iceberg-rest-catalog-open-api.yaml#/components/parameters/page-size'

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.

Aside from yaml cross-references, I do not think pagination parameters are defined with due rigour in IRC. Specifically, the treatment of empty page tokens and defauting to "all". I think it would be nicer to define pagination locally in a Polaris spec.


---
paths:
/polaris/v1/{prefix}/namespaces/{namespace}/directories:

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.

Non-blocking: this path prefix interleaves with other Polaris API (e.g. Generic Tables, Policies...). Since endpoints are distinct, it is not a problem. However, it makes separating APIs more difficult.

The v1 prefix is shared and it is usually perceived as the "API root".

There is no static prefix just for the directories API, which can complicate network routing if someone wants to segregate traffic by API.

I know this fit the existing pattern, so my comment is non-blocking 😅

@dimas-b dimas-b 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.

Proactively reviewing non-API parts. LGTM with some comments 😅

Nice feature overall, @jbonofre ! Sorry about the delayed review.


@ApplicationScoped
@Priority(350)
public class DirectoryConfigEndpoints implements CatalogConfigEndpointContributor {

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'm not sure what we gain by exposing Directory endpoints in the IRC config.

Previous discussion on this topic identified only a very narrow use case for Spark Clients discovering Generic Tables:

https://lists.apache.org/thread/84yc07xdo7p7385vvtm9xomm7oxwh7o8

Do we expect a Directories API client to check IRC config for the presence of Directory endpoints?

ConnectionConfigInfoDpo connectionConfig,
PolarisCredentialManager polarisCredentialManager,
Map<String, String> catalogProperties) {
throw new UnsupportedOperationException("Directory federation is not supported.");

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.

This is awkward... why should a "federated" Catalog Factory care about Directories at all? It does not look like we have any support for Directories in Federated catalogs ATM 🤔


public static final FeatureConfiguration<Boolean> ENABLE_DIRECTORY_SCAN =
PolarisConfiguration.<Boolean>builder()
.key("ENABLE_DIRECTORY_SCAN")

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.

Do we need a flag for this? It could be disabled via the Authorizer, I guess 🤔

"credentials");
}

public String directories(Namespace ns) {

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.

This is used only in tests. Could we move it to test utilities?

"polaris/v1/{prefix}/namespaces/{namespace}/generic-tables/{generic-table}";

// Directory endpoints
public static final String V1_DIRECTORIES =

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.

Why not keep it in DirectoryEndpoints for better feature isolation?

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.

This call always throws, does it not? 🤔

// 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)
.validateNoDirectoryLocationOverlap(

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.

@adutra : could review from the recent location check improvements perspective?

identifier, baseLocation, resolvedParent.getRawFullPath());

DirectoryScanner.validateFilters(parseJsonArray(filterInclude), parseJsonArray(filterExclude));
TableIdentifier tableId = inventoryTableIdentifier(identifier);

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.

duplicates line 273


@QuarkusTest
@TestProfile(Profiles.DefaultProfile.class)
public class PolarisDirectoryCatalogRelationalTest extends AbstractPolarisDirectoryCatalogTest {}

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.

What makes it "relational"? Did you mean RelationalJdbcProfile? 🤔

implementation("org.apache.iceberg:iceberg-core")
implementation("org.apache.iceberg:iceberg-data")
implementation("org.apache.iceberg:iceberg-parquet")
implementation(libs.parquet.hadoop)

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.

Could we put Directories impl. code into a separate module to avoid these new deps in runtime/service?

This is our usual practice to avoid automatically pushing new feature deps to downstream servers. Pretty much all downstream servers have to depend on runtime/service. Ideally optional features should only be bundled in runtime/server to allow downstream project to opt in/out.

@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.

5 participants