Example #1
0
def database(connection):
    create = 'CREATE DATABASE IF NOT EXISTS {db}'
    drop = 'DROP DATABASE IF EXISTS {db}'
    try:
        yield execute(create, connection=connection)
    finally:
        execute(drop, connection=connection)
Example #2
0
def database(connection):
    # drop database key, because it's not existing yet
    connection = dict(host=connection['host'])
    create = 'CREATE DATABASE IF NOT EXISTS test'
    drop = 'DROP DATABASE IF EXISTS test'
    try:
        yield execute(create, connection=connection)
    finally:
        execute(drop, connection=connection)
Example #3
0
def decimals(connection, database):
    create = '''
        CREATE TABLE IF NOT EXISTS {db}.decimals (
            A UInt64, B Int32, C UInt16, D Date
        ) ENGINE = MergeTree(D, (A), 8192)
    '''
    drop = 'DROP TABLE IF EXISTS {db}.decimals'
    try:
        yield execute(create, connection=connection)
    finally:
        execute(drop, connection=connection)
Example #4
0
def xyz(connection, database):
    create = '''
        CREATE TABLE IF NOT EXISTS {db}.xyz (
            id Int64,
            sss String,
            date Date
        ) ENGINE = MergeTree(date, (id), 8192);
    '''
    drop = 'DROP TABLE IF EXISTS {db}.xyz'
    try:
        yield execute(create, connection=connection)
    finally:
        execute(drop, connection=connection)
Example #5
0
def nullable(connection, database):
    create = """
        CREATE TABLE IF NOT EXISTS {db}.nullable (
            A Int64,
            B Nullable(Float32),
            C Nullable(Int32),
            D Date
        ) ENGINE = MergeTree(D, (A), 8192)
    """
    drop = "DROP TABLE IF EXISTS {db}.nullable"
    try:
        yield execute(create, connection=connection)
    finally:
        execute(drop, connection=connection)
Example #6
0
def xyz2(connection, database):
    create = """
        CREATE TABLE IF NOT EXISTS {db}.xyz2 (
            id Int64,
            joe UInt64,
            sss String,
            date Date,
            jessy Int32
        ) ENGINE = MergeTree(date, (id), 8192);
    """
    drop = "DROP TABLE IF EXISTS {db}.xyz2"
    try:
        yield execute(create, connection=connection)
    finally:
        execute(drop, connection=connection)
Example #7
0
def test_execute_long_query(decimals, connection):
    where_clause = " WHERE A IN {0}".format(tuple(range(1, 4000)))
    query = "SELECT count(*) FROM {db}.decimals " + where_clause
    execute(query=query, connection=connection, stream=True)
Example #8
0
def test_execute(connection):
    query = "DESC system.parts FORMAT CSV;"
    response = execute(query, connection=connection)
    assert isinstance(response, bytes)
Example #9
0
def test_wrong_query(connection):
    query = "SELECT * FROM default.nonexisting"
    with pytest.raises((ClickhouseException, RequestException)):
        execute(query, connection=connection)
Example #10
0
def test_wrong_host():
    query = "DESC system.parts FORMAT CSV;"
    with pytest.raises(ConnectionError):
        execute(query, connection={"host": "http://local"})
Example #11
0
def test_execute_stream(connection):
    query = "DESC system.parts FORMAT CSV;"
    response = execute(query, stream=True, connection=connection)
    result = response.read()
    assert result
Example #12
0
def test_wrong_host():
    query = 'DESC system.parts FORMAT CSV;'
    with pytest.raises(ConnectionError):
        execute(query, connection={'host': 'http://local'})