use of com.baidu.hugegraph.backend.query.ConditionQuery in project incubator-hugegraph by apache.
the class VerticesAPI method scan.
@GET
@Timed
@Path("scan")
@Compress
@Produces(APPLICATION_JSON_WITH_CHARSET)
public String scan(@Context GraphManager manager, @PathParam("graph") String graph, @QueryParam("start") String start, @QueryParam("end") String end, @QueryParam("page") String page, @QueryParam("page_limit") @DefaultValue(DEFAULT_PAGE_LIMIT) long pageLimit) {
LOG.debug("Graph [{}] query vertices by shard(start: {}, end: {}, " + "page: {}) ", graph, start, end, page);
HugeGraph g = graph(manager, graph);
ConditionQuery query = new ConditionQuery(HugeType.VERTEX);
query.scan(start, end);
query.page(page);
if (query.paging()) {
query.limit(pageLimit);
}
Iterator<Vertex> vertices = g.vertices(query);
return manager.serializer(g).writeVertices(vertices, query.paging());
}
use of com.baidu.hugegraph.backend.query.ConditionQuery in project incubator-hugegraph by apache.
the class QueryTest method testToString.
@Test
public void testToString() {
Query query = new Query(HugeType.VERTEX);
Assert.assertEquals("`Query * from VERTEX`", query.toString());
query.page("p1");
Assert.assertEquals("`Query * from VERTEX page 'p1'`", query.toString());
query = new Query(HugeType.VERTEX);
query.limit(10L);
Assert.assertEquals("`Query * from VERTEX limit 10`", query.toString());
query = new Query(HugeType.VERTEX);
query.aggregate(AggregateFunc.COUNT, null);
query.limit(10L);
Assert.assertEquals("`Query count(*) from VERTEX limit 10`", query.toString());
query = new Query(HugeType.VERTEX);
query.aggregate(AggregateFunc.MAX, "age");
query.limit(10L);
Assert.assertEquals("`Query max(age) from VERTEX limit 10`", query.toString());
query = new Query(HugeType.VERTEX);
query.page("p2");
query.limit(10L);
Assert.assertEquals("`Query * from VERTEX page 'p2', limit 10`", query.toString());
query = new Query(HugeType.VERTEX);
query.page("p3");
query.offset(100L);
query.limit(10L);
Assert.assertEquals("`Query * from VERTEX page 'p3', offset 100, " + "limit 10`", query.toString());
query = new Query(HugeType.VERTEX);
query.page("");
query.offset(100L);
query.limit(10L);
query.order(HugeKeys.NAME, Order.ASC);
query.order(HugeKeys.FIELDS, Order.DESC);
Assert.assertEquals("`Query * from VERTEX page '', offset 100, " + "limit 10, order by {NAME=ASC, FIELDS=DESC}`", query.toString());
IdQuery query2 = new IdQuery(HugeType.VERTEX, IdGenerator.of(1));
query2.query(IdGenerator.of(3));
query2.limit(10L);
Assert.assertEquals("`Query * from VERTEX limit 10 where id in [1, 3]`", query2.toString());
ConditionQuery query3 = new ConditionQuery(HugeType.EDGE);
query3.eq(HugeKeys.LABEL, 3);
query3.gt(HugeKeys.PROPERTIES, 10);
query3.lt(HugeKeys.PROPERTIES, 18);
query3.limit(10L);
String qStr = query3.toString();
Assert.assertTrue(qStr.contains("`Query * from EDGE limit 10 where ["));
Assert.assertTrue(qStr.contains("LABEL == 3"));
Assert.assertTrue(qStr.contains("PROPERTIES > 10"));
Assert.assertTrue(qStr.contains("PROPERTIES < 18"));
ConditionQuery query4 = new ConditionQuery(HugeType.EDGE);
query4.query(ImmutableSet.of(IdGenerator.of(1), IdGenerator.of(3)));
query4.eq(HugeKeys.LABEL, 3);
query4.lt(HugeKeys.PROPERTIES, 18);
query4.limit(10L);
qStr = query4.toString();
Assert.assertTrue(qStr.contains("`Query * from EDGE limit 10 " + "where id in [1, 3] and ["));
Assert.assertTrue(qStr.contains("LABEL == 3"));
Assert.assertTrue(qStr.contains("PROPERTIES < 18"));
}
use of com.baidu.hugegraph.backend.query.ConditionQuery in project incubator-hugegraph by apache.
the class ConditionQueryFlattenTest method testFlattenWithOrAndTree.
@Test
public void testFlattenWithOrAndTree() {
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.and(c2).or(c3.and(c4)));
Assert.assertEquals(1, query.conditions().size());
List<ConditionQuery> queries = ConditionQueryFlatten.flatten(query);
Assert.assertEquals(2, queries.size());
List<Collection<Condition>> expect;
expect = ImmutableList.of(ImmutableList.of(c1, c2), ImmutableList.of(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 ConditionQueryFlattenTest method testFlattenWithOr.
@Test
public void testFlattenWithOr() {
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.or(c2));
Assert.assertEquals(1, query.conditions().size());
List<ConditionQuery> queries = ConditionQueryFlatten.flatten(query);
Assert.assertEquals(2, queries.size());
List<Collection<Condition>> expect;
expect = ImmutableList.of(ImmutableList.of(c1), ImmutableList.of(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 testFlattenWithOrTree.
@Test
public void testFlattenWithOrTree() {
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).or(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), ImmutableList.of(c2), ImmutableList.of(c3), ImmutableList.of(c4));
List<Collection<Condition>> actual = new ArrayList<>();
for (ConditionQuery q : queries) {
actual.add(q.conditions());
}
Assert.assertEquals(expect, actual);
}
Aggregations