tajo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jihoon...@apache.org
Subject [8/9] git commit: TAJO-961: TajoCli should exit when at least one query faces error while executing a SQL script. (hyunsik)
Date Mon, 21 Jul 2014 01:02:15 GMT
TAJO-961: TajoCli should exit when at least one query faces error while executing a SQL script.
(hyunsik)

Closes #84


Project: http://git-wip-us.apache.org/repos/asf/tajo/repo
Commit: http://git-wip-us.apache.org/repos/asf/tajo/commit/6dac6a5b
Tree: http://git-wip-us.apache.org/repos/asf/tajo/tree/6dac6a5b
Diff: http://git-wip-us.apache.org/repos/asf/tajo/diff/6dac6a5b

Branch: refs/heads/index_support
Commit: 6dac6a5b8764720a40740f7bb27ef48be1c0f7d5
Parents: b1b16d5
Author: Hyunsik Choi <hyunsik@apache.org>
Authored: Mon Jul 21 00:06:43 2014 +0900
Committer: Hyunsik Choi <hyunsik@apache.org>
Committed: Mon Jul 21 00:06:43 2014 +0900

----------------------------------------------------------------------
 CHANGES                                         |  3 ++
 .../main/java/org/apache/tajo/cli/TajoCli.java  | 41 ++++++++++++--------
 2 files changed, 27 insertions(+), 17 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tajo/blob/6dac6a5b/CHANGES
----------------------------------------------------------------------
diff --git a/CHANGES b/CHANGES
index 27593fc..4010042 100644
--- a/CHANGES
+++ b/CHANGES
@@ -97,6 +97,9 @@ Release 0.9.0 - unreleased
 
   BUG FIXES
 
+    TAJO-961: TajoCli should exit when at least one query faces error while
+    executing a SQL script. (hyunsik)
+
     TAJO-960: TajoCli's problem does not show the current status. (hyunsik)
 
     TAJO-945: Connecting to Tajo by JDBC driver failed with SQL Exception 

http://git-wip-us.apache.org/repos/asf/tajo/blob/6dac6a5b/tajo-client/src/main/java/org/apache/tajo/cli/TajoCli.java
----------------------------------------------------------------------
diff --git a/tajo-client/src/main/java/org/apache/tajo/cli/TajoCli.java b/tajo-client/src/main/java/org/apache/tajo/cli/TajoCli.java
index a97d08e..98a5bf4 100644
--- a/tajo-client/src/main/java/org/apache/tajo/cli/TajoCli.java
+++ b/tajo-client/src/main/java/org/apache/tajo/cli/TajoCli.java
@@ -202,9 +202,9 @@ public class TajoCli {
 
     if (cmd.hasOption("c")) {
       outputFormatter.setScirptMode();
-      executeScript(cmd.getOptionValue("c"));
+      int exitCode = executeScript(cmd.getOptionValue("c"));
       sout.flush();
-      System.exit(0);
+      System.exit(exitCode);
     }
     if (cmd.hasOption("f")) {
       outputFormatter.setScirptMode();
@@ -213,9 +213,9 @@ public class TajoCli {
       if (sqlFile.exists()) {
         String script = FileUtil.readTextFile(new File(cmd.getOptionValue("f")));
         script = replaceParam(script, cmd.getOptionValues("param"));
-        executeScript(script);
+        int exitCode = executeScript(script);
         sout.flush();
-        System.exit(0);
+        System.exit(exitCode);
       } else {
         System.err.println(ERROR_PREFIX + "No such a file \"" + cmd.getOptionValue("f") +
"\"");
         System.exit(-1);
@@ -308,7 +308,7 @@ public class TajoCli {
   public int runShell() throws Exception {
     String line;
     String currentPrompt = context.getCurrentDatabase();
-    int code = 0;
+    int exitCode = 0;
 
     sout.write("Try \\? for help.\n");
 
@@ -328,25 +328,32 @@ public class TajoCli {
             history.addStatement(parsed.getHistoryStatement() + (parsed.getType() == STATEMENT
? ";" : ""));
           }
         }
-        executeParsedResults(parsedResults);
+        exitCode = executeParsedResults(parsedResults);
         currentPrompt = updatePrompt(parser.getState());
+
+        if (exitCode != 0 && context.getConf().getBoolVar(ConfVars.CLI_ERROR_STOP))
{
+          return exitCode;
+        }
       }
     }
-    return code;
+    return exitCode;
   }
 
-  private void executeParsedResults(Collection<ParsedResult> parsedResults) throws
Exception {
+  private int executeParsedResults(Collection<ParsedResult> parsedResults) throws Exception
{
+    int exitCode = 0;
     for (ParsedResult parsedResult : parsedResults) {
       if (parsedResult.getType() == META) {
-        executeMetaCommand(parsedResult.getStatement());
+        exitCode = executeMetaCommand(parsedResult.getStatement());
       } else {
-        executeQuery(parsedResult.getStatement());
+        exitCode = executeQuery(parsedResult.getStatement());
       }
 
-      if (wasError && context.getConf().getBoolVar(ConfVars.CLI_ERROR_STOP)) {
-        break;
+      if (exitCode != 0) {
+        return exitCode;
       }
     }
+
+    return exitCode;
   }
 
   public int executeMetaCommand(String line) throws Exception {
@@ -409,7 +416,7 @@ public class TajoCli {
     }
   }
 
-  private void executeQuery(String statement) throws ServiceException {
+  private int executeQuery(String statement) throws ServiceException {
     long startTime = System.currentTimeMillis();
     ClientProtos.SubmitQueryResponse response = client.executeQuery(statement);
     if (response == null) {
@@ -432,6 +439,8 @@ public class TajoCli {
         wasError = true;
       }
     }
+
+    return wasError ? -1 : 0;
   }
 
   private void localQueryCompleted(ClientProtos.SubmitQueryResponse response, long startTime)
{
@@ -538,8 +547,7 @@ public class TajoCli {
   public int executeScript(String script) throws Exception {
     wasError = false;
     List<ParsedResult> results = SimpleParser.parseScript(script);
-    executeParsedResults(results);
-    return 0;
+    return executeParsedResults(results);
   }
 
   private void printUsage() {
@@ -562,7 +570,6 @@ public class TajoCli {
     TajoConf conf = new TajoConf();
     TajoCli shell = new TajoCli(conf, args, System.in, System.out);
     System.out.println();
-    int status = shell.runShell();
-    System.exit(status);
+    System.exit(shell.runShell());
   }
 }


Mime
View raw message