Search in sources :

Example 31 with IndexLabel

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

the class SchemaDefine method createRangeIndex.

protected IndexLabel createRangeIndex(VertexLabel label, String field) {
    SchemaManager schema = this.schema();
    String name = Hidden.hide(label + "-index-by-" + field);
    IndexLabel indexLabel = schema.indexLabel(name).range().on(HugeType.VERTEX_LABEL, this.label).by(field).build();
    this.graph.schemaTransaction().addIndexLabel(label, indexLabel);
    return indexLabel;
}
Also used : IndexLabel(com.baidu.hugegraph.schema.IndexLabel) SchemaManager(com.baidu.hugegraph.schema.SchemaManager)

Example 32 with IndexLabel

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

the class TableSerializer method readIndexLabel.

@Override
public IndexLabel readIndexLabel(HugeGraph graph, BackendEntry backendEntry) {
    if (backendEntry == null) {
        return null;
    }
    TableBackendEntry entry = this.convertEntry(backendEntry);
    Number id = schemaColumn(entry, HugeKeys.ID);
    String name = schemaColumn(entry, HugeKeys.NAME);
    HugeType baseType = schemaEnum(entry, HugeKeys.BASE_TYPE, HugeType.class);
    Number baseValueId = schemaColumn(entry, HugeKeys.BASE_VALUE);
    IndexType indexType = schemaEnum(entry, HugeKeys.INDEX_TYPE, IndexType.class);
    Object indexFields = schemaColumn(entry, HugeKeys.FIELDS);
    SchemaStatus status = schemaEnum(entry, HugeKeys.STATUS, SchemaStatus.class);
    IndexLabel indexLabel = new IndexLabel(graph, this.toId(id), name);
    indexLabel.baseType(baseType);
    indexLabel.baseValue(this.toId(baseValueId));
    indexLabel.indexType(indexType);
    indexLabel.indexFields(this.toIdArray(indexFields));
    indexLabel.status(status);
    this.readUserdata(indexLabel, entry);
    return indexLabel;
}
Also used : IndexLabel(com.baidu.hugegraph.schema.IndexLabel) IndexType(com.baidu.hugegraph.type.define.IndexType) HugeType(com.baidu.hugegraph.type.HugeType) SchemaStatus(com.baidu.hugegraph.type.define.SchemaStatus)

Example 33 with IndexLabel

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

the class TextSerializer method readIndex.

@Override
public HugeIndex readIndex(HugeGraph graph, ConditionQuery query, BackendEntry backendEntry) {
    E.checkNotNull(graph, "serializer graph");
    if (backendEntry == null) {
        return null;
    }
    TextBackendEntry entry = this.convertEntry(backendEntry);
    String indexValues = entry.column(formatSyspropName(HugeKeys.FIELD_VALUES));
    String indexLabelId = entry.column(formatSyspropName(HugeKeys.INDEX_LABEL_ID));
    String elemIds = entry.column(formatSyspropName(HugeKeys.ELEMENT_IDS));
    IndexLabel indexLabel = IndexLabel.label(graph, readId(indexLabelId));
    HugeIndex index = new HugeIndex(graph, indexLabel);
    index.fieldValues(JsonUtil.fromJson(indexValues, Object.class));
    for (IdWithExpiredTime elemId : readElementIds(elemIds)) {
        long expiredTime = elemId.expiredTime();
        Id id;
        if (indexLabel.queryType().isEdge()) {
            id = EdgeId.parse(elemId.id().asString());
        } else {
            id = elemId.id();
        }
        index.elementIds(id, expiredTime);
    }
    // Memory backend might return empty BackendEntry
    return index;
}
Also used : IdWithExpiredTime(com.baidu.hugegraph.structure.HugeIndex.IdWithExpiredTime) IndexLabel(com.baidu.hugegraph.schema.IndexLabel) HugeIndex(com.baidu.hugegraph.structure.HugeIndex) Id(com.baidu.hugegraph.backend.id.Id) EdgeId(com.baidu.hugegraph.backend.id.EdgeId)

Example 34 with IndexLabel

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

the class SchemaIndexTransaction method updateNameIndex.

@Watched(prefix = "index")
public void updateNameIndex(SchemaElement element, boolean removed) {
    if (!this.needIndexForName()) {
        return;
    }
    IndexLabel indexLabel = IndexLabel.label(element.type());
    // Update name index if backend store not supports name-query
    HugeIndex index = new HugeIndex(this.graph(), indexLabel);
    index.fieldValues(element.name());
    index.elementIds(element.id());
    if (removed) {
        this.doEliminate(this.serializer.writeIndex(index));
    } else {
        this.doAppend(this.serializer.writeIndex(index));
    }
}
Also used : IndexLabel(com.baidu.hugegraph.schema.IndexLabel) HugeIndex(com.baidu.hugegraph.structure.HugeIndex) Watched(com.baidu.hugegraph.perf.PerfUtil.Watched)

Example 35 with IndexLabel

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

the class SchemaIndexTransaction method queryByName.

@Watched(prefix = "index")
private QueryResults<BackendEntry> queryByName(ConditionQuery query) {
    if (!this.needIndexForName()) {
        return super.query(query);
    }
    IndexLabel il = IndexLabel.label(query.resultType());
    String name = (String) query.condition(HugeKeys.NAME);
    E.checkState(name != null, "The name in condition can't be null " + "when querying schema by name");
    ConditionQuery indexQuery;
    indexQuery = new ConditionQuery(HugeType.SECONDARY_INDEX, query);
    indexQuery.eq(HugeKeys.FIELD_VALUES, name);
    indexQuery.eq(HugeKeys.INDEX_LABEL_ID, il.id());
    IdQuery idQuery = new IdQuery(query.resultType(), query);
    Iterator<BackendEntry> entries = super.query(indexQuery).iterator();
    try {
        while (entries.hasNext()) {
            HugeIndex index = this.serializer.readIndex(graph(), indexQuery, entries.next());
            idQuery.query(index.elementIds());
            Query.checkForceCapacity(idQuery.idsSize());
        }
    } finally {
        CloseableIterator.closeIterator(entries);
    }
    if (idQuery.ids().isEmpty()) {
        return QueryResults.empty();
    }
    assert idQuery.idsSize() == 1 : idQuery.ids();
    if (idQuery.idsSize() > 1) {
        LOG.warn("Multiple ids are found with same name '{}': {}", name, idQuery.ids());
    }
    return super.query(idQuery);
}
Also used : BackendEntry(com.baidu.hugegraph.backend.store.BackendEntry) ConditionQuery(com.baidu.hugegraph.backend.query.ConditionQuery) IndexLabel(com.baidu.hugegraph.schema.IndexLabel) IdQuery(com.baidu.hugegraph.backend.query.IdQuery) HugeIndex(com.baidu.hugegraph.structure.HugeIndex) Watched(com.baidu.hugegraph.perf.PerfUtil.Watched)

Aggregations

IndexLabel (com.baidu.hugegraph.schema.IndexLabel)53 Id (com.baidu.hugegraph.backend.id.Id)24 Watched (com.baidu.hugegraph.perf.PerfUtil.Watched)8 SchemaLabel (com.baidu.hugegraph.schema.SchemaLabel)8 SchemaManager (com.baidu.hugegraph.schema.SchemaManager)8 Test (org.junit.Test)8 ConditionQuery (com.baidu.hugegraph.backend.query.ConditionQuery)7 HugeGraph (com.baidu.hugegraph.HugeGraph)5 PropertyKey (com.baidu.hugegraph.schema.PropertyKey)5 HugeType (com.baidu.hugegraph.type.HugeType)5 GraphTransaction (com.baidu.hugegraph.backend.tx.GraphTransaction)4 SchemaTransaction (com.baidu.hugegraph.backend.tx.SchemaTransaction)4 VertexLabel (com.baidu.hugegraph.schema.VertexLabel)4 HugeIndex (com.baidu.hugegraph.structure.HugeIndex)4 LockUtil (com.baidu.hugegraph.util.LockUtil)4 IdHolder (com.baidu.hugegraph.backend.page.IdHolder)3 BatchIdHolder (com.baidu.hugegraph.backend.page.IdHolder.BatchIdHolder)3 FixedIdHolder (com.baidu.hugegraph.backend.page.IdHolder.FixedIdHolder)3 PagingIdHolder (com.baidu.hugegraph.backend.page.IdHolder.PagingIdHolder)3 Condition (com.baidu.hugegraph.backend.query.Condition)3