Search in sources :

Example 66 with PropertyKey

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

the class AbstractTransaction method injectOlapPkIfNeeded.

private void injectOlapPkIfNeeded(Query query) {
    if (!query.resultType().isVertex() || !this.graph.readMode().showOlap()) {
        return;
    }
    /*
         * Control olap access by auth, only accessible olap property key
         * will be queried
         */
    Set<Id> olapPks = new IdSet(CollectionType.EC);
    for (PropertyKey propertyKey : this.graph.graph().propertyKeys()) {
        if (propertyKey.olap()) {
            olapPks.add(propertyKey.id());
        }
    }
    query.olapPks(olapPks);
}
Also used : IdSet(com.baidu.hugegraph.util.collection.IdSet) Id(com.baidu.hugegraph.backend.id.Id) PropertyKey(com.baidu.hugegraph.schema.PropertyKey)

Example 67 with PropertyKey

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

the class IndexLabelBuilder method build.

@Override
public IndexLabel build() {
    Id id = this.validOrGenerateId(HugeType.INDEX_LABEL, this.id, this.name);
    this.checkBaseType();
    this.checkIndexType();
    HugeGraph graph = this.graph();
    this.checkFields4Range();
    IndexLabel indexLabel = new IndexLabel(graph, id, this.name);
    indexLabel.baseType(this.baseType);
    SchemaLabel schemaLabel = this.loadBaseLabel();
    indexLabel.baseValue(schemaLabel.id());
    indexLabel.indexType(this.indexType);
    for (String field : this.indexFields) {
        PropertyKey propertyKey = graph.propertyKey(field);
        indexLabel.indexField(propertyKey.id());
    }
    indexLabel.userdata(this.userdata);
    return indexLabel;
}
Also used : HugeGraph(com.baidu.hugegraph.HugeGraph) IndexLabel(com.baidu.hugegraph.schema.IndexLabel) SchemaLabel(com.baidu.hugegraph.schema.SchemaLabel) Id(com.baidu.hugegraph.backend.id.Id) PropertyKey(com.baidu.hugegraph.schema.PropertyKey)

Example 68 with PropertyKey

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

the class IndexLabelBuilder method hasSameProperties.

/**
 * Check whether this has same properties with existedIndexLabel.
 * Only baseType, baseValue, indexType, indexFields are checked.
 * The id, checkExist, userdata are not checked.
 * @param existedIndexLabel to be compared with
 * @return true if this has same properties with existedIndexLabel
 */
private boolean hasSameProperties(IndexLabel existedIndexLabel) {
    // baseType is null, it means HugeType.SYS_SCHEMA
    if ((this.baseType == null && existedIndexLabel.baseType() != HugeType.SYS_SCHEMA) || (this.baseType != null && this.baseType != existedIndexLabel.baseType())) {
        return false;
    }
    SchemaLabel schemaLabel = this.loadBaseLabel();
    if (!schemaLabel.id().equals(existedIndexLabel.baseValue())) {
        return false;
    }
    if (this.indexType == null) {
        // The default index type is SECONDARY
        if (existedIndexLabel.indexType() != IndexType.SECONDARY) {
            return false;
        }
    } else {
        // NOTE: IndexType.RANGE.isRange() return false
        if (this.indexType == IndexType.RANGE) {
            // existedIndexLabel index type format: RANGE_INT, RANGE_LONG
            if (!existedIndexLabel.indexType().isRange()) {
                return false;
            }
        } else if (this.indexType != existedIndexLabel.indexType()) {
            return false;
        }
    }
    List<Id> existedIndexFieldIds = existedIndexLabel.indexFields();
    if (this.indexFields.size() != existedIndexFieldIds.size()) {
        return false;
    }
    for (String field : this.indexFields) {
        PropertyKey propertyKey = graph().propertyKey(field);
        if (!existedIndexFieldIds.contains(propertyKey.id())) {
            return false;
        }
    }
    // all properties are same, return true.
    return true;
}
Also used : SchemaLabel(com.baidu.hugegraph.schema.SchemaLabel) Id(com.baidu.hugegraph.backend.id.Id) PropertyKey(com.baidu.hugegraph.schema.PropertyKey)

Example 69 with PropertyKey

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

the class IndexLabelBuilder method allStringIndex.

private boolean allStringIndex(List<?> fields) {
    for (Object field : fields) {
        PropertyKey pk = field instanceof Id ? this.graph().propertyKey((Id) field) : this.graph().propertyKey((String) field);
        DataType dataType = pk.dataType();
        if (dataType.isNumber() || dataType.isDate()) {
            return false;
        }
    }
    return true;
}
Also used : DataType(com.baidu.hugegraph.type.define.DataType) Id(com.baidu.hugegraph.backend.id.Id) PropertyKey(com.baidu.hugegraph.schema.PropertyKey)

Example 70 with PropertyKey

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

the class EdgeLabelBuilder method hasSameProperties.

/**
 * Check whether this has same properties with existedEdgeLabel.
 * Only sourceId, targetId, frequency, enableLabelIndex, properties, sortKeys,
 * nullableKeys are checked.
 * The id, ttl, ttlStartTime, userdata are not checked.
 * @param existedEdgeLabel to be compared with
 * @return true if this has same properties with existedVertexLabel
 */
private boolean hasSameProperties(EdgeLabel existedEdgeLabel) {
    HugeGraph graph = this.graph();
    Id sourceId = graph.vertexLabel(this.sourceLabel).id();
    if (!existedEdgeLabel.sourceLabel().equals(sourceId)) {
        return false;
    }
    Id targetId = graph.vertexLabel(this.targetLabel).id();
    if (!existedEdgeLabel.targetLabel().equals(targetId)) {
        return false;
    }
    if ((this.frequency == Frequency.DEFAULT && existedEdgeLabel.frequency() != Frequency.SINGLE) || (this.frequency != Frequency.DEFAULT && this.frequency != existedEdgeLabel.frequency())) {
        return false;
    }
    // this.enableLabelIndex == null, it means true.
    if (this.enableLabelIndex == null || this.enableLabelIndex) {
        if (!existedEdgeLabel.enableLabelIndex()) {
            return false;
        }
    } else {
        // this false
        if (existedEdgeLabel.enableLabelIndex()) {
            return false;
        }
    }
    Set<Id> existedProperties = existedEdgeLabel.properties();
    if (this.properties.size() != existedProperties.size()) {
        return false;
    }
    for (String key : this.properties) {
        PropertyKey propertyKey = graph.propertyKey(key);
        if (!existedProperties.contains(propertyKey.id())) {
            return false;
        }
    }
    List<Id> existedSortKeys = existedEdgeLabel.sortKeys();
    if (this.sortKeys.size() != existedSortKeys.size()) {
        return false;
    }
    for (String key : this.sortKeys) {
        PropertyKey propertyKey = graph.propertyKey(key);
        if (!existedSortKeys.contains(propertyKey.id())) {
            return false;
        }
    }
    Set<Id> existedNullableKeys = existedEdgeLabel.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;
        }
    }
    return true;
}
Also used : HugeGraph(com.baidu.hugegraph.HugeGraph) 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