use of org.janusgraph.diskstorage.EntryMetaData in project janusgraph by JanusGraph.
the class CQLResultSetKeyIteratorTest method testPartialIterateColumns.
@Test
public void testPartialIterateColumns() throws IOException {
final Random random = new Random();
final Function1<Integer, ByteBuffer> randomLong = idx -> {
final ByteBuffer buffer = ByteBuffer.allocate(Long.BYTES).putLong(random.nextLong());
buffer.flip();
return buffer;
};
final Array<Tuple2<ByteBuffer, Array<Tuple2<ByteBuffer, ByteBuffer>>>> keysMap = Array.range(0, random.nextInt(100) + 100).map(randomLong).map(key -> Tuple.of(key, Array.rangeClosed(0, random.nextInt(100) + 1).map(idx -> Tuple.of(randomLong.apply(idx), randomLong.apply(idx)))));
final Seq<Row> rows = keysMap.flatMap(tuple -> tuple._2.map(columnAndValue -> {
final Row row = mock(Row.class);
when(row.getBytes("key")).thenReturn(tuple._1);
when(row.getBytes("column1")).thenReturn(columnAndValue._1);
when(row.getBytes("value")).thenReturn(columnAndValue._2);
return row;
}));
final ResultSet resultSet = mock(ResultSet.class);
when(resultSet.iterator()).thenReturn(rows.iterator());
final CQLColValGetter getter = new CQLColValGetter(new EntryMetaData[0]);
try (final CQLResultSetKeyIterator resultSetKeyIterator = new CQLResultSetKeyIterator(ALL_COLUMNS, getter, resultSet)) {
final Iterator<Tuple2<ByteBuffer, Array<Tuple2<ByteBuffer, ByteBuffer>>>> iterator = keysMap.iterator();
while (resultSetKeyIterator.hasNext()) {
final StaticBuffer next = resultSetKeyIterator.next();
try (final RecordIterator<Entry> entries = resultSetKeyIterator.getEntries()) {
final Tuple2<ByteBuffer, Array<Tuple2<ByteBuffer, ByteBuffer>>> current = iterator.next();
final ByteBuffer currentKey = current._1;
final Array<Tuple2<ByteBuffer, ByteBuffer>> columnValues = current._2;
final Iterator<Tuple2<ByteBuffer, ByteBuffer>> columnIterator = columnValues.iterator();
while (entries.hasNext()) {
final Entry entry = entries.next();
final Tuple2<ByteBuffer, ByteBuffer> columnAndValue = columnIterator.next();
assertEquals(currentKey, next.asByteBuffer());
assertEquals(columnAndValue._1, entry.getColumn().asByteBuffer());
assertEquals(columnAndValue._2, entry.getValue().asByteBuffer());
assertEquals(columnIterator.hasNext(), entries.hasNext());
// 10% of the time, don't complete the iteration
if (random.nextInt(10) == 0) {
break;
}
}
}
}
}
}
use of org.janusgraph.diskstorage.EntryMetaData in project janusgraph by JanusGraph.
the class EdgeSerializer method parseRelation.
@Override
public RelationCache parseRelation(Entry data, boolean excludeProperties, TypeInspector tx) {
ReadBuffer in = data.asReadBuffer();
LongObjectHashMap properties = excludeProperties ? null : new LongObjectHashMap(4);
RelationTypeParse typeAndDir = IDHandler.readRelationType(in);
long typeId = typeAndDir.typeId;
Direction dir = typeAndDir.dirID.getDirection();
RelationType relationType = tx.getExistingRelationType(typeId);
InternalRelationType def = (InternalRelationType) relationType;
Multiplicity multiplicity = def.multiplicity();
long[] keySignature = def.getSortKey();
long relationId;
Object other;
int startKeyPos = in.getPosition();
int endKeyPos = 0;
if (relationType.isEdgeLabel()) {
long otherVertexId;
if (multiplicity.isConstrained()) {
if (multiplicity.isUnique(dir)) {
otherVertexId = VariableLong.readPositive(in);
} else {
in.movePositionTo(data.getValuePosition());
otherVertexId = VariableLong.readPositiveBackward(in);
in.movePositionTo(data.getValuePosition());
}
relationId = VariableLong.readPositive(in);
} else {
in.movePositionTo(data.getValuePosition());
relationId = VariableLong.readPositiveBackward(in);
otherVertexId = VariableLong.readPositiveBackward(in);
endKeyPos = in.getPosition();
in.movePositionTo(data.getValuePosition());
}
other = otherVertexId;
} else {
assert relationType.isPropertyKey();
PropertyKey key = (PropertyKey) relationType;
if (multiplicity.isConstrained()) {
other = readPropertyValue(in, key);
relationId = VariableLong.readPositive(in);
} else {
in.movePositionTo(data.getValuePosition());
relationId = VariableLong.readPositiveBackward(in);
endKeyPos = in.getPosition();
in.movePositionTo(data.getValuePosition());
other = readPropertyValue(in, key);
}
Preconditions.checkState(other != null, "Encountered error in deserializer [null value returned]. Check serializer compatibility.");
}
assert other != null;
if (!excludeProperties && !multiplicity.isConstrained() && keySignature.length > 0) {
int currentPos = in.getPosition();
// Read sort key which only exists if type is not unique in this direction
assert endKeyPos > startKeyPos;
// after reading the ids, we are on the last byte of the key
int keyLength = endKeyPos - startKeyPos;
in.movePositionTo(startKeyPos);
ReadBuffer inKey = in;
if (def.getSortOrder() == Order.DESC)
inKey = in.subrange(keyLength, true);
readInlineTypes(keySignature, properties, inKey, tx, InlineType.KEY);
in.movePositionTo(currentPos);
}
if (!excludeProperties) {
// read value signature
readInlineTypes(def.getSignature(), properties, in, tx, InlineType.SIGNATURE);
// Third: read rest
while (in.hasRemaining()) {
PropertyKey type = tx.getExistingPropertyKey(IDHandler.readInlineRelationType(in));
Object propertyValue = readInline(in, type, InlineType.NORMAL);
assert propertyValue != null;
properties.put(type.longId(), propertyValue);
}
if (data.hasMetaData()) {
for (Map.Entry<EntryMetaData, Object> metas : data.getMetaData().entrySet()) {
ImplicitKey key = ImplicitKey.MetaData2ImplicitKey.get(metas.getKey());
if (key != null) {
assert metas.getValue() != null;
properties.put(key.longId(), metas.getValue());
}
}
}
}
return new RelationCache(dir, typeId, relationId, other, properties);
}
use of org.janusgraph.diskstorage.EntryMetaData in project janusgraph by JanusGraph.
the class AbstractStoreManager method getMetaDataSchema.
public EntryMetaData[] getMetaDataSchema(String storeName) {
List<EntryMetaData> schemaBuilder = Lists.newArrayList();
StoreFeatures features = getFeatures();
if (features.hasTimestamps() && storageConfig.get(STORE_META_TIMESTAMPS, storeName))
schemaBuilder.add(EntryMetaData.TIMESTAMP);
if (features.hasCellTTL() && storageConfig.get(STORE_META_TTL, storeName))
schemaBuilder.add(EntryMetaData.TTL);
if (features.hasVisibility() && storageConfig.get(STORE_META_VISIBILITY, storeName))
schemaBuilder.add(EntryMetaData.VISIBILITY);
if (schemaBuilder.isEmpty())
return StaticArrayEntry.EMPTY_SCHEMA;
return schemaBuilder.toArray(new EntryMetaData[schemaBuilder.size()]);
}
use of org.janusgraph.diskstorage.EntryMetaData in project janusgraph by JanusGraph.
the class CQLResultSetKeyIteratorTest method testUneven.
@Test
public void testUneven() throws IOException {
final Random random = new Random();
final Function1<Integer, ByteBuffer> randomLong = idx -> {
final ByteBuffer buffer = ByteBuffer.allocate(Long.BYTES).putLong(random.nextLong());
buffer.flip();
return buffer;
};
final Array<Tuple2<ByteBuffer, Array<Tuple2<ByteBuffer, ByteBuffer>>>> keysMap = Array.range(0, random.nextInt(100) + 100).map(randomLong).map(key -> Tuple.of(key, Array.rangeClosed(0, random.nextInt(100) + 1).map(idx -> Tuple.of(randomLong.apply(idx), randomLong.apply(idx)))));
final Seq<Row> rows = keysMap.flatMap(tuple -> tuple._2.map(columnAndValue -> {
final Row row = mock(Row.class);
when(row.getBytes("key")).thenReturn(tuple._1);
when(row.getBytes("column1")).thenReturn(columnAndValue._1);
when(row.getBytes("value")).thenReturn(columnAndValue._2);
return row;
}));
final ResultSet resultSet = mock(ResultSet.class);
when(resultSet.iterator()).thenReturn(rows.iterator());
final CQLColValGetter getter = new CQLColValGetter(new EntryMetaData[0]);
try (final CQLResultSetKeyIterator resultSetKeyIterator = new CQLResultSetKeyIterator(ALL_COLUMNS, getter, resultSet)) {
final Iterator<Tuple2<ByteBuffer, Array<Tuple2<ByteBuffer, ByteBuffer>>>> iterator = keysMap.iterator();
while (resultSetKeyIterator.hasNext()) {
final StaticBuffer next = resultSetKeyIterator.next();
try (final RecordIterator<Entry> entries = resultSetKeyIterator.getEntries()) {
final Tuple2<ByteBuffer, Array<Tuple2<ByteBuffer, ByteBuffer>>> current = iterator.next();
final ByteBuffer currentKey = current._1;
final Array<Tuple2<ByteBuffer, ByteBuffer>> columnValues = current._2;
final Iterator<Tuple2<ByteBuffer, ByteBuffer>> columnIterator = columnValues.iterator();
while (entries.hasNext()) {
final Entry entry = entries.next();
final Tuple2<ByteBuffer, ByteBuffer> columnAndValue = columnIterator.next();
assertEquals(currentKey, next.asByteBuffer());
assertEquals(columnAndValue._1, entry.getColumn().asByteBuffer());
assertEquals(columnAndValue._2, entry.getValue().asByteBuffer());
assertEquals(columnIterator.hasNext(), entries.hasNext());
}
}
}
}
}
use of org.janusgraph.diskstorage.EntryMetaData in project janusgraph by JanusGraph.
the class CQLResultSetKeyIteratorTest method testNoIterateColumns.
@Test
public void testNoIterateColumns() throws IOException {
final Random random = new Random();
final Function1<Integer, ByteBuffer> randomLong = idx -> {
final ByteBuffer buffer = ByteBuffer.allocate(Long.BYTES).putLong(random.nextLong());
buffer.flip();
return buffer;
};
final Array<Tuple2<ByteBuffer, Array<Tuple2<ByteBuffer, ByteBuffer>>>> keysMap = Array.range(0, random.nextInt(100) + 100).map(randomLong).map(key -> Tuple.of(key, Array.rangeClosed(0, random.nextInt(100) + 1).map(idx -> Tuple.of(randomLong.apply(idx), randomLong.apply(idx)))));
final Seq<Row> rows = keysMap.flatMap(tuple -> tuple._2.map(columnAndValue -> {
final Row row = mock(Row.class);
when(row.getBytes("key")).thenReturn(tuple._1);
when(row.getBytes("column1")).thenReturn(columnAndValue._1);
when(row.getBytes("value")).thenReturn(columnAndValue._2);
return row;
}));
final ResultSet resultSet = mock(ResultSet.class);
when(resultSet.iterator()).thenReturn(rows.iterator());
final CQLColValGetter getter = new CQLColValGetter(new EntryMetaData[0]);
try (final CQLResultSetKeyIterator resultSetKeyIterator = new CQLResultSetKeyIterator(ALL_COLUMNS, getter, resultSet)) {
final Iterator<Tuple2<ByteBuffer, Array<Tuple2<ByteBuffer, ByteBuffer>>>> iterator = keysMap.iterator();
while (resultSetKeyIterator.hasNext()) {
final StaticBuffer next = resultSetKeyIterator.next();
assertEquals(iterator.next()._1, next.asByteBuffer());
}
}
}
Aggregations