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