roryqi commented on code in PR #12380:
URL: https://github.com/apache/gravitino/pull/12380#discussion_r3725788920


##########
core/src/main/java/org/apache/gravitino/tag/TagManager.java:
##########
@@ -381,6 +413,69 @@ public String[] associateTagsForMetadataObject(
                 }));
   }
 
+  private static String[] allowedValuesForStorage(TagValueConstraint 
valueConstraint) {
+    TagValueConstraint normalizedConstraint =
+        valueConstraint == null ? TagValueConstraint.anyValue() : 
valueConstraint;
+    switch (normalizedConstraint.type()) {
+      case ANY_VALUE:
+        return null;
+      case NO_VALUE:
+        return normalizedConstraint.allowedValues();
+      case ALLOWED_VALUES:
+        return Arrays.stream(normalizedConstraint.allowedValues())
+            .distinct()
+            .toArray(String[]::new);
+      default:
+        throw new IllegalArgumentException("Unknown tag value constraint: " + 
normalizedConstraint);
+    }
+  }
+
+  private static void validateTagValuesToAdd(TagValue[] tagValues) {
+    if (tagValues == null) {
+      return;
+    }
+
+    Map<String, Boolean> valuedByTagName = Maps.newHashMap();
+    for (TagValue tagValue : tagValues) {
+      Preconditions.checkNotNull(tagValue, "Tag value to add must not be 
null");
+      boolean valued = tagValue.value().isPresent();
+      Boolean previous = valuedByTagName.putIfAbsent(tagValue.name(), valued);
+      Preconditions.checkArgument(
+          previous == null || previous == valued,
+          "Cannot add assignments both with and without values for tag %s",
+          tagValue.name());
+    }
+  }
+
+  private static void validateTagValuesToRemove(TagValue[] tagValues) {
+    if (tagValues == null) {
+      return;
+    }
+
+    for (TagValue tagValue : tagValues) {
+      Preconditions.checkNotNull(tagValue, "Tag value to remove must not be 
null");
+    }
+  }
+
+  private static TagValue[] toNoValue(String[] tags) {
+    if (tags == null) {
+      return null;
+    }
+
+    return Arrays.stream(tags).map(TagValue::noValue).toArray(TagValue[]::new);
+  }
+
+  private static RelationEdgeTarget[] toRelationEdgeTargets(String metalake, 
TagValue[] tagValues) {

Review Comment:
   This helper does not access any instance state, so it is intentionally 
static. This is also consistent with the existing `toRelationEdgeTargets` 
helpers in `SupportsRelationOperations` and `RelationalEntityStore`.



-- 
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]

Reply via email to