Skip to content

Commit f5a87ee

Browse files
committed
improve logging
1 parent d33dd31 commit f5a87ee

File tree

5 files changed

+25
-24
lines changed

5 files changed

+25
-24
lines changed

main.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
import asyncio
22
from py_boilingdata import BoilingData
33

4-
boiling = BoilingData()
5-
64

75
async def main():
6+
boiling = BoilingData()
87
await boiling.connect()
98
results = await boiling.execute(
109
"""
@@ -17,5 +16,4 @@ async def main():
1716
await boiling.close()
1817

1918

20-
loop = asyncio.get_event_loop()
21-
loop.run_until_complete(main())
19+
asyncio.new_event_loop().run_until_complete(main())

py_boilingdata/__init__.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,21 +38,24 @@
3838
class BoilingData:
3939
"""Run SQL with BoilingData and local DuckDB"""
4040

41-
def __init__(self, log_level=logging.ERROR):
41+
def __init__(self, log_level=logging.DEBUG):
42+
logging.basicConfig()
4243
self.log_level = log_level
4344
self.logger = logging.getLogger("BoilingData")
4445
self.logger.setLevel(self.log_level)
4546
self.bd_conn = BoilingDataConnection(log_level=self.log_level)
4647
self.conn = duckdb.connect(":memory:")
4748

4849
async def _populate(self):
50+
self.logger.debug("Creating local boilingdata data catalog")
4951
self.conn.execute("ATTACH ':memory:' AS boilingdata;")
5052
self.conn.execute("SET search_path='memory,boilingdata';")
5153
# Boiling specific table, contains data shares
5254
q = "SELECT * FROM information_schema.create_tables_statements"
5355
tables = await self.execute(q, None, True)
5456
if tables:
5557
for table in tables:
58+
self.logger.debug(f"Creating table {table}")
5659
self.conn.execute(table)
5760

5861
def _is_boiling_execute(self, sql):
@@ -98,6 +101,7 @@ async def close(self):
98101

99102
async def execute(self, sql, cb=None, force_boiling=False):
100103
"""Send SQL Query to Boiling or run locally"""
104+
sql = sql.replace("\n", " ")
101105
if not force_boiling and not self._is_boiling_execute(sql):
102106
return self.conn.execute(sql).fetchall()
103107
fut = await self.bd_conn.bd_execute(sql, cb)
@@ -199,7 +203,10 @@ def _on_msg(self, ws_app, data):
199203
if not reqId:
200204
return
201205
msg_type = msg.get("messageType")
202-
# TODO: Store statistics sent from Boiling (INFO messages)
206+
if msg_type == "LOG_MESSAGE":
207+
log_level = msg.get("logLevel")
208+
if log_level == "ERROR":
209+
raise Exception(msg.get("logMessage"))
203210
if msg_type != "DATA":
204211
return
205212
req = self.requests.get(reqId)
@@ -252,6 +259,7 @@ async def connect(self):
252259
"""Connect to BoilingData WebSocket API"""
253260
if self.websocket is not None:
254261
raise Exception("WebSocket already exists")
262+
self.logger.info("Connecting")
255263
self.websocket = websocket.WebSocket()
256264
websocket.enableTrace(self.ws_trace)
257265
auth_headers = self._get_auth_headers()

py_boilingdata/data_queue.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
from pprint import pprint
2-
3-
41
class DataQueue:
52
def __init__(self, requestId, callback, fut=None):
63
self.requestId = requestId
@@ -21,7 +18,6 @@ def _have_all_parts(self):
2118
if self.parts_done == True:
2219
return True
2320
msg = self.data[0]
24-
# print(msg)
2521
totalBatches = msg.get("totalBatches")
2622
totalSubBatches = msg.get("totalSubBatches")
2723
totalSplitSerials = msg.get("totalSplitSerials")
@@ -72,7 +68,6 @@ def _have_all_parts(self):
7268
# print(f"\tsplits: {len(value.get('splits'))}/{totalSplits}")
7369
if len(value.get("splits")) < totalSplits:
7470
return False
75-
# pprint(self.batchCounters)
7671
self.parts_done = True
7772
return True
7873

@@ -99,10 +94,8 @@ def _notify(self):
9994
raise Exception("Deleted queue!")
10095
data = self._compile()
10196
if self.callback:
102-
# print(f"CALLING CALLBACK {data}")
10397
self.callback({"data": data, "requestId": self.requestId})
10498
if self.fut:
105-
# print(f"SETTING FUT RESULT: {data}")
10699
self.fut.set_result(data)
107100

108101
##

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ asyncio_mode = "auto"
33

44
[tool.poetry]
55
name = "py-boilingdata"
6-
version = "0.2.3"
6+
version = "0.2.4"
77
description = "BoilingData (websockets) client for Python"
88
authors = ["Dan Forsberg <dan@boilingdata.com>"]
99
readme = "README.md"

tests/test_connection.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,16 @@ async def test_local_tables():
3939

4040

4141
@pytest.mark.asyncio
42-
async def test_bd_query_cb():
42+
async def test_bd_query():
4343
"""Small response from Boiling"""
44+
q = "SELECT first_name, email FROM parquet_scan('s3://boilingdata-demo/test.parquet') LIMIT 1"
45+
data = await boiling.execute(q) # awaits as lont as the result is available
46+
assert data == [{"email": "ajordan0@com.com", "first_name": "Amanda"}]
47+
48+
49+
@pytest.mark.asyncio
50+
async def test_bd_query_cb():
51+
"""Small response from Boiling with callback"""
4452
global data
4553
data = None
4654

@@ -49,17 +57,11 @@ def cb(resp):
4957
global data
5058
data = resp
5159

52-
q = "SELECT first_name, email FROM parquet_scan('s3://boilingdata-demo/test.parquet') LIMIT 1"
60+
q = "SELECT email FROM parquet_scan('s3://boilingdata-demo/test.parquet') LIMIT 2"
5361
await boiling.execute(q, cb) # only awaits as long as the request is dispatched
54-
await asyncio.sleep(5)
55-
assert data == [{"email": "ajordan0@com.com", "first_name": "Amanda"}]
56-
57-
58-
@pytest.mark.asyncio
59-
async def test_bd_query():
60-
"""Small response from Boiling"""
6162
q = "SELECT first_name, email FROM parquet_scan('s3://boilingdata-demo/test.parquet') LIMIT 1"
62-
data = await boiling.execute(q) # awaits as lont as the result is available
63+
await boiling.execute(q, cb) # only awaits as long as the request is dispatched
64+
await asyncio.sleep(5) # let them race...
6365
assert data == [{"email": "ajordan0@com.com", "first_name": "Amanda"}]
6466

6567

0 commit comments

Comments
 (0)