You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@hugegraph.apache.org by "DanGuge (via GitHub)" <gi...@apache.org> on 2023/08/25 06:35:14 UTC

[GitHub] [incubator-hugegraph] DanGuge opened a new pull request, #2295: feat(api&core): support label & property filtering for both edge and vertex & support kout dfs mode

DanGuge opened a new pull request, #2295:
URL: https://github.com/apache/incubator-hugegraph/pull/2295

   <!-- 
     Thank you very much for contributing to Apache HugeGraph, we are happy that you want to help us improve it!
   
     Here are some tips for you:
       1. If this is your first time, please read the [contributing guidelines](https://github.com/apache/hugegraph/blob/master/CONTRIBUTING.md)
   
       2. If a PR fix/close an issue, type the message "close xxx" (xxx is the link of related 
   issue) in the content, GitHub will auto link it (Required)
   
       3. Name the PR title in "Google Commit Format", start with "feat | fix | perf | refactor | doc | chore", 
         such like: "feat(core): support the PageRank algorithm" or "fix: wrong break in the compute loop" (module is optional)
         skip it if you are unsure about which is the best component.
   
       4. One PR address one issue, better not to mix up multiple issues.
   
       5. Put an `x` in the `[ ]` to mark the item as CHECKED. `[x]` (or click it directly after 
   published)
   -->
   
   ## Purpose of the PR
   
   - 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
   - related issue #2276
   
   <!--
   Please explain more context in this section, clarify why the changes are needed. 
   e.g:
   - If you propose a new API, clarify the use case for a new API.
   - If you fix a bug, you can clarify why it is a bug, and should be associated with an issue.
   -->
   
   ## 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](https://hugegraph.feishu.cn/wiki/ZYjSw3PJji5cvxkfJbVcP5MrnJl)
   
   ![项目架构-顶点和边过滤](https://github.com/apache/incubator-hugegraph/assets/77946882/b175bb56-57dc-43a4-9227-0a44a6d13510)
   
   
   ### 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](https://hugegraph.feishu.cn/wiki/EOOMwn0pUiqo8TkqQobcqzYknNb)
   
   
   <!-- Please clarify what changes you are proposing. The purpose of this section is to outline the changes and how this PR fixes the issue. These change logs are helpful for better ant faster reviews.)
   
   For example:
   
   - If you introduce a new feature, please show detailed design here or add the link of design documentation.
   - If you refactor some codes with changing classes, showing the class hierarchy will help reviewers.
   - If there is a discussion in the mailing list, please add the link. -->
   
   ## Verifying these changes
   
   <!-- Please pick the proper options below -->
   
   - [ ] Trivial rework / code cleanup without any test coverage. (No Need)
   - [ ] Already covered by existing tests, such as *(please modify tests here)*.
   - [x] 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](https://hugegraph.apache.org/docs/clients/restful-api/traverser/#32-detailed-explanation-of-traverser-api-1)
   
   ### Label & property filtering for edge and vertex in Kout Post
   
   - Method & Url
   
   ```
   POST http://localhost:8080/graphs/{graph}/traversers/kout
   ```
   
   - Request Body
   
   ```json
   {
     "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
   
   ```json
   {
       "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
   
   ```json
   {
     "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
   
   ```json
   {
       "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
       }
   }
   ```
   
   <img width="853" alt="image" src="https://github.com/apache/incubator-hugegraph/assets/77946882/5190bea0-ca00-4ab2-acfc-48416b73d724">
   
   
   ## Does this PR potentially affect the following parts?
   
   <!-- DO NOT REMOVE THIS SECTION. CHECK THE PROPER BOX ONLY. -->
   
   - [ ]  Nope
   - [ ]  Dependencies (add/update license info) <!-- Don't forget to add/update the info in "LICENSE" & "NOTICE" files (both in root & dist module) -->
   - [ ]  Modify configurations
   - [x]  The public API
   - [ ]  Other affects (typed here)
   
   ## Documentation Status
   
   <!-- DO NOT REMOVE THIS SECTION. CHECK THE PROPER BOX ONLY. -->
   
   - [x]  `Doc - TODO` <!-- Your PR changes impact docs and you will update later -->
   - [ ]  `Doc - Done` <!-- Related docs have been already added or updated -->
   - [ ]  `Doc - No Need` <!-- Your PR changes don't impact/need docs -->
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@hugegraph.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@hugegraph.apache.org
For additional commands, e-mail: issues-help@hugegraph.apache.org


[GitHub] [incubator-hugegraph] imbajin commented on a diff in pull request #2295: feat(api&core): support label & property filtering for both edge and vertex & support kout dfs mode

Posted by "imbajin (via GitHub)" <gi...@apache.org>.
imbajin commented on code in PR #2295:
URL: https://github.com/apache/incubator-hugegraph/pull/2295#discussion_r1312603535


##########
hugegraph-core/src/main/java/org/apache/hugegraph/traversal/optimize/TraversalUtil.java:
##########
@@ -310,9 +311,9 @@ public static void extractAggregateFunc(Step<?, ?> newStep,
     }
 
     public static ConditionQuery fillConditionQuery(
-                                 ConditionQuery query,
-                                 List<HasContainer> hasContainers,
-                                 HugeGraph graph) {
+            ConditionQuery query,
+            List<HasContainer> hasContainers,
+            HugeGraph graph) {

Review Comment:
   > > > 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



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@hugegraph.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@hugegraph.apache.org
For additional commands, e-mail: issues-help@hugegraph.apache.org


[GitHub] [incubator-hugegraph] javeme commented on a diff in pull request #2295: feat(api&core): support label & property filtering for both edge and vertex & support kout dfs mode

Posted by "javeme (via GitHub)" <gi...@apache.org>.
javeme commented on code in PR #2295:
URL: https://github.com/apache/incubator-hugegraph/pull/2295#discussion_r1320132868


##########
hugegraph-core/src/main/java/org/apache/hugegraph/traversal/algorithm/KoutTraverser.java:
##########
@@ -138,6 +138,38 @@ public KoutRecords customizedKout(Id source, EdgeStep step,
         return records;
     }
 
+    public KoutRecords DFSKout(Id source, Steps steps,
+                               int maxDepth, boolean nearest,
+                               long capacity, long limit) {
+        E.checkNotNull(source, "source vertex id");
+        this.checkVertexExist(source, "source vertex");
+        checkPositive(maxDepth, "k-out max_depth");

Review Comment:
   It's OK, I missed your reply



##########
hugegraph-core/src/main/java/org/apache/hugegraph/traversal/algorithm/HugeTraverser.java:
##########
@@ -164,6 +171,17 @@ public static void checkSkipDegree(long skipDegree, long degree,
         }
     }
 
+    public static void checkTraverseMode(String traverseMode) {
+        E.checkArgument(traverseMode.compareToIgnoreCase(TRAVERSE_MODE_BFS) == 0 ||
+                        traverseMode.compareToIgnoreCase(TRAVERSE_MODE_DFS) == 0,
+                        "The traverse mode must be one of '%s' or '%s', but got '%s'",
+                        TRAVERSE_MODE_BFS, TRAVERSE_MODE_DFS, traverseMode);
+    }
+
+    public static boolean isDFSAlgorithm(String algorithm) {

Review Comment:
   isTraverseModeDFS



##########
hugegraph-core/src/main/java/org/apache/hugegraph/traversal/algorithm/steps/Steps.java:
##########
@@ -0,0 +1,186 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with this
+ * work for additional information regarding copyright ownership. The ASF
+ * licenses this file to You under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.hugegraph.traversal.algorithm.steps;
+
+import static org.apache.hugegraph.traversal.algorithm.HugeTraverser.NO_LIMIT;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.hugegraph.HugeGraph;
+import org.apache.hugegraph.backend.id.Id;
+import org.apache.hugegraph.schema.EdgeLabel;
+import org.apache.hugegraph.schema.VertexLabel;
+import org.apache.hugegraph.traversal.algorithm.HugeTraverser;
+import org.apache.hugegraph.traversal.optimize.TraversalUtil;
+import org.apache.hugegraph.type.define.Directions;
+import org.apache.hugegraph.util.E;
+
+public class Steps {
+
+    protected final Map<Id, StepEntity> edgeSteps;
+    protected final Map<Id, StepEntity> vertexSteps;
+    protected final Directions direction;
+    protected final long degree;
+    protected final long skipDegree;
+
+    public Steps(HugeGraph graph, Directions direction,
+                 Map<String, Map<String, Object>> vSteps,
+                 Map<String, Map<String, Object>> eSteps,
+                 long degree, long skipDegree) {
+        E.checkArgument(degree == NO_LIMIT || degree > 0L,
+                        "The max degree must be > 0 or == -1, but got: %s", degree);
+        HugeTraverser.checkSkipDegree(skipDegree, degree, NO_LIMIT);
+
+        this.direction = direction;
+
+        // parse vertex steps
+        this.vertexSteps = new HashMap<>();
+        if (vSteps != null && !vSteps.isEmpty()) {
+            initVertexFilter(graph, vSteps);
+        }
+
+        // parse edge steps
+        this.edgeSteps = new HashMap<>();
+        if (eSteps != null && !eSteps.isEmpty()) {
+            initEdgeFilter(graph, eSteps);
+        }
+
+        this.degree = degree;
+        this.skipDegree = skipDegree;
+    }
+
+    private void initVertexFilter(HugeGraph graph, Map<String, Map<String, Object>> vSteps) {
+        for (Map.Entry<String, Map<String, Object>> entry : vSteps.entrySet()) {
+            if (checkEntryEmpty(entry)) {
+                continue;
+            }
+            E.checkArgument(entry.getKey() != null && !entry.getKey().isEmpty(),
+                            "The vertex step label could not be null");
+
+            VertexLabel vertexLabel = graph.vertexLabel(entry.getKey());
+            StepEntity stepEntity = handleStepEntity(graph, entry, vertexLabel.id());
+            this.vertexSteps.put(vertexLabel.id(), stepEntity);
+        }
+    }
+
+    private void initEdgeFilter(HugeGraph graph, Map<String, Map<String, Object>> eSteps) {
+        for (Map.Entry<String, Map<String, Object>> entry : eSteps.entrySet()) {
+            if (checkEntryEmpty(entry)) {
+                continue;
+            }
+            E.checkArgument(entry.getKey() != null && !entry.getKey().isEmpty(),
+                            "The edge step label could not be null");
+
+            EdgeLabel edgeLabel = graph.edgeLabel(entry.getKey());
+            StepEntity stepEntity = handleStepEntity(graph, entry, edgeLabel.id());
+            this.edgeSteps.put(edgeLabel.id(), stepEntity);
+        }
+    }
+
+    private StepEntity handleStepEntity(HugeGraph graph,
+                                        Map.Entry<String, Map<String, Object>> entry,
+                                        Id id) {
+        Map<Id, Object> properties = null;
+        if (entry.getValue() != null) {
+            properties = TraversalUtil.transProperties(graph, entry.getValue());
+        }
+        return new StepEntity(id, entry.getKey(), properties);
+    }
+
+    private boolean checkEntryEmpty(Map.Entry<String, Map<String, Object>> entry) {
+        return (entry.getKey() == null || entry.getKey().isEmpty()) &&
+               (entry.getValue() == null || entry.getValue().isEmpty());
+    }
+
+    public long degree() {
+        return degree;

Review Comment:
   add `this.` prefix for members access



##########
hugegraph-core/src/main/java/org/apache/hugegraph/traversal/algorithm/steps/Steps.java:
##########
@@ -0,0 +1,186 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with this
+ * work for additional information regarding copyright ownership. The ASF
+ * licenses this file to You under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.hugegraph.traversal.algorithm.steps;
+
+import static org.apache.hugegraph.traversal.algorithm.HugeTraverser.NO_LIMIT;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.hugegraph.HugeGraph;
+import org.apache.hugegraph.backend.id.Id;
+import org.apache.hugegraph.schema.EdgeLabel;
+import org.apache.hugegraph.schema.VertexLabel;
+import org.apache.hugegraph.traversal.algorithm.HugeTraverser;
+import org.apache.hugegraph.traversal.optimize.TraversalUtil;
+import org.apache.hugegraph.type.define.Directions;
+import org.apache.hugegraph.util.E;
+
+public class Steps {
+
+    protected final Map<Id, StepEntity> edgeSteps;
+    protected final Map<Id, StepEntity> vertexSteps;
+    protected final Directions direction;
+    protected final long degree;
+    protected final long skipDegree;
+
+    public Steps(HugeGraph graph, Directions direction,
+                 Map<String, Map<String, Object>> vSteps,
+                 Map<String, Map<String, Object>> eSteps,
+                 long degree, long skipDegree) {
+        E.checkArgument(degree == NO_LIMIT || degree > 0L,
+                        "The max degree must be > 0 or == -1, but got: %s", degree);
+        HugeTraverser.checkSkipDegree(skipDegree, degree, NO_LIMIT);
+
+        this.direction = direction;
+
+        // parse vertex steps
+        this.vertexSteps = new HashMap<>();
+        if (vSteps != null && !vSteps.isEmpty()) {
+            initVertexFilter(graph, vSteps);
+        }
+
+        // parse edge steps
+        this.edgeSteps = new HashMap<>();
+        if (eSteps != null && !eSteps.isEmpty()) {
+            initEdgeFilter(graph, eSteps);
+        }
+
+        this.degree = degree;
+        this.skipDegree = skipDegree;
+    }
+
+    private void initVertexFilter(HugeGraph graph, Map<String, Map<String, Object>> vSteps) {
+        for (Map.Entry<String, Map<String, Object>> entry : vSteps.entrySet()) {
+            if (checkEntryEmpty(entry)) {
+                continue;
+            }
+            E.checkArgument(entry.getKey() != null && !entry.getKey().isEmpty(),
+                            "The vertex step label could not be null");
+
+            VertexLabel vertexLabel = graph.vertexLabel(entry.getKey());
+            StepEntity stepEntity = handleStepEntity(graph, entry, vertexLabel.id());
+            this.vertexSteps.put(vertexLabel.id(), stepEntity);
+        }
+    }
+
+    private void initEdgeFilter(HugeGraph graph, Map<String, Map<String, Object>> eSteps) {
+        for (Map.Entry<String, Map<String, Object>> entry : eSteps.entrySet()) {
+            if (checkEntryEmpty(entry)) {
+                continue;
+            }
+            E.checkArgument(entry.getKey() != null && !entry.getKey().isEmpty(),
+                            "The edge step label could not be null");
+
+            EdgeLabel edgeLabel = graph.edgeLabel(entry.getKey());
+            StepEntity stepEntity = handleStepEntity(graph, entry, edgeLabel.id());
+            this.edgeSteps.put(edgeLabel.id(), stepEntity);
+        }
+    }
+
+    private StepEntity handleStepEntity(HugeGraph graph,
+                                        Map.Entry<String, Map<String, Object>> entry,
+                                        Id id) {
+        Map<Id, Object> properties = null;
+        if (entry.getValue() != null) {
+            properties = TraversalUtil.transProperties(graph, entry.getValue());
+        }
+        return new StepEntity(id, entry.getKey(), properties);
+    }
+
+    private boolean checkEntryEmpty(Map.Entry<String, Map<String, Object>> entry) {
+        return (entry.getKey() == null || entry.getKey().isEmpty()) &&
+               (entry.getValue() == null || entry.getValue().isEmpty());
+    }
+
+    public long degree() {
+        return degree;
+    }
+
+    public Map<Id, StepEntity> edgeSteps() {
+        return edgeSteps;
+    }
+
+    public Map<Id, StepEntity> vertexSteps() {
+        return vertexSteps;
+    }
+
+    public long skipDegree() {
+        return skipDegree;
+    }
+
+    public Directions direction() {
+        return direction;
+    }
+
+    public long limit() {
+        return this.skipDegree > 0L ? this.skipDegree : this.degree;
+    }
+
+    public List<Id> edgeLabels() {
+        return new ArrayList<>(this.edgeSteps.keySet());
+    }
+
+    public boolean isVertexEmpty() {
+        return this.vertexSteps.isEmpty();
+    }
+
+    @Override
+    public String toString() {
+        return "Steps{" +
+               "edgeSteps=" + edgeSteps +
+               ", vertexSteps=" + vertexSteps +
+               ", direction=" + direction +
+               ", degree=" + degree +
+               ", skipDegree=" + skipDegree +
+               '}';
+    }
+
+    public static class StepEntity {

Review Comment:
   expect a blank line here



##########
hugegraph-core/src/main/java/org/apache/hugegraph/backend/tx/GraphTransaction.java:
##########
@@ -1696,12 +1719,9 @@ private <T extends HugeElement> Iterator<T> filterUnmatchedRecords(
                 return false;
             }
             // Process results that query from left index or primary-key
-            if (query.resultType().isVertex() == elem.type().isVertex() &&
-                !rightResultFromIndexQuery(query, elem)) {
-                // Only index query will come here
-                return false;
-            }
-            return true;
+            // Only index query will come here

Review Comment:
   `// Only index query will come here` only when returning false, prefer to revert it 



##########
hugegraph-core/src/main/java/org/apache/hugegraph/traversal/algorithm/HugeTraverser.java:
##########
@@ -85,6 +89,9 @@ public class HugeTraverser {
     // Empirical value of scan limit, with which results can be returned in 3s
     public static final String DEFAULT_PAGE_LIMIT = "100000";
     public static final long NO_LIMIT = -1L;
+    // algorithms

Review Comment:
   we can remove the comment or add more details



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@hugegraph.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@hugegraph.apache.org
For additional commands, e-mail: issues-help@hugegraph.apache.org


[GitHub] [incubator-hugegraph] DanGuge commented on pull request #2295: feat(api&core): support label & property filtering for both edge and vertex & support kout dfs mode

Posted by "DanGuge (via GitHub)" <gi...@apache.org>.
DanGuge commented on PR #2295:
URL: https://github.com/apache/incubator-hugegraph/pull/2295#issuecomment-1712527891

   > > 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](https://github.com/apache/incubator-hugegraph-doc).


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@hugegraph.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@hugegraph.apache.org
For additional commands, e-mail: issues-help@hugegraph.apache.org


[GitHub] [incubator-hugegraph] DanGuge commented on a diff in pull request #2295: feat(api&core): support label & property filtering for both edge and vertex & support kout dfs mode

Posted by "DanGuge (via GitHub)" <gi...@apache.org>.
DanGuge commented on code in PR #2295:
URL: https://github.com/apache/incubator-hugegraph/pull/2295#discussion_r1311578520


##########
hugegraph-core/src/main/java/org/apache/hugegraph/traversal/algorithm/HugeTraverser.java:
##########
@@ -438,6 +465,92 @@ private Iterator<Edge> edgesOfVertex(Id source, EdgeStep edgeStep,
         return edgeStep.skipSuperNodeIfNeeded(edges);
     }
 
+    protected Iterator<Edge> edgesOfVertex(Id source, Steps steps) {
+        List<Id> edgeLabels = steps.edgeLabels();
+        ConditionQuery cq = GraphTransaction.constructEdgesQuery(
+                source, steps.direction(), edgeLabels);
+        cq.capacity(Query.NO_CAPACITY);
+        if (steps.limit() != NO_LIMIT) {
+            cq.limit(steps.limit());
+        }
+
+        Map<Id, ConditionQuery> edgeConditions =
+                getElementFilterQuery(steps.edgeSteps(), HugeType.EDGE);
+
+        Iterator<Edge> filteredEdges =
+                new FilterIterator<>(this.graph().edges(cq),
+                                     edge -> validateEdge(edgeConditions, (HugeEdge) edge));
+
+        return edgesOfVertexStep(filteredEdges, steps);
+    }
+
+    protected Iterator<Edge> edgesOfVertexStep(Iterator<Edge> edges, Steps steps) {
+        if (steps.isVertexEmpty()) {
+            return edges;
+        }
+
+        Map<Id, ConditionQuery> vertexConditions =
+                getElementFilterQuery(steps.vertexSteps(), HugeType.VERTEX);
+
+        return new FilterIterator<>(edges,
+                                    edge -> validateVertex(vertexConditions, (HugeEdge) edge));
+    }
+
+    private Boolean validateVertex(Map<Id, ConditionQuery> vConditions,
+                                   HugeEdge edge) {
+        HugeVertex sourceV = edge.sourceVertex();
+        HugeVertex targetV = edge.targetVertex();
+        if (!vConditions.containsKey(sourceV.schemaLabel().id()) ||
+            !vConditions.containsKey(targetV.schemaLabel().id())) {
+            return false;
+        }
+
+        ConditionQuery cq = vConditions.get(sourceV.schemaLabel().id());
+        if (cq != null) {
+            sourceV = (HugeVertex) this.graph.vertex(sourceV.id());
+            if (!cq.test(sourceV)) {
+                return false;
+            }
+        }
+
+        cq = vConditions.get(targetV.schemaLabel().id());
+        if (cq != null) {
+            targetV = (HugeVertex) this.graph.vertex(targetV.id());
+            return cq.test(targetV);
+        }
+        return true;
+    }
+
+    private Boolean validateEdge(Map<Id, ConditionQuery> eConditions,
+                                 HugeEdge edge) {
+        if (!eConditions.containsKey(edge.schemaLabel().id())) {
+            return false;
+        }
+
+        ConditionQuery cq = eConditions.get(edge.schemaLabel().id());
+        if (cq != null) {
+            return cq.test(edge);
+        }
+        return true;
+    }
+
+    private Map<Id, ConditionQuery> getElementFilterQuery(

Review Comment:
   fixed



##########
hugegraph-core/src/main/java/org/apache/hugegraph/traversal/algorithm/HugeTraverser.java:
##########
@@ -878,4 +1006,166 @@ public Set<Edge> getEdges(Iterator<Id> vertexIter) {
         }
 
     }
+
+    public static class NestedIterator extends WrappedIterator<Edge> {

Review Comment:
   fixed



##########
hugegraph-core/src/main/java/org/apache/hugegraph/traversal/algorithm/KoutTraverser.java:
##########
@@ -138,6 +138,38 @@ public KoutRecords customizedKout(Id source, EdgeStep step,
         return records;
     }
 
+    public KoutRecords DFSKout(Id source, Steps steps,

Review Comment:
   fixed



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@hugegraph.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@hugegraph.apache.org
For additional commands, e-mail: issues-help@hugegraph.apache.org


[GitHub] [incubator-hugegraph] javeme commented on a diff in pull request #2295: feat(api&core): support label & property filtering for both edge and vertex & support kout dfs mode

Posted by "javeme (via GitHub)" <gi...@apache.org>.
javeme commented on code in PR #2295:
URL: https://github.com/apache/incubator-hugegraph/pull/2295#discussion_r1310633944


##########
hugegraph-core/src/main/java/org/apache/hugegraph/backend/tx/GraphTransaction.java:
##########
@@ -130,9 +114,18 @@ public class GraphTransaction extends IndexableTransaction {
     private final int commitPartOfAdjacentEdges;
     private final int batchSize;
     private final int pageSize;
-
     private final int verticesCapacity;
     private final int edgesCapacity;
+    private Map<Id, HugeVertex> addedVertices;
+    private Map<Id, HugeVertex> removedVertices;
+    private Map<Id, HugeEdge> addedEdges;
+    private Map<Id, HugeEdge> removedEdges;
+    private Set<HugeProperty<?>> addedProps;
+    private Set<HugeProperty<?>> removedProps;
+    // These are used to rollback state
+    private Map<Id, HugeVertex> updatedVertices;
+    private Map<Id, HugeEdge> updatedEdges;
+    private Set<HugeProperty<?>> updatedOldestProps; // Oldest props

Review Comment:
   can we keep the origin location to avoid conflicts



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@hugegraph.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@hugegraph.apache.org
For additional commands, e-mail: issues-help@hugegraph.apache.org


[GitHub] [incubator-hugegraph] DanGuge commented on a diff in pull request #2295: feat(api&core): support label & property filtering for both edge and vertex & support kout dfs mode

Posted by "DanGuge (via GitHub)" <gi...@apache.org>.
DanGuge commented on code in PR #2295:
URL: https://github.com/apache/incubator-hugegraph/pull/2295#discussion_r1311576776


##########
hugegraph-core/src/main/java/org/apache/hugegraph/backend/tx/GraphTransaction.java:
##########
@@ -171,6 +164,199 @@ public GraphTransaction(HugeGraphParams graph, BackendStore store) {
                         this.edgesCapacity);
     }
 
+    /**

Review Comment:
   fixed



##########
hugegraph-core/src/main/java/org/apache/hugegraph/backend/tx/GraphTransaction.java:
##########
@@ -1696,12 +1719,9 @@ private <T extends HugeElement> Iterator<T> filterUnmatchedRecords(
                 return false;
             }
             // Process results that query from left index or primary-key
-            if (query.resultType().isVertex() == elem.type().isVertex() &&
-                !rightResultFromIndexQuery(query, elem)) {
-                // Only index query will come here
-                return false;
-            }
-            return true;
+            // Only index query will come here

Review Comment:
   fixed



##########
hugegraph-core/src/main/java/org/apache/hugegraph/backend/tx/GraphTransaction.java:
##########
@@ -1574,14 +1597,14 @@ private void checkNonnullProperty(HugeVertex vertex) {
         // Check whether passed all non-null property
         @SuppressWarnings("unchecked")
         Collection<Id> nonNullKeys = CollectionUtils.subtract(
-                                     vertexLabel.properties(),
-                                     vertexLabel.nullableKeys());
+                vertexLabel.properties(),
+                vertexLabel.nullableKeys());

Review Comment:
   fixed



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@hugegraph.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@hugegraph.apache.org
For additional commands, e-mail: issues-help@hugegraph.apache.org


[GitHub] [incubator-hugegraph] DanGuge commented on a diff in pull request #2295: feat(api&core): support label & property filtering for both edge and vertex & support kout dfs mode

Posted by "DanGuge (via GitHub)" <gi...@apache.org>.
DanGuge commented on code in PR #2295:
URL: https://github.com/apache/incubator-hugegraph/pull/2295#discussion_r1311771944


##########
hugegraph-core/src/main/java/org/apache/hugegraph/traversal/algorithm/KoutTraverser.java:
##########
@@ -138,6 +138,38 @@ public KoutRecords customizedKout(Id source, EdgeStep step,
         return records;
     }
 
+    public KoutRecords DFSKout(Id source, Steps steps,
+                               int maxDepth, boolean nearest,
+                               long capacity, long limit) {
+        E.checkNotNull(source, "source vertex id");
+        this.checkVertexExist(source, "source vertex");
+        checkPositive(maxDepth, "k-out max_depth");

Review Comment:
   I am not sure, so should we add `this.` keyword? 
   
   I checked other traverser implementations and they didn't add `this.` keyword, such as PathsTraverser.java, SameNeighborTraverser.java and so on.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@hugegraph.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@hugegraph.apache.org
For additional commands, e-mail: issues-help@hugegraph.apache.org


[GitHub] [incubator-hugegraph] DanGuge commented on a diff in pull request #2295: feat(api&core): support label & property filtering for both edge and vertex & support kout dfs mode

Posted by "DanGuge (via GitHub)" <gi...@apache.org>.
DanGuge commented on code in PR #2295:
URL: https://github.com/apache/incubator-hugegraph/pull/2295#discussion_r1311578158


##########
hugegraph-core/src/main/java/org/apache/hugegraph/backend/tx/GraphTransaction.java:
##########
@@ -1574,14 +1597,14 @@ private void checkNonnullProperty(HugeVertex vertex) {
         // Check whether passed all non-null property
         @SuppressWarnings("unchecked")
         Collection<Id> nonNullKeys = CollectionUtils.subtract(
-                                     vertexLabel.properties(),
-                                     vertexLabel.nullableKeys());
+                vertexLabel.properties(),
+                vertexLabel.nullableKeys());
         if (!keys.containsAll(nonNullKeys)) {
             @SuppressWarnings("unchecked")
             Collection<Id> missed = CollectionUtils.subtract(nonNullKeys, keys);
             HugeGraph graph = this.graph();
             E.checkArgument(false, "All non-null property keys %s of " +
-                            "vertex label '%s' must be set, missed keys %s",
+                                   "vertex label '%s' must be set, missed keys %s",

Review Comment:
   fixed



##########
hugegraph-core/src/main/java/org/apache/hugegraph/traversal/algorithm/HugeTraverser.java:
##########
@@ -438,6 +465,92 @@ private Iterator<Edge> edgesOfVertex(Id source, EdgeStep edgeStep,
         return edgeStep.skipSuperNodeIfNeeded(edges);
     }
 
+    protected Iterator<Edge> edgesOfVertex(Id source, Steps steps) {
+        List<Id> edgeLabels = steps.edgeLabels();
+        ConditionQuery cq = GraphTransaction.constructEdgesQuery(
+                source, steps.direction(), edgeLabels);
+        cq.capacity(Query.NO_CAPACITY);
+        if (steps.limit() != NO_LIMIT) {
+            cq.limit(steps.limit());
+        }
+
+        Map<Id, ConditionQuery> edgeConditions =
+                getElementFilterQuery(steps.edgeSteps(), HugeType.EDGE);
+
+        Iterator<Edge> filteredEdges =
+                new FilterIterator<>(this.graph().edges(cq),
+                                     edge -> validateEdge(edgeConditions, (HugeEdge) edge));
+
+        return edgesOfVertexStep(filteredEdges, steps);
+    }
+
+    protected Iterator<Edge> edgesOfVertexStep(Iterator<Edge> edges, Steps steps) {
+        if (steps.isVertexEmpty()) {
+            return edges;
+        }
+
+        Map<Id, ConditionQuery> vertexConditions =
+                getElementFilterQuery(steps.vertexSteps(), HugeType.VERTEX);
+
+        return new FilterIterator<>(edges,
+                                    edge -> validateVertex(vertexConditions, (HugeEdge) edge));
+    }
+
+    private Boolean validateVertex(Map<Id, ConditionQuery> vConditions,

Review Comment:
   fixed



##########
hugegraph-core/src/main/java/org/apache/hugegraph/traversal/algorithm/HugeTraverser.java:
##########
@@ -438,6 +465,92 @@ private Iterator<Edge> edgesOfVertex(Id source, EdgeStep edgeStep,
         return edgeStep.skipSuperNodeIfNeeded(edges);
     }
 
+    protected Iterator<Edge> edgesOfVertex(Id source, Steps steps) {
+        List<Id> edgeLabels = steps.edgeLabels();
+        ConditionQuery cq = GraphTransaction.constructEdgesQuery(
+                source, steps.direction(), edgeLabels);
+        cq.capacity(Query.NO_CAPACITY);
+        if (steps.limit() != NO_LIMIT) {
+            cq.limit(steps.limit());
+        }
+
+        Map<Id, ConditionQuery> edgeConditions =
+                getElementFilterQuery(steps.edgeSteps(), HugeType.EDGE);
+
+        Iterator<Edge> filteredEdges =
+                new FilterIterator<>(this.graph().edges(cq),
+                                     edge -> validateEdge(edgeConditions, (HugeEdge) edge));
+
+        return edgesOfVertexStep(filteredEdges, steps);
+    }
+
+    protected Iterator<Edge> edgesOfVertexStep(Iterator<Edge> edges, Steps steps) {
+        if (steps.isVertexEmpty()) {
+            return edges;
+        }
+
+        Map<Id, ConditionQuery> vertexConditions =
+                getElementFilterQuery(steps.vertexSteps(), HugeType.VERTEX);
+
+        return new FilterIterator<>(edges,
+                                    edge -> validateVertex(vertexConditions, (HugeEdge) edge));
+    }
+
+    private Boolean validateVertex(Map<Id, ConditionQuery> vConditions,
+                                   HugeEdge edge) {
+        HugeVertex sourceV = edge.sourceVertex();
+        HugeVertex targetV = edge.targetVertex();
+        if (!vConditions.containsKey(sourceV.schemaLabel().id()) ||
+            !vConditions.containsKey(targetV.schemaLabel().id())) {
+            return false;
+        }
+
+        ConditionQuery cq = vConditions.get(sourceV.schemaLabel().id());
+        if (cq != null) {
+            sourceV = (HugeVertex) this.graph.vertex(sourceV.id());
+            if (!cq.test(sourceV)) {
+                return false;
+            }
+        }
+
+        cq = vConditions.get(targetV.schemaLabel().id());
+        if (cq != null) {
+            targetV = (HugeVertex) this.graph.vertex(targetV.id());
+            return cq.test(targetV);
+        }
+        return true;
+    }
+
+    private Boolean validateEdge(Map<Id, ConditionQuery> eConditions,

Review Comment:
   fixed



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@hugegraph.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@hugegraph.apache.org
For additional commands, e-mail: issues-help@hugegraph.apache.org


[GitHub] [incubator-hugegraph] imbajin commented on a diff in pull request #2295: feat(api&core): support label & property filtering for both edge and vertex & support kout dfs mode

Posted by "imbajin (via GitHub)" <gi...@apache.org>.
imbajin commented on code in PR #2295:
URL: https://github.com/apache/incubator-hugegraph/pull/2295#discussion_r1312518071


##########
hugegraph-core/src/main/java/org/apache/hugegraph/traversal/optimize/TraversalUtil.java:
##########
@@ -310,9 +311,9 @@ public static void extractAggregateFunc(Step<?, ?> newStep,
     }
 
     public static ConditionQuery fillConditionQuery(
-                                 ConditionQuery query,
-                                 List<HasContainer> hasContainers,
-                                 HugeGraph graph) {
+            ConditionQuery query,
+            List<HasContainer> hasContainers,
+            HugeGraph graph) {

Review Comment:
   > ok, I reverted the style changes in all files
   
   after apply the `hugegraph-style.xml` we still get a string of differ foramt?



##########
hugegraph-core/src/main/java/org/apache/hugegraph/traversal/optimize/TraversalUtil.java:
##########
@@ -310,9 +311,9 @@ public static void extractAggregateFunc(Step<?, ?> newStep,
     }
 
     public static ConditionQuery fillConditionQuery(
-                                 ConditionQuery query,
-                                 List<HasContainer> hasContainers,
-                                 HugeGraph graph) {
+            ConditionQuery query,
+            List<HasContainer> hasContainers,
+            HugeGraph graph) {

Review Comment:
   > ok, I reverted the style changes in all files
   
   after apply the `hugegraph-style.xml` we still get a string of differ format?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@hugegraph.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@hugegraph.apache.org
For additional commands, e-mail: issues-help@hugegraph.apache.org


[GitHub] [incubator-hugegraph] javeme commented on a diff in pull request #2295: feat(api&core): support label & property filtering for both edge and vertex & support kout dfs mode

Posted by "javeme (via GitHub)" <gi...@apache.org>.
javeme commented on code in PR #2295:
URL: https://github.com/apache/incubator-hugegraph/pull/2295#discussion_r1310647689


##########
hugegraph-core/src/main/java/org/apache/hugegraph/traversal/algorithm/HugeTraverser.java:
##########
@@ -878,4 +1006,166 @@ public Set<Edge> getEdges(Iterator<Id> vertexIter) {
         }
 
     }
+
+    public static class NestedIterator extends WrappedIterator<Edge> {

Review Comment:
   can we move it into a separate file



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@hugegraph.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@hugegraph.apache.org
For additional commands, e-mail: issues-help@hugegraph.apache.org


[GitHub] [incubator-hugegraph] imbajin commented on a diff in pull request #2295: feat(api&core): support label & property filtering for both edge and vertex & support kout dfs mode

Posted by "imbajin (via GitHub)" <gi...@apache.org>.
imbajin commented on code in PR #2295:
URL: https://github.com/apache/incubator-hugegraph/pull/2295#discussion_r1320543984


##########
hugegraph-api/src/main/java/org/apache/hugegraph/api/traversers/KoutAPI.java:
##########
@@ -229,15 +238,19 @@ private static class Request {
         @JsonProperty("with_edge")
         public boolean withEdge = false;
 
+        @JsonProperty("algorithm")

Review Comment:
   do we need the extra line 240?
   ![image](https://github.com/apache/incubator-hugegraph/assets/17706099/e4b237d4-a51d-4084-9f8e-8edb9351594b)
   



##########
hugegraph-core/src/main/java/org/apache/hugegraph/traversal/algorithm/HugeTraverser.java:
##########
@@ -878,4 +1006,5 @@ public Set<Edge> getEdges(Iterator<Id> vertexIter) {
         }
 
     }
+

Review Comment:
   need it?



##########
hugegraph-core/src/main/java/org/apache/hugegraph/traversal/algorithm/iterator/NestedIterator.java:
##########
@@ -0,0 +1,195 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with this
+ * work for additional information regarding copyright ownership. The ASF
+ * licenses this file to You under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.hugegraph.traversal.algorithm.iterator;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import org.apache.hugegraph.backend.id.Id;
+import org.apache.hugegraph.iterator.WrappedIterator;
+import org.apache.hugegraph.structure.HugeEdge;
+import org.apache.hugegraph.traversal.algorithm.HugeTraverser;
+import org.apache.hugegraph.traversal.algorithm.steps.Steps;
+import org.apache.hugegraph.util.collection.ObjectIntMapping;
+import org.apache.hugegraph.util.collection.ObjectIntMappingFactory;
+import org.apache.tinkerpop.gremlin.structure.Edge;
+
+public class NestedIterator extends WrappedIterator<Edge> {
+
+    private final int MAX_CACHED_COUNT = 1000;
+    /*

Review Comment:
   ```suggestion
       /**
   ```



##########
hugegraph-core/src/main/java/org/apache/hugegraph/traversal/algorithm/HugeTraverser.java:
##########
@@ -85,6 +89,9 @@ public class HugeTraverser {
     // Empirical value of scan limit, with which results can be returned in 3s
     public static final String DEFAULT_PAGE_LIMIT = "100000";
     public static final long NO_LIMIT = -1L;
+    // kout traverse mode algorithms: bfs and dfs
+    public static final String TRAVERSE_MODE_BFS = "breadth_first_search";
+    public static final String TRAVERSE_MODE_DFS = "depth_first_search";

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



##########
hugegraph-core/src/main/java/org/apache/hugegraph/traversal/algorithm/HugeTraverser.java:
##########
@@ -438,6 +465,92 @@ private Iterator<Edge> edgesOfVertex(Id source, EdgeStep edgeStep,
         return edgeStep.skipSuperNodeIfNeeded(edges);
     }
 
+    public Iterator<Edge> edgesOfVertex(Id source, Steps steps) {
+        List<Id> edgeLabels = steps.edgeLabels();
+        ConditionQuery cq = GraphTransaction.constructEdgesQuery(
+                source, steps.direction(), edgeLabels);
+        cq.capacity(Query.NO_CAPACITY);
+        if (steps.limit() != NO_LIMIT) {
+            cq.limit(steps.limit());
+        }
+
+        Map<Id, ConditionQuery> edgeConditions =
+                getFilterQueryConditions(steps.edgeSteps(), HugeType.EDGE);
+
+        Iterator<Edge> filteredEdges =
+                new FilterIterator<>(this.graph().edges(cq),
+                                     edge -> validateEdge(edgeConditions, (HugeEdge) edge));
+
+        return edgesOfVertexStep(filteredEdges, steps);
+    }
+
+    protected Iterator<Edge> edgesOfVertexStep(Iterator<Edge> edges, Steps steps) {
+        if (steps.isVertexEmpty()) {
+            return edges;
+        }
+
+        Map<Id, ConditionQuery> vertexConditions =
+                getFilterQueryConditions(steps.vertexSteps(), HugeType.VERTEX);
+
+        return new FilterIterator<>(edges,
+                                    edge -> validateVertex(vertexConditions, (HugeEdge) edge));
+    }
+
+    private Boolean validateVertex(Map<Id, ConditionQuery> conditions,
+                                   HugeEdge edge) {
+        HugeVertex sourceV = edge.sourceVertex();
+        HugeVertex targetV = edge.targetVertex();
+        if (!conditions.containsKey(sourceV.schemaLabel().id()) ||
+            !conditions.containsKey(targetV.schemaLabel().id())) {
+            return false;
+        }
+
+        ConditionQuery cq = conditions.get(sourceV.schemaLabel().id());
+        if (cq != null) {
+            sourceV = (HugeVertex) this.graph.vertex(sourceV.id());
+            if (!cq.test(sourceV)) {
+                return false;
+            }
+        }
+
+        cq = conditions.get(targetV.schemaLabel().id());
+        if (cq != null) {
+            targetV = (HugeVertex) this.graph.vertex(targetV.id());
+            return cq.test(targetV);
+        }
+        return true;
+    }
+
+    private Boolean validateEdge(Map<Id, ConditionQuery> conditions,
+                                 HugeEdge edge) {
+        if (!conditions.containsKey(edge.schemaLabel().id())) {
+            return false;
+        }
+
+        ConditionQuery cq = conditions.get(edge.schemaLabel().id());
+        if (cq != null) {
+            return cq.test(edge);
+        }
+        return true;
+    }
+
+    private Map<Id, ConditionQuery> getFilterQueryConditions(
+            Map<Id, Steps.StepEntity> idStepEntityMap, HugeType type) {
+        Map<Id, ConditionQuery> conditions = new HashMap<>();
+        for (Map.Entry<Id, Steps.StepEntity> entry : idStepEntityMap.entrySet()) {

Review Comment:
   ```suggestion
           Map<Id, ConditionQuery> conditions = new HashMap<>();
   
           for (Map.Entry<Id, Steps.StepEntity> entry : idStepEntityMap.entrySet()) {
   ```



##########
hugegraph-core/src/main/java/org/apache/hugegraph/traversal/algorithm/HugeTraverser.java:
##########
@@ -513,6 +626,21 @@ protected void checkVertexExist(Id vertexId, String name) {
         }
     }
 
+    public Iterator<Edge> createNestedIterator(Id sourceV, Steps steps,
+                                               int depth, Set<Id> visited, boolean nearest) {
+        E.checkArgument(depth > 0,
+                        "The depth should large than 0 for nested iterator");
+
+        visited.add(sourceV);

Review Comment:
   ```suggestion
           E.checkArgument(depth > 0, "The depth should large than 0 for nested iterator");
           visited.add(sourceV);
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@hugegraph.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@hugegraph.apache.org
For additional commands, e-mail: issues-help@hugegraph.apache.org


[GitHub] [incubator-hugegraph] DanGuge commented on a diff in pull request #2295: feat(api&core): support label & property filtering for both edge and vertex & support kout dfs mode

Posted by "DanGuge (via GitHub)" <gi...@apache.org>.
DanGuge commented on code in PR #2295:
URL: https://github.com/apache/incubator-hugegraph/pull/2295#discussion_r1311764578


##########
hugegraph-core/src/main/java/org/apache/hugegraph/traversal/algorithm/HugeTraverser.java:
##########
@@ -85,6 +89,9 @@ public class HugeTraverser {
     // Empirical value of scan limit, with which results can be returned in 3s
     public static final String DEFAULT_PAGE_LIMIT = "100000";
     public static final long NO_LIMIT = -1L;
+    // algorithms
+    public static final String ALGORITHM_BFS = "breadth_first_search";

Review Comment:
   fixed



##########
hugegraph-core/src/main/java/org/apache/hugegraph/traversal/algorithm/HugeTraverser.java:
##########
@@ -85,6 +89,9 @@ public class HugeTraverser {
     // Empirical value of scan limit, with which results can be returned in 3s
     public static final String DEFAULT_PAGE_LIMIT = "100000";
     public static final long NO_LIMIT = -1L;
+    // algorithms

Review Comment:
   fixed



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@hugegraph.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@hugegraph.apache.org
For additional commands, e-mail: issues-help@hugegraph.apache.org


[GitHub] [incubator-hugegraph] javeme commented on a diff in pull request #2295: feat(api&core): support label & property filtering for both edge and vertex & support kout dfs mode

Posted by "javeme (via GitHub)" <gi...@apache.org>.
javeme commented on code in PR #2295:
URL: https://github.com/apache/incubator-hugegraph/pull/2295#discussion_r1310642023


##########
hugegraph-core/src/main/java/org/apache/hugegraph/backend/tx/GraphTransaction.java:
##########
@@ -1574,14 +1597,14 @@ private void checkNonnullProperty(HugeVertex vertex) {
         // Check whether passed all non-null property
         @SuppressWarnings("unchecked")
         Collection<Id> nonNullKeys = CollectionUtils.subtract(
-                                     vertexLabel.properties(),
-                                     vertexLabel.nullableKeys());
+                vertexLabel.properties(),
+                vertexLabel.nullableKeys());
         if (!keys.containsAll(nonNullKeys)) {
             @SuppressWarnings("unchecked")
             Collection<Id> missed = CollectionUtils.subtract(nonNullKeys, keys);
             HugeGraph graph = this.graph();
             E.checkArgument(false, "All non-null property keys %s of " +
-                            "vertex label '%s' must be set, missed keys %s",
+                                   "vertex label '%s' must be set, missed keys %s",

Review Comment:
   prefer to wrap line before "All non-null..."



##########
hugegraph-core/src/main/java/org/apache/hugegraph/traversal/algorithm/HugeTraverser.java:
##########
@@ -438,6 +465,92 @@ private Iterator<Edge> edgesOfVertex(Id source, EdgeStep edgeStep,
         return edgeStep.skipSuperNodeIfNeeded(edges);
     }
 
+    protected Iterator<Edge> edgesOfVertex(Id source, Steps steps) {
+        List<Id> edgeLabels = steps.edgeLabels();
+        ConditionQuery cq = GraphTransaction.constructEdgesQuery(
+                source, steps.direction(), edgeLabels);
+        cq.capacity(Query.NO_CAPACITY);
+        if (steps.limit() != NO_LIMIT) {
+            cq.limit(steps.limit());
+        }
+
+        Map<Id, ConditionQuery> edgeConditions =
+                getElementFilterQuery(steps.edgeSteps(), HugeType.EDGE);
+
+        Iterator<Edge> filteredEdges =
+                new FilterIterator<>(this.graph().edges(cq),
+                                     edge -> validateEdge(edgeConditions, (HugeEdge) edge));
+
+        return edgesOfVertexStep(filteredEdges, steps);
+    }
+
+    protected Iterator<Edge> edgesOfVertexStep(Iterator<Edge> edges, Steps steps) {
+        if (steps.isVertexEmpty()) {
+            return edges;
+        }
+
+        Map<Id, ConditionQuery> vertexConditions =
+                getElementFilterQuery(steps.vertexSteps(), HugeType.VERTEX);
+
+        return new FilterIterator<>(edges,
+                                    edge -> validateVertex(vertexConditions, (HugeEdge) edge));
+    }
+
+    private Boolean validateVertex(Map<Id, ConditionQuery> vConditions,
+                                   HugeEdge edge) {
+        HugeVertex sourceV = edge.sourceVertex();
+        HugeVertex targetV = edge.targetVertex();
+        if (!vConditions.containsKey(sourceV.schemaLabel().id()) ||
+            !vConditions.containsKey(targetV.schemaLabel().id())) {
+            return false;
+        }
+
+        ConditionQuery cq = vConditions.get(sourceV.schemaLabel().id());
+        if (cq != null) {
+            sourceV = (HugeVertex) this.graph.vertex(sourceV.id());
+            if (!cq.test(sourceV)) {
+                return false;
+            }
+        }
+
+        cq = vConditions.get(targetV.schemaLabel().id());
+        if (cq != null) {
+            targetV = (HugeVertex) this.graph.vertex(targetV.id());
+            return cq.test(targetV);
+        }
+        return true;
+    }
+
+    private Boolean validateEdge(Map<Id, ConditionQuery> eConditions,

Review Comment:
   ditto



##########
hugegraph-core/src/main/java/org/apache/hugegraph/traversal/algorithm/HugeTraverser.java:
##########
@@ -438,6 +465,92 @@ private Iterator<Edge> edgesOfVertex(Id source, EdgeStep edgeStep,
         return edgeStep.skipSuperNodeIfNeeded(edges);
     }
 
+    protected Iterator<Edge> edgesOfVertex(Id source, Steps steps) {
+        List<Id> edgeLabels = steps.edgeLabels();
+        ConditionQuery cq = GraphTransaction.constructEdgesQuery(
+                source, steps.direction(), edgeLabels);
+        cq.capacity(Query.NO_CAPACITY);
+        if (steps.limit() != NO_LIMIT) {
+            cq.limit(steps.limit());
+        }
+
+        Map<Id, ConditionQuery> edgeConditions =
+                getElementFilterQuery(steps.edgeSteps(), HugeType.EDGE);
+
+        Iterator<Edge> filteredEdges =
+                new FilterIterator<>(this.graph().edges(cq),
+                                     edge -> validateEdge(edgeConditions, (HugeEdge) edge));
+
+        return edgesOfVertexStep(filteredEdges, steps);
+    }
+
+    protected Iterator<Edge> edgesOfVertexStep(Iterator<Edge> edges, Steps steps) {
+        if (steps.isVertexEmpty()) {
+            return edges;
+        }
+
+        Map<Id, ConditionQuery> vertexConditions =
+                getElementFilterQuery(steps.vertexSteps(), HugeType.VERTEX);
+
+        return new FilterIterator<>(edges,
+                                    edge -> validateVertex(vertexConditions, (HugeEdge) edge));
+    }
+
+    private Boolean validateVertex(Map<Id, ConditionQuery> vConditions,
+                                   HugeEdge edge) {
+        HugeVertex sourceV = edge.sourceVertex();
+        HugeVertex targetV = edge.targetVertex();
+        if (!vConditions.containsKey(sourceV.schemaLabel().id()) ||
+            !vConditions.containsKey(targetV.schemaLabel().id())) {
+            return false;
+        }
+
+        ConditionQuery cq = vConditions.get(sourceV.schemaLabel().id());
+        if (cq != null) {
+            sourceV = (HugeVertex) this.graph.vertex(sourceV.id());
+            if (!cq.test(sourceV)) {
+                return false;
+            }
+        }
+
+        cq = vConditions.get(targetV.schemaLabel().id());
+        if (cq != null) {
+            targetV = (HugeVertex) this.graph.vertex(targetV.id());
+            return cq.test(targetV);
+        }
+        return true;
+    }
+
+    private Boolean validateEdge(Map<Id, ConditionQuery> eConditions,
+                                 HugeEdge edge) {
+        if (!eConditions.containsKey(edge.schemaLabel().id())) {
+            return false;
+        }
+
+        ConditionQuery cq = eConditions.get(edge.schemaLabel().id());
+        if (cq != null) {
+            return cq.test(edge);
+        }
+        return true;
+    }
+
+    private Map<Id, ConditionQuery> getElementFilterQuery(

Review Comment:
   prefer to rename to getFilterQueryConditions



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@hugegraph.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@hugegraph.apache.org
For additional commands, e-mail: issues-help@hugegraph.apache.org


[GitHub] [incubator-hugegraph] imbajin commented on a diff in pull request #2295: feat(api&core): support label & property filtering for both edge and vertex & support kout dfs mode

Posted by "imbajin (via GitHub)" <gi...@apache.org>.
imbajin commented on code in PR #2295:
URL: https://github.com/apache/incubator-hugegraph/pull/2295#discussion_r1312517504


##########
hugegraph-core/src/main/java/org/apache/hugegraph/traversal/algorithm/KoutTraverser.java:
##########
@@ -138,6 +138,38 @@ public KoutRecords customizedKout(Id source, EdgeStep step,
         return records;
     }
 
+    public KoutRecords DFSKout(Id source, Steps steps,
+                               int maxDepth, boolean nearest,
+                               long capacity, long limit) {
+        E.checkNotNull(source, "source vertex id");
+        this.checkVertexExist(source, "source vertex");
+        checkPositive(maxDepth, "k-out max_depth");

Review Comment:
   > I am not sure, so should we add `this.` keyword?
   > 
   > I checked other traverser implementations and they didn't add `this.` keyword, such as PathsTraverser.java, SameNeighborTraverser.java and so on.
   
   seems if `checkPositive` is a static method, we shouldn't add `this` for it



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@hugegraph.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@hugegraph.apache.org
For additional commands, e-mail: issues-help@hugegraph.apache.org


[GitHub] [incubator-hugegraph] DanGuge commented on a diff in pull request #2295: feat(api&core): support label & property filtering for both edge and vertex & support kout dfs mode

Posted by "DanGuge (via GitHub)" <gi...@apache.org>.
DanGuge commented on code in PR #2295:
URL: https://github.com/apache/incubator-hugegraph/pull/2295#discussion_r1311578871


##########
hugegraph-core/src/main/java/org/apache/hugegraph/traversal/optimize/TraversalUtil.java:
##########
@@ -625,8 +626,8 @@ public static void convAllHasSteps(Traversal.Admin<?, ?> traversal) {
         // Extract all has steps in traversal
         @SuppressWarnings("rawtypes")
         List<HasStep> steps =
-                      TraversalHelper.getStepsOfAssignableClassRecursively(
-                      HasStep.class, traversal);
+                TraversalHelper.getStepsOfAssignableClassRecursively(
+                        HasStep.class, traversal);

Review Comment:
   fixed



##########
hugegraph-core/src/main/java/org/apache/hugegraph/backend/query/Query.java:
##########
@@ -50,7 +50,7 @@ public class Query implements Cloneable {
     public static final long NO_CAPACITY = -1L;
     public static final long DEFAULT_CAPACITY = 800000L; // HugeGraph-777
 
-    private static final ThreadLocal<Long> CAPACITY_CONTEXT = new ThreadLocal<>();
+    protected static final ThreadLocal<Long> CAPACITY_CONTEXT = new ThreadLocal<>();

Review Comment:
   fixed



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@hugegraph.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@hugegraph.apache.org
For additional commands, e-mail: issues-help@hugegraph.apache.org


[GitHub] [incubator-hugegraph] DanGuge commented on a diff in pull request #2295: feat(api&core): support label & property filtering for both edge and vertex & support kout dfs mode

Posted by "DanGuge (via GitHub)" <gi...@apache.org>.
DanGuge commented on code in PR #2295:
URL: https://github.com/apache/incubator-hugegraph/pull/2295#discussion_r1311764213


##########
hugegraph-core/src/main/java/org/apache/hugegraph/backend/tx/GraphTransaction.java:
##########
@@ -1608,11 +1639,11 @@ private void checkVertexExistIfCustomizedId(Map<Id, HugeVertex> vertices) {
             HugeVertex newVertex = vertices.get(existedVertex.id());
             if (!existedVertex.label().equals(newVertex.label())) {
                 throw new HugeException(
-                          "The newly added vertex with id:'%s' label:'%s' " +
-                          "is not allowed to insert, because already exist " +
-                          "a vertex with same id and different label:'%s'",
-                          newVertex.id(), newVertex.label(),
-                          existedVertex.label());
+                        "The newly added vertex with id:'%s' label:'%s' " +
+                        "is not allowed to insert, because already exist " +
+                        "a vertex with same id and different label:'%s'",
+                        newVertex.id(), newVertex.label(),
+                        existedVertex.label());

Review Comment:
   fixed



##########
hugegraph-core/src/main/java/org/apache/hugegraph/backend/tx/GraphTransaction.java:
##########
@@ -1753,7 +1784,7 @@ private boolean rightResultFromIndexQuery(Query query, HugeElement elem) {
     }
 
     private <T extends HugeElement> Iterator<T> filterExpiredResultFromBackend(
-                                    Query query, Iterator<T> results) {
+            Query query, Iterator<T> results) {

Review Comment:
   fixed



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@hugegraph.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@hugegraph.apache.org
For additional commands, e-mail: issues-help@hugegraph.apache.org


[GitHub] [incubator-hugegraph] DanGuge commented on a diff in pull request #2295: feat(api&core): support label & property filtering for both edge and vertex & support kout dfs mode

Posted by "DanGuge (via GitHub)" <gi...@apache.org>.
DanGuge commented on code in PR #2295:
URL: https://github.com/apache/incubator-hugegraph/pull/2295#discussion_r1311764832


##########
hugegraph-core/src/main/java/org/apache/hugegraph/traversal/algorithm/HugeTraverser.java:
##########
@@ -164,6 +171,17 @@ public static void checkSkipDegree(long skipDegree, long degree,
         }
     }
 
+    public static void checkAlgorithm(String algorithm) {

Review Comment:
   fixed



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@hugegraph.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@hugegraph.apache.org
For additional commands, e-mail: issues-help@hugegraph.apache.org


[GitHub] [incubator-hugegraph] DanGuge commented on a diff in pull request #2295: feat(api&core): support label & property filtering for both edge and vertex & support kout dfs mode

Posted by "DanGuge (via GitHub)" <gi...@apache.org>.
DanGuge commented on code in PR #2295:
URL: https://github.com/apache/incubator-hugegraph/pull/2295#discussion_r1320469832


##########
hugegraph-core/src/main/java/org/apache/hugegraph/traversal/algorithm/steps/Steps.java:
##########
@@ -0,0 +1,186 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with this
+ * work for additional information regarding copyright ownership. The ASF
+ * licenses this file to You under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.hugegraph.traversal.algorithm.steps;
+
+import static org.apache.hugegraph.traversal.algorithm.HugeTraverser.NO_LIMIT;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.hugegraph.HugeGraph;
+import org.apache.hugegraph.backend.id.Id;
+import org.apache.hugegraph.schema.EdgeLabel;
+import org.apache.hugegraph.schema.VertexLabel;
+import org.apache.hugegraph.traversal.algorithm.HugeTraverser;
+import org.apache.hugegraph.traversal.optimize.TraversalUtil;
+import org.apache.hugegraph.type.define.Directions;
+import org.apache.hugegraph.util.E;
+
+public class Steps {
+
+    protected final Map<Id, StepEntity> edgeSteps;
+    protected final Map<Id, StepEntity> vertexSteps;
+    protected final Directions direction;
+    protected final long degree;
+    protected final long skipDegree;
+
+    public Steps(HugeGraph graph, Directions direction,
+                 Map<String, Map<String, Object>> vSteps,
+                 Map<String, Map<String, Object>> eSteps,
+                 long degree, long skipDegree) {
+        E.checkArgument(degree == NO_LIMIT || degree > 0L,
+                        "The max degree must be > 0 or == -1, but got: %s", degree);
+        HugeTraverser.checkSkipDegree(skipDegree, degree, NO_LIMIT);
+
+        this.direction = direction;
+
+        // parse vertex steps
+        this.vertexSteps = new HashMap<>();
+        if (vSteps != null && !vSteps.isEmpty()) {
+            initVertexFilter(graph, vSteps);
+        }
+
+        // parse edge steps
+        this.edgeSteps = new HashMap<>();
+        if (eSteps != null && !eSteps.isEmpty()) {
+            initEdgeFilter(graph, eSteps);
+        }
+
+        this.degree = degree;
+        this.skipDegree = skipDegree;
+    }
+
+    private void initVertexFilter(HugeGraph graph, Map<String, Map<String, Object>> vSteps) {
+        for (Map.Entry<String, Map<String, Object>> entry : vSteps.entrySet()) {
+            if (checkEntryEmpty(entry)) {
+                continue;
+            }
+            E.checkArgument(entry.getKey() != null && !entry.getKey().isEmpty(),
+                            "The vertex step label could not be null");
+
+            VertexLabel vertexLabel = graph.vertexLabel(entry.getKey());
+            StepEntity stepEntity = handleStepEntity(graph, entry, vertexLabel.id());
+            this.vertexSteps.put(vertexLabel.id(), stepEntity);
+        }
+    }
+
+    private void initEdgeFilter(HugeGraph graph, Map<String, Map<String, Object>> eSteps) {
+        for (Map.Entry<String, Map<String, Object>> entry : eSteps.entrySet()) {
+            if (checkEntryEmpty(entry)) {
+                continue;
+            }
+            E.checkArgument(entry.getKey() != null && !entry.getKey().isEmpty(),
+                            "The edge step label could not be null");
+
+            EdgeLabel edgeLabel = graph.edgeLabel(entry.getKey());
+            StepEntity stepEntity = handleStepEntity(graph, entry, edgeLabel.id());
+            this.edgeSteps.put(edgeLabel.id(), stepEntity);
+        }
+    }
+
+    private StepEntity handleStepEntity(HugeGraph graph,
+                                        Map.Entry<String, Map<String, Object>> entry,
+                                        Id id) {
+        Map<Id, Object> properties = null;
+        if (entry.getValue() != null) {
+            properties = TraversalUtil.transProperties(graph, entry.getValue());
+        }
+        return new StepEntity(id, entry.getKey(), properties);
+    }
+
+    private boolean checkEntryEmpty(Map.Entry<String, Map<String, Object>> entry) {
+        return (entry.getKey() == null || entry.getKey().isEmpty()) &&
+               (entry.getValue() == null || entry.getValue().isEmpty());
+    }
+
+    public long degree() {
+        return degree;

Review Comment:
   fixed



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@hugegraph.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@hugegraph.apache.org
For additional commands, e-mail: issues-help@hugegraph.apache.org


[GitHub] [incubator-hugegraph] codecov[bot] commented on pull request #2295: feat(api&core): support label & property filtering for both edge and vertex & support kout dfs mode

Posted by "codecov[bot] (via GitHub)" <gi...@apache.org>.
codecov[bot] commented on PR #2295:
URL: https://github.com/apache/incubator-hugegraph/pull/2295#issuecomment-1692854493

   ## [Codecov](https://app.codecov.io/gh/apache/incubator-hugegraph/pull/2295?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) Report
   > Merging [#2295](https://app.codecov.io/gh/apache/incubator-hugegraph/pull/2295?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) (2cbc170) into [master](https://app.codecov.io/gh/apache/incubator-hugegraph/commit/4d7ad86776482900ef75406760b6a6391ef08781?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) (4d7ad86) will **decrease** coverage by `15.72%`.
   > The diff coverage is `40.58%`.
   
   > :exclamation: Current head 2cbc170 differs from pull request most recent head 8662451. Consider uploading reports for the commit 8662451 to get more accurate results
   
   ```diff
   @@              Coverage Diff              @@
   ##             master    #2295       +/-   ##
   =============================================
   - Coverage     65.07%   49.35%   -15.72%     
   + Complexity      979      662      -317     
   =============================================
     Files           498      499        +1     
     Lines         41240    41513      +273     
     Branches       5738     5789       +51     
   =============================================
   - Hits          26837    20490     -6347     
   - Misses        11743    18830     +7087     
   + Partials       2660     2193      -467     
   ```
   
   
   | [Files Changed](https://app.codecov.io/gh/apache/incubator-hugegraph/pull/2295?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Coverage Δ | |
   |---|---|---|
   | [...e/hugegraph/traversal/algorithm/KoutTraverser.java](https://app.codecov.io/gh/apache/incubator-hugegraph/pull/2295?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-aHVnZWdyYXBoLWNvcmUvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL2h1Z2VncmFwaC90cmF2ZXJzYWwvYWxnb3JpdGhtL0tvdXRUcmF2ZXJzZXIuamF2YQ==) | `57.14% <9.09%> (-16.10%)` | :arrow_down: |
   | [...graph/traversal/algorithm/records/KoutRecords.java](https://app.codecov.io/gh/apache/incubator-hugegraph/pull/2295?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-aHVnZWdyYXBoLWNvcmUvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL2h1Z2VncmFwaC90cmF2ZXJzYWwvYWxnb3JpdGhtL3JlY29yZHMvS291dFJlY29yZHMuamF2YQ==) | `42.85% <10.00%> (-42.86%)` | :arrow_down: |
   | [...e/hugegraph/traversal/algorithm/HugeTraverser.java](https://app.codecov.io/gh/apache/incubator-hugegraph/pull/2295?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-aHVnZWdyYXBoLWNvcmUvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL2h1Z2VncmFwaC90cmF2ZXJzYWwvYWxnb3JpdGhtL0h1Z2VUcmF2ZXJzZXIuamF2YQ==) | `50.59% <17.73%> (-12.84%)` | :arrow_down: |
   | [...he/hugegraph/traversal/optimize/TraversalUtil.java](https://app.codecov.io/gh/apache/incubator-hugegraph/pull/2295?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-aHVnZWdyYXBoLWNvcmUvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL2h1Z2VncmFwaC90cmF2ZXJzYWwvb3B0aW1pemUvVHJhdmVyc2FsVXRpbC5qYXZh) | `48.73% <33.33%> (-10.68%)` | :arrow_down: |
   | [...a/org/apache/hugegraph/api/traversers/KoutAPI.java](https://app.codecov.io/gh/apache/incubator-hugegraph/pull/2295?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-aHVnZWdyYXBoLWFwaS9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvaHVnZWdyYXBoL2FwaS90cmF2ZXJzZXJzL0tvdXRBUEkuamF2YQ==) | `67.46% <38.46%> (-0.89%)` | :arrow_down: |
   | [...che/hugegraph/traversal/algorithm/steps/Steps.java](https://app.codecov.io/gh/apache/incubator-hugegraph/pull/2295?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-aHVnZWdyYXBoLWNvcmUvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL2h1Z2VncmFwaC90cmF2ZXJzYWwvYWxnb3JpdGhtL3N0ZXBzL1N0ZXBzLmphdmE=) | `51.78% <51.78%> (ø)` | |
   | [.../apache/hugegraph/api/traversers/TraverserAPI.java](https://app.codecov.io/gh/apache/incubator-hugegraph/pull/2295?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-aHVnZWdyYXBoLWFwaS9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvaHVnZWdyYXBoL2FwaS90cmF2ZXJzZXJzL1RyYXZlcnNlckFQSS5qYXZh) | `60.71% <55.00%> (-14.29%)` | :arrow_down: |
   | [.../apache/hugegraph/api/traversers/KneighborAPI.java](https://app.codecov.io/gh/apache/incubator-hugegraph/pull/2295?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-aHVnZWdyYXBoLWFwaS9zcmMvbWFpbi9qYXZhL29yZy9hcGFjaGUvaHVnZWdyYXBoL2FwaS90cmF2ZXJzZXJzL0tuZWlnaGJvckFQSS5qYXZh) | `67.56% <60.00%> (ø)` | |
   | [.../apache/hugegraph/backend/tx/GraphTransaction.java](https://app.codecov.io/gh/apache/incubator-hugegraph/pull/2295?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-aHVnZWdyYXBoLWNvcmUvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL2h1Z2VncmFwaC9iYWNrZW5kL3R4L0dyYXBoVHJhbnNhY3Rpb24uamF2YQ==) | `74.18% <68.18%> (-5.50%)` | :arrow_down: |
   | [...java/org/apache/hugegraph/backend/query/Query.java](https://app.codecov.io/gh/apache/incubator-hugegraph/pull/2295?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-aHVnZWdyYXBoLWNvcmUvc3JjL21haW4vamF2YS9vcmcvYXBhY2hlL2h1Z2VncmFwaC9iYWNrZW5kL3F1ZXJ5L1F1ZXJ5LmphdmE=) | `78.26% <72.72%> (-8.31%)` | :arrow_down: |
   | ... and [2 more](https://app.codecov.io/gh/apache/incubator-hugegraph/pull/2295?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | |
   
   ... and [152 files with indirect coverage changes](https://app.codecov.io/gh/apache/incubator-hugegraph/pull/2295/indirect-changes?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)
   
   :mega: We’re building smart automated test selection to slash your CI/CD build times. [Learn more](https://about.codecov.io/iterative-testing/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@hugegraph.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@hugegraph.apache.org
For additional commands, e-mail: issues-help@hugegraph.apache.org


[GitHub] [incubator-hugegraph] DanGuge commented on a diff in pull request #2295: feat(api&core): support label & property filtering for both edge and vertex & support kout dfs mode

Posted by "DanGuge (via GitHub)" <gi...@apache.org>.
DanGuge commented on code in PR #2295:
URL: https://github.com/apache/incubator-hugegraph/pull/2295#discussion_r1311763688


##########
hugegraph-core/src/main/java/org/apache/hugegraph/backend/tx/GraphTransaction.java:
##########
@@ -1018,9 +1211,7 @@ protected Iterator<HugeEdge> queryEdgesFromBackend(Query query) {
             if (vertex == null) {
                 return null;
             }
-            if (query.idsSize() == 1) {
-                assert vertex.getEdges().size() == 1;
-            }
+            assert query.idsSize() != 1 || vertex.getEdges().size() == 1;

Review Comment:
   fixed



##########
hugegraph-core/src/main/java/org/apache/hugegraph/backend/tx/GraphTransaction.java:
##########
@@ -171,6 +171,199 @@ public GraphTransaction(HugeGraphParams graph, BackendStore store) {
                         this.edgesCapacity);
     }
 
+    /**
+     * Construct one edge condition query based on source vertex, direction and
+     * edge labels
+     *
+     * @param sourceVertex source vertex of edge
+     * @param direction    only be "IN", "OUT" or "BOTH"
+     * @param edgeLabels   edge labels of queried edges
+     * @return constructed condition query
+     */
+    @Watched
+    public static ConditionQuery constructEdgesQuery(Id sourceVertex,
+                                                     Directions direction,
+                                                     Id... edgeLabels) {
+        E.checkState(sourceVertex != null,
+                     "The edge query must contain source vertex");
+        E.checkState(direction != null,
+                     "The edge query must contain direction");
+
+        ConditionQuery query = new ConditionQuery(HugeType.EDGE);
+
+        // Edge source vertex
+        query.eq(HugeKeys.OWNER_VERTEX, sourceVertex);
+
+        // Edge direction
+        if (direction == Directions.BOTH) {
+            query.query(Condition.or(
+                    Condition.eq(HugeKeys.DIRECTION, Directions.OUT),
+                    Condition.eq(HugeKeys.DIRECTION, Directions.IN)));
+        } else {
+            assert direction == Directions.OUT || direction == Directions.IN;
+            query.eq(HugeKeys.DIRECTION, direction);
+        }
+
+        // Edge labels
+        if (edgeLabels.length == 1) {
+            query.eq(HugeKeys.LABEL, edgeLabels[0]);
+        } else if (edgeLabels.length > 1) {
+            query.query(Condition.in(HugeKeys.LABEL,
+                                     Arrays.asList(edgeLabels)));
+        }
+
+        return query;
+    }
+
+    public static ConditionQuery constructEdgesQuery(Id sourceVertex,
+                                                     Directions direction,
+                                                     List<Id> edgeLabels) {
+        E.checkState(sourceVertex != null,
+                     "The edge query must contain source vertex");
+        E.checkState(direction != null,
+                     "The edge query must contain direction");
+
+        ConditionQuery query = new ConditionQuery(HugeType.EDGE);
+
+        // Edge source vertex
+        query.eq(HugeKeys.OWNER_VERTEX, sourceVertex);
+
+        // Edge direction
+        if (direction == Directions.BOTH) {
+            query.query(Condition.or(
+                    Condition.eq(HugeKeys.DIRECTION, Directions.OUT),
+                    Condition.eq(HugeKeys.DIRECTION, Directions.IN)));
+        } else {
+            assert direction == Directions.OUT || direction == Directions.IN;
+            query.eq(HugeKeys.DIRECTION, direction);
+        }
+
+        // Edge labels
+        if (edgeLabels.size() == 1) {
+            query.eq(HugeKeys.LABEL, edgeLabels.get(0));
+        } else if (edgeLabels.size() > 1) {
+            query.query(Condition.in(HugeKeys.LABEL, edgeLabels));
+        }
+
+        return query;
+    }
+
+    public static boolean matchFullEdgeSortKeys(ConditionQuery query,
+                                                HugeGraph graph) {
+        // All queryKeys in sortKeys
+        return matchEdgeSortKeys(query, true, graph);
+    }
+
+    public static boolean matchPartialEdgeSortKeys(ConditionQuery query,
+                                                   HugeGraph graph) {
+        // Partial queryKeys in sortKeys
+        return matchEdgeSortKeys(query, false, graph);
+    }
+
+    private static boolean matchEdgeSortKeys(ConditionQuery query,
+                                             boolean matchAll,
+                                             HugeGraph graph) {
+        assert query.resultType().isEdge();
+        Id label = query.condition(HugeKeys.LABEL);
+        if (label == null) {
+            return false;
+        }
+        List<Id> sortKeys = graph.edgeLabel(label).sortKeys();
+        if (sortKeys.isEmpty()) {
+            return false;
+        }
+        Set<Id> queryKeys = query.userpropKeys();
+        for (int i = sortKeys.size(); i > 0; i--) {
+            List<Id> subFields = sortKeys.subList(0, i);
+            if (queryKeys.containsAll(subFields)) {
+                if (queryKeys.size() == subFields.size() || !matchAll) {
+                    /*
+                     * Return true if:
+                     * matchAll=true and all queryKeys are in sortKeys
+                     *  or
+                     * partial queryKeys are in sortKeys
+                     */
+                    return true;
+                }
+            }
+        }
+        return false;
+    }
+
+    private static void verifyVerticesConditionQuery(ConditionQuery query) {
+        assert query.resultType().isVertex();
+
+        int total = query.conditionsSize();
+        if (total == 1) {
+            /*
+             * Supported query:
+             *  1.query just by vertex label
+             *  2.query just by PROPERTIES (like containsKey,containsValue)
+             *  3.query with scan
+             */
+            if (query.containsCondition(HugeKeys.LABEL) ||
+                query.containsCondition(HugeKeys.PROPERTIES) ||
+                query.containsScanRelation()) {
+                return;
+            }
+        }
+
+        int matched = 0;
+        if (query.containsCondition(HugeKeys.PROPERTIES)) {
+            matched++;
+            if (query.containsCondition(HugeKeys.LABEL)) {
+                matched++;
+            }
+        }
+
+        if (matched != total) {
+            throw new HugeException("Not supported querying vertices by %s",
+                                    query.conditions());
+        }
+    }
+
+    private static void verifyEdgesConditionQuery(ConditionQuery query) {
+        assert query.resultType().isEdge();
+
+        int total = query.conditionsSize();
+        if (total == 1) {
+            /*
+             * Supported query:
+             *  1.query just by edge label
+             *  2.query just by PROPERTIES (like containsKey,containsValue)
+             *  3.query with scan
+             */
+            if (query.containsCondition(HugeKeys.LABEL) ||
+                query.containsCondition(HugeKeys.PROPERTIES) ||
+                query.containsScanRelation()) {
+                return;
+            }
+        }
+
+        int matched = 0;
+        for (HugeKeys key : EdgeId.KEYS) {
+            Object value = query.condition(key);
+            if (value == null) {
+                break;
+            }
+            matched++;
+        }
+        int count = matched;
+
+        if (query.containsCondition(HugeKeys.PROPERTIES)) {
+            matched++;
+            if (count < 3 && query.containsCondition(HugeKeys.LABEL)) {
+                matched++;
+            }
+        }
+
+        if (matched != total) {
+            throw new HugeException(
+                    "Not supported querying edges by %s, expect %s",
+                    query.conditions(), EdgeId.KEYS[count]);
+        }
+    }
+

Review Comment:
   fixed



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@hugegraph.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@hugegraph.apache.org
For additional commands, e-mail: issues-help@hugegraph.apache.org


[GitHub] [incubator-hugegraph] DanGuge commented on a diff in pull request #2295: feat(api&core): support label & property filtering for both edge and vertex & support kout dfs mode

Posted by "DanGuge (via GitHub)" <gi...@apache.org>.
DanGuge commented on code in PR #2295:
URL: https://github.com/apache/incubator-hugegraph/pull/2295#discussion_r1311593486


##########
hugegraph-core/src/main/java/org/apache/hugegraph/traversal/algorithm/KoutTraverser.java:
##########
@@ -138,6 +138,38 @@ public KoutRecords customizedKout(Id source, EdgeStep step,
         return records;
     }
 
+    public KoutRecords DFSKout(Id source, Steps steps,
+                               int maxDepth, boolean nearest,
+                               long capacity, long limit) {
+        E.checkNotNull(source, "source vertex id");
+        this.checkVertexExist(source, "source vertex");
+        checkPositive(maxDepth, "k-out max_depth");

Review Comment:
   The difference between these two `check` method is that `checkPositive()` is a static method while `checkVertexExist()` is not.
   
   According to stackoverflow, `this` refers to the object instance and there is no object instance in a call of a static method.
   
   stackoverflow: https://stackoverflow.com/questions/11664522/why-cant-we-use-this-keyword-in-a-static-method



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@hugegraph.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@hugegraph.apache.org
For additional commands, e-mail: issues-help@hugegraph.apache.org


[GitHub] [incubator-hugegraph] javeme commented on a diff in pull request #2295: feat(api&core): support label & property filtering for both edge and vertex & support kout dfs mode

Posted by "javeme (via GitHub)" <gi...@apache.org>.
javeme commented on code in PR #2295:
URL: https://github.com/apache/incubator-hugegraph/pull/2295#discussion_r1310641844


##########
hugegraph-core/src/main/java/org/apache/hugegraph/backend/tx/GraphTransaction.java:
##########
@@ -1574,14 +1597,14 @@ private void checkNonnullProperty(HugeVertex vertex) {
         // Check whether passed all non-null property
         @SuppressWarnings("unchecked")
         Collection<Id> nonNullKeys = CollectionUtils.subtract(
-                                     vertexLabel.properties(),
-                                     vertexLabel.nullableKeys());
+                vertexLabel.properties(),
+                vertexLabel.nullableKeys());

Review Comment:
   can we keep the origin code style



##########
hugegraph-core/src/main/java/org/apache/hugegraph/traversal/algorithm/HugeTraverser.java:
##########
@@ -438,6 +465,92 @@ private Iterator<Edge> edgesOfVertex(Id source, EdgeStep edgeStep,
         return edgeStep.skipSuperNodeIfNeeded(edges);
     }
 
+    protected Iterator<Edge> edgesOfVertex(Id source, Steps steps) {
+        List<Id> edgeLabels = steps.edgeLabels();
+        ConditionQuery cq = GraphTransaction.constructEdgesQuery(
+                source, steps.direction(), edgeLabels);
+        cq.capacity(Query.NO_CAPACITY);
+        if (steps.limit() != NO_LIMIT) {
+            cq.limit(steps.limit());
+        }
+
+        Map<Id, ConditionQuery> edgeConditions =
+                getElementFilterQuery(steps.edgeSteps(), HugeType.EDGE);
+
+        Iterator<Edge> filteredEdges =
+                new FilterIterator<>(this.graph().edges(cq),
+                                     edge -> validateEdge(edgeConditions, (HugeEdge) edge));
+
+        return edgesOfVertexStep(filteredEdges, steps);
+    }
+
+    protected Iterator<Edge> edgesOfVertexStep(Iterator<Edge> edges, Steps steps) {
+        if (steps.isVertexEmpty()) {
+            return edges;
+        }
+
+        Map<Id, ConditionQuery> vertexConditions =
+                getElementFilterQuery(steps.vertexSteps(), HugeType.VERTEX);
+
+        return new FilterIterator<>(edges,
+                                    edge -> validateVertex(vertexConditions, (HugeEdge) edge));
+    }
+
+    private Boolean validateVertex(Map<Id, ConditionQuery> vConditions,

Review Comment:
   rename vConditions to conditions?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@hugegraph.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@hugegraph.apache.org
For additional commands, e-mail: issues-help@hugegraph.apache.org


[GitHub] [incubator-hugegraph] javeme commented on a diff in pull request #2295: feat(api&core): support label & property filtering for both edge and vertex & support kout dfs mode

Posted by "javeme (via GitHub)" <gi...@apache.org>.
javeme commented on code in PR #2295:
URL: https://github.com/apache/incubator-hugegraph/pull/2295#discussion_r1310632443


##########
hugegraph-core/src/main/java/org/apache/hugegraph/backend/query/Query.java:
##########
@@ -560,25 +580,6 @@ public String toString() {
         return sb.toString();
     }
 
-    public static long defaultCapacity(long capacity) {
-        Long old = CAPACITY_CONTEXT.get();
-        CAPACITY_CONTEXT.set(capacity);
-        return old != null ? old : DEFAULT_CAPACITY;
-    }
-
-    public static long defaultCapacity() {
-        Long capacity = CAPACITY_CONTEXT.get();
-        return capacity != null ? capacity : DEFAULT_CAPACITY;
-    }
-
-    public static void checkForceCapacity(long count) throws LimitExceedException {
-        if (count > Query.DEFAULT_CAPACITY) {
-            throw new LimitExceedException(
-                      "Too many records(must <= %s) for one query",
-                      Query.DEFAULT_CAPACITY);
-        }
-    }
-

Review Comment:
   prefer to keep these methods



##########
hugegraph-core/src/main/java/org/apache/hugegraph/backend/query/Query.java:
##########
@@ -50,7 +50,7 @@ public class Query implements Cloneable {
     public static final long NO_CAPACITY = -1L;
     public static final long DEFAULT_CAPACITY = 800000L; // HugeGraph-777
 
-    private static final ThreadLocal<Long> CAPACITY_CONTEXT = new ThreadLocal<>();
+    protected static final ThreadLocal<Long> CAPACITY_CONTEXT = new ThreadLocal<>();

Review Comment:
   it does not expect to be accessed by others classes



##########
hugegraph-core/src/main/java/org/apache/hugegraph/traversal/optimize/TraversalUtil.java:
##########
@@ -625,8 +626,8 @@ public static void convAllHasSteps(Traversal.Admin<?, ?> traversal) {
         // Extract all has steps in traversal
         @SuppressWarnings("rawtypes")
         List<HasStep> steps =
-                      TraversalHelper.getStepsOfAssignableClassRecursively(
-                      HasStep.class, traversal);
+                TraversalHelper.getStepsOfAssignableClassRecursively(
+                        HasStep.class, traversal);

Review Comment:
   prefer to keep the origin code style



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@hugegraph.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@hugegraph.apache.org
For additional commands, e-mail: issues-help@hugegraph.apache.org


[GitHub] [incubator-hugegraph] javeme commented on a diff in pull request #2295: feat(api&core): support label & property filtering for both edge and vertex & support kout dfs mode

Posted by "javeme (via GitHub)" <gi...@apache.org>.
javeme commented on code in PR #2295:
URL: https://github.com/apache/incubator-hugegraph/pull/2295#discussion_r1310649907


##########
hugegraph-core/src/main/java/org/apache/hugegraph/traversal/algorithm/KoutTraverser.java:
##########
@@ -138,6 +138,38 @@ public KoutRecords customizedKout(Id source, EdgeStep step,
         return records;
     }
 
+    public KoutRecords DFSKout(Id source, Steps steps,
+                               int maxDepth, boolean nearest,
+                               long capacity, long limit) {
+        E.checkNotNull(source, "source vertex id");
+        this.checkVertexExist(source, "source vertex");
+        checkPositive(maxDepth, "k-out max_depth");

Review Comment:
   "this." -- keep the same styles



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@hugegraph.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@hugegraph.apache.org
For additional commands, e-mail: issues-help@hugegraph.apache.org


[GitHub] [incubator-hugegraph] DanGuge commented on a diff in pull request #2295: feat(api&core): support label & property filtering for both edge and vertex & support kout dfs mode

Posted by "DanGuge (via GitHub)" <gi...@apache.org>.
DanGuge commented on code in PR #2295:
URL: https://github.com/apache/incubator-hugegraph/pull/2295#discussion_r1311576441


##########
hugegraph-core/src/main/java/org/apache/hugegraph/backend/query/Query.java:
##########
@@ -560,25 +580,6 @@ public String toString() {
         return sb.toString();
     }
 
-    public static long defaultCapacity(long capacity) {
-        Long old = CAPACITY_CONTEXT.get();
-        CAPACITY_CONTEXT.set(capacity);
-        return old != null ? old : DEFAULT_CAPACITY;
-    }
-
-    public static long defaultCapacity() {
-        Long capacity = CAPACITY_CONTEXT.get();
-        return capacity != null ? capacity : DEFAULT_CAPACITY;
-    }
-
-    public static void checkForceCapacity(long count) throws LimitExceedException {
-        if (count > Query.DEFAULT_CAPACITY) {
-            throw new LimitExceedException(
-                      "Too many records(must <= %s) for one query",
-                      Query.DEFAULT_CAPACITY);
-        }
-    }
-

Review Comment:
   fixed



##########
hugegraph-core/src/main/java/org/apache/hugegraph/backend/tx/GraphTransaction.java:
##########
@@ -130,9 +114,18 @@ public class GraphTransaction extends IndexableTransaction {
     private final int commitPartOfAdjacentEdges;
     private final int batchSize;
     private final int pageSize;
-
     private final int verticesCapacity;
     private final int edgesCapacity;
+    private Map<Id, HugeVertex> addedVertices;
+    private Map<Id, HugeVertex> removedVertices;
+    private Map<Id, HugeEdge> addedEdges;
+    private Map<Id, HugeEdge> removedEdges;
+    private Set<HugeProperty<?>> addedProps;
+    private Set<HugeProperty<?>> removedProps;
+    // These are used to rollback state
+    private Map<Id, HugeVertex> updatedVertices;
+    private Map<Id, HugeEdge> updatedEdges;
+    private Set<HugeProperty<?>> updatedOldestProps; // Oldest props

Review Comment:
   fixed



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@hugegraph.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@hugegraph.apache.org
For additional commands, e-mail: issues-help@hugegraph.apache.org


[GitHub] [incubator-hugegraph] imbajin commented on a diff in pull request #2295: feat(api&core): support label & property filtering for both edge and vertex & support kout dfs mode

Posted by "imbajin (via GitHub)" <gi...@apache.org>.
imbajin commented on code in PR #2295:
URL: https://github.com/apache/incubator-hugegraph/pull/2295#discussion_r1312518071


##########
hugegraph-core/src/main/java/org/apache/hugegraph/traversal/optimize/TraversalUtil.java:
##########
@@ -310,9 +311,9 @@ public static void extractAggregateFunc(Step<?, ?> newStep,
     }
 
     public static ConditionQuery fillConditionQuery(
-                                 ConditionQuery query,
-                                 List<HasContainer> hasContainers,
-                                 HugeGraph graph) {
+            ConditionQuery query,
+            List<HasContainer> hasContainers,
+            HugeGraph graph) {

Review Comment:
   > ok, I reverted the style changes in all files
   
   after applying the `hugegraph-style.xml` we still get a string of differ format?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@hugegraph.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@hugegraph.apache.org
For additional commands, e-mail: issues-help@hugegraph.apache.org


[GitHub] [incubator-hugegraph] javeme commented on a diff in pull request #2295: feat(api&core): support label & property filtering for both edge and vertex & support kout dfs mode

Posted by "javeme (via GitHub)" <gi...@apache.org>.
javeme commented on code in PR #2295:
URL: https://github.com/apache/incubator-hugegraph/pull/2295#discussion_r1320715953


##########
hugegraph-api/src/main/java/org/apache/hugegraph/api/traversers/KoutAPI.java:
##########
@@ -237,19 +237,19 @@ private static class Request {
         public boolean withPath = false;
         @JsonProperty("with_edge")
         public boolean withEdge = false;
-        @JsonProperty("algorithm")
-        public String algorithm = HugeTraverser.TRAVERSE_MODE_BFS;
+        @JsonProperty("traverse_mode")
+        public String traverse_mode = HugeTraverser.TRAVERSE_MODE_BFS;

Review Comment:
   keep var name  traverseMode style



##########
hugegraph-core/src/main/java/org/apache/hugegraph/traversal/algorithm/HugeTraverser.java:
##########
@@ -178,8 +178,8 @@ public static void checkTraverseMode(String traverseMode) {
                         TRAVERSE_MODE_BFS, TRAVERSE_MODE_DFS, traverseMode);
     }
 
-    public static boolean isTraverseModeDFS(String algorithm) {
-        return algorithm.compareToIgnoreCase(TRAVERSE_MODE_DFS) == 0;
+    public static boolean isTraverseModeDFS(String traverse_mode) {

Review Comment:
   ditto



##########
hugegraph-api/src/main/java/org/apache/hugegraph/api/traversers/KoutAPI.java:
##########
@@ -237,19 +237,19 @@ private static class Request {
         public boolean withPath = false;
         @JsonProperty("with_edge")
         public boolean withEdge = false;
-        @JsonProperty("algorithm")
-        public String algorithm = HugeTraverser.TRAVERSE_MODE_BFS;
+        @JsonProperty("traverse_mode")
+        public String traverse_mode = HugeTraverser.TRAVERSE_MODE_BFS;
 
         @Override
         public String toString() {
             return String.format("KoutRequest{source=%s,steps=%s,maxDepth=%s" +
                                  "nearest=%s,countOnly=%s,capacity=%s," +
                                  "limit=%s,withVertex=%s,withPath=%s," +
-                                 "withEdge=%s,algorithm=%s}", this.source,
+                                 "withEdge=%s,traverse_mode=%s}", this.source,

Review Comment:
   ditto



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@hugegraph.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@hugegraph.apache.org
For additional commands, e-mail: issues-help@hugegraph.apache.org


[GitHub] [incubator-hugegraph] DanGuge commented on a diff in pull request #2295: feat(api&core): support label & property filtering for both edge and vertex & support kout dfs mode

Posted by "DanGuge (via GitHub)" <gi...@apache.org>.
DanGuge commented on code in PR #2295:
URL: https://github.com/apache/incubator-hugegraph/pull/2295#discussion_r1320582306


##########
hugegraph-core/src/main/java/org/apache/hugegraph/traversal/algorithm/HugeTraverser.java:
##########
@@ -85,6 +89,9 @@ public class HugeTraverser {
     // Empirical value of scan limit, with which results can be returned in 3s
     public static final String DEFAULT_PAGE_LIMIT = "100000";
     public static final long NO_LIMIT = -1L;
+    // kout traverse mode algorithms: bfs and dfs
+    public static final String TRAVERSE_MODE_BFS = "breadth_first_search";
+    public static final String TRAVERSE_MODE_DFS = "depth_first_search";

Review Comment:
   Got it



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@hugegraph.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@hugegraph.apache.org
For additional commands, e-mail: issues-help@hugegraph.apache.org


[GitHub] [incubator-hugegraph] javeme commented on a diff in pull request #2295: feat(api&core): support label & property filtering for both edge and vertex & support kout dfs mode

Posted by "javeme (via GitHub)" <gi...@apache.org>.
javeme commented on code in PR #2295:
URL: https://github.com/apache/incubator-hugegraph/pull/2295#discussion_r1311595120


##########
hugegraph-core/src/main/java/org/apache/hugegraph/traversal/algorithm/HugeTraverser.java:
##########
@@ -85,6 +89,9 @@ public class HugeTraverser {
     // Empirical value of scan limit, with which results can be returned in 3s
     public static final String DEFAULT_PAGE_LIMIT = "100000";
     public static final long NO_LIMIT = -1L;
+    // algorithms

Review Comment:
   to be improved



##########
hugegraph-core/src/main/java/org/apache/hugegraph/traversal/algorithm/HugeTraverser.java:
##########
@@ -164,6 +171,17 @@ public static void checkSkipDegree(long skipDegree, long degree,
         }
     }
 
+    public static void checkAlgorithm(String algorithm) {

Review Comment:
   also update it



##########
hugegraph-core/src/main/java/org/apache/hugegraph/backend/tx/GraphTransaction.java:
##########
@@ -1574,14 +1597,14 @@ private void checkNonnullProperty(HugeVertex vertex) {
         // Check whether passed all non-null property
         @SuppressWarnings("unchecked")
         Collection<Id> nonNullKeys = CollectionUtils.subtract(
-                                     vertexLabel.properties(),
-                                     vertexLabel.nullableKeys());
+                vertexLabel.properties(),
+                vertexLabel.nullableKeys());
         if (!keys.containsAll(nonNullKeys)) {
             @SuppressWarnings("unchecked")
             Collection<Id> missed = CollectionUtils.subtract(nonNullKeys, keys);
             HugeGraph graph = this.graph();
             E.checkArgument(false, "All non-null property keys %s of " +
-                            "vertex label '%s' must be set, missed keys %s",
+                                   "vertex label '%s' must be set, missed keys %s",

Review Comment:
   try this style:
   ```java
   E.checkArgument(false, 
                   "All non-null property keys %s of " +
                   "vertex label '%s' must be set, missed keys %s",
   ```



##########
hugegraph-core/src/main/java/org/apache/hugegraph/backend/tx/GraphTransaction.java:
##########
@@ -1018,9 +1211,7 @@ protected Iterator<HugeEdge> queryEdgesFromBackend(Query query) {
             if (vertex == null) {
                 return null;
             }
-            if (query.idsSize() == 1) {
-                assert vertex.getEdges().size() == 1;
-            }
+            assert query.idsSize() != 1 || vertex.getEdges().size() == 1;

Review Comment:
   seems like you are trying to reduce the number of lines of code, I think we prefer to keep the origin logic for more readable



##########
hugegraph-core/src/main/java/org/apache/hugegraph/backend/tx/GraphTransaction.java:
##########
@@ -1608,11 +1639,11 @@ private void checkVertexExistIfCustomizedId(Map<Id, HugeVertex> vertices) {
             HugeVertex newVertex = vertices.get(existedVertex.id());
             if (!existedVertex.label().equals(newVertex.label())) {
                 throw new HugeException(
-                          "The newly added vertex with id:'%s' label:'%s' " +
-                          "is not allowed to insert, because already exist " +
-                          "a vertex with same id and different label:'%s'",
-                          newVertex.id(), newVertex.label(),
-                          existedVertex.label());
+                        "The newly added vertex with id:'%s' label:'%s' " +
+                        "is not allowed to insert, because already exist " +
+                        "a vertex with same id and different label:'%s'",
+                        newVertex.id(), newVertex.label(),
+                        existedVertex.label());

Review Comment:
   ditto



##########
hugegraph-core/src/main/java/org/apache/hugegraph/backend/tx/GraphTransaction.java:
##########
@@ -171,6 +171,199 @@ public GraphTransaction(HugeGraphParams graph, BackendStore store) {
                         this.edgesCapacity);
     }
 
+    /**
+     * Construct one edge condition query based on source vertex, direction and
+     * edge labels
+     *
+     * @param sourceVertex source vertex of edge
+     * @param direction    only be "IN", "OUT" or "BOTH"
+     * @param edgeLabels   edge labels of queried edges
+     * @return constructed condition query
+     */
+    @Watched
+    public static ConditionQuery constructEdgesQuery(Id sourceVertex,
+                                                     Directions direction,
+                                                     Id... edgeLabels) {
+        E.checkState(sourceVertex != null,
+                     "The edge query must contain source vertex");
+        E.checkState(direction != null,
+                     "The edge query must contain direction");
+
+        ConditionQuery query = new ConditionQuery(HugeType.EDGE);
+
+        // Edge source vertex
+        query.eq(HugeKeys.OWNER_VERTEX, sourceVertex);
+
+        // Edge direction
+        if (direction == Directions.BOTH) {
+            query.query(Condition.or(
+                    Condition.eq(HugeKeys.DIRECTION, Directions.OUT),
+                    Condition.eq(HugeKeys.DIRECTION, Directions.IN)));
+        } else {
+            assert direction == Directions.OUT || direction == Directions.IN;
+            query.eq(HugeKeys.DIRECTION, direction);
+        }
+
+        // Edge labels
+        if (edgeLabels.length == 1) {
+            query.eq(HugeKeys.LABEL, edgeLabels[0]);
+        } else if (edgeLabels.length > 1) {
+            query.query(Condition.in(HugeKeys.LABEL,
+                                     Arrays.asList(edgeLabels)));
+        }
+
+        return query;
+    }
+
+    public static ConditionQuery constructEdgesQuery(Id sourceVertex,
+                                                     Directions direction,
+                                                     List<Id> edgeLabels) {
+        E.checkState(sourceVertex != null,
+                     "The edge query must contain source vertex");
+        E.checkState(direction != null,
+                     "The edge query must contain direction");
+
+        ConditionQuery query = new ConditionQuery(HugeType.EDGE);
+
+        // Edge source vertex
+        query.eq(HugeKeys.OWNER_VERTEX, sourceVertex);
+
+        // Edge direction
+        if (direction == Directions.BOTH) {
+            query.query(Condition.or(
+                    Condition.eq(HugeKeys.DIRECTION, Directions.OUT),
+                    Condition.eq(HugeKeys.DIRECTION, Directions.IN)));
+        } else {
+            assert direction == Directions.OUT || direction == Directions.IN;
+            query.eq(HugeKeys.DIRECTION, direction);
+        }
+
+        // Edge labels
+        if (edgeLabels.size() == 1) {
+            query.eq(HugeKeys.LABEL, edgeLabels.get(0));
+        } else if (edgeLabels.size() > 1) {
+            query.query(Condition.in(HugeKeys.LABEL, edgeLabels));
+        }
+
+        return query;
+    }
+
+    public static boolean matchFullEdgeSortKeys(ConditionQuery query,
+                                                HugeGraph graph) {
+        // All queryKeys in sortKeys
+        return matchEdgeSortKeys(query, true, graph);
+    }
+
+    public static boolean matchPartialEdgeSortKeys(ConditionQuery query,
+                                                   HugeGraph graph) {
+        // Partial queryKeys in sortKeys
+        return matchEdgeSortKeys(query, false, graph);
+    }
+
+    private static boolean matchEdgeSortKeys(ConditionQuery query,
+                                             boolean matchAll,
+                                             HugeGraph graph) {
+        assert query.resultType().isEdge();
+        Id label = query.condition(HugeKeys.LABEL);
+        if (label == null) {
+            return false;
+        }
+        List<Id> sortKeys = graph.edgeLabel(label).sortKeys();
+        if (sortKeys.isEmpty()) {
+            return false;
+        }
+        Set<Id> queryKeys = query.userpropKeys();
+        for (int i = sortKeys.size(); i > 0; i--) {
+            List<Id> subFields = sortKeys.subList(0, i);
+            if (queryKeys.containsAll(subFields)) {
+                if (queryKeys.size() == subFields.size() || !matchAll) {
+                    /*
+                     * Return true if:
+                     * matchAll=true and all queryKeys are in sortKeys
+                     *  or
+                     * partial queryKeys are in sortKeys
+                     */
+                    return true;
+                }
+            }
+        }
+        return false;
+    }
+
+    private static void verifyVerticesConditionQuery(ConditionQuery query) {
+        assert query.resultType().isVertex();
+
+        int total = query.conditionsSize();
+        if (total == 1) {
+            /*
+             * Supported query:
+             *  1.query just by vertex label
+             *  2.query just by PROPERTIES (like containsKey,containsValue)
+             *  3.query with scan
+             */
+            if (query.containsCondition(HugeKeys.LABEL) ||
+                query.containsCondition(HugeKeys.PROPERTIES) ||
+                query.containsScanRelation()) {
+                return;
+            }
+        }
+
+        int matched = 0;
+        if (query.containsCondition(HugeKeys.PROPERTIES)) {
+            matched++;
+            if (query.containsCondition(HugeKeys.LABEL)) {
+                matched++;
+            }
+        }
+
+        if (matched != total) {
+            throw new HugeException("Not supported querying vertices by %s",
+                                    query.conditions());
+        }
+    }
+
+    private static void verifyEdgesConditionQuery(ConditionQuery query) {
+        assert query.resultType().isEdge();
+
+        int total = query.conditionsSize();
+        if (total == 1) {
+            /*
+             * Supported query:
+             *  1.query just by edge label
+             *  2.query just by PROPERTIES (like containsKey,containsValue)
+             *  3.query with scan
+             */
+            if (query.containsCondition(HugeKeys.LABEL) ||
+                query.containsCondition(HugeKeys.PROPERTIES) ||
+                query.containsScanRelation()) {
+                return;
+            }
+        }
+
+        int matched = 0;
+        for (HugeKeys key : EdgeId.KEYS) {
+            Object value = query.condition(key);
+            if (value == null) {
+                break;
+            }
+            matched++;
+        }
+        int count = matched;
+
+        if (query.containsCondition(HugeKeys.PROPERTIES)) {
+            matched++;
+            if (count < 3 && query.containsCondition(HugeKeys.LABEL)) {
+                matched++;
+            }
+        }
+
+        if (matched != total) {
+            throw new HugeException(
+                    "Not supported querying edges by %s, expect %s",
+                    query.conditions(), EdgeId.KEYS[count]);
+        }
+    }
+

Review Comment:
   move to line 1385?



##########
hugegraph-core/src/main/java/org/apache/hugegraph/traversal/optimize/TraversalUtil.java:
##########
@@ -310,9 +311,9 @@ public static void extractAggregateFunc(Step<?, ?> newStep,
     }
 
     public static ConditionQuery fillConditionQuery(
-                                 ConditionQuery query,
-                                 List<HasContainer> hasContainers,
-                                 HugeGraph graph) {
+            ConditionQuery query,
+            List<HasContainer> hasContainers,
+            HugeGraph graph) {

Review Comment:
   can we revert the style changes in all files.



##########
hugegraph-core/src/main/java/org/apache/hugegraph/traversal/algorithm/HugeTraverser.java:
##########
@@ -85,6 +89,9 @@ public class HugeTraverser {
     // Empirical value of scan limit, with which results can be returned in 3s
     public static final String DEFAULT_PAGE_LIMIT = "100000";
     public static final long NO_LIMIT = -1L;
+    // algorithms
+    public static final String ALGORITHM_BFS = "breadth_first_search";

Review Comment:
   prefer TRAVERSE_MODE_BFS



##########
hugegraph-core/src/main/java/org/apache/hugegraph/traversal/algorithm/KoutTraverser.java:
##########
@@ -138,6 +138,38 @@ public KoutRecords customizedKout(Id source, EdgeStep step,
         return records;
     }
 
+    public KoutRecords DFSKout(Id source, Steps steps,
+                               int maxDepth, boolean nearest,
+                               long capacity, long limit) {
+        E.checkNotNull(source, "source vertex id");
+        this.checkVertexExist(source, "source vertex");
+        checkPositive(maxDepth, "k-out max_depth");

Review Comment:
   not addressed



##########
hugegraph-core/src/main/java/org/apache/hugegraph/backend/tx/GraphTransaction.java:
##########
@@ -1753,7 +1784,7 @@ private boolean rightResultFromIndexQuery(Query query, HugeElement elem) {
     }
 
     private <T extends HugeElement> Iterator<T> filterExpiredResultFromBackend(
-                                    Query query, Iterator<T> results) {
+            Query query, Iterator<T> results) {

Review Comment:
   ditto



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@hugegraph.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@hugegraph.apache.org
For additional commands, e-mail: issues-help@hugegraph.apache.org


[GitHub] [incubator-hugegraph] javeme commented on a diff in pull request #2295: feat(api&core): support label & property filtering for both edge and vertex & support kout dfs mode

Posted by "javeme (via GitHub)" <gi...@apache.org>.
javeme commented on code in PR #2295:
URL: https://github.com/apache/incubator-hugegraph/pull/2295#discussion_r1310648591


##########
hugegraph-core/src/main/java/org/apache/hugegraph/traversal/algorithm/KoutTraverser.java:
##########
@@ -138,6 +138,38 @@ public KoutRecords customizedKout(Id source, EdgeStep step,
         return records;
     }
 
+    public KoutRecords DFSKout(Id source, Steps steps,

Review Comment:
   keep dfsKout style?



##########
hugegraph-core/src/main/java/org/apache/hugegraph/backend/tx/GraphTransaction.java:
##########
@@ -1696,12 +1719,9 @@ private <T extends HugeElement> Iterator<T> filterUnmatchedRecords(
                 return false;
             }
             // Process results that query from left index or primary-key
-            if (query.resultType().isVertex() == elem.type().isVertex() &&
-                !rightResultFromIndexQuery(query, elem)) {
-                // Only index query will come here
-                return false;
-            }
-            return true;
+            // Only index query will come here

Review Comment:
   the logic is not equivalent here, I think maybe the origin code is more readable



##########
hugegraph-core/src/main/java/org/apache/hugegraph/backend/tx/GraphTransaction.java:
##########
@@ -171,6 +164,199 @@ public GraphTransaction(HugeGraphParams graph, BackendStore store) {
                         this.edgesCapacity);
     }
 
+    /**

Review Comment:
   can we keep the origin location to avoid conflicts



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@hugegraph.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@hugegraph.apache.org
For additional commands, e-mail: issues-help@hugegraph.apache.org


[GitHub] [incubator-hugegraph] DanGuge commented on a diff in pull request #2295: feat(api&core): support label & property filtering for both edge and vertex & support kout dfs mode

Posted by "DanGuge (via GitHub)" <gi...@apache.org>.
DanGuge commented on code in PR #2295:
URL: https://github.com/apache/incubator-hugegraph/pull/2295#discussion_r1311765309


##########
hugegraph-core/src/main/java/org/apache/hugegraph/traversal/optimize/TraversalUtil.java:
##########
@@ -310,9 +311,9 @@ public static void extractAggregateFunc(Step<?, ?> newStep,
     }
 
     public static ConditionQuery fillConditionQuery(
-                                 ConditionQuery query,
-                                 List<HasContainer> hasContainers,
-                                 HugeGraph graph) {
+            ConditionQuery query,
+            List<HasContainer> hasContainers,
+            HugeGraph graph) {

Review Comment:
   ok, I revert the style changes in all files



##########
hugegraph-core/src/main/java/org/apache/hugegraph/traversal/optimize/TraversalUtil.java:
##########
@@ -310,9 +311,9 @@ public static void extractAggregateFunc(Step<?, ?> newStep,
     }
 
     public static ConditionQuery fillConditionQuery(
-                                 ConditionQuery query,
-                                 List<HasContainer> hasContainers,
-                                 HugeGraph graph) {
+            ConditionQuery query,
+            List<HasContainer> hasContainers,
+            HugeGraph graph) {

Review Comment:
   ok, I reverted the style changes in all files



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@hugegraph.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@hugegraph.apache.org
For additional commands, e-mail: issues-help@hugegraph.apache.org


[GitHub] [incubator-hugegraph] DanGuge commented on a diff in pull request #2295: feat(api&core): support label & property filtering for both edge and vertex & support kout dfs mode

Posted by "DanGuge (via GitHub)" <gi...@apache.org>.
DanGuge commented on code in PR #2295:
URL: https://github.com/apache/incubator-hugegraph/pull/2295#discussion_r1312556697


##########
hugegraph-core/src/main/java/org/apache/hugegraph/traversal/optimize/TraversalUtil.java:
##########
@@ -310,9 +311,9 @@ public static void extractAggregateFunc(Step<?, ?> newStep,
     }
 
     public static ConditionQuery fillConditionQuery(
-                                 ConditionQuery query,
-                                 List<HasContainer> hasContainers,
-                                 HugeGraph graph) {
+            ConditionQuery query,
+            List<HasContainer> hasContainers,
+            HugeGraph graph) {

Review Comment:
   > > 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`.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@hugegraph.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@hugegraph.apache.org
For additional commands, e-mail: issues-help@hugegraph.apache.org


[GitHub] [incubator-hugegraph] javeme commented on a diff in pull request #2295: feat(api&core): support label & property filtering for both edge and vertex & support kout dfs mode

Posted by "javeme (via GitHub)" <gi...@apache.org>.
javeme commented on code in PR #2295:
URL: https://github.com/apache/incubator-hugegraph/pull/2295#discussion_r1320679346


##########
hugegraph-api/src/main/java/org/apache/hugegraph/api/traversers/KoutAPI.java:
##########
@@ -228,16 +237,19 @@ private static class Request {
         public boolean withPath = false;
         @JsonProperty("with_edge")
         public boolean withEdge = false;
+        @JsonProperty("algorithm")

Review Comment:
   please also update to traverse_mode?



##########
hugegraph-api/src/main/java/org/apache/hugegraph/api/traversers/KoutAPI.java:
##########
@@ -228,16 +237,19 @@ private static class Request {
         public boolean withPath = false;
         @JsonProperty("with_edge")
         public boolean withEdge = false;
+        @JsonProperty("algorithm")
+        public String algorithm = HugeTraverser.TRAVERSE_MODE_BFS;

Review Comment:
   ditto



##########
hugegraph-core/src/main/java/org/apache/hugegraph/traversal/algorithm/HugeTraverser.java:
##########
@@ -164,6 +171,17 @@ public static void checkSkipDegree(long skipDegree, long degree,
         }
     }
 
+    public static void checkTraverseMode(String traverseMode) {
+        E.checkArgument(traverseMode.compareToIgnoreCase(TRAVERSE_MODE_BFS) == 0 ||
+                        traverseMode.compareToIgnoreCase(TRAVERSE_MODE_DFS) == 0,
+                        "The traverse mode must be one of '%s' or '%s', but got '%s'",
+                        TRAVERSE_MODE_BFS, TRAVERSE_MODE_DFS, traverseMode);
+    }
+
+    public static boolean isTraverseModeDFS(String algorithm) {

Review Comment:
   ditto



##########
hugegraph-api/src/main/java/org/apache/hugegraph/api/traversers/KoutAPI.java:
##########
@@ -228,16 +237,19 @@ private static class Request {
         public boolean withPath = false;
         @JsonProperty("with_edge")
         public boolean withEdge = false;
+        @JsonProperty("algorithm")
+        public String algorithm = HugeTraverser.TRAVERSE_MODE_BFS;
 
         @Override
         public String toString() {
-            return String.format("KoutRequest{source=%s,step=%s,maxDepth=%s" +
+            return String.format("KoutRequest{source=%s,steps=%s,maxDepth=%s" +
                                  "nearest=%s,countOnly=%s,capacity=%s," +
                                  "limit=%s,withVertex=%s,withPath=%s," +
-                                 "withEdge=%s}", this.source, this.step,
-                                 this.maxDepth, this.nearest, this.countOnly,
-                                 this.capacity, this.limit, this.withVertex,
-                                 this.withPath, this.withEdge);
+                                 "withEdge=%s,algorithm=%s}", this.source,

Review Comment:
   ditto



##########
hugegraph-core/src/main/java/org/apache/hugegraph/traversal/algorithm/HugeTraverser.java:
##########
@@ -85,6 +89,9 @@ public class HugeTraverser {
     // Empirical value of scan limit, with which results can be returned in 3s
     public static final String DEFAULT_PAGE_LIMIT = "100000";
     public static final long NO_LIMIT = -1L;
+    // kout traverse mode algorithms: bfs and dfs

Review Comment:
   "traverse mode of kout algorithm: bfs and dfs"



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@hugegraph.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@hugegraph.apache.org
For additional commands, e-mail: issues-help@hugegraph.apache.org


[GitHub] [incubator-hugegraph] imbajin merged pull request #2295: feat(api-core): support label & property filtering for both edge and vertex & support kout dfs mode

Posted by "imbajin (via GitHub)" <gi...@apache.org>.
imbajin merged PR #2295:
URL: https://github.com/apache/incubator-hugegraph/pull/2295


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@hugegraph.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@hugegraph.apache.org
For additional commands, e-mail: issues-help@hugegraph.apache.org


[GitHub] [incubator-hugegraph] DanGuge commented on a diff in pull request #2295: feat(api&core): support label & property filtering for both edge and vertex & support kout dfs mode

Posted by "DanGuge (via GitHub)" <gi...@apache.org>.
DanGuge commented on code in PR #2295:
URL: https://github.com/apache/incubator-hugegraph/pull/2295#discussion_r1320469799


##########
hugegraph-core/src/main/java/org/apache/hugegraph/traversal/algorithm/HugeTraverser.java:
##########
@@ -164,6 +171,17 @@ public static void checkSkipDegree(long skipDegree, long degree,
         }
     }
 
+    public static void checkTraverseMode(String traverseMode) {
+        E.checkArgument(traverseMode.compareToIgnoreCase(TRAVERSE_MODE_BFS) == 0 ||
+                        traverseMode.compareToIgnoreCase(TRAVERSE_MODE_DFS) == 0,
+                        "The traverse mode must be one of '%s' or '%s', but got '%s'",
+                        TRAVERSE_MODE_BFS, TRAVERSE_MODE_DFS, traverseMode);
+    }
+
+    public static boolean isDFSAlgorithm(String algorithm) {

Review Comment:
   fixed



##########
hugegraph-core/src/main/java/org/apache/hugegraph/traversal/algorithm/steps/Steps.java:
##########
@@ -0,0 +1,186 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with this
+ * work for additional information regarding copyright ownership. The ASF
+ * licenses this file to You under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.hugegraph.traversal.algorithm.steps;
+
+import static org.apache.hugegraph.traversal.algorithm.HugeTraverser.NO_LIMIT;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.hugegraph.HugeGraph;
+import org.apache.hugegraph.backend.id.Id;
+import org.apache.hugegraph.schema.EdgeLabel;
+import org.apache.hugegraph.schema.VertexLabel;
+import org.apache.hugegraph.traversal.algorithm.HugeTraverser;
+import org.apache.hugegraph.traversal.optimize.TraversalUtil;
+import org.apache.hugegraph.type.define.Directions;
+import org.apache.hugegraph.util.E;
+
+public class Steps {
+
+    protected final Map<Id, StepEntity> edgeSteps;
+    protected final Map<Id, StepEntity> vertexSteps;
+    protected final Directions direction;
+    protected final long degree;
+    protected final long skipDegree;
+
+    public Steps(HugeGraph graph, Directions direction,
+                 Map<String, Map<String, Object>> vSteps,
+                 Map<String, Map<String, Object>> eSteps,
+                 long degree, long skipDegree) {
+        E.checkArgument(degree == NO_LIMIT || degree > 0L,
+                        "The max degree must be > 0 or == -1, but got: %s", degree);
+        HugeTraverser.checkSkipDegree(skipDegree, degree, NO_LIMIT);
+
+        this.direction = direction;
+
+        // parse vertex steps
+        this.vertexSteps = new HashMap<>();
+        if (vSteps != null && !vSteps.isEmpty()) {
+            initVertexFilter(graph, vSteps);
+        }
+
+        // parse edge steps
+        this.edgeSteps = new HashMap<>();
+        if (eSteps != null && !eSteps.isEmpty()) {
+            initEdgeFilter(graph, eSteps);
+        }
+
+        this.degree = degree;
+        this.skipDegree = skipDegree;
+    }
+
+    private void initVertexFilter(HugeGraph graph, Map<String, Map<String, Object>> vSteps) {
+        for (Map.Entry<String, Map<String, Object>> entry : vSteps.entrySet()) {
+            if (checkEntryEmpty(entry)) {
+                continue;
+            }
+            E.checkArgument(entry.getKey() != null && !entry.getKey().isEmpty(),
+                            "The vertex step label could not be null");
+
+            VertexLabel vertexLabel = graph.vertexLabel(entry.getKey());
+            StepEntity stepEntity = handleStepEntity(graph, entry, vertexLabel.id());
+            this.vertexSteps.put(vertexLabel.id(), stepEntity);
+        }
+    }
+
+    private void initEdgeFilter(HugeGraph graph, Map<String, Map<String, Object>> eSteps) {
+        for (Map.Entry<String, Map<String, Object>> entry : eSteps.entrySet()) {
+            if (checkEntryEmpty(entry)) {
+                continue;
+            }
+            E.checkArgument(entry.getKey() != null && !entry.getKey().isEmpty(),
+                            "The edge step label could not be null");
+
+            EdgeLabel edgeLabel = graph.edgeLabel(entry.getKey());
+            StepEntity stepEntity = handleStepEntity(graph, entry, edgeLabel.id());
+            this.edgeSteps.put(edgeLabel.id(), stepEntity);
+        }
+    }
+
+    private StepEntity handleStepEntity(HugeGraph graph,
+                                        Map.Entry<String, Map<String, Object>> entry,
+                                        Id id) {
+        Map<Id, Object> properties = null;
+        if (entry.getValue() != null) {
+            properties = TraversalUtil.transProperties(graph, entry.getValue());
+        }
+        return new StepEntity(id, entry.getKey(), properties);
+    }
+
+    private boolean checkEntryEmpty(Map.Entry<String, Map<String, Object>> entry) {
+        return (entry.getKey() == null || entry.getKey().isEmpty()) &&
+               (entry.getValue() == null || entry.getValue().isEmpty());
+    }
+
+    public long degree() {
+        return degree;
+    }
+
+    public Map<Id, StepEntity> edgeSteps() {
+        return edgeSteps;
+    }
+
+    public Map<Id, StepEntity> vertexSteps() {
+        return vertexSteps;
+    }
+
+    public long skipDegree() {
+        return skipDegree;
+    }
+
+    public Directions direction() {
+        return direction;
+    }
+
+    public long limit() {
+        return this.skipDegree > 0L ? this.skipDegree : this.degree;
+    }
+
+    public List<Id> edgeLabels() {
+        return new ArrayList<>(this.edgeSteps.keySet());
+    }
+
+    public boolean isVertexEmpty() {
+        return this.vertexSteps.isEmpty();
+    }
+
+    @Override
+    public String toString() {
+        return "Steps{" +
+               "edgeSteps=" + edgeSteps +
+               ", vertexSteps=" + vertexSteps +
+               ", direction=" + direction +
+               ", degree=" + degree +
+               ", skipDegree=" + skipDegree +
+               '}';
+    }
+
+    public static class StepEntity {

Review Comment:
   fixed



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@hugegraph.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@hugegraph.apache.org
For additional commands, e-mail: issues-help@hugegraph.apache.org