Search in sources :

Example 6 with FieldValueProvider

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

the class TestJsonDecoder method testSimple.

@Test
public void testSimple() throws Exception {
    byte[] json = ByteStreams.toByteArray(TestJsonDecoder.class.getResourceAsStream("/decoder/json/message.json"));
    JsonRowDecoder rowDecoder = new JsonRowDecoder(PROVIDER.get());
    DecoderTestColumnHandle row1 = new DecoderTestColumnHandle("", 0, "row1", createVarcharType(100), "source", null, null, false, false, false);
    DecoderTestColumnHandle row2 = new DecoderTestColumnHandle("", 1, "row2", createVarcharType(10), "user/screen_name", null, null, false, false, false);
    DecoderTestColumnHandle row3 = new DecoderTestColumnHandle("", 2, "row3", BigintType.BIGINT, "id", null, null, false, false, false);
    DecoderTestColumnHandle row4 = new DecoderTestColumnHandle("", 3, "row4", BigintType.BIGINT, "user/statuses_count", null, null, false, false, false);
    DecoderTestColumnHandle row5 = new DecoderTestColumnHandle("", 4, "row5", BooleanType.BOOLEAN, "user/geo_enabled", null, null, false, false, false);
    List<DecoderColumnHandle> columns = ImmutableList.of(row1, row2, row3, row4, row5);
    Set<FieldValueProvider> providers = new HashSet<>();
    boolean corrupt = rowDecoder.decodeRow(json, null, providers, columns, buildMap(columns));
    assertFalse(corrupt);
    assertEquals(providers.size(), columns.size());
    checkValue(providers, row1, "<a href=\"http://twitterfeed.com\" rel=\"nofollow\">twitterfeed</a>");
    checkValue(providers, row2, "EKentuckyN");
    checkValue(providers, row3, 493857959588286460L);
    checkValue(providers, row4, 7630);
    checkValue(providers, row5, true);
}
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 7 with FieldValueProvider

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

the class TestMillisecondsSinceEpochJsonFieldDecoder 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", MillisecondsSinceEpochJsonFieldDecoder.NAME, null, false, false, false);
    DecoderTestColumnHandle row4 = new DecoderTestColumnHandle("", 3, "row4", BigintType.BIGINT, "a_string", MillisecondsSinceEpochJsonFieldDecoder.NAME, null, false, false, false);
    DecoderTestColumnHandle row5 = new DecoderTestColumnHandle("", 4, "row5", createVarcharType(100), "a_number", MillisecondsSinceEpochJsonFieldDecoder.NAME, null, false, false, false);
    DecoderTestColumnHandle row6 = new DecoderTestColumnHandle("", 5, "row6", createVarcharType(100), "a_string", MillisecondsSinceEpochJsonFieldDecoder.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 8 with FieldValueProvider

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

the class TestMillisecondsSinceEpochJsonFieldDecoder method testBasicFormatting.

@Test
public void testBasicFormatting() throws Exception {
    long now = System.currentTimeMillis();
    String nowString = MillisecondsSinceEpochJsonFieldDecoder.FORMATTER.print(now);
    byte[] json = format("{\"a_number\":%d,\"a_string\":\"%d\"}", now, now).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", MillisecondsSinceEpochJsonFieldDecoder.NAME, null, false, false, false);
    DecoderTestColumnHandle row4 = new DecoderTestColumnHandle("", 3, "row4", BigintType.BIGINT, "a_string", MillisecondsSinceEpochJsonFieldDecoder.NAME, null, false, false, false);
    DecoderTestColumnHandle row5 = new DecoderTestColumnHandle("", 4, "row5", createVarcharType(100), "a_number", MillisecondsSinceEpochJsonFieldDecoder.NAME, null, false, false, false);
    DecoderTestColumnHandle row6 = new DecoderTestColumnHandle("", 5, "row6", createVarcharType(100), "a_string", MillisecondsSinceEpochJsonFieldDecoder.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, Long.toString(now));
    // number parsed as number --> return as time stamp (millis)
    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, nowString);
    // string parsed as string --> parse text, convert to timestamp, turn into string
    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 9 with FieldValueProvider

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

the class TestRFC2822JsonFieldDecoder 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", 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
    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 10 with FieldValueProvider

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

the class TestSecondsSinceEpochJsonFieldDecoder method testBasicFormatting.

@Test
public void testBasicFormatting() throws Exception {
    // SecondsSinceEpoch is second granularity
    long now = System.currentTimeMillis() / 1000;
    String nowString = FORMATTER.print(now * 1000);
    byte[] json = format("{\"a_number\":%d,\"a_string\":\"%d\"}", now, now).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
    checkValue(providers, row1, now);
    checkValue(providers, row2, Long.toString(now));
    // number parsed as number --> return as time stamp (millis)
    checkValue(providers, row3, now * 1000);
    // string parsed as number --> parse text, convert to timestamp
    checkValue(providers, row4, now * 1000);
    // number parsed as string --> parse text, convert to timestamp, turn into string
    checkValue(providers, row5, nowString);
    // string parsed as string --> parse text, convert to timestamp, turn into string
    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)

Aggregations

FieldValueProvider (com.facebook.presto.decoder.FieldValueProvider)25 HashSet (java.util.HashSet)20 DecoderColumnHandle (com.facebook.presto.decoder.DecoderColumnHandle)19 DecoderTestColumnHandle (com.facebook.presto.decoder.DecoderTestColumnHandle)19 Test (org.testng.annotations.Test)19 ByteBuffer (java.nio.ByteBuffer)3