tajo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hyun...@apache.org
Subject [04/50] [abbrv] git commit: TAJO-793: CLI should be able to exit when single query is failed. (Hyoungjun Kim via jinho)
Date Wed, 09 Jul 2014 04:10:21 GMT
TAJO-793: CLI should be able to exit when single query is failed. (Hyoungjun Kim via jinho)

Closes #25


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

Branch: refs/heads/window_function
Commit: d365e9e17e0ee5074d98f9d9c2f20cbb2f326ec6
Parents: 8e65022
Author: jinossy <jinossy@gmail.com>
Authored: Mon Jun 2 17:18:51 2014 +0900
Committer: jinossy <jinossy@gmail.com>
Committed: Mon Jun 2 17:18:51 2014 +0900

----------------------------------------------------------------------
 CHANGES                                         |  3 +++
 .../tajo/cli/DefaultTajoCliOutputFormatter.java |  6 +++++
 .../main/java/org/apache/tajo/cli/TajoCli.java  | 25 +++++++++++++++++++-
 .../java/org/apache/tajo/conf/TajoConf.java     |  1 +
 .../java/org/apache/tajo/cli/TestTajoCli.java   | 17 +++++++++++++
 .../TestTajoCli/testStopWhenError.result        |  5 ++++
 6 files changed, 56 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tajo/blob/d365e9e1/CHANGES
----------------------------------------------------------------------
diff --git a/CHANGES b/CHANGES
index 9121a85..b5f5189 100644
--- a/CHANGES
+++ b/CHANGES
@@ -15,6 +15,9 @@ Release 0.9.0 - unreleased
 
   IMPROVEMENT
 
+    TAJO-793: CLI should be able to exit when single query is failed.
+    (Hyoungjun Kim via jinho)
+
     TAJO-846: Clean up the task history in woker. (jinho)
 
     TAJO-842: NULL handling in JDBC. (Hyoungjun Kim via jinho)

http://git-wip-us.apache.org/repos/asf/tajo/blob/d365e9e1/tajo-client/src/main/java/org/apache/tajo/cli/DefaultTajoCliOutputFormatter.java
----------------------------------------------------------------------
diff --git a/tajo-client/src/main/java/org/apache/tajo/cli/DefaultTajoCliOutputFormatter.java
b/tajo-client/src/main/java/org/apache/tajo/cli/DefaultTajoCliOutputFormatter.java
index a619981..62736b5 100644
--- a/tajo-client/src/main/java/org/apache/tajo/cli/DefaultTajoCliOutputFormatter.java
+++ b/tajo-client/src/main/java/org/apache/tajo/cli/DefaultTajoCliOutputFormatter.java
@@ -128,6 +128,7 @@ public class DefaultTajoCliOutputFormatter implements TajoCliOutputFormatter
{
   @Override
   public void printNoResult(PrintWriter sout) {
     sout.println("(0 rows)");
+    sout.flush();
   }
 
   @Override
@@ -141,6 +142,7 @@ public class DefaultTajoCliOutputFormatter implements TajoCliOutputFormatter
{
   @Override
   public void printMessage(PrintWriter sout, String message) {
     sout.println(message);
+    sout.flush();
   }
 
   @Override
@@ -149,16 +151,19 @@ public class DefaultTajoCliOutputFormatter implements TajoCliOutputFormatter
{
     if (printErrorTrace) {
       sout.println(ExceptionUtils.getStackTrace(t));
     }
+    sout.flush();
   }
 
   @Override
   public void printErrorMessage(PrintWriter sout, String message) {
     sout.println(parseErrorMessage(message));
+    sout.flush();
   }
 
   @Override
   public void printKilledMessage(PrintWriter sout, QueryId queryId) {
     sout.println(TajoCli.KILL_PREFIX + queryId);
+    sout.flush();
   }
 
   @Override
@@ -171,6 +176,7 @@ public class DefaultTajoCliOutputFormatter implements TajoCliOutputFormatter
{
     if (printErrorTrace && status.getErrorTrace() != null && !status.getErrorTrace().isEmpty())
{
       sout.println(status.getErrorTrace());
     }
+    sout.flush();
   }
 
   public static String parseErrorMessage(String message) {

http://git-wip-us.apache.org/repos/asf/tajo/blob/d365e9e1/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 85787ca..1fc27dc 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
@@ -64,6 +64,8 @@ public class TajoCli {
 
   private TajoCliOutputFormatter outputFormatter;
 
+  private boolean wasError = false;
+
   private static final Class [] registeredCommands = {
       DescTableCommand.class,
       DescFunctionCommand.class,
@@ -315,7 +317,7 @@ public class TajoCli {
       if (line.equals("")) {
         continue;
       }
-
+      wasError = false;
       if (line.startsWith("{")) {
         executeJsonQuery(line);
       } else {
@@ -340,6 +342,10 @@ public class TajoCli {
       } else {
         executeQuery(parsedResult.getStatement());
       }
+
+      if (wasError && context.getConf().getBoolVar(ConfVars.CLI_ERROR_STOP)) {
+        break;
+      }
     }
   }
 
@@ -351,6 +357,7 @@ public class TajoCli {
       TajoShellCommand invoked = commands.get(arguments[0]);
       if (invoked == null) {
         printInvalidCommand(arguments[0]);
+        wasError = true;
         return -1;
       }
 
@@ -358,13 +365,19 @@ public class TajoCli {
         invoked.invoke(arguments);
       } catch (IllegalArgumentException ige) {
         outputFormatter.printErrorMessage(sout, ige);
+        wasError = true;
         return -1;
       } catch (Exception e) {
         outputFormatter.printErrorMessage(sout, e);
+        wasError = true;
         return -1;
       } finally {
         context.getOutput().flush();
       }
+
+      if (wasError && context.getConf().getBoolVar(ConfVars.CLI_ERROR_STOP)) {
+        break;
+      }
     }
 
     return 0;
@@ -375,6 +388,7 @@ public class TajoCli {
     ClientProtos.SubmitQueryResponse response = client.executeQueryWithJson(json);
     if (response == null) {
       outputFormatter.printErrorMessage(sout, "response is null");
+      wasError = true;
     } else if (response.getResultCode() == ClientProtos.ResultCode.OK) {
       if (response.getIsForwarded()) {
         QueryId queryId = new QueryId(response.getQueryId());
@@ -382,6 +396,7 @@ public class TajoCli {
       } else {
         if (!response.hasTableDesc() && !response.hasResultSet()) {
           outputFormatter.printMessage(sout, "OK");
+          wasError = true;
         } else {
           localQueryCompleted(response, startTime);
         }
@@ -389,6 +404,7 @@ public class TajoCli {
     } else {
       if (response.hasErrorMessage()) {
         outputFormatter.printErrorMessage(sout, response.getErrorMessage());
+        wasError = true;
       }
     }
   }
@@ -398,6 +414,7 @@ public class TajoCli {
     ClientProtos.SubmitQueryResponse response = client.executeQuery(statement);
     if (response == null) {
       outputFormatter.printErrorMessage(sout, "response is null");
+      wasError = true;
     } else if (response.getResultCode() == ClientProtos.ResultCode.OK) {
       if (response.getIsForwarded()) {
         QueryId queryId = new QueryId(response.getQueryId());
@@ -412,6 +429,7 @@ public class TajoCli {
     } else {
       if (response.hasErrorMessage()) {
         outputFormatter.printErrorMessage(sout, response.getErrorMessage());
+        wasError = true;
       }
     }
   }
@@ -433,6 +451,7 @@ public class TajoCli {
       }
     } catch (Throwable t) {
       outputFormatter.printErrorMessage(sout, t);
+      wasError = true;
     } finally {
       if (res != null) {
         try {
@@ -481,8 +500,10 @@ public class TajoCli {
 
       if (status.getState() == QueryState.QUERY_ERROR || status.getState() == QueryState.QUERY_FAILED)
{
         outputFormatter.printErrorMessage(sout, status);
+        wasError = true;
       } else if (status.getState() == QueryState.QUERY_KILLED) {
         outputFormatter.printKilledMessage(sout, queryId);
+        wasError = true;
       } else {
         if (status.getState() == QueryState.QUERY_SUCCEEDED) {
           float responseTime = ((float)(status.getFinishTime() - status.getSubmitTime())
/ 1000.0f);
@@ -499,6 +520,7 @@ public class TajoCli {
       }
     } catch (Throwable t) {
       outputFormatter.printErrorMessage(sout, t);
+      wasError = true;
     } finally {
       if (res != null) {
         try {
@@ -514,6 +536,7 @@ public class TajoCli {
   }
 
   public int executeScript(String script) throws Exception {
+    wasError = false;
     List<ParsedResult> results = SimpleParser.parseScript(script);
     executeParsedResults(results);
     return 0;

http://git-wip-us.apache.org/repos/asf/tajo/blob/d365e9e1/tajo-common/src/main/java/org/apache/tajo/conf/TajoConf.java
----------------------------------------------------------------------
diff --git a/tajo-common/src/main/java/org/apache/tajo/conf/TajoConf.java b/tajo-common/src/main/java/org/apache/tajo/conf/TajoConf.java
index 5891493..3f2b16f 100644
--- a/tajo-common/src/main/java/org/apache/tajo/conf/TajoConf.java
+++ b/tajo-common/src/main/java/org/apache/tajo/conf/TajoConf.java
@@ -325,6 +325,7 @@ public class TajoConf extends Configuration {
     CLI_PRINT_ERROR_TRACE("tajo.cli.print.error.trace", true),
     CLI_OUTPUT_FORMATTER_CLASS("tajo.cli.output.formatter", "org.apache.tajo.cli.DefaultTajoCliOutputFormatter"),
     CLI_NULL_CHAR("tajo.cli.nullchar", ""),
+    CLI_ERROR_STOP("tajo.cli.error.stop", false),
 
     //TIME & DATE
     TAJO_TIMEZONE("tajo.timezone", System.getProperty("user.timezone")),

http://git-wip-us.apache.org/repos/asf/tajo/blob/d365e9e1/tajo-core/src/test/java/org/apache/tajo/cli/TestTajoCli.java
----------------------------------------------------------------------
diff --git a/tajo-core/src/test/java/org/apache/tajo/cli/TestTajoCli.java b/tajo-core/src/test/java/org/apache/tajo/cli/TestTajoCli.java
index a49f23b..f862cb1 100644
--- a/tajo-core/src/test/java/org/apache/tajo/cli/TestTajoCli.java
+++ b/tajo-core/src/test/java/org/apache/tajo/cli/TestTajoCli.java
@@ -275,6 +275,23 @@ public class TestTajoCli {
     assertEquals(expectedResult, actual);
   }
 
+  @Test
+  public void testStopWhenError() throws Exception {
+    TajoConf tajoConf = TpchTestBase.getInstance().getTestingCluster().getConfiguration();
+    tajoConf.setVar(ConfVars.CLI_OUTPUT_FORMATTER_CLASS, TajoCliOutputTestFormatter.class.getName());
+
+    ByteArrayOutputStream out = new ByteArrayOutputStream();
+    tajoCli = new TajoCli(tajoConf, new String[]{}, System.in, out);
+    tajoCli.executeMetaCommand("\\set tajo.cli.error.stop true");
+
+    tajoCli.executeScript("select count(*) from lineitem; " +
+        "select count(*) from lineitem2; " +
+        "select count(*) from orders");
+
+    String consoleResult = new String(out.toByteArray());
+    assertOutputResult(consoleResult);
+  }
+
   public static class TajoCliOutputTestFormatter extends DefaultTajoCliOutputFormatter {
     @Override
     protected String getResponseTimeReadable(float responseTime) {

http://git-wip-us.apache.org/repos/asf/tajo/blob/d365e9e1/tajo-core/src/test/resources/results/TestTajoCli/testStopWhenError.result
----------------------------------------------------------------------
diff --git a/tajo-core/src/test/resources/results/TestTajoCli/testStopWhenError.result b/tajo-core/src/test/resources/results/TestTajoCli/testStopWhenError.result
new file mode 100644
index 0000000..183e6c5
--- /dev/null
+++ b/tajo-core/src/test/resources/results/TestTajoCli/testStopWhenError.result
@@ -0,0 +1,5 @@
+?count
+-------------------------------
+5
+(1 rows, , 2 B selected)
+ERROR: relation "default.lineitem2" does not exist


Mime
View raw message