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,90 @@
1
+ #include "DecimalConverter.hpp"
2
+
3
+ #include <memory>
4
+ #include <mutex>
5
+ #include <string>
6
+
7
+ #include "Python/Common.hpp"
8
+ #include "Python/Helpers.hpp"
9
+
10
+ namespace sf {
11
+
12
+ DecimalBaseConverter::DecimalBaseConverter() : m_pyDecimalConstructor(initPyDecimalConstructor()) {}
13
+
14
+ py::UniqueRef& DecimalBaseConverter::initPyDecimalConstructor() {
15
+ static py::UniqueRef pyDecimalConstructor;
16
+ // The empty check races when the GIL does not serialize this init.
17
+ static std::once_flag onceFlag;
18
+ std::call_once(onceFlag, []() {
19
+ py::UniqueRef decimalModule;
20
+ py::importPythonModule("decimal", decimalModule);
21
+ py::importFromModule(decimalModule, "Decimal", pyDecimalConstructor);
22
+ Py_XINCREF(pyDecimalConstructor.get());
23
+ });
24
+
25
+ return pyDecimalConstructor;
26
+ }
27
+
28
+ DecimalFromIntConverter::DecimalFromIntConverter(ArrowArrayView* array, int /* precision */, int scale)
29
+ : m_array(array), m_scale(scale) {}
30
+
31
+ PyObject* DecimalFromIntConverter::toPyObject(int64_t rowIndex) const {
32
+ if (ArrowArrayViewIsNull(m_array, rowIndex)) {
33
+ Py_RETURN_NONE;
34
+ }
35
+ int64_t val = ArrowArrayViewGetIntUnsafe(m_array, rowIndex);
36
+ py::UniqueRef decimal(PyObject_CallFunction(m_pyDecimalConstructor.get(), "L", val));
37
+ return PyObject_CallMethod(decimal.get(), "scaleb", "i", -m_scale);
38
+ }
39
+
40
+ NumpyDecimalConverter::NumpyDecimalConverter(ArrowArrayView* array, int /* precision */, int scale,
41
+ PyObject* context)
42
+ : m_array(array), m_scale(scale), m_context(context) {}
43
+
44
+ PyObject* NumpyDecimalConverter::toPyObject(int64_t rowIndex) const {
45
+ if (ArrowArrayViewIsNull(m_array, rowIndex)) {
46
+ Py_RETURN_NONE;
47
+ }
48
+ int64_t val = ArrowArrayViewGetIntUnsafe(m_array, rowIndex);
49
+ return PyObject_CallMethod(m_context, "FIXED_to_numpy_float64", "Li", val, m_scale);
50
+ }
51
+
52
+ DecimalFromDecimalConverter::DecimalFromDecimalConverter(PyObject* context, ArrowArrayView* array,
53
+ int scale)
54
+ : m_array(array), m_context(context), m_scale(scale) {}
55
+
56
+ PyObject* DecimalFromDecimalConverter::toPyObject(int64_t rowIndex) const {
57
+ if (ArrowArrayViewIsNull(m_array, rowIndex)) {
58
+ Py_RETURN_NONE;
59
+ }
60
+ int64_t bytes_start = 16 * (m_array->array->offset + rowIndex);
61
+ const char* ptr_start = m_array->buffer_views[1].data.as_char;
62
+ PyObject* int128_bytes = PyBytes_FromStringAndSize(&(ptr_start[bytes_start]), 16);
63
+ /**
64
+ # Alternatively, the decimal conversion can be implemented using the
65
+ ArrowDecimal related APIs in the following # code snippets, however, it's less
66
+ performant than the direct memory manipulation. # The code snippets here is
67
+ for context reference.
68
+
69
+ ArrowDecimal arrowDecimal;
70
+ ArrowDecimalInit(&arrowDecimal, 128, precision, scale);
71
+ ArrowArrayViewGetDecimalUnsafe(m_array, rowIndex, &arrowDecimal);
72
+ uint8_t outBytes[16];
73
+ ArrowDecimalGetBytes(&arrowDecimal, outBytes);
74
+ PyObject* int128_bytes = PyBytes_FromStringAndSize(&outBytes, 16);
75
+ */
76
+ PyObject* return_object =
77
+ PyObject_CallMethod(m_context, "DECIMAL128_to_decimal_or_int", "Si", int128_bytes, m_scale);
78
+ /**
79
+ int128_bytes is a new referenced created by PyBytes_FromStringAndSize,
80
+ to avoid memory leak we need to free it after usage
81
+ check docs:
82
+ https://docs.python.org/3/c-api/bytes.html#c.PyBytes_FromStringAndSize
83
+ https://docs.python.org/3/c-api/refcounting.html#c.Py_XDECREF
84
+
85
+ */
86
+ Py_XDECREF(int128_bytes);
87
+ return return_object;
88
+ }
89
+
90
+ } // namespace sf
@@ -0,0 +1,63 @@
1
+ #ifndef PC_DECIMALCONVERTER_HPP
2
+ #define PC_DECIMALCONVERTER_HPP
3
+
4
+ #include <memory>
5
+
6
+ #include "IColumnConverter.hpp"
7
+ #include "Python/Common.hpp"
8
+ #include "nanoarrow.h"
9
+
10
+ namespace sf {
11
+
12
+ class DecimalBaseConverter : public IColumnConverter {
13
+ public:
14
+ DecimalBaseConverter();
15
+ virtual ~DecimalBaseConverter() = default;
16
+
17
+ protected:
18
+ py::UniqueRef& m_pyDecimalConstructor;
19
+
20
+ private:
21
+ static py::UniqueRef& initPyDecimalConstructor();
22
+ };
23
+
24
+ class DecimalFromDecimalConverter : public DecimalBaseConverter {
25
+ public:
26
+ explicit DecimalFromDecimalConverter(PyObject* context, ArrowArrayView* array, int scale);
27
+
28
+ PyObject* toPyObject(int64_t rowIndex) const override;
29
+
30
+ private:
31
+ ArrowArrayView* m_array;
32
+ PyObject* m_context;
33
+ int m_scale;
34
+ /** no need for this converter to store precision*/
35
+ };
36
+
37
+ class DecimalFromIntConverter : public DecimalBaseConverter {
38
+ public:
39
+ explicit DecimalFromIntConverter(ArrowArrayView* array, int precision, int scale);
40
+
41
+ PyObject* toPyObject(int64_t rowIndex) const override;
42
+
43
+ private:
44
+ ArrowArrayView* m_array;
45
+ int m_scale;
46
+ };
47
+
48
+ class NumpyDecimalConverter : public IColumnConverter {
49
+ public:
50
+ explicit NumpyDecimalConverter(ArrowArrayView* array, int precision, int scale,
51
+ PyObject* context);
52
+
53
+ PyObject* toPyObject(int64_t rowIndex) const override;
54
+
55
+ private:
56
+ ArrowArrayView* m_array;
57
+ int m_scale;
58
+ PyObject* m_context;
59
+ };
60
+
61
+ } // namespace sf
62
+
63
+ #endif // PC_DECIMALCONVERTER_HPP
@@ -0,0 +1,62 @@
1
+ #include "FixedSizeListConverter.hpp"
2
+
3
+ namespace sf {
4
+ Logger* FixedSizeListConverter::logger = new Logger("snowflake.connector.FixedSizeListConverter");
5
+
6
+ FixedSizeListConverter::FixedSizeListConverter(ArrowArrayView* array) : m_array(array) {}
7
+
8
+ void FixedSizeListConverter::generateError(const std::string& msg) const {
9
+ logger->error(__FILE__, __func__, __LINE__, msg.c_str());
10
+ PyErr_SetString(PyExc_Exception, msg.c_str());
11
+ }
12
+
13
+ PyObject* FixedSizeListConverter::toPyObject(int64_t rowIndex) const {
14
+ if (ArrowArrayViewIsNull(m_array, rowIndex)) {
15
+ Py_RETURN_NONE;
16
+ }
17
+
18
+ if (m_array->n_children != 1) {
19
+ std::string errorInfo = Logger::formatString(
20
+ "[Snowflake Exception] invalid arrow element schema for fixed size "
21
+ "list: got (%d) "
22
+ "children",
23
+ m_array->n_children);
24
+ this->generateError(errorInfo);
25
+ return nullptr;
26
+ }
27
+
28
+ // m_array->length represents the number of fixed size lists in the array
29
+ // m_array->children[0] has a buffer view that contains the actual data of
30
+ // each list, back-to-back m_array->children[0]->length represents the sum of
31
+ // the lengths of the fixed size lists in the array.
32
+
33
+ ArrowArrayView* elements = m_array->children[0];
34
+ const auto fixedSizeArrayLength = elements->length / m_array->length;
35
+ PyObject* list = PyList_New(fixedSizeArrayLength);
36
+
37
+ const int64_t startIndexWithoutOffset = rowIndex * fixedSizeArrayLength;
38
+ for (int64_t i = 0; i < fixedSizeArrayLength; ++i) {
39
+ const auto bufferIndexWithoutOffset = startIndexWithoutOffset + i;
40
+ switch (elements->storage_type) {
41
+ case NANOARROW_TYPE_INT32: {
42
+ const auto value = ArrowArrayViewGetIntUnsafe(elements, bufferIndexWithoutOffset);
43
+ PyList_SetItem(list, i, PyLong_FromLongLong(value));
44
+ } break;
45
+ case NANOARROW_TYPE_FLOAT: {
46
+ const auto value = ArrowArrayViewGetDoubleUnsafe(elements, bufferIndexWithoutOffset);
47
+ PyList_SetItem(list, i, PyFloat_FromDouble(value));
48
+ } break;
49
+ default:
50
+ std::string errorInfo = Logger::formatString(
51
+ "[Snowflake Exception] invalid arrow element type for fixed size "
52
+ "list: got (%s)",
53
+ ArrowTypeString(elements->storage_type));
54
+ this->generateError(errorInfo);
55
+ return nullptr;
56
+ }
57
+ }
58
+
59
+ return list;
60
+ }
61
+
62
+ } // namespace sf
@@ -0,0 +1,28 @@
1
+ #ifndef PC_FIXEDSIZELISTCONVERTER_HPP
2
+ #define PC_FIXEDSIZELISTCONVERTER_HPP
3
+
4
+ #include <memory>
5
+
6
+ #include "IColumnConverter.hpp"
7
+ #include "logging.hpp"
8
+ #include "nanoarrow.h"
9
+ #include "nanoarrow.hpp"
10
+
11
+ namespace sf {
12
+
13
+ class FixedSizeListConverter : public IColumnConverter {
14
+ public:
15
+ explicit FixedSizeListConverter(ArrowArrayView* array);
16
+ PyObject* toPyObject(int64_t rowIndex) const override;
17
+
18
+ private:
19
+ void generateError(const std::string& msg) const;
20
+
21
+ ArrowArrayView* m_array;
22
+
23
+ static Logger* logger;
24
+ };
25
+
26
+ } // namespace sf
27
+
28
+ #endif // PC_FIXEDSIZELISTCONVERTER_HPP
@@ -0,0 +1,29 @@
1
+ #include "FloatConverter.hpp"
2
+
3
+ #include <memory>
4
+
5
+ namespace sf {
6
+
7
+ /** snowflake float is 64-precision, which refers to double here */
8
+ FloatConverter::FloatConverter(ArrowArrayView* array) : m_array(array) {}
9
+
10
+ PyObject* FloatConverter::toPyObject(int64_t rowIndex) const {
11
+ if (ArrowArrayViewIsNull(m_array, rowIndex)) {
12
+ Py_RETURN_NONE;
13
+ }
14
+ return PyFloat_FromDouble(ArrowArrayViewGetDoubleUnsafe(m_array, rowIndex));
15
+ }
16
+
17
+ NumpyFloat64Converter::NumpyFloat64Converter(ArrowArrayView* array, PyObject* context)
18
+ : m_array(array), m_context(context) {}
19
+
20
+ PyObject* NumpyFloat64Converter::toPyObject(int64_t rowIndex) const {
21
+ if (ArrowArrayViewIsNull(m_array, rowIndex)) {
22
+ Py_RETURN_NONE;
23
+ }
24
+
25
+ double val = ArrowArrayViewGetDoubleUnsafe(m_array, rowIndex);
26
+ return PyObject_CallMethod(m_context, "REAL_to_numpy_float64", "d", val);
27
+ }
28
+
29
+ } // namespace sf
@@ -0,0 +1,35 @@
1
+ #ifndef PC_FLOATCONVERTER_HPP
2
+ #define PC_FLOATCONVERTER_HPP
3
+
4
+ #include <memory>
5
+
6
+ #include "IColumnConverter.hpp"
7
+ #include "nanoarrow.h"
8
+
9
+ namespace sf {
10
+
11
+ class FloatConverter : public IColumnConverter {
12
+ public:
13
+ explicit FloatConverter(ArrowArrayView* array);
14
+
15
+ PyObject* toPyObject(int64_t rowIndex) const override;
16
+
17
+ private:
18
+ ArrowArrayView* m_array;
19
+ };
20
+
21
+ class NumpyFloat64Converter : public IColumnConverter {
22
+ public:
23
+ explicit NumpyFloat64Converter(ArrowArrayView* array, PyObject* context);
24
+
25
+ PyObject* toPyObject(int64_t rowIndex) const override;
26
+
27
+ private:
28
+ ArrowArrayView* m_array;
29
+
30
+ PyObject* m_context;
31
+ };
32
+
33
+ } // namespace sf
34
+
35
+ #endif // PC_FLOATCONVERTER_HPP
@@ -0,0 +1,17 @@
1
+ #ifndef PC_ICOLUMNCONVERTER_HPP
2
+ #define PC_ICOLUMNCONVERTER_HPP
3
+
4
+ #include "Python/Common.hpp"
5
+
6
+ namespace sf {
7
+
8
+ class IColumnConverter {
9
+ public:
10
+ IColumnConverter() = default;
11
+ virtual ~IColumnConverter() = default;
12
+ // The caller is responsible for calling DECREF on the returned pointer
13
+ virtual PyObject* toPyObject(int64_t rowIndex) const = 0;
14
+ };
15
+ } // namespace sf
16
+
17
+ #endif // PC_ICOLUMNCONVERTER_HPP
@@ -0,0 +1,23 @@
1
+ #include "IntConverter.hpp"
2
+
3
+ namespace sf {
4
+ /** this file is here for future use and if this is useless at the end, it will
5
+ * be removed */
6
+
7
+ PyObject* IntConverter::toPyObject(int64_t rowIndex) const {
8
+ if (ArrowArrayViewIsNull(m_array, rowIndex)) {
9
+ Py_RETURN_NONE;
10
+ }
11
+ int64_t val = ArrowArrayViewGetIntUnsafe(m_array, rowIndex);
12
+ return pyLongForward(val);
13
+ }
14
+
15
+ PyObject* NumpyIntConverter::toPyObject(int64_t rowIndex) const {
16
+ if (ArrowArrayViewIsNull(m_array, rowIndex)) {
17
+ Py_RETURN_NONE;
18
+ }
19
+ int64_t val = ArrowArrayViewGetIntUnsafe(m_array, rowIndex);
20
+ return PyObject_CallMethod(m_context, "FIXED_to_numpy_int64", "L", val);
21
+ }
22
+
23
+ } // namespace sf
@@ -0,0 +1,41 @@
1
+ #ifndef PC_INTCONVERTER_HPP
2
+ #define PC_INTCONVERTER_HPP
3
+
4
+ #include <memory>
5
+
6
+ #include "IColumnConverter.hpp"
7
+ #include "nanoarrow.h"
8
+ #include "nanoarrow.hpp"
9
+
10
+ namespace sf {
11
+
12
+ class IntConverter : public IColumnConverter {
13
+ public:
14
+ explicit IntConverter(ArrowArrayView* array) : m_array(array) {}
15
+
16
+ PyObject* pyLongForward(int64_t value) const { return PyLong_FromLongLong(value); }
17
+
18
+ PyObject* pyLongForward(int32_t value) const { return PyLong_FromLong(value); }
19
+
20
+ PyObject* toPyObject(int64_t rowIndex) const override;
21
+
22
+ private:
23
+ ArrowArrayView* m_array;
24
+ };
25
+
26
+ class NumpyIntConverter : public IColumnConverter {
27
+ public:
28
+ explicit NumpyIntConverter(ArrowArrayView* array, PyObject* context)
29
+ : m_array(array), m_context(context) {}
30
+
31
+ PyObject* toPyObject(int64_t rowIndex) const override;
32
+
33
+ private:
34
+ ArrowArrayView* m_array;
35
+
36
+ PyObject* m_context;
37
+ };
38
+
39
+ } // namespace sf
40
+
41
+ #endif // PC_INTCONVERTER_HPP
@@ -0,0 +1,65 @@
1
+ #include "IntervalConverter.hpp"
2
+
3
+ #include <memory>
4
+ #include <string>
5
+
6
+ #include "Python/Common.hpp"
7
+ #include "Python/Helpers.hpp"
8
+
9
+ namespace sf {
10
+
11
+ static constexpr char INTERVAL_DT_DECIMAL_TO_NUMPY_TIMEDELTA[] =
12
+ "INTERVAL_DAY_TIME_decimal_to_numpy_timedelta";
13
+ static constexpr char INTERVAL_DT_DECIMAL_TO_TIMEDELTA[] = "INTERVAL_DAY_TIME_decimal_to_timedelta";
14
+ static constexpr char INTERVAL_DT_INT_TO_NUMPY_TIMEDELTA[] =
15
+ "INTERVAL_DAY_TIME_int_to_numpy_timedelta";
16
+ static constexpr char INTERVAL_DT_INT_TO_TIMEDELTA[] = "INTERVAL_DAY_TIME_int_to_timedelta";
17
+ static constexpr char INTERVAL_YEAR_MONTH_TO_NUMPY_TIMEDELTA[] =
18
+ "INTERVAL_YEAR_MONTH_to_numpy_timedelta";
19
+ // Python timedelta does not support year-month intervals. Use ANSI SQL
20
+ // formatted string instead.
21
+ static constexpr char INTERVAL_YEAR_MONTH_TO_STR[] = "INTERVAL_YEAR_MONTH_to_str";
22
+
23
+ IntervalYearMonthConverter::IntervalYearMonthConverter(ArrowArrayView* array, PyObject* context, bool useNumpy, int scale)
24
+ : m_array(array), m_context(context), m_scale(scale) {
25
+ m_method = useNumpy ? INTERVAL_YEAR_MONTH_TO_NUMPY_TIMEDELTA : INTERVAL_YEAR_MONTH_TO_STR;
26
+ }
27
+
28
+ PyObject* IntervalYearMonthConverter::toPyObject(int64_t rowIndex) const {
29
+ if (ArrowArrayViewIsNull(m_array, rowIndex)) {
30
+ Py_RETURN_NONE;
31
+ }
32
+ int64_t val = ArrowArrayViewGetIntUnsafe(m_array, rowIndex);
33
+ return PyObject_CallMethod(m_context, m_method, "Li", val, m_scale);
34
+ }
35
+
36
+ IntervalDayTimeConverterInt::IntervalDayTimeConverterInt(ArrowArrayView* array, PyObject* context,
37
+ bool useNumpy)
38
+ : m_array(array), m_context(context) {
39
+ m_method = useNumpy ? INTERVAL_DT_INT_TO_NUMPY_TIMEDELTA : INTERVAL_DT_INT_TO_TIMEDELTA;
40
+ }
41
+
42
+ PyObject* IntervalDayTimeConverterInt::toPyObject(int64_t rowIndex) const {
43
+ if (ArrowArrayViewIsNull(m_array, rowIndex)) {
44
+ Py_RETURN_NONE;
45
+ }
46
+ int64_t val = ArrowArrayViewGetIntUnsafe(m_array, rowIndex);
47
+ return PyObject_CallMethod(m_context, m_method, "L", val);
48
+ }
49
+
50
+ IntervalDayTimeConverterDecimal::IntervalDayTimeConverterDecimal(ArrowArrayView* array,
51
+ PyObject* context, bool useNumpy)
52
+ : m_array(array), m_context(context) {
53
+ m_method = useNumpy ? INTERVAL_DT_DECIMAL_TO_NUMPY_TIMEDELTA : INTERVAL_DT_DECIMAL_TO_TIMEDELTA;
54
+ }
55
+
56
+ PyObject* IntervalDayTimeConverterDecimal::toPyObject(int64_t rowIndex) const {
57
+ if (ArrowArrayViewIsNull(m_array, rowIndex)) {
58
+ Py_RETURN_NONE;
59
+ }
60
+ int64_t bytes_start = 16 * (m_array->array->offset + rowIndex);
61
+ const char* ptr_start = m_array->buffer_views[1].data.as_char;
62
+ PyObject* int128_bytes = PyBytes_FromStringAndSize(&(ptr_start[bytes_start]), 16);
63
+ return PyObject_CallMethod(m_context, m_method, "S", int128_bytes);
64
+ }
65
+ } // namespace sf
@@ -0,0 +1,54 @@
1
+ #ifndef PC_INTERVALCONVERTER_HPP
2
+ #define PC_INTERVALCONVERTER_HPP
3
+
4
+ #include <memory>
5
+
6
+ #include "IColumnConverter.hpp"
7
+ #include "nanoarrow.h"
8
+ #include "nanoarrow.hpp"
9
+
10
+ namespace sf {
11
+
12
+ class IntervalYearMonthConverter : public IColumnConverter {
13
+ public:
14
+ explicit IntervalYearMonthConverter(ArrowArrayView* array, PyObject* context, bool useNumpy, int scale);
15
+ virtual ~IntervalYearMonthConverter() = default;
16
+
17
+ PyObject* toPyObject(int64_t rowIndex) const override;
18
+
19
+ private:
20
+ ArrowArrayView* m_array;
21
+ PyObject* m_context;
22
+ const char* m_method;
23
+ int m_scale;
24
+ };
25
+
26
+ class IntervalDayTimeConverterInt : public IColumnConverter {
27
+ public:
28
+ explicit IntervalDayTimeConverterInt(ArrowArrayView* array, PyObject* context, bool useNumpy);
29
+ virtual ~IntervalDayTimeConverterInt() = default;
30
+
31
+ PyObject* toPyObject(int64_t rowIndex) const override;
32
+
33
+ private:
34
+ ArrowArrayView* m_array;
35
+ PyObject* m_context;
36
+ const char* m_method;
37
+ };
38
+
39
+ class IntervalDayTimeConverterDecimal : public IColumnConverter {
40
+ public:
41
+ explicit IntervalDayTimeConverterDecimal(ArrowArrayView* array, PyObject* context, bool useNumpy);
42
+ virtual ~IntervalDayTimeConverterDecimal() = default;
43
+
44
+ PyObject* toPyObject(int64_t rowIndex) const override;
45
+
46
+ private:
47
+ ArrowArrayView* m_array;
48
+ PyObject* m_context;
49
+ const char* m_method;
50
+ };
51
+
52
+ } // namespace sf
53
+
54
+ #endif // PC_INTERVALCONVERTER_HPP