Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -288,11 +288,13 @@ public <T> T condition(Object key) {
return value;
}

boolean initialized = false;
Set<Object> intersectValues = InsertionOrderUtil.newSet();
for (Object value : valuesEQ) {
List<Object> valueAsList = ImmutableList.of(value);
if (intersectValues.isEmpty()) {
if (!initialized) {
intersectValues.addAll(valueAsList);
initialized = true;
} else {
CollectionUtil.intersectWithModify(intersectValues,
valueAsList);
Expand All @@ -301,8 +303,9 @@ public <T> T condition(Object key) {
for (Object value : valuesIN) {
@SuppressWarnings("unchecked")
List<Object> valueAsList = (List<Object>) value;
if (intersectValues.isEmpty()) {
if (!initialized) {
intersectValues.addAll(valueAsList);
initialized = true;
} else {
CollectionUtil.intersectWithModify(intersectValues,
valueAsList);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4646,6 +4646,29 @@ public void testQueryInEdgesOfVertexByLabels() {
Assert.assertEquals(3L, size);
}

@Test
public void testQueryInEdgesOfVertexByConflictingLabels() {
HugeGraph graph = graph();
init18Edges();

long direct = graph.traversal().V().inE("created")
.hasLabel("created", "look")
.hasLabel("authored")
.count().next();
Assert.assertEquals(0L, direct);

long matched = graph.traversal().V()
.match(__.as("start1")
.inE("created")
.as("m1"))
.select("m1")
.hasLabel("created", "look")
.hasLabel("authored")
.count().next();
Assert.assertEquals(0L, matched);
Assert.assertEquals(matched, direct);
}

@Test
public void testQueryInEdgesOfVertexBySortkey() {
HugeGraph graph = graph();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@

package org.apache.hugegraph.unit.core;

import org.apache.hugegraph.backend.id.Id;
import org.apache.hugegraph.backend.id.IdGenerator;
import org.apache.hugegraph.backend.query.Aggregate.AggregateFunc;
import org.apache.hugegraph.backend.query.Condition;
import org.apache.hugegraph.backend.query.ConditionQuery;
import org.apache.hugegraph.backend.query.IdPrefixQuery;
import org.apache.hugegraph.backend.query.IdQuery;
Expand All @@ -30,6 +32,7 @@
import org.apache.hugegraph.type.define.HugeKeys;
import org.junit.Test;

import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;

Expand All @@ -45,6 +48,53 @@ public void testOrderBy() {
query.orders());
}

@Test
public void testConditionWithEqAndIn() {
Id label1 = IdGenerator.of(1);
Id label2 = IdGenerator.of(2);

ConditionQuery query = new ConditionQuery(HugeType.EDGE);
query.eq(HugeKeys.LABEL, label1);
query.query(Condition.in(HugeKeys.LABEL,
ImmutableList.of(label1, label2)));

Assert.assertEquals(label1, query.condition(HugeKeys.LABEL));
}

@Test
public void testConditionWithConflictingEqAndIn() {
Id label1 = IdGenerator.of(1);
Id label2 = IdGenerator.of(2);
Id label3 = IdGenerator.of(3);

ConditionQuery query = new ConditionQuery(HugeType.EDGE);
query.eq(HugeKeys.LABEL, label1);
query.eq(HugeKeys.LABEL, label2);
query.query(Condition.in(HugeKeys.LABEL,
ImmutableList.of(label1, label3)));

Assert.assertNull(query.condition(HugeKeys.LABEL));
}

@Test
public void testConditionWithMultipleMatchedInValues() {
Id label1 = IdGenerator.of(1);
Id label2 = IdGenerator.of(2);
Id label3 = IdGenerator.of(3);
Id label4 = IdGenerator.of(4);

ConditionQuery query = new ConditionQuery(HugeType.EDGE);
query.query(Condition.in(HugeKeys.LABEL,
ImmutableList.of(label1, label2, label3)));
query.query(Condition.in(HugeKeys.LABEL,
ImmutableList.of(label1, label2, label4)));

Assert.assertThrows(IllegalStateException.class,
() -> query.condition(HugeKeys.LABEL),
e -> Assert.assertContains("Illegal key 'LABEL'",
e.getMessage()));
}

@Test
public void testToString() {
Query query = new Query(HugeType.VERTEX);
Expand Down
Loading