Search in sources :

Example 16 with FieldValueProvider

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

the class DecoderTestUtil method checkIsNull.

public static void checkIsNull(Set<FieldValueProvider> providers, DecoderColumnHandle handle) {
    FieldValueProvider provider = findValueProvider(providers, handle);
    assertNotNull(provider);
    assertTrue(provider.isNull());
}
Also used : FieldValueProvider(com.facebook.presto.decoder.FieldValueProvider)

Example 17 with FieldValueProvider

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

the class DecoderTestUtil method checkValue.

public static void checkValue(Set<FieldValueProvider> providers, DecoderColumnHandle handle, boolean value) {
    FieldValueProvider provider = findValueProvider(providers, handle);
    assertNotNull(provider);
    assertEquals(provider.getBoolean(), value);
}
Also used : FieldValueProvider(com.facebook.presto.decoder.FieldValueProvider)

Example 18 with FieldValueProvider

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

the class TestCsvDecoder method testSimple.

@Test
public void testSimple() {
    String csv = "\"row 1\",row2,\"row3\",100,\"200\",300,4.5";
    CsvRowDecoder rowDecoder = new CsvRowDecoder();
    DecoderTestColumnHandle row1 = new DecoderTestColumnHandle("", 0, "row1", createVarcharType(2), "0", null, null, false, false, false);
    DecoderTestColumnHandle row2 = new DecoderTestColumnHandle("", 1, "row2", createVarcharType(10), "1", null, null, false, false, false);
    DecoderTestColumnHandle row3 = new DecoderTestColumnHandle("", 2, "row3", createVarcharType(10), "2", null, null, false, false, false);
    DecoderTestColumnHandle row4 = new DecoderTestColumnHandle("", 3, "row4", BigintType.BIGINT, "3", null, null, false, false, false);
    DecoderTestColumnHandle row5 = new DecoderTestColumnHandle("", 4, "row5", BigintType.BIGINT, "4", null, null, false, false, false);
    DecoderTestColumnHandle row6 = new DecoderTestColumnHandle("", 5, "row6", BigintType.BIGINT, "5", null, null, false, false, false);
    DecoderTestColumnHandle row7 = new DecoderTestColumnHandle("", 6, "row7", DoubleType.DOUBLE, "6", null, null, false, false, false);
    List<DecoderColumnHandle> columns = ImmutableList.of(row1, row2, row3, row4, row5, row6, row7);
    Set<FieldValueProvider> providers = new HashSet<>();
    boolean corrupt = rowDecoder.decodeRow(csv.getBytes(StandardCharsets.UTF_8), null, providers, columns, buildMap(columns));
    assertFalse(corrupt);
    assertEquals(providers.size(), columns.size());
    checkValue(providers, row1, "ro");
    checkValue(providers, row2, "row2");
    checkValue(providers, row3, "row3");
    checkValue(providers, row4, 100);
    checkValue(providers, row5, 200);
    checkValue(providers, row6, 300);
    checkValue(providers, row7, 4.5d);
}
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 19 with FieldValueProvider

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

the class TestCsvDecoder method testBoolean.

@Test
public void testBoolean() {
    String csv = "True,False,0,1,\"0\",\"1\",\"true\",\"false\"";
    CsvRowDecoder rowDecoder = new CsvRowDecoder();
    DecoderTestColumnHandle row1 = new DecoderTestColumnHandle("", 0, "row1", BooleanType.BOOLEAN, "0", null, null, false, false, false);
    DecoderTestColumnHandle row2 = new DecoderTestColumnHandle("", 1, "row2", BooleanType.BOOLEAN, "1", null, null, false, false, false);
    DecoderTestColumnHandle row3 = new DecoderTestColumnHandle("", 2, "row3", BooleanType.BOOLEAN, "2", null, null, false, false, false);
    DecoderTestColumnHandle row4 = new DecoderTestColumnHandle("", 3, "row4", BooleanType.BOOLEAN, "3", null, null, false, false, false);
    DecoderTestColumnHandle row5 = new DecoderTestColumnHandle("", 4, "row5", BooleanType.BOOLEAN, "4", null, null, false, false, false);
    DecoderTestColumnHandle row6 = new DecoderTestColumnHandle("", 5, "row6", BooleanType.BOOLEAN, "5", null, null, false, false, false);
    DecoderTestColumnHandle row7 = new DecoderTestColumnHandle("", 6, "row7", BooleanType.BOOLEAN, "6", null, null, false, false, false);
    DecoderTestColumnHandle row8 = new DecoderTestColumnHandle("", 7, "row8", BooleanType.BOOLEAN, "7", null, null, false, false, false);
    List<DecoderColumnHandle> columns = ImmutableList.of(row1, row2, row3, row4, row5, row6, row7, row8);
    Set<FieldValueProvider> providers = new HashSet<>();
    boolean corrupt = rowDecoder.decodeRow(csv.getBytes(StandardCharsets.UTF_8), null, providers, columns, buildMap(columns));
    assertFalse(corrupt);
    assertEquals(providers.size(), columns.size());
    checkValue(providers, row1, true);
    checkValue(providers, row2, false);
    checkValue(providers, row3, false);
    checkValue(providers, row4, false);
    checkValue(providers, row5, false);
    checkValue(providers, row6, false);
    checkValue(providers, row7, true);
    checkValue(providers, row8, false);
}
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 20 with FieldValueProvider

use of com.facebook.presto.decoder.FieldValueProvider 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)

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