use of com.facebook.presto.decoder.DecoderTestColumnHandle in project presto by prestodb.
the class TestJsonDecoder method testNonExistent.
@Test
public void testNonExistent() {
byte[] json = "{}".getBytes(StandardCharsets.UTF_8);
DecoderTestColumnHandle column1 = new DecoderTestColumnHandle(0, "column1", createVarcharType(100), "very/deep/varchar", null, null, false, false, false);
DecoderTestColumnHandle column2 = new DecoderTestColumnHandle(1, "column2", BIGINT, "no_bigint", null, null, false, false, false);
DecoderTestColumnHandle column3 = new DecoderTestColumnHandle(2, "column3", DOUBLE, "double/is_missing", null, null, false, false, false);
DecoderTestColumnHandle column4 = new DecoderTestColumnHandle(3, "column4", BOOLEAN, "hello", null, null, false, false, false);
Set<DecoderColumnHandle> columns = ImmutableSet.of(column1, column2, column3, column4);
RowDecoder rowDecoder = DECODER_FACTORY.create(emptyMap(), columns);
Map<DecoderColumnHandle, FieldValueProvider> decodedRow = rowDecoder.decodeRow(json, null).orElseThrow(AssertionError::new);
assertEquals(decodedRow.size(), columns.size());
checkIsNull(decodedRow, column1);
checkIsNull(decodedRow, column2);
checkIsNull(decodedRow, column3);
checkIsNull(decodedRow, column4);
}
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());
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);
Set<DecoderColumnHandle> columns = ImmutableSet.of(row01, row02, row03, row04, row11, row12, row13, row14, row21, row22, row23, row24, row31, row32, row33, row34);
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, row01, 127);
checkValue(decodedRow, row02, false);
checkValue(decodedRow, row03, 126);
checkValue(decodedRow, row04, true);
checkValue(decodedRow, row11, 125);
checkValue(decodedRow, row12, false);
checkValue(decodedRow, row13, 124);
checkValue(decodedRow, row14, true);
checkValue(decodedRow, row21, 123);
checkValue(decodedRow, row22, false);
checkValue(decodedRow, row23, 122);
checkValue(decodedRow, row24, true);
checkValue(decodedRow, row31, 121);
checkValue(decodedRow, row32, false);
checkValue(decodedRow, row33, 120);
checkValue(decodedRow, row34, true);
}
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);
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);
Set<DecoderColumnHandle> columns = ImmutableSet.of(row1, row2, row3, row4);
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, str);
checkValue(decodedRow, row2, str);
// these only work for single byte encodings...
checkValue(decodedRow, row3, str.substring(0, 4));
checkValue(decodedRow, row4, str.substring(5, 8));
}
use of com.facebook.presto.decoder.DecoderTestColumnHandle in project presto by prestodb.
the class TestRawDecoder method testFloatStuff.
@SuppressWarnings("NumericCastThatLosesPrecision")
@Test
public void testFloatStuff() {
ByteBuffer buf = ByteBuffer.allocate(100);
buf.putDouble(Math.PI);
buf.putFloat((float) Math.E);
buf.putDouble(Math.E);
byte[] row = new byte[buf.position()];
System.arraycopy(buf.array(), 0, row, 0, buf.position());
DecoderTestColumnHandle row1 = new DecoderTestColumnHandle(0, "row1", DOUBLE, null, "DOUBLE", null, false, false, false);
DecoderTestColumnHandle row2 = new DecoderTestColumnHandle(1, "row2", DOUBLE, "8", "FLOAT", null, false, false, false);
Set<DecoderColumnHandle> columns = ImmutableSet.of(row1, row2);
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, Math.PI);
checkValue(decodedRow, row2, Math.E);
}
use of com.facebook.presto.decoder.DecoderTestColumnHandle in project presto by prestodb.
the class TestAvroDecoder method testDoubleDecodedAsDouble.
@Test
public void testDoubleDecodedAsDouble() throws Exception {
DecoderTestColumnHandle row = new DecoderTestColumnHandle(0, "row", DOUBLE, "double_field", null, null, false, false, false);
Map<DecoderColumnHandle, FieldValueProvider> decodedRow = buildAndDecodeColumn(row, "double_field", "\"double\"", 56.898);
checkValue(decodedRow, row, 56.898);
}
Aggregations