use of io.trino.spi.type.ArrayType in project trino by trinodb.
the class TestAvroDecoder method testRowWithNulls.
@Test
public void testRowWithNulls() {
Schema schema = SchemaBuilder.record("record_field").fields().name("f1").type().optional().floatType().name("f2").type().optional().doubleType().name("f3").type().optional().intType().name("f4").type().optional().longType().name("f5").type().optional().stringType().name("f6").type().optional().enumeration("color").symbols("red", "blue", "green").name("f7").type().optional().fixed("fixed5").size(5).name("f8").type().optional().bytesType().name("f9").type().optional().booleanType().name("f10").type().optional().array().items().unionOf().nullType().and().record("sub_array_field").fields().name("sf1").type().optional().stringType().name("sf2").type().optional().longType().endRecord().endUnion().name("f11").type().optional().map().values().unionOf().nullType().and().record("sub_map_field").fields().name("sf1").type().optional().doubleType().name("sf2").type().optional().booleanType().endRecord().endUnion().name("f12").type().optional().record("sub_row_field").fields().name("sf1").type().optional().intType().name("sf2").type().optional().enumeration("state").symbols("initialized", "running", "finished", "failed").endRecord().endRecord();
RowType rowType = RowType.from(ImmutableList.<RowType.Field>builder().add(RowType.field("f1", REAL)).add(RowType.field("f2", DOUBLE)).add(RowType.field("f3", INTEGER)).add(RowType.field("f4", BIGINT)).add(RowType.field("f5", VARCHAR)).add(RowType.field("f6", VARCHAR)).add(RowType.field("f7", VARBINARY)).add(RowType.field("f8", VARBINARY)).add(RowType.field("f9", BOOLEAN)).add(RowType.field("f10", new ArrayType(RowType.from(ImmutableList.<RowType.Field>builder().add(RowType.field("sf1", VARCHAR)).add(RowType.field("sf2", BIGINT)).build())))).add(RowType.field("f11", MAP_OF_RECORD)).add(RowType.field("f12", RowType.from(ImmutableList.<RowType.Field>builder().add(RowType.field("sf1", INTEGER)).add(RowType.field("sf2", VARCHAR)).build()))).build());
GenericRecord data = new GenericRecordBuilder(schema).build();
DecoderTestColumnHandle row = new DecoderTestColumnHandle(0, "record_field", rowType, "record_field", null, null, false, false, false);
Map<DecoderColumnHandle, FieldValueProvider> decodedRow = buildAndDecodeColumn(row, "record_field", schema.toString(), data);
checkRowValue(decodedRow, row, data);
// Check nested fields with null values
GenericData.Array<GenericRecord> array = new GenericData.Array<GenericRecord>(schema.getField("f10").schema().getTypes().get(1), Arrays.asList(new GenericRecordBuilder(schema.getField("f10").schema().getTypes().get(1).getElementType().getTypes().get(1)).build(), null));
data = new GenericRecordBuilder(schema).set("f10", array).set("f11", ImmutableMap.builder().put("key1", new GenericRecordBuilder(schema.getField("f11").schema().getTypes().get(1).getValueType().getTypes().get(1)).build()).buildOrThrow()).set("f12", new GenericRecordBuilder(schema.getField("f12").schema().getTypes().get(1)).build()).build();
decodedRow = buildAndDecodeColumn(row, "record_field", schema.toString(), data);
checkRowValue(decodedRow, row, data);
}
use of io.trino.spi.type.ArrayType in project trino by trinodb.
the class TestAvroDecoder method testArrayDecodedAsArray.
@Test
public void testArrayDecodedAsArray() {
DecoderTestColumnHandle row = new DecoderTestColumnHandle(0, "row", new ArrayType(BIGINT), "array_field", null, null, false, false, false);
Map<DecoderColumnHandle, FieldValueProvider> decodedRow = buildAndDecodeColumn(row, "array_field", "{\"type\": \"array\", \"items\": [\"long\"]}", ImmutableList.of(114L, 136L));
checkArrayValue(decodedRow, row, ImmutableList.of(114L, 136L));
}
use of io.trino.spi.type.ArrayType in project trino by trinodb.
the class TestAvroDecoder method testNestedStringArrayWithNulls.
@Test
public void testNestedStringArrayWithNulls() {
DecoderTestColumnHandle row = new DecoderTestColumnHandle(0, "row", new ArrayType(new ArrayType(VARCHAR)), "array_field", null, null, false, false, false);
Schema schema = SchemaBuilder.array().items().nullable().array().items().nullable().stringType();
List<List<String>> data = Arrays.asList(ImmutableList.of("a", "bb", "ccc"), ImmutableList.of("foo", "bar", "baz", "car"), null, Arrays.asList("boo", "hoo", null, "hoo"));
GenericArray<List<String>> list = new GenericData.Array<>(schema, data);
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 testDeeplyNestedLongArray.
@Test
public void testDeeplyNestedLongArray() {
Schema schema = SchemaBuilder.array().items().array().items().array().items().longType();
List<List<List<Long>>> data = ImmutableList.<List<List<Long>>>builder().add(ImmutableList.<List<Long>>builder().add(ImmutableList.of(12L, 15L, 17L)).add(ImmutableList.of(22L, 25L, 27L, 29L)).build()).build();
GenericArray<List<List<Long>>> list = new GenericData.Array<>(schema, data);
DecoderTestColumnHandle row = new DecoderTestColumnHandle(0, "row", new ArrayType(new ArrayType(new ArrayType(BIGINT))), "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 TestDeltaLakeSchemaSupport method testSerializeSchemaAsJson.
@Test
public void testSerializeSchemaAsJson() throws Exception {
DeltaLakeColumnHandle arrayColumn = new DeltaLakeColumnHandle("arr", new ArrayType(new ArrayType(INTEGER)), REGULAR);
DeltaLakeColumnHandle structColumn = new DeltaLakeColumnHandle("str", RowType.from(ImmutableList.of(new RowType.Field(Optional.of("s1"), VarcharType.createUnboundedVarcharType()), new RowType.Field(Optional.of("s2"), RowType.from(ImmutableList.of(new RowType.Field(Optional.of("i1"), INTEGER), new RowType.Field(Optional.of("d2"), DecimalType.createDecimalType(38, 0))))))), REGULAR);
TypeOperators typeOperators = new TypeOperators();
DeltaLakeColumnHandle mapColumn = new DeltaLakeColumnHandle("m", new MapType(INTEGER, new MapType(INTEGER, INTEGER, typeOperators), typeOperators), REGULAR);
URL expected = getResource("io/trino/plugin/deltalake/transactionlog/schema/nested_schema.json");
ObjectMapper objectMapper = new ObjectMapper();
String jsonEncoding = serializeSchemaAsJson(ImmutableList.of(arrayColumn, structColumn, mapColumn));
assertEquals(objectMapper.readTree(jsonEncoding), objectMapper.readTree(expected));
}
Aggregations