Search in sources :

Example 21 with TestingTypeManager

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

the class TestAvroSchemaConverter method testTypesWithDefaults.

@Test
public void testTypesWithDefaults() {
    Schema schema = SchemaBuilder.record(RECORD_NAME).fields().name("bool_col").type().booleanType().booleanDefault(true).name("int_col").type().intType().intDefault(3).name("long_col").type().longType().longDefault(3L).name("float_col").type().floatType().floatDefault(3.3F).name("double_col").type().doubleType().doubleDefault(3.3D).name("string_col").type().stringType().stringDefault("three").name("enum_col").type().enumeration("colors").symbols("blue", "red", "yellow").enumDefault("yellow").name("bytes_col").type().bytesType().bytesDefault(new byte[] { 1, 2, 3 }).name("fixed_col").type().fixed("fixed").size(5).fixedDefault(new byte[] { 1, 2, 3 }).name("union_col").type().unionOf().nullType().and().floatType().and().doubleType().endUnion().nullDefault().name("union_col2").type().unionOf().nullType().and().intType().and().longType().endUnion().nullDefault().name("union_col3").type().unionOf().nullType().and().bytesType().and().type("fixed").endUnion().nullDefault().name("union_col4").type().unionOf().nullType().and().type("colors").and().stringType().endUnion().nullDefault().name("list_col").type().array().items().intType().arrayDefault(Arrays.asList(1, 2, 3)).name("map_col").type().map().values().intType().mapDefault(ImmutableMap.<String, Integer>builder().put("one", 1).put("two", 2).buildOrThrow()).name("record_col").type().record("record_col").fields().name("nested_list").type().array().items().map().values().stringType().noDefault().name("nested_map").type().map().values().array().items().stringType().noDefault().endRecord().recordDefault(new GenericRecordBuilder(SchemaBuilder.record("record_col").fields().name("nested_list").type().array().items().map().values().stringType().noDefault().name("nested_map").type().map().values().array().items().stringType().noDefault().endRecord()).set("nested_list", Arrays.asList(ImmutableMap.<String, String>builder().put("key", "value").put("key1", "value1").buildOrThrow(), ImmutableMap.<String, String>builder().put("key2", "value2").put("key3", "value3").buildOrThrow())).set("nested_map", ImmutableMap.<String, List<String>>builder().put("key1", Arrays.asList("one", "two", "three")).put("key2", Arrays.asList("four", "two", "three")).buildOrThrow()).build()).endRecord();
    AvroSchemaConverter avroSchemaConverter = new AvroSchemaConverter(new TestingTypeManager(), IGNORE);
    List<Type> types = avroSchemaConverter.convertAvroSchema(schema);
    List<Type> expected = ImmutableList.<Type>builder().add(BOOLEAN).add(INTEGER).add(BIGINT).add(REAL).add(DOUBLE).add(VARCHAR).add(VARCHAR).add(VARBINARY).add(VARBINARY).add(DOUBLE).add(BIGINT).add(VARBINARY).add(VARCHAR).add(new ArrayType(INTEGER)).add(createType(INTEGER)).add(RowType.from(ImmutableList.<RowType.Field>builder().add(new RowType.Field(Optional.of("nested_list"), new ArrayType(createType(VARCHAR)))).add(new RowType.Field(Optional.of("nested_map"), createType(new ArrayType(VARCHAR)))).build())).build();
    assertEquals(types, expected);
}
Also used : ArrayType(io.trino.spi.type.ArrayType) Type(io.trino.spi.type.Type) RowType(io.trino.spi.type.RowType) MapType(io.trino.spi.type.MapType) ArrayType(io.trino.spi.type.ArrayType) Schema(org.apache.avro.Schema) GenericRecordBuilder(org.apache.avro.generic.GenericRecordBuilder) RowType(io.trino.spi.type.RowType) TestingTypeManager(io.trino.spi.type.TestingTypeManager) Test(org.testng.annotations.Test)

Aggregations

TestingTypeManager (io.trino.spi.type.TestingTypeManager)21 Type (io.trino.spi.type.Type)14 Test (org.testng.annotations.Test)14 ObjectMapperProvider (io.airlift.json.ObjectMapperProvider)8 ArrayType (io.trino.spi.type.ArrayType)7 MapType (io.trino.spi.type.MapType)6 RowType (io.trino.spi.type.RowType)6 TestingTypeDeserializer (io.trino.spi.type.TestingTypeDeserializer)6 Schema (org.apache.avro.Schema)6 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)5 SimpleModule (com.fasterxml.jackson.databind.module.SimpleModule)5 Block (io.trino.spi.block.Block)5 CatalogName (io.trino.plugin.base.CatalogName)4 FileMetastoreTableOperationsProvider (io.trino.plugin.iceberg.catalog.file.FileMetastoreTableOperationsProvider)4 TrinoHiveCatalog (io.trino.plugin.iceberg.catalog.hms.TrinoHiveCatalog)4 TestingBlockEncodingSerde (io.trino.spi.block.TestingBlockEncodingSerde)4 TestingBlockJsonSerde (io.trino.spi.block.TestingBlockJsonSerde)4 JsonCodecFactory (io.airlift.json.JsonCodecFactory)3 HdfsConfig (io.trino.plugin.hive.HdfsConfig)3 HdfsConfiguration (io.trino.plugin.hive.HdfsConfiguration)3