use of com.baidu.hugegraph.schema.VertexLabel in project incubator-hugegraph by apache.
the class VertexLabelBuilder method checkNullableKeys.
@SuppressWarnings("unchecked")
private void checkNullableKeys(Action action) {
// Not using switch-case to avoid indent too much
if (action == Action.ELIMINATE) {
if (!this.nullableKeys.isEmpty()) {
throw new NotAllowException("Not support to eliminate nullableKeys " + "for vertex label currently");
}
return;
}
VertexLabel vertexLabel = this.vertexLabelOrNull(this.name);
// The originProps is empty when firstly create vertex label
List<String> originProps = vertexLabel == null ? ImmutableList.of() : this.graph().mapPkId2Name(vertexLabel.properties());
Set<String> appendProps = this.properties;
E.checkArgument(CollectionUtil.union(originProps, appendProps).containsAll(this.nullableKeys), "The nullableKeys: %s to be created or appended " + "must belong to the origin/new properties: %s/%s", this.nullableKeys, originProps, appendProps);
List<String> primaryKeys = vertexLabel == null ? this.primaryKeys : this.graph().mapPkId2Name(vertexLabel.primaryKeys());
E.checkArgument(!CollectionUtil.hasIntersection(primaryKeys, this.nullableKeys), "The nullableKeys: %s are not allowed to " + "belong to primaryKeys: %s of vertex label '%s'", this.nullableKeys, primaryKeys, this.name);
if (action == Action.APPEND) {
Collection<String> newAddedProps = CollectionUtils.subtract(appendProps, originProps);
E.checkArgument(this.nullableKeys.containsAll(newAddedProps), "The new added properties: %s must be nullable", newAddedProps);
}
}
use of com.baidu.hugegraph.schema.VertexLabel in project incubator-hugegraph by apache.
the class VertexLabelBuilder method build.
@Override
public VertexLabel build() {
Id id = this.validOrGenerateId(HugeType.VERTEX_LABEL, this.id, this.name);
VertexLabel vertexLabel = new VertexLabel(this.graph(), id, this.name);
vertexLabel.idStrategy(this.idStrategy);
vertexLabel.enableLabelIndex(this.enableLabelIndex == null || this.enableLabelIndex);
vertexLabel.ttl(this.ttl);
if (this.ttlStartTime != null) {
vertexLabel.ttlStartTime(this.graph().propertyKey(this.ttlStartTime).id());
}
// Assign properties
for (String key : this.properties) {
PropertyKey propertyKey = this.graph().propertyKey(key);
vertexLabel.property(propertyKey.id());
}
for (String key : this.primaryKeys) {
PropertyKey propertyKey = this.graph().propertyKey(key);
vertexLabel.primaryKey(propertyKey.id());
}
for (String key : this.nullableKeys) {
PropertyKey propertyKey = this.graph().propertyKey(key);
vertexLabel.nullableKey(propertyKey.id());
}
vertexLabel.userdata(this.userdata);
return vertexLabel;
}
use of com.baidu.hugegraph.schema.VertexLabel in project incubator-hugegraph by apache.
the class VertexLabelRemoveJob method removeVertexLabel.
private static void removeVertexLabel(HugeGraphParams graph, Id id) {
GraphTransaction graphTx = graph.graphTransaction();
SchemaTransaction schemaTx = graph.schemaTransaction();
VertexLabel vertexLabel = schemaTx.getVertexLabel(id);
// If the vertex label does not exist, return directly
if (vertexLabel == null) {
return;
}
if (vertexLabel.status().deleting()) {
LOG.info("The vertex label '{}' has been in {} status, " + "please check if it's expected to delete it again", vertexLabel, vertexLabel.status());
}
// Check no edge label use the vertex label
List<EdgeLabel> edgeLabels = schemaTx.getEdgeLabels();
for (EdgeLabel edgeLabel : edgeLabels) {
if (edgeLabel.linkWithLabel(id)) {
throw new HugeException("Not allowed to remove vertex label '%s' " + "because the edge label '%s' still link with it", vertexLabel.name(), edgeLabel.name());
}
}
/*
* Copy index label ids because removeIndexLabel will mutate
* vertexLabel.indexLabels()
*/
Set<Id> indexLabelIds = ImmutableSet.copyOf(vertexLabel.indexLabels());
LockUtil.Locks locks = new LockUtil.Locks(graph.name());
try {
locks.lockWrites(LockUtil.VERTEX_LABEL_DELETE, id);
schemaTx.updateSchemaStatus(vertexLabel, SchemaStatus.DELETING);
try {
for (Id ilId : indexLabelIds) {
IndexLabelRemoveJob.removeIndexLabel(graph, ilId);
}
// TODO: use event to replace direct call
// Deleting a vertex will automatically deletes the held edge
graphTx.removeVertices(vertexLabel);
/*
* Should commit changes to backend store before release
* delete lock
*/
graph.graph().tx().commit();
// Remove vertex label
removeSchema(schemaTx, vertexLabel);
} catch (Throwable e) {
schemaTx.updateSchemaStatus(vertexLabel, SchemaStatus.UNDELETED);
throw e;
}
} finally {
locks.unlock();
}
}
use of com.baidu.hugegraph.schema.VertexLabel in project incubator-hugegraph by apache.
the class VertexCoreTest method testQueryFilterByPropName.
@Test
public void testQueryFilterByPropName() {
HugeGraph graph = graph();
Assume.assumeTrue("Not support CONTAINS_KEY query", storeFeatures().supportsQueryWithContainsKey());
init10Vertices();
VertexLabel language = graph.vertexLabel("language");
PropertyKey dynamic = graph.propertyKey("dynamic");
// Query vertex by condition (does contain the property name?)
ConditionQuery q = new ConditionQuery(HugeType.VERTEX);
q.eq(HugeKeys.LABEL, language.id());
q.key(HugeKeys.PROPERTIES, dynamic.id());
List<Vertex> vertices = ImmutableList.copyOf(graph.vertices(q));
Assert.assertEquals(1, vertices.size());
assertContains(vertices, T.label, "language", "name", "python", "dynamic", true);
// Query vertex by condition (does contain the property name?)
q = new ConditionQuery(HugeType.VERTEX);
q.key(HugeKeys.PROPERTIES, dynamic.id());
vertices = ImmutableList.copyOf(graph.vertices(q));
Assert.assertEquals(1, vertices.size());
assertContains(vertices, T.label, "language", "name", "python", "dynamic", true);
}
use of com.baidu.hugegraph.schema.VertexLabel in project incubator-hugegraph by apache.
the class VertexLabelCoreTest method testAddVertexLabelWith2PrimaryKey.
@Test
public void testAddVertexLabelWith2PrimaryKey() {
super.initPropertyKeys();
SchemaManager schema = graph().schema();
VertexLabel person = schema.vertexLabel("person").properties("name", "age", "city").primaryKeys("name", "age").create();
Assert.assertNotNull(person);
Assert.assertEquals("person", person.name());
Assert.assertEquals(3, person.properties().size());
assertContainsPk(person.properties(), "name", "age", "city");
Assert.assertEquals(2, person.primaryKeys().size());
assertContainsPk(person.primaryKeys(), "name", "age");
}
Aggregations