/** * Writes the byte representation of a GradoopId into the target byte array * starting at the specified offset * @param value GradoopId that will be written * @param target Target byte array * @param offset offset the value will be written to */ private void writeId(GradoopId value, byte[] target, int offset) { System.arraycopy(value.toByteArray(), 0, target, offset, GradoopId.ID_SIZE); }
/** * Writes the byte representation of a GradoopId into the target byte array * starting at the specified offset * @param value GradoopId that will be written * @param target Target byte array * @param offset offset the value will be written to */ private void writeId(GradoopId value, byte[] target, int offset) { System.arraycopy(value.toByteArray(), 0, target, offset, GradoopId.ID_SIZE); }
/** * Adds an entry to the embedding. * This can either be an ID representing referencing a Vertex/Edge or a pointer to a path entry * @param id the id that will be added to the embedding * @param isIdList indicates if the id represents a GraphElement or points to a path entry */ private void add(GradoopId id, boolean isIdList) { byte[] newIds = new byte[idData.length + 1 + GradoopId.ID_SIZE]; System.arraycopy(idData, 0, newIds, 0, idData.length); newIds[idData.length] = isIdList ? ID_LIST_FLAG : ID_ENTRY_FLAG; System.arraycopy(id.toByteArray(), 0, newIds, idData.length + 1, GradoopId.ID_SIZE); idData = newIds; }
/** * Adds an entry to the embedding. * This can either be an ID representing referencing a Vertex/Edge or a pointer to a path entry * @param id the id that will be added to the embedding * @param isIdList indicates if the id represents a GraphElement or points to a path entry */ private void add(GradoopId id, boolean isIdList) { byte[] newIds = new byte[idData.length + 1 + GradoopId.ID_SIZE]; System.arraycopy(idData, 0, newIds, 0, idData.length); newIds[idData.length] = isIdList ? ID_LIST_FLAG : ID_ENTRY_FLAG; System.arraycopy(id.toByteArray(), 0, newIds, idData.length + 1, GradoopId.ID_SIZE); idData = newIds; }
/** * Serialize all ids into a byte array. * @param ids sequence of {@link GradoopId}s * @return a binary representation */ private byte[] writeIds(Set<GradoopId> ids) { byte[] bytes = new byte[ids.size() * GradoopId.ID_SIZE]; int i = 0; for (GradoopId id : ids) { System.arraycopy(id.toByteArray(), 0, bytes, i * GradoopId.ID_SIZE, GradoopId.ID_SIZE); i++; } return bytes; }
/** * Appends all ids to the embeddings * * @param ids list of ids */ public void addAll(GradoopId... ids) { byte[] newIds = new byte[idData.length + ids.length * ID_ENTRY_SIZE]; System.arraycopy(idData, 0, newIds, 0, idData.length); int offset = idData.length; for (GradoopId id : ids) { newIds[offset] = ID_ENTRY_FLAG; System.arraycopy(id.toByteArray(), 0, newIds, offset + 1, GradoopId.ID_SIZE); offset += ID_ENTRY_SIZE; } idData = newIds; } /**
/** * Appends all ids to the embeddings * * @param ids list of ids */ public void addAll(GradoopId... ids) { byte[] newIds = new byte[idData.length + ids.length * ID_ENTRY_SIZE]; System.arraycopy(idData, 0, newIds, 0, idData.length); int offset = idData.length; for (GradoopId id : ids) { newIds[offset] = ID_ENTRY_FLAG; System.arraycopy(id.toByteArray(), 0, newIds, offset + 1, GradoopId.ID_SIZE); offset += ID_ENTRY_SIZE; } idData = newIds; } /**
/** * {@inheritDoc} * Used for writing the rowKey to HBase. */ @Override public byte[] getRowKey(@Nonnull final GradoopId elementId) { return useSpreadingByte ? RowKeyDistributor.getInstance().getDistributedKey(elementId.toByteArray()) : elementId.toByteArray(); }
@Override public Put writeSource(final Put put, final GradoopId sourceId) { return put.addColumn(CF_META_BYTES, COL_SOURCE_BYTES, sourceId.toByteArray()); }
/** * Sets the wrapped value as {@code GradoopId} value. * * @param gradoopIdValue value */ public void setGradoopId(GradoopId gradoopIdValue) { byte[] valueBytes = gradoopIdValue.toByteArray(); rawBytes = new byte[OFFSET + GradoopId.ID_SIZE]; rawBytes[0] = TYPE_GRADOOP_ID; Bytes.putBytes(rawBytes, OFFSET, valueBytes, 0, valueBytes.length); }
@Override public Put writeTarget(Put put, GradoopId targetId) { return put.addColumn(CF_META_BYTES, COL_TARGET_BYTES, targetId.toByteArray()); }
@Override public List<byte[]> getPossibleRowKeys(@Nonnull final GradoopId elementId) { List<byte[]> possibleKeys = new ArrayList<>(); final byte[][] allDistributedKeys = RowKeyDistributor.getInstance() .getAllDistributedKeys(elementId.toByteArray()); Collections.addAll(possibleKeys, allDistributedKeys); return possibleKeys; } }
@Override public GraphHead readGraph(@Nonnull final GradoopId graphId) throws IOException { GraphHead graphData = null; GraphHeadHandler graphHeadHandler = config.getGraphHeadHandler(); List<Get> getList = new ArrayList<>(); if (graphHeadHandler.isSpreadingByteUsed()) { for (byte[] rowKey : graphHeadHandler.getPossibleRowKeys(graphId)) { getList.add(new Get(rowKey)); } } else { getList.add(new Get(graphId.toByteArray())); } final Result[] results = graphHeadTable.get(getList); for (Result res : results) { if (!res.isEmpty()) { graphData = graphHeadHandler.readGraphHead(res); break; } } return graphData; }
byte[] rowKey = Bytes.add(dummyByte, gradoopId.toByteArray()); fuzzyList.add(new Pair<>(rowKey, fuzzyInfo)); RowFilter rowFilter = new RowFilter( CompareFilter.CompareOp.EQUAL, new BinaryComparator(gradoopId.toByteArray()) ); filterList.addFilter(rowFilter);
@Test public void testGetRawBytes() { GradoopId originalId = GradoopId.get(); assertEquals(GradoopId.ID_SIZE, originalId.toByteArray().length); assertEquals( "Reconstruction failed", originalId, GradoopId.fromByteArray(originalId.toByteArray()) ); }
@Test public void testMultiColumn() throws Exception { GradoopId v0 = GradoopId.get(); GradoopId v1 = GradoopId.get(); Embedding embedding = createEmbedding(v0, v1); ExtractJoinColumns udf = new ExtractJoinColumns(Arrays.asList(0, 1)); Assert.assertEquals( ArrayUtils.toString(v0.toByteArray()) + ArrayUtils.toString(v1.toByteArray()), udf.getKey(embedding) ); }
@Test public void testSingleColumn() throws Exception { GradoopId v0 = GradoopId.get(); GradoopId v1 = GradoopId.get(); Embedding embedding = createEmbedding(v0, v1); ExtractJoinColumns udf = new ExtractJoinColumns(Collections.singletonList(0)); Assert.assertEquals(ArrayUtils.toString(v0.toByteArray()), udf.getKey(embedding)); }
@Test public void testGetIdBytesByColumn() { GradoopId id = GradoopId.get(); Embedding embedding = new Embedding(); embedding.add(id); assertArrayEquals(id.toByteArray(), embedding.getRawId(0)); }
/** * Test if {@link GradoopId}s implement * {@link org.apache.flink.types.NormalizableKey#copyNormalizedKey(MemorySegment, int, int)} * correctly. * The normalized key representation of a {@link GradoopId} should be equal to its * byte-representation. */ @Test public void testCopyAsNormalizedKey() { GradoopId inputId = GradoopId.get(); byte[] byteRepresentationBuffer = new byte[GradoopId.ID_SIZE]; MemorySegment memorySegment = MemorySegmentFactory.wrap(byteRepresentationBuffer); inputId.copyNormalizedKey(memorySegment, 0, inputId.getMaxNormalizedKeyLen()); assertArrayEquals(inputId.toByteArray(), byteRepresentationBuffer); }
@Test public void testGetIdBytesOfProjectionEntry() { GradoopId id = GradoopId.get(); Embedding embedding = new Embedding(); embedding.add(id, PropertyValue.create("String"), PropertyValue.create(42)); assertArrayEquals(id.toByteArray(), embedding.getRawId(0)); }