Skip to content

Commit

Permalink
Remove instance checks in PositionAppenders
Browse files Browse the repository at this point in the history
Current Type contract does not enforce
particular block type for data.
Hence PositionAppenders should work with
generic Block type.
  • Loading branch information
sopel39 committed Jul 21, 2022
1 parent f28c507 commit 94a87da
Show file tree
Hide file tree
Showing 7 changed files with 7 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import java.util.Arrays;
import java.util.Optional;

import static com.google.common.base.Preconditions.checkArgument;
import static io.airlift.slice.SizeOf.sizeOf;
import static io.trino.operator.output.PositionsAppenderUtil.calculateBlockResetSize;
import static io.trino.operator.output.PositionsAppenderUtil.calculateNewArraySize;
Expand Down Expand Up @@ -56,13 +55,12 @@ public BytePositionsAppender(int expectedEntries)
}

@Override
// TODO: Make PositionsAppender work performant with different block types (https://github.com/trinodb/trino/issues/13267)
public void append(IntArrayList positions, Block block)
{
if (positions.isEmpty()) {
return;
}
// performance of this method depends on block being always the same, flat type
checkArgument(block instanceof ByteArrayBlock);
int[] positionArray = positions.elements();
int positionsSize = positions.size();
ensureCapacity(positionCount + positionsSize);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import java.util.Arrays;
import java.util.Optional;

import static com.google.common.base.Preconditions.checkArgument;
import static io.airlift.slice.SizeOf.SIZE_OF_LONG;
import static io.airlift.slice.SizeOf.sizeOf;
import static io.trino.operator.output.PositionsAppenderUtil.calculateBlockResetSize;
Expand Down Expand Up @@ -57,13 +56,12 @@ public Int128PositionsAppender(int expectedEntries)
}

@Override
// TODO: Make PositionsAppender work performant with different block types (https://github.com/trinodb/trino/issues/13267)
public void append(IntArrayList positions, Block block)
{
if (positions.isEmpty()) {
return;
}
// performance of this method depends on block being always the same, flat type
checkArgument(block instanceof Int128ArrayBlock);
int[] positionArray = positions.elements();
int positionsSize = positions.size();
ensureCapacity(positionCount + positionsSize);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import java.util.Arrays;
import java.util.Optional;

import static com.google.common.base.Preconditions.checkArgument;
import static io.airlift.slice.SizeOf.SIZE_OF_LONG;
import static io.airlift.slice.SizeOf.sizeOf;
import static io.trino.operator.output.PositionsAppenderUtil.calculateBlockResetSize;
Expand Down Expand Up @@ -58,13 +57,12 @@ public Int96PositionsAppender(int expectedEntries)
}

@Override
// TODO: Make PositionsAppender work performant with different block types (https://github.com/trinodb/trino/issues/13267)
public void append(IntArrayList positions, Block block)
{
if (positions.isEmpty()) {
return;
}
// performance of this method depends on block being always the same, flat type
checkArgument(block instanceof Int96ArrayBlock);
int[] positionArray = positions.elements();
int positionsSize = positions.size();
ensureCapacity(positionCount + positionsSize);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import java.util.Arrays;
import java.util.Optional;

import static com.google.common.base.Preconditions.checkArgument;
import static io.airlift.slice.SizeOf.sizeOf;
import static io.trino.operator.output.PositionsAppenderUtil.calculateBlockResetSize;
import static io.trino.operator.output.PositionsAppenderUtil.calculateNewArraySize;
Expand Down Expand Up @@ -56,13 +55,12 @@ public IntPositionsAppender(int expectedEntries)
}

@Override
// TODO: Make PositionsAppender work performant with different block types (https://github.com/trinodb/trino/issues/13267)
public void append(IntArrayList positions, Block block)
{
if (positions.isEmpty()) {
return;
}
// performance of this method depends on block being always the same, flat type
checkArgument(block instanceof IntArrayBlock);
int[] positionArray = positions.elements();
int positionsSize = positions.size();
ensureCapacity(positionCount + positionsSize);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import java.util.Arrays;
import java.util.Optional;

import static com.google.common.base.Preconditions.checkArgument;
import static io.airlift.slice.SizeOf.sizeOf;
import static io.trino.operator.output.PositionsAppenderUtil.calculateBlockResetSize;
import static io.trino.operator.output.PositionsAppenderUtil.calculateNewArraySize;
Expand Down Expand Up @@ -56,13 +55,12 @@ public LongPositionsAppender(int expectedEntries)
}

@Override
// TODO: Make PositionsAppender work performant with different block types (https://github.com/trinodb/trino/issues/13267)
public void append(IntArrayList positions, Block block)
{
if (positions.isEmpty()) {
return;
}
// performance of this method depends on block being always the same, flat type
checkArgument(block instanceof LongArrayBlock);
int[] positionArray = positions.elements();
int positionsSize = positions.size();
ensureCapacity(positionCount + positionsSize);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import java.util.Arrays;
import java.util.Optional;

import static com.google.common.base.Preconditions.checkArgument;
import static io.airlift.slice.SizeOf.sizeOf;
import static io.trino.operator.output.PositionsAppenderUtil.calculateBlockResetSize;
import static io.trino.operator.output.PositionsAppenderUtil.calculateNewArraySize;
Expand Down Expand Up @@ -56,13 +55,12 @@ public ShortPositionsAppender(int expectedEntries)
}

@Override
// TODO: Make PositionsAppender work performant with different block types (https://github.com/trinodb/trino/issues/13267)
public void append(IntArrayList positions, Block block)
{
if (positions.isEmpty()) {
return;
}
// performance of this method depends on block being always the same, flat type
checkArgument(block instanceof ShortArrayBlock);
int[] positionArray = positions.elements();
int positionsSize = positions.size();
ensureCapacity(positionCount + positionsSize);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import java.util.Arrays;
import java.util.Optional;

import static com.google.common.base.Preconditions.checkArgument;
import static io.airlift.slice.SizeOf.SIZE_OF_BYTE;
import static io.airlift.slice.SizeOf.SIZE_OF_INT;
import static io.airlift.slice.SizeOf.sizeOf;
Expand Down Expand Up @@ -74,13 +73,12 @@ public SlicePositionsAppender(int expectedEntries, int expectedBytes)
}

@Override
// TODO: Make PositionsAppender work performant with different block types (https://github.com/trinodb/trino/issues/13267)
public void append(IntArrayList positions, Block block)
{
if (positions.isEmpty()) {
return;
}
// performance of this method depends on block being always the same, flat type
checkArgument(block instanceof VariableWidthBlock);
ensurePositionCapacity(positionCount + positions.size());
int[] positionArray = positions.elements();
int newByteCount = 0;
Expand Down

0 comments on commit 94a87da

Please sign in to comment.