Search in sources :

Example 1 with InLongMsg

use of org.apache.inlong.common.msg.InLongMsg 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 InLongMsg

use of org.apache.inlong.common.msg.InLongMsg in project incubator-inlong by apache.

the class InLongMsgCsvFormatDeserializerTest method testUnmatchedFields1.

@Test
public void testUnmatchedFields1() throws Exception {
    final InLongMsgCsvFormatDeserializer deserializer = new InLongMsgCsvFormatDeserializer(TEST_ROW_INFO);
    InLongMsg inLongMsg = InLongMsg.newInLongMsg();
    String attrs = "m=0&" + INLONGMSG_ATTR_STREAM_ID + "=testInterfaceId&t=20200322&__addcol1__=1&__addcol2__=2";
    String body1 = "123,field11,field12";
    String body2 = "123,field21,field22,field23,field24";
    inLongMsg.addMsg(attrs, body1.getBytes());
    inLongMsg.addMsg(attrs, body2.getBytes());
    Map<String, String> expectedAttributes = new HashMap<>();
    expectedAttributes.put("m", "0");
    expectedAttributes.put(INLONGMSG_ATTR_STREAM_ID, "testInterfaceId");
    expectedAttributes.put("t", "20200322");
    expectedAttributes.put("__addcol1__", "1");
    expectedAttributes.put("__addcol2__", "2");
    Row expectedRow1 = Row.of(Timestamp.valueOf("2020-03-22 00:00:00"), expectedAttributes, 1, 2, 123, "field11", "field12", null);
    Row expectedRow2 = Row.of(Timestamp.valueOf("2020-03-22 00:00:00"), expectedAttributes, 1, 2, 123, "field21", "field22", "field23");
    testRowDeserialization(deserializer, inLongMsg.buildArray(), Arrays.asList(expectedRow1, expectedRow2));
}
Also used : HashMap(java.util.HashMap) InLongMsg(org.apache.inlong.common.msg.InLongMsg) Row(org.apache.flink.types.Row) Test(org.junit.Test)

Example 3 with InLongMsg

use of org.apache.inlong.common.msg.InLongMsg in project incubator-inlong by apache.

the class InLongMsgCsvFormatDeserializerTest method testUnmatchedFields2.

@Test
public void testUnmatchedFields2() throws Exception {
    final InLongMsgCsvFormatDeserializer deserializer = new InLongMsgCsvFormatDeserializer(TEST_ROW_INFO);
    InLongMsg inLongMsg = InLongMsg.newInLongMsg();
    String attrs = "m=0&" + INLONGMSG_ATTR_STREAM_ID + "=testInterfaceId&t=20200322&__addcol1__=1&" + "__addcol2__=2&__addcol3__=3&__addcol4__=4&__addcol5__=5&__addcol6__=6&__addcol7__=7";
    String body = "field11,field12";
    inLongMsg.addMsg(attrs, body.getBytes());
    Map<String, String> expectedAttributes = new HashMap<>();
    expectedAttributes.put("m", "0");
    expectedAttributes.put(INLONGMSG_ATTR_STREAM_ID, "testInterfaceId");
    expectedAttributes.put("t", "20200322");
    expectedAttributes.put("__addcol1__", "1");
    expectedAttributes.put("__addcol2__", "2");
    expectedAttributes.put("__addcol3__", "3");
    expectedAttributes.put("__addcol4__", "4");
    expectedAttributes.put("__addcol5__", "5");
    expectedAttributes.put("__addcol6__", "6");
    expectedAttributes.put("__addcol7__", "7");
    Row expectedRow = Row.of(Timestamp.valueOf("2020-03-22 00:00:00"), expectedAttributes, 1, 2, 3, "4", "5", "6");
    testRowDeserialization(deserializer, inLongMsg.buildArray(), Collections.singletonList(expectedRow));
}
Also used : HashMap(java.util.HashMap) InLongMsg(org.apache.inlong.common.msg.InLongMsg) Row(org.apache.flink.types.Row) Test(org.junit.Test)

Example 4 with InLongMsg

use of org.apache.inlong.common.msg.InLongMsg in project incubator-inlong by apache.

the class InLongMsgCsvFormatDeserializerTest method testIgnoreBodyErrors.

@Test
public void testIgnoreBodyErrors() throws Exception {
    final InLongMsgCsvFormatDeserializer deserializer = new InLongMsgCsvFormatDeserializer(TEST_ROW_INFO, DEFAULT_TIME_FIELD_NAME, DEFAULT_ATTRIBUTES_FIELD_NAME, Charset.defaultCharset().name(), TableFormatConstants.DEFAULT_DELIMITER, null, null, null, true, true);
    InLongMsg inLongMsg = InLongMsg.newInLongMsg();
    String attrs = "m=0&" + INLONGMSG_ATTR_STREAM_ID + "=testInterfaceId&t=20200322&__addcol1__=1&__addcol2__=2";
    String body1 = "aaa,field11,field12,field13";
    String body2 = "123,field21,field22,field23";
    inLongMsg.addMsg(attrs, body1.getBytes());
    inLongMsg.addMsg(attrs, body2.getBytes());
    Map<String, String> expectedAttributes = new HashMap<>();
    expectedAttributes.put("m", "0");
    expectedAttributes.put(INLONGMSG_ATTR_STREAM_ID, "testInterfaceId");
    expectedAttributes.put("t", "20200322");
    expectedAttributes.put("__addcol1__", "1");
    expectedAttributes.put("__addcol2__", "2");
    Row expectedRow2 = Row.of(Timestamp.valueOf("2020-03-22 00:00:00"), expectedAttributes, 1, 2, 123, "field21", "field22", "field23");
    testRowDeserialization(deserializer, inLongMsg.buildArray(), Collections.singletonList(expectedRow2));
}
Also used : HashMap(java.util.HashMap) InLongMsg(org.apache.inlong.common.msg.InLongMsg) Row(org.apache.flink.types.Row) Test(org.junit.Test)

Example 5 with InLongMsg

use of org.apache.inlong.common.msg.InLongMsg in project incubator-inlong by apache.

the class InLongMsgCsvFormatDeserializerTest method testNormal.

@Test
public void testNormal() throws Exception {
    final InLongMsgCsvFormatDeserializer deserializer = new InLongMsgCsvFormatDeserializer(TEST_ROW_INFO);
    InLongMsg inLongMsg = InLongMsg.newInLongMsg();
    String attrs = "m=0&" + INLONGMSG_ATTR_STREAM_ID + "=testInterfaceId&t=20200322&__addcol1__=1&__addcol2__=2";
    String body1 = "123,field11,field12,field13";
    String body2 = "123,field21,field22,field23";
    inLongMsg.addMsg(attrs, body1.getBytes());
    inLongMsg.addMsg(attrs, body2.getBytes());
    Map<String, String> expectedAttributes = new HashMap<>();
    expectedAttributes.put("m", "0");
    expectedAttributes.put(INLONGMSG_ATTR_STREAM_ID, "testInterfaceId");
    expectedAttributes.put("t", "20200322");
    expectedAttributes.put("__addcol1__", "1");
    expectedAttributes.put("__addcol2__", "2");
    Row expectedRow1 = Row.of(Timestamp.valueOf("2020-03-22 00:00:00"), expectedAttributes, 1, 2, 123, "field11", "field12", "field13");
    Row expectedRow2 = Row.of(Timestamp.valueOf("2020-03-22 00:00:00"), expectedAttributes, 1, 2, 123, "field21", "field22", "field23");
    testRowDeserialization(deserializer, inLongMsg.buildArray(), Arrays.asList(expectedRow1, expectedRow2));
}
Also used : HashMap(java.util.HashMap) InLongMsg(org.apache.inlong.common.msg.InLongMsg) Row(org.apache.flink.types.Row) Test(org.junit.Test)

Aggregations

InLongMsg (org.apache.inlong.common.msg.InLongMsg)16 HashMap (java.util.HashMap)13 Row (org.apache.flink.types.Row)11 Test (org.junit.Test)11 SimpleDateFormat (java.text.SimpleDateFormat)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Map (java.util.Map)2 ChannelException (org.apache.flume.ChannelException)2 Event (org.apache.flume.Event)2 ProxyMessage (org.apache.inlong.dataproxy.base.ProxyMessage)2 FieldInfo (org.apache.inlong.sort.protocol.FieldInfo)2 SerializedRecord (org.apache.inlong.sort.singletenant.flink.SerializedRecord)2 IOException (java.io.IOException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 Timestamp (java.sql.Timestamp)1 Iterator (java.util.Iterator)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 DeserializationSchema (org.apache.flink.api.common.serialization.DeserializationSchema)1 ProcessFunction (org.apache.flink.streaming.api.functions.ProcessFunction)1