Search in sources :

Example 71 with PropertyKey

use of com.baidu.hugegraph.schema.PropertyKey in project incubator-hugegraph by apache.

the class EdgeLabelBuilder method build.

@Override
public EdgeLabel build() {
    Id id = this.validOrGenerateId(HugeType.EDGE_LABEL, this.id, this.name);
    HugeGraph graph = this.graph();
    EdgeLabel edgeLabel = new EdgeLabel(graph, id, this.name);
    edgeLabel.sourceLabel(graph.vertexLabel(this.sourceLabel).id());
    edgeLabel.targetLabel(graph.vertexLabel(this.targetLabel).id());
    edgeLabel.frequency(this.frequency == Frequency.DEFAULT ? Frequency.SINGLE : this.frequency);
    edgeLabel.ttl(this.ttl);
    if (this.ttlStartTime != null) {
        edgeLabel.ttlStartTime(this.graph().propertyKey(this.ttlStartTime).id());
    }
    edgeLabel.enableLabelIndex(this.enableLabelIndex == null || this.enableLabelIndex);
    for (String key : this.properties) {
        PropertyKey propertyKey = graph.propertyKey(key);
        edgeLabel.property(propertyKey.id());
    }
    for (String key : this.sortKeys) {
        PropertyKey propertyKey = graph.propertyKey(key);
        edgeLabel.sortKey(propertyKey.id());
    }
    for (String key : this.nullableKeys) {
        PropertyKey propertyKey = graph.propertyKey(key);
        edgeLabel.nullableKey(propertyKey.id());
    }
    edgeLabel.userdata(this.userdata);
    return edgeLabel;
}
Also used : HugeGraph(com.baidu.hugegraph.HugeGraph) EdgeLabel(com.baidu.hugegraph.schema.EdgeLabel) Id(com.baidu.hugegraph.backend.id.Id) PropertyKey(com.baidu.hugegraph.schema.PropertyKey)

Example 72 with PropertyKey

use of com.baidu.hugegraph.schema.PropertyKey in project incubator-hugegraph by apache.

the class EdgeLabelBuilder method checkTtl.

private void checkTtl() {
    E.checkArgument(this.ttl >= 0, "The ttl must be >= 0, but got: %s", this.ttl);
    if (this.ttl == 0L) {
        E.checkArgument(this.ttlStartTime == null, "Can't set ttl start time if ttl is not set");
        return;
    }
    VertexLabel source = this.graph().vertexLabel(this.sourceLabel);
    VertexLabel target = this.graph().vertexLabel(this.targetLabel);
    E.checkArgument((source.ttl() == 0L || this.ttl <= source.ttl()) && (target.ttl() == 0L || this.ttl <= target.ttl()), "The ttl(%s) of edge label '%s' should less than " + "ttl(%s) of source label '%s' and ttl(%s) of target " + "label '%s'", this.ttl, this.name, source.ttl(), this.sourceLabel, target.ttl(), this.targetLabel);
    if (this.ttlStartTime == null) {
        return;
    }
    // Check whether the properties contains the specified keys
    E.checkArgument(!this.properties.isEmpty(), "The properties can't be empty when exist " + "ttl start time for edge label '%s'", this.name);
    E.checkArgument(this.properties.contains(this.ttlStartTime), "The ttl start time '%s' must be contained in " + "properties '%s' for edge label '%s'", this.ttlStartTime, this.name, this.properties);
    PropertyKey pkey = this.graph().propertyKey(this.ttlStartTime);
    E.checkArgument(pkey.dataType().isDate(), "The ttl start time property must be date type," + "but got '%s(%s)'", this.ttlStartTime, pkey.dataType());
}
Also used : VertexLabel(com.baidu.hugegraph.schema.VertexLabel) PropertyKey(com.baidu.hugegraph.schema.PropertyKey)

Example 73 with PropertyKey

use of com.baidu.hugegraph.schema.PropertyKey in project incubator-hugegraph by apache.

the class HugeVertex method property.

@Watched(prefix = "vertex")
@Override
public <V> VertexProperty<V> property(VertexProperty.Cardinality cardinality, String key, V value, Object... objects) {
    if (objects.length != 0 && objects[0].equals(T.id)) {
        throw VertexProperty.Exceptions.userSuppliedIdsNotSupported();
    }
    // TODO: extra props: objects
    if (objects.length != 0) {
        throw VertexProperty.Exceptions.metaPropertiesNotSupported();
    }
    PropertyKey propertyKey = this.graph().propertyKey(key);
    /*
         * g.AddV("xxx").property("key1", val1).property("key2", val2)
         * g.AddV("xxx").property(single, "key1", val1)
         *              .property(list, "key2", val2)
         *
         * The cardinality single may be user supplied single, it may also be
         * that user doesn't supplied cardinality, when it is latter situation,
         * we shouldn't check it. Because of this reason, we are forced to
         * give up the check of user supplied cardinality single.
         * The cardinality not single must be user supplied, so should check it
         */
    if (cardinality != VertexProperty.Cardinality.single) {
        E.checkArgument(propertyKey.cardinality() == Cardinality.convert(cardinality), "Invalid cardinality '%s' for property key '%s', " + "expect '%s'", cardinality, key, propertyKey.cardinality().string());
    }
    // Check key in vertex label
    E.checkArgument(VertexLabel.OLAP_VL.equals(this.label) || this.label.properties().contains(propertyKey.id()), "Invalid property '%s' for vertex label '%s'", key, this.label);
    // Primary-Keys can only be set once
    if (this.schemaLabel().primaryKeys().contains(propertyKey.id())) {
        E.checkArgument(!this.hasProperty(propertyKey.id()), "Can't update primary key: '%s'", key);
    }
    @SuppressWarnings("unchecked") VertexProperty<V> prop = (VertexProperty<V>) this.addProperty(propertyKey, value, !this.fresh());
    return prop;
}
Also used : VertexProperty(org.apache.tinkerpop.gremlin.structure.VertexProperty) PropertyKey(com.baidu.hugegraph.schema.PropertyKey) Watched(com.baidu.hugegraph.perf.PerfUtil.Watched)

Example 74 with PropertyKey

use of com.baidu.hugegraph.schema.PropertyKey in project incubator-hugegraph by apache.

the class PropertyKeyBuilder method createWithTask.

@Override
public SchemaElement.TaskWithSchema createWithTask() {
    HugeType type = HugeType.PROPERTY_KEY;
    this.checkSchemaName(this.name);
    return this.lockCheckAndCreateSchema(type, this.name, name -> {
        PropertyKey propertyKey = this.propertyKeyOrNull(name);
        if (propertyKey != null) {
            if (this.checkExist || !hasSameProperties(propertyKey)) {
                throw new ExistedException(type, name);
            }
            return new SchemaElement.TaskWithSchema(propertyKey, IdGenerator.ZERO);
        }
        this.checkSchemaIdIfRestoringMode(type, this.id);
        Userdata.check(this.userdata, Action.INSERT);
        this.checkAggregateType();
        this.checkOlap();
        propertyKey = this.build();
        assert propertyKey.name().equals(name);
        Id id = this.graph().addPropertyKey(propertyKey);
        return new SchemaElement.TaskWithSchema(propertyKey, id);
    });
}
Also used : ExistedException(com.baidu.hugegraph.exception.ExistedException) Id(com.baidu.hugegraph.backend.id.Id) HugeType(com.baidu.hugegraph.type.HugeType) PropertyKey(com.baidu.hugegraph.schema.PropertyKey)

Example 75 with PropertyKey

use of com.baidu.hugegraph.schema.PropertyKey in project incubator-hugegraph by apache.

the class PropertyKeyBuilder method append.

@Override
public PropertyKey append() {
    PropertyKey propertyKey = this.propertyKeyOrNull(this.name);
    if (propertyKey == null) {
        throw new NotFoundException("Can't update property key '%s' " + "since it doesn't exist", this.name);
    }
    this.checkStableVars();
    Userdata.check(this.userdata, Action.APPEND);
    propertyKey.userdata(this.userdata);
    this.graph().addPropertyKey(propertyKey);
    return propertyKey;
}
Also used : NotFoundException(com.baidu.hugegraph.exception.NotFoundException) PropertyKey(com.baidu.hugegraph.schema.PropertyKey)

Aggregations

PropertyKey (com.baidu.hugegraph.schema.PropertyKey)94 Id (com.baidu.hugegraph.backend.id.Id)31 Test (org.junit.Test)24 VertexLabel (com.baidu.hugegraph.schema.VertexLabel)20 SchemaManager (com.baidu.hugegraph.schema.SchemaManager)15 HugeGraph (com.baidu.hugegraph.HugeGraph)13 EdgeLabel (com.baidu.hugegraph.schema.EdgeLabel)11 EdgeId (com.baidu.hugegraph.backend.id.EdgeId)9 HugeVertex (com.baidu.hugegraph.structure.HugeVertex)9 BaseUnitTest (com.baidu.hugegraph.unit.BaseUnitTest)9 ConditionQuery (com.baidu.hugegraph.backend.query.ConditionQuery)7 FakeObjects (com.baidu.hugegraph.unit.FakeObjects)7 Watched (com.baidu.hugegraph.perf.PerfUtil.Watched)6 HugeEdge (com.baidu.hugegraph.structure.HugeEdge)6 DataType (com.baidu.hugegraph.type.define.DataType)6 Map (java.util.Map)6 IndexLabel (com.baidu.hugegraph.schema.IndexLabel)5 Timed (com.codahale.metrics.annotation.Timed)5 RolesAllowed (jakarta.annotation.security.RolesAllowed)5 Collection (java.util.Collection)5