Search in sources :

Example 6 with PropertyKey

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

the class IndexLabelBuilder method checkFields4Range.

private void checkFields4Range() {
    if (this.indexType != IndexType.RANGE) {
        return;
    }
    List<String> fields = this.indexFields;
    E.checkArgument(fields.size() == 1, "Range index can only build on " + "one field, but got %s fields: '%s'", fields.size(), fields);
    String field = fields.iterator().next();
    PropertyKey property = this.graph().propertyKey(field);
    E.checkArgument(!property.cardinality().multiple(), "Not allowed to build range index on property " + "'%s' whose cardinality is multiple", field);
    DataType dataType = this.graph().propertyKey(field).dataType();
    E.checkArgument(dataType.isNumber() || dataType.isDate(), "Range index can only build on numeric or " + "date property, but got %s(%s)", dataType, field);
    switch(dataType) {
        case BYTE:
        case INT:
            this.indexType = IndexType.RANGE_INT;
            break;
        case FLOAT:
            this.indexType = IndexType.RANGE_FLOAT;
            break;
        case LONG:
        case DATE:
            this.indexType = IndexType.RANGE_LONG;
            break;
        case DOUBLE:
            this.indexType = IndexType.RANGE_DOUBLE;
            break;
        default:
            throw new AssertionError("Invalid datatype: " + dataType);
    }
}
Also used : DataType(com.baidu.hugegraph.type.define.DataType) PropertyKey(com.baidu.hugegraph.schema.PropertyKey)

Example 7 with PropertyKey

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

the class IndexLabelBuilder method checkFields.

private void checkFields(Set<Id> propertyIds) {
    List<String> fields = this.indexFields;
    E.checkNotEmpty(fields, "index fields", this.name);
    Set<Id> olapPks = new IdSet(CollectionType.EC);
    for (String field : fields) {
        PropertyKey pkey = this.propertyKeyOrNull(field);
        // In general this will not happen
        E.checkArgument(pkey != null, "Can't build index on undefined property key " + "'%s' for '%s': '%s'", field, this.baseType.readableName(), this.baseValue);
        E.checkArgument(pkey.aggregateType().isIndexable(), "The aggregate type %s is not indexable", pkey.aggregateType());
        if (pkey.cardinality().multiple()) {
            E.checkArgument(fields.size() == 1, "Not allowed to build union index on property" + " key '%s' whose cardinality is multiple", pkey.name());
        }
        if (pkey.olap()) {
            olapPks.add(pkey.id());
        }
    }
    if (!olapPks.isEmpty()) {
        E.checkArgument(olapPks.size() == 1, "Can't build index on multiple olap properties, " + "but got fields '%s' for index label '%s'", fields, this.name);
        E.checkArgument(olapPks.size() == fields.size(), "Can't build index on olap properties and oltp " + "properties in one index label, " + "but got fields '%s' for index label '%s'", fields, this.name);
        E.checkArgument(this.indexType == IndexType.SECONDARY || this.indexType == IndexType.RANGE, "Only secondary and range index can be built on " + "olap property, but got index type '%s' on olap " + "property key '%s' for index label '%s'", this.indexType, fields.get(0), this.name);
    }
    List<String> properties = this.graph().mapPkId2Name(propertyIds);
    E.checkArgument(properties.containsAll(fields), "Not all index fields '%s' are contained in " + "schema properties '%s'", fields, properties);
    // Range index must build on single numeric column
    if (this.indexType == IndexType.RANGE) {
        this.checkFields4Range();
    }
    // Search index must build on single text column
    if (this.indexType.isSearch()) {
        E.checkArgument(fields.size() == 1, "Search index can only build on " + "one field, but got %s fields: '%s'", fields.size(), fields);
        String field = fields.iterator().next();
        DataType dataType = this.graph().propertyKey(field).dataType();
        E.checkArgument(dataType.isText(), "Search index can only build on text property, " + "but got %s(%s)", dataType, field);
    }
}
Also used : IdSet(com.baidu.hugegraph.util.collection.IdSet) DataType(com.baidu.hugegraph.type.define.DataType) Id(com.baidu.hugegraph.backend.id.Id) PropertyKey(com.baidu.hugegraph.schema.PropertyKey)

Example 8 with PropertyKey

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

the class IndexLabelBuilder method oneNumericField.

private boolean oneNumericField() {
    if (this.indexFields.size() != 1) {
        return false;
    }
    String field = this.indexFields.get(0);
    PropertyKey propertyKey = this.graph().propertyKey(field);
    DataType dataType = propertyKey.dataType();
    return dataType.isNumber() || dataType.isDate();
}
Also used : DataType(com.baidu.hugegraph.type.define.DataType) PropertyKey(com.baidu.hugegraph.schema.PropertyKey)

Example 9 with PropertyKey

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

the class HugeEdge method property.

@Override
public <V> Property<V> property(String key, V value) {
    PropertyKey propertyKey = this.graph().propertyKey(key);
    // Check key in edge label
    E.checkArgument(this.label.properties().contains(propertyKey.id()), "Invalid property '%s' for edge label '%s'", key, this.label());
    // Sort-Keys can only be set once
    if (this.schemaLabel().sortKeys().contains(propertyKey.id())) {
        E.checkArgument(!this.hasProperty(propertyKey.id()), "Can't update sort key: '%s'", key);
    }
    return this.addProperty(propertyKey, value, !this.fresh());
}
Also used : PropertyKey(com.baidu.hugegraph.schema.PropertyKey)

Example 10 with PropertyKey

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

the class PropertyKeyBuilder method build.

@Override
public PropertyKey build() {
    Id id = this.validOrGenerateId(HugeType.PROPERTY_KEY, this.id, this.name);
    PropertyKey propertyKey = new PropertyKey(this.graph(), id, this.name);
    propertyKey.dataType(this.dataType);
    propertyKey.cardinality(this.cardinality);
    propertyKey.aggregateType(this.aggregateType);
    propertyKey.writeType(this.writeType);
    propertyKey.userdata(this.userdata);
    return propertyKey;
}
Also used : 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