use of io.trino.spi.block.LongArrayBlock in project trino by trinodb.
the class TestPolymorphicScalarFunction method testSelectsMultipleChoiceWithBlockPosition.
@Test
public void testSelectsMultipleChoiceWithBlockPosition() throws Throwable {
Signature signature = Signature.builder().operatorType(IS_DISTINCT_FROM).argumentTypes(DECIMAL_SIGNATURE, DECIMAL_SIGNATURE).returnType(BOOLEAN.getTypeSignature()).build();
SqlScalarFunction function = new PolymorphicScalarFunctionBuilder(TestMethods.class).signature(signature).argumentNullability(true, true).deterministic(true).choice(choice -> choice.argumentProperties(NULL_FLAG, NULL_FLAG).implementation(methodsGroup -> methodsGroup.methods("shortShort", "longLong"))).choice(choice -> choice.argumentProperties(BLOCK_POSITION, BLOCK_POSITION).implementation(methodsGroup -> methodsGroup.methodWithExplicitJavaTypes("blockPositionLongLong", asList(Optional.of(Int128.class), Optional.of(Int128.class))).methodWithExplicitJavaTypes("blockPositionShortShort", asList(Optional.of(long.class), Optional.of(long.class))))).build();
BoundSignature shortDecimalBoundSignature = new BoundSignature(signature.getName(), BOOLEAN, ImmutableList.of(SHORT_DECIMAL_BOUND_TYPE, SHORT_DECIMAL_BOUND_TYPE));
ChoicesScalarFunctionImplementation functionImplementation = (ChoicesScalarFunctionImplementation) function.specialize(shortDecimalBoundSignature, new FunctionDependencies(FUNCTION_MANAGER::getScalarFunctionInvoker, ImmutableMap.of(), ImmutableSet.of()));
assertEquals(functionImplementation.getChoices().size(), 2);
assertEquals(functionImplementation.getChoices().get(0).getInvocationConvention(), new InvocationConvention(ImmutableList.of(NULL_FLAG, NULL_FLAG), FAIL_ON_NULL, false, false));
assertEquals(functionImplementation.getChoices().get(1).getInvocationConvention(), new InvocationConvention(ImmutableList.of(BLOCK_POSITION, BLOCK_POSITION), FAIL_ON_NULL, false, false));
Block block1 = new LongArrayBlock(0, Optional.empty(), new long[0]);
Block block2 = new LongArrayBlock(0, Optional.empty(), new long[0]);
assertFalse((boolean) functionImplementation.getChoices().get(1).getMethodHandle().invoke(block1, 0, block2, 0));
BoundSignature longDecimalBoundSignature = new BoundSignature(signature.getName(), BOOLEAN, ImmutableList.of(LONG_DECIMAL_BOUND_TYPE, LONG_DECIMAL_BOUND_TYPE));
functionImplementation = (ChoicesScalarFunctionImplementation) function.specialize(longDecimalBoundSignature, new FunctionDependencies(FUNCTION_MANAGER::getScalarFunctionInvoker, ImmutableMap.of(), ImmutableSet.of()));
assertTrue((boolean) functionImplementation.getChoices().get(1).getMethodHandle().invoke(block1, 0, block2, 0));
}
use of io.trino.spi.block.LongArrayBlock in project trino by trinodb.
the class BenchmarkGroupByHash method benchmarkHashPosition.
@Benchmark
@OperationsPerInvocation(POSITIONS)
public List<Page> benchmarkHashPosition(BenchmarkData data) {
InterpretedHashGenerator hashGenerator = new InterpretedHashGenerator(data.getTypes(), data.getChannels(), TYPE_OPERATOR_FACTORY);
ImmutableList.Builder<Page> results = ImmutableList.builderWithExpectedSize(data.getPages().size());
for (Page page : data.getPages()) {
long[] hashes = new long[page.getPositionCount()];
for (int position = 0; position < page.getPositionCount(); position++) {
hashes[position] = hashGenerator.hashPosition(position, page);
}
results.add(page.appendColumn(new LongArrayBlock(page.getPositionCount(), Optional.empty(), hashes)));
}
return results.build();
}
use of io.trino.spi.block.LongArrayBlock in project trino by trinodb.
the class TestLongArrayBlock method testCompactBlock.
@Test
public void testCompactBlock() {
long[] longArray = { 0L, 0L, 1L, 2L, 3L, 4L };
boolean[] valueIsNull = { false, true, false, false, false, false };
testCompactBlock(new LongArrayBlock(0, Optional.empty(), new long[0]));
testCompactBlock(new LongArrayBlock(longArray.length, Optional.of(valueIsNull), longArray));
testIncompactBlock(new LongArrayBlock(longArray.length - 1, Optional.of(valueIsNull), longArray));
}
Aggregations