use of org.apache.inlong.sort.singletenant.flink.SerializedRecord in project incubator-inlong by apache.
the class DeserializationFunction method processElement.
@Override
public void processElement(SerializedRecord value, ProcessFunction<SerializedRecord, Row>.Context ctx, Collector<Row> out) throws Exception {
InLongMsg inLongMsg = InLongMsg.parseFrom(value.getData());
for (String attr : inLongMsg.getAttrs()) {
Iterator<byte[]> iterator = inLongMsg.getIterator(attr);
if (iterator == null) {
continue;
}
while (iterator.hasNext()) {
byte[] bodyBytes = iterator.next();
if (bodyBytes == null || bodyBytes.length == 0) {
continue;
}
deserializationSchema.deserialize(bodyBytes, new CallbackCollector<>(inputRow -> {
if (appendAttributes) {
inputRow = Row.join(Row.of(new HashMap<>()), inputRow);
}
out.collect(fieldMappingTransformer.transform(inputRow, value.getTimestampMillis()));
}));
}
}
}
use of org.apache.inlong.sort.singletenant.flink.SerializedRecord in project incubator-inlong by apache.
the class DeserializationFunctionTest method testProcessElement.
@Test
public void testProcessElement() throws Exception {
InLongMsg inLongMsg = InLongMsg.newInLongMsg();
String testData = "testData";
inLongMsg.addMsg("m=12&iname=tid", testData.getBytes(StandardCharsets.UTF_8));
SerializedRecord serializedRecord = new SerializedRecord(1, inLongMsg.buildArray());
FieldInfo[] fieldInfos = { new FieldInfo("content", StringFormatInfo.INSTANCE) };
DeserializationFunction function = new DeserializationFunction(DeserializationSchemaFactory.build(fieldInfos, null), new FieldMappingTransformer(new Configuration(), fieldInfos));
ListCollector<Row> collector = new ListCollector<>();
function.processElement(serializedRecord, null, collector);
Row row = collector.getInnerList().get(0);
assertEquals(1, row.getArity());
assertEquals(testData, row.getField(0));
}
Aggregations