Search in sources :

Example 6 with IntArrayBlock

use of io.trino.spi.block.IntArrayBlock in project trino by trinodb.

the class TestSimplePagesHashStrategy method testCompareSortChannelPositionsWithIntegerType.

@Test
public void testCompareSortChannelPositionsWithIntegerType() {
    Block block = new IntArrayBlock(3, Optional.empty(), new int[] { 1234, 5678, 1234 });
    SimplePagesHashStrategy strategy = createSimplePagesHashStrategy(INTEGER, ImmutableList.of(block));
    // This works because IntegerType is orderable.
    assertEquals(strategy.compareSortChannelPositions(0, 0, 0, 1), -1);
    assertEquals(strategy.compareSortChannelPositions(0, 1, 0, 0), 1);
    assertEquals(strategy.compareSortChannelPositions(0, 0, 0, 2), 0);
}
Also used : IntArrayBlock(io.trino.spi.block.IntArrayBlock) IntArrayBlock(io.trino.spi.block.IntArrayBlock) Block(io.trino.spi.block.Block) Test(org.testng.annotations.Test)

Example 7 with IntArrayBlock

use of io.trino.spi.block.IntArrayBlock in project trino by trinodb.

the class TestSimplePagesHashStrategy method testHashRowWithIntegerType.

@Test
public void testHashRowWithIntegerType() {
    Block block = new IntArrayBlock(1, Optional.empty(), new int[] { 1234 });
    SimplePagesHashStrategy strategy = createSimplePagesHashStrategy(INTEGER, ImmutableList.of(block));
    Page page = new Page(block);
    // This works because IntegerType is comparable.
    assertEquals(strategy.hashRow(0, page), -4467490526933615037L);
}
Also used : IntArrayBlock(io.trino.spi.block.IntArrayBlock) IntArrayBlock(io.trino.spi.block.IntArrayBlock) Block(io.trino.spi.block.Block) Page(io.trino.spi.Page) Test(org.testng.annotations.Test)

Example 8 with IntArrayBlock

use of io.trino.spi.block.IntArrayBlock in project trino by trinodb.

the class TestExpressionOptimizer method testCastWithJsonParseOptimization.

@Test
public void testCastWithJsonParseOptimization() {
    ResolvedFunction jsonParseFunction = functionResolution.resolveFunction(QualifiedName.of("json_parse"), fromTypes(VARCHAR));
    // constant
    ResolvedFunction jsonCastFunction = functionResolution.getCoercion(JSON, new ArrayType(INTEGER));
    RowExpression jsonCastExpression = new CallExpression(jsonCastFunction, ImmutableList.of(call(jsonParseFunction, constant(utf8Slice("[1, 2]"), VARCHAR))));
    RowExpression resultExpression = optimizer.optimize(jsonCastExpression);
    assertInstanceOf(resultExpression, ConstantExpression.class);
    Object resultValue = ((ConstantExpression) resultExpression).getValue();
    assertInstanceOf(resultValue, IntArrayBlock.class);
    assertEquals(toValues(INTEGER, (IntArrayBlock) resultValue), ImmutableList.of(1, 2));
    // varchar to array
    testCastWithJsonParseOptimization(jsonParseFunction, new ArrayType(VARCHAR), JSON_STRING_TO_ARRAY_NAME);
    // varchar to map
    testCastWithJsonParseOptimization(jsonParseFunction, mapType(INTEGER, VARCHAR), JSON_STRING_TO_MAP_NAME);
    // varchar to row
    testCastWithJsonParseOptimization(jsonParseFunction, RowType.anonymous(ImmutableList.of(VARCHAR, BIGINT)), JSON_STRING_TO_ROW_NAME);
}
Also used : ArrayType(io.trino.spi.type.ArrayType) IntArrayBlock(io.trino.spi.block.IntArrayBlock) ResolvedFunction(io.trino.metadata.ResolvedFunction) ConstantExpression(io.trino.sql.relational.ConstantExpression) RowExpression(io.trino.sql.relational.RowExpression) CallExpression(io.trino.sql.relational.CallExpression) Test(org.testng.annotations.Test)

Example 9 with IntArrayBlock

use of io.trino.spi.block.IntArrayBlock in project trino by trinodb.

the class TestIntArrayBlock method testCompactBlock.

@Test
public void testCompactBlock() {
    int[] intArray = { 0, 0, 1, 2, 3, 4 };
    boolean[] valueIsNull = { false, true, false, false, false, false };
    testCompactBlock(new IntArrayBlock(0, Optional.empty(), new int[0]));
    testCompactBlock(new IntArrayBlock(intArray.length, Optional.of(valueIsNull), intArray));
    testIncompactBlock(new IntArrayBlock(intArray.length - 1, Optional.of(valueIsNull), intArray));
}
Also used : IntArrayBlock(io.trino.spi.block.IntArrayBlock) Test(org.testng.annotations.Test)

Aggregations

IntArrayBlock (io.trino.spi.block.IntArrayBlock)9 Test (org.testng.annotations.Test)9 Block (io.trino.spi.block.Block)5 Page (io.trino.spi.Page)4 MapType (io.trino.spi.type.MapType)3 TypeOperators (io.trino.spi.type.TypeOperators)3 BlockTypeOperators (io.trino.type.BlockTypeOperators)3 BlockAssertions.createSlicesBlock (io.trino.block.BlockAssertions.createSlicesBlock)1 ResolvedFunction (io.trino.metadata.ResolvedFunction)1 DictionaryBlock (io.trino.spi.block.DictionaryBlock)1 VariableWidthBlock (io.trino.spi.block.VariableWidthBlock)1 ArrayType (io.trino.spi.type.ArrayType)1 CallExpression (io.trino.sql.relational.CallExpression)1 ConstantExpression (io.trino.sql.relational.ConstantExpression)1 RowExpression (io.trino.sql.relational.RowExpression)1