Esempio n. 1
0
def test_session_local() -> None:
    local_session = ck.LocalSession(tcp_port=9001,
                                    http_port=8124,
                                    user='******',
                                    password='******',
                                    stop=True,
                                    start=True)

    pid_1 = local_session.stop()

    assert pid_1 is not None
    assert local_session.get_pid() is None

    pid_2 = local_session.stop()

    assert pid_2 is None
    assert local_session.get_pid() is None

    pid_3 = local_session.start()

    assert pid_3 is not None
    assert local_session.get_pid() is not None

    pid_4 = local_session.start()

    assert pid_4 is None
    assert local_session.get_pid() == pid_3

    for method in METHODS:
        assert local_session.query('select 1', method=method) == b'1\n'
        assert local_session.query_async('select 1', method=method)() == b'1\n'
Esempio n. 2
0
def test_session_passive() -> None:
    local_session = ck.LocalSession(tcp_port=9001,
                                    http_port=8124,
                                    user='******',
                                    password='******',
                                    stop=True,
                                    start=True)
    passive_session = ck.PassiveSession(tcp_port=9001,
                                        http_port=8124,
                                        user='******',
                                        password='******')

    local_session.stop()

    for method in METHODS:
        assert not passive_session.ping(method=method)

    local_session.start()

    for method in METHODS:
        assert passive_session.ping(method=method)

    for method in METHODS:
        assert passive_session.query('select 1', method=method) == b'1\n'
        assert passive_session.query_async('select 1',
                                           method=method)() == b'1\n'
Esempio n. 3
0
def test_session_method_ssh_benchmark(
        benchmark: pytest_benchmark.fixture.BenchmarkFixture) -> None:
    local_session = ck.LocalSession(stop=True)

    def run() -> None:
        local_session.query('select number from numbers(1000000)',
                            method='ssh')

    benchmark(run)
Esempio n. 4
0
def test_connection_http_benchmark(
        benchmark: pytest_benchmark.fixture.BenchmarkFixture) -> None:
    ck.LocalSession(stop=True, start=True)

    def run() -> None:
        connection.run_http(
            'localhost', 8123, '/', {},
            iteration.given_in([b'select number from numbers(1000000)']),
            iteration.ignore_out(), iteration.empty_out())()

    benchmark(run)
Esempio n. 5
0
def test_connection_process_benchmark(
        benchmark: pytest_benchmark.fixture.BenchmarkFixture) -> None:
    ck.LocalSession(stop=True, start=True)

    def run() -> None:
        connection.run_process([clickhouse.binary_file(), 'client'],
                               iteration.given_in(
                                   [b'select number from numbers(1000000)']),
                               iteration.ignore_out(), iteration.empty_out())()

    benchmark(run)
Esempio n. 6
0
def test_connection_http() -> None:
    ck.LocalSession(stop=True, start=True)

    stdout_list: typing.List[bytes] = []
    status = connection.run_http('localhost', 8123, '/', {},
                                 iteration.given_in([b'select 1']),
                                 iteration.collect_out(stdout_list),
                                 iteration.empty_out())()

    assert stdout_list == [b'1\n']
    assert status == 200
Esempio n. 7
0
def test_connection_process() -> None:
    ck.LocalSession(stop=True, start=True)

    stdout_list: typing.List[bytes] = []
    status = connection.run_process([clickhouse.binary_file(), 'client'],
                                    iteration.given_in([b'select 1']),
                                    iteration.collect_out(stdout_list),
                                    iteration.empty_out())()

    assert stdout_list == [b'1\n']
    assert status == 0
Esempio n. 8
0
def test_session_gen_bytes() -> None:
    local_session = ck.LocalSession(stop=True)

    local_session.query('drop table if exists pyck_test')
    local_session.query('create table pyck_test (x String) engine = Memory')

    local_session.query('insert into pyck_test format TSV',
                        data=b'hello\nworld\n')

    assert local_session.query(
        'select * from pyck_test format TSV') == b'hello\nworld\n'

    local_session.query('drop table pyck_test')
Esempio n. 9
0
def test_session_gen_pandas() -> None:
    local_session = ck.LocalSession(stop=True)

    local_session.query('drop table if exists pyck_test')
    local_session.query('create table pyck_test (x Int64) engine = Memory')

    dataframe_1 = pandas.DataFrame({'x': pandas.RangeIndex(1000000)})

    local_session.query_pandas('insert into pyck_test', dataframe=dataframe_1)
    dataframe_2 = local_session.query_pandas('select * from pyck_test')

    assert dataframe_2 is not None
    assert dataframe_2.x.to_list() == dataframe_1.x.to_list()

    local_session.query('drop table pyck_test')
Esempio n. 10
0
def test_session_settings() -> None:
    local_session = ck.LocalSession()

    query_text = 'select isNull(y) ' \
        'from (select 1 as x) as lhs ' \
        'any left join (select 2 as x, 3 as y) as rhs ' \
        'using x'

    for method in METHODS:
        assert local_session.query(query_text,
                                   method=method,
                                   settings={'join_use_nulls': '0'}) == b'0\n'
        assert local_session.query(query_text,
                                   method=method,
                                   settings={'join_use_nulls': '1'}) == b'1\n'
Esempio n. 11
0
def test_session_file() -> None:
    local_session = ck.LocalSession()

    local_session.query('drop table if exists pyck_test')
    local_session.query('create table pyck_test (x String) engine = Memory')

    open('/tmp/pyck_test_session_1', 'wb').write(b'hello\nworld\n')
    local_session.query('insert into pyck_test format TSV',
                        gen_in=iteration.file_in('/tmp/pyck_test_session_1'))
    open('/tmp/pyck_test_session_2', 'wb').write(b'')
    local_session.query('select * from pyck_test format TSV',
                        gen_out=iteration.file_out('/tmp/pyck_test_session_2'))
    assert open('/tmp/pyck_test_session_2', 'rb').read() == b'hello\nworld\n'

    local_session.query('drop table pyck_test')
Esempio n. 12
0
def test_connection_ssh() -> None:
    ck.LocalSession()

    ssh_client = connection.connect_ssh('localhost')

    stdout_list: typing.List[bytes] = []
    status = connection.run_ssh(
        ssh_client,
        [clickhouse.binary_file(), 'client'],
        iteration.given_in([b'select 1']),
        iteration.collect_out(stdout_list),
        iteration.empty_out()
    )()

    assert stdout_list == [b'1\n']
    assert status == 0
Esempio n. 13
0
def test_connection_ssh_benchmark(
        benchmark: pytest_benchmark.fixture.BenchmarkFixture
) -> None:
    ck.LocalSession()

    ssh_client = connection.connect_ssh('localhost')

    def run() -> None:
        connection.run_ssh(
            ssh_client,
            [clickhouse.binary_file(), 'client'],
            iteration.given_in([b'select number from numbers(1000000)']),
            iteration.ignore_out(),
            iteration.empty_out()
        )()

    benchmark(run)
Esempio n. 14
0
def test_session_passive() -> None:
    local_session = ck.LocalSession()
    passive_session = ck.PassiveSession()

    local_session.stop()

    for method in METHODS:
        assert not passive_session.ping(method=method)

    local_session.start()

    for method in METHODS:
        assert passive_session.ping(method=method)

    for method in METHODS:
        assert passive_session.query('select 1', method=method) == b'1\n'
        assert passive_session.query_async('select 1',
                                           method=method)() == b'1\n'
Esempio n. 15
0
def test_session_gen_stream() -> None:
    local_session = ck.LocalSession(stop=True)

    local_session.query('drop table if exists pyck_test')
    local_session.query('create table pyck_test (x Int64) engine = Memory')

    dataframe_1 = pandas.DataFrame({'x': pandas.RangeIndex(1000000)})

    read_stream, write_stream = iteration.echo_io()
    join = local_session.query_stream_async(
        'insert into pyck_test format CSVWithNames', stream_in=read_stream)
    dataframe_1.to_csv(io.TextIOWrapper(write_stream), index=False)
    join()
    read_stream, write_stream = iteration.echo_io()
    join = local_session.query_stream_async(
        'select * from pyck_test format CSVWithNames', stream_out=write_stream)
    dataframe_2 = pandas.read_csv(io.TextIOWrapper(read_stream))
    join()

    assert dataframe_2.x.to_list() == dataframe_1.x.to_list()

    local_session.query('drop table pyck_test')
Esempio n. 16
0
def test_session_local() -> None:
    local_session = ck.LocalSession()

    pid_1 = local_session.stop()
    assert pid_1 is not None
    assert local_session.get_pid() is None

    pid_2 = local_session.stop()
    assert pid_2 is None
    assert local_session.get_pid() is None

    pid_3 = local_session.start()
    assert pid_3 is not None
    assert local_session.get_pid() is not None

    pid_4 = local_session.start()
    assert pid_4 is None
    assert local_session.get_pid() == pid_3

    for method in METHODS:
        assert local_session.query('select 1', method=method) == b'1\n'
        assert local_session.query_async('select 1', method=method)() == b'1\n'