Search in sources :

Example 1 with NotAllowException

use of com.baidu.hugegraph.exception.NotAllowException in project incubator-hugegraph by apache.

the class VertexLabelBuilder method checkNullableKeys.

@SuppressWarnings("unchecked")
private void checkNullableKeys(Action action) {
    // Not using switch-case to avoid indent too much
    if (action == Action.ELIMINATE) {
        if (!this.nullableKeys.isEmpty()) {
            throw new NotAllowException("Not support to eliminate nullableKeys " + "for vertex label currently");
        }
        return;
    }
    VertexLabel vertexLabel = this.vertexLabelOrNull(this.name);
    // The originProps is empty when firstly create vertex label
    List<String> originProps = vertexLabel == null ? ImmutableList.of() : this.graph().mapPkId2Name(vertexLabel.properties());
    Set<String> appendProps = this.properties;
    E.checkArgument(CollectionUtil.union(originProps, appendProps).containsAll(this.nullableKeys), "The nullableKeys: %s to be created or appended " + "must belong to the origin/new properties: %s/%s", this.nullableKeys, originProps, appendProps);
    List<String> primaryKeys = vertexLabel == null ? this.primaryKeys : this.graph().mapPkId2Name(vertexLabel.primaryKeys());
    E.checkArgument(!CollectionUtil.hasIntersection(primaryKeys, this.nullableKeys), "The nullableKeys: %s are not allowed to " + "belong to primaryKeys: %s of vertex label '%s'", this.nullableKeys, primaryKeys, this.name);
    if (action == Action.APPEND) {
        Collection<String> newAddedProps = CollectionUtils.subtract(appendProps, originProps);
        E.checkArgument(this.nullableKeys.containsAll(newAddedProps), "The new added properties: %s must be nullable", newAddedProps);
    }
}
Also used : VertexLabel(com.baidu.hugegraph.schema.VertexLabel) NotAllowException(com.baidu.hugegraph.exception.NotAllowException)

Example 2 with NotAllowException

use of com.baidu.hugegraph.exception.NotAllowException in project incubator-hugegraph by apache.

the class EdgeLabelBuilder method checkNullableKeys.

@SuppressWarnings("unchecked")
private void checkNullableKeys(Action action) {
    // Not using switch-case to avoid indent too much
    if (action == Action.ELIMINATE) {
        if (!this.nullableKeys.isEmpty()) {
            throw new NotAllowException("Not support to eliminate nullableKeys " + "for edge label currently");
        }
        return;
    }
    EdgeLabel edgeLabel = this.edgeLabelOrNull(this.name);
    // The originProps is empty when firstly create edge label
    List<String> originProps = edgeLabel == null ? ImmutableList.of() : this.graph().mapPkId2Name(edgeLabel.properties());
    Set<String> appendProps = this.properties;
    E.checkArgument(CollectionUtil.union(originProps, appendProps).containsAll(this.nullableKeys), "The nullableKeys: %s to be created or appended " + "must belong to the origin/new properties: %s/%s ", this.nullableKeys, originProps, appendProps);
    List<String> sortKeys = edgeLabel == null ? this.sortKeys : this.graph().mapPkId2Name(edgeLabel.sortKeys());
    E.checkArgument(!CollectionUtil.hasIntersection(sortKeys, this.nullableKeys), "The nullableKeys: %s are not allowed to " + "belong to sortKeys: %s of edge label '%s'", this.nullableKeys, sortKeys, this.name);
    if (action == Action.APPEND) {
        Collection<String> newAddedProps = CollectionUtils.subtract(appendProps, originProps);
        E.checkArgument(this.nullableKeys.containsAll(newAddedProps), "The new added properties: %s must be nullable", newAddedProps);
    }
}
Also used : EdgeLabel(com.baidu.hugegraph.schema.EdgeLabel) NotAllowException(com.baidu.hugegraph.exception.NotAllowException)

Example 3 with NotAllowException

use of com.baidu.hugegraph.exception.NotAllowException in project incubator-hugegraph by apache.

the class GraphIndexTransaction method queryByUserprop.

@Watched(prefix = "index")
private IdHolderList queryByUserprop(ConditionQuery query) {
    // related index labels
    if (!this.graph().readMode().showOlap()) {
        for (Id pkId : query.userpropKeys()) {
            PropertyKey propertyKey = this.graph().propertyKey(pkId);
            if (propertyKey.olap()) {
                throw new NotAllowException("Not allowed to query by olap property key '%s'" + " when graph-read-mode is '%s'", propertyKey, this.graph().readMode());
            }
        }
    }
    Set<MatchedIndex> indexes = this.collectMatchedIndexes(query);
    if (indexes.isEmpty()) {
        Id label = query.condition(HugeKeys.LABEL);
        throw noIndexException(this.graph(), query, label);
    }
    // Value type of Condition not matched
    boolean paging = query.paging();
    if (!validQueryConditionValues(this.graph(), query)) {
        return IdHolderList.empty(paging);
    }
    // Do index query
    IdHolderList holders = new IdHolderList(paging);
    for (MatchedIndex index : indexes) {
        for (IndexLabel il : index.indexLabels()) {
            validateIndexLabel(il);
        }
        if (paging && index.indexLabels().size() > 1) {
            throw new NotSupportException("joint index query in paging");
        }
        if (index.containsSearchIndex()) {
            // Do search-index query
            holders.addAll(this.doSearchIndex(query, index));
        } else {
            // Do secondary-index, range-index or shard-index query
            IndexQueries queries = index.constructIndexQueries(query);
            assert !paging || queries.size() <= 1;
            IdHolder holder = this.doSingleOrJointIndex(queries);
            holders.add(holder);
        }
    /*
             * NOTE: need to skip the offset if offset > 0, but can't handle
             * it here because the query may a sub-query after flatten,
             * so the offset will be handle in QueryList.IndexQuery
             *
             * TODO: finish early here if records exceeds required limit with
             *       FixedIdHolder.
             */
    }
    return holders;
}
Also used : SortByCountIdHolderList(com.baidu.hugegraph.backend.page.SortByCountIdHolderList) IdHolderList(com.baidu.hugegraph.backend.page.IdHolderList) IndexLabel(com.baidu.hugegraph.schema.IndexLabel) IdHolder(com.baidu.hugegraph.backend.page.IdHolder) FixedIdHolder(com.baidu.hugegraph.backend.page.IdHolder.FixedIdHolder) PagingIdHolder(com.baidu.hugegraph.backend.page.IdHolder.PagingIdHolder) BatchIdHolder(com.baidu.hugegraph.backend.page.IdHolder.BatchIdHolder) Id(com.baidu.hugegraph.backend.id.Id) NotSupportException(com.baidu.hugegraph.exception.NotSupportException) NotAllowException(com.baidu.hugegraph.exception.NotAllowException) PropertyKey(com.baidu.hugegraph.schema.PropertyKey) Watched(com.baidu.hugegraph.perf.PerfUtil.Watched)

Example 4 with NotAllowException

use of com.baidu.hugegraph.exception.NotAllowException in project incubator-hugegraph by apache.

the class SchemaTransaction method removePropertyKey.

@Watched(prefix = "schema")
public Id removePropertyKey(Id id) {
    LOG.debug("SchemaTransaction remove property key '{}'", id);
    PropertyKey propertyKey = this.getPropertyKey(id);
    // If the property key does not exist, return directly
    if (propertyKey == null) {
        return null;
    }
    List<VertexLabel> vertexLabels = this.getVertexLabels();
    for (VertexLabel vertexLabel : vertexLabels) {
        if (vertexLabel.properties().contains(id)) {
            throw new NotAllowException("Not allowed to remove property key: '%s' " + "because the vertex label '%s' is still using it.", propertyKey, vertexLabel.name());
        }
    }
    List<EdgeLabel> edgeLabels = this.getEdgeLabels();
    for (EdgeLabel edgeLabel : edgeLabels) {
        if (edgeLabel.properties().contains(id)) {
            throw new NotAllowException("Not allowed to remove property key: '%s' " + "because the edge label '%s' is still using it.", propertyKey, edgeLabel.name());
        }
    }
    if (propertyKey.oltp()) {
        this.removeSchema(propertyKey);
        return IdGenerator.ZERO;
    } else {
        return this.removeOlapPk(propertyKey);
    }
}
Also used : VertexLabel(com.baidu.hugegraph.schema.VertexLabel) EdgeLabel(com.baidu.hugegraph.schema.EdgeLabel) NotAllowException(com.baidu.hugegraph.exception.NotAllowException) PropertyKey(com.baidu.hugegraph.schema.PropertyKey) Watched(com.baidu.hugegraph.perf.PerfUtil.Watched)

Aggregations

NotAllowException (com.baidu.hugegraph.exception.NotAllowException)4 Watched (com.baidu.hugegraph.perf.PerfUtil.Watched)2 EdgeLabel (com.baidu.hugegraph.schema.EdgeLabel)2 PropertyKey (com.baidu.hugegraph.schema.PropertyKey)2 VertexLabel (com.baidu.hugegraph.schema.VertexLabel)2 Id (com.baidu.hugegraph.backend.id.Id)1 IdHolder (com.baidu.hugegraph.backend.page.IdHolder)1 BatchIdHolder (com.baidu.hugegraph.backend.page.IdHolder.BatchIdHolder)1 FixedIdHolder (com.baidu.hugegraph.backend.page.IdHolder.FixedIdHolder)1 PagingIdHolder (com.baidu.hugegraph.backend.page.IdHolder.PagingIdHolder)1 IdHolderList (com.baidu.hugegraph.backend.page.IdHolderList)1 SortByCountIdHolderList (com.baidu.hugegraph.backend.page.SortByCountIdHolderList)1 NotSupportException (com.baidu.hugegraph.exception.NotSupportException)1 IndexLabel (com.baidu.hugegraph.schema.IndexLabel)1