mapepire-python 1.0.0__tar.gz → 1.0.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. {mapepire_python-1.0.0 → mapepire_python-1.0.1}/PKG-INFO +1 -1
  2. {mapepire_python-1.0.0 → mapepire_python-1.0.1}/mapepire_python/client/query.py +1 -1
  3. {mapepire_python-1.0.0 → mapepire_python-1.0.1}/mapepire_python/core/cursor.py +65 -34
  4. {mapepire_python-1.0.0 → mapepire_python-1.0.1}/mapepire_python/version.py +1 -1
  5. {mapepire_python-1.0.0 → mapepire_python-1.0.1}/mapepire_python.egg-info/PKG-INFO +1 -1
  6. {mapepire_python-1.0.0 → mapepire_python-1.0.1}/LICENSE +0 -0
  7. {mapepire_python-1.0.0 → mapepire_python-1.0.1}/README.md +0 -0
  8. {mapepire_python-1.0.0 → mapepire_python-1.0.1}/mapepire_python/__init__.py +0 -0
  9. {mapepire_python-1.0.0 → mapepire_python-1.0.1}/mapepire_python/async_base_job.py +0 -0
  10. {mapepire_python-1.0.0 → mapepire_python-1.0.1}/mapepire_python/asyncio/__init__.py +0 -0
  11. {mapepire_python-1.0.0 → mapepire_python-1.0.1}/mapepire_python/asyncio/connection.py +0 -0
  12. {mapepire_python-1.0.0 → mapepire_python-1.0.1}/mapepire_python/asyncio/cursor.py +0 -0
  13. {mapepire_python-1.0.0 → mapepire_python-1.0.1}/mapepire_python/authentication/kerberosTokenProvider.py +0 -0
  14. {mapepire_python-1.0.0 → mapepire_python-1.0.1}/mapepire_python/base_job.py +0 -0
  15. {mapepire_python-1.0.0 → mapepire_python-1.0.1}/mapepire_python/client/__init__.py +0 -0
  16. {mapepire_python-1.0.0 → mapepire_python-1.0.1}/mapepire_python/client/async_sql_job.py +0 -0
  17. {mapepire_python-1.0.0 → mapepire_python-1.0.1}/mapepire_python/client/sql_job.py +0 -0
  18. {mapepire_python-1.0.0 → mapepire_python-1.0.1}/mapepire_python/client/websocket_client.py +0 -0
  19. {mapepire_python-1.0.0 → mapepire_python-1.0.1}/mapepire_python/core/__init__.py +0 -0
  20. {mapepire_python-1.0.0 → mapepire_python-1.0.1}/mapepire_python/core/connection.py +0 -0
  21. {mapepire_python-1.0.0 → mapepire_python-1.0.1}/mapepire_python/core/exceptions.py +0 -0
  22. {mapepire_python-1.0.0 → mapepire_python-1.0.1}/mapepire_python/core/utils.py +0 -0
  23. {mapepire_python-1.0.0 → mapepire_python-1.0.1}/mapepire_python/data_types.py +0 -0
  24. {mapepire_python-1.0.0 → mapepire_python-1.0.1}/mapepire_python/pool/__init__.py +0 -0
  25. {mapepire_python-1.0.0 → mapepire_python-1.0.1}/mapepire_python/pool/async_websocket_client.py +0 -0
  26. {mapepire_python-1.0.0 → mapepire_python-1.0.1}/mapepire_python/pool/pool_client.py +0 -0
  27. {mapepire_python-1.0.0 → mapepire_python-1.0.1}/mapepire_python/pool/pool_job.py +0 -0
  28. {mapepire_python-1.0.0 → mapepire_python-1.0.1}/mapepire_python/pool/pool_query.py +0 -0
  29. {mapepire_python-1.0.0 → mapepire_python-1.0.1}/mapepire_python/py.typed +0 -0
  30. {mapepire_python-1.0.0 → mapepire_python-1.0.1}/mapepire_python/query_manager.py +0 -0
  31. {mapepire_python-1.0.0 → mapepire_python-1.0.1}/mapepire_python/ssl.py +0 -0
  32. {mapepire_python-1.0.0 → mapepire_python-1.0.1}/mapepire_python/websocket.py +0 -0
  33. {mapepire_python-1.0.0 → mapepire_python-1.0.1}/mapepire_python.egg-info/SOURCES.txt +0 -0
  34. {mapepire_python-1.0.0 → mapepire_python-1.0.1}/mapepire_python.egg-info/dependency_links.txt +0 -0
  35. {mapepire_python-1.0.0 → mapepire_python-1.0.1}/mapepire_python.egg-info/requires.txt +0 -0
  36. {mapepire_python-1.0.0 → mapepire_python-1.0.1}/mapepire_python.egg-info/top_level.txt +0 -0
  37. {mapepire_python-1.0.0 → mapepire_python-1.0.1}/pyproject.toml +0 -0
  38. {mapepire_python-1.0.0 → mapepire_python-1.0.1}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: mapepire-python
3
- Version: 1.0.0
3
+ Version: 1.0.1
4
4
  Author-email: Adam Shedivy <adam.shedivy@ibm.com>, Irfan Sharif <IrfanSharif@ibm.com>
5
5
  License: Apache License
6
6
  Version 2.0, January 2004
@@ -152,7 +152,7 @@ class Query(Generic[T]):
152
152
  return query_result
153
153
 
154
154
  @handle_ws_errors
155
- def fetch_more(self, rows_to_fetch: Optional[int] = None) -> Dict[str, Any]:
155
+ def fetch_more(self, rows_to_fetch: Optional[int] = None) -> SqlMoreResponse:
156
156
  if rows_to_fetch is None:
157
157
  rows_to_fetch = self._rows_to_fetch
158
158
  else:
@@ -1,7 +1,18 @@
1
1
  import logging
2
2
  import weakref
3
3
  from collections import deque
4
- from typing import TYPE_CHECKING, Any, Optional, Sequence, Type, Union, cast
4
+ from dataclasses import dataclass, field
5
+ from typing import (
6
+ TYPE_CHECKING,
7
+ Any,
8
+ Deque,
9
+ List,
10
+ Optional,
11
+ Sequence,
12
+ Type,
13
+ Union,
14
+ cast,
15
+ )
5
16
 
6
17
  import pep249
7
18
  from pep249 import (
@@ -14,23 +25,33 @@ from pep249 import (
14
25
  SQLQuery,
15
26
  )
16
27
 
17
- if TYPE_CHECKING:
18
- # pylint: disable=cyclic-import
19
- from ..core.connection import Connection
20
-
21
28
  from ..client.query import Query, QueryState
22
29
  from ..client.sql_job import SQLJob
23
30
  from ..core.exceptions import convert_runtime_errors
24
31
  from ..core.utils import DB_TYPE_MAP, QueryResultSet, raise_if_closed, row_to_tuple
25
32
  from ..data_types import QueryOptions
26
33
 
34
+ if TYPE_CHECKING:
35
+ # pylint: disable=cyclic-import
36
+ from ..core.connection import Connection
37
+
27
38
  __all__ = ["Cursor"]
28
39
 
29
40
  logger = logging.getLogger(__name__)
30
41
 
31
42
 
43
+ @dataclass
44
+ class _ResultState:
45
+ """Fetch state for one query: its column metadata and rows received but not yet returned."""
46
+
47
+ metadata: Any
48
+ rows: Deque[Any] = field(default_factory=deque)
49
+
50
+
32
51
  class Cursor(pep249.CursorConnectionMixin, pep249.IterableCursorMixin, pep249.TransactionalCursor):
33
52
  max_rows = 2147483647
53
+ # Rows requested per round trip when fetchone() (and so iteration) needs more data.
54
+ fetch_size = 100
34
55
 
35
56
  def __init__(self, connection: "Connection", job: SQLJob) -> None:
36
57
  super().__init__()
@@ -38,7 +59,10 @@ class Cursor(pep249.CursorConnectionMixin, pep249.IterableCursorMixin, pep249.Tr
38
59
  self.job = job
39
60
  self.query: Optional[Query] = None
40
61
  self.query_q: deque[Query] = deque(maxlen=20)
41
- self._result_set: Optional[QueryResultSet] = None
62
+ # Keyed weakly so a query evicted from query_q takes its buffered rows with it.
63
+ self._results: "weakref.WeakKeyDictionary[Query, _ResultState]" = (
64
+ weakref.WeakKeyDictionary()
65
+ )
42
66
  self._metadata = None
43
67
  self.__closed = False
44
68
  self.__has_results = False
@@ -113,6 +137,8 @@ class Cursor(pep249.CursorConnectionMixin, pep249.IterableCursorMixin, pep249.Tr
113
137
  self.query = query
114
138
  self.__set_has_results(True)
115
139
  self.query_q.append(query)
140
+ # Rows that arrive with the execute response are served by the first fetch.
141
+ self._results[query] = _ResultState(self._metadata, deque(qs.data or []))
116
142
  else:
117
143
  self.__set_has_results(False)
118
144
 
@@ -156,42 +182,46 @@ class Cursor(pep249.CursorConnectionMixin, pep249.IterableCursorMixin, pep249.Tr
156
182
  for col in self._metadata.columns
157
183
  ]
158
184
 
185
+ def _fetch_rows(self, size: int, batch_size: int = 0) -> ResultSet:
186
+ """Return up to ``size`` rows of the current query as tuples.
187
+
188
+ Buffered rows are served first; the server is only asked for more once
189
+ the buffer is empty, and then for at least ``batch_size`` rows. Once the
190
+ result set is exhausted this returns what it has (possibly ``[]``)
191
+ instead of raising.
192
+ """
193
+ if self.query is None:
194
+ return []
195
+ state = self._results[self.query]
196
+ rows: List[ResultRow] = []
197
+ while len(rows) < size:
198
+ if not state.rows:
199
+ if self.query.state == QueryState.RUN_DONE:
200
+ break
201
+ res = self.query.fetch_more(rows_to_fetch=max(size - len(rows), batch_size))
202
+ if not res.data:
203
+ break
204
+ state.rows.extend(res.data)
205
+ rows.append(row_to_tuple(state.rows.popleft(), state.metadata))
206
+ return rows
207
+
159
208
  @raise_if_closed
160
209
  @convert_runtime_errors
161
210
  def fetchone(self) -> Optional[ResultRow]:
162
- if not self.query or self.query.state == QueryState.RUN_DONE:
163
- return None
164
- res = self.query.fetch_more(rows_to_fetch=1)
165
- if res:
166
- self._result_set = QueryResultSet(res)
167
- if self._result_set.data:
168
- return row_to_tuple(self._result_set.data[0], self._metadata)
169
- return None
211
+ rows = self._fetch_rows(1, batch_size=self.fetch_size)
212
+ return rows[0] if rows else None
170
213
 
171
214
  @raise_if_closed
172
215
  @convert_runtime_errors
173
216
  def fetchall(self) -> ResultSet:
174
- if not self.query:
175
- return []
176
-
177
- res = self.query.fetch_more(rows_to_fetch=self.max_rows)
178
- if res:
179
- self._result_set = QueryResultSet(res)
180
- return [row_to_tuple(row, self._metadata) for row in self._result_set.data]
181
- return []
217
+ return self._fetch_rows(self.max_rows)
182
218
 
183
219
  @raise_if_closed
184
220
  @convert_runtime_errors
185
221
  def fetchmany(self, size: Optional[int] = None) -> ResultSet:
186
222
  if size is None:
187
223
  size = self.arraysize
188
- if not self.query:
189
- return []
190
- res = self.query.fetch_more(rows_to_fetch=size)
191
- if res:
192
- self._result_set = QueryResultSet(res)
193
- return [row_to_tuple(row, self._metadata) for row in self._result_set.data]
194
- return []
224
+ return self._fetch_rows(size)
195
225
 
196
226
  def executescript(self, script: SQLQuery) -> "Cursor":
197
227
  """A lazy implementation of SQLite's `executescript`."""
@@ -202,6 +232,7 @@ class Cursor(pep249.CursorConnectionMixin, pep249.IterableCursorMixin, pep249.Tr
202
232
  if len(self.query_q) > 1:
203
233
  self.query_q.popleft()
204
234
  self.query = self.query_q[0]
235
+ self._metadata = self._results[self.query].metadata
205
236
  self.__set_has_results(True)
206
237
  return True
207
238
  return None
@@ -214,11 +245,11 @@ class Cursor(pep249.CursorConnectionMixin, pep249.IterableCursorMixin, pep249.Tr
214
245
  if self._closed:
215
246
  return
216
247
  logger.debug("Closing cursor")
217
- if self.query:
218
- for q in self.query_q:
219
- q.close()
220
- self.query_q.clear()
221
- self._closed = True
248
+ for q in self.query_q:
249
+ q.close()
250
+ self.query_q.clear()
251
+ self._results.clear()
252
+ self._closed = True
222
253
 
223
254
  def commit(self) -> None:
224
255
  self.job.query_and_run("COMMIT")
@@ -2,7 +2,7 @@ _MAJOR = "1"
2
2
  _MINOR = "0"
3
3
  # On main and in a nightly release the patch should be one ahead of the last
4
4
  # released build.
5
- _PATCH = "0"
5
+ _PATCH = "1"
6
6
  # This is mainly for nightly builds which have the suffix ".dev$DATE". See
7
7
  # https://semver.org/#is-v123-a-semantic-version for the semantics.
8
8
  _SUFFIX = ""
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: mapepire-python
3
- Version: 1.0.0
3
+ Version: 1.0.1
4
4
  Author-email: Adam Shedivy <adam.shedivy@ibm.com>, Irfan Sharif <IrfanSharif@ibm.com>
5
5
  License: Apache License
6
6
  Version 2.0, January 2004
File without changes