Skip to content

Commit a12b943

Browse files
authored
[FLINK-32772] Add support of SET statements in the SQL Runner example
1 parent 48d6703 commit a12b943

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

Diff for: examples/flink-sql-runner-example/src/main/java/org/apache/flink/examples/SqlRunner.java

+16-2
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
import java.io.File;
2828
import java.util.ArrayList;
2929
import java.util.List;
30+
import java.util.regex.Matcher;
31+
import java.util.regex.Pattern;
3032

3133
/** Main class for executing SQL scripts. */
3234
public class SqlRunner {
@@ -38,6 +40,9 @@ public class SqlRunner {
3840

3941
private static final String COMMENT_PATTERN = "(--.*)|(((\\/\\*)+?[\\w\\W]+?(\\*\\/)+))";
4042

43+
private static final Pattern SET_STATEMENT_PATTERN =
44+
Pattern.compile("SET\\s+'(\\S+)'\\s+=\\s+'(.*)';", Pattern.CASE_INSENSITIVE);
45+
4146
public static void main(String[] args) throws Exception {
4247
if (args.length != 1) {
4348
throw new Exception("Exactly one argument is expected.");
@@ -48,8 +53,17 @@ public static void main(String[] args) throws Exception {
4853
var tableEnv = TableEnvironment.create(new Configuration());
4954

5055
for (String statement : statements) {
51-
LOG.info("Executing:\n{}", statement);
52-
tableEnv.executeSql(statement);
56+
Matcher setMatcher = SET_STATEMENT_PATTERN.matcher(statement.trim());
57+
58+
if (setMatcher.matches()) {
59+
// Handle SET statements
60+
String key = setMatcher.group(1);
61+
String value = setMatcher.group(2);
62+
tableEnv.getConfig().getConfiguration().setString(key, value);
63+
} else {
64+
LOG.info("Executing:\n{}", statement);
65+
tableEnv.executeSql(statement);
66+
}
5367
}
5468
}
5569

0 commit comments

Comments
 (0)