Skip to content
Open
Show file tree
Hide file tree
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 @@ -39,6 +39,18 @@ public class DynamicRecord {
private boolean upsertMode;
@Nullable private Set<String> equalityFields;

/**
* Constructs a new DynamicRecord.
*
* @param tableIdentifier The target table identifier.
* @param branch The target table branch.
* @param schema The target table schema.
* @param rowData The data matching the provided schema.
* @param partitionSpec The target table {@link PartitionSpec}.
* @param distributionMode The {@link DistributionMode}.
* @param writeParallelism The number of parallel writers. If set to {@literal <= 0}, will
Copy link
Contributor

Choose a reason for hiding this comment

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

What if we set it to MAX_INT. It is easier to calculate with min later

* automatically configure the maximum available write parallelism.
*/
public DynamicRecord(
TableIdentifier tableIdentifier,
String branch,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,14 @@ static int safeAbs(int input) {

return -input;
}

static int firstPositive(int first, int second) {
if (first > 0) {
return first;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: new line.

if (second > 0) {
return second;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: new line

throw new IllegalArgumentException("None of the supplied ints were positive!");
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we print out both values to facilitate troubleshooting?

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@ int generateKey(
dynamicRecord.distributionMode(), DistributionMode.NONE),
MoreObjects.firstNonNull(
dynamicRecord.equalityFields(), Collections.emptySet()),
dynamicRecord.writeParallelism()));
DynamicSinkUtil.firstPositive(
dynamicRecord.writeParallelism(), maxWriteParallelism)));
try {
return keySelector.getKey(
overrideRowData != null ? overrideRowData : dynamicRecord.rowData());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,28 @@ void testEqualityKeys() throws Exception {
assertThat(getSubTaskId(writeKey3, writeParallelism, maxWriteParallelism)).isEqualTo(0);
}

@Test
void testUseMaxWriteParallelismIfWriteParallelismUnspecified() throws Exception {
final int maxWriteParallelism = 5;
HashKeyGenerator generator = new HashKeyGenerator(16, maxWriteParallelism);

Set<Integer> writeKeys = Sets.newHashSet();
for (int i = 0; i < maxWriteParallelism; i++) {
GenericRowData row = GenericRowData.of(i, StringData.fromString("z"));
writeKeys.add(
getWriteKey(
generator,
PartitionSpec.unpartitioned(),
DistributionMode.NONE,
// Use a writeParallelism <= 0
-i,
Collections.emptySet(),
row));
}

assertThat(writeKeys).hasSize(maxWriteParallelism);
}

@Test
void testCapAtMaxWriteParallelism() throws Exception {
int writeParallelism = 10;
Expand Down