use of com.baidu.hugegraph.backend.query.ConditionQuery in project incubator-hugegraph by apache.
the class EdgeCoreTest method testScanEdgeInPaging.
@Test
public void testScanEdgeInPaging() {
HugeGraph graph = graph();
Assume.assumeTrue("Not support scan", storeFeatures().supportsScanToken() || storeFeatures().supportsScanKeyRange());
init18Edges();
List<Edge> edges = new LinkedList<>();
ConditionQuery query = new ConditionQuery(HugeType.EDGE);
String backend = graph.backend();
if (backend.equals("cassandra") || backend.equals("scylladb")) {
query.scan(String.valueOf(Long.MIN_VALUE), String.valueOf(Long.MAX_VALUE));
} else {
query.scan(BackendTable.ShardSplitter.START, BackendTable.ShardSplitter.END);
}
query.limit(1);
String page = PageInfo.PAGE_NONE;
while (page != null) {
query.page(page);
Iterator<Edge> iterator = graph.edges(query);
while (iterator.hasNext()) {
edges.add(iterator.next());
}
page = PageInfo.pageInfo(iterator);
CloseableIterator.closeIterator(iterator);
}
Assert.assertEquals(18, edges.size());
}
use of com.baidu.hugegraph.backend.query.ConditionQuery in project incubator-hugegraph by apache.
the class EdgeCoreTest method testQueryEdgesByInvalidSysprop.
@Test
public void testQueryEdgesByInvalidSysprop() {
HugeGraph graph = graph();
init18Edges();
List<Edge> edges = graph.traversal().E().hasLabel("know").toList();
Assert.assertEquals(1, edges.size());
HugeEdge edge = (HugeEdge) edges.get(0);
Id id = edge.id();
Id know = edge.schemaLabel().id();
Assert.assertThrows(IllegalArgumentException.class, () -> {
graph.traversal().E().hasLabel("know").has("ID", id).toList();
}, e -> {
Assert.assertContains("Undefined property key: 'ID'", e.getMessage());
});
Assert.assertThrows(IllegalArgumentException.class, () -> {
graph.traversal().E().hasLabel("know").has("NAME", "n1").toList();
}, e -> {
Assert.assertContains("Undefined property key: 'NAME'", e.getMessage());
});
Assert.assertThrows(HugeException.class, () -> {
ConditionQuery query = new ConditionQuery(HugeType.EDGE);
query.eq(HugeKeys.LABEL, know);
query.query(id);
graph.edges(query).hasNext();
}, e -> {
Assert.assertContains("Not supported querying by id and conditions", e.getMessage());
});
Assert.assertThrows(HugeException.class, () -> {
ConditionQuery query = new ConditionQuery(HugeType.EDGE);
query.eq(HugeKeys.LABEL, know);
query.eq(HugeKeys.NAME, "n1");
graph.edges(query).hasNext();
}, e -> {
Assert.assertContains("Not supported querying edges by", e.getMessage());
Assert.assertContains("NAME == n1", e.getMessage());
});
Assert.assertThrows(HugeException.class, () -> {
ConditionQuery query = new ConditionQuery(HugeType.EDGE);
query.eq(HugeKeys.LABEL, know);
query.eq(HugeKeys.NAME, "n2");
query.query(Condition.eq(IdGenerator.of("fake"), "n3"));
graph.edges(query).hasNext();
}, e -> {
Assert.assertContains("Can't do index query with [", e.getMessage());
Assert.assertContains("LABEL == ", e.getMessage());
Assert.assertContains("NAME == n2", e.getMessage());
});
}
use of com.baidu.hugegraph.backend.query.ConditionQuery in project incubator-hugegraph by apache.
the class EdgeCoreTest method testScanEdge.
@Test
public void testScanEdge() {
HugeGraph graph = graph();
Assume.assumeTrue("Not support scan", storeFeatures().supportsScanToken() || storeFeatures().supportsScanKeyRange());
init18Edges();
Set<Edge> edges = new HashSet<>();
long splitSize = 1L * 1024L * 1024L;
List<Shard> splits = graph.metadata(HugeType.EDGE_OUT, "splits", splitSize);
for (Shard split : splits) {
ConditionQuery q = new ConditionQuery(HugeType.EDGE);
q.scan(split.start(), split.end());
edges.addAll(ImmutableList.copyOf(graph.edges(q)));
}
Assert.assertEquals(18, edges.size());
}
use of com.baidu.hugegraph.backend.query.ConditionQuery in project incubator-hugegraph by apache.
the class EdgeCoreTest method testQueryEdgesByDirection.
@Test
public void testQueryEdgesByDirection() {
HugeGraph graph = graph();
init18Edges();
// Query vertex by condition (filter by Direction)
ConditionQuery q = new ConditionQuery(HugeType.EDGE);
q.eq(HugeKeys.DIRECTION, Direction.OUT);
Assert.assertThrows(HugeException.class, () -> {
graph.edges(q);
});
}
use of com.baidu.hugegraph.backend.query.ConditionQuery in project incubator-hugegraph by apache.
the class VertexCoreTest method testQueryByInvalidSysprop.
@Test
public void testQueryByInvalidSysprop() {
HugeGraph graph = graph();
init10Vertices();
List<Vertex> vertices = graph.traversal().V().hasLabel("author").has("id", 1).toList();
Assert.assertEquals(1, vertices.size());
Vertex vertex = vertices.get(0);
Id author = graph.vertexLabel(vertex.label()).id();
Assert.assertThrows(IllegalArgumentException.class, () -> {
graph.traversal().V().hasLabel("author").has("ID", 1).toList();
}, e -> {
Assert.assertContains("Undefined property key: 'ID'", e.getMessage());
});
Assert.assertThrows(IllegalArgumentException.class, () -> {
graph.traversal().V().hasLabel("author").has("NAME", "n1").toList();
}, e -> {
Assert.assertContains("Undefined property key: 'NAME'", e.getMessage());
});
Assert.assertThrows(HugeException.class, () -> {
ConditionQuery query = new ConditionQuery(HugeType.VERTEX);
query.eq(HugeKeys.LABEL, author);
query.query((Id) vertex.id());
graph.vertices(query).hasNext();
}, e -> {
Assert.assertContains("Not supported querying by id and conditions", e.getMessage());
});
Assert.assertThrows(HugeException.class, () -> {
ConditionQuery query = new ConditionQuery(HugeType.VERTEX);
query.eq(HugeKeys.LABEL, author);
query.eq(HugeKeys.NAME, "n1");
graph.vertices(query).hasNext();
}, e -> {
Assert.assertContains("Not supported querying vertices by", e.getMessage());
Assert.assertContains("NAME == n1", e.getMessage());
});
Assert.assertThrows(HugeException.class, () -> {
ConditionQuery query = new ConditionQuery(HugeType.VERTEX);
query.eq(HugeKeys.LABEL, author);
query.eq(HugeKeys.NAME, "n2");
query.query(Condition.eq(IdGenerator.of("fake"), "n3"));
graph.vertices(query).hasNext();
}, e -> {
Assert.assertContains("Can't do index query with [", e.getMessage());
Assert.assertContains("LABEL == ", e.getMessage());
Assert.assertContains("NAME == n2", e.getMessage());
});
}
Aggregations