Code review comment: enforce no dynamic destinations in batch? Or I think the BoundedWriter needs to group output by topic as publish is just all messages to single topic currently.

Code before review:
public PDone expand(PCollection<T> input) {
if (getTopicProvider() == null && !getDynamicDestinations()) {
throw new IllegalStateException(
"need to set the topic of a PubsubIO.Write transform if not using "
+ "dynamic topic destinations.");
}
SerializableFunction<ValueInSingleWindow<T>, PubsubIO.PubsubTopic> topicFunction =
getTopicFunction();
if (topicFunction == null && getTopicProvider() != null) {
topicFunction = v -> getTopicProvider().get();
}
int maxMessageSize = PUBSUB_MESSAGE_MAX_TOTAL_SIZE;
if (input.isBounded() == PCollection.IsBounded.BOUNDED) {
maxMessageSize =
Math.min(
maxMessageSize,
MoreObjects.firstNonNull(
getMaxBatchBytesSize(), MAX_PUBLISH_BATCH_BYTE_SIZE_DEFAULT));
}
PCollection<PubsubMessage> pubsubMessages =
input.apply(
ParDo.of(new PreparePubsubWriteDoFn<>(getFormatFn(), topicFunction, maxMessageSize)));
switch (input.isBounded()) {
case BOUNDED:
pubsubMessages.apply(
ParDo.of(
new PubsubBoundedWriter(
MoreObjects.firstNonNull(getMaxBatchSize(), MAX_PUBLISH_BATCH_SIZE),
MoreObjects.firstNonNull(
getMaxBatchBytesSize(), MAX_PUBLISH_BATCH_BYTE_SIZE_DEFAULT))));
return PDone.in(input.getPipeline());
case UNBOUNDED:
return pubsubMessages.apply(
new PubsubUnboundedSink(
getPubsubClientFactory(),
getTopicProvider() != null
? NestedValueProvider.of(getTopicProvider(), new TopicPathTranslator())
: null,
getTimestampAttribute(),
getIdAttribute(),
100 /* numShards */,
MoreObjects.firstNonNull(
getMaxBatchSize(), PubsubUnboundedSink.DEFAULT_PUBLISH_BATCH_SIZE),
MoreObjects.firstNonNull(
getMaxBatchBytesSize(), PubsubUnboundedSink.DEFAULT_PUBLISH_BATCH_BYTES),
getPubsubRootUrl()));
}
throw new RuntimeException();
}

Line under review: }

Code after addressing the review:
public PDone expand(PCollection<T> input) {
if (getTopicProvider() == null && !getDynamicDestinations()) {
throw new IllegalStateException(
"need to set the topic of a PubsubIO.Write transform if not using "
+ "dynamic topic destinations.");
}
SerializableFunction<ValueInSingleWindow<T>, PubsubIO.PubsubTopic> topicFunction =
getTopicFunction();
if (topicFunction == null && getTopicProvider() != null) {
topicFunction = v -> getTopicProvider().get();
}
int maxMessageSize = PUBSUB_MESSAGE_MAX_TOTAL_SIZE;
if (input.isBounded() == PCollection.IsBounded.BOUNDED) {
maxMessageSize =
Math.min(
maxMessageSize,
MoreObjects.firstNonNull(
getMaxBatchBytesSize(), MAX_PUBLISH_BATCH_BYTE_SIZE_DEFAULT));
}
PCollection<PubsubMessage> pubsubMessages =
input
.apply(
ParDo.of(
new PreparePubsubWriteDoFn<>(getFormatFn(), topicFunction, maxMessageSize)))
.setCoder(new PubsubMessageWithTopicCoder());
switch (input.isBounded()) {
case BOUNDED:
pubsubMessages.apply(
ParDo.of(
new PubsubBoundedWriter(
MoreObjects.firstNonNull(getMaxBatchSize(), MAX_PUBLISH_BATCH_SIZE),
MoreObjects.firstNonNull(
getMaxBatchBytesSize(), MAX_PUBLISH_BATCH_BYTE_SIZE_DEFAULT))));
return PDone.in(input.getPipeline());
case UNBOUNDED:
return pubsubMessages.apply(
new PubsubUnboundedSink(
getPubsubClientFactory(),
getTopicProvider() != null
? NestedValueProvider.of(getTopicProvider(), new TopicPathTranslator())
: null,
getTimestampAttribute(),
getIdAttribute(),
100 /* numShards */,
MoreObjects.firstNonNull(
getMaxBatchSize(), PubsubUnboundedSink.DEFAULT_PUBLISH_BATCH_SIZE),
MoreObjects.firstNonNull(
getMaxBatchBytesSize(), PubsubUnboundedSink.DEFAULT_PUBLISH_BATCH_BYTES),
getPubsubRootUrl()));
}
throw new RuntimeException();
}