Search in sources :

Example 11 with DecoderColumnHandle

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

the class TestAvroDecoder method testFixedDecodedAsVarbinary.

@Test
public void testFixedDecodedAsVarbinary() {
    Schema schema = SchemaBuilder.record("record").fields().name("fixed_field").type().fixed("fixed5").size(5).noDefault().endRecord();
    Schema fixedType = schema.getField("fixed_field").schema();
    GenericData.Fixed fixedValue = new GenericData.Fixed(schema.getField("fixed_field").schema());
    byte[] bytes = { 5, 4, 3, 2, 1 };
    fixedValue.bytes(bytes);
    DecoderTestColumnHandle row = new DecoderTestColumnHandle(0, "row", VARBINARY, "fixed_field", null, null, false, false, false);
    Map<DecoderColumnHandle, FieldValueProvider> decodedRow = buildAndDecodeColumn(row, "fixed_field", fixedType.toString(), fixedValue);
    checkValue(decodedRow, row, Slices.wrappedBuffer(bytes));
}
Also used : DecoderTestColumnHandle(io.trino.decoder.DecoderTestColumnHandle) FieldValueProvider(io.trino.decoder.FieldValueProvider) Schema(org.apache.avro.Schema) DecoderColumnHandle(io.trino.decoder.DecoderColumnHandle) GenericData(org.apache.avro.generic.GenericData) Test(org.testng.annotations.Test)

Example 12 with DecoderColumnHandle

use of io.trino.decoder.DecoderColumnHandle 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 13 with DecoderColumnHandle

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

the class TestAvroDecoder method testMapOfArrayOfMapsWithDifferentValues.

@Test
public void testMapOfArrayOfMapsWithDifferentValues() {
    Schema schema = SchemaBuilder.map().values().array().items().map().values().floatType();
    Map<String, List<Map<String, Float>>> data = buildMapFromKeysAndValues(ImmutableList.of("k1", "k2"), Arrays.asList(Arrays.asList(buildMapFromKeysAndValues(ImmutableList.of("sk1", "sk2", "sk3"), Arrays.asList(1.3F, -5.3F, 2.3F))), Arrays.asList(buildMapFromKeysAndValues(ImmutableList.of("sk11", "sk21", "sk31"), Arrays.asList(11.3F, -1.5F, 12.3F)))));
    Map<String, List<Map<String, Float>>> mismatchedData = buildMapFromKeysAndValues(ImmutableList.of("k1", "k2"), Arrays.asList(Arrays.asList(buildMapFromKeysAndValues(ImmutableList.of("sk1", "sk2", "sk3"), Arrays.asList(1.3F, -5.3F, -2.3F))), Arrays.asList(buildMapFromKeysAndValues(ImmutableList.of("sk11", "sk21", "sk31"), Arrays.asList(11.3F, -1.5F, 12.3F)))));
    DecoderTestColumnHandle row = new DecoderTestColumnHandle(0, "row", MAP_OF_ARRAY_OF_MAP_TYPE, "map_field", null, null, false, false, false);
    Map<DecoderColumnHandle, FieldValueProvider> decodedRow = buildAndDecodeColumn(row, "map_field", schema.toString(), data);
    assertThatThrownBy(() -> checkArrayValue(decodedRow, row, mismatchedData)).isInstanceOf(AssertionError.class).hasMessage("Unexpected type expected [true] but found [false]");
}
Also used : 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 14 with DecoderColumnHandle

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

the class TestAvroDecoder method testIntDecodedAsSmallInt.

@Test
public void testIntDecodedAsSmallInt() {
    DecoderTestColumnHandle row = new DecoderTestColumnHandle(0, "row", SMALLINT, "id", null, null, false, false, false);
    Map<DecoderColumnHandle, FieldValueProvider> decodedRow = buildAndDecodeColumn(row, "id", "\"int\"", 1000);
    checkValue(decodedRow, row, 1000);
}
Also used : DecoderTestColumnHandle(io.trino.decoder.DecoderTestColumnHandle) FieldValueProvider(io.trino.decoder.FieldValueProvider) DecoderColumnHandle(io.trino.decoder.DecoderColumnHandle) Test(org.testng.annotations.Test)

Example 15 with DecoderColumnHandle

use of io.trino.decoder.DecoderColumnHandle 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

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