jerryshao commented on code in PR #14779:
URL: https://github.com/apache/gravitino/pull/14779#discussion_r4512103324
##########
server/src/main/java/org/apache/gravitino/server/web/rest/TagOperations.java:
##########
@@ -415,13 +419,27 @@ public Response addPolicyForTag(
PolicyTagAddRequest effectiveRequest =
request == null ? new PolicyTagAddRequest() : request;
effectiveRequest.validate();
- tagDispatcher.addPolicyForTag(
- metalake, tagName, policyName, effectiveRequest.selector());
+ PolicyAssociationSelector selector = effectiveRequest.selector();
+ if (selector instanceof TagValueSelector) {
+ TagValueConstraint constraint =
+ tagDispatcher.getTag(metalake, tagName).valueConstraint();
Review Comment:
The constraint check was moved out of core into this REST method, so any
other caller of addPolicyForTag (Java client paths, internal code, other
dispatchers) skips it. Keep the validation in the core or dispatcher layer, or
have both layers share one helper.
##########
server/src/main/java/org/apache/gravitino/server/web/rest/TagOperations.java:
##########
@@ -415,13 +419,27 @@ public Response addPolicyForTag(
PolicyTagAddRequest effectiveRequest =
request == null ? new PolicyTagAddRequest() : request;
effectiveRequest.validate();
- tagDispatcher.addPolicyForTag(
- metalake, tagName, policyName, effectiveRequest.selector());
+ PolicyAssociationSelector selector = effectiveRequest.selector();
+ if (selector instanceof TagValueSelector) {
+ TagValueConstraint constraint =
+ tagDispatcher.getTag(metalake, tagName).valueConstraint();
Review Comment:
The tag is read and the selector is written in two separate steps, so the
constraint can change in between and an invalid value can still be stored.
Also, this check does not cover a constraint that is changed after the
association exists; please say whether that is intended.
##########
iceberg/iceberg-rest-server/src/main/java/org/apache/gravitino/iceberg/service/IcebergRESTUtils.java:
##########
@@ -347,17 +361,28 @@ public static PlanTableScanResponse
rewriteScanPlanCredentials(
static PlanTableScanResponse copyWithCredentials(
PlanTableScanResponse response,
List<org.apache.iceberg.rest.credentials.Credential> credentials) {
- return PlanTableScanResponse.builder()
+ return scanPlanResponseBuilder(scanResponseSpecs(response))
.withPlanStatus(response.planStatus())
.withPlanId(response.planId())
.withPlanTasks(response.planTasks())
.withFileScanTasks(response.fileScanTasks())
- .withSpecsById(response.specsById())
.withErrorResponse(response.errorResponse())
.withCredentials(credentials)
.build();
}
+ /** Creates a scan response builder with specs on both supported Iceberg
runtimes. */
+ static PlanTableScanResponse.Builder scanPlanResponseBuilder(
+ @Nullable Map<Integer, PartitionSpec> specs) {
+ return SCAN_RESPONSE_WITH_SPECS.invoke(PlanTableScanResponse.builder(),
specs);
Review Comment:
hiddenImpl uses setAccessible on Iceberg internals, which can fail or break
on a newer Iceberg version; the static initializer would then fail the whole
class at load time. Is there a fallback or a clear error message if resolution
fails?
##########
server/src/main/java/org/apache/gravitino/server/web/rest/TagOperations.java:
##########
@@ -415,13 +419,27 @@ public Response addPolicyForTag(
PolicyTagAddRequest effectiveRequest =
request == null ? new PolicyTagAddRequest() : request;
effectiveRequest.validate();
- tagDispatcher.addPolicyForTag(
- metalake, tagName, policyName, effectiveRequest.selector());
+ PolicyAssociationSelector selector = effectiveRequest.selector();
+ if (selector instanceof TagValueSelector) {
+ TagValueConstraint constraint =
+ tagDispatcher.getTag(metalake, tagName).valueConstraint();
+ String value = ((TagValueSelector) selector).value();
+ Preconditions.checkArgument(
+ constraint.type() != TagValueConstraint.Type.NO_VALUE,
+ "Tag %s does not allow assignment values",
+ tagName);
+ Preconditions.checkArgument(
+ constraint.type() != TagValueConstraint.Type.ALLOWED_VALUES
Review Comment:
Preconditions.checkArgument throws IllegalArgumentException; confirm
handleTagException maps it to 400 and not 500. Also guard against a null
allowedValues array, since Arrays.asList(null) throws NullPointerException.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]