예제 #1
0
def test_ch_context_manager():

    ch = ClickHouse()
    ch.conn_class = create_factory()

    ch.run('CREATE TABLE IF NOT EXISTS test1 (name String) ENGINE = Log()')
    with ch.table('test1') as b:
        b.push({'name': 'lalala'})
예제 #2
0
def test_ch_push():

    ch = ClickHouse()
    ch.conn_class = create_factory()

    ch.run('CREATE TABLE IF NOT EXISTS test1 (name String) ENGINE = Log()')
    ch.push('textxx', {'name': 'lalala'})
    ch.flush_all()
    recs = [*ch.objects_stream('SELECT * FROM textxx')]
    assert len(recs) == 1
    ch.push('textxx', {'name': 'nananan'})
    ch.flush('textxx')
    recs = [*ch.objects_stream('SELECT * FROM textxx')]
    assert len(recs) == 2
예제 #3
0
def test_simplech_wrapping():

    ch = ClickHouse()
    ch.conn_class = create_factory()
    td = ch.discover('ga_stat', set1)
    td.date(
        'date').idx('ga_dimension2',
                    'date').metrics('ga_pageviews',
                                    'ga_newUsers',
                                    'ga_timeOnPage',
                                    'ga_sessions',
                                    'ga_users')
    assert td.tc.idx == ['ga_dimension2', 'date']
    assert 'ga_stat' == td.table
예제 #4
0
async def td_context_manager_async():
    ch = AsyncClickHouse()
    ch.conn_class = create_factory(async_mode=True)
    td = ch.discover('ga_stat', set3).date('date').idx('date').metrics('sale')

    d1 = '2019-01-10'
    d2 = '2019-01-13'

    async with td.difference(d1, d2, set3) as d:
        async for row in d:
            td.push(row)

    recs = []
    async for rec in ch.objects_stream('SELECT * FROM textxx'):
        recs.append(rec)

    print(recs)
    assert len(recs) == 3
예제 #5
0
def test_ch_delta_iter():

    ch = ClickHouse()
    ch.conn_class = create_factory()

    ch.run('CREATE TABLE IF NOT EXISTS test1 (name String) ENGINE = Log()')
    upd = [{'name': 'lalala', 'value': 1}, {'name': 'bababa', 'value': 2}, {'name': 'nanana', 'value': 3}]

    td = ch.discover('test1', upd).metrics('value')

    d1 = '2019-01-10'
    d2 = '2019-01-13'

    new_recs = []
    with td.difference(d1, d2, upd) as delta:
        for row in delta:
            new_recs.append(row)

    for r in upd:
        assert r in new_recs

    ch.close()
예제 #6
0
def test_td_context_manager():

    ch = ClickHouse()
    ch.conn_class = create_factory()
    td = ch.discover('ga_stat', set3).date('date').idx('date').metrics('sale')

    d1 = '2019-01-10'
    d2 = '2019-01-13'

    with td.difference(d1, d2, set3) as delta:
        assert delta.d1 == d1
        assert delta.d2 == d2
        assert delta.disco == td
        assert td.ch == delta.ch
        for row in delta:
            td.push(row)

    recs = [*ch.objects_stream('SELECT * FROM textxx')]

    assert len(recs) == 3
    assert td.tc.idx == ['date']
    assert 'ga_stat' == td.table
예제 #7
0
async def async_ch_push():

    ch = AsyncClickHouse()
    ch.conn_class = create_factory(async_mode=True)

    await ch.run('CREATE TABLE IF NOT EXISTS test1 (name String) ENGINE = Log()')
    ch.push('textxx', {'name': 'lalala'})
    await ch.flush_all()
    recs = []
    async for rec in ch.objects_stream('SELECT * FROM textxx'):
        print(type(rec))
        recs.append(rec)
    assert len(recs) > 0
    ch.push('textxx', {'name': 'nananan'})
    await ch.flush('textxx')
    recs = []
    
    async for rec in ch.objects_stream('SELECT * FROM textxx'):
        print(type(rec))
        recs.append(rec)
    assert len(recs) > 0

    ch.close()
예제 #8
0
def test_ch_run():

    ch = ClickHouse()
    ch.conn_class = create_factory()
    ch.run('SELECT')