def test_dimensions(): # 'date', 'cid', 'date_time', 'id', 'sale', 'uid' ch = ClickHouse() td = ch.discover('ga_stat', set3).date('date').idx('date').metrics('sale') assert set(td.tc.dimensions.keys()) == { 'cid', 'date_time', 'id', 'date', 'uid'} td = ch.discover('ga_stat', set3).date('date').idx('date') assert set(td.tc.dimensions.keys()) == { 'cid', 'date_time', 'id', 'date', 'uid', 'sale'}
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
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
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'})
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()
def sync_test(): # run ch = ClickHouse( debug=test_debug, host=test_host, user=test_user, db=test_db) ch.run('DROP TABLE IF EXISTS libtest') ch.run('CREATE TABLE IF NOT EXISTS libtest (id UInt64, date Date, descr String) ENGINE = Log') ch.run("INSERT INTO libtest (id, date, descr) VALUES (1, '2018-06-01', 'descr'), (7, '2018-06-03', 'дескр')") print(ch.select('SELECT * FROM libtest')) ch.push('libtest', {'id': 8, 'date': '2019-09-01'}) ch.push('libtest', {'id': 10, 'date': '2019-09-03', 'descr': 'лалалала'}) ch.flush('libtest') ch.push('libtest', {'id': 11, 'date': '2019-09-09'}) ch.flush_all() # Objects stream for obj in ch.objects_stream("SELECT * from libtest"): print(obj) print('---') ch.run('DROP TABLE IF EXISTS libtest')
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
from requests import post, get from simplech import ClickHouse app = Flask(__name__) app.config['DEBUG'] = False app.config['JWT_SECRET_KEY'] = 'jwt-secret-string' app.config['JWT_BLACKLIST_ENABLED'] = True app.config['JWT_BLACKLIST_TOKEN_CHECKS'] = ['access', 'refresh'] app.config['JWT_ERROR_MESSAGE_KEY'] = 'message' # app.config['JWT_ACCESS_TOKEN_EXPIRES'] = int(10) jwt = JWTManager(app) auth = HTTPBasicAuth() clickhouse_client = ClickHouse(host=CLICKHOUSE_server, user=CLICKHOUSE_username, password=CLICKHOUSE_password, port=CLICKHOUSE_port, db=CLICKHOUSE_database) @auth.verify_password def verify_password(username, password): return check_password_hash(get_password(username), password) @jwt.user_claims_loader def add_claims_to_access_token(identity): return { 'role': get_user_role(identity), }
def test_ch_run(): ch = ClickHouse() ch.conn_class = create_factory() ch.run('SELECT')