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,379 @@
1
+ // Licensed to the Apache Software Foundation (ASF) under one
2
+ // or more contributor license agreements. See the NOTICE file
3
+ // distributed with this work for additional information
4
+ // regarding copyright ownership. The ASF licenses this file
5
+ // to you under the Apache License, Version 2.0 (the
6
+ // "License"); you may not use this file except in compliance
7
+ // with the License. You may obtain a copy of the License at
8
+ //
9
+ // http://www.apache.org/licenses/LICENSE-2.0
10
+ //
11
+ // Unless required by applicable law or agreed to in writing,
12
+ // software distributed under the License is distributed on an
13
+ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
+ // KIND, either express or implied. See the License for the
15
+ // specific language governing permissions and limitations
16
+ // under the License.
17
+
18
+ #include <stdexcept>
19
+ #include <string>
20
+ #include <vector>
21
+
22
+ #include "nanoarrow.h"
23
+
24
+ #ifndef NANOARROW_HPP_INCLUDED
25
+ #define NANOARROW_HPP_INCLUDED
26
+
27
+ /// \defgroup nanoarrow_hpp Nanoarrow C++ Helpers
28
+ ///
29
+ /// The utilities provided in this file are intended to support C++ users
30
+ /// of the nanoarrow C library such that C++-style resource allocation
31
+ /// and error handling can be used with nanoarrow data structures.
32
+ /// These utilities are not intended to mirror the nanoarrow C API.
33
+
34
+ namespace nanoarrow {
35
+
36
+ /// \defgroup nanoarrow_hpp-errors Error handling helpers
37
+ ///
38
+ /// Most functions in the C API return an ArrowErrorCode to communicate
39
+ /// possible failure. Except where documented, it is usually not safe to
40
+ /// continue after a non-zero value has been returned. While the
41
+ /// nanoarrow C++ helpers do not throw any exceptions of their own,
42
+ /// these helpers are provided to facilitate using the nanoarrow C++ helpers
43
+ /// in frameworks where this is a useful error handling idiom.
44
+ ///
45
+ /// @{
46
+
47
+ class Exception : public std::exception {
48
+ public:
49
+ Exception(const std::string& msg) : msg_(msg) {}
50
+ const char* what() const noexcept { return msg_.c_str(); }
51
+
52
+ private:
53
+ std::string msg_;
54
+ };
55
+
56
+ #if defined(NANOARROW_DEBUG)
57
+ #define _NANOARROW_THROW_NOT_OK_IMPL(NAME, EXPR, EXPR_STR) \
58
+ do { \
59
+ const int NAME = (EXPR); \
60
+ if (NAME) { \
61
+ throw nanoarrow::Exception( \
62
+ std::string(EXPR_STR) + std::string(" failed with errno ") + \
63
+ std::to_string(NAME) + std::string("\n * ") + \
64
+ std::string(__FILE__) + std::string(":") + \
65
+ std::to_string(__LINE__) + std::string("\n")); \
66
+ } \
67
+ } while (0)
68
+ #else
69
+ #define _NANOARROW_THROW_NOT_OK_IMPL(NAME, EXPR, EXPR_STR) \
70
+ do { \
71
+ const int NAME = (EXPR); \
72
+ if (NAME) { \
73
+ throw nanoarrow::Exception(std::string(EXPR_STR) + \
74
+ std::string(" failed with errno ") + \
75
+ std::to_string(NAME)); \
76
+ } \
77
+ } while (0)
78
+ #endif
79
+
80
+ #define NANOARROW_THROW_NOT_OK(EXPR) \
81
+ _NANOARROW_THROW_NOT_OK_IMPL( \
82
+ _NANOARROW_MAKE_NAME(errno_status_, __COUNTER__), EXPR, #EXPR)
83
+
84
+ /// @}
85
+
86
+ namespace internal {
87
+
88
+ /// \defgroup nanoarrow_hpp-unique_base Base classes for Unique wrappers
89
+ ///
90
+ /// @{
91
+
92
+ static inline void init_pointer(struct ArrowSchema* data) {
93
+ data->release = nullptr;
94
+ }
95
+
96
+ static inline void move_pointer(struct ArrowSchema* src,
97
+ struct ArrowSchema* dst) {
98
+ ArrowSchemaMove(src, dst);
99
+ }
100
+
101
+ static inline void release_pointer(struct ArrowSchema* data) {
102
+ if (data->release != nullptr) {
103
+ data->release(data);
104
+ }
105
+ }
106
+
107
+ static inline void init_pointer(struct ArrowArray* data) {
108
+ data->release = nullptr;
109
+ }
110
+
111
+ static inline void move_pointer(struct ArrowArray* src,
112
+ struct ArrowArray* dst) {
113
+ ArrowArrayMove(src, dst);
114
+ }
115
+
116
+ static inline void release_pointer(struct ArrowArray* data) {
117
+ if (data->release != nullptr) {
118
+ data->release(data);
119
+ }
120
+ }
121
+
122
+ static inline void init_pointer(struct ArrowArrayStream* data) {
123
+ data->release = nullptr;
124
+ }
125
+
126
+ static inline void move_pointer(struct ArrowArrayStream* src,
127
+ struct ArrowArrayStream* dst) {
128
+ ArrowArrayStreamMove(src, dst);
129
+ }
130
+
131
+ static inline void release_pointer(ArrowArrayStream* data) {
132
+ if (data->release != nullptr) {
133
+ data->release(data);
134
+ }
135
+ }
136
+
137
+ static inline void init_pointer(struct ArrowBuffer* data) {
138
+ ArrowBufferInit(data);
139
+ }
140
+
141
+ static inline void move_pointer(struct ArrowBuffer* src,
142
+ struct ArrowBuffer* dst) {
143
+ ArrowBufferMove(src, dst);
144
+ }
145
+
146
+ static inline void release_pointer(struct ArrowBuffer* data) {
147
+ ArrowBufferReset(data);
148
+ }
149
+
150
+ static inline void init_pointer(struct ArrowBitmap* data) {
151
+ ArrowBitmapInit(data);
152
+ }
153
+
154
+ static inline void move_pointer(struct ArrowBitmap* src,
155
+ struct ArrowBitmap* dst) {
156
+ ArrowBitmapMove(src, dst);
157
+ }
158
+
159
+ static inline void release_pointer(struct ArrowBitmap* data) {
160
+ ArrowBitmapReset(data);
161
+ }
162
+
163
+ static inline void init_pointer(struct ArrowArrayView* data) {
164
+ ArrowArrayViewInitFromType(data, NANOARROW_TYPE_UNINITIALIZED);
165
+ }
166
+
167
+ static inline void move_pointer(struct ArrowArrayView* src,
168
+ struct ArrowArrayView* dst) {
169
+ ArrowArrayViewMove(src, dst);
170
+ }
171
+
172
+ static inline void release_pointer(struct ArrowArrayView* data) {
173
+ ArrowArrayViewReset(data);
174
+ }
175
+
176
+ /// \brief A unique_ptr-like base class for stack-allocatable objects
177
+ /// \tparam T The object type
178
+ template <typename T>
179
+ class Unique {
180
+ public:
181
+ /// \brief Construct an invalid instance of T holding no resources
182
+ Unique() { init_pointer(&data_); }
183
+
184
+ /// \brief Move and take ownership of data
185
+ Unique(T* data) { move_pointer(data, &data_); }
186
+
187
+ /// \brief Move and take ownership of data wrapped by rhs
188
+ Unique(Unique&& rhs) : Unique(rhs.get()) {}
189
+
190
+ // These objects are not copyable
191
+ Unique(Unique& rhs) = delete;
192
+
193
+ /// \brief Get a pointer to the data owned by this object
194
+ T* get() noexcept { return &data_; }
195
+
196
+ /// \brief Use the pointer operator to access fields of this object
197
+ T* operator->() { return &data_; }
198
+
199
+ /// \brief Call data's release callback if valid
200
+ void reset() { release_pointer(&data_); }
201
+
202
+ /// \brief Call data's release callback if valid and move ownership of the
203
+ /// data pointed to by data
204
+ void reset(T* data) {
205
+ reset();
206
+ move_pointer(data, &data_);
207
+ }
208
+
209
+ /// \brief Move ownership of this object to the data pointed to by out
210
+ void move(T* out) { move_pointer(&data_, out); }
211
+
212
+ ~Unique() { reset(); }
213
+
214
+ protected:
215
+ T data_;
216
+ };
217
+
218
+ /// @}
219
+
220
+ } // namespace internal
221
+
222
+ /// \defgroup nanoarrow_hpp-unique Unique object wrappers
223
+ ///
224
+ /// The Arrow C Data interface, the Arrow C Stream interface, and the
225
+ /// nanoarrow C library use stack-allocatable objects, some of which
226
+ /// require initialization or cleanup.
227
+ ///
228
+ /// @{
229
+
230
+ /// \brief Class wrapping a unique struct ArrowSchema
231
+ using UniqueSchema = internal::Unique<struct ArrowSchema>;
232
+
233
+ /// \brief Class wrapping a unique struct ArrowArray
234
+ using UniqueArray = internal::Unique<struct ArrowArray>;
235
+
236
+ /// \brief Class wrapping a unique struct ArrowArrayStream
237
+ using UniqueArrayStream = internal::Unique<struct ArrowArrayStream>;
238
+
239
+ /// \brief Class wrapping a unique struct ArrowBuffer
240
+ using UniqueBuffer = internal::Unique<struct ArrowBuffer>;
241
+
242
+ /// \brief Class wrapping a unique struct ArrowBitmap
243
+ using UniqueBitmap = internal::Unique<struct ArrowBitmap>;
244
+
245
+ /// \brief Class wrapping a unique struct ArrowArrayView
246
+ using UniqueArrayView = internal::Unique<struct ArrowArrayView>;
247
+
248
+ /// @}
249
+
250
+ /// \defgroup nanoarrow_hpp-array-stream ArrayStream helpers
251
+ ///
252
+ /// These classes provide simple struct ArrowArrayStream implementations that
253
+ /// can be extended to help simplify the process of creating a valid
254
+ /// ArrowArrayStream implementation or used as-is for testing.
255
+ ///
256
+ /// @{
257
+
258
+ /// \brief An empty array stream
259
+ ///
260
+ /// This class can be constructed from an enum ArrowType or
261
+ /// struct ArrowSchema and implements a default get_next() method that
262
+ /// always marks the output ArrowArray as released. This class can
263
+ /// be extended with an implementation of get_next() for a custom
264
+ /// source.
265
+ class EmptyArrayStream {
266
+ public:
267
+ /// \brief Create an empty UniqueArrayStream from a struct ArrowSchema
268
+ ///
269
+ /// This object takes ownership of the schema and marks the source schema
270
+ /// as released.
271
+ static UniqueArrayStream MakeUnique(struct ArrowSchema* schema) {
272
+ UniqueArrayStream stream;
273
+ (new EmptyArrayStream(schema))->MakeStream(stream.get());
274
+ return stream;
275
+ }
276
+
277
+ virtual ~EmptyArrayStream() {}
278
+
279
+ protected:
280
+ UniqueSchema schema_;
281
+ struct ArrowError error_;
282
+
283
+ EmptyArrayStream(struct ArrowSchema* schema) : schema_(schema) {
284
+ error_.message[0] = '\0';
285
+ }
286
+
287
+ void MakeStream(struct ArrowArrayStream* stream) {
288
+ stream->get_schema = &get_schema_wrapper;
289
+ stream->get_next = &get_next_wrapper;
290
+ stream->get_last_error = &get_last_error_wrapper;
291
+ stream->release = &release_wrapper;
292
+ stream->private_data = this;
293
+ }
294
+
295
+ virtual int get_schema(struct ArrowSchema* schema) {
296
+ return ArrowSchemaDeepCopy(schema_.get(), schema);
297
+ }
298
+
299
+ virtual int get_next(struct ArrowArray* array) {
300
+ array->release = nullptr;
301
+ return NANOARROW_OK;
302
+ }
303
+
304
+ virtual const char* get_last_error() { return error_.message; }
305
+
306
+ private:
307
+ static int get_schema_wrapper(struct ArrowArrayStream* stream,
308
+ struct ArrowSchema* schema) {
309
+ return reinterpret_cast<EmptyArrayStream*>(stream->private_data)
310
+ ->get_schema(schema);
311
+ }
312
+
313
+ static int get_next_wrapper(struct ArrowArrayStream* stream,
314
+ struct ArrowArray* array) {
315
+ return reinterpret_cast<EmptyArrayStream*>(stream->private_data)
316
+ ->get_next(array);
317
+ }
318
+
319
+ static const char* get_last_error_wrapper(struct ArrowArrayStream* stream) {
320
+ return reinterpret_cast<EmptyArrayStream*>(stream->private_data)
321
+ ->get_last_error();
322
+ }
323
+
324
+ static void release_wrapper(struct ArrowArrayStream* stream) {
325
+ delete reinterpret_cast<EmptyArrayStream*>(stream->private_data);
326
+ stream->release = nullptr;
327
+ stream->private_data = nullptr;
328
+ }
329
+ };
330
+
331
+ /// \brief Implementation of an ArrowArrayStream backed by a vector of
332
+ /// ArrowArray objects
333
+ class VectorArrayStream : public EmptyArrayStream {
334
+ public:
335
+ /// \brief Create a UniqueArrowArrayStream from an existing array
336
+ ///
337
+ /// Takes ownership of the schema and the array.
338
+ static UniqueArrayStream MakeUnique(struct ArrowSchema* schema,
339
+ struct ArrowArray* array) {
340
+ std::vector<UniqueArray> arrays;
341
+ arrays.emplace_back(array);
342
+ return MakeUnique(schema, std::move(arrays));
343
+ }
344
+
345
+ /// \brief Create a UniqueArrowArrayStream from existing arrays
346
+ ///
347
+ /// This object takes ownership of the schema and arrays.
348
+ static UniqueArrayStream MakeUnique(struct ArrowSchema* schema,
349
+ std::vector<UniqueArray> arrays) {
350
+ UniqueArrayStream stream;
351
+ (new VectorArrayStream(schema, std::move(arrays)))
352
+ ->MakeStream(stream.get());
353
+ return stream;
354
+ }
355
+
356
+ protected:
357
+ VectorArrayStream(struct ArrowSchema* schema, std::vector<UniqueArray> arrays)
358
+ : EmptyArrayStream(schema), arrays_(std::move(arrays)), offset_(0) {}
359
+
360
+ int get_next(struct ArrowArray* array) {
361
+ if (offset_ < static_cast<int64_t>(arrays_.size())) {
362
+ arrays_[offset_++].move(array);
363
+ } else {
364
+ array->release = nullptr;
365
+ }
366
+
367
+ return NANOARROW_OK;
368
+ }
369
+
370
+ private:
371
+ std::vector<UniqueArray> arrays_;
372
+ int64_t offset_;
373
+ };
374
+
375
+ /// @}
376
+
377
+ } // namespace nanoarrow
378
+
379
+ #endif
@@ -0,0 +1,256 @@
1
+ # distutils: language = c++
2
+ # cython: language_level=3
3
+
4
+
5
+ from cpython.ref cimport PyObject
6
+ from cython.operator cimport dereference
7
+ from libc.stdint cimport int64_t, uint8_t, uintptr_t
8
+ from libcpp.vector cimport vector
9
+
10
+ INSTALLED_PYARROW = False
11
+ try:
12
+ import pyarrow
13
+ INSTALLED_PYARROW = True
14
+ except ImportError:
15
+ pass
16
+
17
+ from .constants import IterUnit
18
+ from .errorcode import (
19
+ ER_FAILED_TO_CONVERT_ROW_TO_PYTHON_TYPE,
20
+ ER_FAILED_TO_READ_ARROW_STREAM,
21
+ ER_NO_PYARROW,
22
+ )
23
+ from .errors import Error, InterfaceError, OperationalError, ProgrammingError
24
+ from .snow_logging import getSnowLogger
25
+
26
+ snow_logger = getSnowLogger(__name__)
27
+
28
+
29
+ cdef extern from "CArrowIterator.hpp" namespace "sf":
30
+ cdef cppclass ReturnVal:
31
+ PyObject * successObj;
32
+
33
+ PyObject * exception;
34
+
35
+ cdef cppclass CArrowIterator:
36
+ ReturnVal next() except +;
37
+ ReturnVal checkInitializationStatus() except +;
38
+ vector[uintptr_t] getArrowArrayPtrs();
39
+ vector[uintptr_t] getArrowSchemaPtrs();
40
+
41
+
42
+ cdef extern from "CArrowChunkIterator.hpp" namespace "sf":
43
+ cdef cppclass CArrowChunkIterator(CArrowIterator):
44
+ CArrowChunkIterator(
45
+ PyObject* context,
46
+ char* arrow_bytes,
47
+ int64_t arrow_bytes_size,
48
+ PyObject* use_numpy,
49
+ PyObject* check_error_on_every_column,
50
+ ) except +
51
+
52
+ cdef cppclass DictCArrowChunkIterator(CArrowChunkIterator):
53
+ DictCArrowChunkIterator(
54
+ PyObject* context,
55
+ char* arrow_bytes,
56
+ int64_t arrow_bytes_size,
57
+ PyObject* use_numpy
58
+ ) except +
59
+
60
+ cdef extern from "CArrowTableIterator.hpp" namespace "sf":
61
+ cdef cppclass CArrowTableIterator(CArrowIterator):
62
+ CArrowTableIterator(
63
+ PyObject* context,
64
+ char* arrow_bytes,
65
+ int64_t arrow_bytes_size,
66
+ bint number_to_decimal,
67
+ ) except +
68
+
69
+
70
+ cdef class EmptyPyArrowIterator:
71
+
72
+ def __iter__(self):
73
+ return self
74
+
75
+ def __next__(self):
76
+ raise StopIteration
77
+
78
+ def init(self, str iter_unit, bint number_to_decimal):
79
+ pass
80
+
81
+
82
+ cdef class PyArrowIterator(EmptyPyArrowIterator):
83
+ cdef object context
84
+ cdef CArrowIterator* cIterator
85
+ cdef str unit
86
+ cdef object use_dict_result
87
+ cdef object cursor
88
+ cdef vector[uintptr_t] nanoarrow_Table
89
+ cdef vector[uintptr_t] nanoarrow_Schema
90
+ cdef object table_returned
91
+ cdef char* arrow_bytes
92
+ cdef int64_t arrow_bytes_size
93
+
94
+ # this is the flag indicating whether fetch data as numpy datatypes or not. The flag
95
+ # is passed from the constructor of SnowflakeConnection class. Note, only FIXED, REAL
96
+ # and TIMESTAMP_NTZ will be converted into numpy data types, all other sql types will
97
+ # still be converted into native python types.
98
+ # https://docs.snowflake.com/en/user-guide/sqlalchemy.html#numpy-data-type-support
99
+ cdef object use_numpy
100
+ cdef object check_error_on_every_column
101
+ cdef object number_to_decimal
102
+ cdef object pyarrow_table
103
+
104
+ def __cinit__(
105
+ self,
106
+ object cursor,
107
+ object arrow_bytes,
108
+ object arrow_context,
109
+ object use_dict_result,
110
+ object numpy,
111
+ object number_to_decimal,
112
+ object check_error_on_every_column
113
+ ):
114
+ self.context = arrow_context
115
+ self.cIterator = NULL
116
+ self.use_dict_result = use_dict_result
117
+ self.cursor = cursor
118
+ self.use_numpy = numpy
119
+ self.check_error_on_every_column = check_error_on_every_column
120
+ self.number_to_decimal = number_to_decimal
121
+ self.pyarrow_table = None
122
+ self.table_returned = False
123
+ self.arrow_bytes = <char*>arrow_bytes
124
+ self.arrow_bytes_size = len(arrow_bytes)
125
+
126
+ def __dealloc__(self):
127
+ del self.cIterator
128
+
129
+ def __iter__(self):
130
+ return self
131
+
132
+
133
+ cdef class PyArrowRowIterator(PyArrowIterator):
134
+ def __cinit__(
135
+ self,
136
+ object cursor,
137
+ object py_inputstream,
138
+ object arrow_context,
139
+ object use_dict_result,
140
+ object numpy,
141
+ object number_to_decimal,
142
+ object check_error_on_every_column,
143
+ ):
144
+ super().__init__(cursor, py_inputstream, arrow_context, use_dict_result, numpy, number_to_decimal, check_error_on_every_column)
145
+ if self.cIterator is not NULL:
146
+ return
147
+
148
+ self.cIterator = new DictCArrowChunkIterator(
149
+ <PyObject *> self.context,
150
+ self.arrow_bytes,
151
+ self.arrow_bytes_size,
152
+ <PyObject *> self.use_numpy
153
+ ) \
154
+ if self.use_dict_result \
155
+ else new CArrowChunkIterator(
156
+ <PyObject *> self.context,
157
+ self.arrow_bytes,
158
+ self.arrow_bytes_size,
159
+ <PyObject *> self.use_numpy,
160
+ <PyObject *> self.check_error_on_every_column
161
+ )
162
+ cdef ReturnVal cret = self.cIterator.checkInitializationStatus()
163
+ if cret.exception:
164
+ Error.errorhandler_wrapper(
165
+ self.cursor.connection if self.cursor is not None else None,
166
+ self.cursor,
167
+ OperationalError,
168
+ {
169
+ 'msg': f'Failed to open arrow stream: {str(<object>cret.exception)}',
170
+ 'errno': ER_FAILED_TO_READ_ARROW_STREAM
171
+ })
172
+ snow_logger.debug(msg=f"Batches read: {self.cIterator.getArrowArrayPtrs().size()}", path_name=__file__, func_name="__cinit__")
173
+
174
+ def __next__(self):
175
+ cdef ReturnVal cret = self.cIterator.next()
176
+ if not cret.successObj:
177
+ Error.errorhandler_wrapper(
178
+ self.cursor.connection if self.cursor is not None else None,
179
+ self.cursor,
180
+ InterfaceError,
181
+ {
182
+ 'msg': f'Failed to convert current row, cause: {<object>cret.exception}',
183
+ 'errno': ER_FAILED_TO_CONVERT_ROW_TO_PYTHON_TYPE
184
+ }
185
+ )
186
+ # it looks like this line can help us get into python and detect the global variable immediately
187
+ # however, this log will not show up for unclear reason
188
+ ret = <object>cret.successObj
189
+
190
+ if ret is None:
191
+ raise StopIteration
192
+ else:
193
+ return ret
194
+
195
+
196
+ cdef class PyArrowTableIterator(PyArrowIterator):
197
+ def __cinit__(
198
+ self,
199
+ object cursor,
200
+ object py_inputstream,
201
+ object arrow_context,
202
+ object use_dict_result,
203
+ object numpy,
204
+ object number_to_decimal,
205
+ object check_error_on_every_column
206
+ ):
207
+ super().__init__(cursor, py_inputstream, arrow_context, use_dict_result, numpy, number_to_decimal, check_error_on_every_column)
208
+ if not INSTALLED_PYARROW:
209
+ raise Error.errorhandler_make_exception(
210
+ ProgrammingError,
211
+ {
212
+ "msg": (
213
+ "Optional dependency: 'pyarrow' is not installed, please see the following link for install "
214
+ "instructions: https://docs.snowflake.com/en/user-guide/python-connector-pandas.html#installation"
215
+ ),
216
+ "errno": ER_NO_PYARROW,
217
+ },
218
+ )
219
+
220
+ if self.cIterator is not NULL:
221
+ return
222
+
223
+ self.cIterator = new CArrowTableIterator(
224
+ <PyObject *> self.context,
225
+ self.arrow_bytes,
226
+ self.arrow_bytes_size,
227
+ self.number_to_decimal,
228
+ )
229
+ cdef ReturnVal cret = self.cIterator.checkInitializationStatus()
230
+ if cret.exception:
231
+ Error.errorhandler_wrapper(
232
+ self.cursor.connection if self.cursor is not None else None,
233
+ self.cursor,
234
+ OperationalError,
235
+ {
236
+ 'msg': f'Failed to open arrow stream: {str(<object>cret.exception)}',
237
+ 'errno': ER_FAILED_TO_READ_ARROW_STREAM
238
+ })
239
+ cdef ReturnVal cret2 = self.cIterator.next()
240
+ self.nanoarrow_Table = self.cIterator.getArrowArrayPtrs()
241
+ self.nanoarrow_Schema = self.cIterator.getArrowSchemaPtrs()
242
+ self.pyarrow_table = pyarrow.Table.from_batches(
243
+ batches=[
244
+ pyarrow.RecordBatch._import_from_c(
245
+ self.nanoarrow_Table[i],
246
+ self.nanoarrow_Schema[i]
247
+ ) for i in range(self.nanoarrow_Table.size())
248
+ ]
249
+ )
250
+ snow_logger.debug(msg=f"Batches read: {self.nanoarrow_Table.size()}", path_name=__file__, func_name="__cinit__")
251
+
252
+ def __next__(self):
253
+ if not self.table_returned:
254
+ self.table_returned = True
255
+ return self.pyarrow_table
256
+ raise StopIteration