Skip to content
Merged
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 @@ -74,22 +74,32 @@ public void append(IntArrayList positions, Block block)
return;
}
ensureCapacity(positions.size());
AbstractRowBlock sourceRowBlock = (AbstractRowBlock) block;
IntArrayList nonNullPositions;
if (sourceRowBlock.mayHaveNull()) {
nonNullPositions = processNullablePositions(positions, sourceRowBlock);
hasNullRow |= nonNullPositions.size() < positions.size();
hasNonNullRow |= nonNullPositions.size() > 0;
if (block instanceof AbstractRowBlock sourceRowBlock) {
IntArrayList nonNullPositions;
if (sourceRowBlock.mayHaveNull()) {
nonNullPositions = processNullablePositions(positions, sourceRowBlock);
hasNullRow |= nonNullPositions.size() < positions.size();
hasNonNullRow |= nonNullPositions.size() > 0;
}
else {
// the source Block does not have nulls
nonNullPositions = processNonNullablePositions(positions, sourceRowBlock);
hasNonNullRow = true;
}

List<Block> fieldBlocks = sourceRowBlock.getChildren();
for (int i = 0; i < fieldAppenders.length; i++) {
fieldAppenders[i].append(nonNullPositions, fieldBlocks.get(i));
}
}
else {
// the source Block does not have nulls
nonNullPositions = processNonNullablePositions(positions, sourceRowBlock);
hasNonNullRow = true;
else if (allPositionsNull(positions, block)) {
// all input positions are null. We can handle that even if block type is not RowBLock.
// append positions.size() nulls
Arrays.fill(rowIsNull, positionCount, positionCount + positions.size(), true);
hasNullRow = true;
}

List<Block> fieldBlocks = sourceRowBlock.getChildren();
for (int i = 0; i < fieldAppenders.length; i++) {
fieldAppenders[i].append(nonNullPositions, fieldBlocks.get(i));
else {
throw new IllegalArgumentException("unsupported block type: " + block);
}

positionCount += positions.size();
Expand All @@ -100,20 +110,29 @@ public void append(IntArrayList positions, Block block)
public void appendRle(Block value, int rlePositionCount)
{
ensureCapacity(rlePositionCount);
AbstractRowBlock sourceRowBlock = (AbstractRowBlock) value;
if (sourceRowBlock.isNull(0)) {
if (value instanceof AbstractRowBlock sourceRowBlock) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: I think there might be other places where we assume AbstractRowBlock always

if (sourceRowBlock.isNull(0)) {
// append rlePositionCount nulls
Arrays.fill(rowIsNull, positionCount, positionCount + rlePositionCount, true);
hasNullRow = true;
}
else {
// append not null row value
List<Block> fieldBlocks = sourceRowBlock.getChildren();
int fieldPosition = sourceRowBlock.getFieldBlockOffset(0);
for (int i = 0; i < fieldAppenders.length; i++) {
fieldAppenders[i].appendRle(fieldBlocks.get(i).getSingleValueBlock(fieldPosition), rlePositionCount);
}
hasNonNullRow = true;
}
}
else if (value.isNull(0)) {
// append rlePositionCount nulls
Arrays.fill(rowIsNull, positionCount, positionCount + rlePositionCount, true);
hasNullRow = true;
}
else {
// append not null row value
List<Block> fieldBlocks = sourceRowBlock.getChildren();
int fieldPosition = sourceRowBlock.getFieldBlockOffset(0);
for (int i = 0; i < fieldAppenders.length; i++) {
fieldAppenders[i].appendRle(fieldBlocks.get(i).getSingleValueBlock(fieldPosition), rlePositionCount);
}
hasNonNullRow = true;
throw new IllegalArgumentException("unsupported block type: " + value);
}
positionCount += rlePositionCount;
updateSize();
Expand Down Expand Up @@ -167,6 +186,16 @@ private void reset()
updateRetainedSize();
}

private boolean allPositionsNull(IntArrayList positions, Block block)
{
for (int i = 0; i < positions.size(); i++) {
if (!block.isNull(positions.getInt(i))) {
return false;
}
}
return true;
}

private IntArrayList processNullablePositions(IntArrayList positions, AbstractRowBlock sourceRowBlock)
{
int[] nonNullPositions = new int[positions.size()];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import io.trino.spi.type.VarbinaryType;
import io.trino.spi.type.VarcharType;
import io.trino.type.BlockTypeOperators;
import io.trino.type.UnknownType;
import it.unimi.dsi.fastutil.ints.IntArrayList;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
Expand Down Expand Up @@ -93,6 +94,8 @@ public void testMixedBlockTypes(TestType type)
List<BlockView> input = ImmutableList.of(
input(emptyBlock(type)),
input(nullBlock(type, 3), 0, 2),
input(nullBlock(TestType.UNKNOWN, 3), 0, 2), // a := null projections are handled by UnknownType null block
input(nullBlock(TestType.UNKNOWN, 1), 0), // a := null projections are handled by UnknownType null block, 1 position uses non RLE block
input(notNullBlock(type, 3), 1, 2),
input(partiallyNullBlock(type, 4), 0, 1, 2, 3),
input(partiallyNullBlock(type, 4)), // empty position list
Expand Down Expand Up @@ -270,6 +273,7 @@ public void testRowWithNestedFields()
public static Object[][] types()
{
return Arrays.stream(TestType.values())
.filter(testType -> !testType.equals(TestType.UNKNOWN))
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: why to filter it

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

UnknownType does not support values other than null and tests are producing non null blocks based on the type provided

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would be good to add comment

.map(type -> new Object[] {type})
.toArray(Object[][]::new);
}
Expand Down Expand Up @@ -434,7 +438,8 @@ private enum TestType
LONG_TIMESTAMP(createTimestampType(9)),
ROW_BIGINT_VARCHAR(anonymousRow(BigintType.BIGINT, VarcharType.VARCHAR)),
ARRAY_BIGINT(new ArrayType(BigintType.BIGINT)),
VARCHAR_WITH_TEST_BLOCK(VarcharType.VARCHAR, TestVariableWidthBlock.adaptation());
VARCHAR_WITH_TEST_BLOCK(VarcharType.VARCHAR, TestVariableWidthBlock.adaptation()),
UNKNOWN(UnknownType.UNKNOWN);

private final Type type;
private final Function<Block, Block> blockAdaptation;
Expand Down