Closed aaawuanjun closed 4 months ago
The "Invalid vertex id" error you're encountering when creating an edge using UUIDs as vertex IDs in HugeGraph version 1.0.0 is likely due to a known issue in the checkAndParseVertexId
method in the VertexAPI
class. This method incorrectly handles UUIDs by removing a leading "U" if it exists, which can lead to incorrect parsing and handling of UUIDs.
Here are the steps to resolve this issue:
Ensure Vertex IDs Exist: You've already verified that the vertex IDs exist, which is good. This step ensures that the IDs you are using are valid and present in the database.
Check UUID Handling in VertexAPI: The checkAndParseVertexId
method in the VertexAPI
class has a bug that incorrectly handles UUIDs. This method checks if the idValue
starts with "U\"", and if so, it removes the leading "U" before parsing the UUID. This can lead to incorrect parsing and handling of UUIDs.
Test Case for UUIDs: The VertexApiTest
class includes a test case testGetWithCustomizeUuidId
that demonstrates the correct usage of UUIDs as vertex IDs. This test case creates a vertex with a UUID, retrieves it, and verifies that the ID, label, and properties are correctly handled.
Workaround: As a workaround, you can ensure that the UUIDs are correctly formatted and handled by the API. You might need to modify the request to ensure that the UUIDs are correctly parsed. For example, you can try prefixing the UUIDs with "U" to match the expected format in the checkAndParseVertexId
method.
Modified Request Body:
{
"label": "dsToTaskLineageEdgeLabelTTI",
"inV": "U\"a9a0e424-129b-487d-a089-6372673ebedc\"",
"inVLabel": "taskLineageVertexLabel",
"outV": "U\"3b567246-d408-461f-b481-a899d1477e0d\"",
"outVLabel": "dsLineageVertexLabel",
"properties": {
"date": "20171210",
"weight": 0.4
}
}
By ensuring that the UUIDs are correctly formatted and handled, you should be able to resolve the "Invalid vertex id" error when creating an edge using UUIDs as vertex IDs. If the issue persists, you may need to look into updating to a newer version of HugeGraph where this bug might have been fixed.
To continue the conversation, mention @dosu.
it does not work, the code version is 1.3.0
from belows, it produce exception, it does not judge U prefix
private static Vertex getVertex(HugeGraph graph, Object id, String label) {
HugeVertex vertex;
try {
vertex = (HugeVertex) graph.vertices(id).next();
} catch (NoSuchElementException e) {
throw new IllegalArgumentException(String.format("Invalid vertex id '%s'", id));
}
if (label != null && !vertex.label().equals(label)) {
throw new IllegalArgumentException(String.format(
"The label of vertex '%s' is unmatched, users expect " +
"label '%s', actual label stored is '%s'",
id, label, vertex.label()));
}
// Clone a new vertex to support multi-thread access
return vertex.copy();
}
Problem Type (问题类型)
rest-api (结果不合预期)
Before submit
Environment (环境信息)
Your Question (问题描述)
create edge:
vertices id is exist:
Vertex/Edge example (问题点 / 边数据举例)