use of io.prestosql.decoder.DecoderColumnHandle in project pulsar by apache.
the class TestJsonDecoder method testPrimitiveType.
@Test
public void testPrimitiveType() {
DecoderTestMessage message = new DecoderTestMessage();
message.stringField = "message_1";
message.intField = 22;
message.floatField = 2.2f;
message.doubleField = 22.20D;
message.booleanField = true;
message.longField = 222L;
message.timestampField = System.currentTimeMillis();
message.enumField = DecoderTestMessage.TestEnum.TEST_ENUM_2;
LocalTime now = LocalTime.now(ZoneId.systemDefault());
message.timeField = now.toSecondOfDay() * 1000;
LocalDate localDate = LocalDate.now();
LocalDate epoch = LocalDate.ofEpochDay(0);
message.dateField = Math.toIntExact(ChronoUnit.DAYS.between(epoch, localDate));
ByteBuf payload = io.netty.buffer.Unpooled.copiedBuffer(schema.encode(message));
Map<DecoderColumnHandle, FieldValueProvider> decodedRow = pulsarRowDecoder.decodeRow(payload).get();
PulsarColumnHandle stringFieldColumnHandle = new PulsarColumnHandle(getPulsarConnectorId().toString(), "stringField", VARCHAR, false, false, "stringField", null, null, PulsarColumnHandle.HandleKeyValueType.NONE);
checkValue(decodedRow, stringFieldColumnHandle, message.stringField);
PulsarColumnHandle intFieldColumnHandle = new PulsarColumnHandle(getPulsarConnectorId().toString(), "intField", INTEGER, false, false, "intField", null, null, PulsarColumnHandle.HandleKeyValueType.NONE);
checkValue(decodedRow, intFieldColumnHandle, message.intField);
PulsarColumnHandle floatFieldColumnHandle = new PulsarColumnHandle(getPulsarConnectorId().toString(), "floatField", REAL, false, false, "floatField", null, null, PulsarColumnHandle.HandleKeyValueType.NONE);
checkValue(decodedRow, floatFieldColumnHandle, floatToIntBits(message.floatField));
PulsarColumnHandle doubleFieldColumnHandle = new PulsarColumnHandle(getPulsarConnectorId().toString(), "doubleField", DOUBLE, false, false, "doubleField", null, null, PulsarColumnHandle.HandleKeyValueType.NONE);
checkValue(decodedRow, doubleFieldColumnHandle, message.doubleField);
PulsarColumnHandle booleanFieldColumnHandle = new PulsarColumnHandle(getPulsarConnectorId().toString(), "booleanField", BOOLEAN, false, false, "booleanField", null, null, PulsarColumnHandle.HandleKeyValueType.NONE);
checkValue(decodedRow, booleanFieldColumnHandle, message.booleanField);
PulsarColumnHandle longFieldColumnHandle = new PulsarColumnHandle(getPulsarConnectorId().toString(), "longField", BIGINT, false, false, "longField", null, null, PulsarColumnHandle.HandleKeyValueType.NONE);
checkValue(decodedRow, longFieldColumnHandle, message.longField);
PulsarColumnHandle enumFieldColumnHandle = new PulsarColumnHandle(getPulsarConnectorId().toString(), "enumField", VARCHAR, false, false, "enumField", null, null, PulsarColumnHandle.HandleKeyValueType.NONE);
checkValue(decodedRow, enumFieldColumnHandle, message.enumField.toString());
}
use of io.prestosql.decoder.DecoderColumnHandle in project hetu-core by openlookeng.
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);
}
use of io.prestosql.decoder.DecoderColumnHandle in project hetu-core by openlookeng.
the class TestJsonDecoder method testStringNumber.
@Test
public void testStringNumber() {
byte[] json = "{\"a_number\":481516,\"a_string\":\"2342\"}".getBytes(StandardCharsets.UTF_8);
DecoderTestColumnHandle column1 = new DecoderTestColumnHandle(0, "column1", createVarcharType(100), "a_number", null, null, false, false, false);
DecoderTestColumnHandle column2 = new DecoderTestColumnHandle(1, "column2", BIGINT, "a_number", null, null, false, false, false);
DecoderTestColumnHandle column3 = new DecoderTestColumnHandle(2, "column3", createVarcharType(100), "a_string", null, null, false, false, false);
DecoderTestColumnHandle column4 = new DecoderTestColumnHandle(3, "column4", BIGINT, "a_string", null, null, false, false, false);
Set<DecoderColumnHandle> columns = ImmutableSet.of(column1, column2, column3, column4);
RowDecoder rowDecoder = DECODER_FACTORY.create(emptyMap(), columns);
Optional<Map<DecoderColumnHandle, FieldValueProvider>> decodedRow = rowDecoder.decodeRow(json, null);
assertTrue(decodedRow.isPresent());
assertEquals(decodedRow.get().size(), columns.size());
checkValue(decodedRow.get(), column1, "481516");
checkValue(decodedRow.get(), column2, 481516);
checkValue(decodedRow.get(), column3, "2342");
checkValue(decodedRow.get(), column4, 2342);
}
use of io.prestosql.decoder.DecoderColumnHandle in project hetu-core by openlookeng.
the class TestJsonDecoder method testSimple.
@Test
public void testSimple() throws Exception {
byte[] json = ByteStreams.toByteArray(TestJsonDecoder.class.getResourceAsStream("/decoder/json/message.json"));
DecoderTestColumnHandle column1 = new DecoderTestColumnHandle(0, "column1", createVarcharType(100), "source", null, null, false, false, false);
DecoderTestColumnHandle column2 = new DecoderTestColumnHandle(1, "column2", createVarcharType(10), "user/screen_name", null, null, false, false, false);
DecoderTestColumnHandle column3 = new DecoderTestColumnHandle(2, "column3", BIGINT, "id", null, null, false, false, false);
DecoderTestColumnHandle column4 = new DecoderTestColumnHandle(3, "column4", BIGINT, "user/statuses_count", null, null, false, false, false);
DecoderTestColumnHandle column5 = new DecoderTestColumnHandle(4, "column5", BOOLEAN, "user/geo_enabled", null, null, false, false, false);
Set<DecoderColumnHandle> columns = ImmutableSet.of(column1, column2, column3, column4, column5);
RowDecoder rowDecoder = DECODER_FACTORY.create(emptyMap(), columns);
Map<DecoderColumnHandle, FieldValueProvider> decodedRow = rowDecoder.decodeRow(json, null).orElseThrow(AssertionError::new);
assertEquals(decodedRow.size(), columns.size());
checkValue(decodedRow, column1, "<a href=\"http://twitterfeed.com\" rel=\"nofollow\">twitterfeed</a>");
checkValue(decodedRow, column2, "EKentuckyN");
checkValue(decodedRow, column3, 493857959588286460L);
checkValue(decodedRow, column4, 7630);
checkValue(decodedRow, column5, true);
}
use of io.prestosql.decoder.DecoderColumnHandle in project hetu-core by openlookeng.
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);
}
Aggregations