Search in sources :

Example 26 with PropertyKey

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

the class TableSerializer method readPropertyKey.

@Override
public PropertyKey readPropertyKey(HugeGraph graph, BackendEntry backendEntry) {
    if (backendEntry == null) {
        return null;
    }
    TableBackendEntry entry = this.convertEntry(backendEntry);
    Number id = schemaColumn(entry, HugeKeys.ID);
    String name = schemaColumn(entry, HugeKeys.NAME);
    DataType dataType = schemaEnum(entry, HugeKeys.DATA_TYPE, DataType.class);
    Cardinality cardinality = schemaEnum(entry, HugeKeys.CARDINALITY, Cardinality.class);
    AggregateType aggregateType = schemaEnum(entry, HugeKeys.AGGREGATE_TYPE, AggregateType.class);
    WriteType writeType = schemaEnumOrDefault(entry, HugeKeys.WRITE_TYPE, WriteType.class, WriteType.OLTP);
    Object properties = schemaColumn(entry, HugeKeys.PROPERTIES);
    SchemaStatus status = schemaEnum(entry, HugeKeys.STATUS, SchemaStatus.class);
    PropertyKey propertyKey = new PropertyKey(graph, this.toId(id), name);
    propertyKey.dataType(dataType);
    propertyKey.cardinality(cardinality);
    propertyKey.aggregateType(aggregateType);
    propertyKey.writeType(writeType);
    propertyKey.properties(this.toIdArray(properties));
    propertyKey.status(status);
    this.readUserdata(propertyKey, entry);
    return propertyKey;
}
Also used : Cardinality(com.baidu.hugegraph.type.define.Cardinality) WriteType(com.baidu.hugegraph.type.define.WriteType) DataType(com.baidu.hugegraph.type.define.DataType) AggregateType(com.baidu.hugegraph.type.define.AggregateType) SchemaStatus(com.baidu.hugegraph.type.define.SchemaStatus) PropertyKey(com.baidu.hugegraph.schema.PropertyKey)

Example 27 with PropertyKey

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

the class BinarySerializer method parseProperty.

protected void parseProperty(Id pkeyId, BytesBuffer buffer, HugeElement owner) {
    PropertyKey pkey = owner.graph().propertyKey(pkeyId);
    // Parse value
    Object value = buffer.readProperty(pkey);
    // Set properties of vertex/edge
    if (pkey.cardinality() == Cardinality.SINGLE) {
        owner.addProperty(pkey, value);
    } else {
        if (!(value instanceof Collection)) {
            throw new BackendException("Invalid value of non-single property: %s", value);
        }
        owner.addProperty(pkey, value);
    }
}
Also used : Collection(java.util.Collection) PropertyKey(com.baidu.hugegraph.schema.PropertyKey) BackendException(com.baidu.hugegraph.backend.BackendException)

Example 28 with PropertyKey

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

the class TextSerializer method readPropertyKey.

@Override
public PropertyKey readPropertyKey(HugeGraph graph, BackendEntry backendEntry) {
    if (backendEntry == null) {
        return null;
    }
    TextBackendEntry entry = this.convertEntry(backendEntry);
    Id id = readId(entry.id());
    String name = JsonUtil.fromJson(entry.column(HugeKeys.NAME), String.class);
    String dataType = entry.column(HugeKeys.DATA_TYPE);
    String cardinality = entry.column(HugeKeys.CARDINALITY);
    String aggregateType = entry.column(HugeKeys.AGGREGATE_TYPE);
    String writeType = entry.column(HugeKeys.WRITE_TYPE);
    String properties = entry.column(HugeKeys.PROPERTIES);
    String status = entry.column(HugeKeys.STATUS);
    PropertyKey propertyKey = new PropertyKey(graph, id, name);
    propertyKey.dataType(JsonUtil.fromJson(dataType, DataType.class));
    propertyKey.cardinality(JsonUtil.fromJson(cardinality, Cardinality.class));
    propertyKey.aggregateType(JsonUtil.fromJson(aggregateType, AggregateType.class));
    propertyKey.writeType(JsonUtil.fromJson(writeType, WriteType.class));
    propertyKey.properties(readIds(properties));
    readUserdata(propertyKey, entry);
    propertyKey.status(JsonUtil.fromJson(status, SchemaStatus.class));
    return propertyKey;
}
Also used : Cardinality(com.baidu.hugegraph.type.define.Cardinality) WriteType(com.baidu.hugegraph.type.define.WriteType) DataType(com.baidu.hugegraph.type.define.DataType) Id(com.baidu.hugegraph.backend.id.Id) EdgeId(com.baidu.hugegraph.backend.id.EdgeId) AggregateType(com.baidu.hugegraph.type.define.AggregateType) SchemaStatus(com.baidu.hugegraph.type.define.SchemaStatus) PropertyKey(com.baidu.hugegraph.schema.PropertyKey)

Example 29 with PropertyKey

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

the class TraversalUtil method fillConditionQuery.

public static void fillConditionQuery(ConditionQuery query, Map<Id, Object> properties, HugeGraph graph) {
    for (Map.Entry<Id, Object> entry : properties.entrySet()) {
        Id key = entry.getKey();
        Object value = entry.getValue();
        PropertyKey pk = graph.propertyKey(key);
        if (value instanceof String && ((String) value).startsWith(TraversalUtil.P_CALL)) {
            String predicate = (String) value;
            query.query(TraversalUtil.parsePredicate(pk, predicate));
        } else if (value instanceof Collection) {
            List<Object> validValues = new ArrayList<>();
            for (Object v : (Collection<?>) value) {
                validValues.add(TraversalUtil.validPropertyValue(v, pk));
            }
            query.query(Condition.in(key, validValues));
        } else {
            Object validValue = TraversalUtil.validPropertyValue(value, pk);
            query.query(Condition.eq(key, validValue));
        }
    }
}
Also used : Collection(java.util.Collection) List(java.util.List) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) Id(com.baidu.hugegraph.backend.id.Id) Map(java.util.Map) HashMap(java.util.HashMap) PropertyKey(com.baidu.hugegraph.schema.PropertyKey)

Example 30 with PropertyKey

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

the class TraversalUtil method convRelationType2Relation.

private static Condition convRelationType2Relation(HugeGraph graph, HugeType type, HasContainer has) {
    assert type.isGraph();
    BiPredicate<?, ?> bp = has.getPredicate().getBiPredicate();
    assert bp instanceof RelationType;
    String key = has.getKey();
    PropertyKey pkey = graph.propertyKey(key);
    Id pkeyId = pkey.id();
    Object value = validPropertyValue(has.getValue(), pkey);
    return new Condition.UserpropRelation(pkeyId, (RelationType) bp, value);
}
Also used : RelationType(com.baidu.hugegraph.backend.query.Condition.RelationType) 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