Skip to content

Commit

Permalink
[FLINK-20320][sql-client] Support init sql file in sql client
Browse files Browse the repository at this point in the history
This closes apache#15437
  • Loading branch information
fsk119 authored and KurtYoung committed Apr 1, 2021
1 parent 39354f3 commit c36bce8
Show file tree
Hide file tree
Showing 13 changed files with 345 additions and 183 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -123,13 +123,27 @@ private void openCli(String sessionId, Executor executor) {
CliOptionsParser.OPTION_FILE.getOpt()));
}

boolean isInteractiveMode = !hasSqlFile && !hasUpdateStatement;

try (CliClient cli = new CliClient(sessionId, executor, historyFilePath)) {
if (isInteractiveMode) {
cli.open();
if (options.getInitFile() != null) {
boolean success = cli.executeInitialization(readFromURL(options.getInitFile()));
if (!success) {
System.out.println(
String.format(
"Failed to initialize from sql script: %s. Please refer to the LOG for detailed error messages.",
options.getInitFile()));
return;
} else {
System.out.println(
String.format(
"Successfully initialized from sql script: %s",
options.getInitFile()));
}
}

if (!hasSqlFile && !hasUpdateStatement) {
cli.executeInInteractiveMode();
} else {
cli.executeSqlFile(readExecutionContent());
cli.executeInNonInteractiveMode(readExecutionContent());
}
}
}
Expand Down
Loading

0 comments on commit c36bce8

Please sign in to comment.