18
18
package com .datasqrl ;
19
19
20
20
import java .io .File ;
21
- import java .util .*;
21
+ import java .util .Map ;
22
+ import java .util .TreeMap ;
22
23
import java .util .concurrent .Callable ;
23
24
import lombok .SneakyThrows ;
24
25
import lombok .extern .slf4j .Slf4j ;
29
30
import org .apache .flink .table .api .TableResult ;
30
31
import org .apache .flink .util .FileUtils ;
31
32
import picocli .CommandLine ;
32
- import picocli .CommandLine .*;
33
+ import picocli .CommandLine .Command ;
34
+ import picocli .CommandLine .Option ;
33
35
34
36
/** Main class for executing SQL scripts using picocli. */
35
37
@ Command (
@@ -67,7 +69,7 @@ public class SqlRunner implements Callable<Integer> {
67
69
private String udfPath ;
68
70
69
71
public static void main (String [] args ) {
70
- int exitCode = new CommandLine (new SqlRunner ()).execute (args );
72
+ var exitCode = new CommandLine (new SqlRunner ()).execute (args );
71
73
System .exit (exitCode );
72
74
}
73
75
@@ -79,22 +81,27 @@ public Integer call() throws Exception {
79
81
}
80
82
81
83
// Load configuration if configFile is provided
82
- Configuration configuration = new Configuration ();
84
+ var configuration = new Configuration ();
83
85
if (configFile != null ) {
84
86
configuration = loadConfigurationFromYaml (configFile );
85
87
}
86
88
89
+ log .info ("Environment variables" );
90
+ TreeMap <String , String > envVariables = new TreeMap <>(System .getenv ());
91
+ envVariables .forEach ((name , value ) -> log .info ("{}: {}" , name , value ));
92
+
87
93
// Initialize SqlExecutor
88
- SqlExecutor sqlExecutor = new SqlExecutor (configuration , udfPath );
94
+ var sqlExecutor = new SqlExecutor (configuration , udfPath , envVariables );
89
95
TableResult tableResult ;
90
96
// Input validation and execution logic
91
97
if (sqlFile != null ) {
92
98
// Single SQL file mode
93
- String script = FileUtils .readFileUtf8 (sqlFile );
99
+ var script = FileUtils .readFileUtf8 (sqlFile );
100
+ EnvironmentVariablesUtils .validateEnvironmentVariables (envVariables , script );
94
101
tableResult = sqlExecutor .executeScript (script );
95
102
} else if (planFile != null ) {
96
103
// Compiled plan JSON file
97
- String planJson = FileUtils .readFileUtf8 (planFile );
104
+ var planJson = FileUtils .readFileUtf8 (planFile );
98
105
planJson = replaceScriptWithEnv (planJson );
99
106
100
107
tableResult = sqlExecutor .executeCompiledPlan (planJson );
@@ -120,10 +127,10 @@ private String replaceScriptWithEnv(String script) {
120
127
}
121
128
122
129
public static ObjectMapper getObjectMapper () {
123
- ObjectMapper objectMapper = new ObjectMapper ();
130
+ var objectMapper = new ObjectMapper ();
124
131
125
132
// Register the custom deserializer module
126
- SimpleModule module = new SimpleModule ();
133
+ var module = new SimpleModule ();
127
134
module .addDeserializer (String .class , new JsonEnvVarDeserializer ());
128
135
objectMapper .registerModule (module );
129
136
return objectMapper ;
@@ -138,8 +145,7 @@ public static ObjectMapper getObjectMapper() {
138
145
*/
139
146
private Configuration loadConfigurationFromYaml (File configFile ) throws Exception {
140
147
log .info ("Loading configuration from {}" , configFile .getAbsolutePath ());
141
- Configuration configuration =
142
- GlobalConfiguration .loadConfiguration (configFile .getAbsolutePath ());
148
+ var configuration = GlobalConfiguration .loadConfiguration (configFile .getAbsolutePath ());
143
149
return configuration ;
144
150
}
145
151
}
0 commit comments