Skip to content
This repository has been archived by the owner on Dec 14, 2022. It is now read-only.

fix: pulsar-flink-381 #382

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

package org.apache.flink.streaming.connectors.pulsar.internal;

import org.apache.flink.api.common.functions.util.ListCollector;
import org.apache.flink.streaming.connectors.pulsar.util.MessageIdUtils;
import org.apache.flink.streaming.util.serialization.PulsarDeserializationSchema;

Expand All @@ -28,6 +29,8 @@
import org.apache.pulsar.client.impl.conf.ClientConfigurationData;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;

Expand Down Expand Up @@ -168,12 +171,16 @@ protected void handleTooLargeCursor() {

protected void emitRecord(Message<T> message) throws IOException {
MessageId messageId = message.getMessageId();
final T record = deserializer.deserialize(message);
if (deserializer.isEndOfStream(record)) {
running = false;
return;
List<T> list = new ArrayList<>();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Create this array list every time we emit a message may be too expensive. Can we reuse this array list?

ListCollector<T> listCollector = new ListCollector<>(list);
deserializer.deserialize(message, listCollector);
for (T t : list) {
if (deserializer.isEndOfStream(t)) {
running = false;
return;
}
owner.emitRecordsWithTimestamps(t, state, messageId, message.getEventTime());
}
owner.emitRecordsWithTimestamps(record, state, messageId, message.getEventTime());
}

public void cancel() throws IOException {
Expand Down