tajo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jihoon...@apache.org
Subject tajo git commit: TAJO-1782: Check ON_ERROR_STOP flag in TSQL when error is occured.
Date Wed, 09 Sep 2015 07:59:28 GMT
Repository: tajo
Updated Branches:
  refs/heads/master 1cdd018d9 -> 745818b7f


TAJO-1782: Check ON_ERROR_STOP flag in TSQL when error is occured.

Closes #711

Signed-off-by: Jihoon Son <jihoonson@apache.org>


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

Branch: refs/heads/master
Commit: 745818b7f921b2b3bc400cdc272526e132ec4ac9
Parents: 1cdd018
Author: Dongkyu Hwangbo <dkhwangbo>
Authored: Wed Sep 9 16:59:07 2015 +0900
Committer: Jihoon Son <jihoonson@apache.org>
Committed: Wed Sep 9 16:59:07 2015 +0900

----------------------------------------------------------------------
 CHANGES                                         |  3 ++
 .../java/org/apache/tajo/cli/tsql/TajoCli.java  | 13 ++++----
 .../org/apache/tajo/cli/tsql/TestTajoCli.java   | 35 ++++++++++++++++++++
 3 files changed, 44 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tajo/blob/745818b7/CHANGES
----------------------------------------------------------------------
diff --git a/CHANGES b/CHANGES
index 303dbe3..cb85512 100644
--- a/CHANGES
+++ b/CHANGES
@@ -255,6 +255,9 @@ Release 0.11.0 - unreleased
 
   BUG FIXES
 
+    TAJO-1782: Check ON_ERROR_STOP flag in TSQL when error is occured. 
+    (Contributed by Dongkyu Hwangbo, Committed by jihoon)
+
     TAJO-1829: Fix DelimitedTextFileAppender NPE in negative tests. (jinho)
 
     TAJO-1674: Validation of CTAS schema mismatch. (hyunsik)

http://git-wip-us.apache.org/repos/asf/tajo/blob/745818b7/tajo-cli/src/main/java/org/apache/tajo/cli/tsql/TajoCli.java
----------------------------------------------------------------------
diff --git a/tajo-cli/src/main/java/org/apache/tajo/cli/tsql/TajoCli.java b/tajo-cli/src/main/java/org/apache/tajo/cli/tsql/TajoCli.java
index affd128..f17ec80 100644
--- a/tajo-cli/src/main/java/org/apache/tajo/cli/tsql/TajoCli.java
+++ b/tajo-cli/src/main/java/org/apache/tajo/cli/tsql/TajoCli.java
@@ -36,7 +36,6 @@ import org.apache.tajo.conf.TajoConf.ConfVars;
 import org.apache.tajo.exception.ExceptionUtil;
 import org.apache.tajo.exception.ReturnStateUtil;
 import org.apache.tajo.exception.TajoException;
-import org.apache.tajo.exception.DefaultTajoException;
 import org.apache.tajo.ipc.ClientProtos;
 import org.apache.tajo.service.ServiceTrackerFactory;
 import org.apache.tajo.util.FileUtil;
@@ -405,7 +404,7 @@ public class TajoCli {
     sout.write("Try \\? for help.\n");
 
     SimpleParser parser = new SimpleParser();
-    
+
     try {
       while((line = reader.readLine(currentPrompt + "> ")) != null) {
         if (line.equals("")) {
@@ -427,19 +426,19 @@ public class TajoCli {
           latestState = parser.getState();
           currentPrompt = updatePrompt(latestState);
 
-          // if at least one failed
-          if (exitCode != 0) {
+          // If the ON_ERROR_STOP flag is set, Cli should stop on query failure.
+          if (exitCode != 0 && context.getBool(SessionVars.ON_ERROR_STOP)) {
             return exitCode;
           }
         }
       }
     } catch (Exception e) {
-      System.err.println(ERROR_PREFIX + "Exception was thrown. Casued by " + e.getMessage());
-      
+      System.err.println(ERROR_PREFIX + "Exception was thrown. Caused by " + e.getMessage());
+
       if (client != null) {
         client.close();
       }
-      
+
       throw e;
     }
     return 0;

http://git-wip-us.apache.org/repos/asf/tajo/blob/745818b7/tajo-core-tests/src/test/java/org/apache/tajo/cli/tsql/TestTajoCli.java
----------------------------------------------------------------------
diff --git a/tajo-core-tests/src/test/java/org/apache/tajo/cli/tsql/TestTajoCli.java b/tajo-core-tests/src/test/java/org/apache/tajo/cli/tsql/TestTajoCli.java
index 5005670..8ddef09 100644
--- a/tajo-core-tests/src/test/java/org/apache/tajo/cli/tsql/TestTajoCli.java
+++ b/tajo-core-tests/src/test/java/org/apache/tajo/cli/tsql/TestTajoCli.java
@@ -362,6 +362,41 @@ public class TestTajoCli {
   }
 
   @Test
+  public void testRunWhenError() throws Exception {
+    Thread t = new Thread() {
+      public void run() {
+        try {
+          PipedOutputStream po = new PipedOutputStream();
+          InputStream is = new PipedInputStream(po);
+          ByteArrayOutputStream out = new ByteArrayOutputStream();
+
+          TajoConf tajoConf = new TajoConf();
+          setVar(tajoCli, SessionVars.CLI_FORMATTER_CLASS, TajoCliOutputTestFormatter.class.getName());
+          TajoCli tc = new TajoCli(tajoConf, new String[]{}, is, out);
+
+          tc.executeMetaCommand("\\set ON_ERROR_STOP false");
+          assertSessionVar(tc, SessionVars.ON_ERROR_STOP.keyname(), "false");
+
+          po.write(new String("asdf;\nqwe;\nzxcv;\n").getBytes());
+
+          tc.runShell();
+        } catch (Exception e) {
+          throw new RuntimeException("Cannot run thread in testRunWhenError", e);
+        }
+      }
+    };
+
+    t.start();
+    Thread.sleep(1000);
+    if(!t.isAlive()) {
+      fail("TSQL should be alive");
+    } else {
+      t.interrupt();
+      t.join();
+    }
+  }
+
+  @Test
   public void testHelpSessionVars() throws Exception {
     tajoCli.executeMetaCommand("\\help set");
     assertOutputResult(new String(out.toByteArray()));


Mime
View raw message