Search in sources :

Example 1 with FieldValueProvider

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

the class TestRawDecoder method testSimple.

@Test
public void testSimple() {
    ByteBuffer buf = ByteBuffer.allocate(100);
    // 0 - 7
    buf.putLong(4815162342L);
    // 8 - 11
    buf.putInt(12345678);
    // 12 - 13
    buf.putShort((short) 4567);
    // 14
    buf.put((byte) 123);
    // 15+
    buf.put("Ich bin zwei Oeltanks".getBytes(StandardCharsets.UTF_8));
    byte[] row = new byte[buf.position()];
    System.arraycopy(buf.array(), 0, row, 0, buf.position());
    RawRowDecoder rowDecoder = new RawRowDecoder();
    DecoderTestColumnHandle row1 = new DecoderTestColumnHandle("", 0, "row1", BigintType.BIGINT, "0", "LONG", null, false, false, false);
    DecoderTestColumnHandle row2 = new DecoderTestColumnHandle("", 1, "row2", BigintType.BIGINT, "8", "INT", null, false, false, false);
    DecoderTestColumnHandle row3 = new DecoderTestColumnHandle("", 2, "row3", BigintType.BIGINT, "12", "SHORT", null, false, false, false);
    DecoderTestColumnHandle row4 = new DecoderTestColumnHandle("", 3, "row4", BigintType.BIGINT, "14", "BYTE", null, false, false, false);
    DecoderTestColumnHandle row5 = new DecoderTestColumnHandle("", 4, "row5", createVarcharType(10), "15", null, null, false, false, false);
    List<DecoderColumnHandle> columns = ImmutableList.of(row1, row2, row3, row4, row5);
    Set<FieldValueProvider> providers = new HashSet<>();
    boolean corrupt = rowDecoder.decodeRow(row, null, providers, columns, buildMap(columns));
    assertFalse(corrupt);
    assertEquals(providers.size(), columns.size());
    checkValue(providers, row1, 4815162342L);
    checkValue(providers, row2, 12345678);
    checkValue(providers, row3, 4567);
    checkValue(providers, row4, 123);
    checkValue(providers, row5, "Ich bin zw");
}
Also used : DecoderTestColumnHandle(com.facebook.presto.decoder.DecoderTestColumnHandle) FieldValueProvider(com.facebook.presto.decoder.FieldValueProvider) DecoderColumnHandle(com.facebook.presto.decoder.DecoderColumnHandle) ByteBuffer(java.nio.ByteBuffer) HashSet(java.util.HashSet) Test(org.testng.annotations.Test)

Example 2 with FieldValueProvider

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

the class TestRawDecoder method testEmptyRecord.

@Test
public void testEmptyRecord() {
    RawRowDecoder rowDecoder = new RawRowDecoder();
    byte[] emptyRow = new byte[0];
    DecoderTestColumnHandle column = new DecoderTestColumnHandle("", 0, "row1", BigintType.BIGINT, null, "LONG", null, false, false, false);
    List<DecoderColumnHandle> columns = ImmutableList.of(column);
    Set<FieldValueProvider> providers = new HashSet<>();
    boolean corrupt = rowDecoder.decodeRow(emptyRow, null, providers, columns, buildMap(columns));
    assertFalse(corrupt);
    checkIsNull(providers, column);
}
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 3 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, long value) {
    FieldValueProvider provider = findValueProvider(providers, handle);
    assertNotNull(provider);
    assertEquals(provider.getLong(), value);
}
Also used : FieldValueProvider(com.facebook.presto.decoder.FieldValueProvider)

Example 4 with FieldValueProvider

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

the class TestCsvDecoder method testNulls.

@Test
public void testNulls() {
    String csv = ",,,";
    CsvRowDecoder rowDecoder = new CsvRowDecoder();
    DecoderTestColumnHandle row1 = new DecoderTestColumnHandle("", 0, "row1", createVarcharType(10), "0", null, null, false, false, false);
    DecoderTestColumnHandle row2 = new DecoderTestColumnHandle("", 1, "row2", BigintType.BIGINT, "1", null, null, false, false, false);
    DecoderTestColumnHandle row3 = new DecoderTestColumnHandle("", 2, "row3", DoubleType.DOUBLE, "2", null, null, false, false, false);
    DecoderTestColumnHandle row4 = new DecoderTestColumnHandle("", 3, "row4", BooleanType.BOOLEAN, "3", null, null, false, false, false);
    List<DecoderColumnHandle> columns = ImmutableList.of(row1, row2, row3, row4);
    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, "");
    checkValue(providers, row2, 0);
    checkValue(providers, row3, 0.0d);
    checkValue(providers, row4, 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 5 with FieldValueProvider

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

the class TestJsonDecoder method testStringNumber.

@Test
public void testStringNumber() throws Exception {
    byte[] json = "{\"a_number\":481516,\"a_string\":\"2342\"}".getBytes(StandardCharsets.UTF_8);
    JsonRowDecoder rowDecoder = new JsonRowDecoder(PROVIDER.get());
    DecoderTestColumnHandle row1 = new DecoderTestColumnHandle("", 0, "row1", createVarcharType(100), "a_number", null, null, false, false, false);
    DecoderTestColumnHandle row2 = new DecoderTestColumnHandle("", 1, "row2", BigintType.BIGINT, "a_number", null, null, false, false, false);
    DecoderTestColumnHandle row3 = new DecoderTestColumnHandle("", 2, "row3", createVarcharType(100), "a_string", null, null, false, false, false);
    DecoderTestColumnHandle row4 = new DecoderTestColumnHandle("", 3, "row4", BigintType.BIGINT, "a_string", null, null, false, false, false);
    List<DecoderColumnHandle> columns = ImmutableList.of(row1, row2, row3, row4);
    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, "481516");
    checkValue(providers, row2, 481516);
    checkValue(providers, row3, "2342");
    checkValue(providers, row4, 2342);
}
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