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..05e2f8c70e 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 -> {