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-3730] Add ConfigTool#toMap UT #6035

Merged
merged 2 commits into from
Jul 4, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,6 @@ public static class HiveSyncConfigParams {
public String bucketSpec;
@Parameter(names = {"--sync-comment"}, description = "synchronize table comments to hive")
public Boolean syncComment;
@Parameter(names = {"--with-operation-field"}, description = "Whether to include the '_hoodie_operation' field in the metadata fields")
public Boolean withOperationField; // TODO remove this as it's not used
voonhous marked this conversation as resolved.
Show resolved Hide resolved

public boolean isHelp() {
return hoodieSyncConfigParams.isHelp();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ public static Map<String, String> toMap(String keyValueConfig) {
String[] keyvalues = keyValueConfig.split("\n");
Map<String, String> tableProperties = new HashMap<>();
for (String keyValue : keyvalues) {
// Handle multiple new lines and lines that contain only spaces after splitting
if (keyValue.trim().isEmpty()) {
continue;
}
String[] keyValueArray = keyValue.split("=");
if (keyValueArray.length == 1 || keyValueArray.length == 2) {
String key = keyValueArray[0].trim();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package org.apache.hudi.sync.common.util;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;

import java.util.HashMap;
import java.util.Map;
import org.junit.jupiter.api.Test;

public class TestConfigUtils {

@Test
public void testToMapSucceeds() {
Map<String, String> expectedMap = new HashMap<>();
expectedMap.put("k.1.1.2", "v1");
expectedMap.put("k.2.1.2", "v2");
expectedMap.put("k.3.1.2", "v3");

// Test base case
String srcKv = "k.1.1.2=v1\nk.2.1.2=v2\nk.3.1.2=v3";
Map<String, String> outMap = ConfigUtils.toMap(srcKv);
assertEquals(expectedMap, outMap);

// Test ends with new line
srcKv = "k.1.1.2=v1\nk.2.1.2=v2\nk.3.1.2=v3\n";
outMap = ConfigUtils.toMap(srcKv);
assertEquals(expectedMap, outMap);

// Test delimited by multiple new lines
srcKv = "k.1.1.2=v1\nk.2.1.2=v2\n\nk.3.1.2=v3";
outMap = ConfigUtils.toMap(srcKv);
assertEquals(expectedMap, outMap);

// Test delimited by multiple new lines with spaces in between
srcKv = "k.1.1.2=v1\n \nk.2.1.2=v2\n\nk.3.1.2=v3";
outMap = ConfigUtils.toMap(srcKv);
assertEquals(expectedMap, outMap);

// Test with random spaces if trim works properly
srcKv = " k.1.1.2 = v1\n k.2.1.2 = v2 \nk.3.1.2 = v3";
outMap = ConfigUtils.toMap(srcKv);
assertEquals(expectedMap, outMap);
}

@Test
public void testToMapThrowError() {
String srcKv = "k.1.1.2=v1=v1.1\nk.2.1.2=v2\nk.3.1.2=v3";
assertThrows(IllegalArgumentException.class, () -> ConfigUtils.toMap(srcKv));
}
}