use of com.baidu.hugegraph.schema.VertexLabel 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.schema.VertexLabel in project incubator-hugegraph by apache.
the class VertexLabelCoreTest method testAddVertexLabelWithDisableLabelIndex.
@Test
public void testAddVertexLabelWithDisableLabelIndex() {
super.initPropertyKeys();
HugeGraph graph = graph();
SchemaManager schema = graph.schema();
VertexLabel person = schema.vertexLabel("person").properties("name", "age", "city").primaryKeys("name").nullableKeys("city").enableLabelIndex(false).create();
Assert.assertEquals(false, person.enableLabelIndex());
graph.addVertex(T.label, "person", "name", "marko", "age", 18);
graph.addVertex(T.label, "person", "name", "josh", "age", 20);
graph().tx().commit();
List<Vertex> persons;
if (!storeFeatures().supportsQueryByLabel()) {
Assert.assertThrows(NoIndexException.class, () -> {
graph.traversal().V().hasLabel("person").toList();
});
} else {
persons = graph.traversal().V().hasLabel("person").toList();
Assert.assertEquals(2, persons.size());
}
}
use of com.baidu.hugegraph.schema.VertexLabel in project incubator-hugegraph by apache.
the class VertexLabelCoreTest method testAddVertexWithPrimaryKeyIdStrategyAndPassedPk.
@Test
public void testAddVertexWithPrimaryKeyIdStrategyAndPassedPk() {
super.initPropertyKeys();
HugeGraph graph = graph();
SchemaManager schema = graph.schema();
VertexLabel person = schema.vertexLabel("person").usePrimaryKeyId().properties("name", "age").primaryKeys("name").create();
Assert.assertEquals(IdStrategy.PRIMARY_KEY, person.idStrategy());
}
use of com.baidu.hugegraph.schema.VertexLabel in project incubator-hugegraph by apache.
the class VertexLabelCoreTest method testAddVertexLabelWithNonPKIdStrategyWithoutProperty.
@Test
public void testAddVertexLabelWithNonPKIdStrategyWithoutProperty() {
HugeGraph graph = graph();
SchemaManager schema = graph.schema();
VertexLabel person1 = schema.vertexLabel("person1").useAutomaticId().create();
Assert.assertEquals(IdStrategy.AUTOMATIC, person1.idStrategy());
Assert.assertTrue(person1.properties().isEmpty());
VertexLabel person2 = schema.vertexLabel("person2").useCustomizeStringId().create();
Assert.assertEquals(IdStrategy.CUSTOMIZE_STRING, person2.idStrategy());
Assert.assertTrue(person2.properties().isEmpty());
VertexLabel person3 = schema.vertexLabel("person3").useCustomizeNumberId().create();
Assert.assertEquals(IdStrategy.CUSTOMIZE_NUMBER, person3.idStrategy());
Assert.assertTrue(person3.properties().isEmpty());
}
use of com.baidu.hugegraph.schema.VertexLabel in project incubator-hugegraph by apache.
the class VertexLabelCoreTest method testAddVertexWithCustomizeIdStrategyAndNotPassedPk.
@Test
public void testAddVertexWithCustomizeIdStrategyAndNotPassedPk() {
super.initPropertyKeys();
HugeGraph graph = graph();
SchemaManager schema = graph.schema();
VertexLabel person = schema.vertexLabel("person").useCustomizeStringId().properties("name", "age").create();
Assert.assertEquals(IdStrategy.CUSTOMIZE_STRING, person.idStrategy());
VertexLabel player = schema.vertexLabel("player").useCustomizeNumberId().properties("name", "age").create();
Assert.assertEquals(IdStrategy.CUSTOMIZE_NUMBER, player.idStrategy());
}
Aggregations