Skip to content

Commit

Permalink
Remove getters for narrow integral types from LongArrayBlock
Browse files Browse the repository at this point in the history
Originally added as a temporary workaround, but unused now
  • Loading branch information
raunaqmorarka committed Oct 9, 2023
1 parent f79d509 commit 271b02c
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 60 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
import static io.trino.block.BlockAssertions.createDoubleRepeatBlock;
import static io.trino.block.BlockAssertions.createDoubleSequenceBlock;
import static io.trino.block.BlockAssertions.createDoublesBlock;
import static io.trino.block.BlockAssertions.createIntsBlock;
import static io.trino.block.BlockAssertions.createLongRepeatBlock;
import static io.trino.block.BlockAssertions.createLongSequenceBlock;
import static io.trino.block.BlockAssertions.createLongsBlock;
Expand Down Expand Up @@ -280,9 +281,9 @@ public void testCollectWithNulls()
OperatorFactory operatorFactory = createOperatorFactory(channel(0, INTEGER));
verifyPassthrough(createOperator(operatorFactory),
ImmutableList.of(INTEGER),
new Page(createLongsBlock(1, 2, 3)),
new Page(createIntsBlock(1, 2, 3)),
new Page(blockWithNulls),
new Page(createLongsBlock(4, 5)));
new Page(createIntsBlock(4, 5)));
operatorFactory.noMoreOperators();

assertEquals(partitions.build(), ImmutableList.of(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ public void testMemoryReservationYield()
for (Page page : result.getOutput()) {
assertEquals(page.getChannelCount(), 2);
for (int i = 0; i < page.getPositionCount(); i++) {
assertEquals(page.getBlock(1).getByte(i, 0), 1);
assertEquals(page.getBlock(1).getLong(i, 0), 1);
count++;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ public void testSimpleDeletedRowMerge()

// Show that the row to be deleted is rowId 0, e.g. ('Dave', 11, 'Devon')
Block rowIdRow = outputPage.getBlock(4).getObject(0, Block.class);
assertThat(INTEGER.getInt(rowIdRow, 1)).isEqualTo(0);
assertThat(BIGINT.getLong(rowIdRow, 1)).isEqualTo(0);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import static io.trino.spi.block.BlockUtil.compactArray;
import static io.trino.spi.block.BlockUtil.copyIsNullAndAppendNull;
import static io.trino.spi.block.BlockUtil.ensureCapacity;
import static java.lang.Math.toIntExact;

public class LongArrayBlock
implements Block
Expand Down Expand Up @@ -134,52 +133,6 @@ public long getLong(int position, int offset)
return values[position + arrayOffset];
}

@Override
@Deprecated
// TODO: Remove when we fix intermediate types on aggregations.
public int getInt(int position, int offset)
{
checkReadablePosition(this, position);
if (offset != 0) {
throw new IllegalArgumentException("offset must be zero");
}
return toIntExact(values[position + arrayOffset]);
}

@Override
@Deprecated
// TODO: Remove when we fix intermediate types on aggregations.
public short getShort(int position, int offset)
{
checkReadablePosition(this, position);
if (offset != 0) {
throw new IllegalArgumentException("offset must be zero");
}

short value = (short) (values[position + arrayOffset]);
if (value != values[position + arrayOffset]) {
throw new ArithmeticException("short overflow");
}
return value;
}

@Override
@Deprecated
// TODO: Remove when we fix intermediate types on aggregations.
public byte getByte(int position, int offset)
{
checkReadablePosition(this, position);
if (offset != 0) {
throw new IllegalArgumentException("offset must be zero");
}

byte value = (byte) (values[position + arrayOffset]);
if (value != values[position + arrayOffset]) {
throw new ArithmeticException("byte overflow");
}
return value;
}

@Override
public boolean mayHaveNull()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -634,9 +634,9 @@ private static ColumnReaderFormat<?>[] columnReaders()
// FLOAT parquet primitive type can be read as a DOUBLE or REAL type in Trino
new ColumnReaderFormat<>(FLOAT, DoubleType.DOUBLE, PLAIN_WRITER, DICTIONARY_FLOAT_WRITER, WRITE_FLOAT, ASSERT_DOUBLE_STORED_AS_FLOAT),
new ColumnReaderFormat<>(DOUBLE, DoubleType.DOUBLE, PLAIN_WRITER, DICTIONARY_DOUBLE_WRITER, WRITE_DOUBLE, ASSERT_DOUBLE),
new ColumnReaderFormat<>(INT32, decimalType(0, 8), createDecimalType(8), PLAIN_WRITER, DICTIONARY_INT_WRITER, WRITE_INT, ASSERT_INT),
new ColumnReaderFormat<>(INT32, decimalType(0, 8), createDecimalType(8), PLAIN_WRITER, DICTIONARY_INT_WRITER, WRITE_INT, ASSERT_LONG),
// INT32 can be read as a ShortDecimalType in Trino without decimal logical type annotation as well
new ColumnReaderFormat<>(INT32, createDecimalType(8, 0), PLAIN_WRITER, DICTIONARY_INT_WRITER, WRITE_INT, ASSERT_INT),
new ColumnReaderFormat<>(INT32, createDecimalType(8, 0), PLAIN_WRITER, DICTIONARY_INT_WRITER, WRITE_INT, ASSERT_LONG),
new ColumnReaderFormat<>(INT32, BIGINT, PLAIN_WRITER, DICTIONARY_INT_WRITER, WRITE_INT, ASSERT_LONG),
new ColumnReaderFormat<>(INT32, INTEGER, PLAIN_WRITER, DICTIONARY_INT_WRITER, WRITE_INT, ASSERT_INT),
new ColumnReaderFormat<>(INT32, SMALLINT, PLAIN_WRITER, DICTIONARY_INT_WRITER, WRITE_SHORT, ASSERT_SHORT),
Expand All @@ -658,9 +658,9 @@ private static ColumnReaderFormat<?>[] columnReaders()
// Reading a column TimeLogicalTypeAnnotation as a BIGINT
new ColumnReaderFormat<>(INT64, timeType(false, MICROS), BIGINT, PLAIN_WRITER, DICTIONARY_LONG_WRITER, WRITE_LONG, ASSERT_LONG),
// Short decimals
new ColumnReaderFormat<>(INT32, decimalType(0, 8), createDecimalType(8), PLAIN_WRITER, DICTIONARY_INT_WRITER, WRITE_INT, ASSERT_INT),
new ColumnReaderFormat<>(INT32, decimalType(0, 8), createDecimalType(8), PLAIN_WRITER, DICTIONARY_INT_WRITER, WRITE_INT, ASSERT_LONG),
// INT32 values can be read as zero scale decimals provided the precision is at least 10 to accommodate the largest possible integer
new ColumnReaderFormat<>(INT32, createDecimalType(10), PLAIN_WRITER, DICTIONARY_INT_WRITER, WRITE_INT, ASSERT_INT),
new ColumnReaderFormat<>(INT32, createDecimalType(10), PLAIN_WRITER, DICTIONARY_INT_WRITER, WRITE_INT, ASSERT_LONG),
new ColumnReaderFormat<>(INT32, decimalType(0, 8), BIGINT, PLAIN_WRITER, DICTIONARY_INT_WRITER, WRITE_INT, ASSERT_LONG),
new ColumnReaderFormat<>(INT32, decimalType(0, 8), INTEGER, PLAIN_WRITER, DICTIONARY_INT_WRITER, WRITE_INT, ASSERT_INT),
new ColumnReaderFormat<>(INT32, decimalType(0, 8), SMALLINT, PLAIN_WRITER, DICTIONARY_INT_WRITER, WRITE_SHORT, ASSERT_SHORT),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -318,20 +318,26 @@ public void testMergeHiveColumnStatisticsMap()
@Test
public void testFromComputedStatistics()
{
Function<Integer, Block> singleIntegerValueBlock = value ->
Function<Long, Block> singleLongValueBlock = value ->
{
BlockBuilder blockBuilder = BIGINT.createBlockBuilder(null, 1);
BIGINT.writeLong(blockBuilder, value);
return blockBuilder.build();
};
Function<Integer, Block> singleIntegerValueBlock = value ->
{
BlockBuilder blockBuilder = INTEGER.createBlockBuilder(null, 1);
INTEGER.writeLong(blockBuilder, value);
return blockBuilder.build();
};

ComputedStatistics statistics = ComputedStatistics.builder(ImmutableList.of(), ImmutableList.of())
.addTableStatistic(TableStatisticType.ROW_COUNT, singleIntegerValueBlock.apply(5))
.addTableStatistic(TableStatisticType.ROW_COUNT, singleLongValueBlock.apply(5L))
.addColumnStatistic(MIN_VALUE.createColumnStatisticMetadata("a_column"), singleIntegerValueBlock.apply(1))
.addColumnStatistic(MAX_VALUE.createColumnStatisticMetadata("a_column"), singleIntegerValueBlock.apply(5))
.addColumnStatistic(NUMBER_OF_DISTINCT_VALUES.createColumnStatisticMetadata("a_column"), singleIntegerValueBlock.apply(5))
.addColumnStatistic(NUMBER_OF_NON_NULL_VALUES.createColumnStatisticMetadata("a_column"), singleIntegerValueBlock.apply(5))
.addColumnStatistic(NUMBER_OF_NON_NULL_VALUES.createColumnStatisticMetadata("b_column"), singleIntegerValueBlock.apply(4))
.addColumnStatistic(NUMBER_OF_DISTINCT_VALUES.createColumnStatisticMetadata("a_column"), singleLongValueBlock.apply(5L))
.addColumnStatistic(NUMBER_OF_NON_NULL_VALUES.createColumnStatisticMetadata("a_column"), singleLongValueBlock.apply(5L))
.addColumnStatistic(NUMBER_OF_NON_NULL_VALUES.createColumnStatisticMetadata("b_column"), singleLongValueBlock.apply(4L))
.build();

Map<String, Type> columnTypes = ImmutableMap.of("a_column", INTEGER, "b_column", VARCHAR);
Expand Down

0 comments on commit 271b02c

Please sign in to comment.