Search in sources :

Example 86 with ArrayType

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

the class TestChecksumAggregation method testArray.

@Test
public void testArray() {
    ArrayType arrayType = new ArrayType(BIGINT);
    Block block = createArrayBigintBlock(asList(null, asList(1L, 2L), asList(3L, 4L), asList(5L, 6L)));
    assertAggregation(FUNCTION_RESOLUTION, QualifiedName.of("checksum"), fromTypes(arrayType), expectedChecksum(arrayType, block), block);
}
Also used : ArrayType(io.trino.spi.type.ArrayType) Block(io.trino.spi.block.Block) BlockAssertions.createShortDecimalsBlock(io.trino.block.BlockAssertions.createShortDecimalsBlock) BlockAssertions.createStringsBlock(io.trino.block.BlockAssertions.createStringsBlock) BlockAssertions.createDoublesBlock(io.trino.block.BlockAssertions.createDoublesBlock) BlockAssertions.createBooleansBlock(io.trino.block.BlockAssertions.createBooleansBlock) BlockAssertions.createLongDecimalsBlock(io.trino.block.BlockAssertions.createLongDecimalsBlock) BlockAssertions.createLongsBlock(io.trino.block.BlockAssertions.createLongsBlock) BlockAssertions.createArrayBigintBlock(io.trino.block.BlockAssertions.createArrayBigintBlock) Test(org.testng.annotations.Test)

Example 87 with ArrayType

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

the class TestMapAggAggregation method testDoubleArrayMap.

@Test
public void testDoubleArrayMap() {
    ArrayType arrayType = new ArrayType(VARCHAR);
    assertAggregation(FUNCTION_RESOLUTION, QualifiedName.of(MapAggregationFunction.NAME), fromTypes(DOUBLE, arrayType), ImmutableMap.of(1.0, ImmutableList.of("a", "b"), 2.0, ImmutableList.of("c", "d"), 3.0, ImmutableList.of("e", "f")), createDoublesBlock(1.0, 2.0, 3.0), createStringArraysBlock(ImmutableList.of(ImmutableList.of("a", "b"), ImmutableList.of("c", "d"), ImmutableList.of("e", "f"))));
}
Also used : ArrayType(io.trino.spi.type.ArrayType) Test(org.testng.annotations.Test)

Example 88 with ArrayType

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

the class TestMapAggAggregation method testArrayDoubleMap.

@Test
public void testArrayDoubleMap() {
    ArrayType arrayType = new ArrayType(VARCHAR);
    assertAggregation(FUNCTION_RESOLUTION, QualifiedName.of(MapAggregationFunction.NAME), fromTypes(arrayType, DOUBLE), ImmutableMap.of(ImmutableList.of("a", "b"), 1.0, ImmutableList.of("c", "d"), 2.0, ImmutableList.of("e", "f"), 3.0), createStringArraysBlock(ImmutableList.of(ImmutableList.of("a", "b"), ImmutableList.of("c", "d"), ImmutableList.of("e", "f"))), createDoublesBlock(1.0, 2.0, 3.0));
}
Also used : ArrayType(io.trino.spi.type.ArrayType) Test(org.testng.annotations.Test)

Example 89 with ArrayType

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

the class TestMapUnionAggregation method testStructural.

@Test
public void testStructural() {
    MapType mapType = mapType(DOUBLE, new ArrayType(VARCHAR));
    assertAggregation(FUNCTION_RESOLUTION, QualifiedName.of(MapUnionAggregation.NAME), fromTypes(mapType), ImmutableMap.of(1.0, ImmutableList.of("a", "b"), 2.0, ImmutableList.of("c", "d"), 3.0, ImmutableList.of("e", "f"), 4.0, ImmutableList.of("r", "s")), arrayBlockOf(mapType, mapBlockOf(DOUBLE, new ArrayType(VARCHAR), ImmutableMap.of(1.0, ImmutableList.of("a", "b"), 2.0, ImmutableList.of("c", "d"), 3.0, ImmutableList.of("e", "f"))), mapBlockOf(DOUBLE, new ArrayType(VARCHAR), ImmutableMap.of(1.0, ImmutableList.of("x", "y"), 4.0, ImmutableList.of("r", "s"), 3.0, ImmutableList.of("w", "z")))));
    mapType = mapType(DOUBLE, mapType(VARCHAR, VARCHAR));
    assertAggregation(FUNCTION_RESOLUTION, QualifiedName.of(MapUnionAggregation.NAME), fromTypes(mapType), ImmutableMap.of(1.0, ImmutableMap.of("a", "b"), 2.0, ImmutableMap.of("c", "d"), 3.0, ImmutableMap.of("e", "f")), arrayBlockOf(mapType, mapBlockOf(DOUBLE, mapType(VARCHAR, VARCHAR), ImmutableMap.of(1.0, ImmutableMap.of("a", "b"), 2.0, ImmutableMap.of("c", "d"))), mapBlockOf(DOUBLE, mapType(VARCHAR, VARCHAR), ImmutableMap.of(3.0, ImmutableMap.of("e", "f")))));
    mapType = mapType(new ArrayType(VARCHAR), DOUBLE);
    assertAggregation(FUNCTION_RESOLUTION, QualifiedName.of(MapUnionAggregation.NAME), fromTypes(mapType), ImmutableMap.of(ImmutableList.of("a", "b"), 1.0, ImmutableList.of("c", "d"), 2.0, ImmutableList.of("e", "f"), 3.0), arrayBlockOf(mapType, mapBlockOf(new ArrayType(VARCHAR), DOUBLE, ImmutableMap.of(ImmutableList.of("a", "b"), 1.0, ImmutableList.of("e", "f"), 3.0)), mapBlockOf(new ArrayType(VARCHAR), DOUBLE, ImmutableMap.of(ImmutableList.of("c", "d"), 2.0))));
}
Also used : ArrayType(io.trino.spi.type.ArrayType) MapType(io.trino.spi.type.MapType) Test(org.testng.annotations.Test)

Example 90 with ArrayType

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

the class TestQueryResultRows method shouldHandleNullValuesInArray.

@Test
public void shouldHandleNullValuesInArray() {
    List<Column> columns = ImmutableList.of(new Column("_col0", ARRAY, new ClientTypeSignature(ARRAY)));
    List<Type> types = ImmutableList.of(new ArrayType(TimestampWithTimeZoneType.TIMESTAMP_WITH_TIME_ZONE));
    List<Page> pages = rowPagesBuilder(types).row(singletonList(null)).build();
    TestExceptionConsumer exceptionConsumer = new TestExceptionConsumer();
    QueryResultRows rows = queryResultRowsBuilder(getSession()).withColumnsAndTypes(columns, types).withExceptionConsumer(exceptionConsumer).addPages(pages).build();
    assertThat(exceptionConsumer.getExceptions()).isEmpty();
    assertFalse(rows.isEmpty(), "rows are empty");
    assertThat(rows.getTotalRowsCount()).isEqualTo(1);
    assertThat(getAllValues(rows)).hasSize(1).containsOnly(singletonList(singletonList(null)));
    assertThat(exceptionConsumer.getExceptions()).isEmpty();
}
Also used : ArrayType(io.trino.spi.type.ArrayType) BogusType(io.trino.tests.BogusType) Type(io.trino.spi.type.Type) BooleanType(io.trino.spi.type.BooleanType) TimestampType(io.trino.spi.type.TimestampType) BigintType(io.trino.spi.type.BigintType) TimestampWithTimeZoneType(io.trino.spi.type.TimestampWithTimeZoneType) SmallintType(io.trino.spi.type.SmallintType) RowType(io.trino.spi.type.RowType) IntegerType(io.trino.spi.type.IntegerType) ArrayType(io.trino.spi.type.ArrayType) TypeSignature.mapType(io.trino.spi.type.TypeSignature.mapType) Column(io.trino.client.Column) Page(io.trino.spi.Page) ClientTypeSignature(io.trino.client.ClientTypeSignature) Test(org.testng.annotations.Test)

Aggregations

ArrayType (io.trino.spi.type.ArrayType)289 Test (org.testng.annotations.Test)205 Type (io.trino.spi.type.Type)92 RowType (io.trino.spi.type.RowType)86 ImmutableList (com.google.common.collect.ImmutableList)66 List (java.util.List)62 ArrayList (java.util.ArrayList)59 MapType (io.trino.spi.type.MapType)43 Arrays.asList (java.util.Arrays.asList)36 Collections.singletonList (java.util.Collections.singletonList)34 VarcharType (io.trino.spi.type.VarcharType)32 VarcharType.createUnboundedVarcharType (io.trino.spi.type.VarcharType.createUnboundedVarcharType)32 BlockBuilder (io.trino.spi.block.BlockBuilder)31 MessageType (org.apache.parquet.schema.MessageType)31 DecimalType.createDecimalType (io.trino.spi.type.DecimalType.createDecimalType)30 MessageTypeParser.parseMessageType (org.apache.parquet.schema.MessageTypeParser.parseMessageType)27 DecimalType (io.trino.spi.type.DecimalType)26 StructuralTestUtil.mapType (io.trino.testing.StructuralTestUtil.mapType)24 Block (io.trino.spi.block.Block)23 Map (java.util.Map)23