private byte[] writeId(Id id) { int size = 1 + id.length(); BytesBuffer buffer = BytesBuffer.allocate(size); buffer.writeId(id); return buffer.bytes(); }
private byte[] writeIds(Collection<Id> ids) { E.checkState(ids.size() <= BytesBuffer.UINT16_MAX, "The number of properties of vertex/edge label " + "cannot exceed '%s'", BytesBuffer.UINT16_MAX); int size = 2; for (Id id : ids) { size += (1 + id.length()); } BytesBuffer buffer = BytesBuffer.allocate(size); buffer.writeUInt16(ids.size()); for (Id id : ids) { buffer.writeId(id); } return buffer.bytes(); }
@Override public BinaryBackendEntry newBackendEntry(HugeType type, Id id) { BytesBuffer buffer = BytesBuffer.allocate(1 + id.length()); BinaryId bid = new BinaryId(buffer.writeId(id).bytes(), id); return new BinaryBackendEntry(type, bid); }
protected byte[] formatPropertyName(HugeProperty<?> prop) { Id id = prop.element().id(); int idLen = this.keyWithIdPrefix ? 1 + id.length() : 0; Id pkeyId = prop.propertyKey().id(); BytesBuffer buffer = BytesBuffer.allocate(idLen + 2 + pkeyId.length()); if (this.keyWithIdPrefix) { buffer.writeId(id); } buffer.write(prop.type().code()); buffer.writeId(pkeyId); return buffer.bytes(); }
protected byte[] formatIndexName(HugeIndex index) { Id elemId = index.elementId(); int idLen = 1 + elemId.length(); BytesBuffer buffer; if (!this.keyWithIdPrefix) { buffer = BytesBuffer.allocate(idLen); } else { Id indexId = index.id(); if (indexIdLengthExceedLimit(indexId)) { indexId = index.hashId(); } // Write index-id idLen += 1 + indexId.length(); buffer = BytesBuffer.allocate(idLen); buffer.writeId(indexId); } // Write element-id buffer.writeId(elemId, true); return buffer.bytes(); }
@Override protected Id writeQueryId(HugeType type, Id id) { if (type.isEdge()) { id = writeEdgeId(id); } else { BytesBuffer buffer = BytesBuffer.allocate(1 + id.length()); id = new BinaryId(buffer.writeId(id).bytes(), id); } return id; }
@Override protected void parseRowColumns(Result row, BackendEntry entry, Query query) throws IOException { /* * Collapse owner-vertex id from edge id, NOTE: unneeded to * collapse if BinarySerializer.keyWithIdPrefix set to true */ byte[] key = row.getRow(); key = Arrays.copyOfRange(key, entry.id().length(), key.length); long total = query.total(); CellScanner cellScanner = row.cellScanner(); while (cellScanner.advance() && total-- > 0) { Cell cell = cellScanner.current(); assert CellUtil.cloneQualifier(cell).length == 0; entry.columns(BackendColumn.of(key, CellUtil.cloneValue(cell))); } } }
protected static BinaryId formatIndexId(HugeType type, Id indexLabel, Object fieldValues) { Id id = HugeIndex.formatIndexId(type, indexLabel, fieldValues); if (indexIdLengthExceedLimit(id)) { id = HugeIndex.formatIndexHashId(type, indexLabel, fieldValues); } BytesBuffer buffer = BytesBuffer.allocate(1 + id.length()); return new BinaryId(buffer.writeId(id).bytes(), id); }
protected byte[] formatSyspropName(Id id, HugeKeys col) { int idLen = this.keyWithIdPrefix ? 1 + id.length() : 0; BytesBuffer buffer = BytesBuffer.allocate(idLen + 1 + 1); byte sysprop = HugeType.SYS_PROPERTY.code(); if (this.keyWithIdPrefix) { buffer.writeId(id); } return buffer.write(sysprop).write(col.code()).bytes(); }
private byte[] formatColumnName(HugeKeys key) { Id id = this.entry.id().origin(); int size = 1 + id.length() + 1; BytesBuffer buffer = BytesBuffer.allocate(size); buffer.writeId(id); buffer.write(key.code()); return buffer.bytes(); } }
protected BackendColumn formatLabel(HugeElement elem) { BackendColumn col = new BackendColumn(); col.name = this.formatSyspropName(elem.id(), HugeKeys.LABEL); Id label = elem.schemaLabel().id(); BytesBuffer buffer = BytesBuffer.allocate(label.length() + 1); col.value = buffer.writeId(label).bytes(); return col; }
@Watched(prefix = "edge") public void assignId() { // Generate an id and assign this.id = new EdgeId(this.ownerVertex(), this.direction(), this.schemaLabel().id(), this.name(), this.otherVertex()); int len = this.id.length(); E.checkArgument(len <= BytesBuffer.BIG_ID_MAX_LEN, "The max length of edge id is %s, but got %s {%s}", BytesBuffer.BIG_ID_MAX_LEN, len, this.id); }
private static byte[] joinIdKey(Id id, String key) { int size = 1 + id.length() + key.length(); BytesBuffer buffer = BytesBuffer.allocate(size); buffer.writeId(id); buffer.writeStringToRemaining(key); return buffer.bytes(); }
@Override public BinaryBackendEntry newBackendEntry(HugeType type, Id id) { BytesBuffer buffer = BytesBuffer.allocate(1 + id.length()); BinaryId bid = new BinaryId(buffer.writeId(id).bytes(), id); return new BinaryBackendEntry(type, bid); }
protected byte[] formatPropertyName(HugeProperty<?> prop) { Id id = prop.element().id(); int idLen = this.keyWithIdPrefix ? 1 + id.length() : 0; Id pkeyId = prop.propertyKey().id(); BytesBuffer buffer = BytesBuffer.allocate(idLen + 2 + pkeyId.length()); if (this.keyWithIdPrefix) { buffer.writeId(id); } buffer.write(prop.type().code()); buffer.writeId(pkeyId); return buffer.bytes(); }
@Override protected Id writeQueryId(HugeType type, Id id) { if (type.isEdge()) { id = writeEdgeId(id); } else { BytesBuffer buffer = BytesBuffer.allocate(1 + id.length()); id = new BinaryId(buffer.writeId(id).bytes(), id); } return id; }
protected byte[] formatSyspropName(Id id, HugeKeys col) { int idLen = this.keyWithIdPrefix ? 1 + id.length() : 0; BytesBuffer buffer = BytesBuffer.allocate(idLen + 1 + 1); byte sysprop = HugeType.SYS_PROPERTY.code(); if (this.keyWithIdPrefix) { buffer.writeId(id); } return buffer.write(sysprop).write(col.code()).bytes(); }
protected static BinaryId formatIndexId(HugeType type, Id indexLabel, Object fieldValues) { Id id = HugeIndex.formatIndexId(type, indexLabel, fieldValues); if (indexIdLengthExceedLimit(id)) { id = HugeIndex.formatIndexHashId(type, indexLabel, fieldValues); } BytesBuffer buffer = BytesBuffer.allocate(1 + id.length()); return new BinaryId(buffer.writeId(id).bytes(), id); }
protected BackendColumn formatLabel(HugeElement elem) { BackendColumn col = new BackendColumn(); col.name = this.formatSyspropName(elem.id(), HugeKeys.LABEL); Id label = elem.schemaLabel().id(); BytesBuffer buffer = BytesBuffer.allocate(label.length() + 1); col.value = buffer.writeId(label).bytes(); return col; }
@Watched(prefix = "edge") public void assignId() { // Generate an id and assign this.id = new EdgeId(this.ownerVertex(), this.direction(), this.schemaLabel().id(), this.name(), this.otherVertex()); int len = this.id.length(); E.checkArgument(len <= BytesBuffer.BIG_ID_MAX_LEN, "The max length of edge id is %s, but got %s {%s}", BytesBuffer.BIG_ID_MAX_LEN, len, this.id); }