Skip to content

Commit

Permalink
fix bug hasLabel() failed if having more than 1 label
Browse files Browse the repository at this point in the history
fix #50

Change-Id: I56bee811ded53b3b55109f52877e6781dc5f3629
  • Loading branch information
zhoney authored and Linary committed Sep 20, 2018
1 parent 638d219 commit d13a298
Showing 1 changed file with 43 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ public static Condition convHas2Condition(HasContainer has,
} else if (bp instanceof RelationType) {
condition = convRelationType2Relation(graph, type, has);
} else if (bp instanceof Contains) {
condition = convIn2Relation(graph, has);
condition = convIn2Relation(graph, type, has);
} else if (p instanceof AndP) {
condition = convAnd(graph, type, has);
} else if (p instanceof OrP) {
Expand Down Expand Up @@ -286,17 +286,7 @@ private static Relation convCompare2SyspropRelation(HugeGraph graph,
assert bp instanceof Compare;

HugeKeys key = string2HugeKey(has.getKey());
Object value = has.getValue();

if (key == HugeKeys.LABEL && !(value instanceof Id)) {
value = SchemaLabel.getLabelId(graph, type, value);
} else if (key == HugeKeys.ID && !(value instanceof Id)) {
if (type.isVertex()) {
value = HugeVertex.getIdValue(value);
} else {
value = HugeEdge.getIdValue(value);
}
}
Object value = convSysValueIfNeeded(graph, type, key, has.getValue());

switch ((Compare) bp) {
case eq:
Expand Down Expand Up @@ -360,29 +350,39 @@ private static Condition convRelationType2Relation(HugeGraph graph,
}

public static Condition convIn2Relation(HugeGraph graph,
HugeType type,
HasContainer has) {
BiPredicate<?, ?> bp = has.getPredicate().getBiPredicate();
assert bp instanceof Contains;
List<?> value = (List<?>) has.getValue();
List<?> values = (List<?>) has.getValue();

try {
HugeKeys key = string2HugeKey(has.getKey());
String originKey = has.getKey();
if (values.size() > 1) {
E.checkArgument(!originKey.equals(T.key) &&
!originKey.equals(T.value),
"Not support hasKey() or hasValue() with " +
"multiple values");
}
HugeKeys key = string2HugeKey(originKey);
values = convSysListValueIfNeeded(graph, type, key, values);


switch ((Contains) bp) {
case within:
return Condition.in(key, value);
return Condition.in(key, values);
case without:
return Condition.nin(key, value);
return Condition.nin(key, values);
}
} catch (IllegalArgumentException e) {
String key = has.getKey();
PropertyKey pkey = graph.propertyKey(key);

switch ((Contains) bp) {
case within:
return Condition.in(pkey.id(), value);
return Condition.in(pkey.id(), values);
case without:
return Condition.nin(pkey.id(), value);
return Condition.nin(pkey.id(), values);
}
}

Expand Down Expand Up @@ -479,6 +479,31 @@ private static void convPredicateValue(HugeGraph graph, HasContainer has) {
}
}

private static Object convSysValueIfNeeded(HugeGraph graph,HugeType type,
HugeKeys key, Object value) {
if (key == HugeKeys.LABEL && !(value instanceof Id)) {
value = SchemaLabel.getLabelId(graph, type, value);
} else if (key == HugeKeys.ID && !(value instanceof Id)) {
if (type.isVertex()) {
value = HugeVertex.getIdValue(value);
} else {
value = HugeEdge.getIdValue(value);
}
}
return value;
}

private static List<?> convSysListValueIfNeeded(HugeGraph graph,
HugeType type,
HugeKeys key,
List<?> values) {
List<Object> newValues = new ArrayList<>(values.size());
for (Object value : values) {
newValues.add(convSysValueIfNeeded(graph, type, key, value));
}
return newValues;
}

public static Iterator<Edge> filterResult(Vertex vertex,
Directions dir,
Iterator<Edge> edges) {
Expand Down

0 comments on commit d13a298

Please sign in to comment.