Search in sources :

Example 31 with ArrayType

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

the class TestUnnestOperator method testUnnestNonNumericDoubles.

@Test
public void testUnnestNonNumericDoubles() {
    Type arrayType = new ArrayType(DOUBLE);
    Type mapType = TESTING_TYPE_MANAGER.getType(mapType(BIGINT.getTypeSignature(), BIGINT.getTypeSignature()));
    List<Page> input = rowPagesBuilder(BIGINT, arrayType, mapType).row(1L, arrayBlockOf(DOUBLE, NEGATIVE_INFINITY, POSITIVE_INFINITY, NaN), mapBlockOf(BIGINT, DOUBLE, ImmutableMap.of(1, NEGATIVE_INFINITY, 2, POSITIVE_INFINITY, 3, NaN))).build();
    OperatorFactory operatorFactory = new UnnestOperator.UnnestOperatorFactory(0, new PlanNodeId("test"), ImmutableList.of(0), ImmutableList.of(BIGINT), ImmutableList.of(1, 2), ImmutableList.of(arrayType, mapType), false, false);
    MaterializedResult expected = resultBuilder(driverContext.getSession(), BIGINT, DOUBLE, BIGINT, DOUBLE).row(1L, NEGATIVE_INFINITY, 1L, NEGATIVE_INFINITY).row(1L, POSITIVE_INFINITY, 2L, POSITIVE_INFINITY).row(1L, NaN, 3L, NaN).build();
    assertOperatorEquals(operatorFactory, driverContext, input, expected);
}
Also used : ArrayType(io.trino.spi.type.ArrayType) PlanNodeId(io.trino.sql.planner.plan.PlanNodeId) Type(io.trino.spi.type.Type) RowType(io.trino.spi.type.RowType) ArrayType(io.trino.spi.type.ArrayType) TypeSignature.mapType(io.trino.spi.type.TypeSignature.mapType) OperatorFactory(io.trino.operator.OperatorFactory) Page(io.trino.spi.Page) MaterializedResult(io.trino.testing.MaterializedResult) Test(org.testng.annotations.Test)

Example 32 with ArrayType

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

the class TestUnnestOperator method testOuterUnnest.

@Test
public void testOuterUnnest() {
    Type mapType = TESTING_TYPE_MANAGER.getType(mapType(BIGINT.getTypeSignature(), BIGINT.getTypeSignature()));
    Type arrayType = new ArrayType(BIGINT);
    Type elementType = RowType.anonymous(ImmutableList.of(BIGINT, DOUBLE, VARCHAR));
    Type arrayOfRowType = new ArrayType(elementType);
    List<Page> input = rowPagesBuilder(BIGINT, mapType, arrayType, arrayOfRowType).row(1, mapBlockOf(BIGINT, BIGINT, ImmutableMap.of(1, 2)), arrayBlockOf(BIGINT, 3), arrayBlockOf(elementType, ImmutableList.of(4, 5.5, "a"), ImmutableList.of(6, 7.7, "b"))).row(2, null, null, null).pageBreak().row(3, null, null, null).build();
    OperatorFactory operatorFactory = new UnnestOperator.UnnestOperatorFactory(0, new PlanNodeId("test"), ImmutableList.of(0), ImmutableList.of(BIGINT), ImmutableList.of(1, 2, 3), ImmutableList.of(mapType, arrayType, arrayOfRowType), false, true);
    MaterializedResult expected = resultBuilder(driverContext.getSession(), BIGINT, BIGINT, BIGINT, BIGINT, BIGINT, DOUBLE, VARCHAR).row(1L, 1L, 2L, 3L, 4L, 5.5, "a").row(1L, null, null, null, 6L, 7.7, "b").row(2L, null, null, null, null, null, null).row(3L, null, null, null, null, null, null).build();
    assertOperatorEquals(operatorFactory, driverContext, input, expected);
}
Also used : ArrayType(io.trino.spi.type.ArrayType) PlanNodeId(io.trino.sql.planner.plan.PlanNodeId) Type(io.trino.spi.type.Type) RowType(io.trino.spi.type.RowType) ArrayType(io.trino.spi.type.ArrayType) TypeSignature.mapType(io.trino.spi.type.TypeSignature.mapType) OperatorFactory(io.trino.operator.OperatorFactory) Page(io.trino.spi.Page) MaterializedResult(io.trino.testing.MaterializedResult) Test(org.testng.annotations.Test)

Example 33 with ArrayType

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

the class TestingUnnesterUtil method createArrayBlock.

public static Block createArrayBlock(Slice[][] values) {
    ArrayType arrayType = new ArrayType(VARCHAR);
    BlockBuilder blockBuilder = arrayType.createBlockBuilder(null, 100, 100);
    for (Slice[] expectedValue : values) {
        if (expectedValue == null) {
            blockBuilder.appendNull();
        } else {
            arrayType.writeObject(blockBuilder, createSimpleBlock(expectedValue));
        }
    }
    return blockBuilder.build();
}
Also used : ArrayType(io.trino.spi.type.ArrayType) Slice(io.airlift.slice.Slice) BlockBuilder(io.trino.spi.block.BlockBuilder)

Example 34 with ArrayType

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

the class TestingUnnesterUtil method createArrayBlockOfRowBlocks.

public static Block createArrayBlockOfRowBlocks(Slice[][][] elements, RowType rowType) {
    ArrayType arrayType = new ArrayType(rowType);
    BlockBuilder arrayBlockBuilder = arrayType.createBlockBuilder(null, 100, 100);
    for (int i = 0; i < elements.length; i++) {
        if (elements[i] == null) {
            arrayBlockBuilder.appendNull();
        } else {
            Slice[][] expectedValues = elements[i];
            BlockBuilder elementBlockBuilder = rowType.createBlockBuilder(null, elements[i].length);
            for (Slice[] expectedValue : expectedValues) {
                if (expectedValue == null) {
                    elementBlockBuilder.appendNull();
                } else {
                    BlockBuilder entryBuilder = elementBlockBuilder.beginBlockEntry();
                    for (Slice v : expectedValue) {
                        if (v == null) {
                            entryBuilder.appendNull();
                        } else {
                            VARCHAR.writeSlice(entryBuilder, v);
                        }
                    }
                    elementBlockBuilder.closeEntry();
                }
            }
            arrayType.writeObject(arrayBlockBuilder, elementBlockBuilder.build());
        }
    }
    return arrayBlockBuilder.build();
}
Also used : ArrayType(io.trino.spi.type.ArrayType) Slice(io.airlift.slice.Slice) BlockBuilder(io.trino.spi.block.BlockBuilder)

Example 35 with ArrayType

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

the class TestZipWithFunction method testSameLength.

@Test
public void testSameLength() {
    assertFunction("zip_with(ARRAY[], ARRAY[], (x, y) -> (y, x))", new ArrayType(RowType.anonymous(ImmutableList.of(UNKNOWN, UNKNOWN))), ImmutableList.of());
    assertFunction("zip_with(ARRAY[1, 2], ARRAY['a', 'b'], (x, y) -> (y, x))", new ArrayType(RowType.anonymous(ImmutableList.of(createVarcharType(1), INTEGER))), ImmutableList.of(ImmutableList.of("a", 1), ImmutableList.of("b", 2)));
    assertFunction("zip_with(ARRAY[1, 2], ARRAY[VARCHAR 'a', VARCHAR 'b'], (x, y) -> (y, x))", new ArrayType(RowType.anonymous(ImmutableList.of(VARCHAR, INTEGER))), ImmutableList.of(ImmutableList.of("a", 1), ImmutableList.of("b", 2)));
    assertFunction("zip_with(ARRAY[1, 1], ARRAY[1, 2], (x, y) -> x + y)", new ArrayType(INTEGER), ImmutableList.of(2, 3));
    assertFunction("zip_with(CAST(ARRAY[3, 5] AS ARRAY(BIGINT)), CAST(ARRAY[1, 2] AS ARRAY(BIGINT)), (x, y) -> x * y)", new ArrayType(BIGINT), ImmutableList.of(3L, 10L));
    assertFunction("zip_with(ARRAY[true, false], ARRAY[false, true], (x, y) -> x OR y)", new ArrayType(BOOLEAN), ImmutableList.of(true, true));
    assertFunction("zip_with(ARRAY['a', 'b'], ARRAY['c', 'd'], (x, y) -> concat(x, y))", new ArrayType(VARCHAR), ImmutableList.of("ac", "bd"));
    assertFunction("zip_with(ARRAY[MAP(ARRAY[CAST ('a' AS VARCHAR)], ARRAY[1]), MAP(ARRAY[VARCHAR 'b'], ARRAY[2])], ARRAY[MAP(ARRAY['c'], ARRAY[3]), MAP()], (x, y) -> map_concat(x, y))", new ArrayType(mapType(VARCHAR, INTEGER)), ImmutableList.of(ImmutableMap.of("a", 1, "c", 3), ImmutableMap.of("b", 2)));
}
Also used : ArrayType(io.trino.spi.type.ArrayType) 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