@Override public Block readBlock(SliceInput sliceInput) { int positionCount = sliceInput.readInt(); boolean[] valueIsNull = decodeNullBits(sliceInput, positionCount); long[] values = new long[positionCount]; for (int position = 0; position < positionCount; position++) { if (!valueIsNull[position]) { values[position] = sliceInput.readLong(); } } return new LongArrayBlock(positionCount, valueIsNull, values); }
@Override public void deserialize(Block block, int index, MaxOrMinByState state) { SliceInput input = block.getSlice(index, 0, block.getLength(index)).getInput(); int keyLength = input.readInt(); int valueLength = input.readInt(); state.setKey(null); state.setValue(null); if (keyLength > 0) { state.setKey(toBlock(keyType, input, keyLength)); } if (valueLength > 0) { state.setValue(toBlock(valueType, input, valueLength)); } }
private static Block toBlock(Type type, SliceInput input, int length) { BlockBuilder builder = type.createBlockBuilder(new BlockBuilderStatus(), 1, length); if (type.getJavaType() == long.class) { type.writeLong(builder, input.readLong()); } else if (type.getJavaType() == double.class) { type.writeDouble(builder, input.readDouble()); } else if (type.getJavaType() == Slice.class) { type.writeSlice(builder, input.readSlice(length)); } else if (type.getJavaType() == boolean.class) { type.writeBoolean(builder, input.readByte() != 0); } else { throw new IllegalArgumentException("Unsupported type: " + type.getJavaType().getSimpleName()); } return builder.build(); }