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);
}
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);
}
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);
}
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));
}
}
}
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);
}
Aggregations