-
Notifications
You must be signed in to change notification settings - Fork 209
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
Add data compaction policy validator #1238
base: main
Are you sure you want to change the base?
Conversation
The failure seems unrelated.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @flyrain ! This looks like a great start of Policy Validators. Overall LGTM!
case METADATA_COMPACTION: | ||
case SNAPSHOT_RETENTION: | ||
case ORPHAN_FILE_REMOVAL: | ||
default: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just check my understanding: in the future when we add support for custom type, we will need to load the custom type's validator here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, something like this:
ctor = DynConstructors.builder(PolicyValidator.class).impl(impl).buildChecked();
policyValidator = ctor.newInstance();
* @param targetEntity the target Polaris entity to attach the policy to | ||
* @return {@code true} if the policy is attachable to the target entity; {@code false} otherwise | ||
*/ | ||
public static boolean canAttach(PolicyEntity policy, PolarisEntity targetEntity) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just brainstorming about the name, may be "isAttachable"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The method’s primary role is to decide whether a policy is capable of being attached to a target, "canAttach" can be appropriate. I think isAttachable
is more suitable if the method only takes a policy entity. WDYT?
import org.apache.polaris.core.exceptions.PolarisException; | ||
|
||
/** Exception thrown when a policy is invalid or violates defined rules. */ | ||
public class InvalidPolicyException extends PolarisException { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this map to status code 400, BadRequestError in rest?
} | ||
|
||
try { | ||
var policy = PolicyValidatorUtil.MAPPER.readValue(content, DataCompactionPolicy.class); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
var policy = PolicyValidatorUtil.MAPPER.readValue(content, DataCompactionPolicy.class); | |
DataCompactionPolicy policy = PolicyValidatorUtil.MAPPER.readValue(content, DataCompactionPolicy.class); |
Shall we explicitly write out the type here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm OK with either way.
if (!POLICY_SCHEMA_VERSIONS.contains(policy.getVersion())) { | ||
throw new InvalidPolicyException("Invalid policy version: " + policy.getVersion()); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This may be a follow up: Do we need to validate data compaction configs (if they present). For example, target_file_size_bytes
needs to be a value larger than 0.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We cannot know the semantic within the config map. User can give a string to target_file_size_bytes
, it should still be acceptable, as target_file_size_bytes
doesn't mean anything in the schema.
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
package org.apache.polaris.core.policy.validator; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shall we move Data Compaction Policy Validator to a submodule data-compaction
? I think a submodule for each policy type can offer a more organized layout.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you mean a sub package? make sense, will move it.
import com.fasterxml.jackson.databind.annotation.JsonDeserialize; | ||
import java.util.Map; | ||
|
||
public class DataCompactionPolicy { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
public class DataCompactionPolicy { | |
public class DataCompactionPolicyContent { |
Shall we append "Content" to the name to differentiate it with the Policy
class generated by open api generator?
This PR adds interface PolicyValidator and one implementation for data compaction policy. Policy validator is used at policy creation/update as well as attaching a policy to a Polaris entity.
For more context, check
the design doc: https://docs.google.com/document/d/1kIiVkFFg9tPa5SH70b9WwzbmclrzH3qWHKfCKXw5lbs/edit?tab=t.0#heading=h.nly223xz13km
cc @HonahX