You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hudi.apache.org by da...@apache.org on 2022/09/05 04:10:21 UTC
[hudi] branch master updated: [HUDI-4739] Wrong value returned when key's length equals 1 (#6539)
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 24dd00724c [HUDI-4739] Wrong value returned when key's length equals 1 (#6539)
24dd00724c is described below
commit 24dd00724cf8f49b8e2d5ad07afaa7756165e0a7
Author: wuwenchi <wu...@hotmail.com>
AuthorDate: Mon Sep 5 12:10:13 2022 +0800
[HUDI-4739] Wrong value returned when key's length equals 1 (#6539)
* extracts key fields
Co-authored-by: 吴文池 <wu...@deepexi.com>
---
.../java/org/apache/hudi/keygen/KeyGenUtils.java | 25 ++++++---------
.../org/apache/hudi/keygen/TestKeyGenUtils.java | 37 ++++++++++++++++++++++
2 files changed, 47 insertions(+), 15 deletions(-)
diff --git a/hudi-client/hudi-client-common/src/main/java/org/apache/hudi/keygen/KeyGenUtils.java b/hudi-client/hudi-client-common/src/main/java/org/apache/hudi/keygen/KeyGenUtils.java
index 362ef208d4..1fd46d31e5 100644
--- a/hudi-client/hudi-client-common/src/main/java/org/apache/hudi/keygen/KeyGenUtils.java
+++ b/hudi-client/hudi-client-common/src/main/java/org/apache/hudi/keygen/KeyGenUtils.java
@@ -73,21 +73,16 @@ public class KeyGenUtils {
*/
public static String[] extractRecordKeys(String recordKey) {
String[] fieldKV = recordKey.split(",");
- if (fieldKV.length == 1) {
- return fieldKV;
- } else {
- // a complex key
- return Arrays.stream(fieldKV).map(kv -> {
- final String[] kvArray = kv.split(":");
- if (kvArray[1].equals(NULL_RECORDKEY_PLACEHOLDER)) {
- return null;
- } else if (kvArray[1].equals(EMPTY_RECORDKEY_PLACEHOLDER)) {
- return "";
- } else {
- return kvArray[1];
- }
- }).toArray(String[]::new);
- }
+ return Arrays.stream(fieldKV).map(kv -> {
+ final String[] kvArray = kv.split(":");
+ if (kvArray[1].equals(NULL_RECORDKEY_PLACEHOLDER)) {
+ return null;
+ } else if (kvArray[1].equals(EMPTY_RECORDKEY_PLACEHOLDER)) {
+ return "";
+ } else {
+ return kvArray[1];
+ }
+ }).toArray(String[]::new);
}
public static String getRecordKey(GenericRecord record, List<String> recordKeyFields, boolean consistentLogicalTimestampEnabled) {
diff --git a/hudi-client/hudi-client-common/src/test/java/org/apache/hudi/keygen/TestKeyGenUtils.java b/hudi-client/hudi-client-common/src/test/java/org/apache/hudi/keygen/TestKeyGenUtils.java
new file mode 100644
index 0000000000..06a6fcd7d7
--- /dev/null
+++ b/hudi-client/hudi-client-common/src/test/java/org/apache/hudi/keygen/TestKeyGenUtils.java
@@ -0,0 +1,37 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.hudi.keygen;
+
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+public class TestKeyGenUtils {
+
+ @Test
+ public void testExtractRecordKeys() {
+ String[] s1 = KeyGenUtils.extractRecordKeys("id:1");
+ Assertions.assertArrayEquals(new String[]{"1"}, s1);
+
+ String[] s2 = KeyGenUtils.extractRecordKeys("id:1,id:2");
+ Assertions.assertArrayEquals(new String[]{"1", "2"}, s2);
+
+ String[] s3 = KeyGenUtils.extractRecordKeys("id:1,id2:__null__,id3:__empty__");
+ Assertions.assertArrayEquals(new String[]{"1", null, ""}, s3);
+ }
+}