Search in sources :

Example 6 with SerializedRecord

use of org.apache.inlong.sort.flink.SerializedRecord in project incubator-inlong by apache.

the class MultiTenancyDeserializer method generateDeserializer.

@VisibleForTesting
Deserializer<SerializedRecord, Record> generateDeserializer(FieldInfo[] fields, DeserializationInfo deserializationInfo) {
    final RowFormatInfo rowFormatInfo = CommonUtils.generateDeserializationRowFormatInfo(fields);
    final Deserializer<SerializedRecord, Record> deserializer;
    if (deserializationInfo instanceof InLongMsgCsvDeserializationInfo) {
        InLongMsgCsvDeserializationInfo inLongMsgCsvDeserializationInfo = (InLongMsgCsvDeserializationInfo) deserializationInfo;
        InLongMsgCsvFormatDeserializer inLongMsgCsvFormatDeserializer = new InLongMsgCsvFormatDeserializer(rowFormatInfo, DEFAULT_TIME_FIELD_NAME, DEFAULT_ATTRIBUTES_FIELD_NAME, TableFormatConstants.DEFAULT_CHARSET, inLongMsgCsvDeserializationInfo.getDelimiter(), null, null, null, inLongMsgCsvDeserializationInfo.isDeleteHeadDelimiter(), TableFormatConstants.DEFAULT_IGNORE_ERRORS);
        deserializer = new InLongMsgDeserializer(inLongMsgCsvFormatDeserializer);
    } else {
        // TODO, support more formats here
        throw new UnsupportedOperationException("Not supported yet " + deserializationInfo.getClass().getSimpleName());
    }
    return deserializer;
}
Also used : SerializedRecord(org.apache.inlong.sort.flink.SerializedRecord) InLongMsgCsvFormatDeserializer(org.apache.inlong.sort.formats.inlongmsgcsv.InLongMsgCsvFormatDeserializer) RowFormatInfo(org.apache.inlong.sort.formats.common.RowFormatInfo) SerializedRecord(org.apache.inlong.sort.flink.SerializedRecord) Record(org.apache.inlong.sort.flink.Record) InLongMsgCsvDeserializationInfo(org.apache.inlong.sort.protocol.deserialization.InLongMsgCsvDeserializationInfo) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 7 with SerializedRecord

use of org.apache.inlong.sort.flink.SerializedRecord in project incubator-inlong by apache.

the class RecordTransformerTest method testRecordAndSerializerFieldNotMatch.

@Test
public void testRecordAndSerializerFieldNotMatch() throws Exception {
    final int bufferSize = 1024;
    final RecordTransformer transformer = new RecordTransformer(bufferSize);
    final FieldInfo field1 = new FieldInfo("field1", new LongFormatInfo());
    final FieldInfo field2 = new FieldInfo("field2", new StringFormatInfo());
    final TestingSinkInfo sinkInfo = new TestingSinkInfo(new FieldInfo[] { field1, field2 });
    final DataFlowInfo dataFlowInfo = new DataFlowInfo(1L, new EmptySourceInfo(), sinkInfo);
    transformer.addDataFlow(dataFlowInfo);
    final Row row = new Row(2);
    row.setField(0, 1024L);
    row.setField(1, 2048);
    final Record record = new Record(1L, System.currentTimeMillis(), row);
    try {
        transformer.toSerializedRecord(record);
        Assert.fail();
    } catch (Exception expected) {
    }
    final FieldInfo newField1 = new FieldInfo("field1", new LongFormatInfo());
    final FieldInfo newField2 = new FieldInfo("field2", new IntFormatInfo());
    final TestingSinkInfo newSinkInfo = new TestingSinkInfo(new FieldInfo[] { newField1, newField2 });
    final DataFlowInfo newDataFlowInfo = new DataFlowInfo(1L, new EmptySourceInfo(), newSinkInfo);
    transformer.updateDataFlow(newDataFlowInfo);
    SerializedRecord serializedRecord = transformer.toSerializedRecord(record);
    transformer.updateDataFlow(dataFlowInfo);
    try {
        transformer.toRecord(serializedRecord);
        Assert.fail();
    } catch (Exception expected) {
    }
}
Also used : SerializedRecord(org.apache.inlong.sort.flink.SerializedRecord) IntFormatInfo(org.apache.inlong.sort.formats.common.IntFormatInfo) SerializedRecord(org.apache.inlong.sort.flink.SerializedRecord) Record(org.apache.inlong.sort.flink.Record) LongFormatInfo(org.apache.inlong.sort.formats.common.LongFormatInfo) TestingSinkInfo(org.apache.inlong.sort.util.TestingUtils.TestingSinkInfo) Row(org.apache.flink.types.Row) EmptySourceInfo(org.apache.inlong.sort.util.TestingUtils.EmptySourceInfo) StringFormatInfo(org.apache.inlong.sort.formats.common.StringFormatInfo) FieldInfo(org.apache.inlong.sort.protocol.FieldInfo) DataFlowInfo(org.apache.inlong.sort.protocol.DataFlowInfo) Test(org.junit.Test)

Example 8 with SerializedRecord

use of org.apache.inlong.sort.flink.SerializedRecord in project incubator-inlong by apache.

the class MultiTopicPulsarSourceFunctionTest method producerMessageToPulsar.

protected void producerMessageToPulsar(String pulsarBrokerUrl) throws Exception {
    RowSerializer rowSerializer = CommonUtils.generateRowSerializer(new RowFormatInfo(new String[] { "f1", "f2" }, new FormatInfo[] { StringFormatInfo.INSTANCE, StringFormatInfo.INSTANCE }));
    DataOutputSerializer dataOutputSerializer = new DataOutputSerializer(1024);
    try (PulsarClient client = PulsarClient.builder().serviceUrl(pulsarBrokerUrl).build();
        Producer<byte[]> producer = client.newProducer().topic(TEST_TOPIC).create()) {
        for (int cnt = 0; cnt < TOTAL_COUNT; cnt++) {
            Row row = Row.of(String.valueOf(cnt), String.valueOf(cnt));
            rowSerializer.serialize(row, dataOutputSerializer);
            ByteArrayOutputStream byt = new ByteArrayOutputStream();
            ObjectOutputStream objectOutputStream = new ObjectOutputStream(byt);
            objectOutputStream.writeObject(new SerializedRecord(1L, 0, dataOutputSerializer.getCopyOfBuffer()));
            producer.send(byt.toByteArray());
        }
    }
}
Also used : SerializedRecord(org.apache.inlong.sort.flink.SerializedRecord) DataOutputSerializer(org.apache.flink.core.memory.DataOutputSerializer) RowSerializer(org.apache.flink.api.java.typeutils.runtime.RowSerializer) RowFormatInfo(org.apache.inlong.sort.formats.common.RowFormatInfo) PulsarClient(org.apache.pulsar.client.api.PulsarClient) Row(org.apache.flink.types.Row) ByteArrayOutputStream(java.io.ByteArrayOutputStream) FormatInfo(org.apache.inlong.sort.formats.common.FormatInfo) StringFormatInfo(org.apache.inlong.sort.formats.common.StringFormatInfo) RowFormatInfo(org.apache.inlong.sort.formats.common.RowFormatInfo) ObjectOutputStream(java.io.ObjectOutputStream)

Example 9 with SerializedRecord

use of org.apache.inlong.sort.flink.SerializedRecord in project incubator-inlong by apache.

the class MultiTopicPulsarSourceFunction method processEvent.

private void processEvent(SourceEvent sourceEvent) throws Exception {
    SourceEventType sourceEventType = sourceEvent.getSourceEventType();
    PulsarSourceInfo pulsarSourceInfo = (PulsarSourceInfo) sourceEvent.getSourceInfo();
    Map<String, Object> properties = sourceEvent.getProperties();
    long dataFlowId = sourceEvent.getDataFlowId();
    switch(sourceEventType) {
        case ADDED:
            PulsarSourceFunction<SerializedRecord> pulsarSourceFunction = generateSourceFunction(dataFlowId, properties, pulsarSourceInfo);
            pulsarConsumer.addPulsarSource(dataFlowId, pulsarSourceFunction);
            break;
        case UPDATE:
            PulsarSourceFunction<SerializedRecord> updateSourceFunction = generateSourceFunction(dataFlowId, properties, pulsarSourceInfo);
            pulsarConsumer.updatePulsarSource(dataFlowId, updateSourceFunction);
            break;
        case REMOVED:
            pulsarConsumer.removePulsarSource(dataFlowId);
            break;
        default:
            LOG.error("Unknown source event type {}", sourceEvent.getSourceEventType());
            throw new RuntimeException("Unknown source event type " + sourceEvent.getSourceEventType());
    }
}
Also used : SerializedRecord(org.apache.inlong.sort.flink.SerializedRecord) PulsarSourceInfo(org.apache.inlong.sort.protocol.source.PulsarSourceInfo) SourceEventType(org.apache.inlong.sort.flink.SourceEvent.SourceEventType)

Example 10 with SerializedRecord

use of org.apache.inlong.sort.flink.SerializedRecord in project incubator-inlong by apache.

the class MultiTopicPulsarSourceFunction method generateSourceFunction.

public PulsarSourceFunction<SerializedRecord> generateSourceFunction(long dataFlowId, Map<String, Object> properties, PulsarSourceInfo pulsarSourceInfo) throws Exception {
    org.apache.flink.configuration.Configuration config = new org.apache.flink.configuration.Configuration();
    putMapToConfig(config, properties);
    PulsarSourceFunction<SerializedRecord> pulsarSourceFunction = new PulsarSourceFunction<>(pulsarSourceInfo.getAdminUrl(), pulsarSourceInfo.getServiceUrl(), pulsarSourceInfo.getTopic(), pulsarSourceInfo.getSubscriptionName(), pulsarSourceInfo.getAuthentication(), new SerializedRecordDeserializationSchema(dataFlowId), config);
    pulsarSourceFunction.setRuntimeContext(getRuntimeContext());
    pulsarSourceFunction.initializeState(new MultiTenantFunctionInitializationContext(dataFlowId, functionInitializationContext, getRuntimeContext().getExecutionConfig()));
    pulsarSourceFunction.open(config);
    return pulsarSourceFunction;
}
Also used : SerializedRecord(org.apache.inlong.sort.flink.SerializedRecord) Configuration(org.apache.inlong.sort.configuration.Configuration) PulsarSourceFunction(org.apache.inlong.sort.flink.pulsar.PulsarSourceFunction) MultiTenantFunctionInitializationContext(org.apache.inlong.sort.flink.multitenant.MultiTenantFunctionInitializationContext)

Aggregations

SerializedRecord (org.apache.inlong.sort.flink.SerializedRecord)10 Record (org.apache.inlong.sort.flink.Record)6 RowSerializer (org.apache.flink.api.java.typeutils.runtime.RowSerializer)3 Row (org.apache.flink.types.Row)3 DataOutputSerializer (org.apache.flink.core.memory.DataOutputSerializer)2 RowFormatInfo (org.apache.inlong.sort.formats.common.RowFormatInfo)2 StringFormatInfo (org.apache.inlong.sort.formats.common.StringFormatInfo)2 InLongMsgCsvDeserializationInfo (org.apache.inlong.sort.protocol.deserialization.InLongMsgCsvDeserializationInfo)2 Test (org.junit.Test)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 ObjectOutputStream (java.io.ObjectOutputStream)1 Configuration (org.apache.flink.configuration.Configuration)1 CheckedThread (org.apache.flink.core.testutils.CheckedThread)1 MockStreamingRuntimeContext (org.apache.flink.streaming.util.MockStreamingRuntimeContext)1 Configuration (org.apache.inlong.sort.configuration.Configuration)1 InLongMsgMixedSerializedRecord (org.apache.inlong.sort.flink.InLongMsgMixedSerializedRecord)1 SourceEventType (org.apache.inlong.sort.flink.SourceEvent.SourceEventType)1 MetricData (org.apache.inlong.sort.flink.metrics.MetricData)1 MultiTenantFunctionInitializationContext (org.apache.inlong.sort.flink.multitenant.MultiTenantFunctionInitializationContext)1