Search in sources :

Example 1 with PropertyIndex

use of com.baidu.hugegraph.entity.schema.PropertyIndex in project incubator-hugegraph-toolchain by apache.

the class SchemaService method collectIndexLabels.

public static List<IndexLabel> collectIndexLabels(SchemaLabelEntity entity, HugeClient client) {
    List<PropertyIndex> propertyIndexes = entity.getPropertyIndexes();
    if (CollectionUtils.isEmpty(propertyIndexes)) {
        return Collections.emptyList();
    }
    boolean isVertex = entity.getSchemaType().isVertexLabel();
    String baseValue = entity.getName();
    SchemaManager schema = client.schema();
    List<IndexLabel> indexLabels = new ArrayList<>(propertyIndexes.size());
    for (PropertyIndex index : propertyIndexes) {
        String[] fields = toStringArray(index.getFields());
        IndexLabel indexLabel = schema.indexLabel(index.getName()).on(isVertex, baseValue).indexType(index.getType()).by(fields).build();
        indexLabels.add(indexLabel);
    }
    return indexLabels;
}
Also used : IndexLabel(com.baidu.hugegraph.structure.schema.IndexLabel) ArrayList(java.util.ArrayList) SchemaManager(com.baidu.hugegraph.driver.SchemaManager) PropertyIndex(com.baidu.hugegraph.entity.schema.PropertyIndex)

Example 2 with PropertyIndex

use of com.baidu.hugegraph.entity.schema.PropertyIndex in project incubator-hugegraph-toolchain by apache.

the class PropertyIndexService method list.

public List<PropertyIndex> list(Collection<String> names, int connId, boolean emptyAsAll) {
    HugeClient client = this.client(connId);
    List<IndexLabel> indexLabels;
    if (CollectionUtils.isEmpty(names)) {
        if (emptyAsAll) {
            indexLabels = client.schema().getIndexLabels();
        } else {
            indexLabels = new ArrayList<>();
        }
    } else {
        indexLabels = client.schema().getIndexLabels(new ArrayList<>(names));
    }
    List<PropertyIndex> results = new ArrayList<>(indexLabels.size());
    indexLabels.forEach(indexLabel -> {
        results.add(convert(indexLabel));
    });
    return results;
}
Also used : HugeClient(com.baidu.hugegraph.driver.HugeClient) IndexLabel(com.baidu.hugegraph.structure.schema.IndexLabel) ArrayList(java.util.ArrayList) PropertyIndex(com.baidu.hugegraph.entity.schema.PropertyIndex)

Example 3 with PropertyIndex

use of com.baidu.hugegraph.entity.schema.PropertyIndex in project incubator-hugegraph-toolchain by apache.

the class SchemaController method checkPropertyIndexes.

public static void checkPropertyIndexes(SchemaLabelEntity entity, int connId) {
    List<PropertyIndex> propertyIndexes = entity.getPropertyIndexes();
    if (propertyIndexes != null) {
        for (PropertyIndex propertyIndex : propertyIndexes) {
            Ex.check(propertyIndex.getOwner() == null, "common.param.must-be-null", "property_index.owner");
            Ex.check(propertyIndex.getName() != null, "common.param.cannot-be-null", "property_index.name");
            Ex.check(propertyIndex.getSchemaType() != null, "common.param.cannot-be-null", "property_index.type");
            Ex.check(propertyIndex.getFields() != null, "common.param.cannot-be-null", "property_index.fields");
        }
    }
}
Also used : PropertyIndex(com.baidu.hugegraph.entity.schema.PropertyIndex)

Example 4 with PropertyIndex

use of com.baidu.hugegraph.entity.schema.PropertyIndex in project incubator-hugegraph-toolchain by apache.

the class PropertyIndexService method checkConflict.

public void checkConflict(List<PropertyIndex> entities, ConflictDetail detail, int connId, boolean compareEachOther) {
    if (CollectionUtils.isEmpty(entities)) {
        return;
    }
    Map<String, PropertyIndex> originEntities = new HashMap<>();
    for (PropertyIndex entity : this.list(connId)) {
        originEntities.put(entity.getName(), entity);
    }
    for (PropertyIndex entity : entities) {
        if (detail.anyPropertyKeyConflict(entity.getFields())) {
            detail.add(entity, ConflictStatus.DEP_CONFLICT);
            continue;
        }
        PropertyIndex originEntity = originEntities.get(entity.getName());
        ConflictStatus status = SchemaEntity.compare(entity, originEntity);
        detail.add(entity, status);
    }
    // Compare resued entities with each other
    if (compareEachOther) {
        compareWithEachOther(detail, SchemaType.PROPERTY_INDEX);
    }
}
Also used : ConflictStatus(com.baidu.hugegraph.entity.schema.ConflictStatus) HashMap(java.util.HashMap) PropertyIndex(com.baidu.hugegraph.entity.schema.PropertyIndex)

Example 5 with PropertyIndex

use of com.baidu.hugegraph.entity.schema.PropertyIndex in project incubator-hugegraph-toolchain by apache.

the class PropertyIndexService method list.

public IPage<PropertyIndex> list(int connId, HugeType type, int pageNo, int pageSize) {
    HugeClient client = this.client(connId);
    List<IndexLabel> indexLabels = client.schema().getIndexLabels();
    List<PropertyIndex> results = new ArrayList<>();
    for (IndexLabel indexLabel : indexLabels) {
        if (!indexLabel.baseType().equals(type)) {
            continue;
        }
        // Collect all indexlabels
        results.add(convert(indexLabel));
    }
    // Sort by owner name a-z, then index name a-z
    results.sort((o1, o2) -> {
        String owner1 = o1.getOwner();
        String owner2 = o2.getOwner();
        if (!owner1.equals(owner2)) {
            return owner1.compareTo(owner2);
        }
        return o1.getName().compareTo(o2.getName());
    });
    return PageUtil.page(results, pageNo, pageSize);
}
Also used : HugeClient(com.baidu.hugegraph.driver.HugeClient) IndexLabel(com.baidu.hugegraph.structure.schema.IndexLabel) ArrayList(java.util.ArrayList) PropertyIndex(com.baidu.hugegraph.entity.schema.PropertyIndex)

Aggregations

PropertyIndex (com.baidu.hugegraph.entity.schema.PropertyIndex)8 IndexLabel (com.baidu.hugegraph.structure.schema.IndexLabel)6 ArrayList (java.util.ArrayList)6 HugeClient (com.baidu.hugegraph.driver.HugeClient)3 SchemaManager (com.baidu.hugegraph.driver.SchemaManager)2 ConflictStatus (com.baidu.hugegraph.entity.schema.ConflictStatus)2 SchemaType (com.baidu.hugegraph.entity.schema.SchemaType)2 HashMap (java.util.HashMap)2 Constant (com.baidu.hugegraph.common.Constant)1 ConflictDetail (com.baidu.hugegraph.entity.schema.ConflictDetail)1 SchemaConflict (com.baidu.hugegraph.entity.schema.SchemaConflict)1 SchemaEntity (com.baidu.hugegraph.entity.schema.SchemaEntity)1 ServerException (com.baidu.hugegraph.exception.ServerException)1 HugeType (com.baidu.hugegraph.structure.constant.HugeType)1 PageUtil (com.baidu.hugegraph.util.PageUtil)1 IPage (com.baomidou.mybatisplus.core.metadata.IPage)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 Comparator (java.util.Comparator)1 List (java.util.List)1