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] When vertex strategy is CUSTOMIZE_UUID, is there need to pass the id value in json? #2535

Closed Github-Polaris closed 3 weeks ago

Github-Polaris commented 2 months ago

Problem Type (问题类型)

None

Before submit

Environment (环境信息)

Your Question (问题描述)

image 当一个vertex的id策略为uuid时,即id可以自定义时,增加结点数据需要传入id值吗?我在官方的例子中没有看到相关示例

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

No response

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

No response

dosubot[bot] commented 2 months ago

Yes, when using the CUSTOMIZE_UUID strategy for vertex IDs in Apache HugeGraph, you must include the id value in the JSON body when adding a vertex. This requirement is due to the way the HugeGraph server processes vertex IDs based on the specified ID strategy. Specifically, for CUSTOMIZE_UUID, the system expects an id value to be provided, which it then uses to generate a UUID. If the id value is not provided, the operation will fail because the system attempts to convert a null value into a UUID, leading to errors. This behavior is outlined in the VertexAPI class of the HugeGraph server codebase, indicating the necessity of supplying an id value in your request.

#### 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-client/src/main/java/org/apache/hugegraph/serializer/direct/util/IdGenerator.java](https://github.com/apache/incubator-hugegraph-toolchain/blob/master/hugegraph-client/src/main/java/org/apache/hugegraph/serializer/direct/util/IdGenerator.java) - [hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/backend/id/Id.java](https://github.com/apache/incubator-hugegraph/blob/master/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/backend/id/Id.java) - [hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/backend/tx/GraphTransaction.java](https://github.com/apache/incubator-hugegraph/blob/master/hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/backend/tx/GraphTransaction.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-Polaris commented 2 months ago

@dosu Hi, please see the code section below, what's wrong with this?

{
    "label": "person",
    "properties": {
        "id": "123e4567-e89b-12d3-a456-426614174000",
        "name": "marko",
        "age": 29
    }
}
{
    "exception": "class java.lang.IllegalArgumentException",
    "message": "Must customize vertex string id when id strategy is 'CUSTOMIZE_UUID' for vertex label 'person'",
    "cause": ""
}
dosubot[bot] commented 2 months ago

The error you're encountering, "Must customize vertex string id when id strategy is 'CUSTOMIZE_UUID' for vertex label 'person'", indicates that the format or placement of the id in your JSON request does not meet the expectations for a CUSTOMIZE_UUID ID strategy in Apache HugeGraph. When using CUSTOMIZE_UUID, the id must be provided at the top level of your JSON structure, not nested within the properties object. Your JSON should look like this:

{
    "label": "person",
    "id": "123e4567-e89b-12d3-a456-426614174000",
    "properties": {
        "name": "marko",
        "age": 29
    }
}

In this corrected format, the id is directly under the top level of the JSON object, alongside label and properties. This placement ensures that the id is recognized by HugeGraph as the vertex ID, conforming to the CUSTOMIZE_UUID strategy's requirement for a custom, user-provided UUID string.

#### Details **Sources** - [hugegraph-loader/src/test/resources/vertex_customized_id_unfold/struct.json](https://github.com/apache/incubator-hugegraph-toolchain/blob/master/hugegraph-loader/src/test/resources/vertex_customized_id_unfold/struct.json) - [hugegraph-client/src/main/java/org/apache/hugegraph/structure/schema/VertexLabel.java](https://github.com/apache/incubator-hugegraph-toolchain/blob/master/hugegraph-client/src/main/java/org/apache/hugegraph/structure/schema/VertexLabel.java) - [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)
**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-Polaris commented 1 month ago

@dosu Hi, when the vertex id strategy is UUID, how to construct an edge relation between two vertex? Here is my operation that using EdgeAPI /graphs/hugegraph/graph/edges but has an exception throwed. why there is "Invalid vertex id '123e4567-e89b-12d3-a456-426614174000'"?

{
    "label": "friend",
    "outV": "123e4567-e89b-12d3-a456-426614174000",
    "inV": "123e4567-e89b-12d3-a456-426614174001",
    "outVLabel": "person_id",
    "inVLabel": "person_id",
    "properties": {}
}
{
    "exception": "class java.lang.IllegalArgumentException",
    "message": "Invalid vertex id '123e4567-e89b-12d3-a456-426614174000'",
    "cause": ""
}
dosubot[bot] commented 1 month ago

The error "Invalid vertex id '123e4567-e89b-12d3-a456-426614174000'" you're encountering when trying to construct an edge suggests a couple of potential issues to check:

  1. Vertex Existence: Ensure that the vertices with IDs 123e4567-e89b-12d3-a456-426614174000 and 123e4567-e89b-12d3-a456-426614174001 actually exist in your graph. The error can occur if the vertex ID provided does not exist.

  2. Label Match: If you're specifying vertex labels (outVLabel and inVLabel) when creating the edge, verify that these labels accurately match the labels of the existing vertices. A mismatch in labels can lead to this error.

  3. ID Strategy Consistency: Confirm that your use of UUIDs as vertex IDs is consistent across your graph data. Inconsistencies in ID strategy application can cause confusion and errors.

To troubleshoot, you might start by querying the vertices separately to confirm their existence and labels in the graph. This step can help pinpoint whether the issue lies with the vertex ID, label mismatch, or another aspect of your graph setup.

#### Details **Sources** - [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-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/test/resources/customized_uuid/struct.json](https://github.com/apache/incubator-hugegraph-toolchain/blob/master/hugegraph-loader/src/test/resources/customized_uuid/struct.json) - [hugegraph-client/src/main/java/org/apache/hugegraph/serializer/direct/util/Id.java](https://github.com/apache/incubator-hugegraph-toolchain/blob/master/hugegraph-client/src/main/java/org/apache/hugegraph/serializer/direct/util/Id.java) - [hugegraph-client/src/main/java/org/apache/hugegraph/api/graph/EdgeAPI.java](https://github.com/apache/incubator-hugegraph-toolchain/blob/master/hugegraph-client/src/main/java/org/apache/hugegraph/api/graph/EdgeAPI.java) - [hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/api/EdgeApiTest.java](https://github.com/apache/incubator-hugegraph/blob/master/hugegraph-server/hugegraph-test/src/main/java/org/apache/hugegraph/api/EdgeApiTest.java) - [content/en/docs/clients/restful-api/edge.md](https://github.com/apache/incubator-hugegraph-doc/blob/master/content/en/docs/clients/restful-api/edge.md) - [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-client/src/main/java/org/apache/hugegraph/api/graph/GraphAPI.java](https://github.com/apache/incubator-hugegraph-toolchain/blob/master/hugegraph-client/src/main/java/org/apache/hugegraph/api/graph/GraphAPI.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 1 month 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