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,344 @@
1
+ // Licensed to the Apache Software Foundation (ASF) under one
2
+ // or more contributor license agreements. See the NOTICE file
3
+ // distributed with this work for additional information
4
+ // regarding copyright ownership. The ASF licenses this file
5
+ // to you under the Apache License, Version 2.0 (the
6
+ // "License"); you may not use this file except in compliance
7
+ // with the License. You may obtain a copy of the License at
8
+ //
9
+ // http://www.apache.org/licenses/LICENSE-2.0
10
+ //
11
+ // Unless required by applicable law or agreed to in writing,
12
+ // software distributed under the License is distributed on an
13
+ // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
+ // KIND, either express or implied. See the License for the
15
+ // specific language governing permissions and limitations
16
+ // under the License.
17
+
18
+ #include <stdexcept>
19
+ #include <string>
20
+ #include <vector>
21
+
22
+ #include "nanoarrow.h"
23
+
24
+ #ifndef NANOARROW_HPP_INCLUDED
25
+ #define NANOARROW_HPP_INCLUDED
26
+
27
+ /// \defgroup nanoarrow_hpp Nanoarrow C++ Helpers
28
+ ///
29
+ /// The utilities provided in this file are intended to support C++ users
30
+ /// of the nanoarrow C library such that C++-style resource allocation
31
+ /// and error handling can be used with nanoarrow data structures.
32
+ /// These utilities are not intended to mirror the nanoarrow C API.
33
+
34
+ namespace nanoarrow {
35
+
36
+ /// \defgroup nanoarrow_hpp-errors Error handling helpers
37
+ ///
38
+ /// Most functions in the C API return an ArrowErrorCode to communicate
39
+ /// possible failure. Except where documented, it is usually not safe to
40
+ /// continue after a non-zero value has been returned. While the
41
+ /// nanoarrow C++ helpers do not throw any exceptions of their own,
42
+ /// these helpers are provided to facilitate using the nanoarrow C++ helpers
43
+ /// in frameworks where this is a useful error handling idiom.
44
+ ///
45
+ /// @{
46
+
47
+ class Exception : public std::exception {
48
+ public:
49
+ Exception(const std::string& msg) : msg_(msg) {}
50
+ const char* what() const noexcept { return msg_.c_str(); }
51
+
52
+ private:
53
+ std::string msg_;
54
+ };
55
+
56
+ #if defined(NANOARROW_DEBUG)
57
+ #define _NANOARROW_THROW_NOT_OK_IMPL(NAME, EXPR, EXPR_STR) \
58
+ do { \
59
+ const int NAME = (EXPR); \
60
+ if (NAME) { \
61
+ throw nanoarrow::Exception(std::string(EXPR_STR) + std::string(" failed with errno ") + \
62
+ std::to_string(NAME) + std::string("\n * ") + \
63
+ std::string(__FILE__) + std::string(":") + \
64
+ std::to_string(__LINE__) + std::string("\n")); \
65
+ } \
66
+ } while (0)
67
+ #else
68
+ #define _NANOARROW_THROW_NOT_OK_IMPL(NAME, EXPR, EXPR_STR) \
69
+ do { \
70
+ const int NAME = (EXPR); \
71
+ if (NAME) { \
72
+ throw nanoarrow::Exception(std::string(EXPR_STR) + std::string(" failed with errno ") + \
73
+ std::to_string(NAME)); \
74
+ } \
75
+ } while (0)
76
+ #endif
77
+
78
+ #define NANOARROW_THROW_NOT_OK(EXPR) \
79
+ _NANOARROW_THROW_NOT_OK_IMPL(_NANOARROW_MAKE_NAME(errno_status_, __COUNTER__), EXPR, #EXPR)
80
+
81
+ /// @}
82
+
83
+ namespace internal {
84
+
85
+ /// \defgroup nanoarrow_hpp-unique_base Base classes for Unique wrappers
86
+ ///
87
+ /// @{
88
+
89
+ static inline void init_pointer(struct ArrowSchema* data) { data->release = nullptr; }
90
+
91
+ static inline void move_pointer(struct ArrowSchema* src, struct ArrowSchema* dst) {
92
+ ArrowSchemaMove(src, dst);
93
+ }
94
+
95
+ static inline void release_pointer(struct ArrowSchema* data) {
96
+ if (data->release != nullptr) {
97
+ data->release(data);
98
+ }
99
+ }
100
+
101
+ static inline void init_pointer(struct ArrowArray* data) { data->release = nullptr; }
102
+
103
+ static inline void move_pointer(struct ArrowArray* src, struct ArrowArray* dst) {
104
+ ArrowArrayMove(src, dst);
105
+ }
106
+
107
+ static inline void release_pointer(struct ArrowArray* data) {
108
+ if (data->release != nullptr) {
109
+ data->release(data);
110
+ }
111
+ }
112
+
113
+ static inline void init_pointer(struct ArrowArrayStream* data) { data->release = nullptr; }
114
+
115
+ static inline void move_pointer(struct ArrowArrayStream* src, struct ArrowArrayStream* dst) {
116
+ ArrowArrayStreamMove(src, dst);
117
+ }
118
+
119
+ static inline void release_pointer(ArrowArrayStream* data) {
120
+ if (data->release != nullptr) {
121
+ data->release(data);
122
+ }
123
+ }
124
+
125
+ static inline void init_pointer(struct ArrowBuffer* data) { ArrowBufferInit(data); }
126
+
127
+ static inline void move_pointer(struct ArrowBuffer* src, struct ArrowBuffer* dst) {
128
+ ArrowBufferMove(src, dst);
129
+ }
130
+
131
+ static inline void release_pointer(struct ArrowBuffer* data) { ArrowBufferReset(data); }
132
+
133
+ static inline void init_pointer(struct ArrowBitmap* data) { ArrowBitmapInit(data); }
134
+
135
+ static inline void move_pointer(struct ArrowBitmap* src, struct ArrowBitmap* dst) {
136
+ ArrowBitmapMove(src, dst);
137
+ }
138
+
139
+ static inline void release_pointer(struct ArrowBitmap* data) { ArrowBitmapReset(data); }
140
+
141
+ static inline void init_pointer(struct ArrowArrayView* data) {
142
+ ArrowArrayViewInitFromType(data, NANOARROW_TYPE_UNINITIALIZED);
143
+ }
144
+
145
+ static inline void move_pointer(struct ArrowArrayView* src, struct ArrowArrayView* dst) {
146
+ ArrowArrayViewMove(src, dst);
147
+ }
148
+
149
+ static inline void release_pointer(struct ArrowArrayView* data) { ArrowArrayViewReset(data); }
150
+
151
+ /// \brief A unique_ptr-like base class for stack-allocatable objects
152
+ /// \tparam T The object type
153
+ template <typename T>
154
+ class Unique {
155
+ public:
156
+ /// \brief Construct an invalid instance of T holding no resources
157
+ Unique() { init_pointer(&data_); }
158
+
159
+ /// \brief Move and take ownership of data
160
+ Unique(T* data) { move_pointer(data, &data_); }
161
+
162
+ /// \brief Move and take ownership of data wrapped by rhs
163
+ Unique(Unique&& rhs) : Unique(rhs.get()) {}
164
+
165
+ // These objects are not copyable
166
+ Unique(Unique& rhs) = delete;
167
+
168
+ /// \brief Get a pointer to the data owned by this object
169
+ T* get() noexcept { return &data_; }
170
+
171
+ /// \brief Use the pointer operator to access fields of this object
172
+ T* operator->() { return &data_; }
173
+
174
+ /// \brief Call data's release callback if valid
175
+ void reset() { release_pointer(&data_); }
176
+
177
+ /// \brief Call data's release callback if valid and move ownership of the
178
+ /// data pointed to by data
179
+ void reset(T* data) {
180
+ reset();
181
+ move_pointer(data, &data_);
182
+ }
183
+
184
+ /// \brief Move ownership of this object to the data pointed to by out
185
+ void move(T* out) { move_pointer(&data_, out); }
186
+
187
+ ~Unique() { reset(); }
188
+
189
+ protected:
190
+ T data_;
191
+ };
192
+
193
+ /// @}
194
+
195
+ } // namespace internal
196
+
197
+ /// \defgroup nanoarrow_hpp-unique Unique object wrappers
198
+ ///
199
+ /// The Arrow C Data interface, the Arrow C Stream interface, and the
200
+ /// nanoarrow C library use stack-allocatable objects, some of which
201
+ /// require initialization or cleanup.
202
+ ///
203
+ /// @{
204
+
205
+ /// \brief Class wrapping a unique struct ArrowSchema
206
+ using UniqueSchema = internal::Unique<struct ArrowSchema>;
207
+
208
+ /// \brief Class wrapping a unique struct ArrowArray
209
+ using UniqueArray = internal::Unique<struct ArrowArray>;
210
+
211
+ /// \brief Class wrapping a unique struct ArrowArrayStream
212
+ using UniqueArrayStream = internal::Unique<struct ArrowArrayStream>;
213
+
214
+ /// \brief Class wrapping a unique struct ArrowBuffer
215
+ using UniqueBuffer = internal::Unique<struct ArrowBuffer>;
216
+
217
+ /// \brief Class wrapping a unique struct ArrowBitmap
218
+ using UniqueBitmap = internal::Unique<struct ArrowBitmap>;
219
+
220
+ /// \brief Class wrapping a unique struct ArrowArrayView
221
+ using UniqueArrayView = internal::Unique<struct ArrowArrayView>;
222
+
223
+ /// @}
224
+
225
+ /// \defgroup nanoarrow_hpp-array-stream ArrayStream helpers
226
+ ///
227
+ /// These classes provide simple struct ArrowArrayStream implementations that
228
+ /// can be extended to help simplify the process of creating a valid
229
+ /// ArrowArrayStream implementation or used as-is for testing.
230
+ ///
231
+ /// @{
232
+
233
+ /// \brief An empty array stream
234
+ ///
235
+ /// This class can be constructed from an enum ArrowType or
236
+ /// struct ArrowSchema and implements a default get_next() method that
237
+ /// always marks the output ArrowArray as released. This class can
238
+ /// be extended with an implementation of get_next() for a custom
239
+ /// source.
240
+ class EmptyArrayStream {
241
+ public:
242
+ /// \brief Create an empty UniqueArrayStream from a struct ArrowSchema
243
+ ///
244
+ /// This object takes ownership of the schema and marks the source schema
245
+ /// as released.
246
+ static UniqueArrayStream MakeUnique(struct ArrowSchema* schema) {
247
+ UniqueArrayStream stream;
248
+ (new EmptyArrayStream(schema))->MakeStream(stream.get());
249
+ return stream;
250
+ }
251
+
252
+ virtual ~EmptyArrayStream() {}
253
+
254
+ protected:
255
+ UniqueSchema schema_;
256
+ struct ArrowError error_;
257
+
258
+ EmptyArrayStream(struct ArrowSchema* schema) : schema_(schema) { error_.message[0] = '\0'; }
259
+
260
+ void MakeStream(struct ArrowArrayStream* stream) {
261
+ stream->get_schema = &get_schema_wrapper;
262
+ stream->get_next = &get_next_wrapper;
263
+ stream->get_last_error = &get_last_error_wrapper;
264
+ stream->release = &release_wrapper;
265
+ stream->private_data = this;
266
+ }
267
+
268
+ virtual int get_schema(struct ArrowSchema* schema) {
269
+ return ArrowSchemaDeepCopy(schema_.get(), schema);
270
+ }
271
+
272
+ virtual int get_next(struct ArrowArray* array) {
273
+ array->release = nullptr;
274
+ return NANOARROW_OK;
275
+ }
276
+
277
+ virtual const char* get_last_error() { return error_.message; }
278
+
279
+ private:
280
+ static int get_schema_wrapper(struct ArrowArrayStream* stream, struct ArrowSchema* schema) {
281
+ return reinterpret_cast<EmptyArrayStream*>(stream->private_data)->get_schema(schema);
282
+ }
283
+
284
+ static int get_next_wrapper(struct ArrowArrayStream* stream, struct ArrowArray* array) {
285
+ return reinterpret_cast<EmptyArrayStream*>(stream->private_data)->get_next(array);
286
+ }
287
+
288
+ static const char* get_last_error_wrapper(struct ArrowArrayStream* stream) {
289
+ return reinterpret_cast<EmptyArrayStream*>(stream->private_data)->get_last_error();
290
+ }
291
+
292
+ static void release_wrapper(struct ArrowArrayStream* stream) {
293
+ delete reinterpret_cast<EmptyArrayStream*>(stream->private_data);
294
+ stream->release = nullptr;
295
+ stream->private_data = nullptr;
296
+ }
297
+ };
298
+
299
+ /// \brief Implementation of an ArrowArrayStream backed by a vector of
300
+ /// ArrowArray objects
301
+ class VectorArrayStream : public EmptyArrayStream {
302
+ public:
303
+ /// \brief Create a UniqueArrowArrayStream from an existing array
304
+ ///
305
+ /// Takes ownership of the schema and the array.
306
+ static UniqueArrayStream MakeUnique(struct ArrowSchema* schema, struct ArrowArray* array) {
307
+ std::vector<UniqueArray> arrays;
308
+ arrays.emplace_back(array);
309
+ return MakeUnique(schema, std::move(arrays));
310
+ }
311
+
312
+ /// \brief Create a UniqueArrowArrayStream from existing arrays
313
+ ///
314
+ /// This object takes ownership of the schema and arrays.
315
+ static UniqueArrayStream MakeUnique(struct ArrowSchema* schema, std::vector<UniqueArray> arrays) {
316
+ UniqueArrayStream stream;
317
+ (new VectorArrayStream(schema, std::move(arrays)))->MakeStream(stream.get());
318
+ return stream;
319
+ }
320
+
321
+ protected:
322
+ VectorArrayStream(struct ArrowSchema* schema, std::vector<UniqueArray> arrays)
323
+ : EmptyArrayStream(schema), arrays_(std::move(arrays)), offset_(0) {}
324
+
325
+ int get_next(struct ArrowArray* array) {
326
+ if (offset_ < static_cast<int64_t>(arrays_.size())) {
327
+ arrays_[offset_++].move(array);
328
+ } else {
329
+ array->release = nullptr;
330
+ }
331
+
332
+ return NANOARROW_OK;
333
+ }
334
+
335
+ private:
336
+ std::vector<UniqueArray> arrays_;
337
+ int64_t offset_;
338
+ };
339
+
340
+ /// @}
341
+
342
+ } // namespace nanoarrow
343
+
344
+ #endif