nsivabalan commented on code in PR #18172:
URL: https://github.com/apache/hudi/pull/18172#discussion_r2830375734
##########
hudi-client/hudi-client-common/src/main/java/org/apache/hudi/table/action/cluster/strategy/PartitionAwareClusteringPlanStrategy.java:
##########
@@ -102,15 +102,23 @@ protected Pair<Stream<HoodieClusteringGroup>, Boolean>
buildClusteringGroupsForP
}
if (!currentGroup.isEmpty()) {
- if (currentGroup.size() > 1 ||
writeConfig.shouldClusteringSingleGroup()) {
- int numOutputGroups = getNumberOfOutputFileGroups(totalSizeSoFar,
writeConfig.getClusteringTargetFileMaxBytes());
- log.info("Adding final clustering group " + totalSizeSoFar + " max
bytes: "
- + writeConfig.getClusteringMaxBytesInGroup() + " num input slices:
" + currentGroup.size() + " output groups: " + numOutputGroups);
- fileSliceGroups.add(Pair.of(currentGroup, numOutputGroups));
- }
+ int numOutputGroups = getNumberOfOutputFileGroups(totalSizeSoFar,
writeConfig.getClusteringTargetFileMaxBytes());
+ log.info("Adding final clustering group " + totalSizeSoFar + " max
bytes: "
+ + writeConfig.getClusteringMaxBytesInGroup() + " num input slices: "
+ currentGroup.size() + " output groups: " + numOutputGroups);
+ fileSliceGroups.add(Pair.of(currentGroup, numOutputGroups));
}
- return Pair.of(fileSliceGroups.stream().map(fileSliceGroup ->
+ return Pair.of(fileSliceGroups.stream().filter(fileSliceGroup -> {
+ if (fileSliceGroup.getLeft().size() == 1 && fileSliceGroup.getRight() ==
1 && !writeConfig.shouldClusteringSingleGroup()) {
+ FileSlice targetedFileSlice = fileSliceGroup.getLeft().get(0);
+ long size = targetedFileSlice.getBaseFile().isPresent() ?
targetedFileSlice.getBaseFile().get().getFileSize() :
writeConfig.getParquetMaxFileSize();
+ log.info(String.format("Removing clustering group due to input and
output slices both being 1 and single group clustering is disabled."
+ + " Group stats: currentGroupSize= %s,
maxBytesPerClusteringGroup= %s",
+ size, writeConfig.getClusteringMaxBytesInGroup()));
Review Comment:
where are we checking for sort columns before returning `false` ?
##########
hudi-client/hudi-spark-client/src/test/java/org/apache/hudi/client/clustering/plan/strategy/TestSparkSizeBasedClusteringPlanStrategy.java:
##########
@@ -82,11 +82,36 @@ public void testBuildClusteringGroup() {
Assertions.assertEquals(1,
clusteringGroups.get(1).getNumOutputFileGroups());
}
+ @Test
+ public void testRemaningFileInPartitionNotClustered() {
+ HoodieWriteConfig config = HoodieWriteConfig.newBuilder()
+ .withPath("")
+ .withClusteringConfig(HoodieClusteringConfig.newBuilder()
+
.withClusteringPlanStrategyClass(SparkSizeBasedClusteringPlanStrategy.class.getName())
+ .withClusteringMaxBytesInGroup(2000)
+ .withClusteringTargetFileMaxBytes(1000)
+ .withClusteringPlanSmallFileLimit(500)
+ .withSingleGroupClusteringEnabled(false)
+ .build())
+ .build();
+
+ SparkSizeBasedClusteringPlanStrategy planStrategy = new
SparkSizeBasedClusteringPlanStrategy(table, context, config);
+
+ ArrayList<FileSlice> fileSlices = new ArrayList<>();
+ fileSlices.add(createFileSlice(200));
+
+ Stream<HoodieClusteringGroup> clusteringGroupStream =
(Stream<HoodieClusteringGroup>)
planStrategy.buildClusteringGroupsForPartition("p0", fileSlices).getLeft();
+ List<HoodieClusteringGroup> clusteringGroups =
clusteringGroupStream.collect(Collectors.toList());
+
+ // The only file in partition should not be clustered
+ Assertions.assertEquals(0, clusteringGroups.size());
Review Comment:
lets add a test where we set sort columns, and clustering plan should
generate a plan.
--
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]