Skip to content

Commit

Permalink
fix: can't query edges by multi labels + properties
Browse files Browse the repository at this point in the history
fix: #1735 #1736
Change-Id: I28e3a209074abaab8c8271775679d54845e6e785
  • Loading branch information
javeme committed Jan 20, 2022
1 parent e9cef74 commit 587670b
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import com.baidu.hugegraph.structure.HugeProperty;
import com.baidu.hugegraph.type.HugeType;
import com.baidu.hugegraph.type.define.HugeKeys;
import com.baidu.hugegraph.util.CollectionUtil;
import com.baidu.hugegraph.util.E;
import com.baidu.hugegraph.util.InsertionOrderUtil;
import com.baidu.hugegraph.util.LongEncoding;
Expand Down Expand Up @@ -217,23 +218,56 @@ public Relation relation(Id key){

@Watched
public <T> T condition(Object key) {
List<Object> values = new ArrayList<>();
List<Object> valuesEQ = InsertionOrderUtil.newList();
List<Object> valuesIN = InsertionOrderUtil.newList();
for (Condition c : this.conditions) {
if (c.isRelation()) {
Condition.Relation r = (Condition.Relation) c;
if (r.key().equals(key) && (r.relation() == RelationType.EQ ||
r.relation() == RelationType.IN)) {
values.add(r.value());
if (r.key().equals(key)) {
if (r.relation() == RelationType.EQ) {
valuesEQ.add(r.value());
} else if (r.relation() == RelationType.IN) {
Object value = r.value();
assert value instanceof List;
valuesIN.add(value);
}
}
}
}
if (values.isEmpty()) {
if (valuesEQ.isEmpty() && valuesIN.isEmpty()) {
return null;
}
E.checkState(values.size() == 1,
"Illegal key '%s' with more than one value", key);
if (valuesEQ.size() == 1 && valuesIN.size() == 0) {
@SuppressWarnings("unchecked")
T value = (T) valuesEQ.get(0);
return value;
}

Set<Object> intersectValues = InsertionOrderUtil.newSet();
for (Object value : valuesEQ) {
List<Object> valueAsList = ImmutableList.of(value);
if (intersectValues.isEmpty()) {
intersectValues.addAll(valueAsList);
} else {
CollectionUtil.intersectWithModify(intersectValues,
valueAsList);
}
}
for (Object value : valuesIN) {
@SuppressWarnings("unchecked")
List<Object> valueAsList = (List<Object>) value;
if (intersectValues.isEmpty()) {
intersectValues.addAll(valueAsList);
} else {
CollectionUtil.intersectWithModify(intersectValues,
valueAsList);
}
}
E.checkState(intersectValues.size() == 1,
"Illegal key '%s' with more than one value: %s",
key, intersectValues);
@SuppressWarnings("unchecked")
T value = (T) values.get(0);
T value = (T) intersectValues.iterator().next();
return value;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ protected ConditionQuery constructEdgesQuery(
ConditionQuery query = GraphTransaction.constructEdgesQuery(
vertex, direction, edgeLabels);
// Query by sort-keys
if (withEdgeCond && edgeLabels.length > 0) {
if (withEdgeCond && edgeLabels.length == 1) {
TraversalUtil.fillConditionQuery(query, this.hasContainers, graph);
if (!GraphTransaction.matchPartialEdgeSortKeys(query, graph)) {
// Can't query by sysprop and by index (HugeGraph-749)
Expand Down

0 comments on commit 587670b

Please sign in to comment.