Search in sources :

Example 26 with Id

use of com.baidu.hugegraph.backend.id.Id 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 27 with Id

use of com.baidu.hugegraph.backend.id.Id in project incubator-hugegraph by apache.

the class HugeEdge method properties.

@Watched(prefix = "edge")
// (Property<V>) prop
@SuppressWarnings("unchecked")
@Override
public <V> Iterator<Property<V>> properties(String... keys) {
    this.ensureFilledProperties(true);
    // Capacity should be about the following size
    int propsCapacity = keys.length == 0 ? this.sizeOfProperties() : keys.length;
    List<Property<V>> props = new ArrayList<>(propsCapacity);
    if (keys.length == 0) {
        for (HugeProperty<?> prop : this.getProperties()) {
            assert prop instanceof Property;
            props.add((Property<V>) prop);
        }
    } else {
        for (String key : keys) {
            Id pkeyId;
            try {
                pkeyId = this.graph().propertyKey(key).id();
            } catch (IllegalArgumentException ignored) {
                continue;
            }
            HugeProperty<?> prop = this.getProperty(pkeyId);
            if (prop == null) {
                // Not found
                continue;
            }
            assert prop instanceof Property;
            props.add((Property<V>) prop);
        }
    }
    return props.iterator();
}
Also used : ArrayList(java.util.ArrayList) EdgeId(com.baidu.hugegraph.backend.id.EdgeId) Id(com.baidu.hugegraph.backend.id.Id) Property(org.apache.tinkerpop.gremlin.structure.Property) Watched(com.baidu.hugegraph.perf.PerfUtil.Watched)

Example 28 with Id

use of com.baidu.hugegraph.backend.id.Id in project incubator-hugegraph by apache.

the class HugeEdge method sortValues.

@Watched(prefix = "edge")
protected List<Object> sortValues() {
    List<Id> sortKeys = this.schemaLabel().sortKeys();
    if (sortKeys.isEmpty()) {
        return ImmutableList.of();
    }
    List<Object> propValues = new ArrayList<>(sortKeys.size());
    for (Id sk : sortKeys) {
        HugeProperty<?> property = this.getProperty(sk);
        E.checkState(property != null, "The value of sort key '%s' can't be null", sk);
        Object propValue = property.serialValue(true);
        if (Strings.EMPTY.equals(propValue)) {
            propValue = ConditionQuery.INDEX_VALUE_EMPTY;
        }
        propValues.add(propValue);
    }
    return propValues;
}
Also used : ArrayList(java.util.ArrayList) EdgeId(com.baidu.hugegraph.backend.id.EdgeId) Id(com.baidu.hugegraph.backend.id.Id) Watched(com.baidu.hugegraph.perf.PerfUtil.Watched)

Example 29 with Id

use of com.baidu.hugegraph.backend.id.Id 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)

Example 30 with Id

use of com.baidu.hugegraph.backend.id.Id in project incubator-hugegraph by apache.

the class PropertyKeyBuilder method create.

@Override
public PropertyKey create() {
    // Create index label async
    SchemaElement.TaskWithSchema propertyKeyWithTask = this.createWithTask();
    Id task = propertyKeyWithTask.task();
    if (task == IdGenerator.ZERO) {
        /*
             * Task id will be IdGenerator.ZERO if creating property key
             * already exists or creating property key is oltp
             */
        return propertyKeyWithTask.propertyKey();
    }
    // Wait task completed (change to sync mode)
    HugeGraph graph = this.graph();
    long timeout = graph.option(CoreOptions.TASK_WAIT_TIMEOUT);
    try {
        graph.taskScheduler().waitUntilTaskCompleted(task, timeout);
    } catch (TimeoutException e) {
        throw new HugeException("Failed to wait property key create task completed", e);
    }
    // Return property key without task-info
    return propertyKeyWithTask.propertyKey();
}
Also used : HugeGraph(com.baidu.hugegraph.HugeGraph) SchemaElement(com.baidu.hugegraph.schema.SchemaElement) Id(com.baidu.hugegraph.backend.id.Id) HugeException(com.baidu.hugegraph.HugeException) TimeoutException(java.util.concurrent.TimeoutException)

Aggregations

Id (com.baidu.hugegraph.backend.id.Id)381 Test (org.junit.Test)124 HugeGraph (com.baidu.hugegraph.HugeGraph)104 EdgeId (com.baidu.hugegraph.backend.id.EdgeId)71 BaseUnitTest (com.baidu.hugegraph.unit.BaseUnitTest)54 Timed (com.codahale.metrics.annotation.Timed)41 Produces (jakarta.ws.rs.Produces)40 AuthManager (com.baidu.hugegraph.auth.AuthManager)39 HugeVertex (com.baidu.hugegraph.structure.HugeVertex)37 ArrayList (java.util.ArrayList)35 HugeEdge (com.baidu.hugegraph.structure.HugeEdge)33 Vertex (org.apache.tinkerpop.gremlin.structure.Vertex)33 Watched (com.baidu.hugegraph.perf.PerfUtil.Watched)32 PropertyKey (com.baidu.hugegraph.schema.PropertyKey)32 Directions (com.baidu.hugegraph.type.define.Directions)29 ConditionQuery (com.baidu.hugegraph.backend.query.ConditionQuery)25 IndexLabel (com.baidu.hugegraph.schema.IndexLabel)25 VertexLabel (com.baidu.hugegraph.schema.VertexLabel)24 Edge (org.apache.tinkerpop.gremlin.structure.Edge)22 HugeType (com.baidu.hugegraph.type.HugeType)21