You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hugegraph.apache.org by va...@apache.org on 2022/12/18 18:11:55 UTC

[incubator-hugegraph] branch zy_dev created (now 770d981ff)

This is an automated email from the ASF dual-hosted git repository.

vaughn pushed a change to branch zy_dev
in repository https://gitbox.apache.org/repos/asf/incubator-hugegraph.git


      at 770d981ff chore: setup graph by first step graph when graph is null

This branch includes the following new commits:

     new b4b15309f chore: don't support persistence for memory backend
     new 770d981ff chore: setup graph by first step graph when graph is null

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



[incubator-hugegraph] 02/02: chore: setup graph by first step graph when graph is null

Posted by va...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

vaughn pushed a commit to branch zy_dev
in repository https://gitbox.apache.org/repos/asf/incubator-hugegraph.git

commit 770d981ff2c2d44f7c4e2d326b2a528536112318
Author: vaughn <va...@apache.org>
AuthorDate: Mon Dec 19 01:52:21 2022 +0800

    chore: setup graph by first step graph when graph is null
---
 .../org/apache/hugegraph/StandardHugeGraph.java    |  2 +-
 .../traversal/optimize/HugeGraphStepStrategy.java  |  3 ++
 .../traversal/optimize/TraversalUtil.java          | 39 ++++++++++++++++++----
 3 files changed, 37 insertions(+), 7 deletions(-)

diff --git a/hugegraph-core/src/main/java/org/apache/hugegraph/StandardHugeGraph.java b/hugegraph-core/src/main/java/org/apache/hugegraph/StandardHugeGraph.java
index e7039ba41..3cc1a83dd 100644
--- a/hugegraph-core/src/main/java/org/apache/hugegraph/StandardHugeGraph.java
+++ b/hugegraph-core/src/main/java/org/apache/hugegraph/StandardHugeGraph.java
@@ -193,7 +193,7 @@ public class StandardHugeGraph implements HugeGraph {
 
         this.taskManager = TaskManager.instance();
 
-        boolean supportsPersistence = this.backendStoreFeatures().supportsPersistence();
+        boolean supportsPersistence = !"memory".equals(config.get(CoreOptions.BACKEND));
         this.features = new HugeFeatures(this, supportsPersistence);
 
         this.name = config.get(CoreOptions.STORE);
diff --git a/hugegraph-core/src/main/java/org/apache/hugegraph/traversal/optimize/HugeGraphStepStrategy.java b/hugegraph-core/src/main/java/org/apache/hugegraph/traversal/optimize/HugeGraphStepStrategy.java
index bea1f19ae..baa1946c5 100644
--- a/hugegraph-core/src/main/java/org/apache/hugegraph/traversal/optimize/HugeGraphStepStrategy.java
+++ b/hugegraph-core/src/main/java/org/apache/hugegraph/traversal/optimize/HugeGraphStepStrategy.java
@@ -54,6 +54,9 @@ public final class HugeGraphStepStrategy
         List<GraphStep> steps = TraversalHelper.getStepsOfClass(
                                 GraphStep.class, traversal);
         for (GraphStep originStep : steps) {
+            TraversalUtil.trySetGraph(originStep,
+                                      TraversalUtil.tryGetGraph(steps.get(0)));
+
             HugeGraphStep<?, ?> newStep = new HugeGraphStep<>(originStep);
             TraversalHelper.replaceStep(originStep, newStep, traversal);
 
diff --git a/hugegraph-core/src/main/java/org/apache/hugegraph/traversal/optimize/TraversalUtil.java b/hugegraph-core/src/main/java/org/apache/hugegraph/traversal/optimize/TraversalUtil.java
index d43dcb951..f960ff136 100644
--- a/hugegraph-core/src/main/java/org/apache/hugegraph/traversal/optimize/TraversalUtil.java
+++ b/hugegraph-core/src/main/java/org/apache/hugegraph/traversal/optimize/TraversalUtil.java
@@ -25,6 +25,7 @@ import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
+import java.util.Optional;
 import java.util.function.BiPredicate;
 import java.util.function.Function;
 import java.util.regex.Matcher;
@@ -66,6 +67,7 @@ import org.apache.tinkerpop.gremlin.process.traversal.step.map.NoOpBarrierStep;
 import org.apache.tinkerpop.gremlin.process.traversal.step.map.OrderGlobalStep;
 import org.apache.tinkerpop.gremlin.process.traversal.step.map.PropertiesStep;
 import org.apache.tinkerpop.gremlin.process.traversal.step.map.SumGlobalStep;
+import org.apache.tinkerpop.gremlin.process.traversal.step.map.VertexStep;
 import org.apache.tinkerpop.gremlin.process.traversal.step.sideEffect.IdentityStep;
 import org.apache.tinkerpop.gremlin.process.traversal.step.util.ElementValueComparator;
 import org.apache.tinkerpop.gremlin.process.traversal.step.util.HasContainer;
@@ -105,12 +107,35 @@ public final class TraversalUtil {
     }
 
     public static HugeGraph tryGetGraph(Step<?, ?> step) {
-        Graph graph = step.getTraversal().getGraph().get();
-        if (graph instanceof HugeGraph) {
-            return (HugeGraph) graph;
+        Optional<Graph> graph = step.getTraversal()
+                                    .getGraph()
+                                    .filter(g -> {
+                                        return !(g instanceof EmptyGraph);
+                                    });
+        if (!graph.isPresent()) {
+            return null;
         }
-        assert graph == null || graph instanceof EmptyGraph;
-        return null;
+
+        assert graph.get() instanceof HugeGraph;
+        return (HugeGraph) graph.get();
+    }
+
+    public static void trySetGraph(Step<?, ?> step, HugeGraph graph) {
+        if (graph == null || step == null || step.getTraversal() == null) {
+            return;
+        }
+
+        Optional<Graph> stepGraph = step.getTraversal()
+                                        .getGraph()
+                                        .filter(g -> {
+                                            return !(g instanceof EmptyGraph);
+                                        });
+        if (stepGraph.isPresent()) {
+            assert stepGraph.get() instanceof HugeGraph;
+            return;
+        }
+
+        step.getTraversal().setGraph(graph);
     }
 
     public static void extractHasContainer(HugeGraphStep<?, ?> newStep,
@@ -585,9 +610,11 @@ public final class TraversalUtil {
          *   `g.V().hasLabel('person').union(__.has('name', 'tom'))`
          * Here `__.has()` will create a new traversal, but the graph is null
          */
-        if (steps.isEmpty() || !traversal.getGraph().isPresent()) {
+        if (steps.isEmpty() || !traversal.getGraph().isPresent() ||
+            traversal.getGraph().get() instanceof EmptyGraph) {
             return;
         }
+
         HugeGraph graph = (HugeGraph) traversal.getGraph().get();
         for (HasStep<?> step : steps) {
             TraversalUtil.convHasStep(graph, step);


[incubator-hugegraph] 01/02: chore: don't support persistence for memory backend

Posted by va...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

vaughn pushed a commit to branch zy_dev
in repository https://gitbox.apache.org/repos/asf/incubator-hugegraph.git

commit b4b15309f55ed18c3d7849e7eac5f2f78ff5dcd1
Author: vaughn <va...@apache.org>
AuthorDate: Sun Dec 18 23:49:32 2022 +0800

    chore: don't support persistence for memory backend
---
 .../src/main/java/org/apache/hugegraph/StandardHugeGraph.java          | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/hugegraph-core/src/main/java/org/apache/hugegraph/StandardHugeGraph.java b/hugegraph-core/src/main/java/org/apache/hugegraph/StandardHugeGraph.java
index 22504c267..e7039ba41 100644
--- a/hugegraph-core/src/main/java/org/apache/hugegraph/StandardHugeGraph.java
+++ b/hugegraph-core/src/main/java/org/apache/hugegraph/StandardHugeGraph.java
@@ -193,7 +193,8 @@ public class StandardHugeGraph implements HugeGraph {
 
         this.taskManager = TaskManager.instance();
 
-        this.features = new HugeFeatures(this, true);
+        boolean supportsPersistence = this.backendStoreFeatures().supportsPersistence();
+        this.features = new HugeFeatures(this, supportsPersistence);
 
         this.name = config.get(CoreOptions.STORE);
         this.started = false;