Skip to content

Commit

Permalink
chore: reflactor code
Browse files Browse the repository at this point in the history
  • Loading branch information
zyxxoo committed Dec 19, 2022
1 parent 00e50be commit 49e1d56
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,23 +51,7 @@ 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);
}

return ImmutableList.of(query);
return flattenRelations(query);
}

List<ConditionQuery> queries = new ArrayList<>();
Expand Down Expand Up @@ -267,6 +251,25 @@ private static ConditionQuery newQueryFromRelations(ConditionQuery query,
return cq;
}

private static ImmutableList<ConditionQuery> flattenRelations(ConditionQuery query) {
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);
}
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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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> graph = step.getTraversal()
.getGraph()
.filter(g -> {
Expand Down

0 comments on commit 49e1d56

Please sign in to comment.