Skip to content

Commit

Permalink
[apache#2917] fix: Use * instead of {0,} in regular expressions (apac…
Browse files Browse the repository at this point in the history
…he#3052)

### What changes were proposed in this pull request?

Use * instead of {0,} in regular expressions

### Why are the changes needed?

Fix: apache#2917

### Does this PR introduce _any_ user-facing change?

N/A

### How was this patch tested?

UT
  • Loading branch information
zhoukangcn authored Apr 22, 2024
1 parent c7f4cb8 commit 0fdbb58
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public static Map<String, String> extractPropertiesFromSql(String createTableSql
String[] lines = createTableSql.split("\n");

boolean isProperties = false;
final String sProperties = "\"(.*)\"\\s{0,}=\\s{0,}\"(.*)\",?";
final String sProperties = "\"(.*)\"\\s*=\\s*\"(.*)\",?";
final Pattern patternProperties = Pattern.compile(sProperties);

for (String line : lines) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,12 @@ public void testExtractTablePropertiesFromSql() {
result = DorisUtils.extractPropertiesFromSql(createTableSql);
Assertions.assertEquals("test_value1", result.get("test_property1"));
Assertions.assertEquals("test_value2", result.get("test_property2"));

// test when properties has blank
createTableSql =
"CREATE DATABASE `test`\nPROPERTIES (\n\"property1\" = \"value1\",\n\"comment\"= \"comment\"\n)";
result = DorisUtils.extractPropertiesFromSql(createTableSql);
Assertions.assertEquals("value1", result.get("property1"));
Assertions.assertEquals("comment", result.get("comment"));
}
}

0 comments on commit 0fdbb58

Please sign in to comment.