mirror of
https://github.com/apache/impala.git
synced 2026-01-01 09:00:42 -05:00
Commands with escaped single quotes would cause the shell to enter an infinite loop while trying to parse the command due to shlex not escaping single quotes correctly. Once that change was implemented, shlex would now ignore escaped single and double quotes outside of closed quotes, so there needed to be a check for that as well. ALSO, implemented testing of commands in interactive mode. Needed this to test these inputs, as command line input cannot span multiple lines. Change-Id: Id67368944eeb9a73061bc3e90bd6cda73c9d9f64 Reviewed-on: http://gerrit.sjc.cloudera.com:8080/3408 Reviewed-by: Abdullah Yousufi <abdullah.yousufi@cloudera.com> Tested-by: jenkins Reviewed-on: http://gerrit.sjc.cloudera.com:8080/3893
49 lines
1.8 KiB
Python
49 lines
1.8 KiB
Python
#!/usr/bin/env python
|
|
# encoding=utf-8
|
|
# Copyright 2014 Cloudera Inc.
|
|
#
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
# you may not use this file except in compliance with the License.
|
|
# You may obtain a copy of the License at
|
|
#
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
#
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
# See the License for the specific language governing permissions and
|
|
# limitations under the License.
|
|
|
|
import shlex
|
|
import os
|
|
from subprocess import Popen, PIPE
|
|
import pytest
|
|
from impala_shell_results import get_shell_cmd_result
|
|
|
|
SHELL_CMD = "%s/bin/impala-shell.sh" % os.environ['IMPALA_HOME']
|
|
|
|
class TestImpalaShellInteractive(object):
|
|
"""Test the impala shell interactively"""
|
|
# TODO: Add cancellation tests
|
|
@pytest.mark.execute_serially
|
|
def test_escaped_quotes(self):
|
|
"""Test escaping quotes"""
|
|
# test escaped quotes outside of quotes
|
|
result = run_impala_shell_interactive("select \\'bc';")
|
|
assert "could not match input" in result.stderr
|
|
result = run_impala_shell_interactive("select \\\"bc\";")
|
|
assert "could not match input" in result.stderr
|
|
# test escaped quotes within quotes
|
|
result = run_impala_shell_interactive("select 'ab\\'c';")
|
|
assert "Returned 1 row(s)" in result.stderr
|
|
result = run_impala_shell_interactive("select \"ab\\\"c\";")
|
|
assert "Returned 1 row(s)" in result.stderr
|
|
|
|
def run_impala_shell_interactive(command, shell_args=''):
|
|
"""Runs a command in the Impala shell interactively."""
|
|
cmd = "%s %s" % (SHELL_CMD, shell_args)
|
|
p = Popen(shlex.split(cmd), shell=False, stdout=PIPE, stdin=PIPE, stderr=PIPE)
|
|
p.stdin.write(command + "\n")
|
|
p.stdin.flush()
|
|
return get_shell_cmd_result(p)
|