Skip to content

Commit

Permalink
improve the code logic & comment
Browse files Browse the repository at this point in the history
  • Loading branch information
imbajin committed Feb 26, 2024
1 parent ee64377 commit fb7f000
Showing 1 changed file with 14 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1414,8 +1414,7 @@ private <R> QueryList<R> optimizeQueries(Query query,

private Query optimizeQuery(ConditionQuery query) {
if (query.idsSize() > 0) {
throw new HugeException(
"Not supported querying by id and conditions: %s", query);
throw new HugeException("Not supported querying by id and conditions: %s", query);
}

Id label = query.condition(HugeKeys.LABEL);
Expand All @@ -1435,11 +1434,10 @@ private Query optimizeQuery(ConditionQuery query) {
String primaryValues = query.userpropValuesString(keys);
LOG.debug("Query vertices by primaryKeys: {}", query);
// Convert {vertex-label + primary-key} to vertex-id
Id id = SplicingIdGenerator.splicing(label.asString(),
primaryValues);
Id id = SplicingIdGenerator.splicing(label.asString(), primaryValues);
/*
* Just query by primary-key(id), ignore other userprop(if
* exists) that it will be filtered by queryVertices(Query)
* Just query by primary-key(id), ignore other user-props(if exists)
* that it will be filtered by queryVertices(Query)
*/
return new IdQuery(query, id);
}
Expand All @@ -1462,23 +1460,24 @@ private Query optimizeQuery(ConditionQuery query) {
VertexLabel vertexLabel = graph().vertexLabel(vertex.label());
return edgeLabel.linkWithVertexLabel(vertexLabel.id(), dir);
}).collect(Collectors.toList());

if (CollectionUtils.isEmpty(filterVertexList)) {
// Return empty query to skip storage query
return new Query(query.resultType());

Check warning on line 1465 in hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/backend/tx/GraphTransaction.java

View check run for this annotation

Codecov / codecov/patch

hugegraph-server/hugegraph-core/src/main/java/org/apache/hugegraph/backend/tx/GraphTransaction.java#L1465

Added line #L1465 was not covered by tests
} else if (vertexIdList.size() != filterVertexList.size()) {
}

if (vertexIdList.size() != filterVertexList.size()) {
// Modify on the copied relation to avoid affecting other query
Condition.Relation relation = query.copyRelationAndUpdateQuery(HugeKeys.OWNER_VERTEX);
Condition.Relation relation =
query.copyRelationAndUpdateQuery(HugeKeys.OWNER_VERTEX);
relation.value(filterVertexList);
}
} else if (query.containsRelation(HugeKeys.OWNER_VERTEX, Condition.RelationType.EQ)) {
// For EQ query, just skip query if adjacent schema is unavailable.
Id vertexId = query.condition(HugeKeys.OWNER_VERTEX);
Iterator<Vertex> iter = this.queryVertices(vertexId);
Vertex vertex = QueryResults.one(iter);
Vertex vertex = QueryResults.one(this.queryVertices(vertexId));
if (vertex != null) {
VertexLabel vertexLabel = graph().vertexLabel(vertex.label());
// For EQ query, just skip query storage if adjacent schema doesn't exist
if (!edgeLabel.linkWithVertexLabel(vertexLabel.id(), dir)) {
// Return empty query to skip storage query
return new Query(query.resultType());
}
}
Expand All @@ -1490,8 +1489,8 @@ private Query optimizeQuery(ConditionQuery query) {
query = query.copy();
// Serialize sort-values
List<Id> keys = this.graph().edgeLabel(label).sortKeys();
List<Condition> conditions = GraphIndexTransaction.constructShardConditions(
query, keys, HugeKeys.SORT_VALUES);
List<Condition> conditions = GraphIndexTransaction
.constructShardConditions(query, keys, HugeKeys.SORT_VALUES);
query.query(conditions);
/*
* Reset all userprop since transferred to sort-keys, ignore other
Expand Down

0 comments on commit fb7f000

Please sign in to comment.