2021-08-25 19:30:22 +00:00
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
import time
|
|
|
|
|
|
|
|
import pytest
|
|
|
|
|
|
|
|
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
|
|
|
SCRIPT_DIR = os.path.dirname(os.path.realpath(__file__))
|
|
|
|
|
|
|
|
from helpers.cluster import ClickHouseCluster
|
|
|
|
|
|
|
|
cluster = ClickHouseCluster(__file__)
|
|
|
|
node = cluster.add_instance('node', stay_alive=True, main_configs=[])
|
|
|
|
|
|
|
|
|
|
|
|
def copy_file_to_container(local_path, dist_path, container_id):
|
|
|
|
os.system("docker cp {local} {cont_id}:{dist}".format(local=local_path, cont_id=container_id, dist=dist_path))
|
|
|
|
|
|
|
|
@pytest.fixture(scope="module")
|
|
|
|
def started_cluster():
|
|
|
|
try:
|
|
|
|
cluster.start()
|
|
|
|
|
|
|
|
copy_file_to_container(os.path.join(SCRIPT_DIR, 'user_scripts/.'), '/var/lib/clickhouse/user_scripts', node.docker_id)
|
|
|
|
node.restart_clickhouse()
|
|
|
|
|
|
|
|
yield cluster
|
|
|
|
|
|
|
|
finally:
|
|
|
|
cluster.shutdown()
|
|
|
|
|
|
|
|
def test_executable_function_no_input(started_cluster):
|
|
|
|
assert node.query("SELECT * FROM executable('test_no_input.sh', 'TabSeparated', 'value UInt64')") == '1\n'
|
|
|
|
|
2021-08-28 19:47:59 +00:00
|
|
|
def test_executable_function_input(started_cluster):
|
2021-08-29 20:19:05 +00:00
|
|
|
assert node.query("SELECT * FROM executable('test_input.sh', 'TabSeparated', 'value String', (SELECT 1))") == 'Key 1\n'
|
|
|
|
|
2021-09-02 07:47:21 +00:00
|
|
|
def test_executable_function_input_multiple_pipes(started_cluster):
|
|
|
|
actual = node.query("SELECT * FROM executable('test_input_multiple_pipes.sh', 'TabSeparated', 'value String', (SELECT 1), (SELECT 2), (SELECT 3))")
|
|
|
|
expected = 'Key from 4 fd 3\nKey from 3 fd 2\nKey from 0 fd 1\n'
|
|
|
|
assert actual == expected
|
|
|
|
|
2021-08-30 18:41:36 +00:00
|
|
|
def test_executable_function_argument(started_cluster):
|
|
|
|
assert node.query("SELECT * FROM executable('test_argument.sh 1', 'TabSeparated', 'value String')") == 'Key 1\n'
|
|
|
|
|
2021-08-29 20:19:05 +00:00
|
|
|
def test_executable_storage_no_input(started_cluster):
|
|
|
|
node.query("DROP TABLE IF EXISTS test_table")
|
|
|
|
node.query("CREATE TABLE test_table (value UInt64) ENGINE=Executable('test_no_input.sh', 'TabSeparated')")
|
|
|
|
assert node.query("SELECT * FROM test_table") == '1\n'
|
|
|
|
node.query("DROP TABLE test_table")
|
|
|
|
|
|
|
|
def test_executable_storage_input(started_cluster):
|
|
|
|
node.query("DROP TABLE IF EXISTS test_table")
|
|
|
|
node.query("CREATE TABLE test_table (value String) ENGINE=Executable('test_no_input.sh', 'TabSeparated', (SELECT 1))")
|
|
|
|
assert node.query("SELECT * FROM test_table") == '1\n'
|
|
|
|
node.query("DROP TABLE test_table")
|
2021-08-30 18:41:36 +00:00
|
|
|
|
2021-09-02 07:47:21 +00:00
|
|
|
def test_executable_storage_input_multiple_pipes(started_cluster):
|
|
|
|
node.query("DROP TABLE IF EXISTS test_table")
|
|
|
|
node.query("CREATE TABLE test_table (value String) ENGINE=Executable('test_input_multiple_pipes.sh', 'TabSeparated', (SELECT 1), (SELECT 2), (SELECT 3))")
|
|
|
|
actual = node.query("SELECT * FROM test_table")
|
|
|
|
expected = 'Key from 4 fd 3\nKey from 3 fd 2\nKey from 0 fd 1\n'
|
|
|
|
assert actual == expected
|
|
|
|
node.query("DROP TABLE test_table")
|
|
|
|
|
2021-08-30 18:41:36 +00:00
|
|
|
def test_executable_storage_argument(started_cluster):
|
|
|
|
node.query("DROP TABLE IF EXISTS test_table")
|
|
|
|
node.query("CREATE TABLE test_table (value String) ENGINE=Executable('test_argument.sh 1', 'TabSeparated')")
|
|
|
|
assert node.query("SELECT * FROM test_table") == 'Key 1\n'
|
|
|
|
node.query("DROP TABLE test_table")
|
2021-09-02 11:53:20 +00:00
|
|
|
|
|
|
|
def test_executable_pool_storage(started_cluster):
|
|
|
|
node.query("DROP TABLE IF EXISTS test_table")
|
|
|
|
node.query("CREATE TABLE test_table (value String) ENGINE=ExecutablePool('test_input_process_pool.sh', 'TabSeparated', (SELECT 1))")
|
|
|
|
assert node.query("SELECT * FROM test_table") == 'Key 1\n'
|
|
|
|
node.query("DROP TABLE test_table")
|
|
|
|
|
|
|
|
def test_executable_pool_storage_multiple_pipes(started_cluster):
|
|
|
|
node.query("DROP TABLE IF EXISTS test_table")
|
|
|
|
node.query("CREATE TABLE test_table (value String) ENGINE=ExecutablePool('test_input_process_pool_multiple_pipes.sh', 'TabSeparated', (SELECT 1), (SELECT 2), (SELECT 3))")
|
|
|
|
assert node.query("SELECT * FROM test_table") == 'Key from 4 fd 3\nKey from 3 fd 2\nKey from 0 fd 1\n'
|
|
|
|
node.query("DROP TABLE test_table")
|