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.
Files changed (204) hide show
  1. snowflake/connector/__init__.py +148 -0
  2. snowflake/connector/_common/__init__.py +0 -0
  3. snowflake/connector/_common/extras.py +134 -0
  4. snowflake/connector/_common/telemetry.py +221 -0
  5. snowflake/connector/_common/wif_util.py +92 -0
  6. snowflake/connector/_core/sf_core_python.cp315-win_amd64.pyd +0 -0
  7. snowflake/connector/_core/sf_core_python.pyi +79 -0
  8. snowflake/connector/_internal/__init__.py +6 -0
  9. snowflake/connector/_internal/_private_key_helper.py +31 -0
  10. snowflake/connector/_internal/api_client/__init__.py +93 -0
  11. snowflake/connector/_internal/api_client/bridge.py +41 -0
  12. snowflake/connector/_internal/api_client/client_api.py +976 -0
  13. snowflake/connector/_internal/arrow.py +47 -0
  14. snowflake/connector/_internal/arrow_context.py +240 -0
  15. snowflake/connector/_internal/arrow_stream_async.py +266 -0
  16. snowflake/connector/_internal/arrow_stream_iterator.cp311-win_amd64.pyd +0 -0
  17. snowflake/connector/_internal/arrow_stream_iterator.cp312-win_amd64.pyd +0 -0
  18. snowflake/connector/_internal/arrow_stream_iterator.cp313-win_amd64.pyd +0 -0
  19. snowflake/connector/_internal/arrow_stream_iterator.cp314-win_amd64.pyd +0 -0
  20. snowflake/connector/_internal/arrow_stream_iterator.cp314t-win_amd64.pyd +0 -0
  21. snowflake/connector/_internal/arrow_stream_iterator.cp315-win_amd64.pyd +0 -0
  22. snowflake/connector/_internal/arrow_stream_iterator.pyi +42 -0
  23. snowflake/connector/_internal/arrow_stream_utils.py +171 -0
  24. snowflake/connector/_internal/authenticator_type.py +53 -0
  25. snowflake/connector/_internal/backward_compatibility.py +245 -0
  26. snowflake/connector/_internal/binding_converters.py +741 -0
  27. snowflake/connector/_internal/config_utils.py +71 -0
  28. snowflake/connector/_internal/connection/__init__.py +39 -0
  29. snowflake/connector/_internal/connection/connection.py +616 -0
  30. snowflake/connector/_internal/connection/connection_types.py +13 -0
  31. snowflake/connector/_internal/connection/constants.py +25 -0
  32. snowflake/connector/_internal/connection/decorators.py +31 -0
  33. snowflake/connector/_internal/connection/freezable_proxy.py +104 -0
  34. snowflake/connector/_internal/connection/queries.py +10 -0
  35. snowflake/connector/_internal/connection_config_mixin.py +755 -0
  36. snowflake/connector/_internal/cursor/__init__.py +25 -0
  37. snowflake/connector/_internal/cursor/base.py +732 -0
  38. snowflake/connector/_internal/cursor/cursor_types.py +13 -0
  39. snowflake/connector/_internal/cursor/decorators.py +56 -0
  40. snowflake/connector/_internal/cursor/query_result.py +202 -0
  41. snowflake/connector/_internal/cursor/query_result_waiter.py +98 -0
  42. snowflake/connector/_internal/cursor/result_metadata.py +255 -0
  43. snowflake/connector/_internal/cursor/result_set_wrapper.py +66 -0
  44. snowflake/connector/_internal/decorators.py +539 -0
  45. snowflake/connector/_internal/error_kinds.py +111 -0
  46. snowflake/connector/_internal/errorcode.py +35 -0
  47. snowflake/connector/_internal/errorhandler.py +278 -0
  48. snowflake/connector/_internal/fips.py +28 -0
  49. snowflake/connector/_internal/logging/__init__.py +52 -0
  50. snowflake/connector/_internal/logging/config.py +134 -0
  51. snowflake/connector/_internal/logging/core_logger.py +218 -0
  52. snowflake/connector/_internal/logging/native_extension_logger.py +144 -0
  53. snowflake/connector/_internal/logout_config_mapping.py +187 -0
  54. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/ArrayConverter.cpp +57 -0
  55. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/ArrayConverter.hpp +29 -0
  56. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/ArrowTableConverter.cpp +943 -0
  57. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/ArrowTableConverter.hpp +63 -0
  58. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/BinaryConverter.cpp +18 -0
  59. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/BinaryConverter.hpp +26 -0
  60. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/BooleanConverter.cpp +21 -0
  61. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/BooleanConverter.hpp +23 -0
  62. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/CArrowIterator.cpp +118 -0
  63. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/CArrowIterator.hpp +116 -0
  64. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/CArrowStreamIterator.cpp +323 -0
  65. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/CArrowStreamIterator.hpp +133 -0
  66. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/CArrowStreamTableIterator.cpp +275 -0
  67. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/CArrowStreamTableIterator.hpp +168 -0
  68. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/ConverterUtil.cpp +439 -0
  69. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/ConverterUtil.hpp +30 -0
  70. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/DateConverter.cpp +48 -0
  71. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/DateConverter.hpp +46 -0
  72. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/DecFloatConverter.cpp +76 -0
  73. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/DecFloatConverter.hpp +35 -0
  74. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/DecimalConverter.cpp +90 -0
  75. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/DecimalConverter.hpp +63 -0
  76. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/FixedSizeListConverter.cpp +62 -0
  77. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/FixedSizeListConverter.hpp +28 -0
  78. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/FloatConverter.cpp +29 -0
  79. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/FloatConverter.hpp +35 -0
  80. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/IColumnConverter.hpp +17 -0
  81. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/IntConverter.cpp +23 -0
  82. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/IntConverter.hpp +41 -0
  83. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/IntervalConverter.cpp +65 -0
  84. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/IntervalConverter.hpp +54 -0
  85. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/LICENSE.txt +209 -0
  86. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/MapConverter.cpp +79 -0
  87. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/MapConverter.hpp +30 -0
  88. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/ObjectConverter.cpp +52 -0
  89. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/ObjectConverter.hpp +29 -0
  90. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/Python/Common.cpp +8 -0
  91. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/Python/Common.hpp +117 -0
  92. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/Python/Helpers.cpp +54 -0
  93. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/Python/Helpers.hpp +34 -0
  94. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/SnowflakeType.cpp +33 -0
  95. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/SnowflakeType.hpp +48 -0
  96. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/StringConverter.cpp +18 -0
  97. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/StringConverter.hpp +26 -0
  98. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/TimeConverter.cpp +39 -0
  99. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/TimeConverter.hpp +31 -0
  100. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/TimeStampConverter.cpp +326 -0
  101. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/TimeStampConverter.hpp +138 -0
  102. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/Util/macros.hpp +14 -0
  103. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/Util/time.cpp +65 -0
  104. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/Util/time.hpp +68 -0
  105. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/arrow_stream_iterator.cpp +13278 -0
  106. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/arrow_stream_iterator.pyx +204 -0
  107. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/flatcc_accessors.h +109 -0
  108. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/flatcc_alloc.h +125 -0
  109. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/flatcc_assert.h +45 -0
  110. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/flatcc_builder.h +1914 -0
  111. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/flatcc_emitter.h +208 -0
  112. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/flatcc_endian.h +128 -0
  113. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/flatcc_epilogue.h +7 -0
  114. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/flatcc_flatbuffers.h +58 -0
  115. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/flatcc_identifier.h +144 -0
  116. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/flatcc_iov.h +31 -0
  117. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/flatcc_prologue.h +8 -0
  118. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/flatcc_refmap.h +144 -0
  119. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/flatcc_rtconfig.h +160 -0
  120. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/flatcc_types.h +98 -0
  121. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/flatcc_verifier.h +243 -0
  122. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/portable/flatcc_portable.h +14 -0
  123. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/portable/paligned_alloc.h +207 -0
  124. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/portable/pattributes.h +80 -0
  125. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/portable/pdiagnostic.h +83 -0
  126. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/portable/pdiagnostic_pop.h +20 -0
  127. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/portable/pdiagnostic_push.h +51 -0
  128. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/portable/pendian.h +201 -0
  129. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/portable/pendian_detect.h +108 -0
  130. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/portable/pinline.h +19 -0
  131. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/portable/pinttypes.h +52 -0
  132. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/portable/portable.h +2 -0
  133. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/portable/portable_basic.h +25 -0
  134. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/portable/pstatic_assert.h +67 -0
  135. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/portable/pstdalign.h +164 -0
  136. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/portable/pstdint.h +926 -0
  137. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/portable/punaligned.h +182 -0
  138. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/portable/pversion.h +6 -0
  139. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/portable/pwarnings.h +52 -0
  140. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc.c +3052 -0
  141. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/nanoarrow.c +3019 -0
  142. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/nanoarrow.h +3354 -0
  143. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/nanoarrow.hpp +344 -0
  144. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/nanoarrow_ipc.c +29305 -0
  145. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/nanoarrow_ipc.h +381 -0
  146. snowflake/connector/_internal/nanoarrow_cpp/Logging/logging.cpp +108 -0
  147. snowflake/connector/_internal/nanoarrow_cpp/Logging/logging.hpp +47 -0
  148. snowflake/connector/_internal/nanoarrow_cpp/scripts/.clang-format +8 -0
  149. snowflake/connector/_internal/nanoarrow_cpp/scripts/format.sh +8 -0
  150. snowflake/connector/_internal/protobuf_gen/__init__.py +0 -0
  151. snowflake/connector/_internal/protobuf_gen/database_driver_v1_pb2.py +408 -0
  152. snowflake/connector/_internal/protobuf_gen/database_driver_v1_pb2.pyi +4487 -0
  153. snowflake/connector/_internal/protobuf_gen/database_driver_v1_services.py +2088 -0
  154. snowflake/connector/_internal/protobuf_gen/proto_exception.py +17 -0
  155. snowflake/connector/_internal/result_batch.py +150 -0
  156. snowflake/connector/_internal/snowflake_restful.py +222 -0
  157. snowflake/connector/_internal/snowpark_backcompat_helpers.py +31 -0
  158. snowflake/connector/_internal/sqlstate.py +11 -0
  159. snowflake/connector/_internal/statement_utils.py +207 -0
  160. snowflake/connector/_internal/text_utils.py +112 -0
  161. snowflake/connector/_internal/type_codes.py +139 -0
  162. snowflake/connector/_internal/utils.py +65 -0
  163. snowflake/connector/_internal/write_pandas_operation.py +657 -0
  164. snowflake/connector/aio/README.md +168 -0
  165. snowflake/connector/aio/__init__.py +37 -0
  166. snowflake/connector/aio/connection/__init__.py +17 -0
  167. snowflake/connector/aio/connection/_connection.py +506 -0
  168. snowflake/connector/aio/cursor/__init__.py +35 -0
  169. snowflake/connector/aio/cursor/_base.py +1034 -0
  170. snowflake/connector/aio/cursor/_dict_cursor.py +78 -0
  171. snowflake/connector/aio/cursor/_result_set_wrapper.py +35 -0
  172. snowflake/connector/aio/cursor/_snowflake_cursor.py +72 -0
  173. snowflake/connector/aio/pandas_tools.py +279 -0
  174. snowflake/connector/aio/result_batch.py +165 -0
  175. snowflake/connector/auth/__init__.py +0 -0
  176. snowflake/connector/auth/workload_identity.py +5 -0
  177. snowflake/connector/compat.py +22 -0
  178. snowflake/connector/config_manager.py +392 -0
  179. snowflake/connector/connection/__init__.py +30 -0
  180. snowflake/connector/connection/_connection.py +641 -0
  181. snowflake/connector/connection_config.py +517 -0
  182. snowflake/connector/constants.py +52 -0
  183. snowflake/connector/cursor/__init__.py +37 -0
  184. snowflake/connector/cursor/_base.py +1169 -0
  185. snowflake/connector/cursor/_chunked_download_reader.py +75 -0
  186. snowflake/connector/cursor/_dict_cursor.py +78 -0
  187. snowflake/connector/cursor/_result_set_wrapper.py +35 -0
  188. snowflake/connector/cursor/_snowflake_cursor.py +72 -0
  189. snowflake/connector/description.py +7 -0
  190. snowflake/connector/errors.py +492 -0
  191. snowflake/connector/network.py +71 -0
  192. snowflake/connector/pandas_tools.py +191 -0
  193. snowflake/connector/py.typed +0 -0
  194. snowflake/connector/result_batch.py +216 -0
  195. snowflake/connector/telemetry.py +40 -0
  196. snowflake/connector/time_util.py +11 -0
  197. snowflake/connector/types.py +134 -0
  198. snowflake/connector/util_text.py +3 -0
  199. snowflake/connector/version.py +23 -0
  200. snowflake_connector_python-5.2.0.dist-info/DELVEWHEEL +2 -0
  201. snowflake_connector_python-5.2.0.dist-info/METADATA +190 -0
  202. snowflake_connector_python-5.2.0.dist-info/RECORD +204 -0
  203. snowflake_connector_python-5.2.0.dist-info/WHEEL +4 -0
  204. snowflake_connector_python.libs/msvcp140-a4c2229bdc2a2a630acdc095b4d86008.dll +0 -0
@@ -0,0 +1,191 @@
1
+ """Public API for writing pandas DataFrames to Snowflake tables.
2
+
3
+ Usage:
4
+ from snowflake.connector.pandas_tools import write_pandas
5
+ success, nchunks, nrows, _ = write_pandas(conn, df, 'my_table')
6
+
7
+ Implementation details are in snowflake.connector._internal.write_pandas_operation.
8
+ """
9
+
10
+ from __future__ import annotations
11
+
12
+ from collections.abc import Callable, Iterable
13
+ from functools import partial, wraps
14
+ from typing import TYPE_CHECKING, Any, Literal, TypeVar, cast
15
+
16
+ from ._common.extras import pandas, requires_dependency, sqlalchemy
17
+ from ._internal.decorators import api_telemetry
18
+ from ._internal.errorhandler import route_exception
19
+ from ._internal.write_pandas_operation import (
20
+ WritePandasConfig,
21
+ WritePandasOperation,
22
+ WritePandasResult,
23
+ qualify_name,
24
+ )
25
+ from .errors import Error, ProgrammingError
26
+
27
+
28
+ if TYPE_CHECKING:
29
+ from pandas import DataFrame
30
+ from pandas.io.sql import SQLTable
31
+ from sqlalchemy import engine
32
+
33
+ from .connection import Connection
34
+
35
+ F = TypeVar("F", bound=Callable[..., Any])
36
+
37
+
38
+ def _reject_kwargs(*names: str) -> Callable[[F], F]:
39
+ """Reject the listed *names* if they appear in ``**kwargs``.
40
+
41
+ Both ``pd_writer`` and ``make_pd_writer`` accept open-ended
42
+ ``**kwargs`` that are forwarded to :func:`write_pandas`. Some of
43
+ those keyword names (``table``, ``conn``, ``keys``, ``data_iter``,
44
+ ``df``, ``table_name``, ``schema``) overlap with arguments that
45
+ pandas' ``to_sql`` injects automatically or that ``pd_writer``
46
+ derives from SQLAlchemy objects.
47
+
48
+ If a caller accidentally passes one of them, ``functools.partial``
49
+ (in ``make_pd_writer``) or ``pd_writer`` itself would silently
50
+ pre-bind the value and then collide with the positional argument
51
+ that pandas supplies at call time, producing a confusing
52
+ ``TypeError: got multiple values for argument '...'``.
53
+
54
+ This decorator turns that into an explicit
55
+ :class:`~snowflake.connector.errors.ProgrammingError` with a
56
+ clear message *before* the call is made.
57
+ """
58
+ forbidden = frozenset(names)
59
+
60
+ def decorator(func: F) -> F:
61
+ @wraps(func)
62
+ def wrapper(*args: Any, **kwargs: Any) -> Any:
63
+ found = forbidden & kwargs.keys()
64
+ if found:
65
+ raise ProgrammingError(
66
+ f"{', '.join(sorted(found))} cannot be passed to {func.__name__}; "
67
+ f"{'it is' if len(found) == 1 else 'they are'} derived automatically."
68
+ )
69
+ return func(*args, **kwargs)
70
+
71
+ return cast(F, wrapper)
72
+
73
+ return decorator
74
+
75
+
76
+ @requires_dependency(pandas)
77
+ @api_telemetry
78
+ def write_pandas(
79
+ conn: Connection,
80
+ df: DataFrame,
81
+ table_name: str,
82
+ database: str | None = None,
83
+ schema: str | None = None,
84
+ chunk_size: int | None = None,
85
+ compression: Literal["gzip", "snappy"] = "gzip",
86
+ on_error: str = "abort_statement",
87
+ parallel: int = 4,
88
+ quote_identifiers: bool = True,
89
+ infer_schema: bool = False,
90
+ auto_create_table: bool = False,
91
+ overwrite: bool = False,
92
+ table_type: Literal["", "temp", "temporary", "transient"] = "",
93
+ use_logical_type: bool | None = None,
94
+ iceberg_config: dict[str, str] | None = None,
95
+ bulk_upload_chunks: bool = False,
96
+ use_vectorized_scanner: bool = False,
97
+ **kwargs: Any,
98
+ ) -> WritePandasResult:
99
+ """Write a pandas DataFrame to a Snowflake table via Parquet stage upload.
100
+
101
+ Returns a WritePandasResult named tuple (success, nchunks, nrows, copy_results).
102
+ Backward-compatible with plain tuple unpacking and indexing.
103
+ """
104
+ try:
105
+ cfg = WritePandasConfig(
106
+ conn,
107
+ df,
108
+ table_name,
109
+ database=database,
110
+ schema=schema,
111
+ chunk_size=chunk_size,
112
+ compression=compression,
113
+ on_error=on_error,
114
+ parallel=parallel,
115
+ quote_identifiers=quote_identifiers,
116
+ infer_schema=infer_schema,
117
+ auto_create_table=auto_create_table,
118
+ overwrite=overwrite,
119
+ table_type=table_type,
120
+ use_logical_type=use_logical_type,
121
+ iceberg_config=iceberg_config,
122
+ bulk_upload_chunks=bulk_upload_chunks,
123
+ use_vectorized_scanner=use_vectorized_scanner,
124
+ **kwargs,
125
+ )
126
+ return WritePandasOperation(cfg).execute()
127
+ except Error as exc:
128
+ route_exception(conn, None, exc)
129
+
130
+
131
+ # ------------------------------------------------------------------
132
+ # Snowpark import surface: snowpark's analyzer_utils imports this name
133
+ # directly from snowflake.connector.pandas_tools.
134
+ # ------------------------------------------------------------------
135
+
136
+ # Legacy name for a fully-qualified object name; identical to qualify_name, so
137
+ # alias rather than duplicate the escaping logic.
138
+ build_location_helper = qualify_name
139
+
140
+
141
+ @requires_dependency(pandas, sqlalchemy)
142
+ @_reject_kwargs("table", "conn", "keys", "data_iter")
143
+ def make_pd_writer(
144
+ **kwargs: Any,
145
+ ) -> Callable:
146
+ """Return a ``pd_writer`` with pre-bound keyword arguments.
147
+
148
+ Useful when you need to pass extra options (e.g. ``parallel``,
149
+ ``quote_identifiers``) through ``DataFrame.to_sql(method=...)``.
150
+
151
+ Example::
152
+
153
+ df.to_sql("t", engine, index=False, method=make_pd_writer(parallel=1, quote_identifiers=False))
154
+ """
155
+ return partial(pd_writer, **kwargs)
156
+
157
+
158
+ @requires_dependency(pandas, sqlalchemy)
159
+ @_reject_kwargs("conn", "df", "table_name", "schema")
160
+ def pd_writer(
161
+ table: SQLTable,
162
+ conn: engine.Engine | engine.Connection,
163
+ keys: Iterable,
164
+ data_iter: Iterable,
165
+ **kwargs: Any,
166
+ ) -> None:
167
+ """Adapter for ``DataFrame.to_sql(method=pd_writer)``.
168
+
169
+ Wraps :func:`write_pandas` so it satisfies the pandas ``method`` callable
170
+ protocol. Extra ``**kwargs`` are forwarded to ``write_pandas`` (except
171
+ ``conn``, ``df``, ``table_name``, and ``schema`` which are derived from
172
+ the SQLAlchemy objects).
173
+
174
+ Note:
175
+ Lower-case column names must be quoted in the DataFrame (e.g.
176
+ ``'"my_col"'``) because snowflake-sqlalchemy creates tables
177
+ case-insensitively while ``write_pandas`` quotes columns by default.
178
+
179
+ Example::
180
+
181
+ df.to_sql("driver_versions", engine, index=False, method=pd_writer)
182
+ """
183
+ sf_connection = conn.connection.connection
184
+ df = pandas.DataFrame(data_iter, columns=keys)
185
+ write_pandas(
186
+ conn=sf_connection,
187
+ df=df,
188
+ table_name=table.name.upper(),
189
+ schema=table.schema,
190
+ **kwargs,
191
+ )
File without changes
@@ -0,0 +1,216 @@
1
+ """Result batch classes for distributed fetch.
2
+
3
+ This module provides ``ResultBatch`` objects that represent individual chunks
4
+ of a query result set. Each batch can independently fetch and convert its
5
+ data, making them suitable for distributed processing.
6
+
7
+ These objects are pickleable for easy distribution and replication.
8
+ Note that the URLs stored in remote batches expire; the lifetime is
9
+ dictated by the Snowflake back-end (typically 6 hours).
10
+ """
11
+
12
+ from __future__ import annotations
13
+
14
+ from collections.abc import Iterator
15
+ from typing import TYPE_CHECKING, Any, cast
16
+
17
+ from ._common.extras import pandas, pyarrow, requires_dependency
18
+ from ._internal.api_client.client_api import core_driver
19
+ from ._internal.arrow_stream_utils import (
20
+ collect_arrow_table,
21
+ create_row_iterator,
22
+ create_table_iterator,
23
+ )
24
+ from ._internal.backward_compatibility import install_backward_compatibility_getattr
25
+ from ._internal.decorators import backward_compatibility
26
+ from ._internal.protobuf_gen.database_driver_v1_pb2 import (
27
+ ColumnMetadata,
28
+ ResultChunk,
29
+ )
30
+ from ._internal.result_batch import IterTableStructure, IterUnit, ResultBatchMixin
31
+ from ._internal.statement_utils import get_stream_ptr
32
+
33
+
34
+ if TYPE_CHECKING:
35
+ from pandas import DataFrame
36
+ from pyarrow import Table
37
+
38
+ from .connection import Connection
39
+ from .cursor import ResultMetadata
40
+
41
+
42
+ class ResultBatch(ResultBatchMixin):
43
+ """Represents a single chunk of a query result set.
44
+
45
+ Each ``ResultBatch`` corresponds to what the Snowflake back-end calls
46
+ a "result chunk". Batches know how to retrieve their own data and
47
+ convert it into Python-native formats.
48
+
49
+ Fetching is lazy: the actual download/decode happens when
50
+ :meth:`create_iter`, :meth:`to_arrow`, or :meth:`to_pandas` is called.
51
+
52
+ These objects are pickleable for easy distribution and replication.
53
+ Remote chunks use presigned URLs and can be fetched without a live
54
+ connection. Pass an optional :class:`~snowflake.connector.Connection`
55
+ when you need the connection-scoped HTTP client (for example after
56
+ unpickling in a worker that opens a fresh session).
57
+ """
58
+
59
+ _connection: Connection | None
60
+
61
+ def __init__(
62
+ self,
63
+ chunk: ResultChunk,
64
+ description: list[ResultMetadata],
65
+ connection: Connection | None,
66
+ columns: list[ColumnMetadata] | None = None,
67
+ ) -> None:
68
+ super().__init__(chunk, description, connection, columns)
69
+
70
+ # ------------------------------------------------------------------
71
+ # Properties
72
+ # ------------------------------------------------------------------
73
+
74
+ @property
75
+ def connection(self) -> Connection | None:
76
+ return self._connection
77
+
78
+ @connection.setter
79
+ def connection(self, value: Connection | None) -> None:
80
+ self._connection = value
81
+
82
+ @property
83
+ def _errorhandler_connection(self) -> Connection | None:
84
+ return self._connection
85
+
86
+ # ------------------------------------------------------------------
87
+ # Connection resolution
88
+ # ------------------------------------------------------------------
89
+
90
+ def _resolve_connection(self, connection: Connection | None = None) -> Connection | None:
91
+ return connection or self._connection
92
+
93
+ # ------------------------------------------------------------------
94
+ # Data fetching
95
+ # ------------------------------------------------------------------
96
+
97
+ def _fetch_arrow_stream_ptr(self, connection: Connection | None = None) -> int:
98
+ conn_handle = connection.conn_handle if connection is not None else None
99
+ response = core_driver.database_fetch_chunk(
100
+ conn_handle=conn_handle,
101
+ chunk=self._chunk,
102
+ columns=self._columns,
103
+ )
104
+ return get_stream_ptr(response)
105
+
106
+ def _take_arrow_stream_ptr(self, connection: Connection | None = None) -> int:
107
+ """Return the Arrow stream pointer, fetching first if necessary."""
108
+ if self._arrow_stream_ptr is None:
109
+ self.populate_data(connection=connection)
110
+ stream_ptr = cast(int, self._arrow_stream_ptr)
111
+ self._arrow_stream_ptr = None
112
+ return stream_ptr
113
+
114
+ @backward_compatibility
115
+ def populate_data(self, connection: Connection | None = None, **kwargs: Any) -> ResultBatch:
116
+ """Pre-fetch this batch's data and store it for later consumption."""
117
+ conn = self._resolve_connection(connection)
118
+ self._arrow_stream_ptr = self._fetch_arrow_stream_ptr(conn)
119
+ return self
120
+
121
+ def __iter__(self) -> Iterator[tuple | dict | Exception]:
122
+ return self.create_iter()
123
+
124
+ def create_iter(
125
+ self,
126
+ connection: Connection | None = None,
127
+ iter_unit: IterUnit | str = IterUnit.ROW_UNIT,
128
+ structure: IterTableStructure | str = IterTableStructure.PANDAS,
129
+ use_dict_result: bool = False,
130
+ number_to_decimal: bool = False,
131
+ force_microsecond_precision: bool = False,
132
+ ) -> Iterator[tuple | dict | Exception] | Iterator[Table] | Iterator[DataFrame]:
133
+ """Create an iterator over this batch's data."""
134
+ iter_unit = IterUnit.of(iter_unit)
135
+ structure = IterTableStructure.of(structure)
136
+
137
+ conn = self._resolve_connection(connection)
138
+ if iter_unit == IterUnit.TABLE_UNIT:
139
+ if structure == IterTableStructure.PANDAS:
140
+ return iter(
141
+ [
142
+ self.to_pandas(
143
+ connection=conn,
144
+ number_to_decimal=number_to_decimal,
145
+ force_microsecond_precision=force_microsecond_precision,
146
+ )
147
+ ]
148
+ )
149
+ return iter(
150
+ [
151
+ self.to_arrow(
152
+ connection=conn,
153
+ number_to_decimal=number_to_decimal,
154
+ force_microsecond_precision=force_microsecond_precision,
155
+ )
156
+ ]
157
+ )
158
+
159
+ stream_ptr = self._take_arrow_stream_ptr(conn)
160
+ return create_row_iterator(
161
+ stream_ptr,
162
+ context=self._arrow_context,
163
+ use_dict_result=use_dict_result,
164
+ use_numpy=self._numpy,
165
+ use_core_arrow=self._use_core_arrow,
166
+ )
167
+
168
+ @requires_dependency(pyarrow)
169
+ def to_arrow(
170
+ self,
171
+ connection: Connection | None = None,
172
+ number_to_decimal: bool = False,
173
+ force_microsecond_precision: bool = False,
174
+ ) -> Table:
175
+ conn = self._resolve_connection(connection)
176
+ stream_ptr = self._take_arrow_stream_ptr(conn)
177
+ return collect_arrow_table(
178
+ create_table_iterator(
179
+ stream_ptr,
180
+ context=self._arrow_context,
181
+ number_to_decimal=number_to_decimal,
182
+ force_microsecond_precision=force_microsecond_precision,
183
+ use_core_arrow=self._use_core_arrow,
184
+ ),
185
+ self._description,
186
+ )
187
+
188
+ @requires_dependency(pandas)
189
+ def to_pandas(
190
+ self,
191
+ connection: Connection | None = None,
192
+ number_to_decimal: bool = False,
193
+ force_microsecond_precision: bool = False,
194
+ ) -> DataFrame:
195
+ return self.to_arrow(
196
+ connection=connection,
197
+ number_to_decimal=number_to_decimal,
198
+ force_microsecond_precision=force_microsecond_precision,
199
+ ).to_pandas()
200
+
201
+
202
+ @backward_compatibility
203
+ class ArrowResultBatch(ResultBatch):
204
+ """Backward-compatibility wrapper around :class:`ResultBatch`."""
205
+
206
+
207
+ @backward_compatibility
208
+ class JSONResultBatch(ResultBatch):
209
+ """Backward-compatibility wrapper around :class:`ResultBatch`."""
210
+
211
+
212
+ __all__ = ["IterUnit", "IterTableStructure", "ResultBatch", "ArrowResultBatch", "JSONResultBatch"]
213
+
214
+
215
+ # Must be the last statement; see ``install_backward_compatibility_getattr``.
216
+ install_backward_compatibility_getattr(__name__)
@@ -0,0 +1,40 @@
1
+ """BACKWARD COMPATIBILITY MODULE ONLY"""
2
+
3
+ import warnings
4
+
5
+ from enum import Enum
6
+
7
+ from ._internal.backward_compatibility import _is_caller_external
8
+
9
+
10
+ class TelemetryData:
11
+ TRUE = 1 # snowpark_compat
12
+ FALSE = 0 # snowpark_compat
13
+
14
+ def __init__(self, message: str, timestamp: int) -> None:
15
+ self.message = message
16
+ self.timestamp = timestamp
17
+
18
+
19
+ class TelemetryField(Enum):
20
+ KEY_SOURCE = "source"
21
+ KEY_TYPE = "type"
22
+
23
+
24
+ _TRY_ADD_LOG_TO_BATCH_WARNED = False
25
+
26
+
27
+ class TelemetryClient:
28
+ def try_add_log_to_batch(self, *args, **kwargs): # type: ignore
29
+ global _TRY_ADD_LOG_TO_BATCH_WARNED
30
+ if not _TRY_ADD_LOG_TO_BATCH_WARNED and _is_caller_external():
31
+ _TRY_ADD_LOG_TO_BATCH_WARNED = True
32
+ warnings.warn(
33
+ "'snowflake.connector.telemetry.TelemetryClient.try_add_log_to_batch' "
34
+ "is retained only for backward compatibility and is not used by the "
35
+ "Universal Driver; use 'snowflake.connector._common.telemetry' instead. "
36
+ "It may be removed in a future release.",
37
+ DeprecationWarning,
38
+ stacklevel=2,
39
+ )
40
+ raise NotImplementedError()
@@ -0,0 +1,11 @@
1
+ """BACKWARD COMPATIBILITY MODULE ONLY"""
2
+
3
+ import time
4
+
5
+ from snowflake.connector._internal import internal_api
6
+
7
+
8
+ @internal_api
9
+ def get_time_millis() -> int:
10
+ """Return the current time in milliseconds."""
11
+ return int(time.time() * 1000)
@@ -0,0 +1,134 @@
1
+ """
2
+ PEP 249 Database API 2.0 Type Objects and Constructors
3
+
4
+ This module defines the type constructors and type objects as specified in PEP 249.
5
+ """
6
+
7
+ import datetime
8
+
9
+ from typing import Any
10
+
11
+
12
+ # Type Constructors
13
+ def Date(year: int, month: int, day: int) -> datetime.date:
14
+ """
15
+ Construct an object holding a date value.
16
+
17
+ Args:
18
+ year: Year
19
+ month: Month
20
+ day: Day
21
+
22
+ Returns:
23
+ datetime.date: Date object
24
+ """
25
+ return datetime.date(year, month, day)
26
+
27
+
28
+ def Time(hour: int, minute: int, second: int) -> datetime.time:
29
+ """
30
+ Construct an object holding a time value.
31
+
32
+ Args:
33
+ hour: Hour
34
+ minute: Minute
35
+ second: Second
36
+
37
+ Returns:
38
+ datetime.time: Time object
39
+ """
40
+ return datetime.time(hour, minute, second)
41
+
42
+
43
+ def Timestamp(year: int, month: int, day: int, hour: int, minute: int, second: int) -> datetime.datetime:
44
+ """
45
+ Construct an object holding a timestamp value.
46
+
47
+ Args:
48
+ year: Year
49
+ month: Month
50
+ day: Day
51
+ hour: Hour
52
+ minute: Minute
53
+ second: Second
54
+
55
+ Returns:
56
+ datetime.datetime: Timestamp object
57
+ """
58
+ return datetime.datetime(year, month, day, hour, minute, second)
59
+
60
+
61
+ def DateFromTicks(ticks: float) -> datetime.date:
62
+ """
63
+ Construct an object holding a date value from the given ticks value.
64
+
65
+ Args:
66
+ ticks: Seconds since the epoch
67
+
68
+ Returns:
69
+ datetime.date: Date object
70
+ """
71
+ return datetime.date.fromtimestamp(ticks)
72
+
73
+
74
+ def TimeFromTicks(ticks: float) -> datetime.time:
75
+ """
76
+ Construct an object holding a time value from the given ticks value.
77
+
78
+ Args:
79
+ ticks: Seconds since the epoch
80
+
81
+ Returns:
82
+ datetime.time: Time object
83
+ """
84
+ return datetime.datetime.fromtimestamp(ticks).time()
85
+
86
+
87
+ def TimestampFromTicks(ticks: float) -> datetime.datetime:
88
+ """
89
+ Construct an object holding a timestamp value from the given ticks value.
90
+
91
+ Args:
92
+ ticks: Seconds since the epoch
93
+
94
+ Returns:
95
+ datetime.datetime: Timestamp object
96
+ """
97
+ return datetime.datetime.fromtimestamp(ticks)
98
+
99
+
100
+ def Binary(string: str | bytes) -> bytes:
101
+ """
102
+ Construct an object capable of holding a binary (long) string value.
103
+
104
+ Args:
105
+ string: Binary data
106
+
107
+ Returns:
108
+ bytes: Binary object
109
+ """
110
+ if isinstance(string, str):
111
+ return string.encode("utf-8")
112
+ return bytes(string)
113
+
114
+
115
+ # Type Objects for comparison
116
+ class DBAPITypeObject:
117
+ """Base class for type objects that support comparison with database types."""
118
+
119
+ def __init__(self, *values: str) -> None:
120
+ self.values = values
121
+
122
+ def __eq__(self, other: Any) -> bool:
123
+ return other in self.values
124
+
125
+ def __ne__(self, other: Any) -> bool:
126
+ return other not in self.values
127
+
128
+
129
+ # Type objects for describing database column types
130
+ STRING = DBAPITypeObject("STRING", "VARCHAR", "CHAR", "TEXT")
131
+ BINARY = DBAPITypeObject("BINARY", "VARBINARY", "BLOB")
132
+ NUMBER = DBAPITypeObject("NUMBER", "INTEGER", "INT", "FLOAT", "DOUBLE", "DECIMAL", "NUMERIC")
133
+ DATETIME = DBAPITypeObject("DATETIME", "DATE", "TIME", "TIMESTAMP")
134
+ ROWID = DBAPITypeObject("ROWID", "OID")
@@ -0,0 +1,3 @@
1
+ """BACKWARD COMPATIBILITY MODULE ONLY"""
2
+
3
+ from ._internal.text_utils import split_statements # noqa
@@ -0,0 +1,23 @@
1
+ # PEP 440 compliant version string (used by hatch for packaging)
2
+ __version__ = "5.2.0"
3
+
4
+
5
+ def _release_components(version: str) -> tuple[int, ...]:
6
+ components = []
7
+ for segment in version.split("."):
8
+ numeric = ""
9
+ for char in segment:
10
+ if char.isdigit():
11
+ numeric += char
12
+ else:
13
+ break
14
+ if not numeric:
15
+ break
16
+ components.append(int(numeric))
17
+ if len(numeric) != len(segment):
18
+ break
19
+ return tuple(components)
20
+
21
+
22
+ # Compatibility with old driver pattern
23
+ VERSION = (*_release_components(__version__), None)
@@ -0,0 +1,2 @@
1
+ Version: 1.13.0
2
+ Arguments: ['C:\\Users\\runneradmin\\AppData\\Local\\Temp\\cibw-run-xhv57y_d\\cp315-win_amd64\\build\\venv\\Scripts\\delvewheel', 'repair', '--namespace-pkg', 'snowflake', '-w', 'C:\\Users\\runneradmin\\AppData\\Local\\Temp\\cibw-run-xhv57y_d\\cp315-win_amd64\\repaired_wheel', '-v', 'C:\\Users\\runneradmin\\AppData\\Local\\Temp\\cibw-run-xhv57y_d\\cp315-win_amd64\\built_wheel\\snowflake_connector_python-5.2.0-cp315-cp315-win_amd64.whl']