ahmedabu98 commented on code in PR #39156:
URL: https://github.com/apache/beam/pull/39156#discussion_r3494205093
##########
sdks/java/io/iceberg/src/main/java/org/apache/beam/sdk/io/iceberg/WriteToPartitions.java:
##########
@@ -64,27 +65,32 @@ private PCollection<KV<Row, Iterable<Row>>>
groupByPartition(PCollection<KV<Row,
RowCoder destinationCoder =
RowCoder.of(AssignDestinationsAndPartitions.OUTPUT_SCHEMA);
RowCoder dataCoder = RowCoder.of(dynamicDestinations.getDataSchema());
- GroupIntoBatches<Row, Row> groupIntoPartitions =
- GroupIntoBatches.ofByteSize(DEFAULT_BYTES_PER_FILE);
- if (IcebergUtils.isUnbounded(input) && triggeringFrequency != null) {
- groupIntoPartitions =
groupIntoPartitions.withMaxBufferingDuration(triggeringFrequency);
- }
+ if (IcebergUtils.isUnbounded(input)) {
+ GroupIntoBatches<Row, Row> groupIntoPartitions =
+ GroupIntoBatches.ofByteSize(DEFAULT_BYTES_PER_FILE);
+ if (triggeringFrequency != null) {
+ groupIntoPartitions =
groupIntoPartitions.withMaxBufferingDuration(triggeringFrequency);
+ }
- if (autoSharding) {
+ if (autoSharding) {
+ return input
+ .apply(groupIntoPartitions.withShardedKey())
+ .setCoder(
+ KvCoder.of(
+
org.apache.beam.sdk.util.ShardedKey.Coder.of(destinationCoder),
+ IterableCoder.of(dataCoder)))
+ .apply(
+ "DropShardId",
+ MapElements.into(kvs(rows(), iterables(rows())))
+ .via(kv -> KV.of(kv.getKey().getKey(), kv.getValue())))
+ .setCoder(KvCoder.of(destinationCoder,
IterableCoder.of(dataCoder)));
+ }
return input
- .apply(groupIntoPartitions.withShardedKey())
- .setCoder(
- KvCoder.of(
-
org.apache.beam.sdk.util.ShardedKey.Coder.of(destinationCoder),
- IterableCoder.of(dataCoder)))
- .apply(
- "DropShardId",
- MapElements.into(kvs(rows(), iterables(rows())))
- .via(kv -> KV.of(kv.getKey().getKey(), kv.getValue())))
+ .apply(groupIntoPartitions)
.setCoder(KvCoder.of(destinationCoder, IterableCoder.of(dataCoder)));
} else {
return input
- .apply(groupIntoPartitions)
+ .apply(GroupByKey.create())
.setCoder(KvCoder.of(destinationCoder, IterableCoder.of(dataCoder)));
}
Review Comment:
@atognolas I think this is a valid point.
Were you seeing OOMs even with autosharding enabled? AFAIK autosharding
should distribute to different keys, so the state for any one key shouldn't get
too large.
If it makes sense, we can keep the GroupIntoBatches.withShardedKey() path
for autosharding batch writes.
Otherwise maybe we can add a `num_shards` config to do fixed sharding per
partition, and stick with GBK
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]