Search in sources :

Example 16 with DecoderColumnHandle

use of io.trino.decoder.DecoderColumnHandle in project trino by trinodb.

the class TestAvroDecoder method testSchemaEvolutionRenamingColumn.

@Test
public void testSchemaEvolutionRenamingColumn() {
    byte[] originalData = buildAvroData(getFieldBuilder().name("string_field").type().stringType().noDefault().endRecord(), "string_field", "string_field_value");
    DecoderTestColumnHandle renamedColumn = new DecoderTestColumnHandle(0, "row0", VARCHAR, "string_field_renamed", null, null, false, false, false);
    String renamedColumnSchema = getFieldBuilder().name("string_field_renamed").type().optional().stringType().endRecord().toString();
    Map<DecoderColumnHandle, FieldValueProvider> decodedEvolvedRow = decodeRow(originalData, ImmutableSet.of(renamedColumn), ImmutableMap.of(DATA_SCHEMA, renamedColumnSchema));
    assertEquals(decodedEvolvedRow.size(), 1);
    checkIsNull(decodedEvolvedRow, renamedColumn);
}
Also used : DecoderTestColumnHandle(io.trino.decoder.DecoderTestColumnHandle) FieldValueProvider(io.trino.decoder.FieldValueProvider) DecoderColumnHandle(io.trino.decoder.DecoderColumnHandle) Test(org.testng.annotations.Test)

Example 17 with DecoderColumnHandle

use of io.trino.decoder.DecoderColumnHandle in project trino by trinodb.

the class TestAvroDecoder method testStringDecodedAsVarcharN.

@Test
public void testStringDecodedAsVarcharN() {
    DecoderTestColumnHandle row = new DecoderTestColumnHandle(0, "row", createVarcharType(10), "varcharn_field", null, null, false, false, false);
    Map<DecoderColumnHandle, FieldValueProvider> decodedRow = buildAndDecodeColumn(row, "varcharn_field", "\"string\"", "abcdefghijklmno");
    checkValue(decodedRow, row, "abcdefghij");
}
Also used : DecoderTestColumnHandle(io.trino.decoder.DecoderTestColumnHandle) FieldValueProvider(io.trino.decoder.FieldValueProvider) DecoderColumnHandle(io.trino.decoder.DecoderColumnHandle) Test(org.testng.annotations.Test)

Example 18 with DecoderColumnHandle

use of io.trino.decoder.DecoderColumnHandle in project trino by trinodb.

the class TestAvroDecoder method testNonExistentFieldsAreNull.

@Test
public void testNonExistentFieldsAreNull() {
    DecoderTestColumnHandle row1 = new DecoderTestColumnHandle(0, "row1", createVarcharType(100), "very/deep/varchar", null, null, false, false, false);
    DecoderTestColumnHandle row2 = new DecoderTestColumnHandle(1, "row2", BIGINT, "no_bigint", null, null, false, false, false);
    DecoderTestColumnHandle row3 = new DecoderTestColumnHandle(2, "row3", DOUBLE, "double_record/is_missing", null, null, false, false, false);
    DecoderTestColumnHandle row4 = new DecoderTestColumnHandle(3, "row4", BOOLEAN, "hello", null, null, false, false, false);
    Map<DecoderColumnHandle, FieldValueProvider> decodedRow1 = buildAndDecodeColumn(row1, "dummy", "\"long\"", 0L);
    Map<DecoderColumnHandle, FieldValueProvider> decodedRow2 = buildAndDecodeColumn(row2, "dummy", "\"long\"", 0L);
    Map<DecoderColumnHandle, FieldValueProvider> decodedRow3 = buildAndDecodeColumn(row3, "dummy", "\"long\"", 0L);
    Map<DecoderColumnHandle, FieldValueProvider> decodedRow4 = buildAndDecodeColumn(row4, "dummy", "\"long\"", 0L);
    checkIsNull(decodedRow1, row1);
    checkIsNull(decodedRow2, row2);
    checkIsNull(decodedRow3, row3);
    checkIsNull(decodedRow4, row4);
}
Also used : DecoderTestColumnHandle(io.trino.decoder.DecoderTestColumnHandle) FieldValueProvider(io.trino.decoder.FieldValueProvider) DecoderColumnHandle(io.trino.decoder.DecoderColumnHandle) Test(org.testng.annotations.Test)

Example 19 with DecoderColumnHandle

use of io.trino.decoder.DecoderColumnHandle 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);
}
Also used : DecoderTestColumnHandle(io.trino.decoder.DecoderTestColumnHandle) FieldValueProvider(io.trino.decoder.FieldValueProvider) Schema(org.apache.avro.Schema) RowType(io.trino.spi.type.RowType) DecoderColumnHandle(io.trino.decoder.DecoderColumnHandle) GenericData(org.apache.avro.generic.GenericData) ArrayType(io.trino.spi.type.ArrayType) GenericArray(org.apache.avro.generic.GenericArray) GenericRecordBuilder(org.apache.avro.generic.GenericRecordBuilder) GenericRecord(org.apache.avro.generic.GenericRecord) Test(org.testng.annotations.Test)

Example 20 with DecoderColumnHandle

use of io.trino.decoder.DecoderColumnHandle 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));
}
Also used : ArrayType(io.trino.spi.type.ArrayType) DecoderTestColumnHandle(io.trino.decoder.DecoderTestColumnHandle) FieldValueProvider(io.trino.decoder.FieldValueProvider) DecoderColumnHandle(io.trino.decoder.DecoderColumnHandle) Test(org.testng.annotations.Test)

Aggregations

DecoderColumnHandle (io.trino.decoder.DecoderColumnHandle)66 FieldValueProvider (io.trino.decoder.FieldValueProvider)63 DecoderTestColumnHandle (io.trino.decoder.DecoderTestColumnHandle)61 Test (org.testng.annotations.Test)61 Schema (org.apache.avro.Schema)24 RowDecoder (io.trino.decoder.RowDecoder)17 ArrayType (io.trino.spi.type.ArrayType)15 ImmutableList (com.google.common.collect.ImmutableList)13 ArrayList (java.util.ArrayList)13 List (java.util.List)12 GenericArray (org.apache.avro.generic.GenericArray)11 Map (java.util.Map)9 HashMap (java.util.HashMap)8 ImmutableMap (com.google.common.collect.ImmutableMap)6 ByteBuffer (java.nio.ByteBuffer)4 GenericData (org.apache.avro.generic.GenericData)4 Collections.emptyMap (java.util.Collections.emptyMap)3 GenericRecord (org.apache.avro.generic.GenericRecord)3 GenericRecordBuilder (org.apache.avro.generic.GenericRecordBuilder)3 MockSchemaRegistryClient (io.confluent.kafka.schemaregistry.client.MockSchemaRegistryClient)2