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

feat(interactive): Add Create/Update/Get APIs for vertex/edge in Interactive #4025

Merged
merged 29 commits into from
Aug 1, 2024

Conversation

yqylh
Copy link
Contributor

@yqylh yqylh commented Jul 10, 2024

What do these changes do?

This PR primarily support six interfaces for creating, updating, and retrieving vertices and edges. The Delete operation is not included as the underlying Graph DB does not yet support it.

The interfaces for vertices are as follows:

  • Method: GET (retrieve) / POST (create) / PUT (update)
  • EndPoint: /v1/graph/{graph_id}/vertex

The interfaces for edges are as follows:

  • Method: GET (retrieve) / POST (create) / PUT (update)
  • EndPoint: /v1/graph/{graph_id}/edge

CreateVertex

This API interface enables the creation of any number of vertices within an existing graph, along with the addition of any number of edges. The two vertices connected by these edges must either already exist within the graph or be newly created vertices.

  • For a single vertex and any number of edges, a single_vertex_insert_transaction is triggered, which supports inserting a single vertex and multiple edges.
  • For multiple vertices and any number of edges, an insert_transaction is triggered, which allows for unrestricted insertion of vertices and edges.

Http Request

  • Method:POST
  • EndPoint/v1/graph/{graph_id}/vertex
  • Content-type: application/json
  • Body
{
    "vertex_request":[
        {
            "label": "person",
            "primary_key_value": 2,
            "properties": [
                {
                    "name": "name",
                    "value": "John Doe"
                },
                {
                    "name": "age",
                    "value": 25
                }
            ]
        },
        {
            "label": "software",
            "primary_key_value": 3,
            "properties": [
                {
                    "name": "name",
                    "value": "Graph Database"
                },
                {
                    "name": "lang",
                    "value": "Java"
                }
            ]
        },
        {
            "label": "software",
            "primary_key_value": 4,
            "properties": [
                {
                    "name": "name",
                    "value": "Graph Database"
                },
                {
                    "name": "lang",
                    "value": "C++"
                }
            ]
        }
    ],
    "edge_request":[
        {
            "src_label": "person",
            "dst_label": "software",
            "edge_label": "created",
            "src_primary_key_value": 2,
            "dst_primary_key_value": 3,
            "properties": [
                {
                    "name": "weight",
                    "value": 0.3
                }
            ]
        },
        {
            "src_label": "person",
            "dst_label": "software",
            "edge_label": "created",
            "src_primary_key_value": 2,
            "dst_primary_key_value": 4,
            "properties": [
                {
                    "name": "weight",
                    "value": 0.5
                }
            ]
        }
    ]
}

CreateEdge

This API interface allows the creation of any number of edges within an existing graph. The two vertices connected by these edges must already exist within the graph.

  • For a single edge, a single_edge_insert_transaction is triggered, which supports the insertion of a single edge.
  • For multiple edges, an insert_transaction is triggered, which supports the insertion of an unlimited number of edges.

Http Request

  • Method:POST
  • EndPoint/v1/graph/{graph_id}/edge
  • Content-type: application/json
  • Body
{
    "graph_id": "example_graph",
    "edge_request":[
        {
            "src_label": "person",
            "dst_label": "software",
            "edge_label": "created",
            "src_primary_key_value": 2,
            "dst_primary_key_value": 3,
            "properties": [
                {
                    "name": "weight",
                    "value": 0.3
                }
            ]
        },
        {
            "src_label": "person",
            "dst_label": "software",
            "edge_label": "created",
            "src_primary_key_value": 2,
            "dst_primary_key_value": 4,
            "properties": [
                {
                    "name": "weight",
                    "value": 0.5
                }
            ]
        }
    ]
}

GetVertex(GraphManagement Category)

The function of this API interface is to get the properties of a Vertex in an existing graph.

Http Request

  • Method:GET
  • EndPoint/v1/graph/{graph_id}/vertex
  • parameters
{
    "label":"person",
    "primary_key_value":"1"
}

Expected Response

  • Formatapplication/json
  • Body

Successfully found vertex

{
    "label": "person",
    "values": [
        {
            "name": "name",
            "value": "John Doe"
        },
        {
            "name": "age",
            "value": 25
        }
    ]
}

GetEdge(GraphManagement Category)

The function of this API interface is to get information about the properties of an Edge in an existing graph.

Http Request

  • Method:GET
  • EndPoint/v1/graph/{graph_id}/edge
  • parameters
{
    "src_label": "person",
    "dst_label": "software",
    "edge_label": "created",
    "src_primary_key_value": 2,
    "dst_primary_key_value": 3
}

Expected Response

  • Formatapplication/json
  • Body:Successfully get edge
{
    "src_label": "person",
    "dst_label": "software",
    "edge_label": "created",
    "src_primary_key_value": 2,
    "dst_primary_key_value": 3,
    "properties": [
        {
            "name": "weight",
            "value": 0.5
        }
    ]
}

UpdateVertex(GraphManagement Category)

The function of this API interface is to modify the properties of a Vertex in an existing graph.

Http Request

  • Method:PUT
  • EndPoint/v1/graph/{graph_id}/vertex
  • Content-type: application/json
  • Body
{
    "label": "person",
    "primary_key_value": 2,
    "properties": [
        {
            "name": "name",
            "value": "John Doe"
        },
        {
            "name": "age",
            "value": 25
        }
    ]
}

UpdateEdge(GraphManagement Category)

The function of this API interface is to modify the properties of the Edge in an existing graph.

Http Request

  • Method:PUT
  • EndPoint/v1/graph/{graph_id}/edge
  • Content-type: application/json
  • Body
{
    "src_label": "person",
    "dst_label": "software",
    "edge_label": "created",
    "src_primary_key_value": 2,
    "dst_primary_key_value": 3,
    "properties": [
        {
            "name": "weight",
            "value": 0.3
        }
    ]
}

Limitations:

  1. Due to the significant cost of partitioning, queries on graph_id can only be performed on the currently running graph.

  2. Although the system now supports edges with multiple attributes, the related transactions only support the creation, update, and retrieval of edges with a single attribute. Therefore, operations on multi-attribute edges are not supported at this time.

  3. For edges/vertices of the same type, only 20% of the size N allocated at import time is reserved. If the initial graph is very small, only one or two edges/vertices can be inserted. This aspect will need to be adjusted in the future.

  4. These interfaces have been designed to closely align with the SDK requirements. However, adjustments are needed within the SDK to support batch insertion of multiple vertices and edges.

@yqylh yqylh changed the title This commit primarily support six interfaces for creating, updating,… PR Feat(interactive) : Supports RESTful API Support for Vertex and Edge Operations Including Create, Update, and Get Jul 10, 2024
@yqylh yqylh changed the title PR Feat(interactive) : Supports RESTful API Support for Vertex and Edge Operations Including Create, Update, and Get Feat(interactive) : Supports RESTful API Support for Vertex and Edge Operations Including Create, Update, and Get Jul 10, 2024
@yqylh yqylh changed the title Feat(interactive) : Supports RESTful API Support for Vertex and Edge Operations Including Create, Update, and Get Feat(interactive) : Supports API for Vertex and Edge Operations Including Create, Update, and Get Jul 10, 2024
@zhanglei1949
Copy link
Collaborator

zhanglei1949 commented Jul 10, 2024

Nice work! Could you please add an end-to-end test case covering the creation, updating, and retrieval of vertices and edges? Perhaps including a test scenario within flex/interactive/sdk/python/test and flex/interactive/sdk/java/src/test/.

You may use the ldbc sf0.1 as the dataset.

@zhanglei1949 zhanglei1949 changed the title Feat(interactive) : Supports API for Vertex and Edge Operations Including Create, Update, and Get feat(interactive): Add Create/Update/Get APIs for vertex/edge in Interactive Jul 10, 2024
@yqylh yqylh force-pushed the feat-support-crud-http-new branch from 435308e to 6bcafb1 Compare July 18, 2024 07:22
flex/engines/graph_db/database/manager.cc Outdated Show resolved Hide resolved
flex/engines/graph_db/database/manager.h Outdated Show resolved Hide resolved
flex/engines/graph_db/database/manager.h Outdated Show resolved Hide resolved
flex/engines/http_server/actor/executor.act.cc Outdated Show resolved Hide resolved
@@ -168,6 +169,84 @@ seastar::future<std::unique_ptr<seastar::httpd::reply>> hqps_ic_handler::handle(
auto dst_executor = executor_idx_;
executor_idx_ = (executor_idx_ + 1) % shard_concurrency_;
// TODO(zhanglei): choose read or write based on the request, after the
auto& method = req->_method;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we need a new handler to handle vertex/edge CRUD request? @luoxiaojian

@@ -59,6 +59,8 @@ using admin_query_result = payload<gs::Result<seastar::sstring>>;
// url_path, query_param
using graph_management_param =
payload<std::pair<seastar::sstring, seastar::sstring>>;
using graph_management_query_param =
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need a map?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because the get request is for a map, not a json.

@yqylh yqylh force-pushed the feat-support-crud-http-new branch from 15728c8 to f057101 Compare July 29, 2024 12:58
…ers into scope cancel/recreation

Committed-by: xiaolei.zl from Dev container
Committed-by: xiaolei.zl from Dev container
luoxiaojian
luoxiaojian previously approved these changes Aug 1, 2024
Copy link
Collaborator

@zhanglei1949 zhanglei1949 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@zhanglei1949 zhanglei1949 merged commit bfb70dc into alibaba:main Aug 1, 2024
32 of 33 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants