Skip to content

Commit a6aee3a

Browse files
authored
Return None if no query stats from SDK (#44)
1 parent 11c6b5d commit a6aee3a

File tree

7 files changed

+36
-40
lines changed

7 files changed

+36
-40
lines changed

docs/source/reference/session/base_qldb_session.rst

-8
This file was deleted.

docs/source/reference/session/pooled_qldb_session.rst

-7
This file was deleted.

pyqldb/cursor/buffered_cursor.py

+8-6
Original file line numberDiff line numberDiff line change
@@ -40,18 +40,20 @@ def __next__(self):
4040

4141
def get_consumed_ios(self):
4242
"""
43-
Return a dictionary containing the total amount of IO requests for a statement's execution.
43+
Return a dictionary containing the total amount of IO requests for a statement execution. Return None if there
44+
were no read IOs for a statement execution.
4445
45-
:rtype: dict
46-
:return: The amount of read IO requests for a statement's execution.
46+
:rtype: dict/None
47+
:return: The amount of read IO requests for a statement execution.
4748
"""
4849
return self._consumed_ios
4950

5051
def get_timing_information(self):
5152
"""
52-
Return a dictionary containing the total amount of processing time for a statement's execution.
53+
Return a dictionary containing the total amount of processing time for a statement execution. Return None if
54+
there was no timing information for a statement execution.
5355
54-
:rtype: dict
55-
:return: The amount of processing time in milliseconds for a statement's execution.
56+
:rtype: dict/None
57+
:return: The amount of processing time in milliseconds for a statement execution.
5658
"""
5759
return self._timing_information

pyqldb/cursor/read_ahead_cursor.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class ReadAheadCursor(StreamCursor):
2626
size `read_ahead` and fetch results asynchronously to fill the queue.
2727
2828
:type statement_result: dict
29-
:param statement_result: The initial result set data dictionary of the statement's execution.
29+
:param statement_result: The initial result set data dictionary of the statement execution.
3030
3131
:type session: :py:class:`pyqldb.communication.session_client.SessionClient`
3232
:param session: The parent session that represents the communication channel to QLDB.

pyqldb/cursor/stream_cursor.py

+12-9
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class StreamCursor:
1818
An iterable class representing a stream cursor on a statement's result set.
1919
2020
:type statement_result: dict
21-
:param statement_result: The initial result set data dictionary of the statement's execution.
21+
:param statement_result: The initial result set data dictionary of the statement execution.
2222
2323
:type session: :py:class:`pyqldb.communication.session_client.SessionClient`
2424
:param session: The parent session that represents the communication channel to QLDB.
@@ -78,21 +78,24 @@ def close(self):
7878

7979
def get_consumed_ios(self):
8080
"""
81-
Return a dictionary containing the accumulated amount of IO requests for a statement's execution.
81+
Return a dictionary containing the accumulated amount of IO requests for a statement execution. Return None if
82+
there were no read IOs for a statement execution.
8283
83-
:rtype: dict
84-
:return: The amount of read IO requests for a statement's execution.
84+
:rtype: dict/None
85+
:return: The amount of read IO requests for a statement execution.
8586
"""
86-
return {'ReadIOs': self._read_ios}
87+
return None if self._read_ios is None else {'ReadIOs': self._read_ios}
8788

8889
def get_timing_information(self):
8990
"""
90-
Return a dictionary containing the accumulated amount of processing time for a statement's execution.
91+
Return a dictionary containing the accumulated amount of processing time for a statement execution. Return None
92+
if there was no timing information for a statement execution.
9193
92-
:rtype: dict
93-
:return: The amount of processing time in milliseconds for a statement's execution.
94+
:rtype: dict/None
95+
:return: The amount of processing time in milliseconds for a statement execution.
9496
"""
95-
return {'ProcessingTimeMilliseconds': self._processing_time_milliseconds}
97+
return None if self._processing_time_milliseconds is None else {'ProcessingTimeMilliseconds':
98+
self._processing_time_milliseconds}
9699

97100
def _are_there_more_results(self):
98101
"""

pyqldb/driver/qldb_driver.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ class QldbDriver:
8888
8989
:raises TypeError: When config is not an instance of :py:class:`botocore.config.Config`.
9090
When boto3_session is not an instance of :py:class:`boto3.session.Session`.
91-
When retry_config is not an instance of :py:class:pyqldb.config.retry_config.RetryConfig.
91+
When retry_config is not an instance of :py:class:`pyqldb.config.retry_config.RetryConfig`.
9292
9393
:raises ValueError: When `max_concurrent_transactions` exceeds the limit set by the client.
9494
When `max_concurrent_transactions` is negative.

tests/unit/helper_functions.py

+14-8
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111

1212
from unittest.mock import MagicMock
1313

14-
from pyqldb.cursor.buffered_cursor import BufferedCursor
1514
from pyqldb.cursor.stream_cursor import StreamCursor
1615

16+
1717
def generate_statement_result(read_io, write_io, processing_time, next_page_token, is_first_page,
1818
values=[{'IonBinary': 1}]):
1919
"""
@@ -35,21 +35,27 @@ def generate_statement_result(read_io, write_io, processing_time, next_page_toke
3535
return statement_result
3636

3737

38-
def assert_query_stats(class_instance, buffered_cursor, read_ios_assert, write_ios_assert, timing_information_assert):
38+
def assert_query_stats(test_case, buffered_cursor, read_ios_assert, write_ios_assert, timing_information_assert):
3939
"""
4040
Asserts the query statistics returned by the cursor.
4141
"""
4242
consumed_ios = buffered_cursor.get_consumed_ios()
43-
class_instance.assertIsNotNone(consumed_ios)
44-
read_ios = consumed_ios.get('ReadIOs')
43+
if read_ios_assert is not None:
44+
test_case.assertIsNotNone(consumed_ios)
45+
read_ios = consumed_ios.get('ReadIOs')
4546

46-
class_instance.assertEqual(read_ios, read_ios_assert)
47+
test_case.assertEqual(read_ios, read_ios_assert)
48+
else:
49+
test_case.assertEqual(consumed_ios, None)
4750

4851
timing_information = buffered_cursor.get_timing_information()
49-
class_instance.assertIsNotNone(timing_information)
50-
processing_time_milliseconds = timing_information.get('ProcessingTimeMilliseconds')
52+
if timing_information_assert is not None:
53+
test_case.assertIsNotNone(timing_information)
54+
processing_time_milliseconds = timing_information.get('ProcessingTimeMilliseconds')
5155

52-
class_instance.assertEqual(processing_time_milliseconds, timing_information_assert)
56+
test_case.assertEqual(processing_time_milliseconds, timing_information_assert)
57+
else:
58+
test_case.assertEqual(timing_information_assert, None)
5359

5460

5561
def create_stream_cursor(mock_session, mock_statement_result_execute, mock_statement_result_fetch):

0 commit comments

Comments
 (0)