use of com.baidu.hugegraph.backend.query.ConditionQuery in project incubator-hugegraph by apache.
the class ConditionQueryFlattenTest method testFlattenWithMultiOr.
@Test
public void testFlattenWithMultiOr() {
Condition c1 = Condition.eq(IdGenerator.of("c1"), "1");
Condition c2 = Condition.eq(IdGenerator.of("c2"), "2");
Condition c3 = Condition.eq(IdGenerator.of("c3"), "3");
Condition c4 = Condition.eq(IdGenerator.of("c4"), "4");
ConditionQuery query = new ConditionQuery(HugeType.VERTEX);
query.query(c1.or(c2));
query.query(c3.or(c4));
Assert.assertEquals(2, query.conditions().size());
List<ConditionQuery> queries = ConditionQueryFlatten.flatten(query);
Assert.assertEquals(4, queries.size());
List<Collection<Condition>> expect;
expect = ImmutableList.of(ImmutableList.of(c1, c3), ImmutableList.of(c1, c4), ImmutableList.of(c2, c3), ImmutableList.of(c2, c4));
List<Collection<Condition>> actual = new ArrayList<>();
for (ConditionQuery q : queries) {
actual.add(q.conditions());
}
Assert.assertEquals(expect, actual);
}
use of com.baidu.hugegraph.backend.query.ConditionQuery in project incubator-hugegraph by apache.
the class ConditionQueryFlattenTest method testFlattenWithAnd.
@Test
public void testFlattenWithAnd() {
Condition c1 = Condition.eq(IdGenerator.of("c1"), "1");
Condition c2 = Condition.eq(IdGenerator.of("c2"), "2");
ConditionQuery query = new ConditionQuery(HugeType.VERTEX);
query.query(c1.and(c2));
Assert.assertEquals(1, query.conditions().size());
List<ConditionQuery> queries = ConditionQueryFlatten.flatten(query);
Assert.assertEquals(1, queries.size());
List<Collection<Condition>> expect;
expect = ImmutableList.of(ImmutableList.of(c1, c2));
List<Collection<Condition>> actual = new ArrayList<>();
for (ConditionQuery q : queries) {
actual.add(q.conditions());
}
Assert.assertEquals(expect, actual);
}
use of com.baidu.hugegraph.backend.query.ConditionQuery in project incubator-hugegraph by apache.
the class ConditionQueryFlattenTest method testFlattenWithAndOrTree.
@Test
public void testFlattenWithAndOrTree() {
Condition c1 = Condition.eq(IdGenerator.of("c1"), "1");
Condition c2 = Condition.eq(IdGenerator.of("c2"), "2");
Condition c3 = Condition.eq(IdGenerator.of("c3"), "3");
Condition c4 = Condition.eq(IdGenerator.of("c4"), "4");
ConditionQuery query = new ConditionQuery(HugeType.VERTEX);
query.query(c1.or(c2).and(c3.or(c4)));
Assert.assertEquals(1, query.conditions().size());
List<ConditionQuery> queries = ConditionQueryFlatten.flatten(query);
Assert.assertEquals(4, queries.size());
List<Collection<Condition>> expect;
expect = ImmutableList.of(ImmutableList.of(c1, c3), ImmutableList.of(c1, c4), ImmutableList.of(c2, c3), ImmutableList.of(c2, c4));
List<Collection<Condition>> actual = new ArrayList<>();
for (ConditionQuery q : queries) {
actual.add(q.conditions());
}
Assert.assertEquals(expect, actual);
}
use of com.baidu.hugegraph.backend.query.ConditionQuery in project incubator-hugegraph by apache.
the class ConditionQueryFlattenTest method testFlattenWithMultiAnd.
@Test
public void testFlattenWithMultiAnd() {
Condition c1 = Condition.eq(IdGenerator.of("c1"), "1");
Condition c2 = Condition.eq(IdGenerator.of("c2"), "2");
Condition c3 = Condition.eq(IdGenerator.of("c3"), "3");
Condition c4 = Condition.eq(IdGenerator.of("c4"), "4");
ConditionQuery query = new ConditionQuery(HugeType.VERTEX);
query.query(c1);
query.query(c2);
query.query(c3);
query.query(c4);
Assert.assertEquals(4, query.conditions().size());
List<ConditionQuery> queries = ConditionQueryFlatten.flatten(query);
Assert.assertEquals(1, queries.size());
List<Collection<Condition>> expect;
expect = ImmutableList.of(ImmutableList.of(c1, c2, c3, c4));
List<Collection<Condition>> actual = new ArrayList<>();
for (ConditionQuery q : queries) {
actual.add(q.conditions());
}
Assert.assertEquals(expect, actual);
}
use of com.baidu.hugegraph.backend.query.ConditionQuery in project incubator-hugegraph by apache.
the class TableSerializer method writeQueryCondition.
@Override
protected Query writeQueryCondition(Query query) {
ConditionQuery result = (ConditionQuery) query;
// No user-prop when serialize
assert result.allSysprop();
for (Condition.Relation r : result.relations()) {
if (!r.value().equals(r.serialValue())) {
// Has been serialized before (maybe share a query multi times)
continue;
}
HugeKeys key = (HugeKeys) r.key();
if (r.relation() == Condition.RelationType.IN) {
E.checkArgument(r.value() instanceof List, "Expect list value for IN condition: %s", r);
List<?> values = (List<?>) r.value();
List<Object> serializedValues = new ArrayList<>(values.size());
for (Object v : values) {
serializedValues.add(this.serializeValue(key, v));
}
r.serialValue(serializedValues);
} else if (r.relation() == Condition.RelationType.CONTAINS_VALUE && query.resultType().isGraph()) {
r.serialValue(this.writeProperty(null, r.value()));
} else {
r.serialValue(this.serializeValue(key, r.value()));
}
}
return result;
}
Aggregations