This is an automated email from the ASF dual-hosted git repository.
danny0405 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/hudi.git
The following commit(s) were added to refs/heads/master by this push:
new 0cd28e52873 [MINOR] HoodieAvroUtils performance optimization of
createFullName method (#11747)
0cd28e52873 is described below
commit 0cd28e52873e0c6ef61184047953d5a3feac895b
Author: Sergei <[email protected]>
AuthorDate: Sat Aug 10 11:27:43 2024 +0700
[MINOR] HoodieAvroUtils performance optimization of createFullName method
(#11747)
---
.../main/java/org/apache/hudi/avro/HoodieAvroUtils.java | 16 +++++++++++++---
.../java/org/apache/hudi/avro/TestHoodieAvroUtils.java | 9 +++++++++
2 files changed, 22 insertions(+), 3 deletions(-)
diff --git
a/hudi-common/src/main/java/org/apache/hudi/avro/HoodieAvroUtils.java
b/hudi-common/src/main/java/org/apache/hudi/avro/HoodieAvroUtils.java
index fb936468466..30c2325e775 100644
--- a/hudi-common/src/main/java/org/apache/hudi/avro/HoodieAvroUtils.java
+++ b/hudi-common/src/main/java/org/apache/hudi/avro/HoodieAvroUtils.java
@@ -1017,9 +1017,19 @@ public class HoodieAvroUtils {
public static String createFullName(Deque<String> fieldNames) {
String result = "";
if (!fieldNames.isEmpty()) {
- List<String> parentNames = new ArrayList<>();
- fieldNames.descendingIterator().forEachRemaining(parentNames::add);
- result = parentNames.stream().collect(Collectors.joining("."));
+ Iterator<String> iter = fieldNames.descendingIterator();
+ result = iter.next();
+ if (!iter.hasNext()) {
+ return result;
+ }
+
+ StringBuilder sb = new StringBuilder();
+ sb.append(result);
+ while (iter.hasNext()) {
+ sb.append(".");
+ sb.append(iter.next());
+ }
+ result = sb.toString();
}
return result;
}
diff --git
a/hudi-common/src/test/java/org/apache/hudi/avro/TestHoodieAvroUtils.java
b/hudi-common/src/test/java/org/apache/hudi/avro/TestHoodieAvroUtils.java
index f1e5f606602..256adaacc77 100644
--- a/hudi-common/src/test/java/org/apache/hudi/avro/TestHoodieAvroUtils.java
+++ b/hudi-common/src/test/java/org/apache/hudi/avro/TestHoodieAvroUtils.java
@@ -60,6 +60,7 @@ import java.sql.Timestamp;
import java.time.Instant;
import java.time.LocalDate;
import java.time.temporal.ChronoUnit;
+import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
@@ -652,4 +653,12 @@ public class TestHoodieAvroUtils {
String jsonString = HoodieAvroUtils.safeAvroToJsonString(record);
assertEquals("{\"timestamp\": \"foo\", \"_row_key\": \"key\",
\"non_pii_col\": \"val1\", \"pii_col\": \"val2\"}", jsonString);
}
+
+ @Test
+ void testCreateFullName() {
+ String result = HoodieAvroUtils.createFullName(new
ArrayDeque<>(Arrays.asList("a", "b", "c")));
+ String resultSingle = HoodieAvroUtils.createFullName(new
ArrayDeque<>(Collections.singletonList("a")));
+ assertEquals("c.b.a", result);
+ assertEquals("a", resultSingle);
+ }
}