def test_quota_key(self): c = Client.from_url('clickhouse://host?quota_key=myquota') self.assertEqual(c.connection.context.client_settings['quota_key'], 'myquota') c = Client.from_url('clickhouse://host') self.assertEqual(c.connection.context.client_settings['quota_key'], '')
def test_ssl_key_cert(self): base_url = ('clickhouses://host?' 'verify=true&' 'ssl_version=PROTOCOL_SSLv23&' 'ca_certs=/tmp/certs&' 'ciphers=HIGH:-aNULL:-eNULL:-PSK:RC4-SHA:RC4-MD5&') base_expected = { 'ssl_version': ssl.PROTOCOL_SSLv23, 'ca_certs': '/tmp/certs', 'ciphers': 'HIGH:-aNULL:-eNULL:-PSK:RC4-SHA:RC4-MD5' } c = Client.from_url(base_url + 'keyfile=/tmp/client.key&' 'certfile=/tmp/client.cert') expected = base_expected.copy() expected.update({ 'keyfile': '/tmp/client.key', 'certfile': '/tmp/client.cert' }) self.assertEqual(c.connection.ssl_options, expected) c = Client.from_url(base_url + 'certfile=/tmp/client.cert') expected = base_expected.copy() expected.update({'certfile': '/tmp/client.cert'}) self.assertEqual(c.connection.ssl_options, expected)
def test_schema(self): c = Client.from_url('clickhouse://host') assert c.connection.secure_socket is False c = Client.from_url('clickhouses://host') assert c.connection.secure_socket is True c = Client.from_url('test://host') assert c.connection.secure_socket is False
def test_port(self): c = Client.from_url('clickhouse://host') assert c.connection.hosts == [('host', 9000)] c = Client.from_url('clickhouses://host') assert c.connection.hosts == [('host', 9440)] c = Client.from_url('clickhouses://host:1234') assert c.connection.hosts == [('host', 1234)]
def test_schema(self): c = Client.from_url('clickhouse://host') self.assertFalse(c.connection.secure_socket) c = Client.from_url('clickhouses://host') self.assertTrue(c.connection.secure_socket) c = Client.from_url('test://host') self.assertFalse(c.connection.secure_socket)
def test_port(self): c = Client.from_url('clickhouse://host') self.assertHostsEqual(c, [('host', 9000)]) c = Client.from_url('clickhouses://host') self.assertHostsEqual(c, [('host', 9440)]) c = Client.from_url('clickhouses://host:1234') self.assertHostsEqual(c, [('host', 1234)])
def test_port(self): c = Client.from_url('clickhouse://host') assert c.connection.port == 9000 c = Client.from_url('clickhouses://host') assert c.connection.port == 9440 c = Client.from_url('clickhouses://host:1234') assert c.connection.port == 1234
def test_simple(self): c = Client.from_url('clickhouse://host') assert c.connection.hosts == [('host', 9000)] assert c.connection.database == 'default' c = Client.from_url('clickhouse://host/db') assert c.connection.hosts == [('host', 9000)] assert c.connection.database == 'db'
def test_simple(self): c = Client.from_url('clickhouse://host') self.assertHostsEqual(c, [('host', 9000)]) self.assertEqual(c.connection.database, 'default') c = Client.from_url('clickhouse://host/db') self.assertHostsEqual(c, [('host', 9000)]) self.assertEqual(c.connection.database, 'db')
def test_settings_is_important(self): c = Client.from_url('clickhouse://host?settings_is_important=1') self.assertEqual(c.connection.settings_is_important, True) with self.assertRaises(ValueError): c = Client.from_url('clickhouse://host?settings_is_important=2') self.assertEqual(c.connection.settings_is_important, True) c = Client.from_url('clickhouse://host?settings_is_important=0') self.assertEqual(c.connection.settings_is_important, False)
def test_timeouts(self): with self.assertRaises(ValueError): Client.from_url('clickhouse://host?connect_timeout=test') c = Client.from_url('clickhouse://host?connect_timeout=1.2') assert c.connection.connect_timeout == 1.2 c = Client.from_url('clickhouse://host?send_receive_timeout=1.2') assert c.connection.send_receive_timeout == 1.2 c = Client.from_url('clickhouse://host?sync_request_timeout=1.2') assert c.connection.sync_request_timeout == 1.2
def test_compress_block_size(self): with self.assertRaises(ValueError): Client.from_url('clickhouse://host?compress_block_size=test') c = Client.from_url('clickhouse://host?compress_block_size=100500') # compression is not set assert c.connection.compress_block_size is None c = Client.from_url('clickhouse://host?' 'compress_block_size=100500&' 'compression=1') assert c.connection.compress_block_size == 100500
def test_secure(self): c = Client.from_url('clickhouse://host?secure=n') self.assertHostsEqual(c, [('host', 9000)]) self.assertFalse(c.connection.secure_socket) c = Client.from_url('clickhouse://host?secure=y') self.assertHostsEqual(c, [('host', 9440)]) self.assertTrue(c.connection.secure_socket) c = Client.from_url('clickhouse://host:1234?secure=y') self.assertHostsEqual(c, [('host', 1234)]) self.assertTrue(c.connection.secure_socket) with self.assertRaises(ValueError): Client.from_url('clickhouse://host:1234?secure=nonono')
def test_secure(self): c = Client.from_url('clickhouse://host?secure=n') assert c.connection.port == 9000 assert c.connection.secure_socket is False c = Client.from_url('clickhouse://host?secure=y') assert c.connection.port == 9440 assert c.connection.secure_socket is True c = Client.from_url('clickhouse://host:1234?secure=y') assert c.connection.port == 1234 assert c.connection.secure_socket is True with self.assertRaises(ValueError): Client.from_url('clickhouse://host:1234?secure=nonono')
def test_secure(self): c = Client.from_url('clickhouse://host?secure=n') assert c.connection.hosts == [('host', 9000)] assert c.connection.secure_socket is False c = Client.from_url('clickhouse://host?secure=y') assert c.connection.hosts == [('host', 9440)] assert c.connection.secure_socket is True c = Client.from_url('clickhouse://host:1234?secure=y') assert c.connection.hosts == [('host', 1234)] assert c.connection.secure_socket is True with self.assertRaises(ValueError): Client.from_url('clickhouse://host:1234?secure=nonono')
def test_credentials(self): c = Client.from_url('clickhouse://host/db') self.assertEqual(c.connection.user, 'default') self.assertEqual(c.connection.password, '') c = Client.from_url('clickhouse://*****:*****@host/db') self.assertEqual(c.connection.user, 'admin') self.assertEqual(c.connection.password, 'secure') c = Client.from_url('clickhouse://user:@host/db') self.assertEqual(c.connection.user, 'user') self.assertEqual(c.connection.password, '')
def test_credentials(self): c = Client.from_url('clickhouse://host/db') assert c.connection.user == 'default' assert c.connection.password == '' c = Client.from_url('clickhouse://*****:*****@host/db') assert c.connection.user == 'admin' assert c.connection.password == 'secure' c = Client.from_url('clickhouse://user:@host/db') assert c.connection.user == 'user' assert c.connection.password == ''
def from_url(cls, url, loop=None, executor=None): """ *New in version 0.0.2.* """ _client = BlockingClient.from_url(url) return cls(_client=_client, loop=loop, executor=executor)
def setup_clickhouse(conf) -> None: global click_client log.info("Connecting to clickhouse") click_client = Clickhouse.from_url(conf.clickhouse_url) rows = click_client.execute("SELECT version()") log.debug(f"Clickhouse version: {rows[0][0]}") _click_create_table_fastpath()
def test_settings(self): c = Client.from_url('clickhouse://host?' 'send_logs_level=trace&' 'max_block_size=123') assert c.settings == { 'send_logs_level': 'trace', 'max_block_size': '123' }
def __init__(self, host, logfmt, loglvl=logging.INFO): self.host = host # set logging format and level in driver / worker logging.basicConfig(format=logfmt) logging.getLogger().setLevel(loglvl) self.cli = Client.from_url(host) # perform a test self.test()
def test_ssl(self): c = Client.from_url('clickhouses://host?' 'verify=false&' 'ssl_version=PROTOCOL_SSLv23&' 'ca_certs=/tmp/certs&' 'ciphers=HIGH:-aNULL:-eNULL:-PSK:RC4-SHA:RC4-MD5') assert c.connection.ssl_options == { 'ssl_version': ssl.PROTOCOL_SSLv23, 'ca_certs': '/tmp/certs', 'ciphers': 'HIGH:-aNULL:-eNULL:-PSK:RC4-SHA:RC4-MD5' }
def __init__(self, user='******', password='', host='localhost', port=9000, db_name=None): self.client = Client.from_url('clickhouse://{}:{}@{}:{}'.format( user, password, host, port)) self._test_connection() self.name = db_name self._create_database() self._create_tables()
def test_opentelemetry(self): c = Client.from_url( 'clickhouse://host?opentelemetry_traceparent=' '00-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa-bbbbbbbbbbbbbbbb-00') self.assertEqual( c.connection.context.client_settings['opentelemetry_traceparent'], '00-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa-bbbbbbbbbbbbbbbb-00') self.assertEqual( c.connection.context.client_settings['opentelemetry_tracestate'], '') c = Client.from_url( 'clickhouse://host?opentelemetry_traceparent=' '00-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa-bbbbbbbbbbbbbbbb-00&' 'opentelemetry_tracestate=state') self.assertEqual( c.connection.context.client_settings['opentelemetry_traceparent'], '00-aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa-bbbbbbbbbbbbbbbb-00') self.assertEqual( c.connection.context.client_settings['opentelemetry_tracestate'], 'state')
def run_clickhouse_sql_scripts(app): log = app.logger clickhouse_url = app.config["CLICKHOUSE_URL"] click = Clickhouse.from_url(clickhouse_url) tables = click.execute("SHOW TABLES") for row in tables: if row[0] == "fastpath": return for fn in ["1_schema", "2_fixtures"]: sql_f = Path(f"tests/integ/clickhouse_{fn}.sql") print(f"Running {sql_f} on Clickhouse") queries = sql_f.read_text().split(";") for q in queries: q = q.strip() if not q: continue click.execute(q)
def test_compression(self): c = Client.from_url('clickhouse://host?compression=n') assert c.connection.compression == Compression.DISABLED assert c.connection.compressor_cls is None c = Client.from_url('clickhouse://host?compression=y') assert c.connection.compression == Compression.ENABLED assert c.connection.compressor_cls is LZ4Compressor c = Client.from_url('clickhouse://host?compression=lz4') assert c.connection.compression == Compression.ENABLED assert c.connection.compressor_cls is LZ4Compressor c = Client.from_url('clickhouse://host?compression=lz4hc') assert c.connection.compression == Compression.ENABLED assert c.connection.compressor_cls is LZHC4Compressor c = Client.from_url('clickhouse://host?compression=zstd') assert c.connection.compression == Compression.ENABLED assert c.connection.compressor_cls is ZSTDCompressor with self.assertRaises(ValueError): Client.from_url('clickhouse://host:1234?compression=custom')
def test_compression(self): c = Client.from_url('clickhouse://host?compression=n') self.assertEqual(c.connection.compression, Compression.DISABLED) self.assertIsNone(c.connection.compressor_cls) c = Client.from_url('clickhouse://host?compression=y') self.assertEqual(c.connection.compression, Compression.ENABLED) self.assertIs(c.connection.compressor_cls, LZ4Compressor) c = Client.from_url('clickhouse://host?compression=lz4') self.assertEqual(c.connection.compression, Compression.ENABLED) self.assertIs(c.connection.compressor_cls, LZ4Compressor) c = Client.from_url('clickhouse://host?compression=lz4hc') self.assertEqual(c.connection.compression, Compression.ENABLED) self.assertIs(c.connection.compressor_cls, LZHC4Compressor) c = Client.from_url('clickhouse://host?compression=zstd') self.assertEqual(c.connection.compression, Compression.ENABLED) self.assertIs(c.connection.compressor_cls, ZSTDCompressor) with self.assertRaises(ValueError): Client.from_url('clickhouse://host:1234?compression=custom')
def __init__(self, database_url): Source.__init__(self) self.client = Client.from_url(database_url)
def connect(self, **kwargs): return Client.from_url(**kwargs)
def test_client_name(self): c = Client.from_url('clickhouse://host?client_name=native') assert c.connection.client_name == 'ClickHouse native'