Search in sources :

Example 11 with TrinoThriftBlock

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());
}
Also used : TrinoThriftBlock(io.trino.plugin.thrift.api.TrinoThriftBlock) Block(io.trino.spi.block.Block) TrinoThriftBigint.fromBlock(io.trino.plugin.thrift.api.datatypes.TrinoThriftBigint.fromBlock) TrinoThriftBlock(io.trino.plugin.thrift.api.TrinoThriftBlock) Test(org.testng.annotations.Test)

Example 12 with TrinoThriftBlock

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));
}
Also used : TrinoThriftBlock(io.trino.plugin.thrift.api.TrinoThriftBlock) Block(io.trino.spi.block.Block) TrinoThriftBigint.fromBlock(io.trino.plugin.thrift.api.datatypes.TrinoThriftBigint.fromBlock) TrinoThriftBlock(io.trino.plugin.thrift.api.TrinoThriftBlock) Test(org.testng.annotations.Test)

Example 13 with TrinoThriftBlock

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));
}
Also used : TrinoThriftBlock(io.trino.plugin.thrift.api.TrinoThriftBlock) Block(io.trino.spi.block.Block) TrinoThriftBigint.fromBlock(io.trino.plugin.thrift.api.datatypes.TrinoThriftBigint.fromBlock) TrinoThriftBlock(io.trino.plugin.thrift.api.TrinoThriftBlock) Test(org.testng.annotations.Test)

Example 14 with TrinoThriftBlock

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:.*");
}
Also used : TrinoThriftBlock(io.trino.plugin.thrift.api.TrinoThriftBlock) Test(org.testng.annotations.Test)

Example 15 with TrinoThriftBlock

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));
}
Also used : TrinoThriftBlock(io.trino.plugin.thrift.api.TrinoThriftBlock) Arrays(java.util.Arrays) ThriftField(io.airlift.drift.annotations.ThriftField) TrinoThriftTypeUtils.sameSizeIfPresent(io.trino.plugin.thrift.api.datatypes.TrinoThriftTypeUtils.sameSizeIfPresent) Type(io.trino.spi.type.Type) TrinoThriftBlock.bigintArrayData(io.trino.plugin.thrift.api.TrinoThriftBlock.bigintArrayData) OPTIONAL(io.airlift.drift.annotations.ThriftField.Requiredness.OPTIONAL) Preconditions.checkState(com.google.common.base.Preconditions.checkState) Objects(java.util.Objects) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) TrinoThriftTypeUtils.calculateOffsets(io.trino.plugin.thrift.api.datatypes.TrinoThriftTypeUtils.calculateOffsets) BIGINT(io.trino.spi.type.BigintType.BIGINT) Block(io.trino.spi.block.Block) TrinoThriftTypeUtils.totalSize(io.trino.plugin.thrift.api.datatypes.TrinoThriftTypeUtils.totalSize) ThriftConstructor(io.airlift.drift.annotations.ThriftConstructor) Optional(java.util.Optional) ThriftStruct(io.airlift.drift.annotations.ThriftStruct) LongArrayBlock(io.trino.spi.block.LongArrayBlock) AbstractArrayBlock(io.trino.spi.block.AbstractArrayBlock) ArrayBlock(io.trino.spi.block.ArrayBlock) Nullable(javax.annotation.Nullable) MoreObjects.toStringHelper(com.google.common.base.MoreObjects.toStringHelper) AbstractArrayBlock(io.trino.spi.block.AbstractArrayBlock)

Aggregations

TrinoThriftBlock (io.trino.plugin.thrift.api.TrinoThriftBlock)15 Test (org.testng.annotations.Test)12 Block (io.trino.spi.block.Block)9 TrinoThriftBigint.fromBlock (io.trino.plugin.thrift.api.datatypes.TrinoThriftBigint.fromBlock)8 Type (io.trino.spi.type.Type)2 ArrayList (java.util.ArrayList)2 MoreObjects.toStringHelper (com.google.common.base.MoreObjects.toStringHelper)1 Preconditions.checkArgument (com.google.common.base.Preconditions.checkArgument)1 Preconditions.checkState (com.google.common.base.Preconditions.checkState)1 ImmutableList (com.google.common.collect.ImmutableList)1 ThriftConstructor (io.airlift.drift.annotations.ThriftConstructor)1 ThriftField (io.airlift.drift.annotations.ThriftField)1 OPTIONAL (io.airlift.drift.annotations.ThriftField.Requiredness.OPTIONAL)1 ThriftStruct (io.airlift.drift.annotations.ThriftStruct)1 TrinoThriftBlock.bigintArrayData (io.trino.plugin.thrift.api.TrinoThriftBlock.bigintArrayData)1 TrinoThriftTypeUtils.calculateOffsets (io.trino.plugin.thrift.api.datatypes.TrinoThriftTypeUtils.calculateOffsets)1 TrinoThriftTypeUtils.sameSizeIfPresent (io.trino.plugin.thrift.api.datatypes.TrinoThriftTypeUtils.sameSizeIfPresent)1 TrinoThriftTypeUtils.totalSize (io.trino.plugin.thrift.api.datatypes.TrinoThriftTypeUtils.totalSize)1 AbstractArrayBlock (io.trino.spi.block.AbstractArrayBlock)1 ArrayBlock (io.trino.spi.block.ArrayBlock)1