Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[HUDI-8857] Log shortened list of files instead of all files in MDT validator to avoid huge log message #12617

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
48 changes: 48 additions & 0 deletions hudi-io/src/main/java/org/apache/hudi/common/util/StringUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
import java.util.stream.Stream;

/**
Expand Down Expand Up @@ -369,6 +370,53 @@ public static String concatenateWithThreshold(String a, String b, int byteLength
return a.substring(0, bestLength) + b;
}

/**
* Concatenates the string representation of each object in the list
* and returns a single string. The result is capped at "lengthThreshold" characters.
*
* @param objectList object list
* @param lengthThreshold number of characters to cap the string
* @param <T> type of the object
*
* @return capped string representation of the object list
*/
public static <T> String toStringWithThreshold(List<T> objectList, int lengthThreshold) {
Copy link
Member

Choose a reason for hiding this comment

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

Could you please add UT as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will do. This one is still in draft state.

if (objectList == null || objectList.isEmpty()) {
return "";
codope marked this conversation as resolved.
Show resolved Hide resolved
}
StringBuilder sb = new StringBuilder();

for (Object obj : objectList) {
if (sb.length() >= lengthThreshold) {
setLastThreeDots(sb);
break;
}

String objString = (sb.length() > 0 ? "," : "") + obj;

// Check if appending this string would exceed the limit
if (sb.length() + objString.length() > lengthThreshold) {
int remaining = lengthThreshold - sb.length();
sb.append(objString, 0, remaining);
setLastThreeDots(sb);
break;
} else {
sb.append(objString);
}
}

return sb.toString();
}

private static void setLastThreeDots(StringBuilder sb) {
IntStream.range(1, 4).forEach(i -> {
int loc = sb.length() - i;
if (loc >= 0) {
sb.setCharAt(loc, '.');
}
});
}

private static int getBestLength(String a, int threshold) {
// Binary search to find the maximum length of substring of 'a' that fits within maxBytesForA
int low = 0;
Expand Down
Loading