Skip to content
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

[Question] create edge use uuid as vertices id, but tips "Invalid vertex id" #2542

Closed
1 task done
aaawuanjun opened this issue May 23, 2024 · 2 comments
Closed
1 task done
Labels
api Changes of API question Further information is requested

Comments

@aaawuanjun
Copy link

aaawuanjun commented May 23, 2024

Problem Type (问题类型)

rest-api (结果不合预期)

Before submit

  • 我已经确认现有的 IssuesFAQ 中没有相同 / 重复问题 (I have confirmed and searched that there are no similar problems in the historical issue and documents)

Environment (环境信息)

  • Server Version: 1.3.0 (Apache Release Version)
  • Backend: RocksDB x nodes, HDD or SSD
  • OS: xx CPUs, xx G RAM, Ubuntu 2x.x / CentOS 7.x
  • Data Size: 3 vertices, 0edges

Your Question (问题描述)

create edge:
image

vertices id is exist:
image

Vertex/Edge example (问题点 / 边数据举例)

# create edge
## request:
http://172.16.12.150:8080/graphs/hugegraph/graph/edges

request body:

{
  "label": "dsToTaskLineageEdgeLabelTTI",
  "inV": "a9a0e424-129b-487d-a089-6372673ebedc",
  "inVLabel": "taskLineageVertexLabel",
  "outV": "3b567246-d408-461f-b481-a899d1477e0d",
  "outVLabel": "dsLineageVertexLabel",
  "properties": {
      "date": "20171210",
      "weight": 0.4
  }
}


## response:
```text
{
    "exception": "class java.lang.IllegalArgumentException",
    "message": "Invalid vertex id '3b567246-d408-461f-b481-a899d1477e0d'",
    "cause": ""
}


### Schema [VertexLabel, EdgeLabel, IndexLabel] (元数据结构)

_No response_
Copy link

dosubot bot commented May 23, 2024

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:

  1. 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.

  2. 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.

  3. 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.

  4. 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.

Details

Sources


About Dosu
This response is meant to be useful and save you time. It is not meant to be a precise solution, but rather a starting point for your own research.

Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant.

To continue the conversation, mention @dosu.

@dosubot dosubot bot added api Changes of API question Further information is requested labels May 23, 2024
@aaawuanjun
Copy link
Author

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();
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api Changes of API question Further information is requested
Projects
None yet
Development

No branches or pull requests

1 participant