javeme commented on code in PR #2055: URL: https://github.com/apache/incubator-hugegraph/pull/2055#discussion_r1052027784
########## hugegraph-core/src/main/java/org/apache/hugegraph/backend/query/ConditionQueryFlatten.java: ########## @@ -51,6 +51,22 @@ public static List<ConditionQuery> flatten(ConditionQuery query) { public static List<ConditionQuery> flatten(ConditionQuery query, boolean supportIn) { if (query.isFlattened() && !query.mayHasDupKeys(SPECIAL_KEYS)) { + Relations relations = new Relations(); + List<Condition> noRelations = new ArrayList<>(); Review Comment: rename to conditions? ########## hugegraph-core/src/main/java/org/apache/hugegraph/traversal/optimize/TraversalUtil.java: ########## @@ -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> graph = step.getTraversal() + .getGraph() + .filter(g -> { + return !(g instanceof EmptyGraph); Review Comment: add "TODO: remove these EmptyGraph judgments when upgrading tinkerpop to a [fixed version](https://github.com/apache/tinkerpop/pull/1699)" ########## hugegraph-core/src/main/java/org/apache/hugegraph/backend/query/ConditionQueryFlatten.java: ########## @@ -51,6 +51,22 @@ public static List<ConditionQuery> flatten(ConditionQuery query) { public static List<ConditionQuery> flatten(ConditionQuery query, boolean supportIn) { if (query.isFlattened() && !query.mayHasDupKeys(SPECIAL_KEYS)) { + Relations relations = new Relations(); + List<Condition> 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); + } Review Comment: add a new method flattenRelations()? ########## 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 = !"memory".equals(config.get(CoreOptions.BACKEND)); Review Comment: can we reuse from InMemoryDBStore.BackendFeatures? ########## hugegraph-core/src/main/java/org/apache/hugegraph/traversal/optimize/TraversalUtil.java: ########## @@ -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> graph = step.getTraversal() + .getGraph() + .filter(g -> { + return !(g instanceof EmptyGraph); + }); + if (!graph.isPresent()) { + TraversalParent parent = step.getTraversal().getParent(); + if (parent instanceof Traversal) { + Optional<Graph> 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) { Review Comment: seems don't need to set graph anymore, please refer to https://github.com/apache/tinkerpop/pull/1699 -- 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: dev-unsubscr...@hugegraph.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org