imbajin commented on code in PR #349:
URL: 
https://github.com/apache/hugegraph-computer/pull/349#discussion_r3465310633


##########
computer/computer-core/src/main/java/org/apache/hugegraph/computer/core/input/HugeConverter.java:
##########
@@ -96,4 +105,27 @@ public static Properties convertProperties(
         }
         return properties;
     }
+
+    public static String convertEdgeName(Edge edge) {
+        E.checkArgumentNotNull(edge, "The edge can't be null");
+        String edgeId = edge.id();
+        if (edgeId == null) {
+            return edge.name();
+        }
+
+        String[] parts = SplicingIdGenerator.split(edgeId);
+        if (parts.length == LEGACY_EDGE_ID_PARTS) {
+            return parts[LEGACY_EDGE_NAME_INDEX];
+        } else if (parts.length == PARENT_EDGE_ID_PARTS) {
+            return parts[PARENT_EDGE_NAME_INDEX];
+        } else if (parts.length == DIRECTIONAL_EDGE_ID_PARTS &&

Review Comment:
   ❗️ High priority: this still does not parse the server-generated 6-part edge 
ID format correctly.
   
   This branch only accepts `parts[1]` when it is `EDGE_OUT` or `EDGE_IN`, but 
server-side `EdgeId.asString()` writes the direction via 
`this.direction.type().string()`. In HugeGraph those values are `O` / `I`, not 
the enum names:
   
   - server writer: 
https://github.com/apache/hugegraph/blob/master/hugegraph-struct/src/main/java/org/apache/hugegraph/id/EdgeId.java#L146-L157
   - server direction tokens: 
https://github.com/apache/hugegraph/blob/master/hugegraph-struct/src/main/java/org/apache/hugegraph/type/HugeType.java#L53-L57
   - server parser: 
https://github.com/apache/hugegraph/blob/master/hugegraph-struct/src/main/java/org/apache/hugegraph/id/EdgeId.java#L276-L283
   
   So a valid current server ID like `S1:178201>O>5>5>参数标准!3BA0>S4:239464` will 
skip this branch and fall back to `edge.name()`. That fallback is not safe here 
because Computer still depends on hugegraph-client 1.3.0, whose `Edge.name()` 
only supports the legacy 4-part ID format.
   
   The current java-client invariant is also simpler: for 5/6-part IDs, 
`Edge.name()` returns the penultimate segment: 
https://github.com/apache/hugegraph-toolchain/blob/master/hugegraph-client/src/main/java/org/apache/hugegraph/structure/graph/Edge.java#L142-L149
   
   ```text
   ownerVertexId > O/I > edgeLabelId > subLabelId > sortValues > otherVertexId
                                                   ^
                                         expected edge name
   ```
   
   Please align this parser with that invariant, or at least validate against 
the server tokens `O` and `I`. The regression tests should cover both `>O>` and 
`>I>` forms and prove that valid 6-part IDs do not fall back to the old client 
parser.



##########
computer/computer-api/src/main/java/org/apache/hugegraph/computer/core/util/HugeClientUtil.java:
##########
@@ -0,0 +1,85 @@
+/*
+ * 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.hugegraph.computer.core.util;
+
+import java.util.concurrent.atomic.AtomicBoolean;
+
+import org.apache.hugegraph.driver.HugeClient;
+import org.apache.hugegraph.driver.HugeClientBuilder;
+import org.apache.hugegraph.rest.RestResult;
+import org.apache.hugegraph.structure.schema.EdgeLabel;
+import org.apache.hugegraph.util.JsonUtil;
+
+import com.fasterxml.jackson.databind.BeanDescription;
+import com.fasterxml.jackson.databind.DeserializationConfig;
+import com.fasterxml.jackson.databind.deser.BeanDeserializerBuilder;
+import com.fasterxml.jackson.databind.deser.BeanDeserializerModifier;
+import com.fasterxml.jackson.databind.module.SimpleModule;
+
+public final class HugeClientUtil {
+
+    private static final AtomicBoolean COMPATIBILITY_REGISTERED =
+                                      new AtomicBoolean(false);
+
+    public static HugeClient newHugeClient(String url, String graph,
+                                           String username, String password) {
+        registerCompatibilityModule();
+        return new HugeClientBuilder(url, graph).configUser(username, password)
+                                                .build();
+    }
+
+    public static HugeClient newHugeClient(String url, String graph,
+                                           String username, String password,
+                                           int timeout) {
+        registerCompatibilityModule();
+        return new HugeClientBuilder(url, graph).configUser(username, password)
+                                                .configTimeout(timeout)
+                                                .build();
+    }
+
+    public static void registerCompatibilityModule() {
+        if (!COMPATIBILITY_REGISTERED.compareAndSet(false, true)) {
+            return;
+        }
+        RestResult.registerModule(newCompatibilityModule());
+        JsonUtil.registerModule(newCompatibilityModule());
+    }
+
+    private static SimpleModule newCompatibilityModule() {
+        SimpleModule module = new SimpleModule(
+                              "hugegraph-computer-client-compatibility");
+        module.setDeserializerModifier(new BeanDeserializerModifier() {
+
+            @Override
+            public BeanDeserializerBuilder updateBuilder(
+                   DeserializationConfig config, BeanDescription beanDesc,
+                   BeanDeserializerBuilder builder) {
+                if (EdgeLabel.class.equals(beanDesc.getBeanClass())) {

Review Comment:
   ⚠️ Please avoid making current java-client fields globally ignorable.
   
   This compatibility module ignores `edgelabel_type`, `parent_label`, and 
`links` for every `EdgeLabel` deserialization. That works for the pinned 1.3 
client because those fields are unknown there, but in current java-client 1.7 
they are real fields: `sourceLabel()` / `targetLabel()` derive from `links`.
   
   A more version-tolerant approach would ignore unknown fields rather than 
explicitly dropping known current fields, for example with an 
`@JsonIgnoreProperties(ignoreUnknown = true)` mix-in, or by conditionally 
adding ignorables only when the runtime `EdgeLabel` class does not expose those 
fields. The tests should prove both sides: old client does not fail on new 
server fields, and current client semantics do not lose `links`.



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


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to