Skip to content

Policy Store: Add PolicyEntity and PolicyTypes #1133

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

Merged
merged 7 commits into from
Mar 18, 2025

Conversation

HonahX
Copy link
Contributor

@HonahX HonahX commented Mar 7, 2025

This PR introduces basic classes for supporting Policy Store in Polaris, as discussed in #1059.

  1. PolicyEntity – Represents a policy object in Polaris.
  2. PolicyType – Defines a category of policies, which can be either predefined or custom (user-defined). Currently only predefined classes supported

This will be the first step to unblock all other Policy PRs and discussions

cc: @flyrain

Copy link
Contributor

@flyrain flyrain left a comment

Choose a reason for hiding this comment

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

LGTM. Left minor comments! Thanks @HonahX for the PR.


@JsonIgnore
public int getPolicyTypeCode() {
String policyTypeCode = getPropertiesAsMap().get(POLICY_TYPE_CODE_KEY);
Copy link
Contributor

Choose a reason for hiding this comment

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

We will need policy type to be a top-level field instead of hidden in property map in the future, but it's fine now.

import jakarta.annotation.Nullable;

/* Represents all predefined policy types in Polaris */
public enum PredefinedPolicyType implements PolicyType {
Copy link
Contributor

Choose a reason for hiding this comment

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

Minor: a name like SystemPolicyTypes ? Just wanna brainstorming a bit.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think "Predefined Policy" is widely used throughout our design doc, so I still lean slightly toward keeping it. However, I’ll update it to the plural form.

@github-project-automation github-project-automation bot moved this from PRs In Progress to Ready to merge in Basic Kanban Board Mar 7, 2025
@dimas-b
Copy link
Contributor

dimas-b commented Mar 7, 2025

As discussed in the sync meeting, if possible, please hold this PR until a NoSQL peristence impl. is available (hopefully soon).

@HonahX
Copy link
Contributor Author

HonahX commented Mar 7, 2025

Hi @dimas-b, do you mean hold #1104 which includes the new Persistence Table, interface and impl? For that, I marked #1104 as draft to allow some time for ongoing refactoring and new impl.

For this one, the PolicyEntity will be persisted just like other existing entities. So I think it should not be related to any changes in persistence refactoring or new persistence impl and we can proceed this in parallel with ongoing persistence layer work.

Will NoSQL persistence impl introduce any changes that affect the current persistence model for Entitites?

@dimas-b
Copy link
Contributor

dimas-b commented Mar 7, 2025

Current NoSQL POC using typeCode (#1112), so adding new types will cause some interference, hence my request to hold this PR as well.

@flyrain
Copy link
Contributor

flyrain commented Mar 8, 2025

I think it’s unreasonable to hold multiple PRs due to one persistence implementation. The NoSQL implementation isn’t the only ongoing persistence change—@singhpk234 and I are actively working on the Postgres implementation as well. Given that multiple efforts are running in parallel, we shouldn’t allow one refactor to block overall development.

cc @eric-maynard @dennishuo

@jbonofre
Copy link
Member

jbonofre commented Mar 8, 2025

@flyrain I agee. However, I'm a bit surprised @singhpk234 and you are working on PostgreSQL backend while the "new" API are not yet finalize. @dennishuo and @dimas-b are still working on it. I just want to avoid dual effort.
I propose to open draft PRs to give visibility and anticipate questions/comments to gain time.

@flyrain
Copy link
Contributor

flyrain commented Mar 9, 2025

Thanks @jbonofre! Just like the MongoDb effort, Postgres support is an ongoing effort. I have made this PR(#1128) pass all tests,

snazy
snazy previously requested changes Mar 11, 2025
Copy link
Member

@snazy snazy left a comment

Choose a reason for hiding this comment

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

I think the test coverage is not good enough, because I could imagine errors in the Iceberg catalog implementations as soon as there's some policy in there. Also the interaction of these new types via the entity manager is untested.

Generally, I think it's better to see the whole Policy thing working in a feature branch, which can be a PR in draft state, instead of pushing small bits of rather unused code.

@github-project-automation github-project-automation bot moved this from Ready to merge to PRs In Progress in Basic Kanban Board Mar 11, 2025
@HonahX
Copy link
Contributor Author

HonahX commented Mar 11, 2025

Hi @snazy, thanks for the feedback!

I think the test coverage is not good enough, because I could imagine errors in the Iceberg catalog implementations as soon as there's some policy in there.

Could you clarify this concern? The Policy implementation is independent of the Iceberg catalog. It has its own service interface/implementation, handler, and a PolicyCatalog within service-common, all separate from Iceberg. (I realize part of the design doc is outdated—I'll update that section.)

Also the interaction of these new types via the entity manager is untested.

I can add more tests in ResolverTest and PolarisTestMetastoreManager to improve coverage.

Generally, I think it's better to see the whole Policy thing working in a feature branch, which can be a PR in draft state, instead of pushing small bits of rather unused code.

I do have a draft PR #1104 that includes all necessary Polaris-core changes for the policy store, including basic classes and the PolicyMappingRecord persistence interfaces/implementations. I can publish a larger draft PR that combines core changes with the service implementation for reference. That said, I’d still recommend reviewing and merging smaller pieces incrementally—this makes it easier for everyone to review and avoids one massive PR that’s harder to manage.

Let me know what you think!


/* Represents all predefined policy types in Polaris */
public enum PredefinedPolicyTypes implements PolicyType {
DATA_COMPACTION(0, "system.data-compaction", true),
Copy link
Contributor

Choose a reason for hiding this comment

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

[doubt] I might be late to this, but why system prefix ?

Copy link
Contributor Author

@HonahX HonahX Mar 13, 2025

Choose a reason for hiding this comment

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

The prefix is to make it consistent with the path of the content schema of these policies, introduced in #969.

* either predefined or custom (user-defined).
*
* <p>A policy type can be either inheritable or non-inheritable. Inheritable policies are passed
* down to lower-level entities (e.g., from a namespace to a table).
Copy link
Contributor

Choose a reason for hiding this comment

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

[doubt] may be a naive question, what stops these policies to inherited from namespace -> view ?
As we don't wanna run stuff for views >

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As we don't wanna run stuff for views >

Good question, I think that's a valid concern. Currently, our engine determines how policies are enforced, and the TMS service is focused solely on tables. That said, if we later find it necessary to restrict inheritance, we can extend the PolicyType to provide the functionality to limit the valid target types.

cc @flyrain

Copy link
Contributor

Choose a reason for hiding this comment

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

Currently, our engine determines how policies are enforced, and the TMS service is focused solely on tables

Thats true for enforcing part, but polaris here is acting as a policy store, which should make sure if such inheritence if they are un-intentional are blocked. So a call to get a TMS policy on view should return nothing.

That being said it fine if we want address this later, considering presently the caller just wants TMS on tables and never on a view.

Copy link
Contributor

@singhpk234 singhpk234 left a comment

Choose a reason for hiding this comment

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

LGTM as well, thanks @HonahX !

@HonahX HonahX force-pushed the honahx_add_policy_base_classes branch from 61c0059 to 444fd1b Compare March 18, 2025 00:02
@flyrain flyrain dismissed snazy’s stale review March 18, 2025 18:38

The comment is resolved by the comment and #1133 (comment) and new unit test cases added in the new commits.

@github-project-automation github-project-automation bot moved this from PRs In Progress to Ready to merge in Basic Kanban Board Mar 18, 2025
@flyrain flyrain merged commit b1f7c68 into apache:main Mar 18, 2025
5 checks passed
@github-project-automation github-project-automation bot moved this from Ready to merge to Done in Basic Kanban Board Mar 18, 2025
rakesh-das08 pushed a commit to rakesh-das08/polaris that referenced this pull request Mar 22, 2025
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.

7 participants