Search in sources :

Example 26 with DecoderTestColumnHandle

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

the class TestCustomDateTimeJsonFieldDecoder method testInvalidFormatHint.

@Test
public void testInvalidFormatHint() {
    DecoderTestColumnHandle columnHandle = new DecoderTestColumnHandle(0, "some_column", TIMESTAMP, "mappedField", "custom-date-time", "XXMM/yyyy/dd H:m:sXX", false, false, false);
    assertThatThrownBy(() -> new JsonRowDecoderFactory(new JsonObjectMapperProvider().get()).create(emptyMap(), ImmutableSet.of(columnHandle))).isInstanceOf(PrestoException.class).hasMessageMatching("invalid joda pattern 'XXMM/yyyy/dd H:m:sXX' passed as format hint for column 'some_column'");
}
Also used : DecoderTestColumnHandle(com.facebook.presto.decoder.DecoderTestColumnHandle) JsonObjectMapperProvider(com.facebook.airlift.json.JsonObjectMapperProvider) PrestoException(com.facebook.presto.spi.PrestoException) Test(org.testng.annotations.Test)

Example 27 with DecoderTestColumnHandle

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

the class TestCsvDecoder method testNulls.

@Test
public void testNulls() {
    String csv = ",,,";
    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);
    Set<DecoderColumnHandle> columns = ImmutableSet.of(row1, row2, row3, row4);
    RowDecoder rowDecoder = DECODER_FACTORY.create(emptyMap(), columns);
    Map<DecoderColumnHandle, FieldValueProvider> decodedRow = rowDecoder.decodeRow(csv.getBytes(StandardCharsets.UTF_8), null).orElseThrow(AssertionError::new);
    assertEquals(decodedRow.size(), columns.size());
    checkIsNull(decodedRow, row1);
    checkIsNull(decodedRow, row2);
    checkIsNull(decodedRow, row3);
    checkIsNull(decodedRow, row4);
}
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 28 with DecoderTestColumnHandle

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

the class TestCsvDecoder method testLessTokensThanColumns.

@Test
public void testLessTokensThanColumns() {
    String csv = "ala,10";
    DecoderTestColumnHandle column1 = new DecoderTestColumnHandle(0, "column1", createVarcharType(10), "0", null, null, false, false, false);
    DecoderTestColumnHandle column2 = new DecoderTestColumnHandle(1, "column2", BigintType.BIGINT, "1", null, null, false, false, false);
    DecoderTestColumnHandle column3 = new DecoderTestColumnHandle(2, "column3", createVarcharType(10), "2", null, null, false, false, false);
    DecoderTestColumnHandle column4 = new DecoderTestColumnHandle(0, "column4", BigintType.BIGINT, "3", null, null, false, false, false);
    DecoderTestColumnHandle column5 = new DecoderTestColumnHandle(0, "column5", DoubleType.DOUBLE, "4", null, null, false, false, false);
    DecoderTestColumnHandle column6 = new DecoderTestColumnHandle(0, "column6", BooleanType.BOOLEAN, "5", null, null, false, false, false);
    Set<DecoderColumnHandle> columns = ImmutableSet.of(column1, column2, column3, column4, column5, column6);
    RowDecoder rowDecoder = DECODER_FACTORY.create(emptyMap(), columns);
    Map<DecoderColumnHandle, FieldValueProvider> decodedRow = rowDecoder.decodeRow(csv.getBytes(StandardCharsets.UTF_8), null).orElseThrow(AssertionError::new);
    assertEquals(decodedRow.size(), columns.size());
    checkValue(decodedRow, column1, "ala");
    checkValue(decodedRow, column2, 10);
    checkIsNull(decodedRow, column3);
    checkIsNull(decodedRow, column4);
    checkIsNull(decodedRow, column5);
    checkIsNull(decodedRow, column6);
}
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 29 with DecoderTestColumnHandle

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

the class TestCsvDecoder method fieldValueDecoderFor.

private FieldValueProvider fieldValueDecoderFor(BigintType type, String csv) {
    DecoderTestColumnHandle column = new DecoderTestColumnHandle(0, "column", type, "0", null, null, false, false, false);
    Set<DecoderColumnHandle> columns = ImmutableSet.of(column);
    RowDecoder rowDecoder = DECODER_FACTORY.create(emptyMap(), columns);
    Map<DecoderColumnHandle, FieldValueProvider> decodedRow = rowDecoder.decodeRow(csv.getBytes(StandardCharsets.UTF_8), null).orElseThrow(AssertionError::new);
    return decodedRow.get(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)

Example 30 with DecoderTestColumnHandle

use of com.facebook.presto.decoder.DecoderTestColumnHandle 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());
    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);
    Set<DecoderColumnHandle> columns = ImmutableSet.of(row1, row2, row3, row4, row5);
    RowDecoder rowDecoder = DECODER_FACTORY.create(emptyMap(), columns);
    Map<DecoderColumnHandle, FieldValueProvider> decodedRow = rowDecoder.decodeRow(row, null).orElseThrow(AssertionError::new);
    assertEquals(decodedRow.size(), columns.size());
    checkValue(decodedRow, row1, 4815162342L);
    checkValue(decodedRow, row2, 12345678);
    checkValue(decodedRow, row3, 4567);
    checkValue(decodedRow, row4, 123);
    checkValue(decodedRow, row5, "Ich bin zw");
}
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) ByteBuffer(java.nio.ByteBuffer) 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