use of io.trino.type.BlockTypeOperators in project trino by trinodb.
the class TestGlobalFunctionCatalog method testDuplicateFunctions.
@Test
public void testDuplicateFunctions() {
FunctionBundle functionBundle = extractFunctions(CustomAdd.class);
TypeOperators typeOperators = new TypeOperators();
GlobalFunctionCatalog globalFunctionCatalog = new GlobalFunctionCatalog();
globalFunctionCatalog.addFunctions(SystemFunctionBundle.create(new FeaturesConfig(), typeOperators, new BlockTypeOperators(typeOperators), NodeVersion.UNKNOWN));
globalFunctionCatalog.addFunctions(functionBundle);
assertThatThrownBy(() -> globalFunctionCatalog.addFunctions(functionBundle)).isInstanceOf(IllegalArgumentException.class).hasMessageMatching("\\QFunction already registered: custom_add(bigint,bigint):bigint\\E");
}
use of io.trino.type.BlockTypeOperators in project trino by trinodb.
the class TestTypedHistogram method testMassive.
@Test
public void testMassive() {
BlockBuilder inputBlockBuilder = BIGINT.createBlockBuilder(null, 5000);
BlockTypeOperators blockTypeOperators = new BlockTypeOperators(new TypeOperators());
TypedHistogram typedHistogram = new SingleTypedHistogram(BIGINT, blockTypeOperators.getEqualOperator(BIGINT), blockTypeOperators.getHashCodeOperator(BIGINT), 1000);
IntStream.range(1, 2000).flatMap(i -> IntStream.iterate(i, IntUnaryOperator.identity()).limit(i)).forEach(j -> BIGINT.writeLong(inputBlockBuilder, j));
Block inputBlock = inputBlockBuilder.build();
for (int i = 0; i < inputBlock.getPositionCount(); i++) {
typedHistogram.add(i, inputBlock, 1);
}
MapType mapType = mapType(BIGINT, BIGINT);
BlockBuilder out = mapType.createBlockBuilder(null, 1);
typedHistogram.serialize(out);
Block outputBlock = mapType.getObject(out, 0);
for (int i = 0; i < outputBlock.getPositionCount(); i += 2) {
assertEquals(BIGINT.getLong(outputBlock, i + 1), BIGINT.getLong(outputBlock, i));
}
}
use of io.trino.type.BlockTypeOperators in project trino by trinodb.
the class TestTupleFilterProcessor method testFilter.
@Test
public void testFilter() {
Page tuplePage = Iterables.getOnlyElement(rowPagesBuilder(BIGINT, VARCHAR, DOUBLE).row(1L, "a", 0.1).build());
List<Type> outputTypes = ImmutableList.of(VARCHAR, BIGINT, BOOLEAN, DOUBLE, DOUBLE);
Page inputPage = Iterables.getOnlyElement(rowPagesBuilder(outputTypes).row("a", 1L, true, 0.1, 0.0).row("b", 1L, true, 0.1, 2.0).row("a", 1L, false, 0.1, 2.0).row("a", 0L, false, 0.2, 0.2).build());
FunctionManager functionManager = createTestingFunctionManager();
DynamicTupleFilterFactory filterFactory = new DynamicTupleFilterFactory(42, new PlanNodeId("42"), new int[] { 0, 1, 2 }, new int[] { 1, 0, 3 }, outputTypes, new PageFunctionCompiler(functionManager, 0), new BlockTypeOperators(new TypeOperators()));
PageProcessor tupleFilterProcessor = filterFactory.createPageProcessor(tuplePage, OptionalInt.of(MAX_BATCH_SIZE)).get();
Page actualPage = getOnlyElement(tupleFilterProcessor.process(SESSION, new DriverYieldSignal(), newSimpleAggregatedMemoryContext().newLocalMemoryContext(PageProcessor.class.getSimpleName()), inputPage)).orElseThrow(() -> new AssertionError("page is not present"));
Page expectedPage = Iterables.getOnlyElement(rowPagesBuilder(outputTypes).row("a", 1L, true, 0.1, 0.0).row("a", 1L, false, 0.1, 2.0).build());
assertPageEquals(outputTypes, actualPage, expectedPage);
}
use of io.trino.type.BlockTypeOperators in project trino by trinodb.
the class TestLocalExchange method setUp.
@BeforeMethod
public void setUp() {
NodeScheduler nodeScheduler = new NodeScheduler(new UniformNodeSelectorFactory(new InMemoryNodeManager(), new NodeSchedulerConfig().setIncludeCoordinator(true), new NodeTaskMap(new FinalizerService())));
nodePartitioningManager = new NodePartitioningManager(nodeScheduler, new BlockTypeOperators(new TypeOperators()));
}
use of io.trino.type.BlockTypeOperators in project trino by trinodb.
the class TestJoinCompiler method testDistinctFrom.
@Test
public void testDistinctFrom() {
List<Type> joinTypes = ImmutableList.of(DOUBLE);
List<Integer> joinChannels = Ints.asList(0);
// compile a single channel hash strategy
PagesHashStrategyFactory pagesHashStrategyFactory = joinCompiler.compilePagesHashStrategyFactory(joinTypes, joinChannels);
// create hash strategy with a single channel blocks -- make sure there is some overlap in values
List<Block> channel = ImmutableList.of(BlockAssertions.createDoubleSequenceBlock(10, 20), BlockAssertions.createDoublesBlock(Double.NaN, null, Double.NaN, 1.0, null), BlockAssertions.createDoubleSequenceBlock(20, 30), BlockAssertions.createDoubleSequenceBlock(15, 25));
List<List<Block>> channels = ImmutableList.of(channel);
PagesHashStrategy hashStrategy = pagesHashStrategyFactory.createPagesHashStrategy(channels, OptionalInt.empty());
// verify channel count
assertEquals(hashStrategy.getChannelCount(), 1);
BlockTypeOperators blockTypeOperators = new BlockTypeOperators();
BlockPositionIsDistinctFrom distinctFromOperator = blockTypeOperators.getDistinctFromOperator(DOUBLE);
// verify hashStrategy is consistent with DISTINCT from block
for (int leftBlockIndex = 0; leftBlockIndex < channel.size(); leftBlockIndex++) {
Block leftBlock = channel.get(leftBlockIndex);
for (int leftBlockPosition = 0; leftBlockPosition < leftBlock.getPositionCount(); leftBlockPosition++) {
// position must not be distinct from itself
assertTrue(hashStrategy.positionNotDistinctFromPosition(leftBlockIndex, leftBlockPosition, leftBlockIndex, leftBlockPosition));
// check distinctiveness of every position against every other position in the block
for (int rightBlockIndex = 0; rightBlockIndex < channel.size(); rightBlockIndex++) {
Block rightBlock = channel.get(rightBlockIndex);
for (int rightBlockPosition = 0; rightBlockPosition < rightBlock.getPositionCount(); rightBlockPosition++) {
boolean expectedNotDistinct = !distinctFromOperator.isDistinctFrom(leftBlock, leftBlockPosition, rightBlock, rightBlockPosition);
assertEquals(hashStrategy.positionNotDistinctFromRow(leftBlockIndex, leftBlockPosition, rightBlockPosition, new Page(rightBlock)), expectedNotDistinct);
assertEquals(hashStrategy.rowNotDistinctFromRow(leftBlockPosition, new Page(leftBlock), rightBlockPosition, new Page(rightBlock)), expectedNotDistinct);
assertEquals(hashStrategy.positionNotDistinctFromPosition(leftBlockIndex, leftBlockPosition, rightBlockIndex, rightBlockPosition), expectedNotDistinct);
}
}
// check equality of every position against every other position in the block cursor
for (int rightBlockIndex = 0; rightBlockIndex < channel.size(); rightBlockIndex++) {
Block rightBlock = channel.get(rightBlockIndex);
for (int rightBlockPosition = 0; rightBlockPosition < rightBlock.getPositionCount(); rightBlockPosition++) {
boolean expectedNotDistinct = !distinctFromOperator.isDistinctFrom(leftBlock, leftBlockPosition, rightBlock, rightBlockPosition);
assertEquals(hashStrategy.positionNotDistinctFromRow(leftBlockIndex, leftBlockPosition, rightBlockPosition, new Page(rightBlock)), expectedNotDistinct);
assertEquals(hashStrategy.rowNotDistinctFromRow(leftBlockPosition, new Page(leftBlock), rightBlockPosition, new Page(rightBlock)), expectedNotDistinct);
assertEquals(hashStrategy.positionNotDistinctFromPosition(leftBlockIndex, leftBlockPosition, rightBlockIndex, rightBlockPosition), expectedNotDistinct);
}
}
}
}
}
Aggregations