Skip to content

Commit 90e690e

Browse files
committed
Add test on issue 60
1 parent 045c8e2 commit 90e690e

File tree

1 file changed

+74
-0
lines changed

1 file changed

+74
-0
lines changed

tests/test_issue60.py

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
import threading
2+
import time
3+
import unittest
4+
import chdb
5+
6+
query_str = '''
7+
SELECT
8+
town,
9+
district,
10+
count() AS c,
11+
round(avg(price)) AS price
12+
FROM url('https://datasets-documentation.s3.eu-west-3.amazonaws.com/house_parquet/house_0.parquet')
13+
GROUP BY
14+
town,
15+
district
16+
LIMIT 10
17+
'''
18+
19+
# query_str = '''
20+
# SELECT
21+
# town,
22+
# district,
23+
# count() AS c,
24+
# round(avg(price)) AS price
25+
# FROM file('/home/Clickhouse/server/chdb-server/house_0.parquet', Parquet)
26+
# GROUP BY
27+
# town,
28+
# district
29+
# ORDER BY c DESC
30+
# LIMIT 10
31+
# '''
32+
33+
expected_result = '''"BIRMINGHAM","BIRMINGHAM",35326,146648
34+
"LEEDS","LEEDS",30640,160353
35+
"SHEFFIELD","SHEFFIELD",22420,153128
36+
"MANCHESTER","MANCHESTER",21917,156390
37+
"BRISTOL","CITY OF BRISTOL",21662,217596
38+
"LIVERPOOL","LIVERPOOL",19689,128179
39+
"LONDON","WANDSWORTH",18442,456216
40+
"CARDIFF","CARDIFF",16449,177420
41+
"BRADFORD","BRADFORD",14468,100065
42+
"COVENTRY","COVENTRY",13927,149269
43+
'''
44+
45+
result = ""
46+
47+
class myThread(threading.Thread):
48+
def __init__(self, threadID, name, delay):
49+
threading.Thread.__init__(self)
50+
self.threadID = threadID
51+
self.name = name
52+
self.delay = delay
53+
54+
def run(self):
55+
print_chdb(self.name, self.delay)
56+
57+
58+
def print_chdb(threadName, delay):
59+
global result
60+
result = chdb.query(query_str, 'CSV')
61+
print(result)
62+
time.sleep(delay)
63+
print("%s: %s" % (threadName, time.ctime(time.time())))
64+
65+
66+
class TestQueryInThread(unittest.TestCase):
67+
def test_query_in_thread(self):
68+
thread1 = myThread(1, "Thread-1", 1)
69+
thread1.start()
70+
thread1.join()
71+
self.assertEqual(str(result), expected_result)
72+
73+
if __name__ == '__main__':
74+
unittest.main()

0 commit comments

Comments
 (0)