From 2830974ec095401461551c2d8f788d37be780fc1 Mon Sep 17 00:00:00 2001 From: vaughn Date: Sun, 18 Dec 2022 23:49:32 +0800 Subject: [PATCH 01/13] 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 22504c2672..e7039ba412 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 StandardHugeGraph(HugeConfig config) { 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; From b76394a4e72831f29beeee4ed90df92355fc0401 Mon Sep 17 00:00:00 2001 From: vaughn Date: Mon, 19 Dec 2022 01:52:21 +0800 Subject: [PATCH 02/13] chore: setup graph by first step graph when graph is null --- .../apache/hugegraph/StandardHugeGraph.java | 2 +- .../optimize/HugeGraphStepStrategy.java | 3 + .../traversal/optimize/TraversalUtil.java | 95 +++++++++++++++++-- 3 files changed, 92 insertions(+), 8 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 e7039ba412..3cc1a83dd2 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 StandardHugeGraph(HugeConfig config) { 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 bea1f19ae1..baa1946c5e 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 void apply(Traversal.Admin traversal) { List 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 d43dcb951c..5c76edc67a 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.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; @@ -54,6 +55,7 @@ import org.apache.tinkerpop.gremlin.process.traversal.Traversal; import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal; import org.apache.tinkerpop.gremlin.process.traversal.step.HasContainerHolder; +import org.apache.tinkerpop.gremlin.process.traversal.step.TraversalParent; import org.apache.tinkerpop.gremlin.process.traversal.step.filter.FilterStep; import org.apache.tinkerpop.gremlin.process.traversal.step.filter.HasStep; import org.apache.tinkerpop.gremlin.process.traversal.step.filter.RangeGlobalStep; @@ -105,12 +107,71 @@ public static HugeGraph getGraph(Step step) { } public static HugeGraph tryGetGraph(Step step) { - Graph graph = step.getTraversal().getGraph().get(); - if (graph instanceof HugeGraph) { - return (HugeGraph) graph; + Optional graph = step.getTraversal() + .getGraph() + .filter(g -> { + return !(g instanceof EmptyGraph); + }); + if (!graph.isPresent()) { + TraversalParent parent = step.getTraversal().getParent(); + if (parent instanceof Traversal) { + Optional parentGraph = ((Traversal) parent) + .asAdmin() + .getGraph() + .filter(g -> { + return !(g instanceof EmptyGraph); + }); + if (parentGraph.isPresent()) { + step.getTraversal().setGraph(parentGraph.get()); + return (HugeGraph) parentGraph.get(); + } + } + + 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 stepGraph = step.getTraversal() + .getGraph() + .filter(g -> { + return !(g instanceof EmptyGraph); + }); + + if (step instanceof TraversalParent) { + for (final Traversal.Admin local : ((TraversalParent) step).getLocalChildren()) { + if (local.getGraph() + .filter(g -> { + return !(g instanceof EmptyGraph); + }).isPresent()) { + continue; + } + local.setGraph(graph); + } + for (final Traversal.Admin global : ((TraversalParent) step).getGlobalChildren()) { + if (global.getGraph() + .filter(g -> { + return !(g instanceof EmptyGraph); + }).isPresent()) { + continue; + } + global.setGraph(graph); + } + } + + if (stepGraph.isPresent()) { + assert stepGraph.get() instanceof HugeGraph; + return; + } + + step.getTraversal().setGraph(graph); } public static void extractHasContainer(HugeGraphStep newStep, @@ -580,14 +641,34 @@ public static void convAllHasSteps(Traversal.Admin traversal) { List steps = TraversalHelper.getStepsOfAssignableClassRecursively( HasStep.class, traversal); + + if (steps.isEmpty()) { + return; + } + /* * The graph in traversal may be null, for example: * `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()) { - return; + if (!traversal.getGraph() + .filter(g -> { + return !(g instanceof EmptyGraph); + }).isPresent()) { + if (traversal.getParent() == null || !(traversal.getParent() instanceof Traversal)) { + return; + } + + Optional parentGraph = ((Traversal) traversal.getParent()) + .asAdmin() + .getGraph(); + if (parentGraph.filter(g -> { + return !(g instanceof EmptyGraph); + }).isPresent()) { + traversal.setGraph(parentGraph.get()); + } } + HugeGraph graph = (HugeGraph) traversal.getGraph().get(); for (HasStep step : steps) { TraversalUtil.convHasStep(graph, step); From cd76807787821756c8791a4c8e198c04019d22ea Mon Sep 17 00:00:00 2001 From: vaughn Date: Mon, 19 Dec 2022 16:37:16 +0800 Subject: [PATCH 03/13] chore: apply relations optimize logic --- .../backend/query/ConditionQueryFlatten.java | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/hugegraph-core/src/main/java/org/apache/hugegraph/backend/query/ConditionQueryFlatten.java b/hugegraph-core/src/main/java/org/apache/hugegraph/backend/query/ConditionQueryFlatten.java index 487270ed7f..693b944be9 100644 --- a/hugegraph-core/src/main/java/org/apache/hugegraph/backend/query/ConditionQueryFlatten.java +++ b/hugegraph-core/src/main/java/org/apache/hugegraph/backend/query/ConditionQueryFlatten.java @@ -51,6 +51,22 @@ public static List flatten(ConditionQuery query) { public static List flatten(ConditionQuery query, boolean supportIn) { if (query.isFlattened() && !query.mayHasDupKeys(SPECIAL_KEYS)) { + Relations relations = new Relations(); + List noRelations = new ArrayList<>(); + for (Condition condition : query.conditions()) { + if (condition.isRelation()) { + relations.add((Relation) condition); + } else { + noRelations.add(condition); + } + } + relations = optimizeRelations(relations); + if (relations != null) { + ConditionQuery cq = newQueryFromRelations(query, relations); + cq.query(noRelations); + return ImmutableList.of(cq); + } + return ImmutableList.of(query); } From 00e50be811faf346d8fa26fac30ffd597a817c13 Mon Sep 17 00:00:00 2001 From: vaughn Date: Mon, 19 Dec 2022 17:11:17 +0800 Subject: [PATCH 04/13] chore: don't support null properties --- .../org/apache/hugegraph/structure/HugeFeatures.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/hugegraph-core/src/main/java/org/apache/hugegraph/structure/HugeFeatures.java b/hugegraph-core/src/main/java/org/apache/hugegraph/structure/HugeFeatures.java index 85517c9d61..5fddd23039 100644 --- a/hugegraph-core/src/main/java/org/apache/hugegraph/structure/HugeFeatures.java +++ b/hugegraph-core/src/main/java/org/apache/hugegraph/structure/HugeFeatures.java @@ -271,6 +271,11 @@ public VertexProperty.Cardinality getCardinality(final String key) { return VertexProperty.Cardinality.single; } + @Override + public boolean supportsNullPropertyValues() { + return false; + } + public boolean supportsDefaultLabel() { return true; } @@ -291,6 +296,11 @@ public class HugeEdgeFeatures extends HugeElementFeatures public EdgePropertyFeatures properties() { return this.edgePropertyFeatures; } + + @Override + public boolean supportsNullPropertyValues() { + return false; + } } public class HugeDataTypeFeatures implements DataTypeFeatures { From c3317b116bfe334ae07e943b533c362c234f894c Mon Sep 17 00:00:00 2001 From: vaughn Date: Mon, 19 Dec 2022 19:10:04 +0800 Subject: [PATCH 05/13] chore: reflactor code --- .../backend/query/ConditionQueryFlatten.java | 37 ++++++++++--------- .../traversal/optimize/TraversalUtil.java | 2 + 2 files changed, 22 insertions(+), 17 deletions(-) diff --git a/hugegraph-core/src/main/java/org/apache/hugegraph/backend/query/ConditionQueryFlatten.java b/hugegraph-core/src/main/java/org/apache/hugegraph/backend/query/ConditionQueryFlatten.java index 693b944be9..55af99442a 100644 --- a/hugegraph-core/src/main/java/org/apache/hugegraph/backend/query/ConditionQueryFlatten.java +++ b/hugegraph-core/src/main/java/org/apache/hugegraph/backend/query/ConditionQueryFlatten.java @@ -51,23 +51,7 @@ public static List flatten(ConditionQuery query) { public static List flatten(ConditionQuery query, boolean supportIn) { if (query.isFlattened() && !query.mayHasDupKeys(SPECIAL_KEYS)) { - Relations relations = new Relations(); - List noRelations = new ArrayList<>(); - for (Condition condition : query.conditions()) { - if (condition.isRelation()) { - relations.add((Relation) condition); - } else { - noRelations.add(condition); - } - } - relations = optimizeRelations(relations); - if (relations != null) { - ConditionQuery cq = newQueryFromRelations(query, relations); - cq.query(noRelations); - return ImmutableList.of(cq); - } - - return ImmutableList.of(query); + return flattenRelations(query); } List queries = new ArrayList<>(); @@ -267,6 +251,25 @@ private static ConditionQuery newQueryFromRelations(ConditionQuery query, return cq; } + private static ImmutableList flattenRelations(ConditionQuery query) { + Relations relations = new Relations(); + List noRelations = new ArrayList<>(); + for (Condition condition : query.conditions()) { + if (condition.isRelation()) { + relations.add((Relation) condition); + } else { + noRelations.add(condition); + } + } + relations = optimizeRelations(relations); + if (relations != null) { + ConditionQuery cq = newQueryFromRelations(query, relations); + cq.query(noRelations); + return ImmutableList.of(cq); + } + return ImmutableList.of(query); + } + private static Relations optimizeRelations(Relations relations) { // Optimize and-relations in one query // e.g. (age>1 and age>2) -> (age>2) 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 5c76edc67a..c9f9c3162f 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 @@ -107,6 +107,7 @@ public static HugeGraph getGraph(Step step) { } public static HugeGraph tryGetGraph(Step step) { + // TODO: remove these EmptyGraph judgments when upgrading tinkerpop to a fixed version Optional graph = step.getTraversal() .getGraph() .filter(g -> { @@ -139,6 +140,7 @@ public static void trySetGraph(Step step, HugeGraph graph) { return; } + // TODO: remove these EmptyGraph judgments when upgrading tinkerpop to a fixed version Optional stepGraph = step.getTraversal() .getGraph() .filter(g -> { From 694a7873311c0346c8770fefbcf25f64cd2f07ec Mon Sep 17 00:00:00 2001 From: vaughn Date: Thu, 22 Dec 2022 18:37:32 +0800 Subject: [PATCH 06/13] fix: g.V().has(empty).count() and g.V().count().as('a').select('a') --- .../hugegraph/traversal/optimize/HugeCountStepStrategy.java | 1 + .../apache/hugegraph/traversal/optimize/HugeGraphStep.java | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/hugegraph-core/src/main/java/org/apache/hugegraph/traversal/optimize/HugeCountStepStrategy.java b/hugegraph-core/src/main/java/org/apache/hugegraph/traversal/optimize/HugeCountStepStrategy.java index 699f32640d..5bde0e4543 100644 --- a/hugegraph-core/src/main/java/org/apache/hugegraph/traversal/optimize/HugeCountStepStrategy.java +++ b/hugegraph-core/src/main/java/org/apache/hugegraph/traversal/optimize/HugeCountStepStrategy.java @@ -104,6 +104,7 @@ public void apply(Traversal.Admin traversal) { graphStep.queryInfo().aggregate(Aggregate.AggregateFunc.COUNT, null); HugeCountStep countStep = new HugeCountStep<>(traversal, graphStep); for (Step origin : originSteps) { + TraversalHelper.copyLabels(origin, countStep, false); traversal.removeStep(origin); } traversal.addStep(0, countStep); diff --git a/hugegraph-core/src/main/java/org/apache/hugegraph/traversal/optimize/HugeGraphStep.java b/hugegraph-core/src/main/java/org/apache/hugegraph/traversal/optimize/HugeGraphStep.java index 2df10354a2..b4caec4cf1 100644 --- a/hugegraph-core/src/main/java/org/apache/hugegraph/traversal/optimize/HugeGraphStep.java +++ b/hugegraph-core/src/main/java/org/apache/hugegraph/traversal/optimize/HugeGraphStep.java @@ -72,6 +72,10 @@ public HugeGraphStep(final GraphStep originGraphStep) { } protected long count() { + if (this.ids == null) { + return 0; + } + if (this.returnsVertex()) { return this.verticesCount(); } else { From 1e4a91011aeef29739c5f59d85cc245f40569746 Mon Sep 17 00:00:00 2001 From: Simon Cheung Date: Wed, 21 Dec 2022 16:23:42 +0800 Subject: [PATCH 07/13] fix: specify the code generation directory for raft.proto (#2057) --- hugegraph-core/pom.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/hugegraph-core/pom.xml b/hugegraph-core/pom.xml index e0e3a887c6..0be30c9f01 100644 --- a/hugegraph-core/pom.xml +++ b/hugegraph-core/pom.xml @@ -280,6 +280,7 @@ com.google.protobuf:protoc:${protobuf.version}:exe:${os.detected.classifier} protoc-java ${project.basedir}/src/main/resources/proto + ${basedir}/target/generated-sources/protobuf/java From 02963d5e771b2db758d9941a108abff8ca2059fa Mon Sep 17 00:00:00 2001 From: vaughn Date: Thu, 22 Dec 2022 18:47:34 +0800 Subject: [PATCH 08/13] chore: reflactor code --- .../backend/query/ConditionQueryFlatten.java | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/hugegraph-core/src/main/java/org/apache/hugegraph/backend/query/ConditionQueryFlatten.java b/hugegraph-core/src/main/java/org/apache/hugegraph/backend/query/ConditionQueryFlatten.java index 55af99442a..8034870668 100644 --- a/hugegraph-core/src/main/java/org/apache/hugegraph/backend/query/ConditionQueryFlatten.java +++ b/hugegraph-core/src/main/java/org/apache/hugegraph/backend/query/ConditionQueryFlatten.java @@ -251,23 +251,26 @@ private static ConditionQuery newQueryFromRelations(ConditionQuery query, return cq; } - private static ImmutableList flattenRelations(ConditionQuery query) { + private static List flattenRelations(ConditionQuery query) { Relations relations = new Relations(); - List noRelations = new ArrayList<>(); + List nonRelations = new ArrayList<>(); for (Condition condition : query.conditions()) { if (condition.isRelation()) { relations.add((Relation) condition); } else { - noRelations.add(condition); + nonRelations.add(condition); } } relations = optimizeRelations(relations); + List conditionQueries = new ArrayList<>(); if (relations != null) { ConditionQuery cq = newQueryFromRelations(query, relations); - cq.query(noRelations); - return ImmutableList.of(cq); + cq.query(nonRelations); + conditionQueries.add(cq); + return conditionQueries; } - return ImmutableList.of(query); + conditionQueries.add(query); + return conditionQueries; } private static Relations optimizeRelations(Relations relations) { From 62f9fedaaadc9ffca0d1276f392778138c0d3133 Mon Sep 17 00:00:00 2001 From: vaughn Date: Thu, 22 Dec 2022 19:45:25 +0800 Subject: [PATCH 09/13] fix: tinkerpop unit schema no define --- .../apache/hugegraph/tinkerpop/TestGraph.java | 25 +++++++++++++------ 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/hugegraph-test/src/main/java/org/apache/hugegraph/tinkerpop/TestGraph.java b/hugegraph-test/src/main/java/org/apache/hugegraph/tinkerpop/TestGraph.java index 9eadc72dd3..21a82b3feb 100644 --- a/hugegraph-test/src/main/java/org/apache/hugegraph/tinkerpop/TestGraph.java +++ b/hugegraph-test/src/main/java/org/apache/hugegraph/tinkerpop/TestGraph.java @@ -457,6 +457,7 @@ public void initModernSchema(IdStrategy idStrategy) { schema.propertyKey("ripple").ifNotExist().create(); schema.propertyKey("lop").ifNotExist().create(); schema.propertyKey("test").ifNotExist().create(); + schema.propertyKey("p").ifNotExist().create(); switch (idStrategy) { case AUTOMATIC: @@ -475,8 +476,8 @@ public void initModernSchema(IdStrategy idStrategy) { .nullableKeys("name") .ifNotExist().create(); schema.vertexLabel(DEFAULT_VL) - .properties("name", "age") - .nullableKeys("name", "age") + .properties("name", "age", "p") + .nullableKeys("name", "age", "p") .ifNotExist().create(); schema.vertexLabel("animal") .properties("name", "age", "peter", "josh", "marko", @@ -499,8 +500,8 @@ public void initModernSchema(IdStrategy idStrategy) { .nullableKeys("name") .useCustomizeStringId().ifNotExist().create(); schema.vertexLabel(DEFAULT_VL) - .properties("name", "age") - .nullableKeys("name", "age") + .properties("name", "age", "p") + .nullableKeys("name", "age", "p") .useCustomizeStringId().ifNotExist().create(); schema.vertexLabel("animal") .properties("name", "age") @@ -557,6 +558,8 @@ public void initModernSchema(IdStrategy idStrategy) { .range().ifNotExist().create(); schema.indexLabel("personByNameAge").onV("person").by("name", "age") .ifNotExist().create(); + schema.indexLabel("vertexByP").onV("vertex").by("p") + .ifNotExist().create(); } @Watched @@ -659,6 +662,8 @@ private void initBasicPropertyKey() { schema.propertyKey("f").asFloat().ifNotExist().create(); schema.propertyKey("i").asInt().ifNotExist().create(); schema.propertyKey("l").asLong().ifNotExist().create(); + schema.propertyKey("p").ifNotExist().create(); + schema.propertyKey("k").ifNotExist().create(); schema.propertyKey("here").ifNotExist().create(); schema.propertyKey("to-change").ifNotExist().create(); schema.propertyKey("to-remove").ifNotExist().create(); @@ -704,7 +709,7 @@ private void initBasicVertexLabelV(IdStrategy idStrategy, "favoriteColor", "aKey", "age", "boolean", "float", "double", "string", "integer", "long", "myId", "location", "x", "y", "s", - "n", "d", "f", "i", "l", "to-change", + "n", "d", "f", "i", "l", "p", "k", "to-change", "to-remove", "to-keep", "old", "new", "gremlin.partitionGraphStrategy.partition", "color", "blah") @@ -714,7 +719,7 @@ private void initBasicVertexLabelV(IdStrategy idStrategy, "favoriteColor", "aKey", "age", "boolean", "float", "double", "string", "integer", "long", "myId", "location", "x", "y", "s", - "n", "d", "f", "i", "l", "to-change", + "n", "d", "f", "i", "l", "p", "k", "to-change", "to-remove", "to-keep", "old", "new", "gremlin.partitionGraphStrategy.partition", "color", "blah") @@ -729,7 +734,7 @@ private void initBasicVertexLabelV(IdStrategy idStrategy, "favoriteColor", "aKey", "age", "boolean", "float", "double", "string", "integer", "long", "myId", "location", "x", "y", "s", - "n", "d", "f", "i", "l", "to-change", + "n", "d", "f", "i", "l", "p", "k", "to-change", "to-remove", "to-keep", "old", "new", "gremlin.partitionGraphStrategy.partition", "color", "blah") @@ -739,7 +744,7 @@ private void initBasicVertexLabelV(IdStrategy idStrategy, "favoriteColor", "aKey", "age", "boolean", "float", "double", "string", "integer", "long", "myId", "location", "x", "y", "s", - "n", "d", "f", "i", "l", "to-change", + "n", "d", "f", "i", "l", "p", "k", "to-change", "to-remove", "to-keep", "old", "new", "gremlin.partitionGraphStrategy.partition", "color", "blah") @@ -754,6 +759,10 @@ private void initBasicVertexLabelV(IdStrategy idStrategy, .ifNotExist().create(); schema.indexLabel("defaultVLByName").onV(defaultVL).by("name") .ifNotExist().create(); + schema.indexLabel("defaultVLBySome").onV(defaultVL).by("some") + .ifNotExist().create(); + schema.indexLabel("defaultVLByK").onV(defaultVL).by("k") + .ifNotExist().create(); } @Watched From ae7266d007dbf6d77bb285a576c16b6a5c015b65 Mon Sep 17 00:00:00 2001 From: vaughn Date: Thu, 22 Dec 2022 22:22:34 +0800 Subject: [PATCH 10/13] chore: reflactor code --- .../hugegraph/backend/query/ConditionQueryFlatten.java | 7 ++----- .../apache/hugegraph/traversal/optimize/HugeGraphStep.java | 2 +- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/hugegraph-core/src/main/java/org/apache/hugegraph/backend/query/ConditionQueryFlatten.java b/hugegraph-core/src/main/java/org/apache/hugegraph/backend/query/ConditionQueryFlatten.java index 8034870668..df749014df 100644 --- a/hugegraph-core/src/main/java/org/apache/hugegraph/backend/query/ConditionQueryFlatten.java +++ b/hugegraph-core/src/main/java/org/apache/hugegraph/backend/query/ConditionQueryFlatten.java @@ -262,15 +262,12 @@ private static List flattenRelations(ConditionQuery query) { } } relations = optimizeRelations(relations); - List conditionQueries = new ArrayList<>(); if (relations != null) { ConditionQuery cq = newQueryFromRelations(query, relations); cq.query(nonRelations); - conditionQueries.add(cq); - return conditionQueries; + return ImmutableList.of(cq); } - conditionQueries.add(query); - return conditionQueries; + return ImmutableList.of(query); } private static Relations optimizeRelations(Relations relations) { diff --git a/hugegraph-core/src/main/java/org/apache/hugegraph/traversal/optimize/HugeGraphStep.java b/hugegraph-core/src/main/java/org/apache/hugegraph/traversal/optimize/HugeGraphStep.java index b4caec4cf1..8045d44627 100644 --- a/hugegraph-core/src/main/java/org/apache/hugegraph/traversal/optimize/HugeGraphStep.java +++ b/hugegraph-core/src/main/java/org/apache/hugegraph/traversal/optimize/HugeGraphStep.java @@ -73,7 +73,7 @@ public HugeGraphStep(final GraphStep originGraphStep) { protected long count() { if (this.ids == null) { - return 0; + return 0L; } if (this.returnsVertex()) { From d2a494c777276e629867a5c9b0ba9588d970391e Mon Sep 17 00:00:00 2001 From: vaughn Date: Thu, 22 Dec 2022 23:36:51 +0800 Subject: [PATCH 11/13] chore: improve code --- .../main/java/org/apache/hugegraph/StandardHugeGraph.java | 5 ++--- .../apache/hugegraph/traversal/optimize/TraversalUtil.java | 4 ++-- hugegraph-test/src/main/resources/fast-methods.filter | 1 + hugegraph-test/src/main/resources/methods.filter | 1 + 4 files changed, 6 insertions(+), 5 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 3cc1a83dd2..e7c265084c 100644 --- a/hugegraph-core/src/main/java/org/apache/hugegraph/StandardHugeGraph.java +++ b/hugegraph-core/src/main/java/org/apache/hugegraph/StandardHugeGraph.java @@ -193,9 +193,6 @@ public StandardHugeGraph(HugeConfig config) { this.taskManager = TaskManager.instance(); - boolean supportsPersistence = !"memory".equals(config.get(CoreOptions.BACKEND)); - this.features = new HugeFeatures(this, supportsPersistence); - this.name = config.get(CoreOptions.STORE); this.started = false; this.closed = false; @@ -215,6 +212,8 @@ public StandardHugeGraph(HugeConfig config) { try { this.tx = new TinkerPopTransaction(this); + boolean supportsPersistence = this.backendStoreFeatures().supportsPersistence(); + this.features = new HugeFeatures(this, supportsPersistence); SnowflakeIdGenerator.init(this.params); 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 c9f9c3162f..992cd53688 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 @@ -107,7 +107,7 @@ public static HugeGraph getGraph(Step step) { } public static HugeGraph tryGetGraph(Step step) { - // TODO: remove these EmptyGraph judgments when upgrading tinkerpop to a fixed version + // TODO: remove these EmptyGraph judgments when upgrading tinkerpop to a fixed version tinkerpop#1699 Optional graph = step.getTraversal() .getGraph() .filter(g -> { @@ -140,7 +140,7 @@ public static void trySetGraph(Step step, HugeGraph graph) { return; } - // TODO: remove these EmptyGraph judgments when upgrading tinkerpop to a fixed version + // TODO: remove these EmptyGraph judgments when upgrading tinkerpop to a fixed version tinkerpop#1699 Optional stepGraph = step.getTraversal() .getGraph() .filter(g -> { diff --git a/hugegraph-test/src/main/resources/fast-methods.filter b/hugegraph-test/src/main/resources/fast-methods.filter index fa5231062e..85f099a46f 100644 --- a/hugegraph-test/src/main/resources/fast-methods.filter +++ b/hugegraph-test/src/main/resources/fast-methods.filter @@ -165,6 +165,7 @@ org.apache.tinkerpop.gremlin.process.traversal.step.filter.HasTest.Traversals.g_ org.apache.tinkerpop.gremlin.process.traversal.step.filter.HasTest.Traversals.g_V_hasXname_not_endingWithXasXX: Unsupported predicate 'notEndingWith(as)' org.apache.tinkerpop.gremlin.process.traversal.step.filter.HasTest.Traversals.g_V_hasXage_withoutX27_29X_count: Unsupported relation 'NEQ' org.apache.tinkerpop.gremlin.process.traversal.step.filter.HasTest.Traversals.g_V_hasXname_gtXmX_andXcontainingXoXXX: Unsupported predicate 'containing(o)' +org.apache.tinkerpop.gremlin.process.traversal.step.filter.HasTest.g_V_hasXp_neqXvXX: Unsupported relation 'NEQ' # Unsupport edge label 'created': 'software' -> 'person', has existed an edgelabel (created: person -> software) in this case org.apache.tinkerpop.gremlin.process.traversal.step.map.AddEdgeTest.Traversals.g_V_hasXname_markoX_asXaX_outEXcreatedX_asXbX_inV_addEXselectXbX_labelX_toXaX: Unsupport edge from inV to outV diff --git a/hugegraph-test/src/main/resources/methods.filter b/hugegraph-test/src/main/resources/methods.filter index b106cb9e7b..d32d3126ed 100644 --- a/hugegraph-test/src/main/resources/methods.filter +++ b/hugegraph-test/src/main/resources/methods.filter @@ -128,6 +128,7 @@ org.apache.tinkerpop.gremlin.process.traversal.step.filter.HasTest.Traversals.g_ org.apache.tinkerpop.gremlin.process.traversal.step.filter.HasTest.Traversals.g_V_hasXname_not_endingWithXasXX: Unsupported predicate 'notEndingWith(as)' org.apache.tinkerpop.gremlin.process.traversal.step.filter.HasTest.Traversals.g_V_hasXage_withoutX27_29X_count: Unsupported relation 'NEQ' org.apache.tinkerpop.gremlin.process.traversal.step.filter.HasTest.Traversals.g_V_hasXname_gtXmX_andXcontainingXoXXX: Unsupported predicate 'containing(o)' +org.apache.tinkerpop.gremlin.process.traversal.step.filter.HasTest.g_V_hasXp_neqXvXX: Unsupported relation 'NEQ' # Unsupport edge label 'created': 'software' -> 'person', has existed an edgelabel (created: person -> software) in this case org.apache.tinkerpop.gremlin.process.traversal.step.map.AddEdgeTest.Traversals.g_V_hasXname_markoX_asXaX_outEXcreatedX_asXbX_inV_addEXselectXbX_labelX_toXaX: Unsupport edge from inV to outV From 9b5ee56badb9b8b789d67982549f1ce6b86fcdf1 Mon Sep 17 00:00:00 2001 From: vaughn Date: Fri, 23 Dec 2022 09:02:48 +0800 Subject: [PATCH 12/13] fix: core test --- .../main/java/org/apache/hugegraph/core/MultiGraphsTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hugegraph-test/src/main/java/org/apache/hugegraph/core/MultiGraphsTest.java b/hugegraph-test/src/main/java/org/apache/hugegraph/core/MultiGraphsTest.java index cef98c3977..5dabcbdd42 100644 --- a/hugegraph-test/src/main/java/org/apache/hugegraph/core/MultiGraphsTest.java +++ b/hugegraph-test/src/main/java/org/apache/hugegraph/core/MultiGraphsTest.java @@ -333,7 +333,7 @@ public void testCreateGraphsWithMultiDisksForRocksDB() { g1.clearBackend(); final HugeGraph[] g2 = new HugeGraph[1]; - Assert.assertThrows(ConnectionException.class, () -> { + Assert.assertThrows(RuntimeException.class, () -> { g2[0] = openGraphWithBackend("g2", "rocksdb", "binary", "rocksdb.data_disks", "[g/range_int_index:rocksdb-index1]"); @@ -348,7 +348,7 @@ public void testCreateGraphsWithMultiDisksForRocksDB() { }); final HugeGraph[] g3 = new HugeGraph[1]; - Assert.assertThrows(ConnectionException.class, () -> { + Assert.assertThrows(RuntimeException.class, () -> { g3[0] = openGraphWithBackend("g3", "rocksdb", "binary", "rocksdb.data_disks", "[g/secondary_index:/]"); From 225854c773a1fe1b15f4de4f6895d1d0838779e0 Mon Sep 17 00:00:00 2001 From: imbajin Date: Mon, 26 Dec 2022 20:48:43 +0800 Subject: [PATCH 13/13] fix the style & clean some outdated code --- .github/{workflows => outdated}/release.yml | 6 +-- .github/workflows/ci.yml | 14 +----- .../backend/query/ConditionQueryFlatten.java | 30 ++++++------ .../traversal/optimize/HugeGraphStep.java | 6 +-- .../traversal/optimize/TraversalUtil.java | 48 ++++++------------- .../hugegraph/core/MultiGraphsTest.java | 42 +++++++--------- 6 files changed, 52 insertions(+), 94 deletions(-) rename .github/{workflows => outdated}/release.yml (93%) diff --git a/.github/workflows/release.yml b/.github/outdated/release.yml similarity index 93% rename from .github/workflows/release.yml rename to .github/outdated/release.yml index 5ba24bec26..771ece85f4 100644 --- a/.github/workflows/release.yml +++ b/.github/outdated/release.yml @@ -17,20 +17,20 @@ jobs: distribution: 'zulu' - name: Cache Maven packages - uses: actions/cache@v2 + uses: actions/cache@v3 with: path: ~/.m2 key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }} restore-keys: ${{ runner.os }}-m2 - name: Checkout - uses: actions/checkout@v2 + uses: actions/checkout@v3 with: fetch-depth: 2 - name: Package run: | - mvn clean package -DskipTests + mvn clean package -DskipTests -ntp - name: Rename file if: contains(env.TAG_NAME, "-") diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 17236051ff..c142d2c1e5 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -37,7 +37,7 @@ jobs: distribution: 'zulu' - name: Cache Maven packages - uses: actions/cache@v2 + uses: actions/cache@v3 with: path: ~/.m2 key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }} @@ -68,18 +68,6 @@ jobs: java-version: ${{ matrix.JAVA_VERSION }} distribution: 'zulu' -# - name: Init MySQL Env -# if: ${{ env.BACKEND == 'mysql' }} -# uses: mirromutth/mysql-action@v1.1 -# with: -# host port: 3306 # Optional, default value is 3306. The port of host -# container port: 3306 # Optional, default value is 3306. The port of container -# character set server: 'utf8mb4' # Optional, default value is 'utf8mb4'. The '--character-set-server' option for mysqld -# collation server: 'utf8mb4_general_ci' # Optional, default value is 'utf8mb4_general_ci'. The '--collation-server' option for mysqld -# mysql version: '5.7' # Optional, default value is "latest". The version of the MySQL -# mysql database: 'test' # Optional, default value is "test". The specified database which will be create -# mysql root password: "******" # Required if "mysql user" is empty, default is empty. The root superuser password - - name: Run unit test run: | $TRAVIS_DIR/run-unit-test.sh $BACKEND diff --git a/hugegraph-core/src/main/java/org/apache/hugegraph/backend/query/ConditionQueryFlatten.java b/hugegraph-core/src/main/java/org/apache/hugegraph/backend/query/ConditionQueryFlatten.java index df749014df..be432be2cd 100644 --- a/hugegraph-core/src/main/java/org/apache/hugegraph/backend/query/ConditionQueryFlatten.java +++ b/hugegraph-core/src/main/java/org/apache/hugegraph/backend/query/ConditionQueryFlatten.java @@ -35,13 +35,14 @@ import org.apache.hugegraph.util.E; import org.apache.hugegraph.util.InsertionOrderUtil; import org.apache.hugegraph.util.NumericUtil; + import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSet; public final class ConditionQueryFlatten { private static final Set SPECIAL_KEYS = ImmutableSet.of( - HugeKeys.LABEL + HugeKeys.LABEL ); public static List flatten(ConditionQuery query) { @@ -123,8 +124,8 @@ private static Condition flattenIn(Condition condition, boolean supportIn) { return new Condition.Or(flattenIn(or.left(), supportIn), flattenIn(or.right(), supportIn)); default: - throw new AssertionError(String.format( - "Wrong condition type: '%s'", condition.type())); + throw new AssertionError(String.format("Wrong condition type: '%s'", + condition.type())); } } @@ -144,8 +145,7 @@ private static Condition convIn2Or(Relation relation, boolean supportIn) { (key == HugeKeys.OWNER_VERTEX || key == HugeKeys.ID)) { // TODO: Should not rely on HugeKeys here, improve key judgment // Just mark flatten - return new Condition.FlattenSyspropRelation( - (SyspropRelation) relation); + return new Condition.FlattenSyspropRelation((SyspropRelation) relation); } // Do IN flatten, return null if values.size() == 0 @@ -214,8 +214,8 @@ private static Set flattenAndOr(Condition condition) { flattenAndOr(or.right())); break; default: - throw new AssertionError(String.format( - "Wrong condition type: '%s'", condition.type())); + throw new AssertionError(String.format("Wrong condition type: '%s'", + condition.type())); } return result; } @@ -308,8 +308,9 @@ private static Relations optimizeRelations(Relations relations) { /** * Reduce and merge relations linked with 'AND' for same key - * @param relations linked with 'AND' having same key, may contains 'in', - * 'not in', '>', '<', '>=', '<=', '==', '!=' + * + * @param relations linked with 'AND' having same key, may contain 'in', 'not in', + * '>', '<', '>=', '<=', '==', '!=' * @return merged relations */ private static Relations mergeRelations(Relations relations) { @@ -429,8 +430,8 @@ private static boolean validRange(Relation low, Relation high) { return true; } return compare(low, high) < 0 || compare(low, high) == 0 && - low.relation() == Condition.RelationType.GTE && - high.relation() == Condition.RelationType.LTE; + low.relation() == Condition.RelationType.GTE && + high.relation() == Condition.RelationType.LTE; } private static boolean validEq(Relation eq, Relation low, Relation high) { @@ -479,8 +480,7 @@ private static Relation lowRelation(Relation first, Relation second) { return selectRelation(first, second, false); } - private static Relation selectRelation(Relation first, Relation second, - boolean high) { + private static Relation selectRelation(Relation first, Relation second, boolean high) { if (first == null) { return second; } @@ -510,8 +510,8 @@ private static int compare(Relation first, Relation second) { } else if (firstValue instanceof Date && secondValue instanceof Date) { return ((Date) firstValue).compareTo((Date) secondValue); } else { - throw new IllegalArgumentException(String.format( - "Can't compare between %s and %s", first, second)); + throw new IllegalArgumentException(String.format("Can't compare between %s and %s", + first, second)); } } diff --git a/hugegraph-core/src/main/java/org/apache/hugegraph/traversal/optimize/HugeGraphStep.java b/hugegraph-core/src/main/java/org/apache/hugegraph/traversal/optimize/HugeGraphStep.java index 8045d44627..04e4bfa6fe 100644 --- a/hugegraph-core/src/main/java/org/apache/hugegraph/traversal/optimize/HugeGraphStep.java +++ b/hugegraph-core/src/main/java/org/apache/hugegraph/traversal/optimize/HugeGraphStep.java @@ -148,14 +148,13 @@ private boolean hasIds() { } private Query makeQuery(HugeGraph graph, HugeType type) { - Query query = null; + Query query; if (this.hasContainers.isEmpty()) { // Query all query = new Query(type); } else { ConditionQuery q = new ConditionQuery(type); - query = TraversalUtil.fillConditionQuery(q, this.hasContainers, - graph); + query = TraversalUtil.fillConditionQuery(q, this.hasContainers, graph); } query = this.injectQueryInfo(query); @@ -202,6 +201,7 @@ public Iterator lastTimeResults() { return this.lastTimeResults; } + @Override public boolean equals(Object obj) { if (!(obj instanceof HugeGraphStep)) { return false; 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 992cd53688..fa0922683e 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 @@ -107,21 +107,17 @@ public static HugeGraph getGraph(Step step) { } public static HugeGraph tryGetGraph(Step step) { - // TODO: remove these EmptyGraph judgments when upgrading tinkerpop to a fixed version tinkerpop#1699 + // TODO: remove these EmptyGraph judgments when upgrade tinkerpop (refer-tinkerpop#1699) Optional graph = step.getTraversal() .getGraph() - .filter(g -> { - return !(g instanceof EmptyGraph); - }); + .filter(g -> !(g instanceof EmptyGraph)); if (!graph.isPresent()) { TraversalParent parent = step.getTraversal().getParent(); if (parent instanceof Traversal) { - Optional parentGraph = ((Traversal) parent) - .asAdmin() - .getGraph() - .filter(g -> { - return !(g instanceof EmptyGraph); - }); + Optional parentGraph; + parentGraph = ((Traversal) parent).asAdmin() + .getGraph() + .filter(g -> !(g instanceof EmptyGraph)); if (parentGraph.isPresent()) { step.getTraversal().setGraph(parentGraph.get()); return (HugeGraph) parentGraph.get(); @@ -140,28 +136,20 @@ public static void trySetGraph(Step step, HugeGraph graph) { return; } - // TODO: remove these EmptyGraph judgments when upgrading tinkerpop to a fixed version tinkerpop#1699 + // TODO: remove these EmptyGraph judgments when upgrade tinkerpop (refer-tinkerpop#1699) Optional stepGraph = step.getTraversal() .getGraph() - .filter(g -> { - return !(g instanceof EmptyGraph); - }); + .filter(g -> !(g instanceof EmptyGraph)); if (step instanceof TraversalParent) { for (final Traversal.Admin local : ((TraversalParent) step).getLocalChildren()) { - if (local.getGraph() - .filter(g -> { - return !(g instanceof EmptyGraph); - }).isPresent()) { + if (local.getGraph().filter(g -> !(g instanceof EmptyGraph)).isPresent()) { continue; } local.setGraph(graph); } for (final Traversal.Admin global : ((TraversalParent) step).getGlobalChildren()) { - if (global.getGraph() - .filter(g -> { - return !(g instanceof EmptyGraph); - }).isPresent()) { + if (global.getGraph().filter(g -> !(g instanceof EmptyGraph)).isPresent()) { continue; } global.setGraph(graph); @@ -217,7 +205,6 @@ public static void extractOrder(Step newStep, step = step.getNextStep(); if (step instanceof OrderGlobalStep) { QueryHolder holder = (QueryHolder) newStep; - @SuppressWarnings("resource") OrderGlobalStep orderStep = (OrderGlobalStep) step; orderStep.getComparators().forEach(comp -> { ElementValueComparator comparator = @@ -288,7 +275,6 @@ public static void extractAggregateFunc(Step newStep, do { step = step.getNextStep(); if (step instanceof PropertiesStep) { - @SuppressWarnings("resource") PropertiesStep propStep = (PropertiesStep) step; if (propStep.getReturnType() == PropertyType.VALUE && propStep.getPropertyKeys().length == 1) { @@ -653,10 +639,7 @@ public static void convAllHasSteps(Traversal.Admin traversal) { * `g.V().hasLabel('person').union(__.has('name', 'tom'))` * Here `__.has()` will create a new traversal, but the graph is null */ - if (!traversal.getGraph() - .filter(g -> { - return !(g instanceof EmptyGraph); - }).isPresent()) { + if (!traversal.getGraph().filter(g -> !(g instanceof EmptyGraph)).isPresent()) { if (traversal.getParent() == null || !(traversal.getParent() instanceof Traversal)) { return; } @@ -664,9 +647,7 @@ public static void convAllHasSteps(Traversal.Admin traversal) { Optional parentGraph = ((Traversal) traversal.getParent()) .asAdmin() .getGraph(); - if (parentGraph.filter(g -> { - return !(g instanceof EmptyGraph); - }).isPresent()) { + if (parentGraph.filter(g -> !(g instanceof EmptyGraph)).isPresent()) { traversal.setGraph(parentGraph.get()); } } @@ -686,7 +667,7 @@ public static void convHasStep(HugeGraph graph, HasStep step) { private static void convPredicateValue(HugeGraph graph, HasContainer has) { - // No need to convert if key is sysprop + // No need to convert if key is sys-prop if (isSysProp(has.getKey())) { return; } @@ -802,8 +783,7 @@ private static V validPropertyValue(V value, PropertyKey pkey) { public static void retrieveSysprop(List hasContainers, Function func) { - for (Iterator iter = hasContainers.iterator(); - iter.hasNext();) { + for (Iterator iter = hasContainers.iterator(); iter.hasNext();) { HasContainer container = iter.next(); if (container.getKey().startsWith("~") && func.apply(container)) { iter.remove(); diff --git a/hugegraph-test/src/main/java/org/apache/hugegraph/core/MultiGraphsTest.java b/hugegraph-test/src/main/java/org/apache/hugegraph/core/MultiGraphsTest.java index 5dabcbdd42..dbf6444205 100644 --- a/hugegraph-test/src/main/java/org/apache/hugegraph/core/MultiGraphsTest.java +++ b/hugegraph-test/src/main/java/org/apache/hugegraph/core/MultiGraphsTest.java @@ -53,8 +53,7 @@ public class MultiGraphsTest extends BaseCoreTest { - private static final String NAME48 = - "g12345678901234567890123456789012345678901234567"; + private static final String NAME48 = "g12345678901234567890123456789012345678901234567"; @Test public void testWriteAndReadVersion() { @@ -233,16 +232,12 @@ public void testCopySchemaWithMultiGraphsWithConflict() { @Test public void testCreateGraphsWithInvalidNames() { - List invalidNames = ImmutableList.of( - "", " ", " g", "g 1", " .", ". .", - "@", "$", "%", "^", "&", "*", "(", ")", - "_", "+", "`", "-", "=", "{", "}", "|", - "[", "]", "\"", "<", "?", ";", "'", "~", - ",", ".", "/", "\\", - "~g", "g~", "g'", - "_1", "_a", - "1a", "123", - NAME48 + "8"); + List invalidNames = ImmutableList.of("", " ", " g", "g 1", " .", ". .", + "@", "$", "%", "^", "&", "*", "(", ")", + "_", "+", "`", "-", "=", "{", "}", "|", + "[", "]", "\"", "<", "?", ";", "'", "~", + ",", ".", "/", "\\", "~g", "g~", "g'", + "_1", "_a", "1a", "123", NAME48 + "8"); for (String name : invalidNames) { Assert.assertThrows(RuntimeException.class, () -> openGraphs(name)); } @@ -267,8 +262,7 @@ public void testCreateGraphsWithSameName() { () -> g2.vertexLabel("node")); Assert.assertThrows(IllegalArgumentException.class, () -> g3.vertexLabel("node")); - g1.schema().vertexLabel("node").useCustomizeNumberId() - .ifNotExist().create(); + g1.schema().vertexLabel("node").useCustomizeNumberId().ifNotExist().create(); g2.vertexLabel("node"); g3.vertexLabel("node"); @@ -294,13 +288,11 @@ public void testCreateGraphsWithSameName() { } @Test - public void testCreateGraphWithSameNameDifferentBackends() - throws Exception { + public void testCreateGraphWithSameNameDifferentBackends() throws Exception { HugeGraph g1 = openGraphWithBackend("graph", "memory", "text"); g1.initBackend(); Assert.assertThrows(RuntimeException.class, - () -> openGraphWithBackend("graph", "rocksdb", - "binary")); + () -> openGraphWithBackend("graph", "rocksdb", "binary")); g1.clearBackend(); g1.close(); } @@ -323,12 +315,10 @@ public void testCreateGraphsWithDifferentNameDifferentBackends() { @Test public void testCreateGraphsWithMultiDisksForRocksDB() { - HugeGraph g1 = openGraphWithBackend( - "g1", "rocksdb", "binary", - "rocksdb.data_disks", - "[g/secondary_index:rocksdb-index1," + - " g/range_int_index:rocksdb-index1," + - " g/range_long_index:rocksdb-index2]"); + HugeGraph g1 = openGraphWithBackend("g1", "rocksdb", "binary", "rocksdb.data_disks", + "[g/secondary_index:rocksdb-index1," + + " g/range_int_index:rocksdb-index1," + + " g/range_long_index:rocksdb-index2]"); g1.initBackend(); g1.clearBackend(); @@ -388,7 +378,7 @@ private static HugeGraph openGraphWithBackend(String graph, String backend, Configuration config = buildConfig(graph); config.setProperty(CoreOptions.BACKEND.name(), backend); config.setProperty(CoreOptions.SERIALIZER.name(), serializer); - for (int i = 0; i < configs.length;) { + for (int i = 0; i < configs.length; ) { config.setProperty(configs[i++], configs[i++]); } return ((HugeGraph) GraphFactory.open(config)); @@ -397,7 +387,7 @@ private static HugeGraph openGraphWithBackend(String graph, String backend, private static Configuration buildConfig(String graphName) { PropertiesConfiguration conf = Utils.getConf(); Configuration config = new BaseConfiguration(); - for (Iterator keys = conf.getKeys(); keys.hasNext();) { + for (Iterator keys = conf.getKeys(); keys.hasNext(); ) { String key = keys.next(); config.setProperty(key, conf.getProperty(key)); }