Search in sources :

Example 21 with DecoderTestColumnHandle

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

the class TestAvroDecoder method testMapWithNull.

@Test
public void testMapWithNull() throws Exception {
    DecoderTestColumnHandle row = new DecoderTestColumnHandle(0, "row", VACHAR_MAP_TYPE, "map_field", null, null, false, false, false);
    Map<String, String> expectedValues = new HashMap<>();
    expectedValues.put("key1", null);
    Map<DecoderColumnHandle, FieldValueProvider> decodedRow = buildAndDecodeColumn(row, "map_field", "{\"type\": \"map\", \"values\": \"null\"}", expectedValues);
    checkMapValue(decodedRow, row, expectedValues);
}
Also used : DecoderTestColumnHandle(com.facebook.presto.decoder.DecoderTestColumnHandle) HashMap(java.util.HashMap) FieldValueProvider(com.facebook.presto.decoder.FieldValueProvider) DecoderColumnHandle(com.facebook.presto.decoder.DecoderColumnHandle) Test(org.testng.annotations.Test)

Example 22 with DecoderTestColumnHandle

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

the class TestAvroDecoder method testArrayWithNulls.

@Test
public void testArrayWithNulls() throws Exception {
    DecoderTestColumnHandle row = new DecoderTestColumnHandle(0, "row", new ArrayType(BIGINT), "array_field", null, null, false, false, false);
    List<Long> values = new ArrayList<>();
    values.add(null);
    Map<DecoderColumnHandle, FieldValueProvider> decodedRow = buildAndDecodeColumn(row, "array_field", "{\"type\": \"array\", \"items\": \"null\"}", values);
    checkArrayItemIsNull(decodedRow, row, new long[] { 0 });
}
Also used : ArrayType(com.facebook.presto.common.type.ArrayType) DecoderTestColumnHandle(com.facebook.presto.decoder.DecoderTestColumnHandle) FieldValueProvider(com.facebook.presto.decoder.FieldValueProvider) ArrayList(java.util.ArrayList) DecoderColumnHandle(com.facebook.presto.decoder.DecoderColumnHandle) Test(org.testng.annotations.Test)

Example 23 with DecoderTestColumnHandle

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

the class TestAvroDecoder method testMapDecodedAsMap.

@Test
public void testMapDecodedAsMap() throws Exception {
    DecoderTestColumnHandle row = new DecoderTestColumnHandle(0, "row", VACHAR_MAP_TYPE, "map_field", null, null, false, false, false);
    Map<DecoderColumnHandle, FieldValueProvider> decodedRow = buildAndDecodeColumn(row, "map_field", "{\"type\": \"map\", \"values\": \"string\"}", ImmutableMap.of("key1", "abc", "key2", "def", "key3", "zyx"));
    checkMapValue(decodedRow, row, ImmutableMap.of("key1", "abc", "key2", "def", "key3", "zyx"));
}
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 24 with DecoderTestColumnHandle

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

the class TestAvroDecoder method testIntDecodedAsInteger.

@Test
public void testIntDecodedAsInteger() {
    DecoderTestColumnHandle row = new DecoderTestColumnHandle(0, "row", INTEGER, "id", null, null, false, false, false);
    Map<DecoderColumnHandle, FieldValueProvider> decodedRow = buildAndDecodeColumn(row, "id", "\"int\"", 100_000);
    checkValue(decodedRow, row, 100_000);
}
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 25 with DecoderTestColumnHandle

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

the class TestAvroDecoder method testSchemaEvolutionRemovingColumn.

@Test
public void testSchemaEvolutionRemovingColumn() throws Exception {
    byte[] originalData = buildAvroData(new Schema.Parser().parse(getAvroSchema(ImmutableMap.of("string_field", "\"string\"", "string_field_to_be_removed", "[\"null\", \"string\"]"))), ImmutableMap.of("string_field", "string_field_value", "string_field_to_be_removed", "removed_field_value"));
    DecoderTestColumnHandle evolvedColumn = new DecoderTestColumnHandle(0, "row0", VARCHAR, "string_field", null, null, false, false, false);
    String removedColumnSchema = getAvroSchema("string_field", "\"string\"");
    Map<DecoderColumnHandle, FieldValueProvider> decodedEvolvedRow = decodeRow(originalData, ImmutableSet.of(evolvedColumn), ImmutableMap.of(DATA_SCHEMA, removedColumnSchema));
    assertEquals(decodedEvolvedRow.size(), 1);
    checkValue(decodedEvolvedRow, evolvedColumn, "string_field_value");
}
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)

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