Search in sources :

Example 46 with ArrayType

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

the class TestAvroDecoder method testDeeplyNestedStringArrayWithNulls.

@Test
public void testDeeplyNestedStringArrayWithNulls() {
    Schema schema = SchemaBuilder.array().items().nullable().array().items().nullable().array().items().nullable().stringType();
    List<List<List<String>>> data = Arrays.asList(Arrays.asList(ImmutableList.of("a", "bb", "ccc"), null, Arrays.asList("boo", "hoo", null, "hoo"), ImmutableList.of("foo", "bar", "baz", "car")), null);
    GenericArray<List<List<String>>> list = new GenericData.Array<>(schema, data);
    DecoderTestColumnHandle row = new DecoderTestColumnHandle(0, "row", new ArrayType(new ArrayType(new ArrayType(VARCHAR))), "array_field", null, null, false, false, false);
    Map<DecoderColumnHandle, FieldValueProvider> decodedRow = buildAndDecodeColumn(row, "array_field", schema.toString(), list);
    checkArrayValue(decodedRow, row, list);
}
Also used : GenericArray(org.apache.avro.generic.GenericArray) ArrayType(io.trino.spi.type.ArrayType) DecoderTestColumnHandle(io.trino.decoder.DecoderTestColumnHandle) FieldValueProvider(io.trino.decoder.FieldValueProvider) Schema(org.apache.avro.Schema) List(java.util.List) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) DecoderColumnHandle(io.trino.decoder.DecoderColumnHandle) Test(org.testng.annotations.Test)

Example 47 with ArrayType

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

the class TestAvroDecoder method testArrayOfMaps.

@Test
public void testArrayOfMaps() {
    Schema schema = SchemaBuilder.array().items().map().values().floatType();
    List<Map<String, Float>> data = ImmutableList.<Map<String, Float>>builder().add(buildMapFromKeysAndValues(ImmutableList.of("key1", "key2", "key3"), ImmutableList.of(1.3F, 2.3F, -.5F))).add(buildMapFromKeysAndValues(ImmutableList.of("key10", "key20", "key30"), ImmutableList.of(11.3F, 12.3F, -1.5F))).build();
    DecoderTestColumnHandle row = new DecoderTestColumnHandle(0, "row", new ArrayType(REAL_MAP_TYPE), "array_field", null, null, false, false, false);
    GenericArray<Map<String, Float>> list = new GenericData.Array<>(schema, data);
    Map<DecoderColumnHandle, FieldValueProvider> decodedRow = buildAndDecodeColumn(row, "array_field", schema.toString(), list);
    checkArrayValues(getBlock(decodedRow, row), row.getType(), data);
}
Also used : ArrayType(io.trino.spi.type.ArrayType) GenericArray(org.apache.avro.generic.GenericArray) DecoderTestColumnHandle(io.trino.decoder.DecoderTestColumnHandle) FieldValueProvider(io.trino.decoder.FieldValueProvider) Schema(org.apache.avro.Schema) DecoderColumnHandle(io.trino.decoder.DecoderColumnHandle) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) HashMap(java.util.HashMap) Test(org.testng.annotations.Test)

Example 48 with ArrayType

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

the class TestAvroDecoder method testArrayOfMapsWithNulls.

@Test
public void testArrayOfMapsWithNulls() {
    Schema schema = SchemaBuilder.array().items().nullable().map().values().nullable().floatType();
    List<Map<String, Float>> data = Arrays.asList(buildMapFromKeysAndValues(ImmutableList.of("key1", "key2", "key3"), ImmutableList.of(1.3F, 2.3F, -.5F)), null, buildMapFromKeysAndValues(ImmutableList.of("key10", "key20", "key30"), ImmutableList.of(11.3F, 12.3F, -1.5F)), buildMapFromKeysAndValues(ImmutableList.of("key100", "key200", "key300"), Arrays.asList(111.3F, null, -11.5F)));
    DecoderTestColumnHandle row = new DecoderTestColumnHandle(0, "row", new ArrayType(REAL_MAP_TYPE), "array_field", null, null, false, false, false);
    GenericArray<Map<String, Float>> list = new GenericData.Array<>(schema, data);
    Map<DecoderColumnHandle, FieldValueProvider> decodedRow = buildAndDecodeColumn(row, "array_field", schema.toString(), list);
    checkArrayValues(getBlock(decodedRow, row), row.getType(), data);
}
Also used : ArrayType(io.trino.spi.type.ArrayType) GenericArray(org.apache.avro.generic.GenericArray) DecoderTestColumnHandle(io.trino.decoder.DecoderTestColumnHandle) FieldValueProvider(io.trino.decoder.FieldValueProvider) Schema(org.apache.avro.Schema) DecoderColumnHandle(io.trino.decoder.DecoderColumnHandle) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) HashMap(java.util.HashMap) Test(org.testng.annotations.Test)

Example 49 with ArrayType

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

the class AvroDecoderTestUtil method checkArrayValues.

public static void checkArrayValues(Block block, Type type, Object value) {
    assertNotNull(type, "Type is null");
    assertTrue(type instanceof ArrayType, "Unexpected type");
    assertNotNull(block, "Block is null");
    assertNotNull(value, "Value is null");
    List<?> list = (List<?>) value;
    assertEquals(block.getPositionCount(), list.size());
    Type elementType = ((ArrayType) type).getElementType();
    if (elementType instanceof ArrayType) {
        for (int index = 0; index < block.getPositionCount(); index++) {
            if (block.isNull(index)) {
                assertNull(list.get(index));
                continue;
            }
            Block arrayBlock = block.getObject(index, Block.class);
            checkArrayValues(arrayBlock, elementType, list.get(index));
        }
    } else if (elementType instanceof MapType) {
        for (int index = 0; index < block.getPositionCount(); index++) {
            if (block.isNull(index)) {
                assertNull(list.get(index));
                continue;
            }
            Block mapBlock = block.getObject(index, Block.class);
            checkMapValues(mapBlock, elementType, list.get(index));
        }
    } else if (elementType instanceof RowType) {
        for (int index = 0; index < block.getPositionCount(); index++) {
            if (block.isNull(index)) {
                assertNull(list.get(index));
                continue;
            }
            Block rowBlock = block.getObject(index, Block.class);
            checkRowValues(rowBlock, elementType, list.get(index));
        }
    } else {
        for (int index = 0; index < block.getPositionCount(); index++) {
            checkPrimitiveValue(getObjectValue(elementType, block, index), list.get(index));
        }
    }
}
Also used : ArrayType(io.trino.spi.type.ArrayType) RowType(io.trino.spi.type.RowType) MapType(io.trino.spi.type.MapType) Type(io.trino.spi.type.Type) ArrayType(io.trino.spi.type.ArrayType) VarcharType(io.trino.spi.type.VarcharType) Block(io.trino.spi.block.Block) RowType(io.trino.spi.type.RowType) List(java.util.List) MapType(io.trino.spi.type.MapType)

Example 50 with ArrayType

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

the class TestAvroDecoder method testNestedLongArrayWithNulls.

@Test
public void testNestedLongArrayWithNulls() {
    DecoderTestColumnHandle row = new DecoderTestColumnHandle(0, "row", new ArrayType(new ArrayType(BIGINT)), "array_field", null, null, false, false, false);
    Schema schema = SchemaBuilder.array().items().nullable().array().items().nullable().longType();
    List<List<Long>> data = Arrays.asList(ImmutableList.of(12L, 15L, 17L), ImmutableList.of(22L, 25L, 27L, 29L), null, Arrays.asList(3L, 5L, null, 6L));
    GenericArray<List<Long>> list = new GenericData.Array<>(schema, data);
    Map<DecoderColumnHandle, FieldValueProvider> decodedRow = buildAndDecodeColumn(row, "array_field", schema.toString(), list);
    checkArrayValue(decodedRow, row, list);
}
Also used : ArrayType(io.trino.spi.type.ArrayType) GenericArray(org.apache.avro.generic.GenericArray) DecoderTestColumnHandle(io.trino.decoder.DecoderTestColumnHandle) FieldValueProvider(io.trino.decoder.FieldValueProvider) Schema(org.apache.avro.Schema) List(java.util.List) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) DecoderColumnHandle(io.trino.decoder.DecoderColumnHandle) 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