-
Notifications
You must be signed in to change notification settings - Fork 330
Implement PolicyCatalog Stage 1: CRUD + ListPolicies #1294
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
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
140 changes: 140 additions & 0 deletions
140
...aris-catalog-service/src/main/java/org/apache/polaris/service/types/PolicyIdentifier.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,140 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
| package org.apache.polaris.service.types; | ||
|
|
||
| import com.fasterxml.jackson.annotation.JsonCreator; | ||
| import com.fasterxml.jackson.annotation.JsonProperty; | ||
| import io.swagger.annotations.ApiModelProperty; | ||
| import java.util.Objects; | ||
| import org.apache.iceberg.catalog.Namespace; | ||
|
|
||
| /** | ||
| * Represents a modified version of the PolicyIdentifier that is different from the one generated by | ||
| * the OpenAPI generator | ||
| * | ||
| * <p>the open api generation inlines the namespace definition, generates a {@code List<String>} | ||
| * directly, instead of generating a Namespace class. This version uses {@link | ||
| * org.apache.iceberg.catalog.Namespace} for namespace field. | ||
| * | ||
| * <p>TODO: make code generation use {@link org.apache.iceberg.catalog.Namespace} directly | ||
| */ | ||
| public class PolicyIdentifier { | ||
|
|
||
| private final Namespace namespace; | ||
| private final String name; | ||
|
|
||
| /** Reference to one or more levels of a namespace */ | ||
| @ApiModelProperty( | ||
| example = "[\"accounting\",\"tax\"]", | ||
| required = true, | ||
| value = "Reference to one or more levels of a namespace") | ||
| @JsonProperty(value = "namespace", required = true) | ||
| public Namespace getNamespace() { | ||
| return namespace; | ||
| } | ||
|
|
||
| /** */ | ||
| @ApiModelProperty(required = true, value = "") | ||
| @JsonProperty(value = "name", required = true) | ||
| public String getName() { | ||
| return name; | ||
| } | ||
|
|
||
| @JsonCreator | ||
| public PolicyIdentifier( | ||
| @JsonProperty(value = "namespace", required = true) Namespace namespace, | ||
| @JsonProperty(value = "name", required = true) String name) { | ||
| this.namespace = Objects.requireNonNullElse(namespace, Namespace.empty()); | ||
| this.name = name; | ||
| } | ||
|
|
||
| public static Builder builder() { | ||
| return new Builder(); | ||
| } | ||
|
|
||
| public static Builder builder(Namespace namespace, String name) { | ||
| return new Builder(namespace, name); | ||
| } | ||
|
|
||
| public static final class Builder { | ||
| private Namespace namespace; | ||
| private String name; | ||
|
|
||
| private Builder() {} | ||
|
|
||
| private Builder(Namespace namespace, String name) { | ||
| this.namespace = Objects.requireNonNullElse(namespace, Namespace.empty()); | ||
| this.name = name; | ||
| } | ||
|
|
||
| public Builder setNamespace(Namespace namespace) { | ||
| this.namespace = namespace; | ||
| return this; | ||
| } | ||
|
|
||
| public Builder setName(String name) { | ||
| this.name = name; | ||
| return this; | ||
| } | ||
|
|
||
| public PolicyIdentifier build() { | ||
| PolicyIdentifier inst = new PolicyIdentifier(namespace, name); | ||
| return inst; | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public boolean equals(Object o) { | ||
| if (this == o) { | ||
| return true; | ||
| } | ||
| if (o == null || getClass() != o.getClass()) { | ||
| return false; | ||
| } | ||
| PolicyIdentifier policyIdentifier = (PolicyIdentifier) o; | ||
| return Objects.equals(this.namespace, policyIdentifier.namespace) | ||
| && Objects.equals(this.name, policyIdentifier.name); | ||
| } | ||
|
|
||
| @Override | ||
| public int hashCode() { | ||
| return Objects.hash(namespace, name); | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| StringBuilder sb = new StringBuilder(); | ||
| sb.append("class PolicyIdentifier {\n"); | ||
|
|
||
| sb.append(" namespace: ").append(toIndentedString(namespace)).append("\n"); | ||
| sb.append(" name: ").append(toIndentedString(name)).append("\n"); | ||
| sb.append("}"); | ||
| return sb.toString(); | ||
| } | ||
|
|
||
| /** | ||
| * Convert the given object to string with each line indented by 4 spaces (except the first line). | ||
| */ | ||
| private String toIndentedString(Object o) { | ||
| if (o == null) { | ||
| return "null"; | ||
| } | ||
| return o.toString().replace("\n", "\n "); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
...s-core/src/main/java/org/apache/polaris/core/policy/exceptions/NoSuchPolicyException.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
| package org.apache.polaris.core.policy.exceptions; | ||
|
|
||
| import org.apache.polaris.core.exceptions.PolarisException; | ||
|
|
||
| public class NoSuchPolicyException extends PolarisException { | ||
|
|
||
| public NoSuchPolicyException(String message) { | ||
| super(message); | ||
| } | ||
|
|
||
| public NoSuchPolicyException(String message, Throwable cause) { | ||
| super(message, cause); | ||
| } | ||
| } |
31 changes: 31 additions & 0 deletions
31
...c/main/java/org/apache/polaris/core/policy/exceptions/PolicyVersionMismatchException.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, | ||
| * software distributed under the License is distributed on an | ||
| * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| * KIND, either express or implied. See the License for the | ||
| * specific language governing permissions and limitations | ||
| * under the License. | ||
| */ | ||
| package org.apache.polaris.core.policy.exceptions; | ||
|
|
||
| import org.apache.polaris.core.exceptions.PolarisException; | ||
|
|
||
| public class PolicyVersionMismatchException extends PolarisException { | ||
| public PolicyVersionMismatchException(String message) { | ||
| super(message); | ||
| } | ||
|
|
||
| public PolicyVersionMismatchException(String message, Throwable cause) { | ||
| super(message, cause); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
One way we could potentially fix the problem is to add a Namespace definition under schema that whose type is object, and then directly link to the iceberg namespace.
And in your policyId, link to this newly defined Namespace, during the generation, map the namespace to Iceberg namespace class. That could potentially fix the generation problem.
We can also try to do this in a follow up PR, but let's make sure we follow up on this.
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.
basically,
Then in the build in the importMappings add
"Namespace" to ""org.apache.iceberg.catalog.Namespace"
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.
Do it help? We will still need the
Namespaceclass in Iceberg core lib, instead of the auto-gen 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.
So the ideal case is that we can auto-generate "PolicyIdentifier" class and let it use iceberg's "Namespace" class instead of a
List<String>. I tried theand unfortunately it does not work, we probably need to explore some open api generator configs to make auto-gen possible.
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.
That is wired, i believe it should work. can you get an issue and let's follow up on this?