34
34
import java .lang .reflect .Method ;
35
35
import java .net .URL ;
36
36
import java .util .Arrays ;
37
+ import java .util .HashMap ;
37
38
import java .util .List ;
39
+ import java .util .Map ;
38
40
import java .util .stream .Collectors ;
39
41
40
42
import static org .apache .flink .client .cli .CliFrontendParser .PYARCHIVE_OPTION ;
@@ -137,6 +139,15 @@ public class CliOptionsParser {
137
139
+ "auto-generate one under your user's home directory." )
138
140
.build ();
139
141
142
+ public static final Option OPTION_CONF = Option
143
+ .builder ("c" )
144
+ .required (false )
145
+ .longOpt ("conf" )
146
+ .numberOfArgs (1 )
147
+ .argName ("dynamic configuration" )
148
+ .desc ("The dynamic configuration that the specified key and value are separated by `=`." )
149
+ .build ();
150
+
140
151
private static final Options EMBEDDED_MODE_CLIENT_OPTIONS =
141
152
getEmbeddedModeClientOptions (new Options ());
142
153
private static final Options GATEWAY_MODE_CLIENT_OPTIONS =
@@ -162,6 +173,7 @@ public static Options getEmbeddedModeClientOptions(Options options) {
162
173
options .addOption (PYARCHIVE_OPTION );
163
174
options .addOption (PYEXEC_OPTION );
164
175
options .addOption (PYCLIENTEXEC_OPTION );
176
+ options .addOption (OPTION_CONF );
165
177
return options ;
166
178
}
167
179
@@ -260,6 +272,30 @@ public static void printHelpGatewayModeGateway() {
260
272
// Line Parsing
261
273
// --------------------------------------------------------------------------------------------
262
274
275
+ private static Map <String , String > getDynamicConfiguration (CommandLine line ) {
276
+ String [] optionValues = line .getOptionValues (CliOptionsParser .OPTION_CONF .getOpt ());
277
+ Map <String , String > dynamicConfMap = new HashMap <>();
278
+ if (optionValues != null && optionValues .length > 0 ) {
279
+ for (String conf : optionValues ) {
280
+ String [] kv = conf .split ("=" , 2 );
281
+ if (kv .length == 1 ) {
282
+ continue ;
283
+ }
284
+
285
+ String key = kv [0 ].trim ();
286
+ String value = kv [1 ].trim ();
287
+
288
+ // sanity check
289
+ if (key .length () == 0 || value .length () == 0 ) {
290
+ continue ;
291
+ }
292
+
293
+ dynamicConfMap .put (key , value );
294
+ }
295
+ }
296
+ return dynamicConfMap ;
297
+ }
298
+
263
299
public static CliOptions parseEmbeddedModeClient (String [] args ) {
264
300
try {
265
301
DefaultParser parser = new DefaultParser ();
@@ -273,7 +309,8 @@ public static CliOptions parseEmbeddedModeClient(String[] args) {
273
309
checkUrls (line , CliOptionsParser .OPTION_LIBRARY ),
274
310
line .getOptionValue (CliOptionsParser .OPTION_UPDATE .getOpt ()),
275
311
line .getOptionValue (CliOptionsParser .OPTION_HISTORY .getOpt ()),
276
- getPythonConfiguration (line ));
312
+ getPythonConfiguration (line ),
313
+ getDynamicConfiguration (line ));
277
314
} catch (ParseException e ) {
278
315
throw new SqlClientException (e .getMessage ());
279
316
}
@@ -292,7 +329,8 @@ public static CliOptions parseGatewayModeClient(String[] args) {
292
329
checkUrls (line , CliOptionsParser .OPTION_LIBRARY ),
293
330
line .getOptionValue (CliOptionsParser .OPTION_UPDATE .getOpt ()),
294
331
line .getOptionValue (CliOptionsParser .OPTION_HISTORY .getOpt ()),
295
- getPythonConfiguration (line ));
332
+ getPythonConfiguration (line ),
333
+ getDynamicConfiguration (line ));
296
334
} catch (ParseException e ) {
297
335
throw new SqlClientException (e .getMessage ());
298
336
}
@@ -311,7 +349,8 @@ public static CliOptions parseGatewayModeGateway(String[] args) {
311
349
checkUrls (line , CliOptionsParser .OPTION_LIBRARY ),
312
350
null ,
313
351
null ,
314
- getPythonConfiguration (line ));
352
+ getPythonConfiguration (line ),
353
+ getDynamicConfiguration (line ));
315
354
} catch (ParseException e ) {
316
355
throw new SqlClientException (e .getMessage ());
317
356
}
0 commit comments