Skip to content

Commit 4ac87b9

Browse files
committed
add a test file and add new type for ClickhouseTableNode parameter with dict input can also go through init process
1 parent b057b71 commit 4ac87b9

4 files changed

Lines changed: 22 additions & 20 deletions

File tree

ClickSQL/clickhouse/ClickHouse.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
available_queries_select = ('select', 'show', 'desc')
1818
available_queries_insert = ('insert', 'optimize', 'create')
1919

20-
SEMAPHORE = 10
20+
SEMAPHORE = 10 # control async number for whole query list
2121

2222
from ClickSQL.conf.parse_rfc_1738_args import _parse_rfc1738_args
2323

@@ -114,7 +114,7 @@ def __init__(self, **db_settings):
114114
self._test_connection_()
115115

116116
@staticmethod
117-
def _check_db_settings(db_settings: dict, available_db_type=[node.__name__]):
117+
def _check_db_settings(db_settings: dict, available_db_type=[node.__name__]): # node.__name__ : clickhouse
118118
"""
119119
it is to check db setting whether is correct!
120120
:param db_settings:
@@ -176,7 +176,7 @@ async def _post(self, url, sql, session):
176176
result = await resp.read()
177177

178178
status = resp.status
179-
reason = resp.reason
179+
# reason = resp.reason
180180
if status != 200:
181181
raise ValueError(result)
182182
return result
@@ -292,19 +292,24 @@ def execute(self, *sql, convert_to: str = 'dataframe', loop=None, ):
292292
to_df=to_df)
293293
return result
294294

295-
def query(self, sql: str):
295+
def query(self, *sql: str):
296296
"""
297297
require to upgrade
298298
:param sql:
299299
:return:
300300
"""
301-
result = self.execute(sql, convert_to='dataframe', loop=None, )
301+
result = self.execute(*sql, convert_to='dataframe', loop=None, )
302302
return result
303303

304304

305305
class ClickHouseTableNode(ClickHouseBaseNode):
306-
def __init__(self, conn_str: str):
307-
db_settings = _parse_rfc1738_args(conn_str)
306+
def __init__(self, conn_str: (str, dict)):
307+
if isinstance(conn_str, str):
308+
db_settings = _parse_rfc1738_args(conn_str)
309+
elif isinstance(conn_str, dict):
310+
db_settings = conn_str
311+
else:
312+
raise ParameterTypeError(f'conn_str must be str or dict but get: {type(conn_str)}')
308313
super(ClickHouseTableNode, self).__init__(**db_settings)
309314

310315
@property

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def read_file(filename):
3434
'numpy>=1.18.5',
3535
'requests>=2.20.0',
3636
'aiohttp>=3.6.2',
37-
'nest-asyncio>-1.4.1'
37+
'nest-asyncio>=1.4.1'
3838
],
3939

4040
)

test/test_connection.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
# coding=utf-8
12
import unittest
23

34
from ClickSQL.clickhouse.ClickHouse import ClickHouseTableNode
@@ -6,12 +7,11 @@
67

78

89
class MyTestConnectionCase(unittest.TestCase):
9-
def test_connection_success(self):
10-
conn = "clickhouse://default:Imsn0wfree@47.104.186.157:8123/system"
11-
node = ClickHouseTableNode(conn)
12-
df1 = node.tables
13-
14-
self.assertGreater(len(df1), 5)
10+
# def test_connection_success(self):
11+
# node = ClickHouseTableNode(conn)
12+
# df1 = node.tables
13+
#
14+
# self.assertGreater(len(df1), 5)
1515

1616
def test_connection_settings_failure_empty(self):
1717
conn = ""

test/testing.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
# coding=utf-8
2-
import pandas as pd
3-
import numpy as np
4-
5-
2+
import unittest
3+
from ClickSQL import ClickHouseTableNode
64

75
if __name__ == '__main__':
6+
print(ClickHouseTableNode)
87

98
pass
10-
11-

0 commit comments

Comments
 (0)