Search in sources :

Example 21 with TypeOperators

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

the class TestGlobalFunctionCatalog method testConflictingScalarAggregation.

@Test
public void testConflictingScalarAggregation() {
    FunctionBundle functions = extractFunctions(ScalarSum.class);
    TypeOperators typeOperators = new TypeOperators();
    GlobalFunctionCatalog globalFunctionCatalog = new GlobalFunctionCatalog();
    globalFunctionCatalog.addFunctions(SystemFunctionBundle.create(new FeaturesConfig(), typeOperators, new BlockTypeOperators(typeOperators), NodeVersion.UNKNOWN));
    assertThatThrownBy(() -> globalFunctionCatalog.addFunctions(functions)).isInstanceOf(IllegalStateException.class).hasMessage("'sum' is both an aggregation and a scalar function");
}
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 22 with TypeOperators

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

the class TestParquetPredicateUtils method testParquetTupleDomainMap.

@Test
public void testParquetTupleDomainMap() {
    MapType mapType = new MapType(INTEGER, INTEGER, new TypeOperators());
    HiveColumnHandle columnHandle = createBaseColumn("my_map", 0, HiveType.valueOf("map<int,int>"), mapType, REGULAR, Optional.empty());
    TupleDomain<HiveColumnHandle> domain = withColumnDomains(ImmutableMap.of(columnHandle, Domain.notNull(mapType)));
    MessageType fileSchema = new MessageType("hive_schema", new GroupType(OPTIONAL, "my_map", new GroupType(REPEATED, "map", new PrimitiveType(REQUIRED, INT32, "key"), new PrimitiveType(OPTIONAL, INT32, "value"))));
    Map<List<String>, RichColumnDescriptor> descriptorsByPath = getDescriptors(fileSchema, fileSchema);
    TupleDomain<ColumnDescriptor> tupleDomain = getParquetTupleDomain(descriptorsByPath, domain, fileSchema, true);
    assertTrue(tupleDomain.isAll());
}
Also used : GroupType(org.apache.parquet.schema.GroupType) RichColumnDescriptor(io.trino.parquet.RichColumnDescriptor) RichColumnDescriptor(io.trino.parquet.RichColumnDescriptor) ColumnDescriptor(org.apache.parquet.column.ColumnDescriptor) PrimitiveType(org.apache.parquet.schema.PrimitiveType) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) MapType(io.trino.spi.type.MapType) HiveColumnHandle(io.trino.plugin.hive.HiveColumnHandle) MessageType(org.apache.parquet.schema.MessageType) TypeOperators(io.trino.spi.type.TypeOperators) Test(org.testng.annotations.Test)

Example 23 with TypeOperators

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

the class TestSimplePagesHashStrategy method testCompareSortChannelPositionsWithMapType.

@Test
public void testCompareSortChannelPositionsWithMapType() {
    MapType mapType = new MapType(INTEGER, INTEGER, new TypeOperators());
    Block block = mapType.createBlockFromKeyValue(Optional.empty(), new int[] { 0, 1 }, new IntArrayBlock(1, Optional.empty(), new int[] { 1234 }), new IntArrayBlock(1, Optional.empty(), new int[] { 5678 }));
    SimplePagesHashStrategy strategy = createSimplePagesHashStrategy(mapType, ImmutableList.of(block));
    // This fails because MapType is not orderable.
    assertThatThrownBy(() -> strategy.compareSortChannelPositions(0, 0, 0, 0)).isInstanceOf(IllegalArgumentException.class).hasMessageContaining("type is not orderable");
}
Also used : IntArrayBlock(io.trino.spi.block.IntArrayBlock) IntArrayBlock(io.trino.spi.block.IntArrayBlock) Block(io.trino.spi.block.Block) MapType(io.trino.spi.type.MapType) BlockTypeOperators(io.trino.type.BlockTypeOperators) TypeOperators(io.trino.spi.type.TypeOperators) Test(org.testng.annotations.Test)

Example 24 with TypeOperators

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

the class TestSimplePagesHashStrategy method testRowEqualsRowWithMapType.

@Test
public void testRowEqualsRowWithMapType() {
    MapType mapType = new MapType(INTEGER, INTEGER, new TypeOperators());
    SimplePagesHashStrategy strategy = createSimplePagesHashStrategy(mapType, ImmutableList.of());
    Page leftPage = new Page(mapType.createBlockFromKeyValue(Optional.empty(), new int[] { 0, 1 }, new IntArrayBlock(1, Optional.empty(), new int[] { 1234 }), new IntArrayBlock(1, Optional.empty(), new int[] { 5678 })));
    Page rightPage1 = new Page(mapType.createBlockFromKeyValue(Optional.empty(), new int[] { 0, 1 }, new IntArrayBlock(1, Optional.empty(), new int[] { 1234 }), new IntArrayBlock(1, Optional.empty(), new int[] { 5678 })));
    Page rightPage2 = new Page(mapType.createBlockFromKeyValue(Optional.empty(), new int[] { 0, 1 }, new IntArrayBlock(1, Optional.empty(), new int[] { 1234 }), new IntArrayBlock(1, Optional.empty(), new int[] { 1234 })));
    // This works because MapType is comparable.
    assertTrue(strategy.rowEqualsRow(0, leftPage, 0, rightPage1));
    assertFalse(strategy.rowEqualsRow(0, leftPage, 0, rightPage2));
}
Also used : IntArrayBlock(io.trino.spi.block.IntArrayBlock) Page(io.trino.spi.Page) MapType(io.trino.spi.type.MapType) BlockTypeOperators(io.trino.type.BlockTypeOperators) TypeOperators(io.trino.spi.type.TypeOperators) Test(org.testng.annotations.Test)

Example 25 with TypeOperators

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

the class TestStreamingAggregationOperator method test.

@Test
public void test() {
    OperatorFactory operatorFactory = StreamingAggregationOperator.createOperatorFactory(0, new PlanNodeId("test"), ImmutableList.of(BOOLEAN, DOUBLE, BIGINT), ImmutableList.of(DOUBLE), ImmutableList.of(1), ImmutableList.of(COUNT.createAggregatorFactory(SINGLE, ImmutableList.of(0), OptionalInt.empty()), LONG_SUM.createAggregatorFactory(SINGLE, ImmutableList.of(2), OptionalInt.empty())), new JoinCompiler(new TypeOperators()));
    RowPagesBuilder rowPagesBuilder = RowPagesBuilder.rowPagesBuilder(BOOLEAN, DOUBLE, BIGINT);
    List<Page> input = rowPagesBuilder.addSequencePage(3, 0, 0, 1).row(true, 3.0, 4).row(false, 3.0, 5).pageBreak().row(true, 3.0, 6).row(false, 4.0, 7).row(true, 4.0, 8).row(false, 4.0, 9).row(true, 4.0, 10).pageBreak().row(false, 5.0, 11).row(true, 5.0, 12).row(false, 5.0, 13).row(true, 5.0, 14).row(false, 5.0, 15).pageBreak().addSequencePage(3, 0, 6, 16).row(false, Double.NaN, 1).row(false, Double.NaN, 10).row(false, null, 2).row(false, null, 20).build();
    MaterializedResult expected = resultBuilder(driverContext.getSession(), DOUBLE, BIGINT, BIGINT).row(0.0, 1L, 1L).row(1.0, 1L, 2L).row(2.0, 1L, 3L).row(3.0, 3L, 15L).row(4.0, 4L, 34L).row(5.0, 5L, 65L).row(6.0, 1L, 16L).row(7.0, 1L, 17L).row(8.0, 1L, 18L).row(Double.NaN, 2L, 11L).row(null, 2L, 22L).build();
    assertOperatorEquals(operatorFactory, driverContext, input, expected);
}
Also used : PlanNodeId(io.trino.sql.planner.plan.PlanNodeId) JoinCompiler(io.trino.sql.gen.JoinCompiler) RowPagesBuilder(io.trino.RowPagesBuilder) Page(io.trino.spi.Page) MaterializedResult(io.trino.testing.MaterializedResult) 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