snowflake-connector-python 5.2.0__cp315-cp315-win_amd64.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (204) hide show
  1. snowflake/connector/__init__.py +148 -0
  2. snowflake/connector/_common/__init__.py +0 -0
  3. snowflake/connector/_common/extras.py +134 -0
  4. snowflake/connector/_common/telemetry.py +221 -0
  5. snowflake/connector/_common/wif_util.py +92 -0
  6. snowflake/connector/_core/sf_core_python.cp315-win_amd64.pyd +0 -0
  7. snowflake/connector/_core/sf_core_python.pyi +79 -0
  8. snowflake/connector/_internal/__init__.py +6 -0
  9. snowflake/connector/_internal/_private_key_helper.py +31 -0
  10. snowflake/connector/_internal/api_client/__init__.py +93 -0
  11. snowflake/connector/_internal/api_client/bridge.py +41 -0
  12. snowflake/connector/_internal/api_client/client_api.py +976 -0
  13. snowflake/connector/_internal/arrow.py +47 -0
  14. snowflake/connector/_internal/arrow_context.py +240 -0
  15. snowflake/connector/_internal/arrow_stream_async.py +266 -0
  16. snowflake/connector/_internal/arrow_stream_iterator.cp311-win_amd64.pyd +0 -0
  17. snowflake/connector/_internal/arrow_stream_iterator.cp312-win_amd64.pyd +0 -0
  18. snowflake/connector/_internal/arrow_stream_iterator.cp313-win_amd64.pyd +0 -0
  19. snowflake/connector/_internal/arrow_stream_iterator.cp314-win_amd64.pyd +0 -0
  20. snowflake/connector/_internal/arrow_stream_iterator.cp314t-win_amd64.pyd +0 -0
  21. snowflake/connector/_internal/arrow_stream_iterator.cp315-win_amd64.pyd +0 -0
  22. snowflake/connector/_internal/arrow_stream_iterator.pyi +42 -0
  23. snowflake/connector/_internal/arrow_stream_utils.py +171 -0
  24. snowflake/connector/_internal/authenticator_type.py +53 -0
  25. snowflake/connector/_internal/backward_compatibility.py +245 -0
  26. snowflake/connector/_internal/binding_converters.py +741 -0
  27. snowflake/connector/_internal/config_utils.py +71 -0
  28. snowflake/connector/_internal/connection/__init__.py +39 -0
  29. snowflake/connector/_internal/connection/connection.py +616 -0
  30. snowflake/connector/_internal/connection/connection_types.py +13 -0
  31. snowflake/connector/_internal/connection/constants.py +25 -0
  32. snowflake/connector/_internal/connection/decorators.py +31 -0
  33. snowflake/connector/_internal/connection/freezable_proxy.py +104 -0
  34. snowflake/connector/_internal/connection/queries.py +10 -0
  35. snowflake/connector/_internal/connection_config_mixin.py +755 -0
  36. snowflake/connector/_internal/cursor/__init__.py +25 -0
  37. snowflake/connector/_internal/cursor/base.py +732 -0
  38. snowflake/connector/_internal/cursor/cursor_types.py +13 -0
  39. snowflake/connector/_internal/cursor/decorators.py +56 -0
  40. snowflake/connector/_internal/cursor/query_result.py +202 -0
  41. snowflake/connector/_internal/cursor/query_result_waiter.py +98 -0
  42. snowflake/connector/_internal/cursor/result_metadata.py +255 -0
  43. snowflake/connector/_internal/cursor/result_set_wrapper.py +66 -0
  44. snowflake/connector/_internal/decorators.py +539 -0
  45. snowflake/connector/_internal/error_kinds.py +111 -0
  46. snowflake/connector/_internal/errorcode.py +35 -0
  47. snowflake/connector/_internal/errorhandler.py +278 -0
  48. snowflake/connector/_internal/fips.py +28 -0
  49. snowflake/connector/_internal/logging/__init__.py +52 -0
  50. snowflake/connector/_internal/logging/config.py +134 -0
  51. snowflake/connector/_internal/logging/core_logger.py +218 -0
  52. snowflake/connector/_internal/logging/native_extension_logger.py +144 -0
  53. snowflake/connector/_internal/logout_config_mapping.py +187 -0
  54. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/ArrayConverter.cpp +57 -0
  55. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/ArrayConverter.hpp +29 -0
  56. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/ArrowTableConverter.cpp +943 -0
  57. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/ArrowTableConverter.hpp +63 -0
  58. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/BinaryConverter.cpp +18 -0
  59. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/BinaryConverter.hpp +26 -0
  60. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/BooleanConverter.cpp +21 -0
  61. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/BooleanConverter.hpp +23 -0
  62. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/CArrowIterator.cpp +118 -0
  63. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/CArrowIterator.hpp +116 -0
  64. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/CArrowStreamIterator.cpp +323 -0
  65. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/CArrowStreamIterator.hpp +133 -0
  66. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/CArrowStreamTableIterator.cpp +275 -0
  67. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/CArrowStreamTableIterator.hpp +168 -0
  68. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/ConverterUtil.cpp +439 -0
  69. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/ConverterUtil.hpp +30 -0
  70. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/DateConverter.cpp +48 -0
  71. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/DateConverter.hpp +46 -0
  72. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/DecFloatConverter.cpp +76 -0
  73. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/DecFloatConverter.hpp +35 -0
  74. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/DecimalConverter.cpp +90 -0
  75. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/DecimalConverter.hpp +63 -0
  76. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/FixedSizeListConverter.cpp +62 -0
  77. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/FixedSizeListConverter.hpp +28 -0
  78. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/FloatConverter.cpp +29 -0
  79. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/FloatConverter.hpp +35 -0
  80. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/IColumnConverter.hpp +17 -0
  81. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/IntConverter.cpp +23 -0
  82. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/IntConverter.hpp +41 -0
  83. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/IntervalConverter.cpp +65 -0
  84. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/IntervalConverter.hpp +54 -0
  85. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/LICENSE.txt +209 -0
  86. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/MapConverter.cpp +79 -0
  87. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/MapConverter.hpp +30 -0
  88. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/ObjectConverter.cpp +52 -0
  89. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/ObjectConverter.hpp +29 -0
  90. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/Python/Common.cpp +8 -0
  91. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/Python/Common.hpp +117 -0
  92. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/Python/Helpers.cpp +54 -0
  93. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/Python/Helpers.hpp +34 -0
  94. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/SnowflakeType.cpp +33 -0
  95. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/SnowflakeType.hpp +48 -0
  96. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/StringConverter.cpp +18 -0
  97. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/StringConverter.hpp +26 -0
  98. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/TimeConverter.cpp +39 -0
  99. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/TimeConverter.hpp +31 -0
  100. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/TimeStampConverter.cpp +326 -0
  101. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/TimeStampConverter.hpp +138 -0
  102. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/Util/macros.hpp +14 -0
  103. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/Util/time.cpp +65 -0
  104. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/Util/time.hpp +68 -0
  105. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/arrow_stream_iterator.cpp +13278 -0
  106. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/arrow_stream_iterator.pyx +204 -0
  107. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/flatcc_accessors.h +109 -0
  108. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/flatcc_alloc.h +125 -0
  109. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/flatcc_assert.h +45 -0
  110. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/flatcc_builder.h +1914 -0
  111. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/flatcc_emitter.h +208 -0
  112. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/flatcc_endian.h +128 -0
  113. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/flatcc_epilogue.h +7 -0
  114. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/flatcc_flatbuffers.h +58 -0
  115. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/flatcc_identifier.h +144 -0
  116. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/flatcc_iov.h +31 -0
  117. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/flatcc_prologue.h +8 -0
  118. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/flatcc_refmap.h +144 -0
  119. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/flatcc_rtconfig.h +160 -0
  120. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/flatcc_types.h +98 -0
  121. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/flatcc_verifier.h +243 -0
  122. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/portable/flatcc_portable.h +14 -0
  123. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/portable/paligned_alloc.h +207 -0
  124. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/portable/pattributes.h +80 -0
  125. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/portable/pdiagnostic.h +83 -0
  126. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/portable/pdiagnostic_pop.h +20 -0
  127. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/portable/pdiagnostic_push.h +51 -0
  128. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/portable/pendian.h +201 -0
  129. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/portable/pendian_detect.h +108 -0
  130. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/portable/pinline.h +19 -0
  131. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/portable/pinttypes.h +52 -0
  132. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/portable/portable.h +2 -0
  133. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/portable/portable_basic.h +25 -0
  134. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/portable/pstatic_assert.h +67 -0
  135. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/portable/pstdalign.h +164 -0
  136. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/portable/pstdint.h +926 -0
  137. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/portable/punaligned.h +182 -0
  138. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/portable/pversion.h +6 -0
  139. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/portable/pwarnings.h +52 -0
  140. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc.c +3052 -0
  141. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/nanoarrow.c +3019 -0
  142. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/nanoarrow.h +3354 -0
  143. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/nanoarrow.hpp +344 -0
  144. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/nanoarrow_ipc.c +29305 -0
  145. snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/nanoarrow_ipc.h +381 -0
  146. snowflake/connector/_internal/nanoarrow_cpp/Logging/logging.cpp +108 -0
  147. snowflake/connector/_internal/nanoarrow_cpp/Logging/logging.hpp +47 -0
  148. snowflake/connector/_internal/nanoarrow_cpp/scripts/.clang-format +8 -0
  149. snowflake/connector/_internal/nanoarrow_cpp/scripts/format.sh +8 -0
  150. snowflake/connector/_internal/protobuf_gen/__init__.py +0 -0
  151. snowflake/connector/_internal/protobuf_gen/database_driver_v1_pb2.py +408 -0
  152. snowflake/connector/_internal/protobuf_gen/database_driver_v1_pb2.pyi +4487 -0
  153. snowflake/connector/_internal/protobuf_gen/database_driver_v1_services.py +2088 -0
  154. snowflake/connector/_internal/protobuf_gen/proto_exception.py +17 -0
  155. snowflake/connector/_internal/result_batch.py +150 -0
  156. snowflake/connector/_internal/snowflake_restful.py +222 -0
  157. snowflake/connector/_internal/snowpark_backcompat_helpers.py +31 -0
  158. snowflake/connector/_internal/sqlstate.py +11 -0
  159. snowflake/connector/_internal/statement_utils.py +207 -0
  160. snowflake/connector/_internal/text_utils.py +112 -0
  161. snowflake/connector/_internal/type_codes.py +139 -0
  162. snowflake/connector/_internal/utils.py +65 -0
  163. snowflake/connector/_internal/write_pandas_operation.py +657 -0
  164. snowflake/connector/aio/README.md +168 -0
  165. snowflake/connector/aio/__init__.py +37 -0
  166. snowflake/connector/aio/connection/__init__.py +17 -0
  167. snowflake/connector/aio/connection/_connection.py +506 -0
  168. snowflake/connector/aio/cursor/__init__.py +35 -0
  169. snowflake/connector/aio/cursor/_base.py +1034 -0
  170. snowflake/connector/aio/cursor/_dict_cursor.py +78 -0
  171. snowflake/connector/aio/cursor/_result_set_wrapper.py +35 -0
  172. snowflake/connector/aio/cursor/_snowflake_cursor.py +72 -0
  173. snowflake/connector/aio/pandas_tools.py +279 -0
  174. snowflake/connector/aio/result_batch.py +165 -0
  175. snowflake/connector/auth/__init__.py +0 -0
  176. snowflake/connector/auth/workload_identity.py +5 -0
  177. snowflake/connector/compat.py +22 -0
  178. snowflake/connector/config_manager.py +392 -0
  179. snowflake/connector/connection/__init__.py +30 -0
  180. snowflake/connector/connection/_connection.py +641 -0
  181. snowflake/connector/connection_config.py +517 -0
  182. snowflake/connector/constants.py +52 -0
  183. snowflake/connector/cursor/__init__.py +37 -0
  184. snowflake/connector/cursor/_base.py +1169 -0
  185. snowflake/connector/cursor/_chunked_download_reader.py +75 -0
  186. snowflake/connector/cursor/_dict_cursor.py +78 -0
  187. snowflake/connector/cursor/_result_set_wrapper.py +35 -0
  188. snowflake/connector/cursor/_snowflake_cursor.py +72 -0
  189. snowflake/connector/description.py +7 -0
  190. snowflake/connector/errors.py +492 -0
  191. snowflake/connector/network.py +71 -0
  192. snowflake/connector/pandas_tools.py +191 -0
  193. snowflake/connector/py.typed +0 -0
  194. snowflake/connector/result_batch.py +216 -0
  195. snowflake/connector/telemetry.py +40 -0
  196. snowflake/connector/time_util.py +11 -0
  197. snowflake/connector/types.py +134 -0
  198. snowflake/connector/util_text.py +3 -0
  199. snowflake/connector/version.py +23 -0
  200. snowflake_connector_python-5.2.0.dist-info/DELVEWHEEL +2 -0
  201. snowflake_connector_python-5.2.0.dist-info/METADATA +190 -0
  202. snowflake_connector_python-5.2.0.dist-info/RECORD +204 -0
  203. snowflake_connector_python-5.2.0.dist-info/WHEEL +4 -0
  204. snowflake_connector_python.libs/msvcp140-a4c2229bdc2a2a630acdc095b4d86008.dll +0 -0
@@ -0,0 +1,204 @@
1
+ # distutils: language = c++
2
+ # cython: language_level=3
3
+ # cython: freethreading_compatible = True
4
+
5
+ from cpython.ref cimport PyObject
6
+ from libc.stdint cimport int64_t, uintptr_t
7
+ from libcpp.memory cimport unique_ptr
8
+
9
+ from .errorcode import ER_FAILED_TO_CONVERT_ROW_TO_PYTHON_TYPE
10
+ from ..errors import InterfaceError
11
+
12
+ try:
13
+ import pyarrow as pa
14
+ except ImportError:
15
+ pass
16
+
17
+
18
+ # Import ReturnVal from C++ (defined in CArrowIterator.hpp)
19
+ cdef extern from "CArrowIterator.hpp" namespace "sf":
20
+ cdef cppclass ReturnVal:
21
+ PyObject* successObj
22
+ PyObject* exception
23
+
24
+
25
+ # Import the C++ stream iterator
26
+ cdef extern from "CArrowStreamIterator.hpp" namespace "sf":
27
+ cdef cppclass CArrowStreamIterator:
28
+ @staticmethod
29
+ unique_ptr[CArrowStreamIterator] from_stream(
30
+ int64_t stream_ptr,
31
+ PyObject* context,
32
+ bint use_numpy,
33
+ bint use_dict_result
34
+ )
35
+ ReturnVal next()
36
+ object nextN(int64_t size)
37
+ object nextAll()
38
+
39
+
40
+ cdef extern from "CArrowStreamTableIterator.hpp" namespace "sf":
41
+ cdef cppclass CArrowStreamTableIterator:
42
+ @staticmethod
43
+ unique_ptr[CArrowStreamTableIterator] from_stream(
44
+ int64_t stream_ptr,
45
+ PyObject* context,
46
+ bint number_to_decimal,
47
+ bint force_microsecond_precision,
48
+ )
49
+ ReturnVal next()
50
+ uintptr_t getArrowArrayPtr()
51
+ uintptr_t getArrowSchemaPtr()
52
+ uintptr_t getConvertedSchemaPtr()
53
+
54
+
55
+ cdef class ArrowStreamIterator:
56
+ """
57
+ Python wrapper for C++ Arrow stream iterator.
58
+
59
+ Reads directly from an ArrowArrayStream pointer. The C++ implementation
60
+ uses Py_BEGIN_ALLOW_THREADS/Py_END_ALLOW_THREADS to release the GIL during
61
+ potentially blocking I/O operations (e.g., fetching data chunks from S3).
62
+ """
63
+ cdef unique_ptr[CArrowStreamIterator] iterator
64
+ cdef object arrow_context
65
+
66
+ def __cinit__(
67
+ self,
68
+ int64_t stream_ptr,
69
+ object arrow_context,
70
+ object use_dict_result=False,
71
+ object use_numpy=False
72
+ ):
73
+ """
74
+ Initialize the stream iterator.
75
+
76
+ Parameters
77
+ ----------
78
+ stream_ptr : int
79
+ Pointer to ArrowArrayStream (as integer)
80
+ arrow_context : ArrowConverterContext
81
+ Context object for conversions
82
+ use_dict_result : bool
83
+ If True, return dicts instead of tuples
84
+ use_numpy : bool
85
+ If True, use numpy types for numeric data
86
+ """
87
+ self.arrow_context = arrow_context
88
+
89
+ # Create the C++ stream iterator using factory method
90
+ self.iterator = CArrowStreamIterator.from_stream(
91
+ stream_ptr,
92
+ <PyObject*>arrow_context,
93
+ use_numpy,
94
+ use_dict_result
95
+ )
96
+
97
+ # Check if creation failed (nullptr returned)
98
+ if self.iterator.get() == NULL:
99
+ raise RuntimeError("Failed to initialize stream iterator")
100
+
101
+ def __iter__(self):
102
+ return self
103
+
104
+ def __next__(self):
105
+ """Get next row from stream."""
106
+ cdef ReturnVal ret
107
+
108
+ ret = self.iterator.get().next()
109
+
110
+ # Check for exception
111
+ if ret.exception != NULL:
112
+ error_msg = <object>ret.exception
113
+ raise InterfaceError(
114
+ msg=f'Failed to convert current row, cause: {error_msg}',
115
+ errno=ER_FAILED_TO_CONVERT_ROW_TO_PYTHON_TYPE,
116
+ )
117
+
118
+ # Check for end of iteration
119
+ if ret.successObj == NULL:
120
+ raise StopIteration
121
+
122
+ # Return the row
123
+ row = <object>ret.successObj
124
+ return row
125
+
126
+ def fetch_many(self, int64_t size):
127
+ """Fetch up to `size` rows as a list in a single C++ call."""
128
+ try:
129
+ return self.iterator.get().nextN(size)
130
+ except Exception as e:
131
+ raise InterfaceError(
132
+ msg=f'Failed to convert rows, cause: {e}',
133
+ errno=ER_FAILED_TO_CONVERT_ROW_TO_PYTHON_TYPE,
134
+ )
135
+
136
+ def fetch_all(self):
137
+ """Fetch all remaining rows as a list in a single C++ call."""
138
+ try:
139
+ return self.iterator.get().nextAll()
140
+ except Exception as e:
141
+ raise InterfaceError(
142
+ msg=f'Failed to convert rows, cause: {e}',
143
+ errno=ER_FAILED_TO_CONVERT_ROW_TO_PYTHON_TYPE,
144
+ )
145
+
146
+ cdef class ArrowStreamTableIterator:
147
+ """
148
+ Python iterator that reads batches from an ArrowArrayStream and yields
149
+ one pyarrow.RecordBatch per batch, with Snowflake type conversions
150
+ applied via ArrowTableConverter.
151
+ """
152
+ cdef unique_ptr[CArrowStreamTableIterator] iterator
153
+ cdef object arrow_context
154
+
155
+ def __cinit__(
156
+ self,
157
+ int64_t stream_ptr,
158
+ object arrow_context,
159
+ bint number_to_decimal = False,
160
+ bint force_microsecond_precision = False,
161
+ ):
162
+ self.arrow_context = arrow_context
163
+
164
+ self.iterator = CArrowStreamTableIterator.from_stream(
165
+ stream_ptr,
166
+ <PyObject*>arrow_context,
167
+ number_to_decimal,
168
+ force_microsecond_precision,
169
+ )
170
+ if self.iterator.get() == NULL:
171
+ raise RuntimeError("Failed to initialize ArrowStreamTableIterator")
172
+
173
+ def __iter__(self):
174
+ return self
175
+
176
+ def __next__(self):
177
+ cdef ReturnVal ret
178
+ cdef uintptr_t array_ptr
179
+ cdef uintptr_t schema_ptr
180
+
181
+ ret = self.iterator.get().next()
182
+
183
+ if ret.exception != NULL:
184
+ error_msg = <object>ret.exception
185
+ raise InterfaceError(
186
+ msg=f'Failed to convert current row, cause: {error_msg}',
187
+ errno=ER_FAILED_TO_CONVERT_ROW_TO_PYTHON_TYPE,
188
+ )
189
+
190
+ if ret.successObj == NULL:
191
+ raise StopIteration
192
+
193
+ if <object>ret.successObj is None:
194
+ raise StopIteration
195
+
196
+ array_ptr = self.iterator.get().getArrowArrayPtr()
197
+ schema_ptr = self.iterator.get().getArrowSchemaPtr()
198
+
199
+ return pa.RecordBatch._import_from_c(array_ptr, schema_ptr)
200
+
201
+ def get_converted_schema(self):
202
+ cdef uintptr_t schema_ptr = self.iterator.get().getConvertedSchemaPtr()
203
+
204
+ return pa.Schema._import_from_c(schema_ptr)
@@ -0,0 +1,109 @@
1
+ #ifndef FLATCC_ACCESSORS
2
+ #define FLATCC_ACCESSORS
3
+
4
+ #ifdef __cplusplus
5
+ extern "C" {
6
+ #endif
7
+
8
+ #ifndef UINT8_MAX
9
+ #include <stdint.h>
10
+ #endif
11
+
12
+ #define __flatcc_basic_scalar_accessors_impl(N, T, W, E) \
13
+ static inline size_t N##__size(void) { return sizeof(T); } \
14
+ static inline T* N##__ptr_add(T* p, size_t i) { return p + i; } \
15
+ static inline const T* N##__const_ptr_add(const T* p, size_t i) { return p + i; } \
16
+ static inline T N##_read_from_pe(const void* p) { return N##_cast_from_pe(*(T*)p); } \
17
+ static inline T N##_read_to_pe(const void* p) { return N##_cast_to_pe(*(T*)p); } \
18
+ static inline T N##_read(const void* p) { return *(T*)p; } \
19
+ static inline void N##_write_from_pe(void* p, T v) { *(T*)p = N##_cast_from_pe(v); } \
20
+ static inline void N##_write_to_pe(void* p, T v) { *(T*)p = N##_cast_to_pe(v); } \
21
+ static inline void N##_write(void* p, T v) { *(T*)p = v; } \
22
+ static inline T N##_read_from_le(const void* p) { return N##_cast_from_le(*(T*)p); } \
23
+ typedef struct { \
24
+ int is_null; \
25
+ T value; \
26
+ } N##_option_t;
27
+
28
+ #define __flatcc_define_integer_accessors_impl(N, T, W, E) \
29
+ static inline T N##_cast_from_pe(T v) { return (T)E##W##toh((uint##W##_t)v); } \
30
+ static inline T N##_cast_to_pe(T v) { return (T)hto##E##W((uint##W##_t)v); } \
31
+ static inline T N##_cast_from_le(T v) { return (T)le##W##toh((uint##W##_t)v); } \
32
+ static inline T N##_cast_to_le(T v) { return (T)htole##W((uint##W##_t)v); } \
33
+ static inline T N##_cast_from_be(T v) { return (T)be##W##toh((uint##W##_t)v); } \
34
+ static inline T N##_cast_to_be(T v) { return (T)htobe##W((uint##W##_t)v); } \
35
+ __flatcc_basic_scalar_accessors_impl(N, T, W, E)
36
+
37
+ #define __flatcc_define_real_accessors_impl(N, T, W, E) \
38
+ union __##N##_cast { \
39
+ T v; \
40
+ uint##W##_t u; \
41
+ }; \
42
+ static inline T N##_cast_from_pe(T v) { \
43
+ union __##N##_cast x; \
44
+ x.v = v; \
45
+ x.u = E##W##toh(x.u); \
46
+ return x.v; \
47
+ } \
48
+ static inline T N##_cast_to_pe(T v) { \
49
+ union __##N##_cast x; \
50
+ x.v = v; \
51
+ x.u = hto##E##W(x.u); \
52
+ return x.v; \
53
+ } \
54
+ static inline T N##_cast_from_le(T v) { \
55
+ union __##N##_cast x; \
56
+ x.v = v; \
57
+ x.u = le##W##toh(x.u); \
58
+ return x.v; \
59
+ } \
60
+ static inline T N##_cast_to_le(T v) { \
61
+ union __##N##_cast x; \
62
+ x.v = v; \
63
+ x.u = htole##W(x.u); \
64
+ return x.v; \
65
+ } \
66
+ static inline T N##_cast_from_be(T v) { \
67
+ union __##N##_cast x; \
68
+ x.v = v; \
69
+ x.u = be##W##toh(x.u); \
70
+ return x.v; \
71
+ } \
72
+ static inline T N##_cast_to_be(T v) { \
73
+ union __##N##_cast x; \
74
+ x.v = v; \
75
+ x.u = htobe##W(x.u); \
76
+ return x.v; \
77
+ } \
78
+ __flatcc_basic_scalar_accessors_impl(N, T, W, E)
79
+
80
+ #define __flatcc_define_integer_accessors(N, T, W, E) \
81
+ __flatcc_define_integer_accessors_impl(N, T, W, E)
82
+
83
+ #define __flatcc_define_real_accessors(N, T, W, E) __flatcc_define_real_accessors_impl(N, T, W, E)
84
+
85
+ #define __flatcc_define_basic_integer_accessors(NS, TN, T, W, E) \
86
+ __flatcc_define_integer_accessors(NS##TN, T, W, E)
87
+
88
+ #define __flatcc_define_basic_real_accessors(NS, TN, T, W, E) \
89
+ __flatcc_define_real_accessors(NS##TN, T, W, E)
90
+
91
+ #define __flatcc_define_basic_scalar_accessors(NS, E) \
92
+ __flatcc_define_basic_integer_accessors( \
93
+ NS, char, char, 8, E) __flatcc_define_basic_integer_accessors(NS, uint8, uint8_t, 8, E) \
94
+ __flatcc_define_basic_integer_accessors(NS, uint16, uint16_t, 16, E) \
95
+ __flatcc_define_basic_integer_accessors(NS, uint32, uint32_t, 32, E) \
96
+ __flatcc_define_basic_integer_accessors(NS, uint64, uint64_t, 64, E) \
97
+ __flatcc_define_basic_integer_accessors(NS, int8, int8_t, 8, E) \
98
+ __flatcc_define_basic_integer_accessors(NS, int16, int16_t, 16, E) \
99
+ __flatcc_define_basic_integer_accessors(NS, int32, int32_t, 32, E) \
100
+ __flatcc_define_basic_integer_accessors(NS, int64, int64_t, 64, E) \
101
+ __flatcc_define_basic_real_accessors(NS, float, float, 32, E) \
102
+ __flatcc_define_basic_real_accessors(NS, double, double, 64, \
103
+ E)
104
+
105
+ #ifdef __cplusplus
106
+ }
107
+ #endif
108
+
109
+ #endif /* FLATCC_ACCESSORS */
@@ -0,0 +1,125 @@
1
+ #ifndef FLATCC_ALLOC_H
2
+ #define FLATCC_ALLOC_H
3
+
4
+ #ifdef __cplusplus
5
+ extern "C" {
6
+ #endif
7
+
8
+ /*
9
+ * These allocation abstractions are __only__ for runtime libraries.
10
+ *
11
+ * The flatcc compiler uses Posix allocation routines regardless
12
+ * of how this file is configured.
13
+ *
14
+ * This header makes it possible to use systems where malloc is not
15
+ * valid to use. In this case the portable library will not help
16
+ * because it implements Posix / C11 abstractions.
17
+ *
18
+ * Systems like FreeRTOS do not work with Posix memory calls and here it
19
+ * can be helpful to override runtime allocation primitives.
20
+ *
21
+ * In general, it is better to customize the allocator and emitter via
22
+ * flatcc_builder_custom_init and to avoid using the default emitter
23
+ * specific high level calls the copy out a buffer that must later be
24
+ * deallocated. This provides full control of allocation withou the need
25
+ * for this file.
26
+ *
27
+ *
28
+ * IMPORTANT
29
+ *
30
+ * If you override malloc, free, etc., make sure your applications
31
+ * use the same allocation methods. For example, samples/monster.c
32
+ * and several test cases are no longer guaranteed to work out of the
33
+ * box.
34
+ *
35
+ * The changes must only affect target runtime compilation including the
36
+ * the runtime library libflatccrt.
37
+ *
38
+ * The host system flatcc compiler and the compiler library libflatcc
39
+ * should NOT be compiled with non-Posix allocation since the compiler
40
+ * has a dependency on the runtime library and the wrong free operation
41
+ * might be callled. The safest way to avoid this problem this is to
42
+ * compile flatcc with the CMake script and the runtime files with a
43
+ * dedicated build system for the target system.
44
+ */
45
+
46
+ #include <stdlib.h>
47
+
48
+ #ifndef FLATCC_ALLOC
49
+ #define FLATCC_ALLOC(n) malloc(n)
50
+ #endif
51
+
52
+ #ifndef FLATCC_FREE
53
+ #define FLATCC_FREE(p) free(p)
54
+ #endif
55
+
56
+ #ifndef FLATCC_REALLOC
57
+ #define FLATCC_REALLOC(p, n) realloc(p, n)
58
+ #endif
59
+
60
+ #ifndef FLATCC_CALLOC
61
+ #define FLATCC_CALLOC(nm, n) calloc(nm, n)
62
+ #endif
63
+
64
+ /*
65
+ * Implements `aligned_alloc` and `aligned_free`.
66
+ * Even with C11, this implements non-standard aligned_free needed for portable
67
+ * aligned_alloc implementations.
68
+ */
69
+ #ifndef FLATCC_USE_GENERIC_ALIGNED_ALLOC
70
+
71
+ #ifndef FLATCC_NO_PALIGNED_ALLOC
72
+ #include "flatcc/portable/paligned_alloc.h"
73
+ #else
74
+ #if !defined(__aligned_free_is_defined) || !__aligned_free_is_defined
75
+ #define aligned_free free
76
+ #endif
77
+ #endif
78
+
79
+ #else /* FLATCC_USE_GENERIC_ALIGNED_ALLOC */
80
+
81
+ #ifndef FLATCC_ALIGNED_ALLOC
82
+ static inline void* __flatcc_aligned_alloc(size_t alignment, size_t size) {
83
+ char* raw;
84
+ void* buf;
85
+ size_t total_size = (size + alignment - 1 + sizeof(void*));
86
+
87
+ if (alignment < sizeof(void*)) {
88
+ alignment = sizeof(void*);
89
+ }
90
+ raw = (char*)(size_t)FLATCC_ALLOC(total_size);
91
+ buf = raw + alignment - 1 + sizeof(void*);
92
+ buf = (void*)(((size_t)buf) & ~(alignment - 1));
93
+ ((void**)buf)[-1] = raw;
94
+ return buf;
95
+ }
96
+ #define FLATCC_ALIGNED_ALLOC(alignment, size) __flatcc_aligned_alloc(alignment, size)
97
+ #endif /* FLATCC_USE_GENERIC_ALIGNED_ALLOC */
98
+
99
+ #ifndef FLATCC_ALIGNED_FREE
100
+ static inline void __flatcc_aligned_free(void* p) {
101
+ char* raw;
102
+
103
+ if (!p) return;
104
+ raw = ((void**)p)[-1];
105
+
106
+ FLATCC_FREE(raw);
107
+ }
108
+ #define FLATCC_ALIGNED_FREE(p) __flatcc_aligned_free(p)
109
+ #endif
110
+
111
+ #endif /* FLATCC_USE_GENERIC_ALIGNED_ALLOC */
112
+
113
+ #ifndef FLATCC_ALIGNED_ALLOC
114
+ #define FLATCC_ALIGNED_ALLOC(a, n) aligned_alloc(a, n)
115
+ #endif
116
+
117
+ #ifndef FLATCC_ALIGNED_FREE
118
+ #define FLATCC_ALIGNED_FREE(p) aligned_free(p)
119
+ #endif
120
+
121
+ #ifdef __cplusplus
122
+ }
123
+ #endif
124
+
125
+ #endif /* FLATCC_ALLOC_H */
@@ -0,0 +1,45 @@
1
+ #ifndef FLATCC_ASSERT_H
2
+ #define FLATCC_ASSERT_H
3
+
4
+ #ifdef __cplusplus
5
+ extern "C" {
6
+ #endif
7
+
8
+ /*
9
+ * This assert abstraction is only used for the flatcc runtime library.
10
+ * The flatcc compiler uses Posix assert routines regardless of how this
11
+ * file is configured.
12
+ *
13
+ * This header makes it possible to use systems where assert is not
14
+ * valid to use. Note that `<assert.h>` may remain a dependency for static
15
+ * assertions.
16
+ *
17
+ * `FLATCC_ASSERT` is designed to handle errors which cannot be ignored
18
+ * and could lead to crash. The portable library may use assertions that
19
+ * are not affected by this macro.
20
+ *
21
+ * `FLATCC_ASSERT` defaults to POSIX assert but can be overrided by a
22
+ * preprocessor definition.
23
+ *
24
+ * Runtime assertions can be entirely disabled by defining
25
+ * `FLATCC_NO_ASSERT`.
26
+ */
27
+
28
+ #ifdef FLATCC_NO_ASSERT
29
+ /* NOTE: This will not affect inclusion of <assert.h> for static assertions. */
30
+ #undef FLATCC_ASSERT
31
+ #define FLATCC_ASSERT(x) ((void)0)
32
+ /* Grisu3 is used for floating point conversion in JSON processing. */
33
+ #define GRISU3_NO_ASSERT
34
+ #endif
35
+
36
+ #ifndef FLATCC_ASSERT
37
+ #include <assert.h>
38
+ #define FLATCC_ASSERT assert
39
+ #endif
40
+
41
+ #ifdef __cplusplus
42
+ }
43
+ #endif
44
+
45
+ #endif /* FLATCC_ASSERT_H */