roryqi commented on code in PR #12234:
URL: https://github.com/apache/gravitino/pull/12234#discussion_r3690272140
##########
core/src/main/java/org/apache/gravitino/SupportsRelationOperations.java:
##########
@@ -220,4 +283,55 @@ default <E extends Entity & HasIdentifier> List<E>
updateEntityRelations(
throw new UnsupportedOperationException(
"updateEntityRelations is not supported by this implementation");
}
+
+ /**
+ * Updates the relations for a source entity by adding and removing target
endpoints that can
+ * carry optional relation values on the relation edges.
+ *
+ * @param <E> The type of the entity returned in the list, which represents
the final state of
+ * related entities.
+ * @param relType The type of relation to update.
+ * @param srcEntityIdent The identifier of the source entity whose relations
are being updated.
+ * @param srcEntityType The source entity type.
+ * @param destEntitiesToAdd Target endpoints to associate with the source
entity.
+ * @param destEntitiesToRemove Target endpoints to disassociate from the
source entity.
+ * @return A list of entities that are related to the given entity after the
update.
+ * @throws IOException If a storage-related error occurs.
+ * @throws NoSuchEntityException If any of the specified entities does not
exist.
+ * @throws EntityAlreadyExistsException If a relation to be added already
exists.
+ */
+ default <E extends Entity & HasIdentifier> List<E> updateEntityRelations(
+ Type relType,
+ NameIdentifier srcEntityIdent,
+ Entity.EntityType srcEntityType,
+ RelationTarget[] destEntitiesToAdd,
+ RelationTarget[] destEntitiesToRemove)
+ throws IOException, NoSuchEntityException, EntityAlreadyExistsException {
+ if (hasRelationValues(destEntitiesToAdd) ||
hasRelationValues(destEntitiesToRemove)) {
+ throw new UnsupportedOperationException(
+ "updateEntityRelations with relation values is not supported by this
implementation");
+ }
+
+ return updateEntityRelations(
Review Comment:
Fixed in `3a301a664`. `RelationalEntityStore` now converts legacy
`NameIdentifier[]` updates into `RelationUpdate` with the derived target type,
validates `RelationEdgeTarget.entityType()` before the backend write, and
invalidates target caches using that same derived type. Added regression
coverage for mismatched target type before backend interaction.
##########
core/src/main/java/org/apache/gravitino/RelationTarget.java:
##########
@@ -0,0 +1,77 @@
+/*
+ * 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.gravitino;
+
+import com.google.common.base.Preconditions;
+import java.util.Optional;
+import javax.annotation.Nullable;
+
+/**
+ * Represents a target entity in a relation update, with optional metadata
carried by the relation
+ * row.
+ */
+public final class RelationTarget {
Review Comment:
Fixed in `3a301a664`. I replaced the value-specific list overload and the
parallel target-array update overload with object-based APIs: `RelationQuery`
for reads and `RelationUpdate`/`RelationEdgeTarget` for writes. The existing
primitive overloads are kept as compatibility adapters, and future edge
metadata can now evolve inside those objects instead of adding more overloads.
--
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]