Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import static io.trino.spi.block.ArrayBlock.createArrayBlockInternal;
import static io.trino.spi.block.EncoderUtil.decodeNullBits;
import static io.trino.spi.block.EncoderUtil.encodeNullsAsBits;
import static io.trino.spi.block.EncoderUtil.retrieveNullBits;

public class ArrayBlockEncoding
implements BlockEncoding
Expand Down Expand Up @@ -67,7 +68,12 @@ public ArrayBlock readBlock(BlockEncodingSerde blockEncodingSerde, SliceInput sl
int positionCount = sliceInput.readInt();
int[] offsets = new int[positionCount + 1];
sliceInput.readInts(offsets);
boolean[] valueIsNull = decodeNullBits(sliceInput, positionCount).orElse(null);
byte[] valueIsNullPacked = retrieveNullBits(sliceInput, positionCount);
if (valueIsNullPacked == null) {
return createArrayBlockInternal(0, positionCount, null, offsets, values);
}

boolean[] valueIsNull = decodeNullBits(valueIsNullPacked, positionCount);
return createArrayBlockInternal(0, positionCount, valueIsNull, offsets, values);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import static io.trino.spi.block.EncoderUtil.decodeNullBits;
import static io.trino.spi.block.EncoderUtil.encodeNullsAsBits;
import static io.trino.spi.block.EncoderUtil.retrieveNullBits;
import static java.lang.System.arraycopy;
import static java.util.Objects.checkFromIndexSize;

public class ByteArrayBlockEncoding
Expand Down Expand Up @@ -56,20 +55,7 @@ public void writeBlock(BlockEncodingSerde blockEncodingSerde, SliceOutput sliceO

encodeNullsAsBits(sliceOutput, isNull, rawOffset, positionCount);

if (isNull == null) {
sliceOutput.writeBytes(rawValues, rawOffset, positionCount);
}
else {
byte[] valuesWithoutNull = new byte[positionCount];
int nonNullPositionCount = 0;
for (int i = 0; i < positionCount; i++) {
valuesWithoutNull[nonNullPositionCount] = rawValues[i + rawOffset];
nonNullPositionCount += isNull[i + rawOffset] ? 0 : 1;
}

sliceOutput.writeInt(nonNullPositionCount);
sliceOutput.writeBytes(valuesWithoutNull, 0, nonNullPositionCount);
}
sliceOutput.writeBytes(rawValues, rawOffset, positionCount);
}

@Override
Expand All @@ -79,42 +65,13 @@ public ByteArrayBlock readBlock(BlockEncodingSerde blockEncodingSerde, SliceInpu

byte[] valueIsNullPacked = retrieveNullBits(sliceInput, positionCount);
byte[] values = new byte[positionCount];
sliceInput.readBytes(Slices.wrappedBuffer(values));

if (valueIsNullPacked == null) {
sliceInput.readBytes(Slices.wrappedBuffer(values));
return new ByteArrayBlock(0, positionCount, null, values);
}
boolean[] valueIsNull = decodeNullBits(valueIsNullPacked, positionCount);

int nonNullPositionCount = sliceInput.readInt();
sliceInput.readBytes(Slices.wrappedBuffer(values, 0, nonNullPositionCount));
int position = nonNullPositionCount - 1;

// Handle Last (positionCount % 8) values
for (int i = positionCount - 1; i >= (positionCount & ~0b111) && position >= 0; i--) {
values[i] = values[position];
if (!valueIsNull[i]) {
position--;
}
}

// Handle the remaining positions.
for (int i = (positionCount & ~0b111) - 8; i >= 0 && position >= 0; i -= 8) {
byte packed = valueIsNullPacked[i >>> 3];
if (packed == 0) { // Only values
arraycopy(values, position - 7, values, i, 8);
position -= 8;
}
else if (packed != -1) { // At least one non-null
for (int j = i + 7; j >= i && position >= 0; j--) {
values[j] = values[position];
if (!valueIsNull[j]) {
position--;
}
}
}
// Do nothing if there are only nulls
}
return new ByteArrayBlock(0, positionCount, valueIsNull, values);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import static io.trino.spi.block.EncoderUtil.decodeNullBits;
import static io.trino.spi.block.EncoderUtil.encodeNullsAsBits;
import static io.trino.spi.block.EncoderUtil.retrieveNullBits;
import static java.util.Objects.checkFromIndexSize;

public class Fixed12BlockEncoding
Expand Down Expand Up @@ -53,47 +54,24 @@ public void writeBlock(BlockEncodingSerde blockEncodingSerde, SliceOutput sliceO

encodeNullsAsBits(sliceOutput, isNull, rawArrayOffset, positionCount);

if (isNull == null) {
sliceOutput.writeInts(rawValues, rawArrayOffset * 3, positionCount * 3);
}
else {
int[] valuesWithoutNull = new int[positionCount * 3];
int nonNullPositionCount = 0;
for (int i = 0; i < positionCount; i++) {
int rawIntOffset = (i + rawArrayOffset) * 3;
valuesWithoutNull[nonNullPositionCount] = rawValues[rawIntOffset];
valuesWithoutNull[nonNullPositionCount + 1] = rawValues[rawIntOffset + 1];
valuesWithoutNull[nonNullPositionCount + 2] = rawValues[rawIntOffset + 2];
nonNullPositionCount += isNull[i + rawArrayOffset] ? 0 : 3;
}

sliceOutput.writeInt(nonNullPositionCount / 3);
sliceOutput.writeInts(valuesWithoutNull, 0, nonNullPositionCount);
}
sliceOutput.writeInts(rawValues, rawArrayOffset * 3, positionCount * 3);
}

@Override
public Fixed12Block readBlock(BlockEncodingSerde blockEncodingSerde, SliceInput sliceInput)
{
int positionCount = sliceInput.readInt();

boolean[] valueIsNull = decodeNullBits(sliceInput, positionCount).orElse(null);

byte[] valueIsNullPacked = retrieveNullBits(sliceInput, positionCount);
int[] values = new int[positionCount * 3];
if (valueIsNull == null) {
sliceInput.readInts(values);
}
else {
int nonNullPositionCount = sliceInput.readInt();
sliceInput.readInts(values, 0, nonNullPositionCount * 3);
int position = 3 * (nonNullPositionCount - 1);
for (int i = positionCount - 1; i >= 0 && position >= 0; i--) {
System.arraycopy(values, position, values, 3 * i, 3);
if (!valueIsNull[i]) {
position -= 3;
}
}
sliceInput.readInts(values);

if (valueIsNullPacked == null) {
return new Fixed12Block(0, positionCount, null, values);
}

boolean[] valueIsNull = decodeNullBits(valueIsNullPacked, positionCount);

return new Fixed12Block(0, positionCount, valueIsNull, values);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import static io.trino.spi.block.EncoderUtil.decodeNullBits;
import static io.trino.spi.block.EncoderUtil.encodeNullsAsBits;
import static io.trino.spi.block.EncoderUtil.retrieveNullBits;
import static java.util.Objects.checkFromIndexSize;

public class Int128ArrayBlockEncoding
Expand Down Expand Up @@ -53,46 +54,24 @@ public void writeBlock(BlockEncodingSerde blockEncodingSerde, SliceOutput sliceO

encodeNullsAsBits(sliceOutput, isNull, rawArrayOffset, positionCount);

if (isNull == null) {
sliceOutput.writeLongs(rawValues, rawArrayOffset * 2, positionCount * 2);
}
else {
long[] valuesWithoutNull = new long[positionCount * 2];
int nonNullPositionCount = 0;
for (int i = 0; i < positionCount; i++) {
int rawValuesIndex = (i + rawArrayOffset) * 2;
valuesWithoutNull[nonNullPositionCount] = rawValues[rawValuesIndex];
valuesWithoutNull[nonNullPositionCount + 1] = rawValues[rawValuesIndex + 1];
nonNullPositionCount += isNull[i + rawArrayOffset] ? 0 : 2;
}

sliceOutput.writeInt(nonNullPositionCount / 2);
sliceOutput.writeLongs(valuesWithoutNull, 0, nonNullPositionCount);
}
sliceOutput.writeLongs(rawValues, rawArrayOffset * 2, positionCount * 2);
}

@Override
public Int128ArrayBlock readBlock(BlockEncodingSerde blockEncodingSerde, SliceInput sliceInput)
{
int positionCount = sliceInput.readInt();

boolean[] valueIsNull = decodeNullBits(sliceInput, positionCount).orElse(null);

byte[] valueIsNullPacked = retrieveNullBits(sliceInput, positionCount);
long[] values = new long[positionCount * 2];
if (valueIsNull == null) {

if (valueIsNullPacked == null) {
sliceInput.readLongs(values);
return new Int128ArrayBlock(0, positionCount, null, values);
}
else {
int nonNullPositionCount = sliceInput.readInt();
sliceInput.readLongs(values, 0, nonNullPositionCount * 2);
int position = 2 * (nonNullPositionCount - 1);
for (int i = positionCount - 1; i >= 0 && position >= 0; i--) {
System.arraycopy(values, position, values, 2 * i, 2);
if (!valueIsNull[i]) {
position -= 2;
}
}
}
boolean[] valueIsNull = decodeNullBits(valueIsNullPacked, positionCount);

sliceInput.readLongs(values);

return new Int128ArrayBlock(0, positionCount, valueIsNull, values);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import static io.trino.spi.block.EncoderUtil.decodeNullBits;
import static io.trino.spi.block.EncoderUtil.encodeNullsAsBits;
import static io.trino.spi.block.EncoderUtil.retrieveNullBits;
import static java.lang.System.arraycopy;
import static java.util.Objects.checkFromIndexSize;

public class IntArrayBlockEncoding
Expand Down Expand Up @@ -55,20 +54,7 @@ public void writeBlock(BlockEncodingSerde blockEncodingSerde, SliceOutput sliceO

encodeNullsAsBits(sliceOutput, isNull, rawOffset, positionCount);

if (isNull == null) {
sliceOutput.writeInts(rawValues, rawOffset, positionCount);
}
else {
int[] valuesWithoutNull = new int[positionCount];
int nonNullPositionCount = 0;
for (int i = 0; i < positionCount; i++) {
valuesWithoutNull[nonNullPositionCount] = rawValues[i + rawOffset];
nonNullPositionCount += isNull[i + rawOffset] ? 0 : 1;
}

sliceOutput.writeInt(nonNullPositionCount);
sliceOutput.writeInts(valuesWithoutNull, 0, nonNullPositionCount);
}
sliceOutput.writeInts(rawValues, rawOffset, positionCount);
}

@Override
Expand All @@ -78,42 +64,13 @@ public IntArrayBlock readBlock(BlockEncodingSerde blockEncodingSerde, SliceInput

byte[] valueIsNullPacked = retrieveNullBits(sliceInput, positionCount);
int[] values = new int[positionCount];
sliceInput.readInts(values);

if (valueIsNullPacked == null) {
sliceInput.readInts(values);
return new IntArrayBlock(0, positionCount, null, values);
}
boolean[] valueIsNull = decodeNullBits(valueIsNullPacked, positionCount);

int nonNullPositionCount = sliceInput.readInt();
sliceInput.readInts(values, 0, nonNullPositionCount);
int position = nonNullPositionCount - 1;

// Handle Last (positionCount % 8) values
for (int i = positionCount - 1; i >= (positionCount & ~0b111) && position >= 0; i--) {
values[i] = values[position];
if (!valueIsNull[i]) {
position--;
}
}

// Handle the remaining positions.
for (int i = (positionCount & ~0b111) - 8; i >= 0 && position >= 0; i -= 8) {
byte packed = valueIsNullPacked[i >>> 3];
if (packed == 0) { // Only values
arraycopy(values, position - 7, values, i, 8);
position -= 8;
}
else if (packed != -1) { // At least one non-null
for (int j = i + 7; j >= i && position >= 0; j--) {
values[j] = values[position];
if (!valueIsNull[j]) {
position--;
}
}
}
// Do nothing if there are only nulls
}
return new IntArrayBlock(0, positionCount, valueIsNull, values);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import static io.trino.spi.block.EncoderUtil.decodeNullBits;
import static io.trino.spi.block.EncoderUtil.encodeNullsAsBits;
import static io.trino.spi.block.EncoderUtil.retrieveNullBits;
import static java.lang.System.arraycopy;
import static java.util.Objects.checkFromIndexSize;

public class LongArrayBlockEncoding
Expand Down Expand Up @@ -55,20 +54,7 @@ public void writeBlock(BlockEncodingSerde blockEncodingSerde, SliceOutput sliceO

encodeNullsAsBits(sliceOutput, isNull, rawOffset, positionCount);

if (isNull == null) {
sliceOutput.writeLongs(rawValues, rawOffset, positionCount);
}
else {
long[] valuesWithoutNull = new long[positionCount];
int nonNullPositionCount = 0;
for (int i = 0; i < positionCount; i++) {
valuesWithoutNull[nonNullPositionCount] = rawValues[i + rawOffset];
nonNullPositionCount += isNull[i + rawOffset] ? 0 : 1;
}

sliceOutput.writeInt(nonNullPositionCount);
sliceOutput.writeLongs(valuesWithoutNull, 0, nonNullPositionCount);
}
sliceOutput.writeLongs(rawValues, rawOffset, positionCount);
}

@Override
Expand All @@ -85,35 +71,8 @@ public LongArrayBlock readBlock(BlockEncodingSerde blockEncodingSerde, SliceInpu
}
boolean[] valueIsNull = decodeNullBits(valueIsNullPacked, positionCount);

int nonNullPositionCount = sliceInput.readInt();
sliceInput.readLongs(values, 0, nonNullPositionCount);
int position = nonNullPositionCount - 1;
sliceInput.readLongs(values);

// Handle Last (positionCount % 8) values
for (int i = positionCount - 1; i >= (positionCount & ~0b111) && position >= 0; i--) {
values[i] = values[position];
if (!valueIsNull[i]) {
position--;
}
}

// Handle the remaining positions.
for (int i = (positionCount & ~0b111) - 8; i >= 0 && position >= 0; i -= 8) {
byte packed = valueIsNullPacked[i >>> 3];
if (packed == 0) { // Only values
arraycopy(values, position - 7, values, i, 8);
position -= 8;
}
else if (packed != -1) { // At least one non-null
for (int j = i + 7; j >= i && position >= 0; j--) {
values[j] = values[position];
if (!valueIsNull[j]) {
position--;
}
}
}
// Do nothing if there are only nulls
}
return new LongArrayBlock(0, positionCount, valueIsNull, values);
}
}
Loading
Loading