KurtYoung commented on a change in pull request #15437:
URL: https://github.com/apache/flink/pull/15437#discussion_r604839697
##########
File path:
flink-table/flink-sql-client/src/main/java/org/apache/flink/table/client/cli/CliClient.java
##########
@@ -223,14 +199,69 @@ public Executor getExecutor() {
return executor;
}
+ /** Closes the CLI instance. */
+ public void close() {
+ if (terminal != null) {
+ closeTerminal();
+ }
+ }
+
/** Opens the interactive CLI shell. */
- public void open() {
+ public void executeInInteractiveMode() {
+ terminal = TerminalUtils.createDefaultTerminal(useSystemInOutStream);
+
+ try {
+ executeInteractive();
+ } catch (Exception e) {
Review comment:
replace with try finally
##########
File path:
flink-table/flink-sql-client/src/main/java/org/apache/flink/table/client/cli/CliClient.java
##########
@@ -223,14 +199,69 @@ public Executor getExecutor() {
return executor;
}
+ /** Closes the CLI instance. */
+ public void close() {
+ if (terminal != null) {
+ closeTerminal();
+ }
+ }
+
/** Opens the interactive CLI shell. */
- public void open() {
+ public void executeInInteractiveMode() {
+ terminal = TerminalUtils.createDefaultTerminal(useSystemInOutStream);
+
+ try {
+ executeInteractive();
+ } catch (Exception e) {
+ closeTerminal();
+ throw e;
+ }
+ }
+
+ public void executeInNonInteractiveMode(String content) {
+ terminal = TerminalUtils.createDefaultTerminal(useSystemInOutStream);
+ executeFile(content, ExecutionMode.NON_INTERACTIVE_EXECUTION);
+ closeTerminal();
+ }
+
+ public boolean executeInitialization(String content) {
+ OutputStream outputStream = new ByteArrayOutputStream(256);
+ terminal = TerminalUtils.createDummyTerminal(outputStream);
+ boolean success = executeFile(content, ExecutionMode.INITIALIZATION);
+ LOG.info(outputStream.toString());
+ closeTerminal();
Review comment:
ditto
##########
File path:
flink-table/flink-sql-client/src/main/java/org/apache/flink/table/client/cli/CliClient.java
##########
@@ -223,14 +199,69 @@ public Executor getExecutor() {
return executor;
}
+ /** Closes the CLI instance. */
+ public void close() {
+ if (terminal != null) {
+ closeTerminal();
+ }
+ }
+
/** Opens the interactive CLI shell. */
- public void open() {
+ public void executeInInteractiveMode() {
+ terminal = TerminalUtils.createDefaultTerminal(useSystemInOutStream);
+
+ try {
+ executeInteractive();
+ } catch (Exception e) {
+ closeTerminal();
+ throw e;
+ }
+ }
+
+ public void executeInNonInteractiveMode(String content) {
+ terminal = TerminalUtils.createDefaultTerminal(useSystemInOutStream);
+ executeFile(content, ExecutionMode.NON_INTERACTIVE_EXECUTION);
+ closeTerminal();
Review comment:
also protect with finally?
##########
File path:
flink-table/flink-sql-client/src/main/java/org/apache/flink/table/client/cli/CliClient.java
##########
@@ -223,14 +199,69 @@ public Executor getExecutor() {
return executor;
}
+ /** Closes the CLI instance. */
+ public void close() {
+ if (terminal != null) {
+ closeTerminal();
+ }
+ }
+
/** Opens the interactive CLI shell. */
- public void open() {
+ public void executeInInteractiveMode() {
+ terminal = TerminalUtils.createDefaultTerminal(useSystemInOutStream);
+
+ try {
+ executeInteractive();
+ } catch (Exception e) {
+ closeTerminal();
+ throw e;
+ }
+ }
+
+ public void executeInNonInteractiveMode(String content) {
+ terminal = TerminalUtils.createDefaultTerminal(useSystemInOutStream);
+ executeFile(content, ExecutionMode.NON_INTERACTIVE_EXECUTION);
+ closeTerminal();
+ }
+
+ public boolean executeInitialization(String content) {
+ OutputStream outputStream = new ByteArrayOutputStream(256);
+ terminal = TerminalUtils.createDummyTerminal(outputStream);
+ boolean success = executeFile(content, ExecutionMode.INITIALIZATION);
+ LOG.info(outputStream.toString());
+ closeTerminal();
+ return success;
+ }
+
+ //
--------------------------------------------------------------------------------------------
+
+ enum ExecutionMode {
+ INTERACTIVE_EXECUTION,
+
+ NON_INTERACTIVE_EXECUTION,
+
+ INITIALIZATION
+ }
+
+ //
--------------------------------------------------------------------------------------------
+
+ /**
+ * Execute statement from the user input and prints status information
and/or errors on the
+ * terminal.
+ */
+ @VisibleForTesting
+ void executeInteractive() {
isRunning = true;
+ LineReader lineReader = createLineReader(terminal);
+ // begin reading loop
Review comment:
wrong place of comment?
##########
File path:
flink-table/flink-sql-client/src/main/java/org/apache/flink/table/client/SqlClient.java
##########
@@ -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.",
Review comment:
%s. -> %s
It looks like the period is part of the file name
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]