use of com.baidu.hugegraph.backend.id.Id in project incubator-hugegraph by apache.
the class Vertices method vertices.
public Iterator<Vertex> vertices(HugeGraph g) {
Map<String, Object> props = this.properties;
E.checkArgument(!((this.ids == null || this.ids.isEmpty()) && (props == null || props.isEmpty()) && this.label == null), "No source vertices provided");
Iterator<Vertex> iterator;
if (this.ids != null && !this.ids.isEmpty()) {
List<Id> sourceIds = new ArrayList<>(this.ids.size());
for (Object id : this.ids) {
sourceIds.add(HugeVertex.getIdValue(id));
}
iterator = g.vertices(sourceIds.toArray());
E.checkArgument(iterator.hasNext(), "Not exist source vertices with ids %s", this.ids);
} else {
ConditionQuery query = new ConditionQuery(HugeType.VERTEX);
if (this.label != null) {
Id label = g.vertexLabel(this.label).id();
query.eq(HugeKeys.LABEL, label);
}
if (props != null && !props.isEmpty()) {
Map<Id, Object> pks = TraversalUtil.transProperties(g, props);
TraversalUtil.fillConditionQuery(query, pks, g);
}
assert !query.empty();
iterator = g.vertices(query);
E.checkArgument(iterator.hasNext(), "Not exist source vertex " + "with label '%s' and properties '%s'", this.label, props);
}
return iterator;
}
use of com.baidu.hugegraph.backend.id.Id in project incubator-hugegraph by apache.
the class FakeObjects method newEdge.
public HugeEdge newEdge(long sourceVertexId, long targetVertexId) {
PropertyKey name = this.newPropertyKey(IdGenerator.of(1), "name");
PropertyKey age = this.newPropertyKey(IdGenerator.of(2), "age", DataType.INT, Cardinality.SINGLE);
PropertyKey city = this.newPropertyKey(IdGenerator.of(3), "city");
PropertyKey date = this.newPropertyKey(IdGenerator.of(4), "date", DataType.DATE);
PropertyKey weight = this.newPropertyKey(IdGenerator.of(5), "weight", DataType.DOUBLE);
VertexLabel vl = this.newVertexLabel(IdGenerator.of(1), "person", IdStrategy.CUSTOMIZE_NUMBER, name.id(), age.id(), city.id());
EdgeLabel el = this.newEdgeLabel(IdGenerator.of(1), "knows", Frequency.SINGLE, vl.id(), vl.id(), date.id(), weight.id());
HugeVertex source = new HugeVertex(this.graph(), IdGenerator.of(sourceVertexId), vl);
source.addProperty(name, "tom");
source.addProperty(age, 18);
source.addProperty(city, "Beijing");
HugeVertex target = new HugeVertex(this.graph(), IdGenerator.of(targetVertexId), vl);
target.addProperty(name, "cat");
target.addProperty(age, 20);
target.addProperty(city, "Shanghai");
Id id = EdgeId.parse("L123456>1>>L987654");
HugeEdge edge = new HugeEdge(this.graph(), id, el);
Whitebox.setInternalState(edge, "sourceVertex", source);
Whitebox.setInternalState(edge, "targetVertex", target);
edge.assignId();
edge.addProperty(date, new Date());
edge.addProperty(weight, 0.75);
return edge;
}
use of com.baidu.hugegraph.backend.id.Id in project incubator-hugegraph by apache.
the class FakeObjects method newEdge.
public HugeEdge newEdge(String sourceVertexId, String targetVertexId) {
PropertyKey name = this.newPropertyKey(IdGenerator.of(1), "name");
PropertyKey age = this.newPropertyKey(IdGenerator.of(2), "age", DataType.INT, Cardinality.SINGLE);
PropertyKey city = this.newPropertyKey(IdGenerator.of(3), "city");
PropertyKey date = this.newPropertyKey(IdGenerator.of(4), "date", DataType.DATE);
PropertyKey weight = this.newPropertyKey(IdGenerator.of(5), "weight", DataType.DOUBLE);
VertexLabel vl = this.newVertexLabel(IdGenerator.of(1), "person", IdStrategy.CUSTOMIZE_NUMBER, name.id(), age.id(), city.id());
EdgeLabel el = this.newEdgeLabel(IdGenerator.of(1), "knows", Frequency.SINGLE, vl.id(), vl.id(), date.id(), weight.id());
HugeVertex source = new HugeVertex(this.graph(), IdGenerator.of(sourceVertexId), vl);
source.addProperty(name, "tom");
source.addProperty(age, 18);
source.addProperty(city, "Beijing");
HugeVertex target = new HugeVertex(this.graph(), IdGenerator.of(targetVertexId), vl);
target.addProperty(name, "cat");
target.addProperty(age, 20);
target.addProperty(city, "Shanghai");
Id id = EdgeId.parse("L123456>1>>L987654");
HugeEdge edge = new HugeEdge(this.graph(), id, el);
Whitebox.setInternalState(edge, "sourceVertex", source);
Whitebox.setInternalState(edge, "targetVertex", target);
edge.assignId();
edge.addProperty(date, new Date());
edge.addProperty(weight, 0.75);
return edge;
}
use of com.baidu.hugegraph.backend.id.Id in project incubator-hugegraph by apache.
the class CacheTest method testMultiThreadsGetWith3Items.
@Test
public void testMultiThreadsGetWith3Items() {
Cache<Id, Object> cache = newCache(10);
Id id1 = IdGenerator.of("1");
cache.update(id1, "value-1");
Id id2 = IdGenerator.of("2");
cache.update(id2, "value-2");
Id id3 = IdGenerator.of("3");
cache.update(id3, "value-3");
Assert.assertEquals(3, cache.size());
runWithThreads(THREADS_NUM, () -> {
for (int i = 0; i < 10000 * 100; i++) {
Assert.assertEquals("value-1", cache.get(id1));
Assert.assertEquals("value-2", cache.get(id2));
Assert.assertEquals("value-2", cache.get(id2));
Assert.assertEquals("value-3", cache.get(id3));
Assert.assertEquals("value-1", cache.get(id1));
}
});
Assert.assertEquals(3, cache.size());
}
use of com.baidu.hugegraph.backend.id.Id in project incubator-hugegraph by apache.
the class CacheTest method testHitsAndMiss.
@Test
public void testHitsAndMiss() {
Cache<Id, Object> cache = newCache();
Assert.assertEquals(false, cache.enableMetrics(true));
Assert.assertEquals(0L, cache.hits());
Assert.assertEquals(0L, cache.miss());
Id id = IdGenerator.of("1");
cache.update(id, "value-1");
Assert.assertEquals(0L, cache.hits());
Assert.assertEquals(0L, cache.miss());
cache.get(IdGenerator.of("not-exist"));
Assert.assertEquals(0L, cache.hits());
Assert.assertEquals(1L, cache.miss());
cache.get(IdGenerator.of("1"));
Assert.assertEquals(1L, cache.hits());
Assert.assertEquals(1L, cache.miss());
cache.get(IdGenerator.of("not-exist"));
Assert.assertEquals(1L, cache.hits());
Assert.assertEquals(2L, cache.miss());
cache.get(IdGenerator.of("1"));
Assert.assertEquals(2L, cache.hits());
Assert.assertEquals(2L, cache.miss());
}
Aggregations