本文整理匯總了Python中util.ImpalaShell.get_result方法的典型用法代碼示例。如果您正苦於以下問題:Python ImpalaShell.get_result方法的具體用法?Python ImpalaShell.get_result怎麽用?Python ImpalaShell.get_result使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類util.ImpalaShell
的用法示例。
在下文中一共展示了ImpalaShell.get_result方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: test_malformed_query
# 需要導入模塊: from util import ImpalaShell [as 別名]
# 或者: from util.ImpalaShell import get_result [as 別名]
def test_malformed_query(self):
"""Test the handling of malformed query without closing quotation"""
shell = ImpalaShell()
query = "with v as (select 1) \nselect foo('\\\\'), ('bar \n;"
shell.send_cmd(query)
result = shell.get_result()
assert "ERROR: ParseException: Unmatched string literal" in result.stderr
示例2: test_multiline_queries_in_history
# 需要導入模塊: from util import ImpalaShell [as 別名]
# 或者: from util.ImpalaShell import get_result [as 別名]
def test_multiline_queries_in_history(self, tmp_history_file):
"""Test to ensure that multiline queries with comments are preserved in history
Ensure that multiline queries are preserved when they're read back from history.
Additionally, also test that comments are preserved.
"""
# readline gets its input from tty, so using stdin does not work.
child_proc = pexpect.spawn(SHELL_CMD)
# List of (input query, expected text in output).
# The expected output is usually the same as the input with a number prefix, except
# where the shell strips newlines before a semicolon.
queries = [
("select\n1;--comment", "[1]: select\n1;--comment"),
("select 1 --comment\n;", "[2]: select 1 --comment;"),
("select 1 --comment\n\n\n;", "[3]: select 1 --comment;"),
("select /*comment*/\n1;", "[4]: select /*comment*/\n1;"),
("select\n/*comm\nent*/\n1;", "[5]: select\n/*comm\nent*/\n1;")]
for query, _ in queries:
child_proc.expect(PROMPT_REGEX)
child_proc.sendline(query)
child_proc.expect("Fetched 1 row\(s\) in [0-9]+\.?[0-9]*s")
child_proc.expect(PROMPT_REGEX)
child_proc.sendline('quit;')
p = ImpalaShell()
p.send_cmd('history')
result = p.get_result()
for _, history_entry in queries:
assert history_entry in result.stderr, "'%s' not in '%s'" % (history_entry,
result.stderr)
示例3: test_cancellation
# 需要導入模塊: from util import ImpalaShell [as 別名]
# 或者: from util.ImpalaShell import get_result [as 別名]
def test_cancellation(self):
impalad = ImpaladService(socket.getfqdn())
assert impalad.wait_for_num_in_flight_queries(0)
command = "select sleep(10000);"
p = ImpalaShell()
p.send_cmd(command)
sleep(3)
os.kill(p.pid(), signal.SIGINT)
result = p.get_result()
assert "Cancelled" not in result.stderr
assert impalad.wait_for_num_in_flight_queries(0)
p = ImpalaShell()
sleep(3)
os.kill(p.pid(), signal.SIGINT)
result = p.get_result()
assert "^C" in result.stderr
示例4: test_change_delimiter
# 需要導入模塊: from util import ImpalaShell [as 別名]
# 或者: from util.ImpalaShell import get_result [as 別名]
def test_change_delimiter(self):
"""Test change output delimiter if delimited mode is enabled"""
p = ImpalaShell()
p.send_cmd("use tpch")
p.send_cmd("set write_delimited=true")
p.send_cmd("set delimiter=,")
p.send_cmd("select * from nation")
result = p.get_result()
assert "21,VIETNAM,2" in result.stdout
示例5: test_cancellation
# 需要導入模塊: from util import ImpalaShell [as 別名]
# 或者: from util.ImpalaShell import get_result [as 別名]
def test_cancellation(self):
"""Test cancellation (Ctrl+C event)."""
args = '-q "select sleep(10000)"'
p = ImpalaShell(args)
sleep(3)
os.kill(p.pid(), signal.SIGINT)
result = p.get_result()
assert "Cancelling Query" in result.stderr, result.stderr
示例6: test_write_delimited
# 需要導入模塊: from util import ImpalaShell [as 別名]
# 或者: from util.ImpalaShell import get_result [as 別名]
def test_write_delimited(self):
"""Test output rows in delimited mode"""
p = ImpalaShell()
p.send_cmd("use tpch")
p.send_cmd("set write_delimited=true")
p.send_cmd("select * from nation")
result = p.get_result()
assert "+----------------+" not in result.stdout
assert "21\tVIETNAM\t2" in result.stdout
示例7: test_cancellation
# 需要導入模塊: from util import ImpalaShell [as 別名]
# 或者: from util.ImpalaShell import get_result [as 別名]
def test_cancellation(self, vector):
"""Test cancellation (Ctrl+C event). Run a query that sleeps 10ms per row so will run
for 110s if not cancelled, but will detect cancellation quickly because of the small
batch size."""
query = "set num_nodes=1; set mt_dop=1; set batch_size=1; \
select sleep(10) from functional_parquet.alltypesagg"
p = ImpalaShell(vector, ['-q', query])
p.wait_for_query_start()
os.kill(p.pid(), signal.SIGINT)
result = p.get_result()
assert "Cancelling Query" in result.stderr, result.stderr
示例8: test_with_clause
# 需要導入模塊: from util import ImpalaShell [as 別名]
# 或者: from util.ImpalaShell import get_result [as 別名]
def test_with_clause(self):
# IMPALA-7939: Fix issue where CTE that contains "insert", "upsert", "update", or
# "delete" is categorized as a DML statement.
for keyword in ["insert", "upsert", "update", "delete", "\\'insert\\'",
"\\'upsert\\'", "\\'update\\'", "\\'delete\\'"]:
p = ImpalaShell()
p.send_cmd("with foo as "
"(select * from functional.alltypestiny where string_col='%s') "
"select * from foo limit 1" % keyword)
result = p.get_result()
assert "Fetched 0 row" in result.stderr
示例9: test_compute_stats_with_live_progress_options
# 需要導入模塊: from util import ImpalaShell [as 別名]
# 或者: from util.ImpalaShell import get_result [as 別名]
def test_compute_stats_with_live_progress_options(self):
"""Test that setting LIVE_PROGRESS options won't cause COMPUTE STATS query fail"""
p = ImpalaShell()
p.send_cmd("set live_progress=True")
p.send_cmd("set live_summary=True")
p.send_cmd('create table test_live_progress_option(col int);')
try:
p.send_cmd('compute stats test_live_progress_option;')
finally:
p.send_cmd('drop table if exists test_live_progress_option;')
result = p.get_result()
assert "Updated 1 partition(s) and 1 column(s)" in result.stdout
示例10: run_and_verify_query_cancellation_test
# 需要導入模塊: from util import ImpalaShell [as 別名]
# 或者: from util.ImpalaShell import get_result [as 別名]
def run_and_verify_query_cancellation_test(self, vector, stmt, cancel_at_state):
"""Starts the execution of the received query, waits until the query
execution in fact starts and then cancels it. Expects the query
cancellation to succeed."""
p = ImpalaShell(vector, ['-q', stmt])
self.wait_for_query_state(vector, stmt, cancel_at_state)
os.kill(p.pid(), signal.SIGINT)
result = p.get_result()
assert "Cancelling Query" in result.stderr
assert "Invalid query handle" not in result.stderr
示例11: test_print_to_file
# 需要導入模塊: from util import ImpalaShell [as 別名]
# 或者: from util.ImpalaShell import get_result [as 別名]
def test_print_to_file(self):
"""Test print to output file and unset"""
# test print to file
p1 = ImpalaShell()
p1.send_cmd("use tpch")
local_file = NamedTemporaryFile(delete=True)
p1.send_cmd("set output_file=%s" % local_file.name)
p1.send_cmd("select * from nation")
result = p1.get_result()
assert "VIETNAM" not in result.stdout
with open(local_file.name, "r") as fi:
# check if the results were written to the file successfully
result = fi.read()
assert "VIETNAM" in result
# test unset to print back to stdout
p2 = ImpalaShell()
p2.send_cmd("use tpch")
p2.send_cmd("set output_file=%s" % local_file.name)
p2.send_cmd("unset output_file")
p2.send_cmd("select * from nation")
result = p2.get_result()
assert "VIETNAM" in result.stdout
示例12: test_compute_stats_with_live_progress_options
# 需要導入模塊: from util import ImpalaShell [as 別名]
# 或者: from util.ImpalaShell import get_result [as 別名]
def test_compute_stats_with_live_progress_options(self, vector, unique_database):
"""Test that setting LIVE_PROGRESS options won't cause COMPUTE STATS query fail"""
p = ImpalaShell(vector)
p.send_cmd("set live_progress=True")
p.send_cmd("set live_summary=True")
table = "{0}.live_progress_option".format(unique_database)
p.send_cmd('create table {0}(col int);'.format(table))
try:
p.send_cmd('compute stats {0};'.format(table))
finally:
p.send_cmd('drop table if exists {0};'.format(table))
result = p.get_result()
assert "Updated 1 partition(s) and 1 column(s)" in result.stdout
示例13: run_impala_shell_interactive
# 需要導入模塊: from util import ImpalaShell [as 別名]
# 或者: from util.ImpalaShell import get_result [as 別名]
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
if type(input_lines) is str:
input_lines = [input_lines]
# workaround to make Popen environment 'utf-8' compatible
# since piping defaults to ascii
my_env = os.environ
my_env['PYTHONIOENCODING'] = 'utf-8'
p = ImpalaShell(shell_args, env=my_env)
for line in input_lines:
p.send_cmd(line)
return p.get_result()
示例14: test_queries_closed
# 需要導入模塊: from util import ImpalaShell [as 別名]
# 或者: from util.ImpalaShell import get_result [as 別名]
def test_queries_closed(self, vector):
"""Regression test for IMPALA-897."""
args = ['-f', '{0}/test_close_queries.sql'.format(QUERY_FILE_PATH), '--quiet', '-B']
# Execute the shell command async
p = ImpalaShell(vector, args)
impalad_service = ImpaladService(get_impalad_host_port(vector).split(':')[0])
# The last query in the test SQL script will sleep for 10 seconds, so sleep
# here for 5 seconds and verify the number of in-flight queries is 1.
sleep(5)
assert 1 == impalad_service.get_num_in_flight_queries()
assert p.get_result().rc == 0
assert 0 == impalad_service.get_num_in_flight_queries()
示例15: test_timezone_validation
# 需要導入模塊: from util import ImpalaShell [as 別名]
# 或者: from util.ImpalaShell import get_result [as 別名]
def test_timezone_validation(self):
"""Test that query option TIMEZONE is validated when executing a query.
Query options are not sent to the coordinator immediately, so the error checking
will only happen when running a query.
"""
p = ImpalaShell()
p.send_cmd('set timezone=BLA;')
p.send_cmd('select 1;')
results = p.get_result()
assert "Fetched 1 row" not in results.stderr
assert "ERROR: Errors parsing query options" in results.stderr
assert "Invalid timezone name 'BLA'" in results.stderr