Search in sources :

Example 76 with PropertyKey

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

the class VertexLabelBuilder method append.

@Override
public VertexLabel append() {
    VertexLabel vertexLabel = this.vertexLabelOrNull(this.name);
    if (vertexLabel == null) {
        throw new NotFoundException("Can't update vertex label '%s' " + "since it doesn't exist", this.name);
    }
    this.checkStableVars();
    this.checkProperties(Action.APPEND);
    this.checkNullableKeys(Action.APPEND);
    Userdata.check(this.userdata, Action.APPEND);
    for (String key : this.properties) {
        PropertyKey propertyKey = this.graph().propertyKey(key);
        vertexLabel.property(propertyKey.id());
    }
    for (String key : this.nullableKeys) {
        PropertyKey propertyKey = this.graph().propertyKey(key);
        vertexLabel.nullableKey(propertyKey.id());
    }
    vertexLabel.userdata(this.userdata);
    this.graph().addVertexLabel(vertexLabel);
    return vertexLabel;
}
Also used : VertexLabel(com.baidu.hugegraph.schema.VertexLabel) NotFoundException(com.baidu.hugegraph.exception.NotFoundException) PropertyKey(com.baidu.hugegraph.schema.PropertyKey)

Example 77 with PropertyKey

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

the class VertexLabelBuilder method hasSameProperties.

/**
 * Check whether this has same properties with existedVertexLabel.
 * Only properties, primaryKeys, nullableKeys, enableLabelIndex are checked.
 * The id, idStrategy, checkExist, userdata are not checked.
 * @param existedVertexLabel to be compared with
 * @return true if this has same properties with existedVertexLabel
 */
private boolean hasSameProperties(VertexLabel existedVertexLabel) {
    HugeGraph graph = this.graph();
    Set<Id> existedProperties = existedVertexLabel.properties();
    if (this.properties.size() != existedProperties.size()) {
        return false;
    }
    for (String propertyName : this.properties) {
        PropertyKey propertyKey = graph.propertyKey(propertyName);
        if (!existedProperties.contains(propertyKey.id())) {
            return false;
        }
    }
    List<Id> existedPrimaryKeys = existedVertexLabel.primaryKeys();
    if (this.primaryKeys.size() != existedPrimaryKeys.size()) {
        return false;
    }
    for (String primaryKeyName : this.primaryKeys) {
        PropertyKey primaryKey = graph.propertyKey(primaryKeyName);
        if (!existedPrimaryKeys.contains(primaryKey.id())) {
            return false;
        }
    }
    Set<Id> existedNullableKeys = existedVertexLabel.nullableKeys();
    if (this.nullableKeys.size() != existedNullableKeys.size()) {
        return false;
    }
    for (String nullableKeyName : this.nullableKeys) {
        PropertyKey nullableKey = graph.propertyKey(nullableKeyName);
        if (!existedNullableKeys.contains(nullableKey.id())) {
            return false;
        }
    }
    // this.enableLabelIndex == null, it means true.
    if (this.enableLabelIndex == null || this.enableLabelIndex) {
        return existedVertexLabel.enableLabelIndex();
    } else {
        // this.enableLabelIndex is false
        return !existedVertexLabel.enableLabelIndex();
    }
}
Also used : HugeGraph(com.baidu.hugegraph.HugeGraph) Id(com.baidu.hugegraph.backend.id.Id) PropertyKey(com.baidu.hugegraph.schema.PropertyKey)

Example 78 with PropertyKey

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

the class OlapPropertyKeyRemoveJob method execute.

@Override
public Object execute() {
    Id olap = this.schemaId();
    // Remove olap data table
    this.params().graphTransaction().removeOlapPk(olap);
    // Remove corresponding index label and index data
    Id indexLabel = findOlapIndexLabel(this.params(), olap);
    if (indexLabel != null) {
        removeIndexLabel(this.params(), indexLabel);
    }
    // Remove olap property key
    SchemaTransaction schemaTx = this.params().schemaTransaction();
    PropertyKey propertyKey = schemaTx.getPropertyKey(olap);
    removeSchema(schemaTx, propertyKey);
    return null;
}
Also used : Id(com.baidu.hugegraph.backend.id.Id) SchemaTransaction(com.baidu.hugegraph.backend.tx.SchemaTransaction) PropertyKey(com.baidu.hugegraph.schema.PropertyKey)

Example 79 with PropertyKey

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

the class TraversalUtil method transProperties.

public static Map<Id, Object> transProperties(HugeGraph graph, Map<String, Object> props) {
    Map<Id, Object> pks = new HashMap<>(props.size());
    for (Map.Entry<String, Object> e : props.entrySet()) {
        PropertyKey pk = graph.propertyKey(e.getKey());
        pks.put(pk.id(), e.getValue());
    }
    return pks;
}
Also used : HashMap(java.util.HashMap) Id(com.baidu.hugegraph.backend.id.Id) Map(java.util.Map) HashMap(java.util.HashMap) PropertyKey(com.baidu.hugegraph.schema.PropertyKey)

Example 80 with PropertyKey

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

the class TraversalUtil method convCompare2UserpropRelation.

private static Relation convCompare2UserpropRelation(HugeGraph graph, HugeType type, HasContainer has) {
    BiPredicate<?, ?> bp = has.getPredicate().getBiPredicate();
    assert bp instanceof Compare;
    String key = has.getKey();
    PropertyKey pkey = graph.propertyKey(key);
    Id pkeyId = pkey.id();
    Object value = validPropertyValue(has.getValue(), pkey);
    switch((Compare) bp) {
        case eq:
            return Condition.eq(pkeyId, value);
        case gt:
            return Condition.gt(pkeyId, value);
        case gte:
            return Condition.gte(pkeyId, value);
        case lt:
            return Condition.lt(pkeyId, value);
        case lte:
            return Condition.lte(pkeyId, value);
        case neq:
            return Condition.neq(pkeyId, value);
        default:
            throw newUnsupportedPredicate(has.getPredicate());
    }
}
Also used : Compare(org.apache.tinkerpop.gremlin.process.traversal.Compare) Id(com.baidu.hugegraph.backend.id.Id) 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