Search in sources :

Example 46 with DecoderTestColumnHandle

use of com.facebook.presto.decoder.DecoderTestColumnHandle in project presto by prestodb.

the class TestAvroDecoder method testSchemaEvolutionToIncompatibleType.

@Test
public void testSchemaEvolutionToIncompatibleType() throws Exception {
    byte[] originalIntData = buildAvroData(new Schema.Parser().parse(getAvroSchema("int_to_string_field", "\"int\"")), "int_to_string_field", 100);
    DecoderTestColumnHandle stringColumnReadingIntData = new DecoderTestColumnHandle(0, "row0", VARCHAR, "int_to_string_field", null, null, false, false, false);
    String changedTypeSchema = getAvroSchema("int_to_string_field", "\"string\"");
    assertThatThrownBy(() -> decodeRow(originalIntData, ImmutableSet.of(stringColumnReadingIntData), ImmutableMap.of(DATA_SCHEMA, changedTypeSchema))).isInstanceOf(PrestoException.class).hasCauseExactlyInstanceOf(AvroTypeException.class).hasStackTraceContaining("Found int, expecting string").hasMessageMatching("Decoding Avro record failed.");
}
Also used : DecoderTestColumnHandle(com.facebook.presto.decoder.DecoderTestColumnHandle) PrestoException(com.facebook.presto.spi.PrestoException) Test(org.testng.annotations.Test)

Example 47 with DecoderTestColumnHandle

use of com.facebook.presto.decoder.DecoderTestColumnHandle in project presto by prestodb.

the class TestAvroDecoder method testStringDecodedAsVarcharN.

@Test
public void testStringDecodedAsVarcharN() throws Exception {
    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(com.facebook.presto.decoder.DecoderTestColumnHandle) FieldValueProvider(com.facebook.presto.decoder.FieldValueProvider) DecoderColumnHandle(com.facebook.presto.decoder.DecoderColumnHandle) Test(org.testng.annotations.Test)

Example 48 with DecoderTestColumnHandle

use of com.facebook.presto.decoder.DecoderTestColumnHandle in project presto by prestodb.

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(com.facebook.presto.decoder.DecoderTestColumnHandle) FieldValueProvider(com.facebook.presto.decoder.FieldValueProvider) DecoderColumnHandle(com.facebook.presto.decoder.DecoderColumnHandle) Test(org.testng.annotations.Test)

Example 49 with DecoderTestColumnHandle

use of com.facebook.presto.decoder.DecoderTestColumnHandle in project presto by prestodb.

the class TestAvroDecoder method testRuntimeDecodingFailure.

@Test
public void testRuntimeDecodingFailure() {
    DecoderTestColumnHandle booleanColumn = new DecoderTestColumnHandle(0, "some_column", BOOLEAN, "long_field", null, null, false, false, false);
    Map<DecoderColumnHandle, FieldValueProvider> decodedRow = buildAndDecodeColumn(booleanColumn, "long_field", "\"long\"", (long) 1);
    assertThatThrownBy(decodedRow.get(booleanColumn)::getBoolean).isInstanceOf(PrestoException.class).hasMessageMatching("cannot decode object of 'class java.lang.Long' as 'boolean' for column 'some_column'");
}
Also used : DecoderTestColumnHandle(com.facebook.presto.decoder.DecoderTestColumnHandle) FieldValueProvider(com.facebook.presto.decoder.FieldValueProvider) PrestoException(com.facebook.presto.spi.PrestoException) DecoderColumnHandle(com.facebook.presto.decoder.DecoderColumnHandle) Test(org.testng.annotations.Test)

Aggregations

DecoderTestColumnHandle (com.facebook.presto.decoder.DecoderTestColumnHandle)49 DecoderColumnHandle (com.facebook.presto.decoder.DecoderColumnHandle)47 Test (org.testng.annotations.Test)47 FieldValueProvider (com.facebook.presto.decoder.FieldValueProvider)46 RowDecoder (com.facebook.presto.decoder.RowDecoder)14 HashSet (java.util.HashSet)8 PrestoException (com.facebook.presto.spi.PrestoException)4 ByteBuffer (java.nio.ByteBuffer)3 Schema (org.apache.avro.Schema)3 GenericData (org.apache.avro.generic.GenericData)3 JsonObjectMapperProvider (com.facebook.airlift.json.JsonObjectMapperProvider)2 ArrayType (com.facebook.presto.common.type.ArrayType)2 Collections.emptyMap (java.util.Collections.emptyMap)2 Map (java.util.Map)2 Type (com.facebook.presto.common.type.Type)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 Slice (io.airlift.slice.Slice)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 String.format (java.lang.String.format)1 UTF_8 (java.nio.charset.StandardCharsets.UTF_8)1