Search in sources :

Example 1 with SerializedRecord

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()));
            }));
        }
    }
}
Also used : DeserializationSchema(org.apache.flink.api.common.serialization.DeserializationSchema) SerializedRecord(org.apache.inlong.sort.singletenant.flink.SerializedRecord) Iterator(java.util.Iterator) Collector(org.apache.flink.util.Collector) HashMap(java.util.HashMap) ProcessFunction(org.apache.flink.streaming.api.functions.ProcessFunction) Row(org.apache.flink.types.Row) InLongMsg(org.apache.inlong.common.msg.InLongMsg) HashMap(java.util.HashMap) InLongMsg(org.apache.inlong.common.msg.InLongMsg)

Example 2 with SerializedRecord

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));
}
Also used : SerializedRecord(org.apache.inlong.sort.singletenant.flink.SerializedRecord) Configuration(org.apache.inlong.sort.configuration.Configuration) InLongMsg(org.apache.inlong.common.msg.InLongMsg) Row(org.apache.flink.types.Row) FieldInfo(org.apache.inlong.sort.protocol.FieldInfo) Test(org.junit.Test)

Aggregations

Row (org.apache.flink.types.Row)2 InLongMsg (org.apache.inlong.common.msg.InLongMsg)2 SerializedRecord (org.apache.inlong.sort.singletenant.flink.SerializedRecord)2 HashMap (java.util.HashMap)1 Iterator (java.util.Iterator)1 DeserializationSchema (org.apache.flink.api.common.serialization.DeserializationSchema)1 ProcessFunction (org.apache.flink.streaming.api.functions.ProcessFunction)1 Collector (org.apache.flink.util.Collector)1 Configuration (org.apache.inlong.sort.configuration.Configuration)1 FieldInfo (org.apache.inlong.sort.protocol.FieldInfo)1 Test (org.junit.Test)1