Search in sources :

Example 11 with DecoderTestColumnHandle

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

the class TestRawDecoder method testBooleanStuff.

@Test
public void testBooleanStuff() {
    ByteBuffer buf = ByteBuffer.allocate(100);
    // offset 0
    buf.put((byte) 127);
    // offset 1
    buf.putLong(0);
    // offset 9
    buf.put((byte) 126);
    // offset 10
    buf.putLong(1);
    // offset 18
    buf.put((byte) 125);
    // offset 19
    buf.putInt(0);
    // offset 23
    buf.put((byte) 124);
    // offset 24
    buf.putInt(1);
    // offset 28
    buf.put((byte) 123);
    // offset 29
    buf.putShort((short) 0);
    // offset 31
    buf.put((byte) 122);
    // offset 32
    buf.putShort((short) 1);
    // offset 34
    buf.put((byte) 121);
    // offset 35
    buf.put((byte) 0);
    // offset 36
    buf.put((byte) 120);
    // offset 37
    buf.put((byte) 1);
    byte[] row = new byte[buf.position()];
    System.arraycopy(buf.array(), 0, row, 0, buf.position());
    RawRowDecoder rowDecoder = new RawRowDecoder();
    DecoderTestColumnHandle row01 = new DecoderTestColumnHandle("", 0, "row01", BigintType.BIGINT, "0", "BYTE", null, false, false, false);
    DecoderTestColumnHandle row02 = new DecoderTestColumnHandle("", 1, "row02", BooleanType.BOOLEAN, "1", "LONG", null, false, false, false);
    DecoderTestColumnHandle row03 = new DecoderTestColumnHandle("", 2, "row03", BigintType.BIGINT, "9", "BYTE", null, false, false, false);
    DecoderTestColumnHandle row04 = new DecoderTestColumnHandle("", 3, "row04", BooleanType.BOOLEAN, "10", "LONG", null, false, false, false);
    DecoderTestColumnHandle row11 = new DecoderTestColumnHandle("", 4, "row11", BigintType.BIGINT, "18", "BYTE", null, false, false, false);
    DecoderTestColumnHandle row12 = new DecoderTestColumnHandle("", 5, "row12", BooleanType.BOOLEAN, "19", "INT", null, false, false, false);
    DecoderTestColumnHandle row13 = new DecoderTestColumnHandle("", 6, "row13", BigintType.BIGINT, "23", "BYTE", null, false, false, false);
    DecoderTestColumnHandle row14 = new DecoderTestColumnHandle("", 7, "row14", BooleanType.BOOLEAN, "24", "INT", null, false, false, false);
    DecoderTestColumnHandle row21 = new DecoderTestColumnHandle("", 8, "row21", BigintType.BIGINT, "28", "BYTE", null, false, false, false);
    DecoderTestColumnHandle row22 = new DecoderTestColumnHandle("", 9, "row22", BooleanType.BOOLEAN, "29", "SHORT", null, false, false, false);
    DecoderTestColumnHandle row23 = new DecoderTestColumnHandle("", 10, "row23", BigintType.BIGINT, "31", "BYTE", null, false, false, false);
    DecoderTestColumnHandle row24 = new DecoderTestColumnHandle("", 11, "row24", BooleanType.BOOLEAN, "32", "SHORT", null, false, false, false);
    DecoderTestColumnHandle row31 = new DecoderTestColumnHandle("", 12, "row31", BigintType.BIGINT, "34", "BYTE", null, false, false, false);
    DecoderTestColumnHandle row32 = new DecoderTestColumnHandle("", 13, "row32", BooleanType.BOOLEAN, "35", "BYTE", null, false, false, false);
    DecoderTestColumnHandle row33 = new DecoderTestColumnHandle("", 14, "row33", BigintType.BIGINT, "36", "BYTE", null, false, false, false);
    DecoderTestColumnHandle row34 = new DecoderTestColumnHandle("", 15, "row34", BooleanType.BOOLEAN, "37", "BYTE", null, false, false, false);
    List<DecoderColumnHandle> columns = ImmutableList.of(row01, row02, row03, row04, row11, row12, row13, row14, row21, row22, row23, row24, row31, row32, row33, row34);
    Set<FieldValueProvider> providers = new HashSet<>();
    boolean corrupt = rowDecoder.decodeRow(row, null, providers, columns, buildMap(columns));
    assertFalse(corrupt);
    assertEquals(providers.size(), columns.size());
    checkValue(providers, row01, 127);
    checkValue(providers, row02, false);
    checkValue(providers, row03, 126);
    checkValue(providers, row04, true);
    checkValue(providers, row11, 125);
    checkValue(providers, row12, false);
    checkValue(providers, row13, 124);
    checkValue(providers, row14, true);
    checkValue(providers, row21, 123);
    checkValue(providers, row22, false);
    checkValue(providers, row23, 122);
    checkValue(providers, row24, true);
    checkValue(providers, row31, 121);
    checkValue(providers, row32, false);
    checkValue(providers, row33, 120);
    checkValue(providers, row34, true);
}
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 12 with DecoderTestColumnHandle

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

the class TestRawDecoder method testFixedWithString.

@Test
public void testFixedWithString() {
    String str = "Ich bin zwei Oeltanks";
    byte[] row = str.getBytes(StandardCharsets.UTF_8);
    RawRowDecoder rowDecoder = new RawRowDecoder();
    DecoderTestColumnHandle row1 = new DecoderTestColumnHandle("", 0, "row1", createVarcharType(100), null, null, null, false, false, false);
    DecoderTestColumnHandle row2 = new DecoderTestColumnHandle("", 1, "row2", createVarcharType(100), "0", null, null, false, false, false);
    DecoderTestColumnHandle row3 = new DecoderTestColumnHandle("", 2, "row3", createVarcharType(100), "0:4", null, null, false, false, false);
    DecoderTestColumnHandle row4 = new DecoderTestColumnHandle("", 3, "row4", createVarcharType(100), "5:8", null, null, false, false, false);
    List<DecoderColumnHandle> columns = ImmutableList.of(row1, row2, row3, row4);
    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, str);
    checkValue(providers, row2, str);
    // these only work for single byte encodings...
    checkValue(providers, row3, str.substring(0, 4));
    checkValue(providers, row4, str.substring(5, 8));
}
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 13 with DecoderTestColumnHandle

use of com.facebook.presto.decoder.DecoderTestColumnHandle 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 14 with DecoderTestColumnHandle

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

Aggregations

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