int blockPositionCount = singleMapBlock.getPositionCount(); if (blockPositionCount % 2 != 0) { throw new IllegalArgumentException(format("block position count is not even: %s", blockPositionCount)); if (singleMapBlock.isNull(i)) { throw new IllegalArgumentException("Map keys must not be null"); singleMapBlock.writePositionTo(i, keyBlockBuilder); if (singleMapBlock.isNull(i + 1)) { valueBlockBuilder.appendNull(); singleMapBlock.writePositionTo(i + 1, valueBlockBuilder); closeEntry(singleMapBlock.getHashTable(), singleMapBlock.getOffset() / 2 * HASH_MULTIPLIER); return this;
for (int position = 0; position < leftSingleMapLeftBlock.getPositionCount(); position += 2) { Object key = readNativeValue(keyType, leftBlock, position); int leftPosition = position + 1; int rightPosition = rightSingleMapBlock.seekKey(key); if (rightPosition == -1) { return false;
@Override public Block getLoadedBlock() { if (keyBlock != keyBlock.getLoadedBlock()) { // keyBlock has to be loaded since MapBlock constructs hash table eagerly. throw new IllegalStateException(); } Block loadedValueBlock = valueBlock.getLoadedBlock(); if (loadedValueBlock == valueBlock) { return this; } return new SingleMapBlock( offset, positionCount, keyBlock, loadedValueBlock, hashTable, keyType, keyNativeHashCode, keyBlockNativeEquals); }
@Override public void writeBlock(BlockEncodingSerde blockEncodingSerde, SliceOutput sliceOutput, Block block) { SingleMapBlock singleMapBlock = (SingleMapBlock) block; TypeSerde.writeType(sliceOutput, singleMapBlock.keyType); int offset = singleMapBlock.getOffset(); int positionCount = singleMapBlock.getPositionCount(); blockEncodingSerde.writeBlock(sliceOutput, singleMapBlock.getRawKeyBlock().getRegion(offset / 2, positionCount / 2)); blockEncodingSerde.writeBlock(sliceOutput, singleMapBlock.getRawValueBlock().getRegion(offset / 2, positionCount / 2)); int[] hashTable = singleMapBlock.getHashTable(); sliceOutput.appendInt(positionCount / 2 * HASH_MULTIPLIER); sliceOutput.writeBytes(wrappedIntArray(hashTable, offset / 2 * HASH_MULTIPLIER, positionCount / 2 * HASH_MULTIPLIER)); }
throw handleThrowable(throwable); throw handleThrowable(throwable); checkNotIndeterminate(match); if (match) { return keyPosition * 2 + 1;
assertEquals(elementBlock.getPositionCount(), map.size() * 2); int pos = elementBlock.seekKey(utf8Slice(entry.getKey())); assertNotEquals(pos, -1); if (entry.getValue() == null) { assertTrue(elementBlock.isNull(pos)); assertFalse(elementBlock.isNull(pos)); assertEquals(BIGINT.getLong(elementBlock, pos), (long) entry.getValue()); assertEquals(elementBlock.seekKey(utf8Slice("not-inserted-" + i)), -1); for (int i = 0; i < elementBlock.getPositionCount(); i += 2) { String actualKey = VARCHAR.getSlice(elementBlock, i).toStringUtf8(); Long actualValue; if (elementBlock.isNull(i + 1)) { actualValue = null;
@Override public String toString() { return format("SingleMapBlock{positionCount=%d}", getPositionCount()); }
@Override public void writeBlock(BlockEncodingSerde blockEncodingSerde, SliceOutput sliceOutput, Block block) { SingleMapBlock singleMapBlock = (SingleMapBlock) block; TypeSerde.writeType(sliceOutput, singleMapBlock.keyType); int offset = singleMapBlock.getOffset(); int positionCount = singleMapBlock.getPositionCount(); blockEncodingSerde.writeBlock(sliceOutput, singleMapBlock.getRawKeyBlock().getRegion(offset / 2, positionCount / 2)); blockEncodingSerde.writeBlock(sliceOutput, singleMapBlock.getRawValueBlock().getRegion(offset / 2, positionCount / 2)); int[] hashTable = singleMapBlock.getHashTable(); sliceOutput.appendInt(positionCount / 2 * HASH_MULTIPLIER); sliceOutput.writeBytes(wrappedIntArray(hashTable, offset / 2 * HASH_MULTIPLIER, positionCount / 2 * HASH_MULTIPLIER)); }
throw handleThrowable(throwable); throw handleThrowable(throwable); checkNotIndeterminate(match); if (match) { return keyPosition * 2 + 1;
@Override public String toString() { return format("SingleMapBlock{positionCount=%d}", getPositionCount()); }
int blockPositionCount = singleMapBlock.getPositionCount(); if (blockPositionCount % 2 != 0) { throw new IllegalArgumentException(format("block position count is not even: %s", blockPositionCount)); if (singleMapBlock.isNull(i)) { throw new IllegalArgumentException("Map keys must not be null"); singleMapBlock.writePositionTo(i, keyBlockBuilder); if (singleMapBlock.isNull(i + 1)) { valueBlockBuilder.appendNull(); singleMapBlock.writePositionTo(i + 1, valueBlockBuilder); closeEntry(singleMapBlock.getHashTable(), singleMapBlock.getOffset() / 2 * HASH_MULTIPLIER); return this;
boolean[] keyFound = new boolean[rightMapBlock.getPositionCount()]; for (int leftKeyPosition = 0; leftKeyPosition < leftMapBlock.getPositionCount(); leftKeyPosition += 2) { Object key = readNativeValue(keyType, leftMapBlock, leftKeyPosition); Object leftValue = readNativeValue(leftValueType, leftMapBlock, leftKeyPosition + 1); int rightValuePosition = rightMapBlock.seekKey(key); Object rightValue = null; if (rightValuePosition != -1) { for (int rightKeyPosition = 0; rightKeyPosition < rightMapBlock.getPositionCount(); rightKeyPosition += 2) { if (!keyFound[rightKeyPosition / 2]) { Object key = readNativeValue(keyType, rightMapBlock, rightKeyPosition);
throw handleThrowable(throwable); throw handleThrowable(throwable); checkNotIndeterminate(match); if (match) { return keyPosition * 2 + 1;
@Override public <T> T getObject(int position, Class<T> clazz) { if (clazz != Block.class) { throw new IllegalArgumentException("clazz must be Block.class"); } checkReadablePosition(position); int startEntryOffset = getOffset(position); int endEntryOffset = getOffset(position + 1); return clazz.cast(new SingleMapBlock( startEntryOffset * 2, (endEntryOffset - startEntryOffset) * 2, getRawKeyBlock(), getRawValueBlock(), getHashTables(), keyType, keyNativeHashCode, keyBlockNativeEquals)); }
throw handleThrowable(throwable); throw handleThrowable(throwable); checkNotIndeterminate(match); if (match) { return keyPosition * 2 + 1;
@Override public Block readBlock(BlockEncodingSerde blockEncodingSerde, SliceInput sliceInput) { Type keyType = TypeSerde.readType(typeManager, sliceInput); MethodHandle keyNativeEquals = typeManager.resolveOperator(OperatorType.EQUAL, asList(keyType, keyType)); MethodHandle keyBlockNativeEquals = compose(keyNativeEquals, nativeValueGetter(keyType)); MethodHandle keyNativeHashCode = typeManager.resolveOperator(OperatorType.HASH_CODE, singletonList(keyType)); Block keyBlock = blockEncodingSerde.readBlock(sliceInput); Block valueBlock = blockEncodingSerde.readBlock(sliceInput); int[] hashTable = new int[sliceInput.readInt()]; sliceInput.readBytes(wrappedIntArray(hashTable)); if (keyBlock.getPositionCount() != valueBlock.getPositionCount() || keyBlock.getPositionCount() * HASH_MULTIPLIER != hashTable.length) { throw new IllegalArgumentException( format("Deserialized SingleMapBlock violates invariants: key %d, value %d, hash %d", keyBlock.getPositionCount(), valueBlock.getPositionCount(), hashTable.length)); } return new SingleMapBlock(0, keyBlock.getPositionCount() * 2, keyBlock, valueBlock, hashTable, keyType, keyNativeHashCode, keyBlockNativeEquals); } }
throw handleThrowable(throwable); throw handleThrowable(throwable); checkNotIndeterminate(match); if (match) { return keyPosition * 2 + 1;
@Override public Block getLoadedBlock() { if (keyBlock != keyBlock.getLoadedBlock()) { // keyBlock has to be loaded since MapBlock constructs hash table eagerly. throw new IllegalStateException(); } Block loadedValueBlock = valueBlock.getLoadedBlock(); if (loadedValueBlock == valueBlock) { return this; } return new SingleMapBlock( offset, positionCount, keyBlock, loadedValueBlock, hashTable, keyType, keyNativeHashCode, keyBlockNativeEquals); }
throw handleThrowable(throwable); throw handleThrowable(throwable); checkNotIndeterminate(match); if (match) { return keyPosition * 2 + 1;
@Override public <T> T getObject(int position, Class<T> clazz) { if (clazz != Block.class) { throw new IllegalArgumentException("clazz must be Block.class"); } checkReadablePosition(position); int startEntryOffset = getOffset(position); int endEntryOffset = getOffset(position + 1); return clazz.cast(new SingleMapBlock( startEntryOffset * 2, (endEntryOffset - startEntryOffset) * 2, getRawKeyBlock(), getRawValueBlock(), getHashTables(), keyType, keyNativeHashCode, keyBlockNativeEquals)); }