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,557 @@
1
+ #include "CArrowChunkIterator.hpp"
2
+
3
+ #include <memory>
4
+ #include <string>
5
+ #include <vector>
6
+
7
+ #include "ArrayConverter.hpp"
8
+ #include "BinaryConverter.hpp"
9
+ #include "BooleanConverter.hpp"
10
+ #include "DateConverter.hpp"
11
+ #include "DecFloatConverter.hpp"
12
+ #include "DecimalConverter.hpp"
13
+ #include "FixedSizeListConverter.hpp"
14
+ #include "FloatConverter.hpp"
15
+ #include "IntConverter.hpp"
16
+ #include "IntervalConverter.hpp"
17
+ #include "MapConverter.hpp"
18
+ #include "ObjectConverter.hpp"
19
+ #include "StringConverter.hpp"
20
+ #include "TimeConverter.hpp"
21
+ #include "TimeStampConverter.hpp"
22
+
23
+ namespace sf {
24
+
25
+ CArrowChunkIterator::CArrowChunkIterator(PyObject* context, char* arrow_bytes,
26
+ int64_t arrow_bytes_size,
27
+ PyObject* use_numpy,
28
+ PyObject* check_error_on_every_column)
29
+ : CArrowIterator(arrow_bytes, arrow_bytes_size),
30
+ m_latestReturnedRow(nullptr),
31
+ m_context(context) {
32
+ if (py::checkPyError()) {
33
+ return;
34
+ }
35
+ m_currentBatchIndex = -1;
36
+ m_rowIndexInBatch = -1;
37
+ m_rowCountInBatch = 0;
38
+ m_latestReturnedRow.reset();
39
+ m_useNumpy = PyObject_IsTrue(use_numpy);
40
+ m_checkErrorOnEveryColumn = PyObject_IsTrue(check_error_on_every_column);
41
+
42
+ m_batchCount = m_ipcArrowArrayVec.size();
43
+ m_columnCount = m_batchCount > 0 ? m_ipcArrowSchema->n_children : 0;
44
+
45
+ logger->debug(
46
+ __FILE__, __func__, __LINE__,
47
+ "Arrow chunk info: batchCount %d, columnCount %d, use_numpy: %d",
48
+ m_batchCount, m_columnCount, m_useNumpy);
49
+ }
50
+
51
+ ReturnVal CArrowChunkIterator::next() {
52
+ m_rowIndexInBatch++;
53
+
54
+ if (m_rowIndexInBatch < m_rowCountInBatch) {
55
+ this->createRowPyObject();
56
+ SF_CHECK_PYTHON_ERR()
57
+ return ReturnVal(m_latestReturnedRow.get(), nullptr);
58
+ } else {
59
+ // the initialization took place in CArrowIterator constructor in which
60
+ // function we can not raise error but we can set error , we check here to
61
+ // see if error occurred during initialization
62
+ SF_CHECK_PYTHON_ERR();
63
+ m_currentBatchIndex++;
64
+ if (m_currentBatchIndex < m_batchCount) {
65
+ m_rowIndexInBatch = 0;
66
+ m_rowCountInBatch = m_ipcArrowArrayVec[m_currentBatchIndex]->length;
67
+ this->initColumnConverters();
68
+ SF_CHECK_PYTHON_ERR()
69
+
70
+ logger->debug(__FILE__, __func__, __LINE__,
71
+ "Current batch index: %d, rows in current batch: %d",
72
+ m_currentBatchIndex, m_rowCountInBatch);
73
+
74
+ this->createRowPyObject();
75
+ SF_CHECK_PYTHON_ERR()
76
+
77
+ return ReturnVal(m_latestReturnedRow.get(), nullptr);
78
+ }
79
+ }
80
+
81
+ /** It looks like no one will decrease the ref of this Py_None, so we don't
82
+ * increment the ref count here */
83
+ return ReturnVal(Py_None, nullptr);
84
+ }
85
+
86
+ void CArrowChunkIterator::createRowPyObject() {
87
+ m_latestReturnedRow.reset(PyTuple_New(m_columnCount));
88
+ for (int i = 0; i < m_columnCount; i++) {
89
+ // PyTuple_SET_ITEM steals a reference to the PyObject returned by
90
+ // toPyObject below
91
+ PyTuple_SET_ITEM(
92
+ m_latestReturnedRow.get(), i,
93
+ m_currentBatchConverters[i]->toPyObject(m_rowIndexInBatch));
94
+ if (m_checkErrorOnEveryColumn && py::checkPyError()) {
95
+ return;
96
+ }
97
+ }
98
+ return;
99
+ }
100
+
101
+ std::shared_ptr<sf::IColumnConverter> getConverterFromSchema(
102
+ ArrowSchema* schema, ArrowArrayView* array, PyObject* context,
103
+ bool useNumpy, Logger* logger) {
104
+ std::shared_ptr<sf::IColumnConverter> converter = nullptr;
105
+ ArrowSchemaView schemaView;
106
+ ArrowError error;
107
+ int returnCode = 0;
108
+
109
+ returnCode = ArrowSchemaViewInit(&schemaView, schema, &error);
110
+ SF_CHECK_ARROW_RC_AND_RETURN(returnCode, nullptr,
111
+ "[Snowflake Exception] error initializing "
112
+ "ArrowSchemaView: %s, error code: %d",
113
+ ArrowErrorMessage(&error), returnCode);
114
+
115
+ struct ArrowStringView snowflakeLogicalType = ArrowCharView(nullptr);
116
+ const char* metadata = schema->metadata;
117
+ returnCode = ArrowMetadataGetValue(metadata, ArrowCharView("logicalType"),
118
+ &snowflakeLogicalType);
119
+
120
+ SF_CHECK_ARROW_RC_AND_RETURN(
121
+ returnCode, nullptr,
122
+ "[Snowflake Exception] error getting 'logicalType' from "
123
+ "Arrow metadata, error code: %d",
124
+ returnCode);
125
+
126
+ SnowflakeType::Type st = SnowflakeType::snowflakeTypeFromString(
127
+ std::string(snowflakeLogicalType.data, snowflakeLogicalType.size_bytes));
128
+
129
+ switch (st) {
130
+ case SnowflakeType::Type::FIXED: {
131
+ struct ArrowStringView scaleString = ArrowCharView(nullptr);
132
+ struct ArrowStringView precisionString = ArrowCharView(nullptr);
133
+ int scale = 0;
134
+ int precision = 38;
135
+ if (metadata != nullptr) {
136
+ returnCode = ArrowMetadataGetValue(metadata, ArrowCharView("scale"),
137
+ &scaleString);
138
+ SF_CHECK_ARROW_RC_AND_RETURN(
139
+ returnCode, nullptr,
140
+ "[Snowflake Exception] error getting 'scale' from "
141
+ "Arrow metadata, error code: %d",
142
+ returnCode);
143
+ returnCode = ArrowMetadataGetValue(metadata, ArrowCharView("precision"),
144
+ &precisionString);
145
+ SF_CHECK_ARROW_RC_AND_RETURN(
146
+ returnCode, nullptr,
147
+ "[Snowflake Exception] error getting 'precision' "
148
+ "from Arrow metadata, error code: %d",
149
+ returnCode);
150
+ scale =
151
+ std::stoi(std::string(scaleString.data, scaleString.size_bytes));
152
+ precision = std::stoi(
153
+ std::string(precisionString.data, precisionString.size_bytes));
154
+ }
155
+
156
+ switch (schemaView.type) {
157
+ #define _SF_INIT_FIXED_CONVERTER(ARROW_TYPE) \
158
+ case ArrowType::ARROW_TYPE: { \
159
+ if (scale > 0) { \
160
+ if (useNumpy) { \
161
+ converter = std::make_shared<sf::NumpyDecimalConverter>( \
162
+ array, precision, scale, context); \
163
+ } else { \
164
+ converter = std::make_shared<sf::DecimalFromIntConverter>( \
165
+ array, precision, scale); \
166
+ } \
167
+ } else { \
168
+ if (useNumpy) { \
169
+ converter = std::make_shared<sf::NumpyIntConverter>(array, context); \
170
+ } else { \
171
+ converter = std::make_shared<sf::IntConverter>(array); \
172
+ } \
173
+ } \
174
+ break; \
175
+ }
176
+ _SF_INIT_FIXED_CONVERTER(NANOARROW_TYPE_INT8)
177
+ _SF_INIT_FIXED_CONVERTER(NANOARROW_TYPE_INT16)
178
+ _SF_INIT_FIXED_CONVERTER(NANOARROW_TYPE_INT32)
179
+ _SF_INIT_FIXED_CONVERTER(NANOARROW_TYPE_INT64)
180
+ #undef _SF_INIT_FIXED_CONVERTER
181
+
182
+ case ArrowType::NANOARROW_TYPE_DECIMAL128: {
183
+ converter = std::make_shared<sf::DecimalFromDecimalConverter>(
184
+ context, array, scale);
185
+ break;
186
+ }
187
+
188
+ default: {
189
+ std::string errorInfo = Logger::formatString(
190
+ "[Snowflake Exception] unknown arrow internal data type(%d) "
191
+ "for FIXED data",
192
+ NANOARROW_TYPE_ENUM_STRING[schemaView.type]);
193
+ logger->error(__FILE__, __func__, __LINE__, errorInfo.c_str());
194
+ PyErr_SetString(PyExc_Exception, errorInfo.c_str());
195
+ break;
196
+ }
197
+ }
198
+ break;
199
+ }
200
+
201
+ case SnowflakeType::Type::ANY:
202
+ case SnowflakeType::Type::CHAR:
203
+ case SnowflakeType::Type::TEXT:
204
+ case SnowflakeType::Type::VARIANT: {
205
+ converter = std::make_shared<sf::StringConverter>(array);
206
+ break;
207
+ }
208
+
209
+ case SnowflakeType::Type::BOOLEAN: {
210
+ converter = std::make_shared<sf::BooleanConverter>(array);
211
+ break;
212
+ }
213
+
214
+ case SnowflakeType::Type::REAL: {
215
+ if (useNumpy) {
216
+ converter = std::make_shared<sf::NumpyFloat64Converter>(array, context);
217
+ } else {
218
+ converter = std::make_shared<sf::FloatConverter>(array);
219
+ }
220
+ break;
221
+ }
222
+
223
+ case SnowflakeType::Type::DATE: {
224
+ if (useNumpy) {
225
+ converter = std::make_shared<sf::NumpyDateConverter>(array, context);
226
+ } else {
227
+ converter = std::make_shared<sf::DateConverter>(array);
228
+ }
229
+ break;
230
+ }
231
+
232
+ case SnowflakeType::Type::BINARY: {
233
+ converter = std::make_shared<sf::BinaryConverter>(array);
234
+ break;
235
+ }
236
+
237
+ case SnowflakeType::Type::TIME: {
238
+ int scale = 9;
239
+ if (metadata != nullptr) {
240
+ struct ArrowStringView scaleString = ArrowCharView(nullptr);
241
+ returnCode = ArrowMetadataGetValue(metadata, ArrowCharView("scale"),
242
+ &scaleString);
243
+ SF_CHECK_ARROW_RC_AND_RETURN(
244
+ returnCode, nullptr,
245
+ "[Snowflake Exception] error getting 'scale' from "
246
+ "Arrow metadata, error code: %d",
247
+ returnCode);
248
+ scale =
249
+ std::stoi(std::string(scaleString.data, scaleString.size_bytes));
250
+ }
251
+ switch (schemaView.type) {
252
+ case NANOARROW_TYPE_INT32:
253
+ case NANOARROW_TYPE_INT64: {
254
+ converter = std::make_shared<sf::TimeConverter>(array, scale);
255
+ break;
256
+ }
257
+
258
+ default: {
259
+ std::string errorInfo = Logger::formatString(
260
+ "[Snowflake Exception] unknown arrow internal data type(%d) "
261
+ "for TIME data",
262
+ NANOARROW_TYPE_ENUM_STRING[schemaView.type]);
263
+ logger->error(__FILE__, __func__, __LINE__, errorInfo.c_str());
264
+ PyErr_SetString(PyExc_Exception, errorInfo.c_str());
265
+ return nullptr;
266
+ }
267
+ }
268
+ break;
269
+ }
270
+
271
+ case SnowflakeType::Type::TIMESTAMP_NTZ: {
272
+ int scale = 9;
273
+ if (metadata != nullptr) {
274
+ struct ArrowStringView scaleString = ArrowCharView(nullptr);
275
+ returnCode = ArrowMetadataGetValue(metadata, ArrowCharView("scale"),
276
+ &scaleString);
277
+ SF_CHECK_ARROW_RC_AND_RETURN(
278
+ returnCode, nullptr,
279
+ "[Snowflake Exception] error getting 'scale' from "
280
+ "Arrow metadata, error code: %d",
281
+ returnCode);
282
+ scale =
283
+ std::stoi(std::string(scaleString.data, scaleString.size_bytes));
284
+ }
285
+ switch (schemaView.type) {
286
+ case NANOARROW_TYPE_INT64: {
287
+ if (useNumpy) {
288
+ converter =
289
+ std::make_shared<sf::NumpyOneFieldTimeStampNTZConverter>(
290
+ array, scale, context);
291
+ } else {
292
+ converter = std::make_shared<sf::OneFieldTimeStampNTZConverter>(
293
+ array, scale, context);
294
+ }
295
+ break;
296
+ }
297
+
298
+ case NANOARROW_TYPE_STRUCT: {
299
+ if (useNumpy) {
300
+ converter =
301
+ std::make_shared<sf::NumpyTwoFieldTimeStampNTZConverter>(
302
+ array, &schemaView, scale, context);
303
+ } else {
304
+ converter = std::make_shared<sf::TwoFieldTimeStampNTZConverter>(
305
+ array, &schemaView, scale, context);
306
+ }
307
+ break;
308
+ }
309
+
310
+ default: {
311
+ std::string errorInfo = Logger::formatString(
312
+ "[Snowflake Exception] unknown arrow internal data type(%d) "
313
+ "for TIMESTAMP_NTZ data",
314
+ NANOARROW_TYPE_ENUM_STRING[schemaView.type]);
315
+ logger->error(__FILE__, __func__, __LINE__, errorInfo.c_str());
316
+ PyErr_SetString(PyExc_Exception, errorInfo.c_str());
317
+ break;
318
+ }
319
+ }
320
+ break;
321
+ }
322
+
323
+ case SnowflakeType::Type::TIMESTAMP_LTZ: {
324
+ int scale = 9;
325
+ if (metadata != nullptr) {
326
+ struct ArrowStringView scaleString = ArrowCharView(nullptr);
327
+ returnCode = ArrowMetadataGetValue(metadata, ArrowCharView("scale"),
328
+ &scaleString);
329
+ SF_CHECK_ARROW_RC_AND_RETURN(
330
+ returnCode, nullptr,
331
+ "[Snowflake Exception] error getting 'scale' from "
332
+ "Arrow metadata, error code: %d",
333
+ returnCode);
334
+ scale =
335
+ std::stoi(std::string(scaleString.data, scaleString.size_bytes));
336
+ }
337
+ switch (schemaView.type) {
338
+ case NANOARROW_TYPE_INT64: {
339
+ converter = std::make_shared<sf::OneFieldTimeStampLTZConverter>(
340
+ array, scale, context);
341
+ break;
342
+ }
343
+
344
+ case NANOARROW_TYPE_STRUCT: {
345
+ converter = std::make_shared<sf::TwoFieldTimeStampLTZConverter>(
346
+ array, &schemaView, scale, context);
347
+ break;
348
+ }
349
+
350
+ default: {
351
+ std::string errorInfo = Logger::formatString(
352
+ "[Snowflake Exception] unknown arrow internal data type(%d) "
353
+ "for TIMESTAMP_LTZ data",
354
+ NANOARROW_TYPE_ENUM_STRING[schemaView.type]);
355
+ logger->error(__FILE__, __func__, __LINE__, errorInfo.c_str());
356
+ PyErr_SetString(PyExc_Exception, errorInfo.c_str());
357
+ break;
358
+ }
359
+ }
360
+ break;
361
+ }
362
+
363
+ case SnowflakeType::Type::TIMESTAMP_TZ: {
364
+ struct ArrowStringView scaleString = ArrowCharView(nullptr);
365
+ struct ArrowStringView byteLengthString = ArrowCharView(nullptr);
366
+ int scale = 9;
367
+ int byteLength = 16;
368
+ if (metadata != nullptr) {
369
+ returnCode = ArrowMetadataGetValue(metadata, ArrowCharView("scale"),
370
+ &scaleString);
371
+ SF_CHECK_ARROW_RC_AND_RETURN(
372
+ returnCode, nullptr,
373
+ "[Snowflake Exception] error getting 'scale' from "
374
+ "Arrow metadata, error code: %d",
375
+ returnCode);
376
+ returnCode = ArrowMetadataGetValue(
377
+ metadata, ArrowCharView("byteLength"), &byteLengthString);
378
+ SF_CHECK_ARROW_RC_AND_RETURN(
379
+ returnCode, nullptr,
380
+ "[Snowflake Exception] error getting 'byteLength' "
381
+ "from Arrow metadata, error code: %d",
382
+ returnCode);
383
+ scale =
384
+ std::stoi(std::string(scaleString.data, scaleString.size_bytes));
385
+
386
+ // Byte Length may be unset if TIMESTAMP_TZ is the child of a structured
387
+ // type In this case rely on the default value.
388
+ if (byteLengthString.data != nullptr) {
389
+ byteLength = std::stoi(
390
+ std::string(byteLengthString.data, byteLengthString.size_bytes));
391
+ }
392
+ }
393
+ switch (byteLength) {
394
+ case 8: {
395
+ converter = std::make_shared<sf::TwoFieldTimeStampTZConverter>(
396
+ array, &schemaView, scale, context);
397
+ break;
398
+ }
399
+
400
+ case 16: {
401
+ converter = std::make_shared<sf::ThreeFieldTimeStampTZConverter>(
402
+ array, &schemaView, scale, context);
403
+ break;
404
+ }
405
+
406
+ default: {
407
+ std::string errorInfo = Logger::formatString(
408
+ "[Snowflake Exception] unknown arrow internal data type(%d) "
409
+ "for TIMESTAMP_TZ data",
410
+ NANOARROW_TYPE_ENUM_STRING[schemaView.type]);
411
+ logger->error(__FILE__, __func__, __LINE__, errorInfo.c_str());
412
+ PyErr_SetString(PyExc_Exception, errorInfo.c_str());
413
+ break;
414
+ }
415
+ }
416
+
417
+ break;
418
+ }
419
+
420
+ case SnowflakeType::Type::ARRAY: {
421
+ switch (schemaView.type) {
422
+ case NANOARROW_TYPE_STRING:
423
+ converter = std::make_shared<sf::StringConverter>(array);
424
+ break;
425
+ case NANOARROW_TYPE_LIST:
426
+ converter = std::make_shared<sf::ArrayConverter>(&schemaView, array,
427
+ context, useNumpy);
428
+ break;
429
+ default: {
430
+ std::string errorInfo = Logger::formatString(
431
+ "[Snowflake Exception] unknown arrow internal data type(%d) "
432
+ "for ARRAY data in %s",
433
+ NANOARROW_TYPE_ENUM_STRING[schemaView.type],
434
+ schemaView.schema->name);
435
+ logger->error(__FILE__, __func__, __LINE__, errorInfo.c_str());
436
+ PyErr_SetString(PyExc_Exception, errorInfo.c_str());
437
+ break;
438
+ }
439
+ }
440
+ break;
441
+ }
442
+
443
+ case SnowflakeType::Type::MAP: {
444
+ converter = std::make_shared<sf::MapConverter>(&schemaView, array,
445
+ context, useNumpy);
446
+ break;
447
+ }
448
+
449
+ case SnowflakeType::Type::OBJECT: {
450
+ switch (schemaView.type) {
451
+ case NANOARROW_TYPE_STRING:
452
+ converter = std::make_shared<sf::StringConverter>(array);
453
+ break;
454
+ case NANOARROW_TYPE_STRUCT:
455
+ converter = std::make_shared<sf::ObjectConverter>(&schemaView, array,
456
+ context, useNumpy);
457
+ break;
458
+ default: {
459
+ std::string errorInfo = Logger::formatString(
460
+ "[Snowflake Exception] unknown arrow internal data type(%d) "
461
+ "for OBJECT data in %s",
462
+ NANOARROW_TYPE_ENUM_STRING[schemaView.type],
463
+ schemaView.schema->name);
464
+ logger->error(__FILE__, __func__, __LINE__, errorInfo.c_str());
465
+ PyErr_SetString(PyExc_Exception, errorInfo.c_str());
466
+ break;
467
+ }
468
+ }
469
+ break;
470
+ }
471
+
472
+ case SnowflakeType::Type::VECTOR: {
473
+ converter = std::make_shared<sf::FixedSizeListConverter>(array);
474
+ break;
475
+ }
476
+
477
+ case SnowflakeType::Type::DECFLOAT: {
478
+ converter = std::make_shared<sf::DecFloatConverter>(*array, schemaView,
479
+ *context, useNumpy);
480
+ break;
481
+ }
482
+
483
+ case SnowflakeType::Type::INTERVAL_YEAR_MONTH: {
484
+ converter = std::make_shared<sf::IntervalYearMonthConverter>(
485
+ array, context, useNumpy);
486
+ break;
487
+ }
488
+
489
+ case SnowflakeType::Type::INTERVAL_DAY_TIME: {
490
+ switch (schemaView.type) {
491
+ case NANOARROW_TYPE_INT64:
492
+ converter = std::make_shared<sf::IntervalDayTimeConverterInt>(
493
+ array, context, useNumpy);
494
+ break;
495
+ case NANOARROW_TYPE_DECIMAL128:
496
+ converter = std::make_shared<sf::IntervalDayTimeConverterDecimal>(
497
+ array, context, useNumpy);
498
+ break;
499
+ default: {
500
+ std::string errorInfo = Logger::formatString(
501
+ "[Snowflake Exception] unknown arrow internal data type(%d) "
502
+ "for OBJECT data in %s",
503
+ NANOARROW_TYPE_ENUM_STRING[schemaView.type],
504
+ schemaView.schema->name);
505
+ logger->error(__FILE__, __func__, __LINE__, errorInfo.c_str());
506
+ PyErr_SetString(PyExc_Exception, errorInfo.c_str());
507
+ break;
508
+ }
509
+ }
510
+ break;
511
+ }
512
+
513
+ default: {
514
+ std::string errorInfo = Logger::formatString(
515
+ "[Snowflake Exception] unknown snowflake data type : %d", st);
516
+ logger->error(__FILE__, __func__, __LINE__, errorInfo.c_str());
517
+ PyErr_SetString(PyExc_Exception, errorInfo.c_str());
518
+ break;
519
+ }
520
+ }
521
+ return converter;
522
+ }
523
+
524
+ void CArrowChunkIterator::initColumnConverters() {
525
+ m_currentBatchConverters.clear();
526
+
527
+ for (int i = 0; i < m_ipcArrowSchema->n_children; i++) {
528
+ ArrowSchema* columnSchema = m_ipcArrowSchema->children[i];
529
+ ArrowArrayView* array =
530
+ m_ipcArrowArrayViewVec[m_currentBatchIndex]->children[i];
531
+ m_currentBatchConverters.push_back(getConverterFromSchema(
532
+ columnSchema, array, m_context, m_useNumpy, logger));
533
+ }
534
+ }
535
+
536
+ DictCArrowChunkIterator::DictCArrowChunkIterator(PyObject* context,
537
+ char* arrow_bytes,
538
+ int64_t arrow_bytes_size,
539
+ PyObject* use_numpy)
540
+ : CArrowChunkIterator(context, arrow_bytes, arrow_bytes_size, use_numpy,
541
+ Py_False) {}
542
+
543
+ void DictCArrowChunkIterator::createRowPyObject() {
544
+ m_latestReturnedRow.reset(PyDict_New());
545
+ for (int i = 0; i < m_ipcArrowSchema->n_children; i++) {
546
+ py::UniqueRef value(
547
+ m_currentBatchConverters[i]->toPyObject(m_rowIndexInBatch));
548
+ if (!value.empty()) {
549
+ // PyDict_SetItemString doesn't steal a reference to value.get().
550
+ PyDict_SetItemString(m_latestReturnedRow.get(),
551
+ m_ipcArrowSchema->children[i]->name, value.get());
552
+ }
553
+ }
554
+ return;
555
+ }
556
+
557
+ } // namespace sf
@@ -0,0 +1,98 @@
1
+ #ifndef PC_ARROWCHUNKITERATOR_HPP
2
+ #define PC_ARROWCHUNKITERATOR_HPP
3
+
4
+ #include <memory>
5
+ #include <vector>
6
+
7
+ #include "CArrowIterator.hpp"
8
+ #include "IColumnConverter.hpp"
9
+ #include "Python/Common.hpp"
10
+ #include "SnowflakeType.hpp"
11
+ #include "logging.hpp"
12
+ #include "nanoarrow.h"
13
+ #include "nanoarrow.hpp"
14
+
15
+ namespace sf {
16
+
17
+ std::shared_ptr<sf::IColumnConverter> getConverterFromSchema(
18
+ ArrowSchema* schema, ArrowArrayView* array, PyObject* context,
19
+ bool useNumpy, Logger* logger);
20
+
21
+ /**
22
+ * Arrow chunk iterator implementation in C++. The caller (python arrow chunk
23
+ * iterator object)
24
+ * will ask for nextRow to be returned back to Python
25
+ */
26
+ class CArrowChunkIterator : public CArrowIterator {
27
+ public:
28
+ /**
29
+ * Constructor
30
+ */
31
+ CArrowChunkIterator(PyObject* context, char* arrow_bytes,
32
+ int64_t arrow_bytes_size, PyObject* use_numpy,
33
+ PyObject* check_error_on_every_column);
34
+
35
+ /**
36
+ * Destructor
37
+ */
38
+ virtual ~CArrowChunkIterator() = default;
39
+
40
+ /**
41
+ * @return a python tuple object which contains all data in current row
42
+ */
43
+ ReturnVal next() override;
44
+
45
+ protected:
46
+ /**
47
+ * @return python object of tuple which is tuple of all row values
48
+ */
49
+ virtual void createRowPyObject();
50
+
51
+ /** pointer to the latest returned python tuple(row) result */
52
+ py::UniqueRef m_latestReturnedRow;
53
+
54
+ /** list of column converters*/
55
+ std::vector<std::shared_ptr<sf::IColumnConverter>> m_currentBatchConverters;
56
+ /** row index inside current record batch (start from 0) */
57
+ int m_rowIndexInBatch;
58
+
59
+ private:
60
+ /** number of columns */
61
+ int m_columnCount;
62
+
63
+ /** number of record batch in current chunk */
64
+ int m_batchCount;
65
+
66
+ /** current index that iterator points to */
67
+ int m_currentBatchIndex;
68
+
69
+ /** total number of rows inside current record batch */
70
+ int64_t m_rowCountInBatch;
71
+
72
+ /** arrow format convert context for the current session */
73
+ PyObject* m_context;
74
+
75
+ /** true if return numpy int64 float64 datetime*/
76
+ bool m_useNumpy;
77
+
78
+ /** a flag that ensures running py::checkPyError after each column processing
79
+ * in order to fail early on first python processing error */
80
+ bool m_checkErrorOnEveryColumn;
81
+
82
+ void initColumnConverters();
83
+ };
84
+
85
+ class DictCArrowChunkIterator : public CArrowChunkIterator {
86
+ public:
87
+ DictCArrowChunkIterator(PyObject* context, char* arrow_bytes,
88
+ int64_t arrow_bytes_size, PyObject* use_numpy);
89
+
90
+ ~DictCArrowChunkIterator() = default;
91
+
92
+ private:
93
+ void createRowPyObject() override;
94
+ };
95
+
96
+ } // namespace sf
97
+
98
+ #endif // PC_ARROWCHUNKITERATOR_HPP