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,95 @@
1
+ #ifndef PC_PYTHON_COMMON_HPP
2
+ #define PC_PYTHON_COMMON_HPP
3
+
4
+ // Support for not having PY_SSIZE_T_CLEAN defined will end in Python 3.10. It
5
+ // causes
6
+ // argument parsing to not accept integers, leaving only Py_ssize_t as an
7
+ // option
8
+ #define PY_SSIZE_T_CLEAN
9
+
10
+ // We have to make sure that we import Python.h once for special flags that need
11
+ // to be
12
+ // set before importing it
13
+ #include <Python.h>
14
+
15
+ #include "Util/macros.hpp"
16
+
17
+ namespace sf {
18
+
19
+ namespace py {
20
+ inline bool checkPyError() { return UNLIKELY(PyErr_Occurred()); }
21
+
22
+ /**
23
+ * A RAII class to wrap the PyObject*. The semantics are like std::unique_ptr.
24
+ */
25
+ class UniqueRef {
26
+ public:
27
+ UniqueRef(const UniqueRef&) = delete;
28
+ UniqueRef& operator=(const UniqueRef&) = delete;
29
+
30
+ UniqueRef() : m_pyObj(nullptr) {}
31
+
32
+ explicit UniqueRef(PyObject* pyObj) : m_pyObj(pyObj) {}
33
+
34
+ UniqueRef(UniqueRef&& other) : UniqueRef(other.release()) {}
35
+
36
+ UniqueRef& operator=(UniqueRef&& other) {
37
+ reset(other.release());
38
+ return *this;
39
+ }
40
+
41
+ ~UniqueRef() { reset(); }
42
+
43
+ // Make this `UniqueRef` take ownership of the reference
44
+ // `pyObj`, if it is not null. If this `UniqueRef` previously
45
+ // owned a reference, it is released (via decrementing the
46
+ // refcount).
47
+ //
48
+ // This provides a similar guarantee as `Py_SETREF()` or
49
+ // `Py_CLEAR()`, by setting the new reference before
50
+ // decrementing the old reference.
51
+ void reset(PyObject* pyObj = nullptr) {
52
+ PyObject* toDelete = m_pyObj;
53
+ m_pyObj = pyObj;
54
+ Py_XDECREF(toDelete);
55
+ }
56
+
57
+ PyObject* release() noexcept {
58
+ PyObject* tmp = m_pyObj;
59
+ m_pyObj = nullptr;
60
+ return tmp;
61
+ }
62
+
63
+ PyObject* get() const noexcept { return m_pyObj; }
64
+
65
+ bool empty() const noexcept { return m_pyObj == nullptr; }
66
+
67
+ private:
68
+ PyObject* m_pyObj;
69
+ };
70
+
71
+ /**
72
+ * A RAII class to help us acquire the python GIL. The semantics are like
73
+ * std::unique_lock.
74
+ * We have to acquire the python GIL every time we call a Python/C API to ensure
75
+ * there is only one python thread running all the time.
76
+ */
77
+ class PyUniqueLock {
78
+ public:
79
+ PyUniqueLock(const PyUniqueLock&) = delete;
80
+ PyUniqueLock& operator=(const PyUniqueLock&) = delete;
81
+ PyUniqueLock(PyUniqueLock&&) = delete;
82
+ PyUniqueLock& operator=(PyUniqueLock&&) = delete;
83
+
84
+ PyUniqueLock() { m_state = PyGILState_Ensure(); }
85
+
86
+ ~PyUniqueLock() { PyGILState_Release(m_state); }
87
+
88
+ private:
89
+ PyGILState_STATE m_state;
90
+ };
91
+
92
+ } // namespace py
93
+ } // namespace sf
94
+
95
+ #endif // PC_PYTHON_COMMON_HPP
@@ -0,0 +1,57 @@
1
+ #include "Helpers.hpp"
2
+
3
+ #include <string>
4
+
5
+ #include "Common.hpp"
6
+
7
+ namespace sf {
8
+
9
+ namespace py {
10
+
11
+ using Logger = ::sf::Logger;
12
+
13
+ void importPythonModule(const std::string& moduleName, UniqueRef& ref) {
14
+ PyObject* module = PyImport_ImportModule(moduleName.c_str());
15
+ if (checkPyError()) {
16
+ return;
17
+ }
18
+ ref.reset(module);
19
+ return;
20
+ }
21
+
22
+ void importPythonModule(const std::string& moduleName, UniqueRef& ref,
23
+ Logger& logger) {
24
+ PyObject* module = PyImport_ImportModule(moduleName.c_str());
25
+ if (checkPyError()) {
26
+ logger.error(__FILE__, __func__, __LINE__,
27
+ "import python module '%s' failed", moduleName.c_str());
28
+ return;
29
+ }
30
+ ref.reset(module);
31
+ return;
32
+ }
33
+
34
+ void importFromModule(const UniqueRef& moduleRef, const std::string& name,
35
+ UniqueRef& ref) {
36
+ PyObject* attr = PyObject_GetAttrString(moduleRef.get(), name.c_str());
37
+ if (checkPyError()) {
38
+ return;
39
+ }
40
+ ref.reset(attr);
41
+ return;
42
+ }
43
+
44
+ void importFromModule(const UniqueRef& moduleRef, const std::string& name,
45
+ UniqueRef& ref, Logger& logger) {
46
+ PyObject* attr = PyObject_GetAttrString(moduleRef.get(), name.c_str());
47
+ if (checkPyError()) {
48
+ logger.error(__FILE__, __func__, __LINE__,
49
+ "import python attribute '%s' failed", name.c_str());
50
+ return;
51
+ }
52
+ ref.reset(attr);
53
+ return;
54
+ }
55
+
56
+ } // namespace py
57
+ } // namespace sf
@@ -0,0 +1,36 @@
1
+ #ifndef PC_PYTHON_HELPERS_HPP
2
+ #define PC_PYTHON_HELPERS_HPP
3
+
4
+ #include <string>
5
+
6
+ #include "logging.hpp"
7
+
8
+ namespace sf {
9
+
10
+ namespace py {
11
+
12
+ class UniqueRef;
13
+
14
+ using Logger = ::sf::Logger;
15
+
16
+ /**
17
+ * \brief: import a python module
18
+ * \param moduleName: the name of the python module
19
+ * \param ref: the RAII object to manage the PyObject
20
+ * \return:
21
+ */
22
+ void importPythonModule(const std::string& moduleName, UniqueRef& ref);
23
+
24
+ void importPythonModule(const std::string& moduleName, UniqueRef& ref,
25
+ const Logger& logger);
26
+
27
+ void importFromModule(const UniqueRef& moduleRef, const std::string& name,
28
+ UniqueRef& ref);
29
+
30
+ void importFromModule(const UniqueRef& moduleRef, const std::string& name,
31
+ UniqueRef& ref, const Logger& logger);
32
+
33
+ } // namespace py
34
+ } // namespace sf
35
+
36
+ #endif // PC_PYTHON_HELPERS_HPP
@@ -0,0 +1,34 @@
1
+ #include "SnowflakeType.hpp"
2
+
3
+ namespace sf {
4
+
5
+ std::unordered_map<std::string, SnowflakeType::Type>
6
+ SnowflakeType::m_strEnumIndex = {
7
+ {"ANY", SnowflakeType::Type::ANY},
8
+ {"ARRAY", SnowflakeType::Type::ARRAY},
9
+ {"BINARY", SnowflakeType::Type::BINARY},
10
+ {"BOOLEAN", SnowflakeType::Type::BOOLEAN},
11
+ {"CHAR", SnowflakeType::Type::CHAR},
12
+ {"DATE", SnowflakeType::Type::DATE},
13
+ {"DOUBLE PRECISION", SnowflakeType::Type::REAL},
14
+ {"DOUBLE", SnowflakeType::Type::REAL},
15
+ {"FIXED", SnowflakeType::Type::FIXED},
16
+ {"DECFLOAT", SnowflakeType::Type::DECFLOAT},
17
+ {"FLOAT", SnowflakeType::Type::REAL},
18
+ {"INTERVAL_YEAR_MONTH", SnowflakeType::Type::INTERVAL_YEAR_MONTH},
19
+ {"INTERVAL_DAY_TIME", SnowflakeType::Type::INTERVAL_DAY_TIME},
20
+ {"MAP", SnowflakeType::Type::MAP},
21
+ {"OBJECT", SnowflakeType::Type::OBJECT},
22
+ {"REAL", SnowflakeType::Type::REAL},
23
+ {"STRING", SnowflakeType::Type::TEXT},
24
+ {"TEXT", SnowflakeType::Type::TEXT},
25
+ {"TIME", SnowflakeType::Type::TIME},
26
+ {"TIMESTAMP", SnowflakeType::Type::TIMESTAMP},
27
+ {"TIMESTAMP_LTZ", SnowflakeType::Type::TIMESTAMP_LTZ},
28
+ {"TIMESTAMP_NTZ", SnowflakeType::Type::TIMESTAMP_NTZ},
29
+ {"TIMESTAMP_TZ", SnowflakeType::Type::TIMESTAMP_TZ},
30
+ {"VARCHAR", SnowflakeType::Type::TEXT},
31
+ {"VARIANT", SnowflakeType::Type::VARIANT},
32
+ {"VECTOR", SnowflakeType::Type::VECTOR}};
33
+
34
+ } // namespace sf
@@ -0,0 +1,48 @@
1
+ #ifndef PC_SNOWFLAKETYPE_HPP
2
+ #define PC_SNOWFLAKETYPE_HPP
3
+
4
+ #include <algorithm>
5
+ #include <cstdint>
6
+ #include <string>
7
+ #include <unordered_map>
8
+
9
+ namespace sf {
10
+
11
+ class SnowflakeType {
12
+ public:
13
+ enum class Type : uint8_t {
14
+ ANY = 0,
15
+ ARRAY = 1,
16
+ BINARY = 2,
17
+ BOOLEAN = 3,
18
+ CHAR = 4,
19
+ DATE = 5,
20
+ FIXED = 6,
21
+ OBJECT = 7,
22
+ REAL = 8,
23
+ TEXT = 9,
24
+ TIME = 10,
25
+ TIMESTAMP = 11,
26
+ TIMESTAMP_LTZ = 12,
27
+ TIMESTAMP_NTZ = 13,
28
+ TIMESTAMP_TZ = 14,
29
+ VARIANT = 15,
30
+ VECTOR = 16,
31
+ MAP = 17,
32
+ DECFLOAT = 18,
33
+ INTERVAL_YEAR_MONTH = 19,
34
+ INTERVAL_DAY_TIME = 20,
35
+ };
36
+
37
+ static SnowflakeType::Type snowflakeTypeFromString(std::string str) {
38
+ std::transform(str.begin(), str.end(), str.begin(), ::toupper);
39
+ return m_strEnumIndex.at(str);
40
+ }
41
+
42
+ private:
43
+ static std::unordered_map<std::string, SnowflakeType::Type> m_strEnumIndex;
44
+ };
45
+
46
+ } // namespace sf
47
+
48
+ #endif // PC_SNOWFLAKETYPE_HPP
@@ -0,0 +1,19 @@
1
+ #include "StringConverter.hpp"
2
+
3
+ #include <memory>
4
+
5
+ namespace sf {
6
+ Logger* StringConverter::logger =
7
+ new Logger("snowflake.connector.StringConverter");
8
+
9
+ StringConverter::StringConverter(ArrowArrayView* array) : m_array(array) {}
10
+
11
+ PyObject* StringConverter::toPyObject(int64_t rowIndex) const {
12
+ if (ArrowArrayViewIsNull(m_array, rowIndex)) {
13
+ Py_RETURN_NONE;
14
+ }
15
+ ArrowStringView stringView = ArrowArrayViewGetStringUnsafe(m_array, rowIndex);
16
+ return PyUnicode_FromStringAndSize(stringView.data, stringView.size_bytes);
17
+ }
18
+
19
+ } // namespace sf
@@ -0,0 +1,26 @@
1
+ #ifndef PC_STRINGCONVERTER_HPP
2
+ #define PC_STRINGCONVERTER_HPP
3
+
4
+ #include <memory>
5
+
6
+ #include "IColumnConverter.hpp"
7
+ #include "logging.hpp"
8
+ #include "nanoarrow.h"
9
+ #include "nanoarrow.hpp"
10
+
11
+ namespace sf {
12
+
13
+ class StringConverter : public IColumnConverter {
14
+ public:
15
+ explicit StringConverter(ArrowArrayView* array);
16
+ PyObject* toPyObject(int64_t rowIndex) const override;
17
+
18
+ private:
19
+ ArrowArrayView* m_array;
20
+
21
+ static Logger* logger;
22
+ };
23
+
24
+ } // namespace sf
25
+
26
+ #endif // PC_STRINGCONVERTER_HPP
@@ -0,0 +1,36 @@
1
+ #include "TimeConverter.hpp"
2
+
3
+ namespace sf {
4
+
5
+ TimeConverter::TimeConverter(ArrowArrayView* array, int32_t scale)
6
+ : m_array(array), m_scale(scale) {}
7
+
8
+ PyObject* TimeConverter::toPyObject(int64_t rowIndex) const {
9
+ if (ArrowArrayViewIsNull(m_array, rowIndex)) {
10
+ Py_RETURN_NONE;
11
+ }
12
+
13
+ int64_t seconds = ArrowArrayViewGetIntUnsafe(m_array, rowIndex);
14
+ using namespace internal;
15
+ py::PyUniqueLock lock;
16
+ return PyObject_CallFunction(m_pyDatetimeTime().get(), "iiii",
17
+ getHourFromSeconds(seconds, m_scale),
18
+ getMinuteFromSeconds(seconds, m_scale),
19
+ getSecondFromSeconds(seconds, m_scale),
20
+ getMicrosecondFromSeconds(seconds, m_scale));
21
+ }
22
+
23
+ py::UniqueRef& TimeConverter::m_pyDatetimeTime() {
24
+ static py::UniqueRef pyDatetimeTime;
25
+ if (pyDatetimeTime.empty()) {
26
+ py::PyUniqueLock lock;
27
+ py::UniqueRef pyDatetimeModule;
28
+ py::importPythonModule("datetime", pyDatetimeModule);
29
+ /** TODO : to check status here */
30
+
31
+ py::importFromModule(pyDatetimeModule, "time", pyDatetimeTime);
32
+ }
33
+ return pyDatetimeTime;
34
+ }
35
+
36
+ } // namespace sf
@@ -0,0 +1,31 @@
1
+ #ifndef PC_TIMECONVERTER_HPP
2
+ #define PC_TIMECONVERTER_HPP
3
+
4
+ #include <memory>
5
+
6
+ #include "IColumnConverter.hpp"
7
+ #include "Python/Common.hpp"
8
+ #include "Python/Helpers.hpp"
9
+ #include "Util/time.hpp"
10
+ #include "nanoarrow.h"
11
+
12
+ namespace sf {
13
+
14
+ class TimeConverter : public IColumnConverter {
15
+ public:
16
+ explicit TimeConverter(ArrowArrayView* array, int32_t scale);
17
+
18
+ PyObject* toPyObject(int64_t rowIndex) const override;
19
+
20
+ private:
21
+ /** can be arrow::Int32Array and arrow::Int64Array */
22
+ ArrowArrayView* m_array;
23
+
24
+ int32_t m_scale;
25
+
26
+ static py::UniqueRef& m_pyDatetimeTime();
27
+ };
28
+
29
+ } // namespace sf
30
+
31
+ #endif // PC_TIMECONVERTER_HPP