Search in sources :

Example 6 with TypeOperators

use of io.trino.spi.type.TypeOperators in project trino by trinodb.

the class TestDynamicFilterSourceOperator method setUp.

@BeforeMethod
public void setUp() {
    blockTypeOperators = new BlockTypeOperators(new TypeOperators());
    executor = newCachedThreadPool(daemonThreadsNamed(getClass().getSimpleName() + "-%s"));
    scheduledExecutor = newScheduledThreadPool(2, daemonThreadsNamed(getClass().getSimpleName() + "-scheduledExecutor-%s"));
    pipelineContext = createTaskContext(executor, scheduledExecutor, TEST_SESSION).addPipelineContext(0, true, true, false);
    partitions = ImmutableList.builder();
}
Also used : BlockTypeOperators(io.trino.type.BlockTypeOperators) TypeOperators(io.trino.spi.type.TypeOperators) BlockTypeOperators(io.trino.type.BlockTypeOperators) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 7 with TypeOperators

use of io.trino.spi.type.TypeOperators in project trino by trinodb.

the class TestSetDigest method testHashCounts.

@Test
public void testHashCounts() {
    SetDigest digest1 = new SetDigest();
    digest1.add(0);
    digest1.add(0);
    digest1.add(1);
    SetDigest digest2 = new SetDigest();
    digest2.add(0);
    digest2.add(0);
    digest2.add(2);
    digest2.add(2);
    MapType mapType = new MapType(BIGINT, SMALLINT, new TypeOperators());
    Block block = hashCounts(mapType, digest1.serialize());
    assertTrue(block instanceof SingleMapBlock);
    Set<Short> blockValues = new HashSet<>();
    for (int i = 1; i < block.getPositionCount(); i += 2) {
        blockValues.add(block.getShort(i, 0));
    }
    Set<Short> expected = ImmutableSet.of((short) 1, (short) 2);
    assertEquals(blockValues, expected);
    digest1.mergeWith(digest2);
    block = hashCounts(mapType, digest1.serialize());
    assertTrue(block instanceof SingleMapBlock);
    expected = ImmutableSet.of((short) 1, (short) 2, (short) 4);
    blockValues = new HashSet<>();
    for (int i = 1; i < block.getPositionCount(); i += 2) {
        blockValues.add(block.getShort(i, 0));
    }
    assertEquals(blockValues, expected);
}
Also used : SingleMapBlock(io.trino.spi.block.SingleMapBlock) Block(io.trino.spi.block.Block) SingleMapBlock(io.trino.spi.block.SingleMapBlock) MapType(io.trino.spi.type.MapType) TypeOperators(io.trino.spi.type.TypeOperators) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Example 8 with TypeOperators

use of io.trino.spi.type.TypeOperators in project trino by trinodb.

the class TestDeltaLakeSchemaSupport method testSerializeSchemaAsJson.

@Test
public void testSerializeSchemaAsJson() throws Exception {
    DeltaLakeColumnHandle arrayColumn = new DeltaLakeColumnHandle("arr", new ArrayType(new ArrayType(INTEGER)), REGULAR);
    DeltaLakeColumnHandle structColumn = new DeltaLakeColumnHandle("str", RowType.from(ImmutableList.of(new RowType.Field(Optional.of("s1"), VarcharType.createUnboundedVarcharType()), new RowType.Field(Optional.of("s2"), RowType.from(ImmutableList.of(new RowType.Field(Optional.of("i1"), INTEGER), new RowType.Field(Optional.of("d2"), DecimalType.createDecimalType(38, 0))))))), REGULAR);
    TypeOperators typeOperators = new TypeOperators();
    DeltaLakeColumnHandle mapColumn = new DeltaLakeColumnHandle("m", new MapType(INTEGER, new MapType(INTEGER, INTEGER, typeOperators), typeOperators), REGULAR);
    URL expected = getResource("io/trino/plugin/deltalake/transactionlog/schema/nested_schema.json");
    ObjectMapper objectMapper = new ObjectMapper();
    String jsonEncoding = serializeSchemaAsJson(ImmutableList.of(arrayColumn, structColumn, mapColumn));
    assertEquals(objectMapper.readTree(jsonEncoding), objectMapper.readTree(expected));
}
Also used : ArrayType(io.trino.spi.type.ArrayType) RowType(io.trino.spi.type.RowType) DeltaLakeColumnHandle(io.trino.plugin.deltalake.DeltaLakeColumnHandle) MapType(io.trino.spi.type.MapType) URL(java.net.URL) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) TypeOperators(io.trino.spi.type.TypeOperators) Test(org.testng.annotations.Test)

Example 9 with TypeOperators

use of io.trino.spi.type.TypeOperators 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");
}
Also used : BlockTypeOperators(io.trino.type.BlockTypeOperators) FeaturesConfig(io.trino.FeaturesConfig) TypeOperators(io.trino.spi.type.TypeOperators) BlockTypeOperators(io.trino.type.BlockTypeOperators) Test(org.testng.annotations.Test)

Example 10 with TypeOperators

use of io.trino.spi.type.TypeOperators 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));
    }
}
Also used : IntStream(java.util.stream.IntStream) BlockTypeOperators(io.trino.type.BlockTypeOperators) IntUnaryOperator(java.util.function.IntUnaryOperator) MapType(io.trino.spi.type.MapType) Assert.assertEquals(org.testng.Assert.assertEquals) SingleTypedHistogram(io.trino.operator.aggregation.histogram.SingleTypedHistogram) Test(org.testng.annotations.Test) TypeOperators(io.trino.spi.type.TypeOperators) StructuralTestUtil.mapType(io.trino.util.StructuralTestUtil.mapType) BIGINT(io.trino.spi.type.BigintType.BIGINT) Block(io.trino.spi.block.Block) TypedHistogram(io.trino.operator.aggregation.histogram.TypedHistogram) BlockBuilder(io.trino.spi.block.BlockBuilder) BlockTypeOperators(io.trino.type.BlockTypeOperators) SingleTypedHistogram(io.trino.operator.aggregation.histogram.SingleTypedHistogram) TypedHistogram(io.trino.operator.aggregation.histogram.TypedHistogram) SingleTypedHistogram(io.trino.operator.aggregation.histogram.SingleTypedHistogram) Block(io.trino.spi.block.Block) MapType(io.trino.spi.type.MapType) BlockBuilder(io.trino.spi.block.BlockBuilder) BlockTypeOperators(io.trino.type.BlockTypeOperators) TypeOperators(io.trino.spi.type.TypeOperators) Test(org.testng.annotations.Test)

Aggregations

TypeOperators (io.trino.spi.type.TypeOperators)37 BlockTypeOperators (io.trino.type.BlockTypeOperators)23 Test (org.testng.annotations.Test)18 MapType (io.trino.spi.type.MapType)10 Type (io.trino.spi.type.Type)9 BeforeMethod (org.testng.annotations.BeforeMethod)9 Page (io.trino.spi.Page)8 JoinCompiler (io.trino.sql.gen.JoinCompiler)6 PlanNodeId (io.trino.sql.planner.plan.PlanNodeId)6 ImmutableList (com.google.common.collect.ImmutableList)4 FeaturesConfig (io.trino.FeaturesConfig)4 Driver (io.trino.operator.Driver)3 DriverFactory (io.trino.operator.DriverFactory)3 GroupByHashPageIndexerFactory (io.trino.operator.GroupByHashPageIndexerFactory)3 OperatorFactory (io.trino.operator.OperatorFactory)3 PagesIndex (io.trino.operator.PagesIndex)3 HashBuilderOperatorFactory (io.trino.operator.join.HashBuilderOperator.HashBuilderOperatorFactory)3 PartitionedLookupSourceFactory (io.trino.operator.join.PartitionedLookupSourceFactory)3 Block (io.trino.spi.block.Block)3 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)2