Repository: tajo Updated Branches: refs/heads/branch-0.11.0 5db0f7b0f -> c13b0562f
TAJO-1782: Check ON_ERROR_STOP flag in TSQL when error is occured. Signed-off-by: Jihoon Son <[email protected]> Project: http://git-wip-us.apache.org/repos/asf/tajo/repo Commit: http://git-wip-us.apache.org/repos/asf/tajo/commit/c13b0562 Tree: http://git-wip-us.apache.org/repos/asf/tajo/tree/c13b0562 Diff: http://git-wip-us.apache.org/repos/asf/tajo/diff/c13b0562 Branch: refs/heads/branch-0.11.0 Commit: c13b0562f39f7bbbcf4ffd073f469c32962e1190 Parents: 5db0f7b Author: Dongkyu Hwangbo <dkhwangbo> Authored: Wed Sep 9 18:04:12 2015 +0900 Committer: Jihoon Son <[email protected]> Committed: Wed Sep 9 18:04:47 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/c13b0562/CHANGES ---------------------------------------------------------------------- diff --git a/CHANGES b/CHANGES index b44f184..c7679c8 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/c13b0562/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/c13b0562/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()));
