Search in sources :

Example 31 with DecoderTestColumnHandle

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

the class TestRawDecoder method testEmptyRecord.

@Test
public void testEmptyRecord() {
    byte[] emptyRow = new byte[0];
    DecoderTestColumnHandle column = new DecoderTestColumnHandle(0, "row1", createUnboundedVarcharType(), null, "BYTE", null, false, false, false);
    Set<DecoderColumnHandle> columns = ImmutableSet.of(column);
    RowDecoder rowDecoder = DECODER_FACTORY.create(emptyMap(), columns);
    Map<DecoderColumnHandle, FieldValueProvider> decodedRow = rowDecoder.decodeRow(emptyRow, null).orElseThrow(AssertionError::new);
    checkIsNull(decodedRow, column);
}
Also used : DecoderTestColumnHandle(com.facebook.presto.decoder.DecoderTestColumnHandle) FieldValueProvider(com.facebook.presto.decoder.FieldValueProvider) DecoderColumnHandle(com.facebook.presto.decoder.DecoderColumnHandle) RowDecoder(com.facebook.presto.decoder.RowDecoder) Test(org.testng.annotations.Test)

Example 32 with DecoderTestColumnHandle

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

the class TestISO8601JsonFieldDecoder method testNullValues.

@Test
public void testNullValues() throws Exception {
    byte[] json = "{}".getBytes(StandardCharsets.UTF_8);
    JsonRowDecoder rowDecoder = new JsonRowDecoder(PROVIDER.get());
    DecoderTestColumnHandle row1 = new DecoderTestColumnHandle("", 0, "row1", BigintType.BIGINT, "a_number", DEFAULT_FIELD_DECODER_NAME, null, false, false, false);
    DecoderTestColumnHandle row2 = new DecoderTestColumnHandle("", 1, "row2", createVarcharType(100), "a_string", DEFAULT_FIELD_DECODER_NAME, null, false, false, false);
    DecoderTestColumnHandle row3 = new DecoderTestColumnHandle("", 2, "row3", BigintType.BIGINT, "a_number", ISO8601JsonFieldDecoder.NAME, null, false, false, false);
    DecoderTestColumnHandle row4 = new DecoderTestColumnHandle("", 3, "row4", BigintType.BIGINT, "a_string", ISO8601JsonFieldDecoder.NAME, null, false, false, false);
    DecoderTestColumnHandle row5 = new DecoderTestColumnHandle("", 4, "row5", createVarcharType(100), "a_number", ISO8601JsonFieldDecoder.NAME, null, false, false, false);
    DecoderTestColumnHandle row6 = new DecoderTestColumnHandle("", 5, "row6", createVarcharType(100), "a_string", ISO8601JsonFieldDecoder.NAME, null, false, false, false);
    List<DecoderColumnHandle> columns = ImmutableList.of(row1, row2, row3, row4, row5, row6);
    Set<FieldValueProvider> providers = new HashSet<>();
    boolean corrupt = rowDecoder.decodeRow(json, null, providers, columns, buildMap(columns));
    assertFalse(corrupt);
    assertEquals(providers.size(), columns.size());
    // sanity checks
    checkIsNull(providers, row1);
    checkIsNull(providers, row2);
    checkIsNull(providers, row3);
    checkIsNull(providers, row4);
    checkIsNull(providers, row5);
    checkIsNull(providers, row6);
}
Also used : DecoderTestColumnHandle(com.facebook.presto.decoder.DecoderTestColumnHandle) FieldValueProvider(com.facebook.presto.decoder.FieldValueProvider) DecoderColumnHandle(com.facebook.presto.decoder.DecoderColumnHandle) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Example 33 with DecoderTestColumnHandle

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

the class TestISO8601JsonFieldDecoder method testBasicFormatting.

@Test
public void testBasicFormatting() throws Exception {
    long now = System.currentTimeMillis();
    String nowString = PRINTER.print(now);
    byte[] json = format("{\"a_number\":%d,\"a_string\":\"%s\"}", now, nowString).getBytes(StandardCharsets.UTF_8);
    JsonRowDecoder rowDecoder = new JsonRowDecoder(PROVIDER.get());
    DecoderTestColumnHandle row1 = new DecoderTestColumnHandle("", 0, "row1", BigintType.BIGINT, "a_number", DEFAULT_FIELD_DECODER_NAME, null, false, false, false);
    DecoderTestColumnHandle row2 = new DecoderTestColumnHandle("", 1, "row2", createVarcharType(100), "a_string", DEFAULT_FIELD_DECODER_NAME, null, false, false, false);
    DecoderTestColumnHandle row3 = new DecoderTestColumnHandle("", 2, "row3", BigintType.BIGINT, "a_number", ISO8601JsonFieldDecoder.NAME, null, false, false, false);
    DecoderTestColumnHandle row4 = new DecoderTestColumnHandle("", 3, "row4", BigintType.BIGINT, "a_string", ISO8601JsonFieldDecoder.NAME, null, false, false, false);
    DecoderTestColumnHandle row5 = new DecoderTestColumnHandle("", 4, "row5", createVarcharType(100), "a_number", ISO8601JsonFieldDecoder.NAME, null, false, false, false);
    DecoderTestColumnHandle row6 = new DecoderTestColumnHandle("", 5, "row6", createVarcharType(100), "a_string", ISO8601JsonFieldDecoder.NAME, null, false, false, false);
    List<DecoderColumnHandle> columns = ImmutableList.of(row1, row2, row3, row4, row5, row6);
    Set<FieldValueProvider> providers = new HashSet<>();
    boolean corrupt = rowDecoder.decodeRow(json, null, providers, columns, buildMap(columns));
    assertFalse(corrupt);
    assertEquals(providers.size(), columns.size());
    // sanity checks
    checkValue(providers, row1, now);
    checkValue(providers, row2, nowString);
    // number parsed as number --> as is
    checkValue(providers, row3, now);
    // string parsed as number --> parse text, convert to timestamp
    checkValue(providers, row4, now);
    // number parsed as string --> parse text, convert to timestamp, turn into string
    checkValue(providers, row5, Long.toString(now));
    // string parsed as string --> as is
    checkValue(providers, row6, nowString);
}
Also used : DecoderTestColumnHandle(com.facebook.presto.decoder.DecoderTestColumnHandle) FieldValueProvider(com.facebook.presto.decoder.FieldValueProvider) DecoderColumnHandle(com.facebook.presto.decoder.DecoderColumnHandle) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Example 34 with DecoderTestColumnHandle

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

the class TestRFC2822JsonFieldDecoder method testBasicFormatting.

@Test
public void testBasicFormatting() throws Exception {
    // rfc2822 is second granularity
    long now = (System.currentTimeMillis() / 1000) * 1000;
    String nowString = FORMATTER.print(now);
    byte[] json = format("{\"a_number\":%d,\"a_string\":\"%s\"}", now, nowString).getBytes(StandardCharsets.UTF_8);
    JsonRowDecoder rowDecoder = new JsonRowDecoder(PROVIDER.get());
    DecoderTestColumnHandle row1 = new DecoderTestColumnHandle("", 0, "row1", BigintType.BIGINT, "a_number", DEFAULT_FIELD_DECODER_NAME, null, false, false, false);
    DecoderTestColumnHandle row2 = new DecoderTestColumnHandle("", 1, "row2", createVarcharType(100), "a_string", DEFAULT_FIELD_DECODER_NAME, null, false, false, false);
    DecoderTestColumnHandle row3 = new DecoderTestColumnHandle("", 2, "row3", BigintType.BIGINT, "a_number", RFC2822JsonFieldDecoder.NAME, null, false, false, false);
    DecoderTestColumnHandle row4 = new DecoderTestColumnHandle("", 3, "row4", BigintType.BIGINT, "a_string", RFC2822JsonFieldDecoder.NAME, null, false, false, false);
    DecoderTestColumnHandle row5 = new DecoderTestColumnHandle("", 4, "row5", createVarcharType(100), "a_number", RFC2822JsonFieldDecoder.NAME, null, false, false, false);
    DecoderTestColumnHandle row6 = new DecoderTestColumnHandle("", 5, "row6", createVarcharType(100), "a_string", RFC2822JsonFieldDecoder.NAME, null, false, false, false);
    List<DecoderColumnHandle> columns = ImmutableList.of(row1, row2, row3, row4, row5, row6);
    Set<FieldValueProvider> providers = new HashSet<>();
    boolean corrupt = rowDecoder.decodeRow(json, null, providers, columns, map(columns));
    assertFalse(corrupt);
    assertEquals(providers.size(), columns.size());
    // sanity checks
    checkValue(providers, row1, now);
    checkValue(providers, row2, nowString);
    // number parsed as number --> as is
    checkValue(providers, row3, now);
    // string parsed as number --> parse text, convert to timestamp
    checkValue(providers, row4, now);
    // number parsed as string --> parse text, convert to timestamp, turn into string
    checkValue(providers, row5, Long.toString(now));
    // string parsed as string --> as is
    checkValue(providers, row6, nowString);
}
Also used : DecoderTestColumnHandle(com.facebook.presto.decoder.DecoderTestColumnHandle) FieldValueProvider(com.facebook.presto.decoder.FieldValueProvider) DecoderColumnHandle(com.facebook.presto.decoder.DecoderColumnHandle) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Example 35 with DecoderTestColumnHandle

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

the class TestSecondsSinceEpochJsonFieldDecoder method testNullValues.

@Test
public void testNullValues() throws Exception {
    byte[] json = "{}".getBytes(StandardCharsets.UTF_8);
    JsonRowDecoder rowDecoder = new JsonRowDecoder(PROVIDER.get());
    DecoderTestColumnHandle row1 = new DecoderTestColumnHandle("", 0, "row1", BigintType.BIGINT, "a_number", DEFAULT_FIELD_DECODER_NAME, null, false, false, false);
    DecoderTestColumnHandle row2 = new DecoderTestColumnHandle("", 1, "row2", createVarcharType(100), "a_string", DEFAULT_FIELD_DECODER_NAME, null, false, false, false);
    DecoderTestColumnHandle row3 = new DecoderTestColumnHandle("", 2, "row3", BigintType.BIGINT, "a_number", SecondsSinceEpochJsonFieldDecoder.NAME, null, false, false, false);
    DecoderTestColumnHandle row4 = new DecoderTestColumnHandle("", 3, "row4", BigintType.BIGINT, "a_string", SecondsSinceEpochJsonFieldDecoder.NAME, null, false, false, false);
    DecoderTestColumnHandle row5 = new DecoderTestColumnHandle("", 4, "row5", createVarcharType(100), "a_number", SecondsSinceEpochJsonFieldDecoder.NAME, null, false, false, false);
    DecoderTestColumnHandle row6 = new DecoderTestColumnHandle("", 5, "row6", createVarcharType(100), "a_string", SecondsSinceEpochJsonFieldDecoder.NAME, null, false, false, false);
    List<DecoderColumnHandle> columns = ImmutableList.of(row1, row2, row3, row4, row5, row6);
    Set<FieldValueProvider> providers = new HashSet<>();
    boolean corrupt = rowDecoder.decodeRow(json, null, providers, columns, buildMap(columns));
    assertFalse(corrupt);
    assertEquals(providers.size(), columns.size());
    // sanity checks
    checkIsNull(providers, row1);
    checkIsNull(providers, row2);
    checkIsNull(providers, row3);
    checkIsNull(providers, row4);
    checkIsNull(providers, row5);
    checkIsNull(providers, row6);
}
Also used : DecoderTestColumnHandle(com.facebook.presto.decoder.DecoderTestColumnHandle) FieldValueProvider(com.facebook.presto.decoder.FieldValueProvider) DecoderColumnHandle(com.facebook.presto.decoder.DecoderColumnHandle) HashSet(java.util.HashSet) 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