IMPALA-4418: Fixes extra blank lines in query result This change avoids printing blank lines when the Impala shell fetches 0 rows from a statement.
Change-Id: I6e18ce36be07ee90a16b007b1e30d5255ef8a839 Reviewed-on: http://gerrit.cloudera.org:8080/7055 Reviewed-by: Alex Behm <[email protected]> Tested-by: Impala Public Jenkins Project: http://git-wip-us.apache.org/repos/asf/incubator-impala/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-impala/commit/1fc7e657 Tree: http://git-wip-us.apache.org/repos/asf/incubator-impala/tree/1fc7e657 Diff: http://git-wip-us.apache.org/repos/asf/incubator-impala/diff/1fc7e657 Branch: refs/heads/master Commit: 1fc7e65723869e8d8f32d726044b2fefb89aa1e6 Parents: 6d5cd61 Author: Vincent Tran <[email protected]> Authored: Fri Jun 2 01:12:22 2017 -0400 Committer: Impala Public Jenkins <[email protected]> Committed: Fri Jun 16 09:33:40 2017 +0000 ---------------------------------------------------------------------- shell/impala_shell.py | 3 +++ tests/shell/test_shell_interactive.py | 15 +++++++++++++++ 2 files changed, 18 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/1fc7e657/shell/impala_shell.py ---------------------------------------------------------------------- diff --git a/shell/impala_shell.py b/shell/impala_shell.py index d143ef1..cbfa8a5 100755 --- a/shell/impala_shell.py +++ b/shell/impala_shell.py @@ -919,6 +919,9 @@ class ImpalaShell(cmd.Cmd): num_rows = 0 for rows in rows_fetched: + # IMPALA-4418: Break out of the loop to prevent printing an unnecessary empty line. + if len(rows) == 0: + break self.output_stream.write(rows) num_rows += len(rows) http://git-wip-us.apache.org/repos/asf/incubator-impala/blob/1fc7e657/tests/shell/test_shell_interactive.py ---------------------------------------------------------------------- diff --git a/tests/shell/test_shell_interactive.py b/tests/shell/test_shell_interactive.py index 76e8f45..9222637 100755 --- a/tests/shell/test_shell_interactive.py +++ b/tests/shell/test_shell_interactive.py @@ -21,6 +21,7 @@ import os import pexpect import pytest +import re import shutil import signal import socket @@ -287,6 +288,20 @@ class TestImpalaShellInteractive(object): result = run_impala_shell_interactive("source %s;" % full_path) assert "No such file or directory" in result.stderr + @pytest.mark.execute_serially + def test_zero_row_fetch(self): + # IMPALA-4418: DROP and USE are generally exceptional statements where + # the client does not fetch. However, when preceded by a comment, the + # Impala shell treats them like any other statement and will try to + # fetch - receiving 0 rows. For statements returning 0 rows we do not + # want an empty line in stdout. + result = run_impala_shell_interactive("-- foo \n use default;") + assert "Fetched 0 row(s)" in result.stderr + assert re.search('> \[', result.stdout) + result = run_impala_shell_interactive("select * from functional.alltypes limit 0;") + assert "Fetched 0 row(s)" in result.stderr + assert re.search('> \[', result.stdout) + def run_impala_shell_interactive(input_lines, shell_args=None): """Runs a command in the Impala shell interactively.""" # if argument "input_lines" is a string, makes it into a list
