snowflake-connector-python 3.16.0__cp313-cp313-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 (246) hide show
  1. snowflake/connector/__init__.py +96 -0
  2. snowflake/connector/_query_context_cache.py +276 -0
  3. snowflake/connector/_sql_util.py +48 -0
  4. snowflake/connector/_utils.py +70 -0
  5. snowflake/connector/arrow_context.py +203 -0
  6. snowflake/connector/auth/__init__.py +53 -0
  7. snowflake/connector/auth/_auth.py +586 -0
  8. snowflake/connector/auth/_http_server.py +220 -0
  9. snowflake/connector/auth/_oauth_base.py +400 -0
  10. snowflake/connector/auth/by_plugin.py +219 -0
  11. snowflake/connector/auth/default.py +36 -0
  12. snowflake/connector/auth/idtoken.py +72 -0
  13. snowflake/connector/auth/keypair.py +222 -0
  14. snowflake/connector/auth/no_auth.py +39 -0
  15. snowflake/connector/auth/oauth.py +49 -0
  16. snowflake/connector/auth/oauth_code.py +479 -0
  17. snowflake/connector/auth/oauth_credentials.py +66 -0
  18. snowflake/connector/auth/okta.py +335 -0
  19. snowflake/connector/auth/pat.py +39 -0
  20. snowflake/connector/auth/usrpwdmfa.py +69 -0
  21. snowflake/connector/auth/webbrowser.py +502 -0
  22. snowflake/connector/auth/workload_identity.py +94 -0
  23. snowflake/connector/azure_storage_client.py +276 -0
  24. snowflake/connector/backoff_policies.py +141 -0
  25. snowflake/connector/bind_upload_agent.py +89 -0
  26. snowflake/connector/cache.py +696 -0
  27. snowflake/connector/compat.py +127 -0
  28. snowflake/connector/config_manager.py +496 -0
  29. snowflake/connector/connection.py +2273 -0
  30. snowflake/connector/connection_diagnostic.py +776 -0
  31. snowflake/connector/constants.py +442 -0
  32. snowflake/connector/converter.py +785 -0
  33. snowflake/connector/converter_issue23517.py +87 -0
  34. snowflake/connector/converter_null.py +14 -0
  35. snowflake/connector/converter_snowsql.py +205 -0
  36. snowflake/connector/cursor.py +1951 -0
  37. snowflake/connector/dbapi.py +53 -0
  38. snowflake/connector/description.py +19 -0
  39. snowflake/connector/direct_file_operation_utils.py +88 -0
  40. snowflake/connector/encryption_util.py +220 -0
  41. snowflake/connector/errorcode.py +91 -0
  42. snowflake/connector/errors.py +615 -0
  43. snowflake/connector/externals_utils/__init__.py +0 -0
  44. snowflake/connector/externals_utils/externals_setup.py +27 -0
  45. snowflake/connector/feature.py +4 -0
  46. snowflake/connector/file_compression_type.py +118 -0
  47. snowflake/connector/file_lock.py +72 -0
  48. snowflake/connector/file_transfer_agent.py +1215 -0
  49. snowflake/connector/file_util.py +153 -0
  50. snowflake/connector/gcs_storage_client.py +474 -0
  51. snowflake/connector/gzip_decoder.py +85 -0
  52. snowflake/connector/local_storage_client.py +90 -0
  53. snowflake/connector/log_configuration.py +60 -0
  54. snowflake/connector/logging_utils/__init__.py +0 -0
  55. snowflake/connector/logging_utils/filters.py +72 -0
  56. snowflake/connector/nanoarrow_arrow_iterator.cp313-win_amd64.pyd +0 -0
  57. snowflake/connector/nanoarrow_cpp/ArrowIterator/ArrayConverter.cpp +60 -0
  58. snowflake/connector/nanoarrow_cpp/ArrowIterator/ArrayConverter.hpp +29 -0
  59. snowflake/connector/nanoarrow_cpp/ArrowIterator/BinaryConverter.cpp +19 -0
  60. snowflake/connector/nanoarrow_cpp/ArrowIterator/BinaryConverter.hpp +26 -0
  61. snowflake/connector/nanoarrow_cpp/ArrowIterator/BooleanConverter.cpp +21 -0
  62. snowflake/connector/nanoarrow_cpp/ArrowIterator/BooleanConverter.hpp +23 -0
  63. snowflake/connector/nanoarrow_cpp/ArrowIterator/CArrowChunkIterator.cpp +557 -0
  64. snowflake/connector/nanoarrow_cpp/ArrowIterator/CArrowChunkIterator.hpp +98 -0
  65. snowflake/connector/nanoarrow_cpp/ArrowIterator/CArrowIterator.cpp +125 -0
  66. snowflake/connector/nanoarrow_cpp/ArrowIterator/CArrowIterator.hpp +115 -0
  67. snowflake/connector/nanoarrow_cpp/ArrowIterator/CArrowTableIterator.cpp +1005 -0
  68. snowflake/connector/nanoarrow_cpp/ArrowIterator/CArrowTableIterator.hpp +127 -0
  69. snowflake/connector/nanoarrow_cpp/ArrowIterator/DateConverter.cpp +47 -0
  70. snowflake/connector/nanoarrow_cpp/ArrowIterator/DateConverter.hpp +46 -0
  71. snowflake/connector/nanoarrow_cpp/ArrowIterator/DecFloatConverter.cpp +83 -0
  72. snowflake/connector/nanoarrow_cpp/ArrowIterator/DecFloatConverter.hpp +35 -0
  73. snowflake/connector/nanoarrow_cpp/ArrowIterator/DecimalConverter.cpp +97 -0
  74. snowflake/connector/nanoarrow_cpp/ArrowIterator/DecimalConverter.hpp +72 -0
  75. snowflake/connector/nanoarrow_cpp/ArrowIterator/FixedSizeListConverter.cpp +73 -0
  76. snowflake/connector/nanoarrow_cpp/ArrowIterator/FixedSizeListConverter.hpp +28 -0
  77. snowflake/connector/nanoarrow_cpp/ArrowIterator/FloatConverter.cpp +30 -0
  78. snowflake/connector/nanoarrow_cpp/ArrowIterator/FloatConverter.hpp +35 -0
  79. snowflake/connector/nanoarrow_cpp/ArrowIterator/IColumnConverter.hpp +17 -0
  80. snowflake/connector/nanoarrow_cpp/ArrowIterator/IntConverter.cpp +23 -0
  81. snowflake/connector/nanoarrow_cpp/ArrowIterator/IntConverter.hpp +45 -0
  82. snowflake/connector/nanoarrow_cpp/ArrowIterator/IntervalConverter.cpp +71 -0
  83. snowflake/connector/nanoarrow_cpp/ArrowIterator/IntervalConverter.hpp +56 -0
  84. snowflake/connector/nanoarrow_cpp/ArrowIterator/LICENSE.txt +209 -0
  85. snowflake/connector/nanoarrow_cpp/ArrowIterator/MapConverter.cpp +75 -0
  86. snowflake/connector/nanoarrow_cpp/ArrowIterator/MapConverter.hpp +30 -0
  87. snowflake/connector/nanoarrow_cpp/ArrowIterator/ObjectConverter.cpp +46 -0
  88. snowflake/connector/nanoarrow_cpp/ArrowIterator/ObjectConverter.hpp +29 -0
  89. snowflake/connector/nanoarrow_cpp/ArrowIterator/Python/Common.cpp +8 -0
  90. snowflake/connector/nanoarrow_cpp/ArrowIterator/Python/Common.hpp +95 -0
  91. snowflake/connector/nanoarrow_cpp/ArrowIterator/Python/Helpers.cpp +57 -0
  92. snowflake/connector/nanoarrow_cpp/ArrowIterator/Python/Helpers.hpp +36 -0
  93. snowflake/connector/nanoarrow_cpp/ArrowIterator/SnowflakeType.cpp +34 -0
  94. snowflake/connector/nanoarrow_cpp/ArrowIterator/SnowflakeType.hpp +48 -0
  95. snowflake/connector/nanoarrow_cpp/ArrowIterator/StringConverter.cpp +19 -0
  96. snowflake/connector/nanoarrow_cpp/ArrowIterator/StringConverter.hpp +26 -0
  97. snowflake/connector/nanoarrow_cpp/ArrowIterator/TimeConverter.cpp +36 -0
  98. snowflake/connector/nanoarrow_cpp/ArrowIterator/TimeConverter.hpp +31 -0
  99. snowflake/connector/nanoarrow_cpp/ArrowIterator/TimeStampConverter.cpp +346 -0
  100. snowflake/connector/nanoarrow_cpp/ArrowIterator/TimeStampConverter.hpp +145 -0
  101. snowflake/connector/nanoarrow_cpp/ArrowIterator/Util/macros.hpp +14 -0
  102. snowflake/connector/nanoarrow_cpp/ArrowIterator/Util/time.cpp +65 -0
  103. snowflake/connector/nanoarrow_cpp/ArrowIterator/Util/time.hpp +68 -0
  104. snowflake/connector/nanoarrow_cpp/ArrowIterator/flatcc/flatcc_accessors.h +101 -0
  105. snowflake/connector/nanoarrow_cpp/ArrowIterator/flatcc/flatcc_alloc.h +127 -0
  106. snowflake/connector/nanoarrow_cpp/ArrowIterator/flatcc/flatcc_assert.h +45 -0
  107. snowflake/connector/nanoarrow_cpp/ArrowIterator/flatcc/flatcc_builder.h +1908 -0
  108. snowflake/connector/nanoarrow_cpp/ArrowIterator/flatcc/flatcc_emitter.h +215 -0
  109. snowflake/connector/nanoarrow_cpp/ArrowIterator/flatcc/flatcc_endian.h +125 -0
  110. snowflake/connector/nanoarrow_cpp/ArrowIterator/flatcc/flatcc_epilogue.h +7 -0
  111. snowflake/connector/nanoarrow_cpp/ArrowIterator/flatcc/flatcc_flatbuffers.h +55 -0
  112. snowflake/connector/nanoarrow_cpp/ArrowIterator/flatcc/flatcc_identifier.h +148 -0
  113. snowflake/connector/nanoarrow_cpp/ArrowIterator/flatcc/flatcc_iov.h +31 -0
  114. snowflake/connector/nanoarrow_cpp/ArrowIterator/flatcc/flatcc_prologue.h +8 -0
  115. snowflake/connector/nanoarrow_cpp/ArrowIterator/flatcc/flatcc_refmap.h +144 -0
  116. snowflake/connector/nanoarrow_cpp/ArrowIterator/flatcc/flatcc_rtconfig.h +162 -0
  117. snowflake/connector/nanoarrow_cpp/ArrowIterator/flatcc/flatcc_types.h +97 -0
  118. snowflake/connector/nanoarrow_cpp/ArrowIterator/flatcc/flatcc_verifier.h +239 -0
  119. snowflake/connector/nanoarrow_cpp/ArrowIterator/flatcc/portable/flatcc_portable.h +14 -0
  120. snowflake/connector/nanoarrow_cpp/ArrowIterator/flatcc/portable/paligned_alloc.h +210 -0
  121. snowflake/connector/nanoarrow_cpp/ArrowIterator/flatcc/portable/pattributes.h +84 -0
  122. snowflake/connector/nanoarrow_cpp/ArrowIterator/flatcc/portable/pdiagnostic.h +84 -0
  123. snowflake/connector/nanoarrow_cpp/ArrowIterator/flatcc/portable/pdiagnostic_pop.h +20 -0
  124. snowflake/connector/nanoarrow_cpp/ArrowIterator/flatcc/portable/pdiagnostic_push.h +51 -0
  125. snowflake/connector/nanoarrow_cpp/ArrowIterator/flatcc/portable/pendian.h +206 -0
  126. snowflake/connector/nanoarrow_cpp/ArrowIterator/flatcc/portable/pendian_detect.h +118 -0
  127. snowflake/connector/nanoarrow_cpp/ArrowIterator/flatcc/portable/pinline.h +19 -0
  128. snowflake/connector/nanoarrow_cpp/ArrowIterator/flatcc/portable/pinttypes.h +52 -0
  129. snowflake/connector/nanoarrow_cpp/ArrowIterator/flatcc/portable/portable.h +2 -0
  130. snowflake/connector/nanoarrow_cpp/ArrowIterator/flatcc/portable/portable_basic.h +25 -0
  131. snowflake/connector/nanoarrow_cpp/ArrowIterator/flatcc/portable/pstatic_assert.h +67 -0
  132. snowflake/connector/nanoarrow_cpp/ArrowIterator/flatcc/portable/pstdalign.h +162 -0
  133. snowflake/connector/nanoarrow_cpp/ArrowIterator/flatcc/portable/pstdint.h +898 -0
  134. snowflake/connector/nanoarrow_cpp/ArrowIterator/flatcc/portable/punaligned.h +190 -0
  135. snowflake/connector/nanoarrow_cpp/ArrowIterator/flatcc/portable/pversion.h +6 -0
  136. snowflake/connector/nanoarrow_cpp/ArrowIterator/flatcc/portable/pwarnings.h +52 -0
  137. snowflake/connector/nanoarrow_cpp/ArrowIterator/flatcc.c +3204 -0
  138. snowflake/connector/nanoarrow_cpp/ArrowIterator/nanoarrow.c +3217 -0
  139. snowflake/connector/nanoarrow_cpp/ArrowIterator/nanoarrow.h +3618 -0
  140. snowflake/connector/nanoarrow_cpp/ArrowIterator/nanoarrow.hpp +379 -0
  141. snowflake/connector/nanoarrow_cpp/ArrowIterator/nanoarrow_arrow_iterator.pyx +256 -0
  142. snowflake/connector/nanoarrow_cpp/ArrowIterator/nanoarrow_device.c +512 -0
  143. snowflake/connector/nanoarrow_cpp/ArrowIterator/nanoarrow_device.h +350 -0
  144. snowflake/connector/nanoarrow_cpp/ArrowIterator/nanoarrow_ipc.c +33273 -0
  145. snowflake/connector/nanoarrow_cpp/ArrowIterator/nanoarrow_ipc.h +397 -0
  146. snowflake/connector/nanoarrow_cpp/Logging/logging.cpp +100 -0
  147. snowflake/connector/nanoarrow_cpp/Logging/logging.hpp +49 -0
  148. snowflake/connector/network.py +1297 -0
  149. snowflake/connector/ocsp_asn1crypto.py +447 -0
  150. snowflake/connector/ocsp_snowflake.py +1883 -0
  151. snowflake/connector/options.py +131 -0
  152. snowflake/connector/pandas_tools.py +732 -0
  153. snowflake/connector/proxy.py +43 -0
  154. snowflake/connector/py.typed +0 -0
  155. snowflake/connector/result_batch.py +786 -0
  156. snowflake/connector/result_set.py +319 -0
  157. snowflake/connector/s3_storage_client.py +605 -0
  158. snowflake/connector/secret_detector.py +181 -0
  159. snowflake/connector/sf_dirs.py +64 -0
  160. snowflake/connector/sfbinaryformat.py +35 -0
  161. snowflake/connector/sfdatetime.py +345 -0
  162. snowflake/connector/snow_logging.py +144 -0
  163. snowflake/connector/sqlstate.py +9 -0
  164. snowflake/connector/ssd_internal_keys.py +30 -0
  165. snowflake/connector/ssl_wrap_socket.py +134 -0
  166. snowflake/connector/storage_client.py +478 -0
  167. snowflake/connector/telemetry.py +249 -0
  168. snowflake/connector/telemetry_oob.py +543 -0
  169. snowflake/connector/test_util.py +30 -0
  170. snowflake/connector/time_util.py +159 -0
  171. snowflake/connector/token_cache.py +402 -0
  172. snowflake/connector/tool/__init__.py +0 -0
  173. snowflake/connector/tool/dump_certs.py +57 -0
  174. snowflake/connector/tool/dump_ocsp_response.py +139 -0
  175. snowflake/connector/tool/dump_ocsp_response_cache.py +194 -0
  176. snowflake/connector/tool/probe_connection.py +69 -0
  177. snowflake/connector/url_util.py +49 -0
  178. snowflake/connector/util_text.py +301 -0
  179. snowflake/connector/vendored/__init__.py +3 -0
  180. snowflake/connector/vendored/requests/LICENSE +175 -0
  181. snowflake/connector/vendored/requests/__init__.py +169 -0
  182. snowflake/connector/vendored/requests/__version__.py +14 -0
  183. snowflake/connector/vendored/requests/_internal_utils.py +50 -0
  184. snowflake/connector/vendored/requests/adapters.py +537 -0
  185. snowflake/connector/vendored/requests/api.py +157 -0
  186. snowflake/connector/vendored/requests/auth.py +315 -0
  187. snowflake/connector/vendored/requests/certs.py +17 -0
  188. snowflake/connector/vendored/requests/compat.py +79 -0
  189. snowflake/connector/vendored/requests/cookies.py +561 -0
  190. snowflake/connector/vendored/requests/exceptions.py +140 -0
  191. snowflake/connector/vendored/requests/help.py +134 -0
  192. snowflake/connector/vendored/requests/hooks.py +33 -0
  193. snowflake/connector/vendored/requests/models.py +1033 -0
  194. snowflake/connector/vendored/requests/sessions.py +833 -0
  195. snowflake/connector/vendored/requests/status_codes.py +128 -0
  196. snowflake/connector/vendored/requests/structures.py +99 -0
  197. snowflake/connector/vendored/requests/utils.py +1093 -0
  198. snowflake/connector/vendored/urllib3/LICENSE.txt +21 -0
  199. snowflake/connector/vendored/urllib3/__init__.py +85 -0
  200. snowflake/connector/vendored/urllib3/_collections.py +355 -0
  201. snowflake/connector/vendored/urllib3/_version.py +2 -0
  202. snowflake/connector/vendored/urllib3/connection.py +572 -0
  203. snowflake/connector/vendored/urllib3/connectionpool.py +1137 -0
  204. snowflake/connector/vendored/urllib3/contrib/__init__.py +0 -0
  205. snowflake/connector/vendored/urllib3/contrib/_appengine_environ.py +36 -0
  206. snowflake/connector/vendored/urllib3/contrib/_securetransport/__init__.py +0 -0
  207. snowflake/connector/vendored/urllib3/contrib/_securetransport/bindings.py +519 -0
  208. snowflake/connector/vendored/urllib3/contrib/_securetransport/low_level.py +397 -0
  209. snowflake/connector/vendored/urllib3/contrib/appengine.py +314 -0
  210. snowflake/connector/vendored/urllib3/contrib/ntlmpool.py +130 -0
  211. snowflake/connector/vendored/urllib3/contrib/pyopenssl.py +509 -0
  212. snowflake/connector/vendored/urllib3/contrib/securetransport.py +920 -0
  213. snowflake/connector/vendored/urllib3/contrib/socks.py +216 -0
  214. snowflake/connector/vendored/urllib3/exceptions.py +323 -0
  215. snowflake/connector/vendored/urllib3/fields.py +274 -0
  216. snowflake/connector/vendored/urllib3/filepost.py +98 -0
  217. snowflake/connector/vendored/urllib3/packages/__init__.py +0 -0
  218. snowflake/connector/vendored/urllib3/packages/backports/__init__.py +0 -0
  219. snowflake/connector/vendored/urllib3/packages/backports/makefile.py +51 -0
  220. snowflake/connector/vendored/urllib3/packages/backports/weakref_finalize.py +155 -0
  221. snowflake/connector/vendored/urllib3/packages/six.py +1076 -0
  222. snowflake/connector/vendored/urllib3/poolmanager.py +540 -0
  223. snowflake/connector/vendored/urllib3/request.py +191 -0
  224. snowflake/connector/vendored/urllib3/response.py +885 -0
  225. snowflake/connector/vendored/urllib3/util/__init__.py +49 -0
  226. snowflake/connector/vendored/urllib3/util/connection.py +156 -0
  227. snowflake/connector/vendored/urllib3/util/proxy.py +57 -0
  228. snowflake/connector/vendored/urllib3/util/queue.py +22 -0
  229. snowflake/connector/vendored/urllib3/util/request.py +146 -0
  230. snowflake/connector/vendored/urllib3/util/response.py +107 -0
  231. snowflake/connector/vendored/urllib3/util/retry.py +620 -0
  232. snowflake/connector/vendored/urllib3/util/ssl_.py +495 -0
  233. snowflake/connector/vendored/urllib3/util/ssl_match_hostname.py +159 -0
  234. snowflake/connector/vendored/urllib3/util/ssltransport.py +221 -0
  235. snowflake/connector/vendored/urllib3/util/timeout.py +271 -0
  236. snowflake/connector/vendored/urllib3/util/url.py +435 -0
  237. snowflake/connector/vendored/urllib3/util/wait.py +152 -0
  238. snowflake/connector/version.py +3 -0
  239. snowflake/connector/wif_util.py +407 -0
  240. snowflake_connector_python-3.16.0.dist-info/METADATA +1475 -0
  241. snowflake_connector_python-3.16.0.dist-info/RECORD +246 -0
  242. snowflake_connector_python-3.16.0.dist-info/WHEEL +5 -0
  243. snowflake_connector_python-3.16.0.dist-info/entry_points.txt +4 -0
  244. snowflake_connector_python-3.16.0.dist-info/licenses/LICENSE.txt +202 -0
  245. snowflake_connector_python-3.16.0.dist-info/licenses/NOTICE +8 -0
  246. snowflake_connector_python-3.16.0.dist-info/top_level.txt +1 -0
@@ -0,0 +1,442 @@
1
+ #!/usr/bin/env python
2
+ from __future__ import annotations
3
+
4
+ from collections import defaultdict
5
+ from enum import Enum, auto, unique
6
+ from typing import TYPE_CHECKING, Any, Callable, DefaultDict, NamedTuple
7
+
8
+ from .options import pyarrow as pa
9
+ from .sf_dirs import _resolve_platform_dirs
10
+
11
+ if TYPE_CHECKING:
12
+ from pyarrow import DataType
13
+
14
+ from .cursor import ResultMetadataV2
15
+
16
+ # Snowflake's central platform dependent directories, if the folder
17
+ # ~/.snowflake/ (customizable by the environment variable SNOWFLAKE_HOME) exists
18
+ # we use that folder for everything. Otherwise, we fall back to platformdirs
19
+ # defaults. Please see comments in sf_dir.py for more information.
20
+ DIRS = _resolve_platform_dirs()
21
+
22
+ # Snowflake's configuration files. By default, platformdirs will resolve
23
+ # them to these places depending on OS:
24
+ # * Linux: `~/.config/snowflake/filename` but can be updated with XDG vars
25
+ # * Windows: `%USERPROFILE%\AppData\Local\snowflake\filename`
26
+ # * Mac: `~/Library/Application Support/snowflake/filename`
27
+ CONNECTIONS_FILE = DIRS.user_config_path / "connections.toml"
28
+ CONFIG_FILE = DIRS.user_config_path / "config.toml"
29
+
30
+ DBAPI_TYPE_STRING = 0
31
+ DBAPI_TYPE_BINARY = 1
32
+ DBAPI_TYPE_NUMBER = 2
33
+ DBAPI_TYPE_TIMESTAMP = 3
34
+
35
+ _DEFAULT_HOSTNAME_TLD = "com"
36
+ _CHINA_HOSTNAME_TLD = "cn"
37
+ _TOP_LEVEL_DOMAIN_REGEX = r"\.[a-zA-Z]{1,63}$"
38
+ _SNOWFLAKE_HOST_SUFFIX_REGEX = r"snowflakecomputing(\.[a-zA-Z]{1,63}){1,2}$"
39
+
40
+
41
+ class FieldType(NamedTuple):
42
+ name: str
43
+ dbapi_type: list[int]
44
+ pa_type: Callable[[ResultMetadataV2], DataType]
45
+
46
+
47
+ def vector_pa_type(metadata: ResultMetadataV2) -> DataType:
48
+ """
49
+ Generate the Arrow type represented by the given vector column metadata.
50
+ Vectors are represented as Arrow fixed-size lists.
51
+ """
52
+ assert (
53
+ metadata.fields is not None and len(metadata.fields) == 1
54
+ ), "Invalid result metadata for vector type: expected a single field to be defined"
55
+ assert (
56
+ metadata.vector_dimension or 0
57
+ ) > 0, "Invalid result metadata for vector type: expected a positive dimension"
58
+
59
+ field_type = FIELD_TYPES[metadata.fields[0].type_code]
60
+ return pa.list_(field_type.pa_type(metadata.fields[0]), metadata.vector_dimension)
61
+
62
+
63
+ def array_pa_type(metadata: ResultMetadataV2) -> DataType:
64
+ """
65
+ Generate the Arrow type represented by the given array column metadata.
66
+ """
67
+ # If fields is missing then structured types are not enabled.
68
+ # Fallback to json encoded string
69
+ if metadata.fields is None:
70
+ return pa.string()
71
+
72
+ assert (
73
+ len(metadata.fields) == 1
74
+ ), "Invalid result metadata for array type: expected a single field to be defined"
75
+
76
+ field_type = FIELD_TYPES[metadata.fields[0].type_code]
77
+ return pa.list_(field_type.pa_type(metadata.fields[0]))
78
+
79
+
80
+ def map_pa_type(metadata: ResultMetadataV2) -> DataType:
81
+ """
82
+ Generate the Arrow type represented by the given map column metadata.
83
+ """
84
+ # If fields is missing then structured types are not enabled.
85
+ # Fallback to json encoded string
86
+ if metadata.fields is None:
87
+ return pa.string()
88
+
89
+ assert (
90
+ len(metadata.fields or []) == 2
91
+ ), "Invalid result metadata for map type: expected a field for key and a field for value"
92
+ key_type = FIELD_TYPES[metadata.fields[0].type_code]
93
+ value_type = FIELD_TYPES[metadata.fields[1].type_code]
94
+ return pa.map_(
95
+ key_type.pa_type(metadata.fields[0]), value_type.pa_type(metadata.fields[1])
96
+ )
97
+
98
+
99
+ def struct_pa_type(metadata: ResultMetadataV2) -> DataType:
100
+ """
101
+ Generate the Arrow type represented by the given struct column metadata.
102
+ """
103
+ # If fields is missing then structured types are not enabled.
104
+ # Fallback to json encoded string
105
+ if metadata.fields is None:
106
+ return pa.string()
107
+
108
+ assert all(
109
+ field.name is not None for field in metadata.fields
110
+ ), "All fields of a stuct type must have a name."
111
+ return pa.struct(
112
+ {
113
+ field.name: FIELD_TYPES[field.type_code].pa_type(field)
114
+ for field in metadata.fields
115
+ }
116
+ )
117
+
118
+
119
+ # This type mapping holds column type definitions.
120
+ # Be careful to not change the ordering as the index is what Snowflake
121
+ # gives to as schema
122
+ #
123
+ # `name` is the SQL name of the type, `dbapi_type` is the set of corresponding
124
+ # PEP 249 type objects, and `pa_type` is a lambda that takes in a column's
125
+ # result metadata and returns the corresponding Arrow type.
126
+ FIELD_TYPES: tuple[FieldType, ...] = (
127
+ FieldType(
128
+ name="FIXED", dbapi_type=[DBAPI_TYPE_NUMBER], pa_type=lambda _: pa.int64()
129
+ ),
130
+ FieldType(
131
+ name="REAL", dbapi_type=[DBAPI_TYPE_NUMBER], pa_type=lambda _: pa.float64()
132
+ ),
133
+ FieldType(
134
+ name="TEXT", dbapi_type=[DBAPI_TYPE_STRING], pa_type=lambda _: pa.string()
135
+ ),
136
+ FieldType(
137
+ name="DATE", dbapi_type=[DBAPI_TYPE_TIMESTAMP], pa_type=lambda _: pa.date64()
138
+ ),
139
+ FieldType(
140
+ name="TIMESTAMP",
141
+ dbapi_type=[DBAPI_TYPE_TIMESTAMP],
142
+ pa_type=lambda _: pa.time64("ns"),
143
+ ),
144
+ FieldType(
145
+ name="VARIANT", dbapi_type=[DBAPI_TYPE_BINARY], pa_type=lambda _: pa.string()
146
+ ),
147
+ FieldType(
148
+ name="TIMESTAMP_LTZ",
149
+ dbapi_type=[DBAPI_TYPE_TIMESTAMP],
150
+ pa_type=lambda _: pa.timestamp("ns"),
151
+ ),
152
+ FieldType(
153
+ name="TIMESTAMP_TZ",
154
+ dbapi_type=[DBAPI_TYPE_TIMESTAMP],
155
+ pa_type=lambda _: pa.timestamp("ns"),
156
+ ),
157
+ FieldType(
158
+ name="TIMESTAMP_NTZ",
159
+ dbapi_type=[DBAPI_TYPE_TIMESTAMP],
160
+ pa_type=lambda _: pa.timestamp("ns"),
161
+ ),
162
+ FieldType(name="OBJECT", dbapi_type=[DBAPI_TYPE_BINARY], pa_type=struct_pa_type),
163
+ FieldType(name="ARRAY", dbapi_type=[DBAPI_TYPE_BINARY], pa_type=array_pa_type),
164
+ FieldType(
165
+ name="BINARY", dbapi_type=[DBAPI_TYPE_BINARY], pa_type=lambda _: pa.binary()
166
+ ),
167
+ FieldType(
168
+ name="TIME",
169
+ dbapi_type=[DBAPI_TYPE_TIMESTAMP],
170
+ pa_type=lambda _: pa.time64("ns"),
171
+ ),
172
+ FieldType(name="BOOLEAN", dbapi_type=[], pa_type=lambda _: pa.bool_()),
173
+ FieldType(
174
+ name="GEOGRAPHY", dbapi_type=[DBAPI_TYPE_STRING], pa_type=lambda _: pa.string()
175
+ ),
176
+ FieldType(
177
+ name="GEOMETRY", dbapi_type=[DBAPI_TYPE_STRING], pa_type=lambda _: pa.string()
178
+ ),
179
+ FieldType(name="VECTOR", dbapi_type=[DBAPI_TYPE_BINARY], pa_type=vector_pa_type),
180
+ FieldType(name="MAP", dbapi_type=[DBAPI_TYPE_BINARY], pa_type=map_pa_type),
181
+ FieldType(
182
+ name="FILE", dbapi_type=[DBAPI_TYPE_STRING], pa_type=lambda _: pa.string()
183
+ ),
184
+ )
185
+
186
+ FIELD_NAME_TO_ID: DefaultDict[Any, int] = defaultdict(int)
187
+ FIELD_ID_TO_NAME: DefaultDict[int, str] = defaultdict(str)
188
+
189
+ __binary_types: list[int] = []
190
+ __binary_type_names: list[str] = []
191
+ __string_types: list[int] = []
192
+ __string_type_names: list[str] = []
193
+ __number_types: list[int] = []
194
+ __number_type_names: list[str] = []
195
+ __timestamp_types: list[int] = []
196
+ __timestamp_type_names: list[str] = []
197
+
198
+ for idx, field_type in enumerate(FIELD_TYPES):
199
+ FIELD_ID_TO_NAME[idx] = field_type.name
200
+ FIELD_NAME_TO_ID[field_type.name] = idx
201
+
202
+ dbapi_types = field_type.dbapi_type
203
+ for dbapi_type in dbapi_types:
204
+ if dbapi_type == DBAPI_TYPE_BINARY:
205
+ __binary_types.append(idx)
206
+ __binary_type_names.append(field_type.name)
207
+ elif dbapi_type == DBAPI_TYPE_TIMESTAMP:
208
+ __timestamp_types.append(idx)
209
+ __timestamp_type_names.append(field_type.name)
210
+ elif dbapi_type == DBAPI_TYPE_NUMBER:
211
+ __number_types.append(idx)
212
+ __number_type_names.append(field_type.name)
213
+ elif dbapi_type == DBAPI_TYPE_STRING:
214
+ __string_types.append(idx)
215
+ __string_type_names.append(field_type.name)
216
+
217
+
218
+ def get_binary_types() -> list[int]:
219
+ return __binary_types
220
+
221
+
222
+ def is_binary_type_name(type_name: str) -> bool:
223
+ return type_name in __binary_type_names
224
+
225
+
226
+ def get_string_types() -> list[int]:
227
+ return __string_types
228
+
229
+
230
+ def is_string_type_name(type_name) -> bool:
231
+ return type_name in __string_type_names
232
+
233
+
234
+ def get_number_types() -> list[int]:
235
+ return __number_types
236
+
237
+
238
+ def is_number_type_name(type_name) -> bool:
239
+ return type_name in __number_type_names
240
+
241
+
242
+ def get_timestamp_types() -> list[int]:
243
+ return __timestamp_types
244
+
245
+
246
+ def is_timestamp_type_name(type_name) -> bool:
247
+ return type_name in __timestamp_type_names
248
+
249
+
250
+ def is_date_type_name(type_name) -> bool:
251
+ return type_name == "DATE"
252
+
253
+
254
+ # Log format
255
+ LOG_FORMAT = (
256
+ "%(asctime)s - %(filename)s:%(lineno)d - "
257
+ "%(funcName)s() - %(levelname)s - %(message)s"
258
+ )
259
+
260
+ # String literals
261
+ UTF8 = "utf-8"
262
+ SHA256_DIGEST = "sha256_digest"
263
+
264
+ # PUT/GET related
265
+ S3_FS = "S3"
266
+ AZURE_FS = "AZURE"
267
+ GCS_FS = "GCS"
268
+ LOCAL_FS = "LOCAL_FS"
269
+ CMD_TYPE_UPLOAD = "UPLOAD"
270
+ CMD_TYPE_DOWNLOAD = "DOWNLOAD"
271
+ FILE_PROTOCOL = "file://"
272
+
273
+
274
+ @unique
275
+ class ResultStatus(Enum):
276
+ ERROR = "ERROR"
277
+ SUCCEEDED = "SUCCEEDED"
278
+ UPLOADED = "UPLOADED"
279
+ DOWNLOADED = "DOWNLOADED"
280
+ COLLISION = "COLLISION"
281
+ SKIPPED = "SKIPPED"
282
+ RENEW_TOKEN = "RENEW_TOKEN"
283
+ RENEW_PRESIGNED_URL = "RENEW_PRESIGNED_URL"
284
+ NOT_FOUND_FILE = "NOT_FOUND_FILE"
285
+ NEED_RETRY = "NEED_RETRY"
286
+ NEED_RETRY_WITH_LOWER_CONCURRENCY = "NEED_RETRY_WITH_LOWER_CONCURRENCY"
287
+
288
+
289
+ class SnowflakeS3FileEncryptionMaterial(NamedTuple):
290
+ query_id: str
291
+ query_stage_master_key: str
292
+ smk_id: int
293
+
294
+
295
+ class MaterialDescriptor(NamedTuple):
296
+ smk_id: int
297
+ query_id: str
298
+ key_size: int
299
+
300
+
301
+ class EncryptionMetadata(NamedTuple):
302
+ key: str
303
+ iv: str
304
+ matdesc: str
305
+
306
+
307
+ class FileHeader(NamedTuple):
308
+ digest: str | None
309
+ content_length: int | None
310
+ encryption_metadata: EncryptionMetadata | None
311
+
312
+
313
+ PARAMETER_AUTOCOMMIT = "AUTOCOMMIT"
314
+ PARAMETER_CLIENT_SESSION_KEEP_ALIVE_HEARTBEAT_FREQUENCY = (
315
+ "CLIENT_SESSION_KEEP_ALIVE_HEARTBEAT_FREQUENCY"
316
+ )
317
+ PARAMETER_CLIENT_SESSION_KEEP_ALIVE = "CLIENT_SESSION_KEEP_ALIVE"
318
+ PARAMETER_CLIENT_PREFETCH_THREADS = "CLIENT_PREFETCH_THREADS"
319
+ PARAMETER_CLIENT_TELEMETRY_ENABLED = "CLIENT_TELEMETRY_ENABLED"
320
+ PARAMETER_CLIENT_TELEMETRY_OOB_ENABLED = "CLIENT_OUT_OF_BAND_TELEMETRY_ENABLED"
321
+ PARAMETER_CLIENT_STORE_TEMPORARY_CREDENTIAL = "CLIENT_STORE_TEMPORARY_CREDENTIAL"
322
+ PARAMETER_CLIENT_REQUEST_MFA_TOKEN = "CLIENT_REQUEST_MFA_TOKEN"
323
+ PARAMETER_CLIENT_USE_SECURE_STORAGE_FOR_TEMPORARY_CREDENTIAL = (
324
+ "CLIENT_USE_SECURE_STORAGE_FOR_TEMPORARY_CREDENTIAL"
325
+ )
326
+ PARAMETER_QUERY_CONTEXT_CACHE_SIZE = "QUERY_CONTEXT_CACHE_SIZE"
327
+ PARAMETER_TIMEZONE = "TIMEZONE"
328
+ PARAMETER_SERVICE_NAME = "SERVICE_NAME"
329
+ PARAMETER_CLIENT_VALIDATE_DEFAULT_PARAMETERS = "CLIENT_VALIDATE_DEFAULT_PARAMETERS"
330
+ PARAMETER_PYTHON_CONNECTOR_QUERY_RESULT_FORMAT = "PYTHON_CONNECTOR_QUERY_RESULT_FORMAT"
331
+ PARAMETER_ENABLE_STAGE_S3_PRIVATELINK_FOR_US_EAST_1 = (
332
+ "ENABLE_STAGE_S3_PRIVATELINK_FOR_US_EAST_1"
333
+ )
334
+ PARAMETER_MULTI_STATEMENT_COUNT = "MULTI_STATEMENT_COUNT"
335
+
336
+ HTTP_HEADER_CONTENT_TYPE = "Content-Type"
337
+ HTTP_HEADER_CONTENT_ENCODING = "Content-Encoding"
338
+ HTTP_HEADER_ACCEPT_ENCODING = "Accept-Encoding"
339
+ HTTP_HEADER_ACCEPT = "accept"
340
+ HTTP_HEADER_USER_AGENT = "User-Agent"
341
+ HTTP_HEADER_SERVICE_NAME = "X-Snowflake-Service"
342
+
343
+ HTTP_HEADER_VALUE_OCTET_STREAM = "application/octet-stream"
344
+
345
+
346
+ @unique
347
+ class OCSPMode(Enum):
348
+ """OCSP Mode enumerator for all the available modes.
349
+
350
+ OCSP mode descriptions:
351
+ FAIL_CLOSED: If the client or driver does not receive a valid OCSP CA response for any reason,
352
+ the connection fails.
353
+ FAIL_OPEN: A response indicating a revoked certificate results in a failed connection. A response with any
354
+ other certificate errors or statuses allows the connection to occur, but denotes the message in the logs
355
+ at the WARNING level with the relevant details in JSON format.
356
+ INSECURE (deprecated): The connection will occur anyway.
357
+ DISABLE_OCSP_CHECKS: The OCSP check will not happen. If the certificate is valid then connection will occur.
358
+ """
359
+
360
+ FAIL_CLOSED = "FAIL_CLOSED"
361
+ FAIL_OPEN = "FAIL_OPEN"
362
+ INSECURE = "INSECURE"
363
+ DISABLE_OCSP_CHECKS = "DISABLE_OCSP_CHECKS"
364
+
365
+
366
+ @unique
367
+ class FileTransferType(Enum):
368
+ """This enum keeps track of the possible file transfer types."""
369
+
370
+ PUT = auto()
371
+ GET = auto()
372
+
373
+
374
+ @unique
375
+ class QueryStatus(Enum):
376
+ RUNNING = 0
377
+ ABORTING = 1
378
+ SUCCESS = 2
379
+ FAILED_WITH_ERROR = 3
380
+ ABORTED = 4
381
+ QUEUED = 5
382
+ FAILED_WITH_INCIDENT = 6
383
+ DISCONNECTED = 7
384
+ RESUMING_WAREHOUSE = 8
385
+ # purposeful typo. Is present in QueryDTO.java
386
+ QUEUED_REPARING_WAREHOUSE = 9
387
+ RESTARTED = 10
388
+ BLOCKED = 11
389
+ NO_DATA = 12
390
+
391
+
392
+ # Size constants
393
+ kilobyte = 1024
394
+ megabyte = kilobyte * 1024
395
+ gigabyte = megabyte * 1024
396
+
397
+
398
+ # ArrowResultChunk constants the unit in this iterator
399
+ # EMPTY_UNIT: default
400
+ # ROW_UNIT: fetch row by row if the user call `fetchone()`
401
+ # TABLE_UNIT: fetch one arrow table if the user call `fetch_pandas()`
402
+ @unique
403
+ class IterUnit(Enum):
404
+ ROW_UNIT = "row"
405
+ TABLE_UNIT = "table"
406
+
407
+
408
+ # File Transfer
409
+ # Amazon S3 multipart upload limits
410
+ # https://docs.aws.amazon.com/AmazonS3/latest/userguide/qfacts.html
411
+ S3_DEFAULT_CHUNK_SIZE = 8 * 1024**2
412
+ S3_MAX_OBJECT_SIZE = 5 * 1024**4
413
+ S3_MAX_PART_SIZE = 5 * 1024**3
414
+ S3_MIN_PART_SIZE = 5 * 1024**2
415
+ S3_MAX_PARTS = 10000
416
+
417
+ S3_CHUNK_SIZE = 8388608 # boto3 default
418
+ AZURE_CHUNK_SIZE = 4 * megabyte
419
+
420
+ # https://requests.readthedocs.io/en/latest/user/advanced/#timeouts
421
+ REQUEST_CONNECTION_TIMEOUT = 10
422
+ REQUEST_READ_TIMEOUT = 600
423
+
424
+ DAY_IN_SECONDS = 60 * 60 * 24
425
+
426
+ # TODO: all env variables definitions should be here
427
+ ENV_VAR_PARTNER = "SF_PARTNER"
428
+ ENV_VAR_TEST_MODE = "SNOWFLAKE_TEST_MODE"
429
+ ENV_VAR_EXPERIMENTAL_AUTHENTICATION = "SF_ENABLE_EXPERIMENTAL_AUTHENTICATION" # Needed to enable new strong auth features during the private preview.
430
+
431
+
432
+ _DOMAIN_NAME_MAP = {_DEFAULT_HOSTNAME_TLD: "GLOBAL", _CHINA_HOSTNAME_TLD: "CHINA"}
433
+
434
+ _CONNECTIVITY_ERR_MSG = (
435
+ "Verify that the hostnames and port numbers in SYSTEM$ALLOWLIST are added to your firewall's allowed list."
436
+ "\nTo further troubleshoot your connection you may reference the following article: "
437
+ "https://docs.snowflake.com/en/user-guide/client-connectivity-troubleshooting/overview."
438
+ )
439
+
440
+ _OAUTH_DEFAULT_SCOPE = "session:role:{role}"
441
+ OAUTH_TYPE_AUTHORIZATION_CODE = "authorization_code"
442
+ OAUTH_TYPE_CLIENT_CREDENTIALS = "client_credentials"