snowflake-connector-python 5.2.0__cp315-cp315-win_amd64.whl
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.
- snowflake/connector/__init__.py +148 -0
- snowflake/connector/_common/__init__.py +0 -0
- snowflake/connector/_common/extras.py +134 -0
- snowflake/connector/_common/telemetry.py +221 -0
- snowflake/connector/_common/wif_util.py +92 -0
- snowflake/connector/_core/sf_core_python.cp315-win_amd64.pyd +0 -0
- snowflake/connector/_core/sf_core_python.pyi +79 -0
- snowflake/connector/_internal/__init__.py +6 -0
- snowflake/connector/_internal/_private_key_helper.py +31 -0
- snowflake/connector/_internal/api_client/__init__.py +93 -0
- snowflake/connector/_internal/api_client/bridge.py +41 -0
- snowflake/connector/_internal/api_client/client_api.py +976 -0
- snowflake/connector/_internal/arrow.py +47 -0
- snowflake/connector/_internal/arrow_context.py +240 -0
- snowflake/connector/_internal/arrow_stream_async.py +266 -0
- snowflake/connector/_internal/arrow_stream_iterator.cp311-win_amd64.pyd +0 -0
- snowflake/connector/_internal/arrow_stream_iterator.cp312-win_amd64.pyd +0 -0
- snowflake/connector/_internal/arrow_stream_iterator.cp313-win_amd64.pyd +0 -0
- snowflake/connector/_internal/arrow_stream_iterator.cp314-win_amd64.pyd +0 -0
- snowflake/connector/_internal/arrow_stream_iterator.cp314t-win_amd64.pyd +0 -0
- snowflake/connector/_internal/arrow_stream_iterator.cp315-win_amd64.pyd +0 -0
- snowflake/connector/_internal/arrow_stream_iterator.pyi +42 -0
- snowflake/connector/_internal/arrow_stream_utils.py +171 -0
- snowflake/connector/_internal/authenticator_type.py +53 -0
- snowflake/connector/_internal/backward_compatibility.py +245 -0
- snowflake/connector/_internal/binding_converters.py +741 -0
- snowflake/connector/_internal/config_utils.py +71 -0
- snowflake/connector/_internal/connection/__init__.py +39 -0
- snowflake/connector/_internal/connection/connection.py +616 -0
- snowflake/connector/_internal/connection/connection_types.py +13 -0
- snowflake/connector/_internal/connection/constants.py +25 -0
- snowflake/connector/_internal/connection/decorators.py +31 -0
- snowflake/connector/_internal/connection/freezable_proxy.py +104 -0
- snowflake/connector/_internal/connection/queries.py +10 -0
- snowflake/connector/_internal/connection_config_mixin.py +755 -0
- snowflake/connector/_internal/cursor/__init__.py +25 -0
- snowflake/connector/_internal/cursor/base.py +732 -0
- snowflake/connector/_internal/cursor/cursor_types.py +13 -0
- snowflake/connector/_internal/cursor/decorators.py +56 -0
- snowflake/connector/_internal/cursor/query_result.py +202 -0
- snowflake/connector/_internal/cursor/query_result_waiter.py +98 -0
- snowflake/connector/_internal/cursor/result_metadata.py +255 -0
- snowflake/connector/_internal/cursor/result_set_wrapper.py +66 -0
- snowflake/connector/_internal/decorators.py +539 -0
- snowflake/connector/_internal/error_kinds.py +111 -0
- snowflake/connector/_internal/errorcode.py +35 -0
- snowflake/connector/_internal/errorhandler.py +278 -0
- snowflake/connector/_internal/fips.py +28 -0
- snowflake/connector/_internal/logging/__init__.py +52 -0
- snowflake/connector/_internal/logging/config.py +134 -0
- snowflake/connector/_internal/logging/core_logger.py +218 -0
- snowflake/connector/_internal/logging/native_extension_logger.py +144 -0
- snowflake/connector/_internal/logout_config_mapping.py +187 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/ArrayConverter.cpp +57 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/ArrayConverter.hpp +29 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/ArrowTableConverter.cpp +943 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/ArrowTableConverter.hpp +63 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/BinaryConverter.cpp +18 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/BinaryConverter.hpp +26 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/BooleanConverter.cpp +21 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/BooleanConverter.hpp +23 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/CArrowIterator.cpp +118 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/CArrowIterator.hpp +116 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/CArrowStreamIterator.cpp +323 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/CArrowStreamIterator.hpp +133 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/CArrowStreamTableIterator.cpp +275 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/CArrowStreamTableIterator.hpp +168 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/ConverterUtil.cpp +439 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/ConverterUtil.hpp +30 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/DateConverter.cpp +48 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/DateConverter.hpp +46 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/DecFloatConverter.cpp +76 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/DecFloatConverter.hpp +35 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/DecimalConverter.cpp +90 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/DecimalConverter.hpp +63 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/FixedSizeListConverter.cpp +62 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/FixedSizeListConverter.hpp +28 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/FloatConverter.cpp +29 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/FloatConverter.hpp +35 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/IColumnConverter.hpp +17 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/IntConverter.cpp +23 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/IntConverter.hpp +41 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/IntervalConverter.cpp +65 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/IntervalConverter.hpp +54 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/LICENSE.txt +209 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/MapConverter.cpp +79 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/MapConverter.hpp +30 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/ObjectConverter.cpp +52 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/ObjectConverter.hpp +29 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/Python/Common.cpp +8 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/Python/Common.hpp +117 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/Python/Helpers.cpp +54 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/Python/Helpers.hpp +34 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/SnowflakeType.cpp +33 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/SnowflakeType.hpp +48 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/StringConverter.cpp +18 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/StringConverter.hpp +26 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/TimeConverter.cpp +39 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/TimeConverter.hpp +31 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/TimeStampConverter.cpp +326 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/TimeStampConverter.hpp +138 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/Util/macros.hpp +14 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/Util/time.cpp +65 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/Util/time.hpp +68 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/arrow_stream_iterator.cpp +13278 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/arrow_stream_iterator.pyx +204 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/flatcc_accessors.h +109 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/flatcc_alloc.h +125 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/flatcc_assert.h +45 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/flatcc_builder.h +1914 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/flatcc_emitter.h +208 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/flatcc_endian.h +128 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/flatcc_epilogue.h +7 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/flatcc_flatbuffers.h +58 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/flatcc_identifier.h +144 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/flatcc_iov.h +31 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/flatcc_prologue.h +8 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/flatcc_refmap.h +144 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/flatcc_rtconfig.h +160 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/flatcc_types.h +98 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/flatcc_verifier.h +243 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/portable/flatcc_portable.h +14 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/portable/paligned_alloc.h +207 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/portable/pattributes.h +80 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/portable/pdiagnostic.h +83 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/portable/pdiagnostic_pop.h +20 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/portable/pdiagnostic_push.h +51 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/portable/pendian.h +201 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/portable/pendian_detect.h +108 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/portable/pinline.h +19 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/portable/pinttypes.h +52 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/portable/portable.h +2 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/portable/portable_basic.h +25 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/portable/pstatic_assert.h +67 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/portable/pstdalign.h +164 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/portable/pstdint.h +926 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/portable/punaligned.h +182 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/portable/pversion.h +6 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/portable/pwarnings.h +52 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc.c +3052 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/nanoarrow.c +3019 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/nanoarrow.h +3354 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/nanoarrow.hpp +344 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/nanoarrow_ipc.c +29305 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/nanoarrow_ipc.h +381 -0
- snowflake/connector/_internal/nanoarrow_cpp/Logging/logging.cpp +108 -0
- snowflake/connector/_internal/nanoarrow_cpp/Logging/logging.hpp +47 -0
- snowflake/connector/_internal/nanoarrow_cpp/scripts/.clang-format +8 -0
- snowflake/connector/_internal/nanoarrow_cpp/scripts/format.sh +8 -0
- snowflake/connector/_internal/protobuf_gen/__init__.py +0 -0
- snowflake/connector/_internal/protobuf_gen/database_driver_v1_pb2.py +408 -0
- snowflake/connector/_internal/protobuf_gen/database_driver_v1_pb2.pyi +4487 -0
- snowflake/connector/_internal/protobuf_gen/database_driver_v1_services.py +2088 -0
- snowflake/connector/_internal/protobuf_gen/proto_exception.py +17 -0
- snowflake/connector/_internal/result_batch.py +150 -0
- snowflake/connector/_internal/snowflake_restful.py +222 -0
- snowflake/connector/_internal/snowpark_backcompat_helpers.py +31 -0
- snowflake/connector/_internal/sqlstate.py +11 -0
- snowflake/connector/_internal/statement_utils.py +207 -0
- snowflake/connector/_internal/text_utils.py +112 -0
- snowflake/connector/_internal/type_codes.py +139 -0
- snowflake/connector/_internal/utils.py +65 -0
- snowflake/connector/_internal/write_pandas_operation.py +657 -0
- snowflake/connector/aio/README.md +168 -0
- snowflake/connector/aio/__init__.py +37 -0
- snowflake/connector/aio/connection/__init__.py +17 -0
- snowflake/connector/aio/connection/_connection.py +506 -0
- snowflake/connector/aio/cursor/__init__.py +35 -0
- snowflake/connector/aio/cursor/_base.py +1034 -0
- snowflake/connector/aio/cursor/_dict_cursor.py +78 -0
- snowflake/connector/aio/cursor/_result_set_wrapper.py +35 -0
- snowflake/connector/aio/cursor/_snowflake_cursor.py +72 -0
- snowflake/connector/aio/pandas_tools.py +279 -0
- snowflake/connector/aio/result_batch.py +165 -0
- snowflake/connector/auth/__init__.py +0 -0
- snowflake/connector/auth/workload_identity.py +5 -0
- snowflake/connector/compat.py +22 -0
- snowflake/connector/config_manager.py +392 -0
- snowflake/connector/connection/__init__.py +30 -0
- snowflake/connector/connection/_connection.py +641 -0
- snowflake/connector/connection_config.py +517 -0
- snowflake/connector/constants.py +52 -0
- snowflake/connector/cursor/__init__.py +37 -0
- snowflake/connector/cursor/_base.py +1169 -0
- snowflake/connector/cursor/_chunked_download_reader.py +75 -0
- snowflake/connector/cursor/_dict_cursor.py +78 -0
- snowflake/connector/cursor/_result_set_wrapper.py +35 -0
- snowflake/connector/cursor/_snowflake_cursor.py +72 -0
- snowflake/connector/description.py +7 -0
- snowflake/connector/errors.py +492 -0
- snowflake/connector/network.py +71 -0
- snowflake/connector/pandas_tools.py +191 -0
- snowflake/connector/py.typed +0 -0
- snowflake/connector/result_batch.py +216 -0
- snowflake/connector/telemetry.py +40 -0
- snowflake/connector/time_util.py +11 -0
- snowflake/connector/types.py +134 -0
- snowflake/connector/util_text.py +3 -0
- snowflake/connector/version.py +23 -0
- snowflake_connector_python-5.2.0.dist-info/DELVEWHEEL +2 -0
- snowflake_connector_python-5.2.0.dist-info/METADATA +190 -0
- snowflake_connector_python-5.2.0.dist-info/RECORD +204 -0
- snowflake_connector_python-5.2.0.dist-info/WHEEL +4 -0
- snowflake_connector_python.libs/msvcp140-a4c2229bdc2a2a630acdc095b4d86008.dll +0 -0
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"""Concrete DictCursor — returns dict rows."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from typing import cast
|
|
6
|
+
|
|
7
|
+
from ..._internal.cursor import DictRow
|
|
8
|
+
from ..._internal.errorhandler import simplified_error_handling
|
|
9
|
+
from ._base import SnowflakeCursorBase
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class DictCursor(SnowflakeCursorBase):
|
|
13
|
+
"""Cursor returning results as dictionaries with column names as keys.
|
|
14
|
+
|
|
15
|
+
Usage::
|
|
16
|
+
|
|
17
|
+
async with connection.cursor(DictCursor) as cur:
|
|
18
|
+
await cur.execute("SELECT 1 AS id, 'hello' AS name")
|
|
19
|
+
row = await cur.fetchone()
|
|
20
|
+
# row == {"ID": 1, "NAME": "hello"}
|
|
21
|
+
"""
|
|
22
|
+
|
|
23
|
+
@property
|
|
24
|
+
def _use_dict_result(self) -> bool:
|
|
25
|
+
return True
|
|
26
|
+
|
|
27
|
+
@simplified_error_handling
|
|
28
|
+
async def fetchone(self) -> DictRow | None:
|
|
29
|
+
"""
|
|
30
|
+
Fetch the next row of a query result set as a dictionary.
|
|
31
|
+
|
|
32
|
+
Returns:
|
|
33
|
+
dict: Next row as a dictionary with column names as keys,
|
|
34
|
+
or None when no more data is available
|
|
35
|
+
"""
|
|
36
|
+
return cast(DictRow | None, await self._fetchone())
|
|
37
|
+
|
|
38
|
+
@simplified_error_handling
|
|
39
|
+
async def fetchmany(self, size: int | None = None) -> list[DictRow]:
|
|
40
|
+
"""
|
|
41
|
+
Fetch the next set of rows as dictionaries.
|
|
42
|
+
|
|
43
|
+
Args:
|
|
44
|
+
size (int): Number of rows to fetch (defaults to arraysize)
|
|
45
|
+
|
|
46
|
+
Returns:
|
|
47
|
+
list[dict]: List of rows as dictionaries
|
|
48
|
+
"""
|
|
49
|
+
return await super().fetchmany(size)
|
|
50
|
+
|
|
51
|
+
async def fetchall(self) -> list[DictRow]:
|
|
52
|
+
"""
|
|
53
|
+
Fetch all (remaining) rows as dictionaries.
|
|
54
|
+
|
|
55
|
+
Returns:
|
|
56
|
+
list[dict]: List of all remaining rows as dictionaries
|
|
57
|
+
"""
|
|
58
|
+
return await super().fetchall()
|
|
59
|
+
|
|
60
|
+
async def __anext__(self) -> DictRow:
|
|
61
|
+
"""
|
|
62
|
+
Fetch the next row from the currently executed statement as a dictionary.
|
|
63
|
+
|
|
64
|
+
Returns:
|
|
65
|
+
dict: Next row
|
|
66
|
+
|
|
67
|
+
Raises:
|
|
68
|
+
StopAsyncIteration: When no more rows are available
|
|
69
|
+
"""
|
|
70
|
+
return cast(DictRow, await super().__anext__())
|
|
71
|
+
|
|
72
|
+
async def next(self) -> DictRow:
|
|
73
|
+
"""Python 2 compatibility alias for ``__anext__``. Returns a dictionary row.
|
|
74
|
+
|
|
75
|
+
Raises:
|
|
76
|
+
StopAsyncIteration: When no more rows are available
|
|
77
|
+
"""
|
|
78
|
+
return await self.__anext__()
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from ..._internal.api_client.client_api import async_core_driver
|
|
4
|
+
from ..._internal.cursor.result_set_wrapper import ResultSetWrapperBase
|
|
5
|
+
from ..._internal.protobuf_gen.database_driver_v1_pb2 import (
|
|
6
|
+
ResultSetGetChunksResponse,
|
|
7
|
+
)
|
|
8
|
+
from ..._internal.statement_utils import get_stream_ptr
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class _ResultSetWrapper(ResultSetWrapperBase):
|
|
12
|
+
"""Async result-set handle owner."""
|
|
13
|
+
|
|
14
|
+
async def get_arrow_stream_ptr(self) -> int:
|
|
15
|
+
"""Fetch the Arrow stream and return the raw C pointer.
|
|
16
|
+
|
|
17
|
+
Each call builds a fresh stream from the stored result set data.
|
|
18
|
+
|
|
19
|
+
Raises:
|
|
20
|
+
ProgrammingError: If no handle is held.
|
|
21
|
+
"""
|
|
22
|
+
handle = self._require_handle()
|
|
23
|
+
response = await async_core_driver.result_set_get_stream(result_set_handle=handle)
|
|
24
|
+
return get_stream_ptr(response)
|
|
25
|
+
|
|
26
|
+
async def get_chunks(self) -> ResultSetGetChunksResponse | None:
|
|
27
|
+
"""Call ``result_set_get_chunks`` on the held handle, or return ``None``.
|
|
28
|
+
|
|
29
|
+
Safe to call multiple times and independently of :meth:`get_arrow_stream_ptr` —
|
|
30
|
+
the core layer re-fetches chunk metadata from Snowflake if the cached copy
|
|
31
|
+
was already consumed.
|
|
32
|
+
"""
|
|
33
|
+
if self._handle is None:
|
|
34
|
+
return None
|
|
35
|
+
return await async_core_driver.result_set_get_chunks(result_set_handle=self._handle)
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"""Concrete SnowflakeCursor — returns tuple rows."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from typing import cast
|
|
6
|
+
|
|
7
|
+
from ..._internal.cursor import Row
|
|
8
|
+
from ..._internal.errorhandler import simplified_error_handling
|
|
9
|
+
from ._base import SnowflakeCursorBase
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class SnowflakeCursor(SnowflakeCursorBase):
|
|
13
|
+
"""Cursor returning results as tuples (default).
|
|
14
|
+
|
|
15
|
+
This is the standard cursor returned by ``connection.cursor()``.
|
|
16
|
+
"""
|
|
17
|
+
|
|
18
|
+
@property
|
|
19
|
+
def _use_dict_result(self) -> bool:
|
|
20
|
+
return False
|
|
21
|
+
|
|
22
|
+
@simplified_error_handling
|
|
23
|
+
async def fetchone(self) -> Row | None:
|
|
24
|
+
"""
|
|
25
|
+
Fetch the next row of a query result set.
|
|
26
|
+
|
|
27
|
+
Returns:
|
|
28
|
+
tuple: Next row, or None when no more data is available
|
|
29
|
+
"""
|
|
30
|
+
return cast(Row | None, await self._fetchone())
|
|
31
|
+
|
|
32
|
+
@simplified_error_handling
|
|
33
|
+
async def fetchmany(self, size: int | None = None) -> list[Row]:
|
|
34
|
+
"""
|
|
35
|
+
Fetch the next set of rows of a query result.
|
|
36
|
+
|
|
37
|
+
Args:
|
|
38
|
+
size (int): Number of rows to fetch (defaults to arraysize)
|
|
39
|
+
|
|
40
|
+
Returns:
|
|
41
|
+
list[tuple]: List of rows as tuples
|
|
42
|
+
"""
|
|
43
|
+
return await super().fetchmany(size)
|
|
44
|
+
|
|
45
|
+
async def fetchall(self) -> list[Row]:
|
|
46
|
+
"""
|
|
47
|
+
Fetch all (remaining) rows of a query result.
|
|
48
|
+
|
|
49
|
+
Returns:
|
|
50
|
+
list[tuple]: List of all remaining rows as tuples
|
|
51
|
+
"""
|
|
52
|
+
return await super().fetchall()
|
|
53
|
+
|
|
54
|
+
async def __anext__(self) -> Row:
|
|
55
|
+
"""
|
|
56
|
+
Fetch the next row from the currently executed statement.
|
|
57
|
+
|
|
58
|
+
Returns:
|
|
59
|
+
tuple: Next row
|
|
60
|
+
|
|
61
|
+
Raises:
|
|
62
|
+
StopAsyncIteration: When no more rows are available
|
|
63
|
+
"""
|
|
64
|
+
return cast(Row, await super().__anext__())
|
|
65
|
+
|
|
66
|
+
async def next(self) -> Row:
|
|
67
|
+
"""Python 2 compatibility alias for ``__anext__``. Returns a tuple row.
|
|
68
|
+
|
|
69
|
+
Raises:
|
|
70
|
+
StopAsyncIteration: When no more rows are available
|
|
71
|
+
"""
|
|
72
|
+
return await self.__anext__()
|
|
@@ -0,0 +1,279 @@
|
|
|
1
|
+
"""Async write_pandas for snowflake.connector.aio.
|
|
2
|
+
|
|
3
|
+
The sync write_pandas in snowflake.connector.pandas_tools is unchanged.
|
|
4
|
+
This module adds an aio-native write_pandas that runs the full
|
|
5
|
+
DDL → PUT → INFER_SCHEMA → COPY INTO pipeline on AsyncConnection /
|
|
6
|
+
AsyncSnowflakeCursor.
|
|
7
|
+
"""
|
|
8
|
+
|
|
9
|
+
from __future__ import annotations
|
|
10
|
+
|
|
11
|
+
from collections.abc import Callable
|
|
12
|
+
from pathlib import Path
|
|
13
|
+
from tempfile import TemporaryDirectory
|
|
14
|
+
from typing import TYPE_CHECKING, Any, Literal, cast
|
|
15
|
+
|
|
16
|
+
from .._common.extras import pandas, requires_dependency
|
|
17
|
+
from .._internal.decorators import api_telemetry
|
|
18
|
+
from .._internal.errorhandler import route_exception
|
|
19
|
+
from .._internal.logging import get_logger
|
|
20
|
+
from .._internal.write_pandas_operation import (
|
|
21
|
+
WritePandasConfig,
|
|
22
|
+
WritePandasMixin,
|
|
23
|
+
WritePandasResult,
|
|
24
|
+
generate_temp_name,
|
|
25
|
+
)
|
|
26
|
+
from ..errors import Error, ProgrammingError
|
|
27
|
+
from .cursor import SnowflakeCursor as AsyncSnowflakeCursor
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
if TYPE_CHECKING:
|
|
31
|
+
from pandas import DataFrame
|
|
32
|
+
|
|
33
|
+
from .connection import Connection
|
|
34
|
+
|
|
35
|
+
logger = get_logger(__name__)
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
# ---------------------------------------------------------------------------
|
|
39
|
+
# _AsyncWritePandasOperation
|
|
40
|
+
# ---------------------------------------------------------------------------
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
class _AsyncWritePandasOperation(WritePandasMixin):
|
|
44
|
+
"""Async-native write_pandas pipeline from a validated WritePandasConfig.
|
|
45
|
+
|
|
46
|
+
execute() runs the full pipeline without mutating self — all intermediate
|
|
47
|
+
state is threaded through local variables and return values.
|
|
48
|
+
"""
|
|
49
|
+
|
|
50
|
+
def __init__(self, cfg: WritePandasConfig) -> None:
|
|
51
|
+
self._cfg = cfg
|
|
52
|
+
|
|
53
|
+
# -- Object lifetime -----------------------------------------------------
|
|
54
|
+
|
|
55
|
+
async def _drop_object(self, cur: AsyncSnowflakeCursor, name: str, object_type: str) -> None:
|
|
56
|
+
await cur.execute(**self._build_drop_object_sql(name, object_type))
|
|
57
|
+
|
|
58
|
+
async def _create_temp_object(
|
|
59
|
+
self,
|
|
60
|
+
cur: AsyncSnowflakeCursor,
|
|
61
|
+
sql_builder: Callable[[str], dict[str, Any]],
|
|
62
|
+
qualified_name: str,
|
|
63
|
+
bare_name: str,
|
|
64
|
+
) -> str:
|
|
65
|
+
"""Try creating in target schema; fall back to current schema on privilege error."""
|
|
66
|
+
try:
|
|
67
|
+
await cur.execute(**sql_builder(qualified_name))
|
|
68
|
+
return qualified_name
|
|
69
|
+
except ProgrammingError:
|
|
70
|
+
await cur.execute(**sql_builder(bare_name))
|
|
71
|
+
return bare_name
|
|
72
|
+
|
|
73
|
+
# -- Main pipeline -------------------------------------------------------
|
|
74
|
+
|
|
75
|
+
async def execute(self) -> WritePandasResult:
|
|
76
|
+
cfg = self._cfg
|
|
77
|
+
cfg.emit_warnings()
|
|
78
|
+
|
|
79
|
+
# This pipeline runs on the async connection. ``cfg.conn`` also allows the sync one.
|
|
80
|
+
cur = cast("Connection", cfg.conn).cursor(AsyncSnowflakeCursor)
|
|
81
|
+
target_location: str | None = None
|
|
82
|
+
try:
|
|
83
|
+
stage_location = await self._create_stage(cur)
|
|
84
|
+
nchunks, nrows = await self._upload_to_stage(cur, stage_location)
|
|
85
|
+
|
|
86
|
+
column_type_map: dict[str, str] | None = None
|
|
87
|
+
if cfg.needs_inference:
|
|
88
|
+
file_format_location = await self._create_file_format(cur)
|
|
89
|
+
column_type_map = await self._infer_column_types(cur, stage_location, file_format_location)
|
|
90
|
+
|
|
91
|
+
target_location = self._resolve_target_table()
|
|
92
|
+
|
|
93
|
+
if cfg.needs_table_creation:
|
|
94
|
+
await self._create_table(cur, target_location, column_type_map)
|
|
95
|
+
|
|
96
|
+
if cfg.needs_truncate:
|
|
97
|
+
await self._truncate_table(cur, target_location)
|
|
98
|
+
|
|
99
|
+
copy_results = await self._copy_into(cur, stage_location, target_location, column_type_map)
|
|
100
|
+
|
|
101
|
+
if cfg.needs_swap:
|
|
102
|
+
await self._swap_tables(cur, target_location)
|
|
103
|
+
|
|
104
|
+
except Exception:
|
|
105
|
+
if cfg.needs_swap and target_location:
|
|
106
|
+
try:
|
|
107
|
+
await self._drop_object(cur, target_location, "TABLE")
|
|
108
|
+
except Exception:
|
|
109
|
+
logger.warning(
|
|
110
|
+
"aio.write_pandas failed and could not drop temporary "
|
|
111
|
+
"staging table %s created for overwrite swap — "
|
|
112
|
+
"it may need to be dropped manually",
|
|
113
|
+
target_location,
|
|
114
|
+
)
|
|
115
|
+
raise
|
|
116
|
+
finally:
|
|
117
|
+
cur.close()
|
|
118
|
+
|
|
119
|
+
success = all(row[1] == "LOADED" for row in copy_results)
|
|
120
|
+
return WritePandasResult(success, nchunks, nrows, copy_results)
|
|
121
|
+
|
|
122
|
+
# -- Stage & upload ------------------------------------------------------
|
|
123
|
+
|
|
124
|
+
async def _create_stage(self, cur: AsyncSnowflakeCursor) -> str:
|
|
125
|
+
cfg = self._cfg
|
|
126
|
+
name = generate_temp_name("STAGE")
|
|
127
|
+
qualified = cfg.qualify(name)
|
|
128
|
+
return await self._create_temp_object(cur, self._build_create_stage_sql, qualified, name)
|
|
129
|
+
|
|
130
|
+
async def _upload_to_stage(self, cur: AsyncSnowflakeCursor, stage_location: str) -> tuple[int, int]:
|
|
131
|
+
cfg = self._cfg
|
|
132
|
+
nchunks = 0
|
|
133
|
+
nrows = 0
|
|
134
|
+
with TemporaryDirectory() as tmp_dir:
|
|
135
|
+
for idx, chunk in self._iter_chunks():
|
|
136
|
+
chunk_path = Path(tmp_dir) / f"file{idx}.txt"
|
|
137
|
+
chunk.to_parquet(path=chunk_path, compression=cfg.compression, **cfg.parquet_kwargs)
|
|
138
|
+
nchunks += 1
|
|
139
|
+
nrows += len(chunk)
|
|
140
|
+
|
|
141
|
+
if not cfg.bulk_upload:
|
|
142
|
+
await self._put_file(cur, stage_location, chunk_path)
|
|
143
|
+
chunk_path.unlink()
|
|
144
|
+
|
|
145
|
+
if cfg.bulk_upload:
|
|
146
|
+
await self._put_directory(cur, stage_location, tmp_dir)
|
|
147
|
+
|
|
148
|
+
return nchunks, nrows
|
|
149
|
+
|
|
150
|
+
async def _put_file(self, cur: AsyncSnowflakeCursor, stage_location: str, path: Path) -> None:
|
|
151
|
+
await cur.execute(**self._build_put_file_sql(stage_location, path))
|
|
152
|
+
|
|
153
|
+
async def _put_directory(self, cur: AsyncSnowflakeCursor, stage_location: str, directory: str) -> None:
|
|
154
|
+
await cur.execute(**self._build_put_directory_sql(stage_location, directory))
|
|
155
|
+
|
|
156
|
+
# -- Schema inference ----------------------------------------------------
|
|
157
|
+
|
|
158
|
+
async def _create_file_format(self, cur: AsyncSnowflakeCursor) -> str:
|
|
159
|
+
cfg = self._cfg
|
|
160
|
+
name = generate_temp_name("FILE_FORMAT")
|
|
161
|
+
qualified = cfg.qualify(name)
|
|
162
|
+
return await self._create_temp_object(cur, self._build_create_file_format_sql, qualified, name)
|
|
163
|
+
|
|
164
|
+
async def _infer_column_types(
|
|
165
|
+
self,
|
|
166
|
+
cur: AsyncSnowflakeCursor,
|
|
167
|
+
stage_location: str,
|
|
168
|
+
file_format_location: str,
|
|
169
|
+
) -> dict[str, str]:
|
|
170
|
+
"""Run INFER_SCHEMA and return {UPPER_COL_NAME: SQL_TYPE} mapping."""
|
|
171
|
+
await cur.execute(**self._build_infer_column_types_sql(stage_location, file_format_location))
|
|
172
|
+
rows = await cur.fetchall()
|
|
173
|
+
return {row[0].upper(): row[1] for row in rows}
|
|
174
|
+
|
|
175
|
+
# -- Table management ----------------------------------------------------
|
|
176
|
+
|
|
177
|
+
async def _create_table(
|
|
178
|
+
self,
|
|
179
|
+
cur: AsyncSnowflakeCursor,
|
|
180
|
+
target_location: str,
|
|
181
|
+
column_type_map: dict[str, str] | None,
|
|
182
|
+
) -> None:
|
|
183
|
+
await cur.execute(**self._build_create_table_sql(target_location, column_type_map))
|
|
184
|
+
|
|
185
|
+
async def _truncate_table(self, cur: AsyncSnowflakeCursor, target_location: str) -> None:
|
|
186
|
+
await cur.execute(**self._build_truncate_table_sql(target_location))
|
|
187
|
+
|
|
188
|
+
async def _swap_tables(self, cur: AsyncSnowflakeCursor, target_location: str) -> None:
|
|
189
|
+
"""Replace original table with temp target via DROP + RENAME.
|
|
190
|
+
|
|
191
|
+
ALTER TABLE SWAP WITH would be atomic but doesn't work when the
|
|
192
|
+
original table doesn't exist yet or tables are different types
|
|
193
|
+
(TEMPORARY vs permanent).
|
|
194
|
+
"""
|
|
195
|
+
original = self._cfg.qualify(self._cfg.table_name)
|
|
196
|
+
await self._drop_object(cur, original, "TABLE")
|
|
197
|
+
await cur.execute(**self._build_rename_table_sql(target_location))
|
|
198
|
+
|
|
199
|
+
# -- COPY INTO -----------------------------------------------------------
|
|
200
|
+
|
|
201
|
+
async def _copy_into(
|
|
202
|
+
self,
|
|
203
|
+
cur: AsyncSnowflakeCursor,
|
|
204
|
+
stage_location: str,
|
|
205
|
+
target_location: str,
|
|
206
|
+
column_type_map: dict[str, str] | None,
|
|
207
|
+
) -> list:
|
|
208
|
+
await cur.execute(**self._build_copy_into_sql(stage_location, target_location, column_type_map))
|
|
209
|
+
return await cur.fetchall()
|
|
210
|
+
|
|
211
|
+
|
|
212
|
+
# ---------------------------------------------------------------------------
|
|
213
|
+
# Public async entry point
|
|
214
|
+
# ---------------------------------------------------------------------------
|
|
215
|
+
|
|
216
|
+
|
|
217
|
+
@requires_dependency(pandas)
|
|
218
|
+
@api_telemetry
|
|
219
|
+
async def write_pandas(
|
|
220
|
+
conn: Connection,
|
|
221
|
+
df: DataFrame,
|
|
222
|
+
table_name: str,
|
|
223
|
+
database: str | None = None,
|
|
224
|
+
schema: str | None = None,
|
|
225
|
+
chunk_size: int | None = None,
|
|
226
|
+
compression: Literal["gzip", "snappy"] = "gzip",
|
|
227
|
+
on_error: str = "abort_statement",
|
|
228
|
+
parallel: int = 4,
|
|
229
|
+
quote_identifiers: bool = True,
|
|
230
|
+
infer_schema: bool = False,
|
|
231
|
+
auto_create_table: bool = False,
|
|
232
|
+
overwrite: bool = False,
|
|
233
|
+
table_type: Literal["", "temp", "temporary", "transient"] = "",
|
|
234
|
+
use_logical_type: bool | None = None,
|
|
235
|
+
iceberg_config: dict[str, str] | None = None,
|
|
236
|
+
bulk_upload_chunks: bool = False,
|
|
237
|
+
use_vectorized_scanner: bool = False,
|
|
238
|
+
**kwargs: Any,
|
|
239
|
+
) -> WritePandasResult:
|
|
240
|
+
"""Write a pandas DataFrame to a Snowflake table via Parquet stage upload (async).
|
|
241
|
+
|
|
242
|
+
Async-native counterpart of :func:`snowflake.connector.pandas_tools.write_pandas`.
|
|
243
|
+
Requires an :class:`~snowflake.connector.aio.Connection`.
|
|
244
|
+
|
|
245
|
+
Returns a WritePandasResult named tuple (success, nchunks, nrows, copy_results).
|
|
246
|
+
Backward-compatible with plain tuple unpacking and indexing.
|
|
247
|
+
|
|
248
|
+
Note:
|
|
249
|
+
Unlike the sync module, this module does not expose ``pd_writer`` or
|
|
250
|
+
``make_pd_writer``. ``DataFrame.to_sql(method=...)`` invokes the method
|
|
251
|
+
callback synchronously and cannot await a coroutine, so an async adapter
|
|
252
|
+
for ``to_sql`` is not possible. Use ``pd_writer`` from
|
|
253
|
+
:mod:`snowflake.connector.pandas_tools` if you need ``to_sql`` integration.
|
|
254
|
+
"""
|
|
255
|
+
try:
|
|
256
|
+
cfg = WritePandasConfig(
|
|
257
|
+
conn,
|
|
258
|
+
df,
|
|
259
|
+
table_name,
|
|
260
|
+
database=database,
|
|
261
|
+
schema=schema,
|
|
262
|
+
chunk_size=chunk_size,
|
|
263
|
+
compression=compression,
|
|
264
|
+
on_error=on_error,
|
|
265
|
+
parallel=parallel,
|
|
266
|
+
quote_identifiers=quote_identifiers,
|
|
267
|
+
infer_schema=infer_schema,
|
|
268
|
+
auto_create_table=auto_create_table,
|
|
269
|
+
overwrite=overwrite,
|
|
270
|
+
table_type=table_type,
|
|
271
|
+
use_logical_type=use_logical_type,
|
|
272
|
+
iceberg_config=iceberg_config,
|
|
273
|
+
bulk_upload_chunks=bulk_upload_chunks,
|
|
274
|
+
use_vectorized_scanner=use_vectorized_scanner,
|
|
275
|
+
**kwargs,
|
|
276
|
+
)
|
|
277
|
+
return await _AsyncWritePandasOperation(cfg).execute()
|
|
278
|
+
except Error as exc:
|
|
279
|
+
route_exception(conn, None, exc)
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
"""Async result batch classes for distributed fetch."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from collections.abc import AsyncIterator
|
|
6
|
+
from typing import TYPE_CHECKING, Any, cast
|
|
7
|
+
|
|
8
|
+
from .._common.extras import pandas, pyarrow, requires_dependency
|
|
9
|
+
from .._internal.api_client.client_api import async_core_driver
|
|
10
|
+
from .._internal.arrow_stream_async import (
|
|
11
|
+
collect_arrow_table_async,
|
|
12
|
+
create_async_row_iterator_from_stream_ptr,
|
|
13
|
+
to_pandas_async,
|
|
14
|
+
)
|
|
15
|
+
from .._internal.arrow_stream_utils import (
|
|
16
|
+
create_table_iterator,
|
|
17
|
+
)
|
|
18
|
+
from .._internal.protobuf_gen.database_driver_v1_pb2 import ColumnMetadata, ResultChunk
|
|
19
|
+
from .._internal.result_batch import IterTableStructure, IterUnit, ResultBatchMixin
|
|
20
|
+
from .._internal.statement_utils import get_stream_ptr
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
if TYPE_CHECKING:
|
|
24
|
+
from pandas import DataFrame
|
|
25
|
+
from pyarrow import Table
|
|
26
|
+
|
|
27
|
+
from ..cursor import ResultMetadata
|
|
28
|
+
from .connection import Connection
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
class ResultBatch(ResultBatchMixin):
|
|
32
|
+
"""Async counterpart of :class:`~snowflake.connector.result_batch.ResultBatch`."""
|
|
33
|
+
|
|
34
|
+
_connection: Connection | None
|
|
35
|
+
|
|
36
|
+
def __init__(
|
|
37
|
+
self,
|
|
38
|
+
chunk: ResultChunk,
|
|
39
|
+
description: list[ResultMetadata],
|
|
40
|
+
connection: Connection | None,
|
|
41
|
+
columns: list[ColumnMetadata] | None = None,
|
|
42
|
+
) -> None:
|
|
43
|
+
super().__init__(chunk, description, connection, columns)
|
|
44
|
+
|
|
45
|
+
# ------------------------------------------------------------------
|
|
46
|
+
# Properties
|
|
47
|
+
# ------------------------------------------------------------------
|
|
48
|
+
|
|
49
|
+
@property
|
|
50
|
+
def connection(self) -> Connection | None:
|
|
51
|
+
return self._connection
|
|
52
|
+
|
|
53
|
+
@connection.setter
|
|
54
|
+
def connection(self, value: Connection | None) -> None:
|
|
55
|
+
self._connection = value
|
|
56
|
+
|
|
57
|
+
# ------------------------------------------------------------------
|
|
58
|
+
# Connection resolution
|
|
59
|
+
# ------------------------------------------------------------------
|
|
60
|
+
|
|
61
|
+
def _resolve_connection(self, connection: Connection | None = None) -> Connection | None:
|
|
62
|
+
return connection or self._connection
|
|
63
|
+
|
|
64
|
+
# ------------------------------------------------------------------
|
|
65
|
+
# Data fetching
|
|
66
|
+
# ------------------------------------------------------------------
|
|
67
|
+
|
|
68
|
+
async def _fetch_arrow_stream_ptr(self, connection: Connection | None = None) -> int:
|
|
69
|
+
conn_handle = connection.conn_handle if connection is not None else None
|
|
70
|
+
response = await async_core_driver.database_fetch_chunk(
|
|
71
|
+
conn_handle=conn_handle,
|
|
72
|
+
chunk=self._chunk,
|
|
73
|
+
columns=self._columns,
|
|
74
|
+
)
|
|
75
|
+
return get_stream_ptr(response)
|
|
76
|
+
|
|
77
|
+
async def _take_arrow_stream_ptr(self, connection: Connection | None = None) -> int:
|
|
78
|
+
if self._arrow_stream_ptr is None:
|
|
79
|
+
await self.populate_data(connection=connection)
|
|
80
|
+
stream_ptr = cast(int, self._arrow_stream_ptr)
|
|
81
|
+
self._arrow_stream_ptr = None
|
|
82
|
+
return stream_ptr
|
|
83
|
+
|
|
84
|
+
async def populate_data(self, connection: Connection | None = None, **kwargs: Any) -> ResultBatch:
|
|
85
|
+
conn = self._resolve_connection(connection)
|
|
86
|
+
self._arrow_stream_ptr = await self._fetch_arrow_stream_ptr(conn)
|
|
87
|
+
return self
|
|
88
|
+
|
|
89
|
+
def __aiter__(self) -> AsyncIterator[tuple | dict | Exception]:
|
|
90
|
+
return self.create_iter()
|
|
91
|
+
|
|
92
|
+
async def create_iter(
|
|
93
|
+
self,
|
|
94
|
+
connection: Connection | None = None,
|
|
95
|
+
iter_unit: IterUnit | str = IterUnit.ROW_UNIT,
|
|
96
|
+
structure: IterTableStructure | str = IterTableStructure.PANDAS,
|
|
97
|
+
use_dict_result: bool = False,
|
|
98
|
+
number_to_decimal: bool = False,
|
|
99
|
+
force_microsecond_precision: bool = False,
|
|
100
|
+
) -> AsyncIterator[tuple | dict | Exception] | AsyncIterator[Table] | AsyncIterator[DataFrame]:
|
|
101
|
+
iter_unit = IterUnit.of(iter_unit)
|
|
102
|
+
structure = IterTableStructure.of(structure)
|
|
103
|
+
|
|
104
|
+
conn = self._resolve_connection(connection)
|
|
105
|
+
if iter_unit == IterUnit.TABLE_UNIT:
|
|
106
|
+
if structure == IterTableStructure.PANDAS:
|
|
107
|
+
yield await self.to_pandas(
|
|
108
|
+
connection=conn,
|
|
109
|
+
number_to_decimal=number_to_decimal,
|
|
110
|
+
force_microsecond_precision=force_microsecond_precision,
|
|
111
|
+
)
|
|
112
|
+
return
|
|
113
|
+
yield await self.to_arrow(
|
|
114
|
+
connection=conn,
|
|
115
|
+
number_to_decimal=number_to_decimal,
|
|
116
|
+
force_microsecond_precision=force_microsecond_precision,
|
|
117
|
+
)
|
|
118
|
+
return
|
|
119
|
+
|
|
120
|
+
iterator = create_async_row_iterator_from_stream_ptr(
|
|
121
|
+
await self._take_arrow_stream_ptr(conn),
|
|
122
|
+
context=self._arrow_context,
|
|
123
|
+
use_dict_result=use_dict_result,
|
|
124
|
+
use_numpy=self._numpy,
|
|
125
|
+
use_core_arrow=self._use_core_arrow,
|
|
126
|
+
)
|
|
127
|
+
async for row in iterator:
|
|
128
|
+
yield row
|
|
129
|
+
|
|
130
|
+
@requires_dependency(pyarrow)
|
|
131
|
+
async def to_arrow(
|
|
132
|
+
self,
|
|
133
|
+
connection: Connection | None = None,
|
|
134
|
+
number_to_decimal: bool = False,
|
|
135
|
+
force_microsecond_precision: bool = False,
|
|
136
|
+
) -> Table:
|
|
137
|
+
conn = self._resolve_connection(connection)
|
|
138
|
+
stream_ptr = await self._take_arrow_stream_ptr(conn)
|
|
139
|
+
return await collect_arrow_table_async(
|
|
140
|
+
create_table_iterator(
|
|
141
|
+
stream_ptr,
|
|
142
|
+
context=self._arrow_context,
|
|
143
|
+
number_to_decimal=number_to_decimal,
|
|
144
|
+
force_microsecond_precision=force_microsecond_precision,
|
|
145
|
+
use_core_arrow=self._use_core_arrow,
|
|
146
|
+
),
|
|
147
|
+
self._description,
|
|
148
|
+
)
|
|
149
|
+
|
|
150
|
+
@requires_dependency(pandas)
|
|
151
|
+
async def to_pandas(
|
|
152
|
+
self,
|
|
153
|
+
connection: Connection | None = None,
|
|
154
|
+
number_to_decimal: bool = False,
|
|
155
|
+
force_microsecond_precision: bool = False,
|
|
156
|
+
) -> DataFrame:
|
|
157
|
+
table = await self.to_arrow(
|
|
158
|
+
connection=connection,
|
|
159
|
+
number_to_decimal=number_to_decimal,
|
|
160
|
+
force_microsecond_precision=force_microsecond_precision,
|
|
161
|
+
)
|
|
162
|
+
return await to_pandas_async(table)
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
__all__ = ["IterUnit", "IterTableStructure", "ResultBatch"]
|
|
File without changes
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"""BACKWARD COMPATIBILITY MODULE ONLY"""
|
|
2
|
+
|
|
3
|
+
import platform
|
|
4
|
+
|
|
5
|
+
from typing import Any
|
|
6
|
+
|
|
7
|
+
from ._internal.decorators import backward_compatibility
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
IS_LINUX = platform.system() == "Linux"
|
|
11
|
+
IS_WINDOWS = platform.system() == "Windows"
|
|
12
|
+
IS_MACOS = platform.system() == "Darwin"
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
@backward_compatibility
|
|
16
|
+
def IS_UNICODE(v: Any) -> bool:
|
|
17
|
+
"""To check whether v is a Unicode string."""
|
|
18
|
+
return isinstance(v, str)
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
# backward compatibility
|
|
22
|
+
IS_STR = IS_UNICODE
|