apache / incubator-hugegraph

A graph database that supports more than 100+ billion data, high performance and scalability (Include OLTP Engine & REST-API & Backends)
https://hugegraph.apache.org
Apache License 2.0
2.58k stars 512 forks source link

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

Closed aaawuanjun closed 4 days ago

aaawuanjun commented 1 month ago

Problem Type (问题类型)

rest-api (结果不合预期)

Before submit

Environment (环境信息)

Your Question (问题描述)

when I use create edge rest api, vertices id use uuid.

create edge cause error: Invalid vertex id '3b567246-d408-461f-b481-a899d1477e0d'

image

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

request url: http://172.16.12.150:8080/graphs/hugegraph/graph/edges
request body:

{
    "label": "pstudent",
    "outV": "3b567246-d408-461f-b481-a899d1477e0d",
    "inV": "a9a0e424-129b-487d-a089-6372673ebedc",
    "outVLabel": "person",
    "inVLabel": "student",
    "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] (元数据结构)

```javascript
{
    "propertykeys": [
        {
            "id": 2,
            "name": "name",
            "data_type": "TEXT",
            "cardinality": "SINGLE",
            "aggregate_type": "NONE",
            "write_type": "OLTP",
            "properties": [],
            "status": "CREATED",
            "user_data": {
                "~create_time": "2024-05-23 14:18:11.467"
            }
        },
        {
            "id": 1,
            "name": "age",
            "data_type": "INT",
            "cardinality": "SINGLE",
            "aggregate_type": "NONE",
            "write_type": "OLTP",
            "properties": [],
            "status": "CREATED",
            "user_data": {
                "~create_time": "2024-05-23 14:15:54.949"
            }
        }
    ],
    "vertexlabels": [
        {
            "id": 1,
            "name": "person",
            "id_strategy": "CUSTOMIZE_UUID",
            "primary_keys": [],
            "nullable_keys": [],
            "index_labels": [],
            "properties": [
                "age",
                "name"
            ],
            "status": "CREATED",
            "ttl": 0,
            "enable_label_index": true,
            "user_data": {
                "~create_time": "2024-05-23 14:18:24.930"
            }
        },
        {
            "id": 2,
            "name": "student",
            "id_strategy": "CUSTOMIZE_UUID",
            "primary_keys": [],
            "nullable_keys": [],
            "index_labels": [],
            "properties": [
                "age",
                "name"
            ],
            "status": "CREATED",
            "ttl": 0,
            "enable_label_index": true,
            "user_data": {
                "~create_time": "2024-05-23 14:18:50.909"
            }
        }
    ],
    "edgelabels": [],
    "indexlabels": []
}
dosubot[bot] commented 1 month ago

To resolve the "Invalid vertex id" error when creating an edge with UUIDs as vertex IDs in HugeGraph, you need to ensure that the vertex IDs are correctly formatted and parsed. In HugeGraph, UUIDs should be prefixed with U" to indicate that they are UUIDs.

Here's how you can modify your request to include the correct format for UUIDs:

Modified Request Body

{
    "label": "pstudent",
    "outV": "U\"3b567246-d408-461f-b481-a899d1477e0d\"",
    "inV": "U\"a9a0e424-129b-487d-a089-6372673ebedc\"",
    "outVLabel": "person",
    "inVLabel": "student",
    "properties": {
        "date": "20171210",
        "weight": 0.4
    }
}

By ensuring that your vertex IDs are prefixed with U", the checkAndParseVertexId method will correctly parse them as UUIDs. This should help you avoid the "Invalid vertex id" error.

#### Details **Sources** - [hugegraph-server/hugegraph-api/src/main/java/org/apache/hugegraph/api/graph/VertexAPI.java](https://github.com/apache/incubator-hugegraph/blob/master/hugegraph-server/hugegraph-api/src/main/java/org/apache/hugegraph/api/graph/VertexAPI.java) - [hugegraph-server/hugegraph-api/src/main/java/org/apache/hugegraph/api/graph/EdgeAPI.java](https://github.com/apache/incubator-hugegraph/blob/master/hugegraph-server/hugegraph-api/src/main/java/org/apache/hugegraph/api/graph/EdgeAPI.java) - [hugegraph-hubble/hubble-be/src/main/java/org/apache/hugegraph/service/graph/GraphService.java](https://github.com/apache/incubator-hugegraph-toolchain/blob/master/hugegraph-hubble/hubble-be/src/main/java/org/apache/hugegraph/service/graph/GraphService.java) - [hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/backend/id/IdGenerator.java](https://github.com/apache/incubator-hugegraph/blob/master/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/backend/id/IdGenerator.java) - [hugegraph-loader/src/main/java/org/apache/hugegraph/loader/util/DataTypeUtil.java](https://github.com/apache/incubator-hugegraph-toolchain/blob/master/hugegraph-loader/src/main/java/org/apache/hugegraph/loader/util/DataTypeUtil.java) - [hugegraph-spark-connector/src/test/java/org/apache/hugegraph/spark/connector/utils/DataTypeUtilsTest.java](https://github.com/apache/incubator-hugegraph-toolchain/blob/master/hugegraph-spark-connector/src/test/java/org/apache/hugegraph/spark/connector/utils/DataTypeUtilsTest.java) - [hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/util/StringEncoding.java](https://github.com/apache/incubator-hugegraph/blob/master/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/util/StringEncoding.java)
**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.

github-actions[bot] commented 3 weeks ago

Due to the lack of activity, the current issue is marked as stale and will be closed after 20 days, any update will remove the stale label