Skip to content

Commit 11a8b66

Browse files
authored
Added support for providing a timeout option while setting up a connection (#85)
1 parent 2ee148a commit 11a8b66

File tree

2 files changed

+48
-1
lines changed

2 files changed

+48
-1
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
from pinotdb import connect
2+
import time
3+
import pytest
4+
import httpx
5+
6+
## Start Pinot Quickstart Batch
7+
## docker run --name pinot-quickstart -p 2123:2123 -p 9000:9000 -p 8000:8000 \
8+
## -d apachepinot/pinot:latest QuickStart -type hybrid
9+
10+
def run_pinot_quickstart_timeout_example() -> None:
11+
12+
#Test 1 : Try without timeout. The request should succeed.
13+
14+
conn = connect(host="localhost", port=8000, path="/query/sql", scheme="http")
15+
curs = conn.cursor()
16+
sql = "SELECT * FROM airlineStats LIMIT 5"
17+
print(f"Sending SQL to Pinot: {sql}")
18+
curs.execute(sql)
19+
conn.close()
20+
21+
#Test 2 : Try with timeout=None. The request should succeed.
22+
23+
conn = connect(host="localhost", port=8000, path="/query/sql", scheme="http", timeout=None)
24+
curs = conn.cursor()
25+
sql = "SELECT count(*) FROM airlineStats LIMIT 5"
26+
print(f"Sending SQL to Pinot: {sql}")
27+
curs.execute(sql)
28+
conn.close()
29+
30+
#Test 3 : Try with a really small timeout. The query should raise an exception.
31+
32+
conn = connect(host="localhost", port=8000, path="/query/sql", scheme="http", timeout=0.001)
33+
curs = conn.cursor()
34+
sql = "SELECT AirlineID, sum(Cancelled) FROM airlineStats WHERE Year > 2010 GROUP BY AirlineID LIMIT 5"
35+
print(f"Sending SQL to Pinot: {sql}")
36+
with pytest.raises(httpx.ReadTimeout):
37+
curs.execute(sql)
38+
conn.close()
39+
40+
41+
def run_main():
42+
run_pinot_quickstart_timeout_example()
43+
44+
45+
if __name__ == '__main__':
46+
run_main()

pinotdb/db.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,8 @@ def cursor(self):
179179
"""Return a new Cursor Object using the connection."""
180180
if not self.session or self.session.is_closed:
181181
self.session = httpx.Client(
182-
verify=self._kwargs.get('verify_ssl'))
182+
verify=self._kwargs.get('verify_ssl'),
183+
timeout=self._kwargs.get('timeout'))
183184

184185
self._kwargs['session'] = self.session
185186
cursor = Cursor(*self._args, **self._kwargs)

0 commit comments

Comments
 (0)