codope commented on code in PR #10352:
URL: https://github.com/apache/hudi/pull/10352#discussion_r1559706816
##########
hudi-common/src/main/java/org/apache/hudi/common/util/BaseFileUtils.java:
##########
@@ -64,6 +67,51 @@ public static BaseFileUtils getInstance(HoodieFileFormat
fileFormat) {
throw new UnsupportedOperationException(fileFormat.name() + " format not
supported yet.");
}
+ /**
+ * Aggregate column range statistics across files in a partition.
+ *
+ * @param fileRanges List of column range statistics for each file in a
partition
+ */
+ public static <T extends Comparable<T>> HoodieColumnRangeMetadata<T>
getColumnRangeInPartition(@Nonnull List<HoodieColumnRangeMetadata<T>>
fileRanges) {
+ if (fileRanges.size() == 1) {
+ // Only one parquet file, we can just return that range.
+ return fileRanges.get(0);
+ }
+ // There are multiple files. Compute min(file_mins) and max(file_maxs)
+ return fileRanges.stream()
+ .sequential()
+ .reduce(BaseFileUtils::mergeRanges).get();
+ }
+
+ private static <T extends Comparable<T>> HoodieColumnRangeMetadata<T>
mergeRanges(HoodieColumnRangeMetadata<T> one,
+
HoodieColumnRangeMetadata<T> another) {
+ final T minValue;
+ final T maxValue;
+ if (one.getMinValue() != null && another.getMinValue() != null) {
+ minValue =
one.getMinValue().toString().compareTo(another.getMinValue().toString()) < 0 ?
one.getMinValue() : another.getMinValue();
+ } else if (one.getMinValue() == null) {
+ minValue = another.getMinValue();
+ } else {
+ minValue = one.getMinValue();
+ }
+
+ if (one.getMaxValue() != null && another.getMaxValue() != null) {
+ maxValue =
one.getMaxValue().toString().compareTo(another.getMaxValue().toString()) < 0 ?
another.getMaxValue() : one.getMaxValue();
+ } else if (one.getMaxValue() == null) {
+ maxValue = another.getMaxValue();
+ } else {
+ maxValue = one.getMaxValue();
+ }
+
+ return HoodieColumnRangeMetadata.create(
+ one.getFilePath(),
Review Comment:
done
--
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]