-
Notifications
You must be signed in to change notification settings - Fork 48
fix: support new HugeGraph edge id format #349
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 2 commits
27b727a
91a04d9
252ea40
b84879d
bc84f0a
7fa84bd
5c792eb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -36,10 +36,18 @@ | |
| import org.apache.hugegraph.computer.core.graph.value.NullValue; | ||
| import org.apache.hugegraph.computer.core.graph.value.StringValue; | ||
| import org.apache.hugegraph.computer.core.graph.value.Value; | ||
| import org.apache.hugegraph.structure.graph.Edge; | ||
| import org.apache.hugegraph.util.E; | ||
| import org.apache.hugegraph.util.SplicingIdGenerator; | ||
|
|
||
| public final class HugeConverter { | ||
|
|
||
| private static final int LEGACY_EDGE_ID_PARTS = 4; | ||
| private static final int PARENT_EDGE_ID_PARTS = 5; | ||
| private static final int DIRECTIONAL_EDGE_ID_PARTS = 6; | ||
| private static final int PARENT_EDGE_NAME_INDEX = 3; | ||
| private static final int DIRECTIONAL_EDGE_NAME_INDEX = 4; | ||
|
|
||
| private static final GraphFactory GRAPH_FACTORY = | ||
| ComputerContext.instance().graphFactory(); | ||
|
|
||
|
|
@@ -96,4 +104,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 edge.name(); | ||
| } else if (parts.length == PARENT_EDGE_ID_PARTS) { | ||
| return parts[PARENT_EDGE_NAME_INDEX]; | ||
| } else if (parts.length == DIRECTIONAL_EDGE_ID_PARTS && | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ❗️ High priority: this still does not parse the server-generated 6-part edge ID format correctly. This branch only accepts
So a valid current server ID like The current java-client invariant is also simpler: for 5/6-part IDs, Please align this parser with that invariant, or at least validate against the server tokens |
||
| isEdgeDirection(parts[1])) { | ||
| return parts[DIRECTIONAL_EDGE_NAME_INDEX]; | ||
| } | ||
| return edge.name(); | ||
| } | ||
|
|
||
| private static boolean isEdgeDirection(String part) { | ||
| return "EDGE_OUT".equals(part) || "EDGE_IN".equals(part); | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
convertEdgeName()already splits the id, but the 4-part branch still delegates toedge.name(). That only works with the currenthugegraph-client1.3.0 dependency; the current java-client implementation only accepts 5/6-part ids and derives the name fromidParts[idParts.length - 2], so this compatibility shim will break for legacy ids when the client dependency is aligned with the 1.7.0 runtime that this PR now validates against.Please return
parts[2]forLEGACY_EDGE_ID_PARTSdirectly, or use the sharedparts[parts.length - 2]invariant for all accepted arities, and leaveedge.name()only for null or unknown formats.