Search in sources :

Example 36 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\"";
    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);
    Set<DecoderColumnHandle> columns = ImmutableSet.of(row1, row2, row3, row4, row5, row6, row7, row8);
    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, row1, true);
    checkValue(decodedRow, row2, false);
    checkValue(decodedRow, row3, false);
    checkValue(decodedRow, row4, false);
    checkValue(decodedRow, row5, false);
    checkValue(decodedRow, row6, false);
    checkValue(decodedRow, row7, true);
    checkValue(decodedRow, row8, false);
}
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 37 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";
    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);
    Set<DecoderColumnHandle> columns = ImmutableSet.of(row1, row2, row3, row4, row5, row6, row7);
    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, row1, "ro");
    checkValue(decodedRow, row2, "row2");
    checkValue(decodedRow, row3, "row3");
    checkValue(decodedRow, row4, 100);
    checkValue(decodedRow, row5, 200);
    checkValue(decodedRow, row6, 300);
    checkValue(decodedRow, row7, 4.5d);
}
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 38 with DecoderTestColumnHandle

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

the class TestAvroDecoder method testStringDecodedAsVarchar.

@Test
public void testStringDecodedAsVarchar() throws Exception {
    DecoderTestColumnHandle row = new DecoderTestColumnHandle(0, "row", VARCHAR, "string_field", null, null, false, false, false);
    Map<DecoderColumnHandle, FieldValueProvider> decodedRow = buildAndDecodeColumn(row, "string_field", "\"string\"", "Mon Jul 28 20:38:07 +0000 2014");
    checkValue(decodedRow, row, "Mon Jul 28 20:38:07 +0000 2014");
}
Also used : DecoderTestColumnHandle(com.facebook.presto.decoder.DecoderTestColumnHandle) FieldValueProvider(com.facebook.presto.decoder.FieldValueProvider) DecoderColumnHandle(com.facebook.presto.decoder.DecoderColumnHandle) Test(org.testng.annotations.Test)

Example 39 with DecoderTestColumnHandle

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

the class TestAvroDecoder method testNonExistentFieldsAreNull.

@Test
public void testNonExistentFieldsAreNull() throws Exception {
    DecoderTestColumnHandle row1 = new DecoderTestColumnHandle(0, "row1", createVarcharType(100), "very/deep/varchar", null, null, false, false, false);
    DecoderTestColumnHandle row2 = new DecoderTestColumnHandle(1, "row2", BIGINT, "no_bigint", null, null, false, false, false);
    DecoderTestColumnHandle row3 = new DecoderTestColumnHandle(2, "row3", DOUBLE, "double_record/is_missing", null, null, false, false, false);
    DecoderTestColumnHandle row4 = new DecoderTestColumnHandle(3, "row4", BOOLEAN, "hello", null, null, false, false, false);
    Map<DecoderColumnHandle, FieldValueProvider> decodedRow1 = buildAndDecodeColumn(row1, "dummy", "\"long\"", 0L);
    Map<DecoderColumnHandle, FieldValueProvider> decodedRow2 = buildAndDecodeColumn(row2, "dummy", "\"long\"", 0L);
    Map<DecoderColumnHandle, FieldValueProvider> decodedRow3 = buildAndDecodeColumn(row3, "dummy", "\"long\"", 0L);
    Map<DecoderColumnHandle, FieldValueProvider> decodedRow4 = buildAndDecodeColumn(row4, "dummy", "\"long\"", 0L);
    checkIsNull(decodedRow1, row1);
    checkIsNull(decodedRow2, row2);
    checkIsNull(decodedRow3, row3);
    checkIsNull(decodedRow4, row4);
}
Also used : DecoderTestColumnHandle(com.facebook.presto.decoder.DecoderTestColumnHandle) FieldValueProvider(com.facebook.presto.decoder.FieldValueProvider) DecoderColumnHandle(com.facebook.presto.decoder.DecoderColumnHandle) Test(org.testng.annotations.Test)

Example 40 with DecoderTestColumnHandle

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

the class JsonFieldDecoderTester method decode.

private FieldValueProvider decode(Optional<String> jsonValue, Type type) {
    String jsonField = "value";
    String json = jsonValue.map(value -> format("{\"%s\":%s}", jsonField, value)).orElse("{}");
    DecoderTestColumnHandle columnHandle = new DecoderTestColumnHandle(0, "some_column", type, jsonField, dataFormat.orElse(null), formatHint.orElse(null), false, false, false);
    RowDecoder rowDecoder = DECODER_FACTORY.create(emptyMap(), ImmutableSet.of(columnHandle));
    Map<DecoderColumnHandle, FieldValueProvider> decodedRow = rowDecoder.decodeRow(json.getBytes(UTF_8), null).orElseThrow(AssertionError::new);
    assertTrue(decodedRow.containsKey(columnHandle), format("column '%s' not found in decoded row", columnHandle.getName()));
    return decodedRow.get(columnHandle);
}
Also used : Collections.emptyMap(java.util.Collections.emptyMap) ImmutableSet(com.google.common.collect.ImmutableSet) FieldValueProvider(com.facebook.presto.decoder.FieldValueProvider) Slice(io.airlift.slice.Slice) UTF_8(java.nio.charset.StandardCharsets.UTF_8) RowDecoder(com.facebook.presto.decoder.RowDecoder) Assert.assertEquals(org.testng.Assert.assertEquals) PrestoException(com.facebook.presto.spi.PrestoException) Preconditions.checkArgument(org.assertj.core.util.Preconditions.checkArgument) String.format(java.lang.String.format) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) JsonObjectMapperProvider(com.facebook.airlift.json.JsonObjectMapperProvider) Map(java.util.Map) Objects.requireNonNull(java.util.Objects.requireNonNull) Optional(java.util.Optional) Assert.assertTrue(org.testng.Assert.assertTrue) DecoderColumnHandle(com.facebook.presto.decoder.DecoderColumnHandle) DecoderTestColumnHandle(com.facebook.presto.decoder.DecoderTestColumnHandle) Assert.assertFalse(org.testng.Assert.assertFalse) Type(com.facebook.presto.common.type.Type) DecoderTestColumnHandle(com.facebook.presto.decoder.DecoderTestColumnHandle) FieldValueProvider(com.facebook.presto.decoder.FieldValueProvider) RowDecoder(com.facebook.presto.decoder.RowDecoder) DecoderColumnHandle(com.facebook.presto.decoder.DecoderColumnHandle)

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