use of org.apache.pulsar.sql.presto.decoder.DecoderTestMessage in project pulsar by apache.
the class TestAvroDecoder method testRow.
@Test
public void testRow() {
DecoderTestMessage message = new DecoderTestMessage();
message.stringField = "message_2";
DecoderTestMessage.TestRow testRow = new DecoderTestMessage.TestRow();
message.rowField = testRow;
testRow.intField = 22;
testRow.stringField = "message_2_testRow";
DecoderTestMessage.NestedRow nestedRow = new DecoderTestMessage.NestedRow();
nestedRow.longField = 222L;
nestedRow.stringField = "message_2_nestedRow";
testRow.nestedRow = nestedRow;
byte[] bytes = schema.encode(message);
ByteBuf payload = io.netty.buffer.Unpooled.copiedBuffer(bytes);
GenericAvroRecord genericRecord = (GenericAvroRecord) GenericAvroSchema.of(schemaInfo).decode(bytes);
Object fieldValue = genericRecord.getAvroRecord().get("rowField");
Map<DecoderColumnHandle, FieldValueProvider> decodedRow = pulsarRowDecoder.decodeRow(payload).get();
RowType columnType = RowType.from(ImmutableList.<RowType.Field>builder().add(RowType.field("intField", INTEGER)).add(RowType.field("nestedRow", RowType.from(ImmutableList.<RowType.Field>builder().add(RowType.field("longField", BIGINT)).add(RowType.field("stringField", VARCHAR)).build()))).add(RowType.field("stringField", VARCHAR)).build());
PulsarColumnHandle columnHandle = new PulsarColumnHandle(getPulsarConnectorId().toString(), "rowField", columnType, false, false, "rowField", null, null, PulsarColumnHandle.HandleKeyValueType.NONE);
checkRowValues(getBlock(decodedRow, columnHandle), columnHandle.getType(), fieldValue);
}
use of org.apache.pulsar.sql.presto.decoder.DecoderTestMessage in project pulsar by apache.
the class TestAvroDecoder method testMap.
@Test
public void testMap() {
DecoderTestMessage message = new DecoderTestMessage();
message.mapField = new HashMap<String, Long>() {
{
put("key1", 2L);
put("key2", 22L);
}
};
byte[] bytes = schema.encode(message);
ByteBuf payload = io.netty.buffer.Unpooled.copiedBuffer(bytes);
GenericAvroRecord genericRecord = (GenericAvroRecord) GenericAvroSchema.of(schemaInfo).decode(bytes);
Object fieldValue = genericRecord.getAvroRecord().get("mapField");
Map<DecoderColumnHandle, FieldValueProvider> decodedRow = pulsarRowDecoder.decodeRow(payload).get();
Type columnType = decoderFactory.getTypeManager().getParameterizedType(StandardTypes.MAP, ImmutableList.of(TypeSignatureParameter.typeParameter(VarcharType.VARCHAR.getTypeSignature()), TypeSignatureParameter.typeParameter(BigintType.BIGINT.getTypeSignature())));
PulsarColumnHandle columnHandle = new PulsarColumnHandle(getPulsarConnectorId().toString(), "mapField", columnType, false, false, "mapField", null, null, PulsarColumnHandle.HandleKeyValueType.NONE);
checkMapValues(getBlock(decodedRow, columnHandle), columnHandle.getType(), fieldValue);
}
use of org.apache.pulsar.sql.presto.decoder.DecoderTestMessage in project pulsar by apache.
the class TestAvroDecoder method testArray.
@Test
public void testArray() {
DecoderTestMessage message = new DecoderTestMessage();
message.arrayField = Arrays.asList("message_1", "message_2", "message_3");
byte[] bytes = schema.encode(message);
ByteBuf payload = io.netty.buffer.Unpooled.copiedBuffer(bytes);
GenericAvroRecord genericRecord = (GenericAvroRecord) GenericAvroSchema.of(schemaInfo).decode(bytes);
Object fieldValue = genericRecord.getAvroRecord().get("arrayField");
Map<DecoderColumnHandle, FieldValueProvider> decodedRow = pulsarRowDecoder.decodeRow(payload).get();
ArrayType columnType = new ArrayType(VARCHAR);
PulsarColumnHandle columnHandle = new PulsarColumnHandle(getPulsarConnectorId().toString(), "arrayField", columnType, false, false, "arrayField", null, null, PulsarColumnHandle.HandleKeyValueType.NONE);
checkArrayValues(getBlock(decodedRow, columnHandle), columnHandle.getType(), fieldValue);
}
use of org.apache.pulsar.sql.presto.decoder.DecoderTestMessage in project pulsar by apache.
the class TestJsonDecoder method testRow.
@Test
public void testRow() {
DecoderTestMessage message = new DecoderTestMessage();
message.stringField = "message_2";
DecoderTestMessage.TestRow testRow = new DecoderTestMessage.TestRow();
message.rowField = testRow;
testRow.intField = 22;
testRow.stringField = "message_2_testRow";
DecoderTestMessage.NestedRow nestedRow = new DecoderTestMessage.NestedRow();
nestedRow.longField = 222L;
nestedRow.stringField = "message_2_nestedRow";
testRow.nestedRow = nestedRow;
byte[] bytes = schema.encode(message);
ByteBuf payload = io.netty.buffer.Unpooled.copiedBuffer(bytes);
GenericJsonRecord genericRecord = (GenericJsonRecord) GenericJsonSchema.of(schemaInfo).decode(bytes);
Object fieldValue = genericRecord.getJsonNode().get("rowField");
Map<DecoderColumnHandle, FieldValueProvider> decodedRow = pulsarRowDecoder.decodeRow(payload).get();
RowType columnType = RowType.from(ImmutableList.<RowType.Field>builder().add(RowType.field("intField", INTEGER)).add(RowType.field("nestedRow", RowType.from(ImmutableList.<RowType.Field>builder().add(RowType.field("longField", BIGINT)).add(RowType.field("stringField", VARCHAR)).build()))).add(RowType.field("stringField", VARCHAR)).build());
PulsarColumnHandle columnHandle = new PulsarColumnHandle(getPulsarConnectorId().toString(), "rowField", columnType, false, false, "rowField", null, null, PulsarColumnHandle.HandleKeyValueType.NONE);
checkRowValues(getBlock(decodedRow, columnHandle), columnHandle.getType(), fieldValue);
}
use of org.apache.pulsar.sql.presto.decoder.DecoderTestMessage in project pulsar by apache.
the class TestJsonDecoder method testMap.
@Test
public void testMap() {
DecoderTestMessage message = new DecoderTestMessage();
message.mapField = new HashMap<String, Long>() {
{
put("key1", 2L);
put("key2", 22L);
}
};
byte[] bytes = schema.encode(message);
ByteBuf payload = io.netty.buffer.Unpooled.copiedBuffer(bytes);
GenericJsonRecord genericRecord = (GenericJsonRecord) GenericJsonSchema.of(schemaInfo).decode(bytes);
Object fieldValue = genericRecord.getJsonNode().get("mapField");
Map<DecoderColumnHandle, FieldValueProvider> decodedRow = pulsarRowDecoder.decodeRow(payload).get();
Type columnType = decoderFactory.getTypeManager().getParameterizedType(StandardTypes.MAP, ImmutableList.of(TypeSignatureParameter.typeParameter(VarcharType.VARCHAR.getTypeSignature()), TypeSignatureParameter.typeParameter(BigintType.BIGINT.getTypeSignature())));
PulsarColumnHandle columnHandle = new PulsarColumnHandle(getPulsarConnectorId().toString(), "mapField", columnType, false, false, "mapField", null, null, PulsarColumnHandle.HandleKeyValueType.NONE);
checkMapValues(getBlock(decodedRow, columnHandle), columnHandle.getType(), fieldValue);
}
Aggregations