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);
}
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);
}
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");
}
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);
}
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);
}
Aggregations