roryqi commented on code in PR #14779:
URL: https://github.com/apache/gravitino/pull/14779#discussion_r4512601515
##########
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:
Moved the validation into core's `PolicyTagRelService`, inside the
transaction that writes policy-to-tag relations. REST no longer preloads the
tag or performs a separate constraint check, so `TagManager` and direct
relation-store callers use the same validation. Added tests through both entry
points covering accepted selectors, invalid and case-mismatched values,
no-value tags, and rejected updates that leave existing relations intact.
Implemented in 22e6fa606e8dc763b27d23874e69a0edc593e199.
##########
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:
Validation now uses the tag row returned by the existing locking read, and
that row lock is held through the association commit. Added a concurrent
storage-writer test: the association waits for the constraint writer, then
rejects a value disallowed by the committed constraint.
Tag value constraints are currently fixed at creation: `TagChange` supports
renaming, comments and properties, but no constraint changes. Existing
associations are intentionally not rewritten by this change. Documented this
scope in `docs/policies.md`. The storage tests cover H2, MySQL and PostgreSQL.
Implemented in 22e6fa606e8dc763b27d23874e69a0edc593e199.
##########
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:
Confirmed that `TagExceptionHandler` maps `IllegalArgumentException` to HTTP
400. The REST tests assert the status, error code, exception type and message
for validation failures propagated from core.
Array handling now lives in storage validation, with guards for both SQL
NULL and a deserialized JSON null before membership checks. Both represent an
unrestricted constraint, consistent with `POConverters`. Added storage coverage
for null constraints, empty arrays and allowed-value lists.
Implemented in 22e6fa606e8dc763b27d23874e69a0edc593e199.
##########
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:
Changed the cached method lookups to resolve lazily, trying the public
method before `hiddenImpl`. Lookup or access failures now throw an
`IllegalStateException` that names the class and method, recommends a supported
Iceberg runtime, and preserves the original cause. Resolution happens when
scanning is used, so it cannot fail `IcebergRESTUtils` static initialization.
A runtime without an accessible spec-map method fails the scan explicitly;
dropping partition specs would change response semantics. Added repeated
missing-method coverage and verified the shared scan-response tests on both
standard and experimental Iceberg runtimes.
Implemented in 6faecd9878b864fa5a0033b9418b805f9174345a.
--
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]