Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: fix TinkerPop unit test #2055

Merged
merged 14 commits into from
Dec 26, 2022
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<>();
zyxxoo marked this conversation as resolved.
Show resolved Hide resolved
for (Condition condition : query.conditions()) {
if (condition.isRelation()) {
relations.add((Relation) condition);
zyxxoo marked this conversation as resolved.
Show resolved Hide resolved
} 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
zyxxoo marked this conversation as resolved.
Show resolved Hide resolved
zyxxoo marked this conversation as resolved.
Show resolved Hide resolved
Optional<Graph> graph = step.getTraversal()
.getGraph()
.filter(g -> {
Expand Down Expand Up @@ -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<Graph> stepGraph = step.getTraversal()
.getGraph()
.filter(g -> {
Expand Down