use of io.trino.plugin.thrift.api.TrinoThriftBlock in project trino by trinodb.
the class TestTrinoThriftBigint method testWriteBlockAllNulls.
@Test
public void testWriteBlockAllNulls() {
Block source = longBlock(null, null, null, null, null);
TrinoThriftBlock column = fromBlock(source);
assertNotNull(column.getBigintData());
assertEquals(column.getBigintData().getNulls(), new boolean[] { true, true, true, true, true });
assertNull(column.getBigintData().getLongs());
}
use of io.trino.plugin.thrift.api.TrinoThriftBlock in project trino by trinodb.
the class TestTrinoThriftBigint method testReadBlock.
@Test
public void testReadBlock() {
TrinoThriftBlock columnsData = longColumn(new boolean[] { false, true, false, false, false, false, true }, new long[] { 2, 0, 1, 3, 8, 4, 0 });
Block actual = columnsData.toBlock(BIGINT);
assertBlockEquals(actual, list(2L, null, 1L, 3L, 8L, 4L, null));
}
use of io.trino.plugin.thrift.api.TrinoThriftBlock in project trino by trinodb.
the class TestTrinoThriftBigint method testReadBlockAllNullsOption1.
@Test
public void testReadBlockAllNullsOption1() {
TrinoThriftBlock columnsData = longColumn(new boolean[] { true, true, true, true, true, true, true }, null);
Block actual = columnsData.toBlock(BIGINT);
assertBlockEquals(actual, list(null, null, null, null, null, null, null));
}
use of io.trino.plugin.thrift.api.TrinoThriftBlock in project trino by trinodb.
the class TestTrinoThriftBigint method testReadBlockWrongDesiredType.
@Test
public void testReadBlockWrongDesiredType() {
TrinoThriftBlock columnsData = longColumn(null, null);
assertThatThrownBy(() -> columnsData.toBlock(INTEGER)).isInstanceOf(IllegalArgumentException.class).hasMessageMatching("type doesn't match:.*");
}
use of io.trino.plugin.thrift.api.TrinoThriftBlock in project trino by trinodb.
the class TrinoThriftBigintArray method fromBlock.
public static TrinoThriftBlock fromBlock(Block block) {
checkArgument(block instanceof AbstractArrayBlock, "block is not of an array type");
AbstractArrayBlock arrayBlock = (AbstractArrayBlock) block;
int positions = arrayBlock.getPositionCount();
if (positions == 0) {
return bigintArrayData(new TrinoThriftBigintArray(null, null, null));
}
boolean[] nulls = null;
int[] sizes = null;
for (int position = 0; position < positions; position++) {
if (arrayBlock.isNull(position)) {
if (nulls == null) {
nulls = new boolean[positions];
}
nulls[position] = true;
} else {
if (sizes == null) {
sizes = new int[positions];
}
sizes[position] = arrayBlock.apply((valuesBlock, startPosition, length) -> length, position);
}
}
TrinoThriftBigint values = arrayBlock.apply((valuesBlock, startPosition, length) -> TrinoThriftBigint.fromBlock(valuesBlock), 0).getBigintData();
checkState(values != null, "values must be present");
checkState(totalSize(nulls, sizes) == values.numberOfRecords(), "unexpected number of values");
return bigintArrayData(new TrinoThriftBigintArray(nulls, sizes, values));
}
Aggregations