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

[Bugfix] [seatunnel-starter] When inside double quotes,',' are treated as normal characters instead of delimiters #6042

Merged
merged 4 commits into from
Dec 22, 2023
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ public abstract class AbstractCommandArgs extends CommandArgs {
@Parameter(
names = {"-i", "--variable"},
splitter = ParameterSplitter.class,
description = "Variable substitution, such as -i city=beijing, or -i date=20190318")
description =
"Variable substitution, such as -i city=beijing, or -i date=20190318."
+ "We use ',' as separator, when inside \"\", ',' are treated as normal characters instead of delimiters.")
protected List<String> variables = Collections.emptyList();

/** check config flag */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,29 +19,29 @@
import com.beust.jcommander.converters.IParameterSplitter;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class ParameterSplitter implements IParameterSplitter {

@Override
public List<String> split(String value) {
if (!value.contains(",")) {
return Collections.singletonList(value);
}

List<String> result = new ArrayList<>();
StringBuilder currentToken = new StringBuilder();
boolean insideBrackets = false;
boolean insideQuotes = false;

for (char c : value.toCharArray()) {

if (c == '[') {
insideBrackets = true;
} else if (c == ']') {
insideBrackets = false;
} else if (c == '"') {
insideQuotes = !insideQuotes;
}

if (c == ',' && !insideBrackets) {
if (c == ',' && !insideQuotes && !insideBrackets) {
result.add(currentToken.toString().trim());
currentToken = new StringBuilder();
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ public void testUserDefinedParamsCommand() throws URISyntaxException {
"username=" + username,
"-i",
"list=" + list,
"-i",
"sql=" + "\"select a , b from fake_source_table\""
};
ClientCommandArgs clientCommandArgs =
CommandLineUtils.parse(args, new ClientCommandArgs(), "seatunnel-zeta", true);
Expand Down Expand Up @@ -94,6 +96,8 @@ public void testUserDefinedParamsCommand() throws URISyntaxException {
List<String> list1 = sinkConfig.getStringList("list");
Assertions.assertEquals(list1.get(0), "par1=20230829");
Assertions.assertEquals(list1.get(1), "par2=20230829");
String sql = sinkConfig.getString("sql");
Assertions.assertEquals(sql, "\"select a , b from fake_source_table\"");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,6 @@ sink {
username = ${username}
password = ${password}
list = ${list}
sql = ${sql}
}
}