27
27
import java .io .File ;
28
28
import java .util .ArrayList ;
29
29
import java .util .List ;
30
+ import java .util .regex .Matcher ;
31
+ import java .util .regex .Pattern ;
30
32
31
33
/** Main class for executing SQL scripts. */
32
34
public class SqlRunner {
@@ -38,6 +40,9 @@ public class SqlRunner {
38
40
39
41
private static final String COMMENT_PATTERN = "(--.*)|(((\\ /\\ *)+?[\\ w\\ W]+?(\\ *\\ /)+))" ;
40
42
43
+ private static final Pattern SET_STATEMENT_PATTERN =
44
+ Pattern .compile ("SET\\ s+'(\\ S+)'\\ s+=\\ s+'(.*)';" , Pattern .CASE_INSENSITIVE );
45
+
41
46
public static void main (String [] args ) throws Exception {
42
47
if (args .length != 1 ) {
43
48
throw new Exception ("Exactly one argument is expected." );
@@ -48,8 +53,17 @@ public static void main(String[] args) throws Exception {
48
53
var tableEnv = TableEnvironment .create (new Configuration ());
49
54
50
55
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
+ }
53
67
}
54
68
}
55
69
0 commit comments