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(api-core): support label & property filtering for both edge and vertex & support kout dfs mode #2295

Merged
merged 19 commits into from
Sep 10, 2023

Conversation

DanGuge
Copy link
Contributor

@DanGuge DanGuge commented Aug 25, 2023

Purpose of the PR

Main Changes

Label & property filtering for edge and vertex

The filtering is supported in Kout Post and Kneighbor Post Apis, and is there a need for other apis?

Originally only edge label filtering was supported, now label and property filtering for edge and vertex is supported.

  • add classes VEStepEntity and VEStep to support serialization in request
  • add class Steps to support filtering of edge and vertex in runtime(core)
  • add new method edgesOfVertex(Id source, Steps steps) to support label and property filtering for both edge and vertex in HugeTraverser.java
  • design document

项目架构-顶点和边过滤

Kout dfs mode

Add DFS-based Kout mode in Kout Post Api and users can select the algorithm throught request parameters.

  • add dfs kout in KoutTraverser.java
  • add class NestedIterator to support dfs traversal which can remember the vertices and layers you traversed in the past
  • design document

Verifying these changes

  • Trivial rework / code cleanup without any test coverage. (No Need)
  • Already covered by existing tests, such as (please modify tests here).
  • Need tests and can be verified as follows:
    • Postman Test: the tests of Kout Post are shown below

Initialize the Graph

  • Initialze the graph according to the link

Label & property filtering for edge and vertex in Kout Post

  • Method & Url
POST http://localhost:8080/graphs/{graph}/traversers/kout
  • Request Body
{
  "source": "1:marko",
    "steps": {
    "direction": "BOTH",
    "edge_steps": [
        {
            "label": "knows",
            "properties": {
                "weight": "P.gt(1.2)"
            }
        },
        {
            "label": "created",
            "properties": {
                "weight": "P.gt(0.39)"
            }
        }
    ],
    "vertex_steps": [
        {
            "label": "person",
            "properties": {
                "age": "P.lt(33)"
            }
        },
        {
            "label": "software",
            "properties": {}
        }
    ],
    "max_degree": 10000,
    "skip_degree": 100000
    },
  "max_depth": 3,
  "nearest": false,
  "limit": 10000,
  "with_vertex": false,
  "with_path": true,
  "with_edge": false
}
  • Response Body
{
    "kout": [
        "2:ripple",
        "2:lop"
    ],
    "size": 2,
    "paths": [
        {
            "objects": [
                "1:marko",
                "2:lop",
                "1:josh",
                "2:lop"
            ]
        },
        {
            "objects": [
                "1:marko",
                "2:lop",
                "1:josh",
                "2:ripple"
            ]
        }
    ],
    "vertices": [
        "2:ripple",
        "1:marko",
        "1:josh",
        "2:lop"
    ],
    "edges": [
        "S1:josh>2>>S2:ripple",
        "S1:josh>2>>S2:lop",
        "S1:marko>2>>S2:lop"
    ],
    "measure": {
        "edge_iterations": 5,
        "vertice_iterations": 3,
        "cost(ns)": 175009500
    }
}

Kout Post dfs mode

  • Method & Url
POST http://localhost:8080/graphs/{graph}/traversers/kout
  • Request Body
{
  "source": "1:marko",
    "steps": {
    "direction": "BOTH",
    "edge_steps": [
        {
            "label": "knows",
            "properties": {
                "weight": "P.gt(1.2)"
            }
        },
        {
            "label": "created",
            "properties": {
                "weight": "P.gt(0.39)"
            }
        }
    ],
    "vertex_steps": [
        {
            "label": "person",
            "properties": {
                "age": "P.lt(33)"
            }
        },
        {
            "label": "software",
            "properties": {}
        }
    ],
    "max_degree": 10000,
    "skip_degree": 100000
    },
  "max_depth": 3,
  "nearest": false,
  "limit": 10000,
  "with_vertex": false,
  "with_path": true,
  "with_edge": false,
  "algorithm": "depth_first_search"
}
  • Response Body
{
    "kout": [
        "2:ripple",
        "2:lop"
    ],
    "size": 2,
    "paths": [
        {
            "objects": [
                "1:marko",
                "2:lop",
                "1:josh",
                "2:lop"
            ]
        },
        {
            "objects": [
                "1:marko",
                "2:lop",
                "1:josh",
                "2:ripple"
            ]
        }
    ],
    "vertices": [
        "2:ripple",
        "1:marko",
        "1:josh",
        "2:lop"
    ],
    "edges": [
        "S1:josh>2>>S2:ripple",
        "S1:josh>2>>S2:lop",
        "S1:marko>2>>S2:lop"
    ],
    "measure": {
        "edge_iterations": 6,
        "vertice_iterations": 3,
        "cost(ns)": 60305791
    }
}
image

Does this PR potentially affect the following parts?

  • Nope
  • Dependencies (add/update license info)
  • Modify configurations
  • The public API
  • Other affects (typed here)

Documentation Status

  • Doc - TODO
  • Doc - Done
  • Doc - No Need

@codecov
Copy link

codecov bot commented Aug 25, 2023

Codecov Report

Merging #2295 (bcae6b8) into master (aaf67cf) will increase coverage by 3.27%.
Report is 1 commits behind head on master.
The diff coverage is 30.69%.

@@             Coverage Diff              @@
##             master    #2295      +/-   ##
============================================
+ Coverage     65.09%   68.36%   +3.27%     
- Complexity      981      987       +6     
============================================
  Files           498      500       +2     
  Lines         41241    41516     +275     
  Branches       5738     5786      +48     
============================================
+ Hits          26844    28384    +1540     
+ Misses        11737    10375    -1362     
- Partials       2660     2757      +97     
Files Changed Coverage Δ
...java/org/apache/hugegraph/backend/query/Query.java 86.56% <ø> (ø)
...h/traversal/algorithm/iterator/NestedIterator.java 0.00% <0.00%> (ø)
...e/hugegraph/traversal/algorithm/KoutTraverser.java 57.14% <9.09%> (-16.10%) ⬇️
...graph/traversal/algorithm/records/KoutRecords.java 42.85% <10.00%> (-42.86%) ⬇️
...he/hugegraph/traversal/optimize/TraversalUtil.java 59.41% <33.33%> (ø)
...e/hugegraph/traversal/algorithm/HugeTraverser.java 59.48% <37.87%> (-3.96%) ⬇️
...a/org/apache/hugegraph/api/traversers/KoutAPI.java 67.46% <38.46%> (-0.89%) ⬇️
...che/hugegraph/traversal/algorithm/steps/Steps.java 51.78% <51.78%> (ø)
.../apache/hugegraph/api/traversers/TraverserAPI.java 60.71% <55.00%> (-14.29%) ⬇️
.../apache/hugegraph/backend/tx/GraphTransaction.java 79.46% <57.89%> (-0.22%) ⬇️
... and 3 more

... and 70 files with indirect coverage changes

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

HugeGraph graph) {
ConditionQuery query,
List<HasContainer> hasContainers,
HugeGraph graph) {
Copy link
Contributor

Choose a reason for hiding this comment

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

can we revert the style changes in all files.

Copy link
Contributor Author

@DanGuge DanGuge Aug 31, 2023

Choose a reason for hiding this comment

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

ok, I reverted the style changes in all files

Copy link
Member

@imbajin imbajin Sep 1, 2023

Choose a reason for hiding this comment

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

ok, I reverted the style changes in all files

after applying the hugegraph-style.xml we still get a string of differ format?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok, I reverted the style changes in all files

after apply the hugegraph-style.xml we still get a string of differ format?

The code after applying the hugegraph-style.xml is different from the origin format and these updates are automatically made by IDEA save on action.

Copy link
Member

Choose a reason for hiding this comment

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

ok, I reverted the style changes in all files

after apply the hugegraph-style.xml we still get a string of differ format?

The code after applying the hugegraph-style.xml is different from the origin format and these updates are automatically made by IDEA save on action.

get it,“save on action” need pay more attention,and I'll check it soon

javeme
javeme previously approved these changes Sep 9, 2023
Copy link
Contributor

@javeme javeme left a comment

Choose a reason for hiding this comment

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

LGTM

@DanGuge DanGuge requested a review from imbajin September 9, 2023 06:19
Copy link
Member

@imbajin imbajin left a comment

Choose a reason for hiding this comment

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

The filtering is supported in Kout Post and Kneighbor Post Apis, and is there a need for other apis?

yep if we already supported them & we need update the doc for the changes

Comment on lines +93 to +94
public static final String TRAVERSE_MODE_BFS = "breadth_first_search";
public static final String TRAVERSE_MODE_DFS = "depth_first_search";
Copy link
Member

Choose a reason for hiding this comment

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

shall we use bfs & dfs for users to input? (just desc the full name in doc)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Got it

Co-authored-by: imbajin <jin@apache.org>
@DanGuge
Copy link
Contributor Author

DanGuge commented Sep 9, 2023

The filtering is supported in Kout Post and Kneighbor Post Apis, and is there a need for other apis?

yep if we already supported them & we need update the doc for the changes

Can I supported this feature of the rest apis in the next PR? As the code submitted this time has already been reviewed.

And I will update the doc for all the changes in hugegraph-doc.

zyxxoo
zyxxoo previously approved these changes Sep 10, 2023
Copy link
Member

@imbajin imbajin left a comment

Choose a reason for hiding this comment

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

Can I supported this feature of the rest apis in the next PR? As the code submitted this time has already been reviewed. And I will update the doc for all the changes in hugegraph-doc.

Fine & LGTM

@imbajin imbajin changed the title feat(api&core): support label & property filtering for both edge and vertex & support kout dfs mode feat(api-core): support label & property filtering for both edge and vertex & support kout dfs mode Sep 10, 2023
@imbajin imbajin merged commit 8e99d85 into apache:master Sep 10, 2023
DanGuge added a commit to DanGuge/incubator-hugegraph that referenced this pull request Sep 25, 2023
…vertex & support kout dfs mode (apache#2295)

- Support label & property filtering for both edge and vertex and the filtering is implemented in Kout Post and Kneighbor - Post Apis, reducing unnecessary graph searches through pruning
- Support Kout dfs mode in Kout Post Api

Originally only edge label filtering was supported, now label and property filtering for edge and vertex is supported.
- add classes VEStepEntity and VEStep to support serialization in request
- add class Steps to support filtering of edge and vertex in runtime(core)
- add new method edgesOfVertex(Id source, Steps steps) to support label and property filtering for both edge and vertex in HugeTraverser.java

---------

Co-authored-by: imbajin <jin@apache.org>
VGalaxies pushed a commit to VGalaxies/incubator-hugegraph that referenced this pull request Nov 10, 2023
…vertex & support kout dfs mode (apache#2295)

- Support label & property filtering for both edge and vertex and the filtering is implemented in Kout Post and Kneighbor - Post Apis, reducing unnecessary graph searches through pruning
- Support Kout dfs mode in Kout Post Api

Originally only edge label filtering was supported, now label and property filtering for edge and vertex is supported.
- add classes VEStepEntity and VEStep to support serialization in request
- add class Steps to support filtering of edge and vertex in runtime(core)
- add new method edgesOfVertex(Id source, Steps steps) to support label and property filtering for both edge and vertex in HugeTraverser.java

---------

Co-authored-by: imbajin <jin@apache.org>
imbajin added a commit that referenced this pull request Nov 10, 2023
…vertex & support kout dfs mode (#2295)

- Support label & property filtering for both edge and vertex and the filtering is implemented in Kout Post and Kneighbor - Post Apis, reducing unnecessary graph searches through pruning
- Support Kout dfs mode in Kout Post Api

Originally only edge label filtering was supported, now label and property filtering for edge and vertex is supported.
- add classes VEStepEntity and VEStep to support serialization in request
- add class Steps to support filtering of edge and vertex in runtime(core)
- add new method edgesOfVertex(Id source, Steps steps) to support label and property filtering for both edge and vertex in HugeTraverser.java

---------

Co-authored-by: imbajin <jin@apache.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

4 participants