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;
}
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;
}
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;
}
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));
}
}
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);
}
Aggregations