Skip to content

feat: add RegisterTable overwrite support (cherry-pick of #3719) - #4506

Merged
adutra merged 10 commits into
apache:mainfrom
adutra:register-table-overwrite
Jun 2, 2026
Merged

adutra merged 10 commits into
apache:mainfrom
adutra:register-table-overwrite

Conversation

@adutra

@adutra adutra commented May 20, 2026 •

Copy link
Copy Markdown
Contributor

This is a cherry-pick of #3719.

Although the logic has been reviewed and confirmed, the patch didn't apply cleanly; therefore, a brief follow-up review is recommended.

UPDATE

Reviews by Copilot uncovered a few serious issues, notably with the Ranger authorizer. Therefore the PR is now significantly different from #3719. A full review is advised.

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)

Copilot AI review requested due to automatic review settings May 20, 2026 11:45
@github-project-automation github-project-automation Bot moved this to PRs In Progress in Basic Kanban Board May 20, 2026
@adutra

adutra commented May 20, 2026

Copy link
Copy Markdown
Contributor Author

\cc @sririshindra @flyrain

Copilot AI 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.

Pull request overview

This PR adds support for overwrite=true on the Iceberg REST register table flow for internal (Polaris-managed) catalogs, including new RBAC operation semantics, documentation, and test coverage for overwrite behaviors.

Changes:

  • Implement registerTable(..., overwrite=true) behavior in the internal IcebergCatalog and route REST requests through IcebergCatalogHandler.
  • Introduce REGISTER_TABLE_OVERWRITE authorization operation mapped to TABLE_FULL_METADATA.
  • Add/extend unit + integration tests and update federation/user documentation plus CHANGELOG.md.

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
site/content/in-dev/unreleased/federation/iceberg-rest-federation.md Documents that overwrite registration is internal-only and rejected for federated catalogs.
runtime/service/src/test/java/org/apache/polaris/service/catalog/iceberg/AbstractIcebergCatalogTest.java Adds catalog-level overwrite behavior tests (update existing, create when missing, reject when overwrite=false).
runtime/service/src/test/java/org/apache/polaris/service/catalog/iceberg/AbstractIcebergCatalogHandlerAuthzTest.java Adds authz tests for overwrite=true privilege requirements.
runtime/service/src/main/java/org/apache/polaris/service/catalog/iceberg/IcebergCatalogHandler.java Adds overwrite routing/authorization and rejects overwrite for federated catalogs.
runtime/service/src/main/java/org/apache/polaris/service/catalog/iceberg/IcebergCatalog.java Implements overwrite-aware registerTable behavior for internal catalogs.
polaris-core/src/main/java/org/apache/polaris/core/auth/RbacOperationSemantics.java Registers RBAC semantics for the new REGISTER_TABLE_OVERWRITE operation.
polaris-core/src/main/java/org/apache/polaris/core/auth/PolarisAuthorizableOperation.java Adds the new authorizable operation enum value.
integration-tests/src/main/java/org/apache/polaris/service/it/test/PolarisRestCatalogIntegrationBase.java Adds REST integration coverage for overwrite=true register behavior.
CHANGELOG.md Adds changelog entries describing overwrite support and authorization mapping.

Comment on lines +619 to +620
authorizeCreateTableLikeUnderNamespaceOperationOrThrow(
PolarisAuthorizableOperation.REGISTER_TABLE_OVERWRITE, identifier);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I think this is a very valid concern.

cc @sririshindra @flyrain

I will do the suggested changes, let me know what you think.

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 believe the same problem exists for normal "create" vs. "update" table. I think we do not have to alter RBAC in this PR (as long as locations are validated), but it's worth a follow-up discussion.

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.

By "alter" I mean existing call paths. The Copilot suggestion above SGTM.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

OK but should I alter the RBAC logic for the register-table-overwrite operation, or are you suggesting to keep the current logic then revisit all the impacted logics later?

@dimas-b dimas-b May 21, 2026 •

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.

Yes, I think REGISTER_TABLE_OVERWRITE should be applied to the table (entity) and REGISTER_TABLE to the namespace -- in this PR 🙂

What I meant for the follow-up discussion is extending "create" / "register" checks to cover the entity too. I believe OPA is capable of that.

@sungwy : FYI.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@dimas-b OK I implemented your suggestion, PTAL.

Comment on lines 288 to 292
register(CREATE_TABLE_STAGED, TABLE_CREATE);
register(CREATE_TABLE_STAGED_WITH_WRITE_DELEGATION, EnumSet.of(TABLE_CREATE, TABLE_WRITE_DATA));
register(REGISTER_TABLE, TABLE_CREATE);
register(REGISTER_TABLE_OVERWRITE, TABLE_FULL_METADATA);
register(LOAD_TABLE, TABLE_READ_PROPERTIES);
@adutra
adutra force-pushed the register-table-overwrite branch from 95f678b to 401a92d Compare May 20, 2026 12:08
@adutra adutra changed the title feat: add RegisterTable overwrite support (#3719) feat: add RegisterTable overwrite support (cherry-pick of #3719) May 20, 2026

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

Sorry for coming late to this review parting and expanding scope... but WDYT?

throw new NoSuchTableException("Table does not exist: %s", identifier);
}

validateLocationForTableLike(identifier, metadataFileLocation, resolvedPath);

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.

Should do this in registerNewTable() too?

resolvedEntityView.getPassthroughResolvedPath(
ResolvedPathKey.ofTableLike(identifier), PolarisEntitySubType.ANY_SUBTYPE);
if (resolvedPath == null || resolvedPath.getRawLeafEntity() == null) {
throw new NoSuchTableException("Table does not exist: %s", 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.

Should we do this check on line 330 instead?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

On line 330 we call tableExists already. Here, we need the resolved path instance. It should normally never be null (since we know already that the table exists), but I think the original author introduced this check in case the entity is dropped between the check on line 330 and this line.

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.

Yeah, exactly. The double load looks odd in this context. However, I do not feel strongly about this.

Set.of(PolarisStorageActions.READ, PolarisStorageActions.LIST));

TableMetadata metadata = TableMetadataParser.read(fileIO, metadataFileLocation);
validateMetadataFileInTableDir(identifier, metadata);

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.

Should we check this in registerNewTable() too?

RBAC_SEMANTICS_BY_OPERATION.put(
PolarisAuthorizableOperation.REGISTER_TABLE,
new RangerPolarisOperationSemantics(toSet(TABLE_CREATE), null, ResolvedPathRooting.ROOT));
RBAC_SEMANTICS_BY_OPERATION.put(

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

FYI this PR now has ramifications into the Ranger authorizer. I did the best I could. There is no simple way to map a super-privilege like TABLE_FULL_METADATA into Ranger logic. And oddly enough, some test files already mentioned a privilege named "table-metadata-full".

cc @flyrain @sririshindra @sneethiraj

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.

@adutra do you see this being a spec mapping issue? if so, I feel we should list out the mapping (your effort) in our docs, to set up a good contract.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

IMO that's a question for @sneethiraj.

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 change looks reasonable to me. Any known reasons to delay merging it?

If Ranger integration is affected we can fix-forward on main.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@adutra / @dimas-b Let me have a look at this change today.

IcebergTableLikeEntity updatedEntity =
new IcebergTableLikeEntity.Builder(existingEntity)
.setInternalProperties(storedProperties)
.setMetadataLocation(metadataFileLocation)

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.

The overwrite path updates metadata-location and internal properties but doesn't call .setBaseLocation(metadata.location()) . So if the new metadata points at a different table location, the entity's stored base drifts. The normal commit path (line ~1612) does update it. Overlap checks and credential-vending scope depend on this being current.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good catch, probably an oversight. cc @sririshindra

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.

.setBaseLocation(metadata.location()) does not look correct to me. The base location is normally the parent of both "data" and "metadata" sub-directories... right?

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.

If metadata.location() is outside the old base location, that will (should?) fail the location checks, right?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

.setBaseLocation(metadata.location()) does not look correct to me. The base location is normally the parent of both "data" and "metadata" sub-directories... right?

AFAIK metadata.location() returns the table base location. The metadata file location is returned by metadata.metadataFileLocation().

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.

right 🤦

RBAC_SEMANTICS_BY_OPERATION.put(
PolarisAuthorizableOperation.REGISTER_TABLE,
new RangerPolarisOperationSemantics(toSet(TABLE_CREATE), null, ResolvedPathRooting.ROOT));
RBAC_SEMANTICS_BY_OPERATION.put(

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.

@adutra do you see this being a spec mapping issue? if so, I feel we should list out the mapping (your effort) in our docs, to set up a good contract.

@flyingImer flyingImer left a comment •

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.

oops repeated clicks

@adutra
adutra force-pushed the register-table-overwrite branch from 442a1c8 to da28087 Compare May 26, 2026 10:07
}

String locationDir = metadataFileLocation.substring(0, lastSlashIndex);
if (tableExists) {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

FYI, we had a test explicitly testing that if overwrite is true but the table doesn't exist, the register operation should behave as if overwrite is false.

dimas-b
dimas-b previously approved these changes May 26, 2026
@github-project-automation github-project-automation Bot moved this from PRs In Progress to Ready to merge in Basic Kanban Board May 26, 2026
@dimas-b
dimas-b requested a review from flyingImer May 26, 2026 17:48
@adutra
adutra force-pushed the register-table-overwrite branch from 977213c to c4176f6 Compare May 27, 2026 10:44
// For non-Polaris/federated catalogs, reject overwrite until this is
// supported by a common catalog contract.
CatalogEntity catalogEntity = getResolvedCatalogEntity();
if (catalogEntity.isExternal()) {

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

FYI this logic didn't exist in the original PR, but one test fails without it, so I added it.

This is because the test baseCatalog instanceof IcebergCatalog is NOT a reliable test to know if a catalog is external: indeed, a static facade external catalog would pass that test.

@flyingImer flyingImer left a comment

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.

Overall LGTM, just minor callouts see inlines

String.format("Failed to fetch resolved parent for TableIdentifier '%s'", identifier));
}

validateLocationForTableLike(identifier, metadataFileLocation, resolvedParent);

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.

This validation is new for the normal register path too, not only for overwrite=true. I think the hardening makes sense, but it can reject register calls that previously succeeded when the metadata file was outside the resolved storage scope/table location. I believe we should mention that behavior change in the changelog and PR description?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

IMHO this doesn't deserve a changelog.

resolutionManifest.resolveAll();

PolarisResolvedPathWrapper tableTarget =
resolutionManifest.getResolvedPath(

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.

FYI, my claude pointed out a ux nit:

if this identifier is occupied by a view, this falls through to the namespace REGISTER_TABLE path and the later create path reports the conflict. That is probably fine authz-wise, but the error may be less clear than "a view already exists at this identifier"

The ux callout makes sense to me, but I haven't dived too deep into how to remediate it

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fair enough, I introduced a view conflict detection logic, PTAL.

dimas-b
dimas-b previously approved these changes May 29, 2026
@adutra
adutra merged commit 1dd5fee into apache:main Jun 2, 2026
43 of 63 checks passed
@github-project-automation github-project-automation Bot moved this from Ready to merge to Done in Basic Kanban Board Jun 2, 2026
@adutra
adutra deleted the register-table-overwrite branch June 2, 2026 13:41
MonkeyCanCode pushed a commit to MonkeyCanCode/polaris that referenced this pull request Jun 4, 2026
MonkeyCanCode pushed a commit to MonkeyCanCode/polaris that referenced this pull request Jun 4, 2026
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.

6 participants