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);
}
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);
}
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);
}
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));
}
Aggregations