use of com.baidu.hugegraph.backend.id.Id in project incubator-hugegraph by apache.
the class CassandraTable method queryId2Select.
protected List<Select> queryId2Select(Query query, Select select) {
// Query by id(s)
if (query.idsSize() == 0) {
return ImmutableList.of(select);
}
List<HugeKeys> nameParts = this.idColumnName();
List<List<Object>> ids = new ArrayList<>(query.idsSize());
for (Id id : query.ids()) {
List<Object> idParts = this.idColumnValue(id);
if (nameParts.size() != idParts.size()) {
throw new NotFoundException("Unsupported ID format: '%s' (should contain %s)", id, nameParts);
}
ids.add(idParts);
}
// Query only by partition-key
if (nameParts.size() == 1) {
List<Object> idList = new ArrayList<>(ids.size());
for (List<Object> id : ids) {
assert id.size() == 1;
idList.add(id.get(0));
}
return this.ids2IdSelects(select, nameParts.get(0), idList);
}
/*
* Query by partition-key + clustering-key
* NOTE: Error if multi-column IN clause include partition key:
* error: multi-column relations can only be applied to clustering
* columns when using: select.where(QueryBuilder.in(names, idList));
* So we use multi-query instead of IN
*/
List<Select> selects = new ArrayList<>(ids.size());
for (List<Object> id : ids) {
assert nameParts.size() == id.size();
Select idSelect = cloneSelect(select, this.table());
/*
* NOTE: concat with AND relation, like:
* "pk = id and ck1 = v1 and ck2 = v2"
*/
for (int i = 0, n = nameParts.size(); i < n; i++) {
idSelect.where(formatEQ(nameParts.get(i), id.get(i)));
}
selects.add(idSelect);
}
return selects;
}
use of com.baidu.hugegraph.backend.id.Id in project incubator-hugegraph by apache.
the class BinarySerializer method readVertex.
@Override
public HugeVertex readVertex(HugeGraph graph, BackendEntry bytesEntry) {
if (bytesEntry == null) {
return null;
}
BinaryBackendEntry entry = this.convertEntry(bytesEntry);
// Parse id
Id id = entry.id().origin();
Id vid = id.edge() ? ((EdgeId) id).ownerVertexId() : id;
HugeVertex vertex = new HugeVertex(graph, vid, VertexLabel.NONE);
// Parse all properties and edges of a Vertex
Iterator<BackendColumn> iterator = entry.columns().iterator();
for (int index = 0; iterator.hasNext(); index++) {
BackendColumn col = iterator.next();
if (entry.type().isEdge()) {
// NOTE: the entry id type is vertex even if entry type is edge
// Parse vertex edges
this.parseColumn(col, vertex);
} else {
assert entry.type().isVertex();
// Parse vertex properties
assert entry.columnsSize() >= 1 : entry.columnsSize();
if (index == 0) {
this.parseVertex(col.value, vertex);
} else {
this.parseVertexOlap(col.value, vertex);
}
}
}
return vertex;
}
use of com.baidu.hugegraph.backend.id.Id in project incubator-hugegraph by apache.
the class BinarySerializer method writeQueryEdgePrefixCondition.
private Query writeQueryEdgePrefixCondition(ConditionQuery cq) {
int count = 0;
BytesBuffer buffer = BytesBuffer.allocate(BytesBuffer.BUF_EDGE_ID);
for (HugeKeys key : EdgeId.KEYS) {
Object value = cq.condition(key);
if (value != null) {
count++;
} else {
if (key == HugeKeys.DIRECTION) {
// Direction is null, set to OUT
value = Directions.OUT;
} else {
break;
}
}
if (key == HugeKeys.OWNER_VERTEX || key == HugeKeys.OTHER_VERTEX) {
writePartitionedId(HugeType.EDGE, (Id) value, buffer);
} else if (key == HugeKeys.DIRECTION) {
byte t = ((Directions) value).type().code();
buffer.write(t);
} else if (key == HugeKeys.LABEL) {
assert value instanceof Id;
buffer.writeId((Id) value);
} else if (key == HugeKeys.SORT_VALUES) {
assert value instanceof String;
buffer.writeStringWithEnding((String) value);
} else {
assert false : key;
}
}
if (count > 0) {
assert count == cq.conditionsSize();
return prefixQuery(cq, new BinaryId(buffer.bytes(), null));
}
return null;
}
use of com.baidu.hugegraph.backend.id.Id in project incubator-hugegraph by apache.
the class BinarySerializer method parseVertexOlap.
protected void parseVertexOlap(byte[] value, HugeVertex vertex) {
BytesBuffer buffer = BytesBuffer.wrap(value);
Id pkeyId = IdGenerator.of(buffer.readVInt());
this.parseProperty(pkeyId, buffer, vertex);
}
use of com.baidu.hugegraph.backend.id.Id in project incubator-hugegraph by apache.
the class BinarySerializer method writeStringIndexQuery.
private Query writeStringIndexQuery(ConditionQuery query) {
E.checkArgument(query.allSysprop() && query.conditionsSize() == 2, "There should be two conditions: " + "INDEX_LABEL_ID and FIELD_VALUES" + "in secondary index query");
Id index = query.condition(HugeKeys.INDEX_LABEL_ID);
Object key = query.condition(HugeKeys.FIELD_VALUES);
E.checkArgument(index != null, "Please specify the index label");
E.checkArgument(key != null, "Please specify the index key");
Id prefix = formatIndexId(query.resultType(), index, key, true);
return prefixQuery(query, prefix);
}
Aggregations