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.
- snowflake/connector/__init__.py +148 -0
- snowflake/connector/_common/__init__.py +0 -0
- snowflake/connector/_common/extras.py +134 -0
- snowflake/connector/_common/telemetry.py +221 -0
- snowflake/connector/_common/wif_util.py +92 -0
- snowflake/connector/_core/sf_core_python.cp315-win_amd64.pyd +0 -0
- snowflake/connector/_core/sf_core_python.pyi +79 -0
- snowflake/connector/_internal/__init__.py +6 -0
- snowflake/connector/_internal/_private_key_helper.py +31 -0
- snowflake/connector/_internal/api_client/__init__.py +93 -0
- snowflake/connector/_internal/api_client/bridge.py +41 -0
- snowflake/connector/_internal/api_client/client_api.py +976 -0
- snowflake/connector/_internal/arrow.py +47 -0
- snowflake/connector/_internal/arrow_context.py +240 -0
- snowflake/connector/_internal/arrow_stream_async.py +266 -0
- snowflake/connector/_internal/arrow_stream_iterator.cp311-win_amd64.pyd +0 -0
- snowflake/connector/_internal/arrow_stream_iterator.cp312-win_amd64.pyd +0 -0
- snowflake/connector/_internal/arrow_stream_iterator.cp313-win_amd64.pyd +0 -0
- snowflake/connector/_internal/arrow_stream_iterator.cp314-win_amd64.pyd +0 -0
- snowflake/connector/_internal/arrow_stream_iterator.cp314t-win_amd64.pyd +0 -0
- snowflake/connector/_internal/arrow_stream_iterator.cp315-win_amd64.pyd +0 -0
- snowflake/connector/_internal/arrow_stream_iterator.pyi +42 -0
- snowflake/connector/_internal/arrow_stream_utils.py +171 -0
- snowflake/connector/_internal/authenticator_type.py +53 -0
- snowflake/connector/_internal/backward_compatibility.py +245 -0
- snowflake/connector/_internal/binding_converters.py +741 -0
- snowflake/connector/_internal/config_utils.py +71 -0
- snowflake/connector/_internal/connection/__init__.py +39 -0
- snowflake/connector/_internal/connection/connection.py +616 -0
- snowflake/connector/_internal/connection/connection_types.py +13 -0
- snowflake/connector/_internal/connection/constants.py +25 -0
- snowflake/connector/_internal/connection/decorators.py +31 -0
- snowflake/connector/_internal/connection/freezable_proxy.py +104 -0
- snowflake/connector/_internal/connection/queries.py +10 -0
- snowflake/connector/_internal/connection_config_mixin.py +755 -0
- snowflake/connector/_internal/cursor/__init__.py +25 -0
- snowflake/connector/_internal/cursor/base.py +732 -0
- snowflake/connector/_internal/cursor/cursor_types.py +13 -0
- snowflake/connector/_internal/cursor/decorators.py +56 -0
- snowflake/connector/_internal/cursor/query_result.py +202 -0
- snowflake/connector/_internal/cursor/query_result_waiter.py +98 -0
- snowflake/connector/_internal/cursor/result_metadata.py +255 -0
- snowflake/connector/_internal/cursor/result_set_wrapper.py +66 -0
- snowflake/connector/_internal/decorators.py +539 -0
- snowflake/connector/_internal/error_kinds.py +111 -0
- snowflake/connector/_internal/errorcode.py +35 -0
- snowflake/connector/_internal/errorhandler.py +278 -0
- snowflake/connector/_internal/fips.py +28 -0
- snowflake/connector/_internal/logging/__init__.py +52 -0
- snowflake/connector/_internal/logging/config.py +134 -0
- snowflake/connector/_internal/logging/core_logger.py +218 -0
- snowflake/connector/_internal/logging/native_extension_logger.py +144 -0
- snowflake/connector/_internal/logout_config_mapping.py +187 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/ArrayConverter.cpp +57 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/ArrayConverter.hpp +29 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/ArrowTableConverter.cpp +943 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/ArrowTableConverter.hpp +63 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/BinaryConverter.cpp +18 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/BinaryConverter.hpp +26 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/BooleanConverter.cpp +21 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/BooleanConverter.hpp +23 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/CArrowIterator.cpp +118 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/CArrowIterator.hpp +116 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/CArrowStreamIterator.cpp +323 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/CArrowStreamIterator.hpp +133 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/CArrowStreamTableIterator.cpp +275 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/CArrowStreamTableIterator.hpp +168 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/ConverterUtil.cpp +439 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/ConverterUtil.hpp +30 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/DateConverter.cpp +48 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/DateConverter.hpp +46 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/DecFloatConverter.cpp +76 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/DecFloatConverter.hpp +35 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/DecimalConverter.cpp +90 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/DecimalConverter.hpp +63 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/FixedSizeListConverter.cpp +62 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/FixedSizeListConverter.hpp +28 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/FloatConverter.cpp +29 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/FloatConverter.hpp +35 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/IColumnConverter.hpp +17 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/IntConverter.cpp +23 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/IntConverter.hpp +41 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/IntervalConverter.cpp +65 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/IntervalConverter.hpp +54 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/LICENSE.txt +209 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/MapConverter.cpp +79 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/MapConverter.hpp +30 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/ObjectConverter.cpp +52 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/ObjectConverter.hpp +29 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/Python/Common.cpp +8 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/Python/Common.hpp +117 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/Python/Helpers.cpp +54 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/Python/Helpers.hpp +34 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/SnowflakeType.cpp +33 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/SnowflakeType.hpp +48 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/StringConverter.cpp +18 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/StringConverter.hpp +26 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/TimeConverter.cpp +39 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/TimeConverter.hpp +31 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/TimeStampConverter.cpp +326 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/TimeStampConverter.hpp +138 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/Util/macros.hpp +14 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/Util/time.cpp +65 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/Util/time.hpp +68 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/arrow_stream_iterator.cpp +13278 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/arrow_stream_iterator.pyx +204 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/flatcc_accessors.h +109 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/flatcc_alloc.h +125 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/flatcc_assert.h +45 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/flatcc_builder.h +1914 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/flatcc_emitter.h +208 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/flatcc_endian.h +128 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/flatcc_epilogue.h +7 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/flatcc_flatbuffers.h +58 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/flatcc_identifier.h +144 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/flatcc_iov.h +31 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/flatcc_prologue.h +8 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/flatcc_refmap.h +144 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/flatcc_rtconfig.h +160 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/flatcc_types.h +98 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/flatcc_verifier.h +243 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/portable/flatcc_portable.h +14 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/portable/paligned_alloc.h +207 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/portable/pattributes.h +80 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/portable/pdiagnostic.h +83 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/portable/pdiagnostic_pop.h +20 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/portable/pdiagnostic_push.h +51 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/portable/pendian.h +201 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/portable/pendian_detect.h +108 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/portable/pinline.h +19 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/portable/pinttypes.h +52 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/portable/portable.h +2 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/portable/portable_basic.h +25 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/portable/pstatic_assert.h +67 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/portable/pstdalign.h +164 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/portable/pstdint.h +926 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/portable/punaligned.h +182 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/portable/pversion.h +6 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc/portable/pwarnings.h +52 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/flatcc.c +3052 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/nanoarrow.c +3019 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/nanoarrow.h +3354 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/nanoarrow.hpp +344 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/nanoarrow_ipc.c +29305 -0
- snowflake/connector/_internal/nanoarrow_cpp/ArrowIterator/nanoarrow_ipc.h +381 -0
- snowflake/connector/_internal/nanoarrow_cpp/Logging/logging.cpp +108 -0
- snowflake/connector/_internal/nanoarrow_cpp/Logging/logging.hpp +47 -0
- snowflake/connector/_internal/nanoarrow_cpp/scripts/.clang-format +8 -0
- snowflake/connector/_internal/nanoarrow_cpp/scripts/format.sh +8 -0
- snowflake/connector/_internal/protobuf_gen/__init__.py +0 -0
- snowflake/connector/_internal/protobuf_gen/database_driver_v1_pb2.py +408 -0
- snowflake/connector/_internal/protobuf_gen/database_driver_v1_pb2.pyi +4487 -0
- snowflake/connector/_internal/protobuf_gen/database_driver_v1_services.py +2088 -0
- snowflake/connector/_internal/protobuf_gen/proto_exception.py +17 -0
- snowflake/connector/_internal/result_batch.py +150 -0
- snowflake/connector/_internal/snowflake_restful.py +222 -0
- snowflake/connector/_internal/snowpark_backcompat_helpers.py +31 -0
- snowflake/connector/_internal/sqlstate.py +11 -0
- snowflake/connector/_internal/statement_utils.py +207 -0
- snowflake/connector/_internal/text_utils.py +112 -0
- snowflake/connector/_internal/type_codes.py +139 -0
- snowflake/connector/_internal/utils.py +65 -0
- snowflake/connector/_internal/write_pandas_operation.py +657 -0
- snowflake/connector/aio/README.md +168 -0
- snowflake/connector/aio/__init__.py +37 -0
- snowflake/connector/aio/connection/__init__.py +17 -0
- snowflake/connector/aio/connection/_connection.py +506 -0
- snowflake/connector/aio/cursor/__init__.py +35 -0
- snowflake/connector/aio/cursor/_base.py +1034 -0
- snowflake/connector/aio/cursor/_dict_cursor.py +78 -0
- snowflake/connector/aio/cursor/_result_set_wrapper.py +35 -0
- snowflake/connector/aio/cursor/_snowflake_cursor.py +72 -0
- snowflake/connector/aio/pandas_tools.py +279 -0
- snowflake/connector/aio/result_batch.py +165 -0
- snowflake/connector/auth/__init__.py +0 -0
- snowflake/connector/auth/workload_identity.py +5 -0
- snowflake/connector/compat.py +22 -0
- snowflake/connector/config_manager.py +392 -0
- snowflake/connector/connection/__init__.py +30 -0
- snowflake/connector/connection/_connection.py +641 -0
- snowflake/connector/connection_config.py +517 -0
- snowflake/connector/constants.py +52 -0
- snowflake/connector/cursor/__init__.py +37 -0
- snowflake/connector/cursor/_base.py +1169 -0
- snowflake/connector/cursor/_chunked_download_reader.py +75 -0
- snowflake/connector/cursor/_dict_cursor.py +78 -0
- snowflake/connector/cursor/_result_set_wrapper.py +35 -0
- snowflake/connector/cursor/_snowflake_cursor.py +72 -0
- snowflake/connector/description.py +7 -0
- snowflake/connector/errors.py +492 -0
- snowflake/connector/network.py +71 -0
- snowflake/connector/pandas_tools.py +191 -0
- snowflake/connector/py.typed +0 -0
- snowflake/connector/result_batch.py +216 -0
- snowflake/connector/telemetry.py +40 -0
- snowflake/connector/time_util.py +11 -0
- snowflake/connector/types.py +134 -0
- snowflake/connector/util_text.py +3 -0
- snowflake/connector/version.py +23 -0
- snowflake_connector_python-5.2.0.dist-info/DELVEWHEEL +2 -0
- snowflake_connector_python-5.2.0.dist-info/METADATA +190 -0
- snowflake_connector_python-5.2.0.dist-info/RECORD +204 -0
- snowflake_connector_python-5.2.0.dist-info/WHEEL +4 -0
- snowflake_connector_python.libs/msvcp140-a4c2229bdc2a2a630acdc095b4d86008.dll +0 -0
|
@@ -0,0 +1,439 @@
|
|
|
1
|
+
#include "ConverterUtil.hpp"
|
|
2
|
+
|
|
3
|
+
#include <memory>
|
|
4
|
+
#include <string>
|
|
5
|
+
|
|
6
|
+
#include "ArrayConverter.hpp"
|
|
7
|
+
#include "BinaryConverter.hpp"
|
|
8
|
+
#include "BooleanConverter.hpp"
|
|
9
|
+
#include "CArrowIterator.hpp"
|
|
10
|
+
#include "DateConverter.hpp"
|
|
11
|
+
#include "DecFloatConverter.hpp"
|
|
12
|
+
#include "DecimalConverter.hpp"
|
|
13
|
+
#include "FixedSizeListConverter.hpp"
|
|
14
|
+
#include "FloatConverter.hpp"
|
|
15
|
+
#include "IntConverter.hpp"
|
|
16
|
+
#include "IntervalConverter.hpp"
|
|
17
|
+
#include "MapConverter.hpp"
|
|
18
|
+
#include "ObjectConverter.hpp"
|
|
19
|
+
#include "SnowflakeType.hpp"
|
|
20
|
+
#include "StringConverter.hpp"
|
|
21
|
+
#include "TimeConverter.hpp"
|
|
22
|
+
#include "TimeStampConverter.hpp"
|
|
23
|
+
#include "nanoarrow.hpp"
|
|
24
|
+
|
|
25
|
+
namespace sf {
|
|
26
|
+
|
|
27
|
+
std::shared_ptr<sf::IColumnConverter> getConverterFromSchema(ArrowSchema* schema,
|
|
28
|
+
ArrowArrayView* array,
|
|
29
|
+
PyObject* context, bool useNumpy,
|
|
30
|
+
Logger* logger) {
|
|
31
|
+
std::shared_ptr<sf::IColumnConverter> converter = nullptr;
|
|
32
|
+
ArrowSchemaView schemaView;
|
|
33
|
+
ArrowError error;
|
|
34
|
+
int returnCode = 0;
|
|
35
|
+
|
|
36
|
+
returnCode = ArrowSchemaViewInit(&schemaView, schema, &error);
|
|
37
|
+
SF_CHECK_ARROW_RC_AND_RETURN(returnCode, nullptr,
|
|
38
|
+
"[Snowflake Exception] error initializing "
|
|
39
|
+
"ArrowSchemaView: %s, error code: %d",
|
|
40
|
+
ArrowErrorMessage(&error), returnCode);
|
|
41
|
+
|
|
42
|
+
struct ArrowStringView snowflakeLogicalType = ArrowCharView(nullptr);
|
|
43
|
+
const char* metadata = schema->metadata;
|
|
44
|
+
returnCode = ArrowMetadataGetValue(metadata, ArrowCharView("logicalType"), &snowflakeLogicalType);
|
|
45
|
+
|
|
46
|
+
SF_CHECK_ARROW_RC_AND_RETURN(returnCode, nullptr,
|
|
47
|
+
"[Snowflake Exception] error getting 'logicalType' from "
|
|
48
|
+
"Arrow metadata, error code: %d",
|
|
49
|
+
returnCode);
|
|
50
|
+
|
|
51
|
+
SnowflakeType::Type sfType = SnowflakeType::snowflakeTypeFromString(
|
|
52
|
+
std::string(snowflakeLogicalType.data, snowflakeLogicalType.size_bytes));
|
|
53
|
+
|
|
54
|
+
switch (sfType) {
|
|
55
|
+
case SnowflakeType::Type::FIXED: {
|
|
56
|
+
struct ArrowStringView scaleString = ArrowCharView(nullptr);
|
|
57
|
+
struct ArrowStringView precisionString = ArrowCharView(nullptr);
|
|
58
|
+
int scale = 0;
|
|
59
|
+
int precision = 38;
|
|
60
|
+
if (metadata != nullptr) {
|
|
61
|
+
returnCode = ArrowMetadataGetValue(metadata, ArrowCharView("scale"), &scaleString);
|
|
62
|
+
SF_CHECK_ARROW_RC_AND_RETURN(returnCode, nullptr,
|
|
63
|
+
"[Snowflake Exception] error getting 'scale' from "
|
|
64
|
+
"Arrow metadata, error code: %d",
|
|
65
|
+
returnCode);
|
|
66
|
+
returnCode = ArrowMetadataGetValue(metadata, ArrowCharView("precision"), &precisionString);
|
|
67
|
+
SF_CHECK_ARROW_RC_AND_RETURN(returnCode, nullptr,
|
|
68
|
+
"[Snowflake Exception] error getting 'precision' "
|
|
69
|
+
"from Arrow metadata, error code: %d",
|
|
70
|
+
returnCode);
|
|
71
|
+
scale = std::stoi(std::string(scaleString.data, scaleString.size_bytes));
|
|
72
|
+
precision = std::stoi(std::string(precisionString.data, precisionString.size_bytes));
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
switch (schemaView.type) {
|
|
76
|
+
#define _SF_INIT_FIXED_CONVERTER(ARROW_TYPE) \
|
|
77
|
+
case ArrowType::ARROW_TYPE: { \
|
|
78
|
+
if (scale > 0) { \
|
|
79
|
+
if (useNumpy) { \
|
|
80
|
+
converter = std::make_shared<sf::NumpyDecimalConverter>(array, precision, scale, context); \
|
|
81
|
+
} else { \
|
|
82
|
+
converter = std::make_shared<sf::DecimalFromIntConverter>(array, precision, scale); \
|
|
83
|
+
} \
|
|
84
|
+
} else { \
|
|
85
|
+
if (useNumpy) { \
|
|
86
|
+
converter = std::make_shared<sf::NumpyIntConverter>(array, context); \
|
|
87
|
+
} else { \
|
|
88
|
+
converter = std::make_shared<sf::IntConverter>(array); \
|
|
89
|
+
} \
|
|
90
|
+
} \
|
|
91
|
+
break; \
|
|
92
|
+
}
|
|
93
|
+
_SF_INIT_FIXED_CONVERTER(NANOARROW_TYPE_INT8)
|
|
94
|
+
_SF_INIT_FIXED_CONVERTER(NANOARROW_TYPE_INT16)
|
|
95
|
+
_SF_INIT_FIXED_CONVERTER(NANOARROW_TYPE_INT32)
|
|
96
|
+
_SF_INIT_FIXED_CONVERTER(NANOARROW_TYPE_INT64)
|
|
97
|
+
#undef _SF_INIT_FIXED_CONVERTER
|
|
98
|
+
|
|
99
|
+
case ArrowType::NANOARROW_TYPE_DECIMAL128: {
|
|
100
|
+
converter = std::make_shared<sf::DecimalFromDecimalConverter>(context, array, scale);
|
|
101
|
+
break;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
default: {
|
|
105
|
+
std::string errorInfo = Logger::formatString(
|
|
106
|
+
"[Snowflake Exception] unknown arrow internal data type(%d) "
|
|
107
|
+
"for FIXED data",
|
|
108
|
+
NANOARROW_TYPE_ENUM_STRING[schemaView.type]);
|
|
109
|
+
logger->error(__FILE__, __func__, __LINE__, errorInfo.c_str());
|
|
110
|
+
PyErr_SetString(PyExc_Exception, errorInfo.c_str());
|
|
111
|
+
break;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
break;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
case SnowflakeType::Type::ANY:
|
|
118
|
+
case SnowflakeType::Type::CHAR:
|
|
119
|
+
case SnowflakeType::Type::TEXT:
|
|
120
|
+
case SnowflakeType::Type::VARIANT: {
|
|
121
|
+
converter = std::make_shared<sf::StringConverter>(array);
|
|
122
|
+
break;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
case SnowflakeType::Type::BOOLEAN: {
|
|
126
|
+
converter = std::make_shared<sf::BooleanConverter>(array);
|
|
127
|
+
break;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
case SnowflakeType::Type::REAL: {
|
|
131
|
+
if (useNumpy) {
|
|
132
|
+
converter = std::make_shared<sf::NumpyFloat64Converter>(array, context);
|
|
133
|
+
} else {
|
|
134
|
+
converter = std::make_shared<sf::FloatConverter>(array);
|
|
135
|
+
}
|
|
136
|
+
break;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
case SnowflakeType::Type::DATE: {
|
|
140
|
+
if (useNumpy) {
|
|
141
|
+
converter = std::make_shared<sf::NumpyDateConverter>(array, context);
|
|
142
|
+
} else {
|
|
143
|
+
converter = std::make_shared<sf::DateConverter>(array);
|
|
144
|
+
}
|
|
145
|
+
break;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
case SnowflakeType::Type::BINARY: {
|
|
149
|
+
converter = std::make_shared<sf::BinaryConverter>(array);
|
|
150
|
+
break;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
case SnowflakeType::Type::TIME: {
|
|
154
|
+
int scale = 9;
|
|
155
|
+
if (metadata != nullptr) {
|
|
156
|
+
struct ArrowStringView scaleString = ArrowCharView(nullptr);
|
|
157
|
+
returnCode = ArrowMetadataGetValue(metadata, ArrowCharView("scale"), &scaleString);
|
|
158
|
+
SF_CHECK_ARROW_RC_AND_RETURN(returnCode, nullptr,
|
|
159
|
+
"[Snowflake Exception] error getting 'scale' from "
|
|
160
|
+
"Arrow metadata, error code: %d",
|
|
161
|
+
returnCode);
|
|
162
|
+
scale = std::stoi(std::string(scaleString.data, scaleString.size_bytes));
|
|
163
|
+
}
|
|
164
|
+
switch (schemaView.type) {
|
|
165
|
+
case NANOARROW_TYPE_INT32:
|
|
166
|
+
case NANOARROW_TYPE_INT64: {
|
|
167
|
+
converter = std::make_shared<sf::TimeConverter>(array, scale);
|
|
168
|
+
break;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
default: {
|
|
172
|
+
std::string errorInfo = Logger::formatString(
|
|
173
|
+
"[Snowflake Exception] unknown arrow internal data type(%d) "
|
|
174
|
+
"for TIME data",
|
|
175
|
+
NANOARROW_TYPE_ENUM_STRING[schemaView.type]);
|
|
176
|
+
logger->error(__FILE__, __func__, __LINE__, errorInfo.c_str());
|
|
177
|
+
PyErr_SetString(PyExc_Exception, errorInfo.c_str());
|
|
178
|
+
return nullptr;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
break;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
case SnowflakeType::Type::TIMESTAMP_NTZ: {
|
|
185
|
+
int scale = 9;
|
|
186
|
+
if (metadata != nullptr) {
|
|
187
|
+
struct ArrowStringView scaleString = ArrowCharView(nullptr);
|
|
188
|
+
returnCode = ArrowMetadataGetValue(metadata, ArrowCharView("scale"), &scaleString);
|
|
189
|
+
SF_CHECK_ARROW_RC_AND_RETURN(returnCode, nullptr,
|
|
190
|
+
"[Snowflake Exception] error getting 'scale' from "
|
|
191
|
+
"Arrow metadata, error code: %d",
|
|
192
|
+
returnCode);
|
|
193
|
+
scale = std::stoi(std::string(scaleString.data, scaleString.size_bytes));
|
|
194
|
+
}
|
|
195
|
+
switch (schemaView.type) {
|
|
196
|
+
case NANOARROW_TYPE_INT64: {
|
|
197
|
+
if (useNumpy) {
|
|
198
|
+
converter =
|
|
199
|
+
std::make_shared<sf::NumpyOneFieldTimeStampNTZConverter>(array, scale, context);
|
|
200
|
+
} else {
|
|
201
|
+
converter = std::make_shared<sf::OneFieldTimeStampNTZConverter>(array, scale, context);
|
|
202
|
+
}
|
|
203
|
+
break;
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
case NANOARROW_TYPE_STRUCT: {
|
|
207
|
+
if (useNumpy) {
|
|
208
|
+
converter = std::make_shared<sf::NumpyTwoFieldTimeStampNTZConverter>(array, &schemaView,
|
|
209
|
+
scale, context);
|
|
210
|
+
} else {
|
|
211
|
+
converter = std::make_shared<sf::TwoFieldTimeStampNTZConverter>(array, &schemaView,
|
|
212
|
+
scale, context);
|
|
213
|
+
}
|
|
214
|
+
break;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
default: {
|
|
218
|
+
std::string errorInfo = Logger::formatString(
|
|
219
|
+
"[Snowflake Exception] unknown arrow internal data type(%d) "
|
|
220
|
+
"for TIMESTAMP_NTZ data",
|
|
221
|
+
NANOARROW_TYPE_ENUM_STRING[schemaView.type]);
|
|
222
|
+
logger->error(__FILE__, __func__, __LINE__, errorInfo.c_str());
|
|
223
|
+
PyErr_SetString(PyExc_Exception, errorInfo.c_str());
|
|
224
|
+
break;
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
break;
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
case SnowflakeType::Type::TIMESTAMP_LTZ: {
|
|
231
|
+
int scale = 9;
|
|
232
|
+
if (metadata != nullptr) {
|
|
233
|
+
struct ArrowStringView scaleString = ArrowCharView(nullptr);
|
|
234
|
+
returnCode = ArrowMetadataGetValue(metadata, ArrowCharView("scale"), &scaleString);
|
|
235
|
+
SF_CHECK_ARROW_RC_AND_RETURN(returnCode, nullptr,
|
|
236
|
+
"[Snowflake Exception] error getting 'scale' from "
|
|
237
|
+
"Arrow metadata, error code: %d",
|
|
238
|
+
returnCode);
|
|
239
|
+
scale = std::stoi(std::string(scaleString.data, scaleString.size_bytes));
|
|
240
|
+
}
|
|
241
|
+
switch (schemaView.type) {
|
|
242
|
+
case NANOARROW_TYPE_INT64: {
|
|
243
|
+
converter = std::make_shared<sf::OneFieldTimeStampLTZConverter>(array, scale, context);
|
|
244
|
+
break;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
case NANOARROW_TYPE_STRUCT: {
|
|
248
|
+
converter = std::make_shared<sf::TwoFieldTimeStampLTZConverter>(array, &schemaView, scale,
|
|
249
|
+
context);
|
|
250
|
+
break;
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
default: {
|
|
254
|
+
std::string errorInfo = Logger::formatString(
|
|
255
|
+
"[Snowflake Exception] unknown arrow internal data type(%d) "
|
|
256
|
+
"for TIMESTAMP_LTZ data",
|
|
257
|
+
NANOARROW_TYPE_ENUM_STRING[schemaView.type]);
|
|
258
|
+
logger->error(__FILE__, __func__, __LINE__, errorInfo.c_str());
|
|
259
|
+
PyErr_SetString(PyExc_Exception, errorInfo.c_str());
|
|
260
|
+
break;
|
|
261
|
+
}
|
|
262
|
+
}
|
|
263
|
+
break;
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
case SnowflakeType::Type::TIMESTAMP_TZ: {
|
|
267
|
+
struct ArrowStringView scaleString = ArrowCharView(nullptr);
|
|
268
|
+
struct ArrowStringView byteLengthString = ArrowCharView(nullptr);
|
|
269
|
+
int scale = 9;
|
|
270
|
+
int byteLength = 16;
|
|
271
|
+
if (metadata != nullptr) {
|
|
272
|
+
returnCode = ArrowMetadataGetValue(metadata, ArrowCharView("scale"), &scaleString);
|
|
273
|
+
SF_CHECK_ARROW_RC_AND_RETURN(returnCode, nullptr,
|
|
274
|
+
"[Snowflake Exception] error getting 'scale' from "
|
|
275
|
+
"Arrow metadata, error code: %d",
|
|
276
|
+
returnCode);
|
|
277
|
+
returnCode =
|
|
278
|
+
ArrowMetadataGetValue(metadata, ArrowCharView("byteLength"), &byteLengthString);
|
|
279
|
+
SF_CHECK_ARROW_RC_AND_RETURN(returnCode, nullptr,
|
|
280
|
+
"[Snowflake Exception] error getting 'byteLength' "
|
|
281
|
+
"from Arrow metadata, error code: %d",
|
|
282
|
+
returnCode);
|
|
283
|
+
scale = std::stoi(std::string(scaleString.data, scaleString.size_bytes));
|
|
284
|
+
|
|
285
|
+
// Byte Length may be unset if TIMESTAMP_TZ is the child of a structured
|
|
286
|
+
// type. In this case rely on the default value.
|
|
287
|
+
if (byteLengthString.data != nullptr) {
|
|
288
|
+
byteLength = std::stoi(std::string(byteLengthString.data, byteLengthString.size_bytes));
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
switch (byteLength) {
|
|
292
|
+
case 8: {
|
|
293
|
+
converter = std::make_shared<sf::TwoFieldTimeStampTZConverter>(array, &schemaView, scale,
|
|
294
|
+
context);
|
|
295
|
+
break;
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
case 16: {
|
|
299
|
+
converter = std::make_shared<sf::ThreeFieldTimeStampTZConverter>(array, &schemaView,
|
|
300
|
+
scale, context);
|
|
301
|
+
break;
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
default: {
|
|
305
|
+
std::string errorInfo = Logger::formatString(
|
|
306
|
+
"[Snowflake Exception] unknown arrow internal data type(%d) "
|
|
307
|
+
"for TIMESTAMP_TZ data",
|
|
308
|
+
NANOARROW_TYPE_ENUM_STRING[schemaView.type]);
|
|
309
|
+
logger->error(__FILE__, __func__, __LINE__, errorInfo.c_str());
|
|
310
|
+
PyErr_SetString(PyExc_Exception, errorInfo.c_str());
|
|
311
|
+
break;
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
break;
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
case SnowflakeType::Type::ARRAY: {
|
|
319
|
+
switch (schemaView.type) {
|
|
320
|
+
case NANOARROW_TYPE_STRING:
|
|
321
|
+
converter = std::make_shared<sf::StringConverter>(array);
|
|
322
|
+
break;
|
|
323
|
+
case NANOARROW_TYPE_LIST:
|
|
324
|
+
converter = std::make_shared<sf::ArrayConverter>(&schemaView, array, context, useNumpy);
|
|
325
|
+
break;
|
|
326
|
+
default: {
|
|
327
|
+
std::string errorInfo = Logger::formatString(
|
|
328
|
+
"[Snowflake Exception] unknown arrow internal data type(%d) "
|
|
329
|
+
"for ARRAY data in %s",
|
|
330
|
+
NANOARROW_TYPE_ENUM_STRING[schemaView.type], schemaView.schema->name);
|
|
331
|
+
logger->error(__FILE__, __func__, __LINE__, errorInfo.c_str());
|
|
332
|
+
PyErr_SetString(PyExc_Exception, errorInfo.c_str());
|
|
333
|
+
break;
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
break;
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
case SnowflakeType::Type::MAP: {
|
|
340
|
+
switch (schemaView.type) {
|
|
341
|
+
case NANOARROW_TYPE_STRING:
|
|
342
|
+
converter = std::make_shared<sf::StringConverter>(array);
|
|
343
|
+
break;
|
|
344
|
+
case NANOARROW_TYPE_MAP:
|
|
345
|
+
converter = std::make_shared<sf::MapConverter>(&schemaView, array, context, useNumpy);
|
|
346
|
+
break;
|
|
347
|
+
default: {
|
|
348
|
+
std::string errorInfo = Logger::formatString(
|
|
349
|
+
"[Snowflake Exception] unknown arrow internal data type(%s) "
|
|
350
|
+
"for MAP data in %s",
|
|
351
|
+
NANOARROW_TYPE_ENUM_STRING[schemaView.type], schemaView.schema->name);
|
|
352
|
+
logger->error(__FILE__, __func__, __LINE__, errorInfo.c_str());
|
|
353
|
+
PyErr_SetString(PyExc_Exception, errorInfo.c_str());
|
|
354
|
+
break;
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
break;
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
case SnowflakeType::Type::OBJECT: {
|
|
361
|
+
switch (schemaView.type) {
|
|
362
|
+
case NANOARROW_TYPE_STRING:
|
|
363
|
+
converter = std::make_shared<sf::StringConverter>(array);
|
|
364
|
+
break;
|
|
365
|
+
case NANOARROW_TYPE_STRUCT:
|
|
366
|
+
converter = std::make_shared<sf::ObjectConverter>(&schemaView, array, context, useNumpy);
|
|
367
|
+
break;
|
|
368
|
+
default: {
|
|
369
|
+
std::string errorInfo = Logger::formatString(
|
|
370
|
+
"[Snowflake Exception] unknown arrow internal data type(%d) "
|
|
371
|
+
"for OBJECT data in %s",
|
|
372
|
+
NANOARROW_TYPE_ENUM_STRING[schemaView.type], schemaView.schema->name);
|
|
373
|
+
logger->error(__FILE__, __func__, __LINE__, errorInfo.c_str());
|
|
374
|
+
PyErr_SetString(PyExc_Exception, errorInfo.c_str());
|
|
375
|
+
break;
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
break;
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
case SnowflakeType::Type::VECTOR: {
|
|
382
|
+
converter = std::make_shared<sf::FixedSizeListConverter>(array);
|
|
383
|
+
break;
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
case SnowflakeType::Type::DECFLOAT: {
|
|
387
|
+
converter = std::make_shared<sf::DecFloatConverter>(*array, schemaView, *context, useNumpy);
|
|
388
|
+
break;
|
|
389
|
+
}
|
|
390
|
+
|
|
391
|
+
case SnowflakeType::Type::INTERVAL_YEAR_MONTH: {
|
|
392
|
+
int scale = 0;
|
|
393
|
+
if (metadata != nullptr) {
|
|
394
|
+
ArrowStringView scaleString = ArrowCharView(nullptr);
|
|
395
|
+
returnCode = ArrowMetadataGetValue(metadata, ArrowCharView("scale"), &scaleString);
|
|
396
|
+
SF_CHECK_ARROW_RC_AND_RETURN(
|
|
397
|
+
returnCode, nullptr,
|
|
398
|
+
"[Snowflake Exception] error getting 'scale' from Arrow metadata, error code: %d", returnCode);
|
|
399
|
+
scale = std::stoi(std::string(scaleString.data, scaleString.size_bytes));
|
|
400
|
+
}
|
|
401
|
+
converter = std::make_shared<sf::IntervalYearMonthConverter>(array, context, useNumpy, scale);
|
|
402
|
+
break;
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
case SnowflakeType::Type::INTERVAL_DAY_TIME: {
|
|
406
|
+
switch (schemaView.type) {
|
|
407
|
+
case NANOARROW_TYPE_INT64:
|
|
408
|
+
converter = std::make_shared<sf::IntervalDayTimeConverterInt>(array, context, useNumpy);
|
|
409
|
+
break;
|
|
410
|
+
case NANOARROW_TYPE_DECIMAL128:
|
|
411
|
+
converter =
|
|
412
|
+
std::make_shared<sf::IntervalDayTimeConverterDecimal>(array, context, useNumpy);
|
|
413
|
+
break;
|
|
414
|
+
default: {
|
|
415
|
+
std::string errorInfo = Logger::formatString(
|
|
416
|
+
"[Snowflake Exception] unknown arrow internal data type(%d) "
|
|
417
|
+
"for INTERVAL_DAY_TIME data in %s",
|
|
418
|
+
NANOARROW_TYPE_ENUM_STRING[schemaView.type], schemaView.schema->name);
|
|
419
|
+
logger->error(__FILE__, __func__, __LINE__, errorInfo.c_str());
|
|
420
|
+
PyErr_SetString(PyExc_Exception, errorInfo.c_str());
|
|
421
|
+
break;
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
break;
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
default: {
|
|
428
|
+
std::string errorInfo =
|
|
429
|
+
Logger::formatString("[Snowflake Exception] unknown snowflake data type : %d", sfType);
|
|
430
|
+
logger->error(__FILE__, __func__, __LINE__, errorInfo.c_str());
|
|
431
|
+
PyErr_SetString(PyExc_Exception, errorInfo.c_str());
|
|
432
|
+
break;
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
return converter;
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
} // namespace sf
|
|
439
|
+
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
#ifndef PC_CONVERTERUTIL_HPP
|
|
2
|
+
#define PC_CONVERTERUTIL_HPP
|
|
3
|
+
|
|
4
|
+
#include <memory>
|
|
5
|
+
|
|
6
|
+
#include "IColumnConverter.hpp"
|
|
7
|
+
#include "logging.hpp"
|
|
8
|
+
#include "nanoarrow.h"
|
|
9
|
+
|
|
10
|
+
namespace sf {
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Factory function to create appropriate column converter based on Arrow schema.
|
|
14
|
+
*
|
|
15
|
+
* @param schema Arrow schema for the column
|
|
16
|
+
* @param array Arrow array view for the column data
|
|
17
|
+
* @param context Python context object for conversions
|
|
18
|
+
* @param useNumpy Whether to use numpy types for numeric data
|
|
19
|
+
* @param logger Logger instance for error reporting
|
|
20
|
+
* @return Shared pointer to column converter, or nullptr on error
|
|
21
|
+
*/
|
|
22
|
+
std::shared_ptr<sf::IColumnConverter> getConverterFromSchema(ArrowSchema* schema,
|
|
23
|
+
ArrowArrayView* array,
|
|
24
|
+
PyObject* context, bool useNumpy,
|
|
25
|
+
Logger* logger);
|
|
26
|
+
|
|
27
|
+
} // namespace sf
|
|
28
|
+
|
|
29
|
+
#endif // PC_CONVERTERUTIL_HPP
|
|
30
|
+
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
#include "DateConverter.hpp"
|
|
2
|
+
|
|
3
|
+
#include <memory>
|
|
4
|
+
#include <mutex>
|
|
5
|
+
|
|
6
|
+
#include "Python/Helpers.hpp"
|
|
7
|
+
|
|
8
|
+
namespace sf {
|
|
9
|
+
Logger* DateConverter::logger = new Logger("snowflake.connector.DateConverter");
|
|
10
|
+
|
|
11
|
+
py::UniqueRef& DateConverter::initPyDatetimeDate() {
|
|
12
|
+
static py::UniqueRef pyDatetimeDate;
|
|
13
|
+
// The empty check races when the GIL does not serialize this init.
|
|
14
|
+
static std::once_flag onceFlag;
|
|
15
|
+
std::call_once(onceFlag, []() {
|
|
16
|
+
py::UniqueRef pyDatetimeModule;
|
|
17
|
+
py::importPythonModule("datetime", pyDatetimeModule);
|
|
18
|
+
py::importFromModule(pyDatetimeModule, "date", pyDatetimeDate);
|
|
19
|
+
Py_XINCREF(pyDatetimeDate.get());
|
|
20
|
+
});
|
|
21
|
+
return pyDatetimeDate;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
DateConverter::DateConverter(ArrowArrayView* array)
|
|
25
|
+
: m_array(array), m_pyDatetimeDate(initPyDatetimeDate()) {}
|
|
26
|
+
|
|
27
|
+
PyObject* DateConverter::toPyObject(int64_t rowIndex) const {
|
|
28
|
+
if (ArrowArrayViewIsNull(m_array, rowIndex)) {
|
|
29
|
+
Py_RETURN_NONE;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
int64_t deltaDays = ArrowArrayViewGetIntUnsafe(m_array, rowIndex);
|
|
33
|
+
return PyObject_CallMethod(m_pyDatetimeDate.get(), "fromordinal", "i", epochDay + deltaDays);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
NumpyDateConverter::NumpyDateConverter(ArrowArrayView* array, PyObject* context)
|
|
37
|
+
: m_array(array), m_context(context) {}
|
|
38
|
+
|
|
39
|
+
PyObject* NumpyDateConverter::toPyObject(int64_t rowIndex) const {
|
|
40
|
+
if (ArrowArrayViewIsNull(m_array, rowIndex)) {
|
|
41
|
+
Py_RETURN_NONE;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
int64_t deltaDays = ArrowArrayViewGetIntUnsafe(m_array, rowIndex);
|
|
45
|
+
return PyObject_CallMethod(m_context, "DATE_to_numpy_datetime64", "i", deltaDays);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
} // namespace sf
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
#ifndef PC_DATECONVERTER_HPP
|
|
2
|
+
#define PC_DATECONVERTER_HPP
|
|
3
|
+
|
|
4
|
+
#include <memory>
|
|
5
|
+
|
|
6
|
+
#include "IColumnConverter.hpp"
|
|
7
|
+
#include "Python/Common.hpp"
|
|
8
|
+
#include "logging.hpp"
|
|
9
|
+
#include "nanoarrow.h"
|
|
10
|
+
|
|
11
|
+
namespace sf {
|
|
12
|
+
|
|
13
|
+
class DateConverter : public IColumnConverter {
|
|
14
|
+
public:
|
|
15
|
+
explicit DateConverter(ArrowArrayView* array);
|
|
16
|
+
|
|
17
|
+
PyObject* toPyObject(int64_t rowIndex) const override;
|
|
18
|
+
|
|
19
|
+
private:
|
|
20
|
+
static py::UniqueRef& initPyDatetimeDate();
|
|
21
|
+
|
|
22
|
+
ArrowArrayView* m_array;
|
|
23
|
+
|
|
24
|
+
/** from Python Ordinal to 1970-01-01 */
|
|
25
|
+
static constexpr int epochDay = 719163;
|
|
26
|
+
|
|
27
|
+
static Logger* logger;
|
|
28
|
+
|
|
29
|
+
py::UniqueRef& m_pyDatetimeDate;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
class NumpyDateConverter : public IColumnConverter {
|
|
33
|
+
public:
|
|
34
|
+
explicit NumpyDateConverter(ArrowArrayView* array, PyObject* context);
|
|
35
|
+
|
|
36
|
+
PyObject* toPyObject(int64_t rowIndex) const override;
|
|
37
|
+
|
|
38
|
+
private:
|
|
39
|
+
ArrowArrayView* m_array;
|
|
40
|
+
|
|
41
|
+
PyObject* m_context;
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
} // namespace sf
|
|
45
|
+
|
|
46
|
+
#endif // PC_DATECONVERTER_HPP
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
|
|
2
|
+
#include "DecFloatConverter.hpp"
|
|
3
|
+
|
|
4
|
+
#include <cstring>
|
|
5
|
+
#include <memory>
|
|
6
|
+
|
|
7
|
+
#include "Python/Helpers.hpp"
|
|
8
|
+
|
|
9
|
+
namespace sf {
|
|
10
|
+
|
|
11
|
+
Logger* DecFloatConverter::logger = new Logger("snowflake.connector.DecFloatConverter");
|
|
12
|
+
|
|
13
|
+
const std::string DecFloatConverter::FIELD_NAME_EXPONENT = "exponent";
|
|
14
|
+
const std::string DecFloatConverter::FIELD_NAME_SIGNIFICAND = "significand";
|
|
15
|
+
|
|
16
|
+
DecFloatConverter::DecFloatConverter(ArrowArrayView& array, ArrowSchemaView& schema,
|
|
17
|
+
PyObject& context, bool useNumpy)
|
|
18
|
+
: m_context(context),
|
|
19
|
+
m_array(array),
|
|
20
|
+
m_exponent(nullptr),
|
|
21
|
+
m_significand(nullptr),
|
|
22
|
+
m_useNumpy(useNumpy) {
|
|
23
|
+
if (schema.schema->n_children != 2) {
|
|
24
|
+
std::string errorInfo = Logger::formatString(
|
|
25
|
+
"[Snowflake Exception] arrow schema field number does not match, "
|
|
26
|
+
"expected 2 but got %d instead",
|
|
27
|
+
schema.schema->n_children);
|
|
28
|
+
logger->error(__FILE__, __func__, __LINE__, errorInfo.c_str());
|
|
29
|
+
PyErr_SetString(PyExc_Exception, errorInfo.c_str());
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
for (int i = 0; i < schema.schema->n_children; i += 1) {
|
|
33
|
+
ArrowSchema* c_schema = schema.schema->children[i];
|
|
34
|
+
if (std::strcmp(c_schema->name, DecFloatConverter::FIELD_NAME_EXPONENT.c_str()) == 0) {
|
|
35
|
+
m_exponent = m_array.children[i];
|
|
36
|
+
} else if (std::strcmp(c_schema->name, DecFloatConverter::FIELD_NAME_SIGNIFICAND.c_str()) ==
|
|
37
|
+
0) {
|
|
38
|
+
m_significand = m_array.children[i];
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
if (!m_exponent || !m_significand) {
|
|
42
|
+
std::string errorInfo = Logger::formatString(
|
|
43
|
+
"[Snowflake Exception] arrow schema field names do not match, "
|
|
44
|
+
"expected %s and %s, but got %s and %s instead",
|
|
45
|
+
DecFloatConverter::FIELD_NAME_EXPONENT.c_str(),
|
|
46
|
+
DecFloatConverter::FIELD_NAME_SIGNIFICAND.c_str(), schema.schema->children[0]->name,
|
|
47
|
+
schema.schema->children[1]->name);
|
|
48
|
+
logger->error(__FILE__, __func__, __LINE__, errorInfo.c_str());
|
|
49
|
+
PyErr_SetString(PyExc_Exception, errorInfo.c_str());
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
PyObject* DecFloatConverter::toPyObject(int64_t rowIndex) const {
|
|
55
|
+
if (ArrowArrayViewIsNull(&m_array, rowIndex)) {
|
|
56
|
+
Py_RETURN_NONE;
|
|
57
|
+
}
|
|
58
|
+
int64_t exponent = ArrowArrayViewGetIntUnsafe(m_exponent, rowIndex);
|
|
59
|
+
ArrowStringView stringView = ArrowArrayViewGetStringUnsafe(m_significand, rowIndex);
|
|
60
|
+
if (stringView.size_bytes > 16) {
|
|
61
|
+
std::string errorInfo = Logger::formatString(
|
|
62
|
+
"[Snowflake Exception] only precisions up to 38 supported. "
|
|
63
|
+
"Please update to a newer version of the connector.");
|
|
64
|
+
logger->error(__FILE__, __func__, __LINE__, errorInfo.c_str());
|
|
65
|
+
PyErr_SetString(PyExc_Exception, errorInfo.c_str());
|
|
66
|
+
return nullptr;
|
|
67
|
+
}
|
|
68
|
+
PyObject* significand = PyBytes_FromStringAndSize(stringView.data, stringView.size_bytes);
|
|
69
|
+
|
|
70
|
+
PyObject* result = PyObject_CallMethod(
|
|
71
|
+
&m_context, m_useNumpy ? "DECFLOAT_to_numpy_float64" : "DECFLOAT_to_decimal", "iS", exponent,
|
|
72
|
+
significand);
|
|
73
|
+
Py_XDECREF(significand);
|
|
74
|
+
return result;
|
|
75
|
+
}
|
|
76
|
+
} // namespace sf
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
|
|
2
|
+
#ifndef PC_DECFLOATCONVERTER_HPP
|
|
3
|
+
#define PC_DECFLOATCONVERTER_HPP
|
|
4
|
+
|
|
5
|
+
#include <memory>
|
|
6
|
+
|
|
7
|
+
#include "IColumnConverter.hpp"
|
|
8
|
+
#include "logging.hpp"
|
|
9
|
+
#include "nanoarrow.h"
|
|
10
|
+
|
|
11
|
+
namespace sf {
|
|
12
|
+
|
|
13
|
+
class DecFloatConverter : public IColumnConverter {
|
|
14
|
+
public:
|
|
15
|
+
static const std::string FIELD_NAME_EXPONENT;
|
|
16
|
+
static const std::string FIELD_NAME_SIGNIFICAND;
|
|
17
|
+
|
|
18
|
+
explicit DecFloatConverter(ArrowArrayView& array, ArrowSchemaView& schema, PyObject& context,
|
|
19
|
+
bool useNumpy);
|
|
20
|
+
|
|
21
|
+
PyObject* toPyObject(int64_t rowIndex) const override;
|
|
22
|
+
|
|
23
|
+
private:
|
|
24
|
+
PyObject& m_context;
|
|
25
|
+
ArrowArrayView& m_array;
|
|
26
|
+
ArrowArrayView* m_exponent;
|
|
27
|
+
ArrowArrayView* m_significand;
|
|
28
|
+
bool m_useNumpy;
|
|
29
|
+
|
|
30
|
+
static Logger* logger;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
} // namespace sf
|
|
34
|
+
|
|
35
|
+
#endif // PC_DECFLOATCONVERTER_HPP
|