snowflake-connector-python 3.16.0__cp313-cp313-win_amd64.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- snowflake/connector/__init__.py +96 -0
- snowflake/connector/_query_context_cache.py +276 -0
- snowflake/connector/_sql_util.py +48 -0
- snowflake/connector/_utils.py +70 -0
- snowflake/connector/arrow_context.py +203 -0
- snowflake/connector/auth/__init__.py +53 -0
- snowflake/connector/auth/_auth.py +586 -0
- snowflake/connector/auth/_http_server.py +220 -0
- snowflake/connector/auth/_oauth_base.py +400 -0
- snowflake/connector/auth/by_plugin.py +219 -0
- snowflake/connector/auth/default.py +36 -0
- snowflake/connector/auth/idtoken.py +72 -0
- snowflake/connector/auth/keypair.py +222 -0
- snowflake/connector/auth/no_auth.py +39 -0
- snowflake/connector/auth/oauth.py +49 -0
- snowflake/connector/auth/oauth_code.py +479 -0
- snowflake/connector/auth/oauth_credentials.py +66 -0
- snowflake/connector/auth/okta.py +335 -0
- snowflake/connector/auth/pat.py +39 -0
- snowflake/connector/auth/usrpwdmfa.py +69 -0
- snowflake/connector/auth/webbrowser.py +502 -0
- snowflake/connector/auth/workload_identity.py +94 -0
- snowflake/connector/azure_storage_client.py +276 -0
- snowflake/connector/backoff_policies.py +141 -0
- snowflake/connector/bind_upload_agent.py +89 -0
- snowflake/connector/cache.py +696 -0
- snowflake/connector/compat.py +127 -0
- snowflake/connector/config_manager.py +496 -0
- snowflake/connector/connection.py +2273 -0
- snowflake/connector/connection_diagnostic.py +776 -0
- snowflake/connector/constants.py +442 -0
- snowflake/connector/converter.py +785 -0
- snowflake/connector/converter_issue23517.py +87 -0
- snowflake/connector/converter_null.py +14 -0
- snowflake/connector/converter_snowsql.py +205 -0
- snowflake/connector/cursor.py +1951 -0
- snowflake/connector/dbapi.py +53 -0
- snowflake/connector/description.py +19 -0
- snowflake/connector/direct_file_operation_utils.py +88 -0
- snowflake/connector/encryption_util.py +220 -0
- snowflake/connector/errorcode.py +91 -0
- snowflake/connector/errors.py +615 -0
- snowflake/connector/externals_utils/__init__.py +0 -0
- snowflake/connector/externals_utils/externals_setup.py +27 -0
- snowflake/connector/feature.py +4 -0
- snowflake/connector/file_compression_type.py +118 -0
- snowflake/connector/file_lock.py +72 -0
- snowflake/connector/file_transfer_agent.py +1215 -0
- snowflake/connector/file_util.py +153 -0
- snowflake/connector/gcs_storage_client.py +474 -0
- snowflake/connector/gzip_decoder.py +85 -0
- snowflake/connector/local_storage_client.py +90 -0
- snowflake/connector/log_configuration.py +60 -0
- snowflake/connector/logging_utils/__init__.py +0 -0
- snowflake/connector/logging_utils/filters.py +72 -0
- snowflake/connector/nanoarrow_arrow_iterator.cp313-win_amd64.pyd +0 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/ArrayConverter.cpp +60 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/ArrayConverter.hpp +29 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/BinaryConverter.cpp +19 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/BinaryConverter.hpp +26 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/BooleanConverter.cpp +21 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/BooleanConverter.hpp +23 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/CArrowChunkIterator.cpp +557 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/CArrowChunkIterator.hpp +98 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/CArrowIterator.cpp +125 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/CArrowIterator.hpp +115 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/CArrowTableIterator.cpp +1005 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/CArrowTableIterator.hpp +127 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/DateConverter.cpp +47 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/DateConverter.hpp +46 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/DecFloatConverter.cpp +83 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/DecFloatConverter.hpp +35 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/DecimalConverter.cpp +97 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/DecimalConverter.hpp +72 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/FixedSizeListConverter.cpp +73 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/FixedSizeListConverter.hpp +28 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/FloatConverter.cpp +30 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/FloatConverter.hpp +35 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/IColumnConverter.hpp +17 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/IntConverter.cpp +23 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/IntConverter.hpp +45 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/IntervalConverter.cpp +71 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/IntervalConverter.hpp +56 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/LICENSE.txt +209 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/MapConverter.cpp +75 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/MapConverter.hpp +30 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/ObjectConverter.cpp +46 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/ObjectConverter.hpp +29 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/Python/Common.cpp +8 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/Python/Common.hpp +95 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/Python/Helpers.cpp +57 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/Python/Helpers.hpp +36 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/SnowflakeType.cpp +34 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/SnowflakeType.hpp +48 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/StringConverter.cpp +19 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/StringConverter.hpp +26 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/TimeConverter.cpp +36 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/TimeConverter.hpp +31 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/TimeStampConverter.cpp +346 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/TimeStampConverter.hpp +145 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/Util/macros.hpp +14 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/Util/time.cpp +65 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/Util/time.hpp +68 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/flatcc/flatcc_accessors.h +101 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/flatcc/flatcc_alloc.h +127 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/flatcc/flatcc_assert.h +45 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/flatcc/flatcc_builder.h +1908 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/flatcc/flatcc_emitter.h +215 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/flatcc/flatcc_endian.h +125 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/flatcc/flatcc_epilogue.h +7 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/flatcc/flatcc_flatbuffers.h +55 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/flatcc/flatcc_identifier.h +148 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/flatcc/flatcc_iov.h +31 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/flatcc/flatcc_prologue.h +8 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/flatcc/flatcc_refmap.h +144 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/flatcc/flatcc_rtconfig.h +162 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/flatcc/flatcc_types.h +97 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/flatcc/flatcc_verifier.h +239 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/flatcc/portable/flatcc_portable.h +14 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/flatcc/portable/paligned_alloc.h +210 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/flatcc/portable/pattributes.h +84 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/flatcc/portable/pdiagnostic.h +84 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/flatcc/portable/pdiagnostic_pop.h +20 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/flatcc/portable/pdiagnostic_push.h +51 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/flatcc/portable/pendian.h +206 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/flatcc/portable/pendian_detect.h +118 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/flatcc/portable/pinline.h +19 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/flatcc/portable/pinttypes.h +52 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/flatcc/portable/portable.h +2 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/flatcc/portable/portable_basic.h +25 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/flatcc/portable/pstatic_assert.h +67 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/flatcc/portable/pstdalign.h +162 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/flatcc/portable/pstdint.h +898 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/flatcc/portable/punaligned.h +190 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/flatcc/portable/pversion.h +6 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/flatcc/portable/pwarnings.h +52 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/flatcc.c +3204 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/nanoarrow.c +3217 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/nanoarrow.h +3618 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/nanoarrow.hpp +379 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/nanoarrow_arrow_iterator.pyx +256 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/nanoarrow_device.c +512 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/nanoarrow_device.h +350 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/nanoarrow_ipc.c +33273 -0
- snowflake/connector/nanoarrow_cpp/ArrowIterator/nanoarrow_ipc.h +397 -0
- snowflake/connector/nanoarrow_cpp/Logging/logging.cpp +100 -0
- snowflake/connector/nanoarrow_cpp/Logging/logging.hpp +49 -0
- snowflake/connector/network.py +1297 -0
- snowflake/connector/ocsp_asn1crypto.py +447 -0
- snowflake/connector/ocsp_snowflake.py +1883 -0
- snowflake/connector/options.py +131 -0
- snowflake/connector/pandas_tools.py +732 -0
- snowflake/connector/proxy.py +43 -0
- snowflake/connector/py.typed +0 -0
- snowflake/connector/result_batch.py +786 -0
- snowflake/connector/result_set.py +319 -0
- snowflake/connector/s3_storage_client.py +605 -0
- snowflake/connector/secret_detector.py +181 -0
- snowflake/connector/sf_dirs.py +64 -0
- snowflake/connector/sfbinaryformat.py +35 -0
- snowflake/connector/sfdatetime.py +345 -0
- snowflake/connector/snow_logging.py +144 -0
- snowflake/connector/sqlstate.py +9 -0
- snowflake/connector/ssd_internal_keys.py +30 -0
- snowflake/connector/ssl_wrap_socket.py +134 -0
- snowflake/connector/storage_client.py +478 -0
- snowflake/connector/telemetry.py +249 -0
- snowflake/connector/telemetry_oob.py +543 -0
- snowflake/connector/test_util.py +30 -0
- snowflake/connector/time_util.py +159 -0
- snowflake/connector/token_cache.py +402 -0
- snowflake/connector/tool/__init__.py +0 -0
- snowflake/connector/tool/dump_certs.py +57 -0
- snowflake/connector/tool/dump_ocsp_response.py +139 -0
- snowflake/connector/tool/dump_ocsp_response_cache.py +194 -0
- snowflake/connector/tool/probe_connection.py +69 -0
- snowflake/connector/url_util.py +49 -0
- snowflake/connector/util_text.py +301 -0
- snowflake/connector/vendored/__init__.py +3 -0
- snowflake/connector/vendored/requests/LICENSE +175 -0
- snowflake/connector/vendored/requests/__init__.py +169 -0
- snowflake/connector/vendored/requests/__version__.py +14 -0
- snowflake/connector/vendored/requests/_internal_utils.py +50 -0
- snowflake/connector/vendored/requests/adapters.py +537 -0
- snowflake/connector/vendored/requests/api.py +157 -0
- snowflake/connector/vendored/requests/auth.py +315 -0
- snowflake/connector/vendored/requests/certs.py +17 -0
- snowflake/connector/vendored/requests/compat.py +79 -0
- snowflake/connector/vendored/requests/cookies.py +561 -0
- snowflake/connector/vendored/requests/exceptions.py +140 -0
- snowflake/connector/vendored/requests/help.py +134 -0
- snowflake/connector/vendored/requests/hooks.py +33 -0
- snowflake/connector/vendored/requests/models.py +1033 -0
- snowflake/connector/vendored/requests/sessions.py +833 -0
- snowflake/connector/vendored/requests/status_codes.py +128 -0
- snowflake/connector/vendored/requests/structures.py +99 -0
- snowflake/connector/vendored/requests/utils.py +1093 -0
- snowflake/connector/vendored/urllib3/LICENSE.txt +21 -0
- snowflake/connector/vendored/urllib3/__init__.py +85 -0
- snowflake/connector/vendored/urllib3/_collections.py +355 -0
- snowflake/connector/vendored/urllib3/_version.py +2 -0
- snowflake/connector/vendored/urllib3/connection.py +572 -0
- snowflake/connector/vendored/urllib3/connectionpool.py +1137 -0
- snowflake/connector/vendored/urllib3/contrib/__init__.py +0 -0
- snowflake/connector/vendored/urllib3/contrib/_appengine_environ.py +36 -0
- snowflake/connector/vendored/urllib3/contrib/_securetransport/__init__.py +0 -0
- snowflake/connector/vendored/urllib3/contrib/_securetransport/bindings.py +519 -0
- snowflake/connector/vendored/urllib3/contrib/_securetransport/low_level.py +397 -0
- snowflake/connector/vendored/urllib3/contrib/appengine.py +314 -0
- snowflake/connector/vendored/urllib3/contrib/ntlmpool.py +130 -0
- snowflake/connector/vendored/urllib3/contrib/pyopenssl.py +509 -0
- snowflake/connector/vendored/urllib3/contrib/securetransport.py +920 -0
- snowflake/connector/vendored/urllib3/contrib/socks.py +216 -0
- snowflake/connector/vendored/urllib3/exceptions.py +323 -0
- snowflake/connector/vendored/urllib3/fields.py +274 -0
- snowflake/connector/vendored/urllib3/filepost.py +98 -0
- snowflake/connector/vendored/urllib3/packages/__init__.py +0 -0
- snowflake/connector/vendored/urllib3/packages/backports/__init__.py +0 -0
- snowflake/connector/vendored/urllib3/packages/backports/makefile.py +51 -0
- snowflake/connector/vendored/urllib3/packages/backports/weakref_finalize.py +155 -0
- snowflake/connector/vendored/urllib3/packages/six.py +1076 -0
- snowflake/connector/vendored/urllib3/poolmanager.py +540 -0
- snowflake/connector/vendored/urllib3/request.py +191 -0
- snowflake/connector/vendored/urllib3/response.py +885 -0
- snowflake/connector/vendored/urllib3/util/__init__.py +49 -0
- snowflake/connector/vendored/urllib3/util/connection.py +156 -0
- snowflake/connector/vendored/urllib3/util/proxy.py +57 -0
- snowflake/connector/vendored/urllib3/util/queue.py +22 -0
- snowflake/connector/vendored/urllib3/util/request.py +146 -0
- snowflake/connector/vendored/urllib3/util/response.py +107 -0
- snowflake/connector/vendored/urllib3/util/retry.py +620 -0
- snowflake/connector/vendored/urllib3/util/ssl_.py +495 -0
- snowflake/connector/vendored/urllib3/util/ssl_match_hostname.py +159 -0
- snowflake/connector/vendored/urllib3/util/ssltransport.py +221 -0
- snowflake/connector/vendored/urllib3/util/timeout.py +271 -0
- snowflake/connector/vendored/urllib3/util/url.py +435 -0
- snowflake/connector/vendored/urllib3/util/wait.py +152 -0
- snowflake/connector/version.py +3 -0
- snowflake/connector/wif_util.py +407 -0
- snowflake_connector_python-3.16.0.dist-info/METADATA +1475 -0
- snowflake_connector_python-3.16.0.dist-info/RECORD +246 -0
- snowflake_connector_python-3.16.0.dist-info/WHEEL +5 -0
- snowflake_connector_python-3.16.0.dist-info/entry_points.txt +4 -0
- snowflake_connector_python-3.16.0.dist-info/licenses/LICENSE.txt +202 -0
- snowflake_connector_python-3.16.0.dist-info/licenses/NOTICE +8 -0
- snowflake_connector_python-3.16.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,346 @@
|
|
|
1
|
+
#include "TimeStampConverter.hpp"
|
|
2
|
+
|
|
3
|
+
#include <cstdint>
|
|
4
|
+
#include <cstring>
|
|
5
|
+
#include <memory>
|
|
6
|
+
#include <type_traits>
|
|
7
|
+
|
|
8
|
+
#include "Python/Helpers.hpp"
|
|
9
|
+
#include "Util/time.hpp"
|
|
10
|
+
|
|
11
|
+
template <typename T>
|
|
12
|
+
constexpr char toType() {
|
|
13
|
+
static_assert(
|
|
14
|
+
std::is_same<T, signed char>::value || std::is_same<T, short>::value ||
|
|
15
|
+
std::is_same<T, int>::value || std::is_same<T, long>::value ||
|
|
16
|
+
std::is_same<T, long long>::value,
|
|
17
|
+
"Unknown type");
|
|
18
|
+
return std::is_same<T, signed char>::value ? 'b'
|
|
19
|
+
: std::is_same<T, short>::value ? 'h'
|
|
20
|
+
: std::is_same<T, int>::value ? 'i'
|
|
21
|
+
: std::is_same<T, long>::value ? 'l'
|
|
22
|
+
: std::is_same<T, long long>::value ? 'L'
|
|
23
|
+
// Should not get here. Error.
|
|
24
|
+
: '?';
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
template <typename T1>
|
|
28
|
+
struct FormatArgs1 {
|
|
29
|
+
char format[2];
|
|
30
|
+
constexpr FormatArgs1() : format{toType<T1>(), '\0'} {}
|
|
31
|
+
};
|
|
32
|
+
template <typename T1, typename T2>
|
|
33
|
+
struct FormatArgs2 {
|
|
34
|
+
char format[3];
|
|
35
|
+
constexpr FormatArgs2() : format{toType<T1>(), toType<T2>(), '\0'} {}
|
|
36
|
+
};
|
|
37
|
+
template <typename T1, typename T2, typename T3>
|
|
38
|
+
struct FormatArgs3 {
|
|
39
|
+
char format[4];
|
|
40
|
+
constexpr FormatArgs3()
|
|
41
|
+
: format{toType<T1>(), toType<T2>(), toType<T3>(), '\0'} {}
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
namespace sf {
|
|
45
|
+
|
|
46
|
+
Logger* TwoFieldTimeStampNTZConverter::logger =
|
|
47
|
+
new Logger("snowflake.connector.TwoFieldTimeStampNTZConverter");
|
|
48
|
+
Logger* NumpyTwoFieldTimeStampNTZConverter::logger =
|
|
49
|
+
new Logger("snowflake.connector.NumpyTwoFieldTimeStampNTZConverter");
|
|
50
|
+
Logger* TwoFieldTimeStampLTZConverter::logger =
|
|
51
|
+
new Logger("snowflake.connector.TwoFieldTimeStampLTZConverter");
|
|
52
|
+
Logger* TwoFieldTimeStampTZConverter::logger =
|
|
53
|
+
new Logger("snowflake.connector.TwoFieldTimeStampTZConverter");
|
|
54
|
+
Logger* ThreeFieldTimeStampTZConverter::logger =
|
|
55
|
+
new Logger("snowflake.connector.ThreeFieldTimeStampTZConverter");
|
|
56
|
+
|
|
57
|
+
TimeStampBaseConverter::TimeStampBaseConverter(PyObject* context, int32_t scale)
|
|
58
|
+
: m_context(context), m_scale(scale) {}
|
|
59
|
+
|
|
60
|
+
OneFieldTimeStampNTZConverter::OneFieldTimeStampNTZConverter(
|
|
61
|
+
ArrowArrayView* array, int32_t scale, PyObject* context)
|
|
62
|
+
: TimeStampBaseConverter(context, scale), m_array(array) {}
|
|
63
|
+
|
|
64
|
+
PyObject* OneFieldTimeStampNTZConverter::toPyObject(int64_t rowIndex) const {
|
|
65
|
+
if (ArrowArrayViewIsNull(m_array, rowIndex)) {
|
|
66
|
+
Py_RETURN_NONE;
|
|
67
|
+
}
|
|
68
|
+
int64_t val = ArrowArrayViewGetIntUnsafe(m_array, rowIndex);
|
|
69
|
+
internal::TimeSpec ts(val, m_scale);
|
|
70
|
+
|
|
71
|
+
static constexpr FormatArgs2<decltype(ts.seconds), decltype(ts.microseconds)>
|
|
72
|
+
format;
|
|
73
|
+
#ifdef _WIN32
|
|
74
|
+
return PyObject_CallMethod(m_context, "TIMESTAMP_NTZ_to_python_windows",
|
|
75
|
+
format.format, ts.seconds, ts.microseconds);
|
|
76
|
+
#else
|
|
77
|
+
return PyObject_CallMethod(m_context, "TIMESTAMP_NTZ_to_python",
|
|
78
|
+
format.format, ts.seconds, ts.microseconds);
|
|
79
|
+
#endif
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
NumpyOneFieldTimeStampNTZConverter::NumpyOneFieldTimeStampNTZConverter(
|
|
83
|
+
ArrowArrayView* array, int32_t scale, PyObject* context)
|
|
84
|
+
: TimeStampBaseConverter(context, scale), m_array(array) {}
|
|
85
|
+
|
|
86
|
+
PyObject* NumpyOneFieldTimeStampNTZConverter::toPyObject(
|
|
87
|
+
int64_t rowIndex) const {
|
|
88
|
+
if (ArrowArrayViewIsNull(m_array, rowIndex)) {
|
|
89
|
+
Py_RETURN_NONE;
|
|
90
|
+
}
|
|
91
|
+
int64_t val = ArrowArrayViewGetIntUnsafe(m_array, rowIndex);
|
|
92
|
+
return PyObject_CallMethod(m_context,
|
|
93
|
+
"TIMESTAMP_NTZ_ONE_FIELD_to_numpy_datetime64",
|
|
94
|
+
"Li", val, m_scale);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
TwoFieldTimeStampNTZConverter::TwoFieldTimeStampNTZConverter(
|
|
98
|
+
ArrowArrayView* array, ArrowSchemaView* schema, int32_t scale,
|
|
99
|
+
PyObject* context)
|
|
100
|
+
: TimeStampBaseConverter(context, scale), m_array(array) {
|
|
101
|
+
if (schema->schema->n_children != 2) {
|
|
102
|
+
std::string errorInfo = Logger::formatString(
|
|
103
|
+
"[Snowflake Exception] arrow schema field number does not match, "
|
|
104
|
+
"expected 2 but got %d instead",
|
|
105
|
+
schema->schema->n_children);
|
|
106
|
+
logger->error(__FILE__, __func__, __LINE__, errorInfo.c_str());
|
|
107
|
+
PyErr_SetString(PyExc_Exception, errorInfo.c_str());
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
for (int i = 0; i < schema->schema->n_children; i += 1) {
|
|
111
|
+
ArrowSchema* c_schema = schema->schema->children[i];
|
|
112
|
+
if (std::strcmp(c_schema->name, internal::FIELD_NAME_EPOCH.c_str()) == 0) {
|
|
113
|
+
m_epoch = m_array->children[i];
|
|
114
|
+
} else if (std::strcmp(c_schema->name,
|
|
115
|
+
internal::FIELD_NAME_FRACTION.c_str()) == 0) {
|
|
116
|
+
m_fraction = m_array->children[i];
|
|
117
|
+
} else {
|
|
118
|
+
// do nothing
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
PyObject* TwoFieldTimeStampNTZConverter::toPyObject(int64_t rowIndex) const {
|
|
124
|
+
if (ArrowArrayViewIsNull(m_array, rowIndex)) {
|
|
125
|
+
Py_RETURN_NONE;
|
|
126
|
+
}
|
|
127
|
+
int64_t seconds = ArrowArrayViewGetIntUnsafe(m_epoch, rowIndex);
|
|
128
|
+
int64_t microseconds =
|
|
129
|
+
ArrowArrayViewGetIntUnsafe(m_fraction, rowIndex) / 1000;
|
|
130
|
+
|
|
131
|
+
static constexpr FormatArgs2<decltype(seconds), decltype(microseconds)>
|
|
132
|
+
format;
|
|
133
|
+
#ifdef _WIN32
|
|
134
|
+
return PyObject_CallMethod(m_context, "TIMESTAMP_NTZ_to_python_windows",
|
|
135
|
+
format.format, seconds, microseconds);
|
|
136
|
+
#else
|
|
137
|
+
return PyObject_CallMethod(m_context, "TIMESTAMP_NTZ_to_python",
|
|
138
|
+
format.format, seconds, microseconds);
|
|
139
|
+
#endif
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
NumpyTwoFieldTimeStampNTZConverter::NumpyTwoFieldTimeStampNTZConverter(
|
|
143
|
+
ArrowArrayView* array, ArrowSchemaView* schema, int32_t scale,
|
|
144
|
+
PyObject* context)
|
|
145
|
+
: TimeStampBaseConverter(context, scale), m_array(array) {
|
|
146
|
+
if (schema->schema->n_children != 2) {
|
|
147
|
+
std::string errorInfo = Logger::formatString(
|
|
148
|
+
"[Snowflake Exception] arrow schema field number does not match, "
|
|
149
|
+
"expected 2 but got %d instead",
|
|
150
|
+
schema->schema->n_children);
|
|
151
|
+
logger->error(__FILE__, __func__, __LINE__, errorInfo.c_str());
|
|
152
|
+
PyErr_SetString(PyExc_Exception, errorInfo.c_str());
|
|
153
|
+
return;
|
|
154
|
+
}
|
|
155
|
+
for (int i = 0; i < schema->schema->n_children; i += 1) {
|
|
156
|
+
ArrowSchema* c_schema = schema->schema->children[i];
|
|
157
|
+
if (std::strcmp(c_schema->name, internal::FIELD_NAME_EPOCH.c_str()) == 0) {
|
|
158
|
+
m_epoch = m_array->children[i];
|
|
159
|
+
} else if (std::strcmp(c_schema->name,
|
|
160
|
+
internal::FIELD_NAME_FRACTION.c_str()) == 0) {
|
|
161
|
+
m_fraction = m_array->children[i];
|
|
162
|
+
} else {
|
|
163
|
+
// do nothing
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
PyObject* NumpyTwoFieldTimeStampNTZConverter::toPyObject(
|
|
169
|
+
int64_t rowIndex) const {
|
|
170
|
+
if (ArrowArrayViewIsNull(m_array, rowIndex)) {
|
|
171
|
+
Py_RETURN_NONE;
|
|
172
|
+
}
|
|
173
|
+
int64_t epoch = ArrowArrayViewGetIntUnsafe(m_epoch, rowIndex);
|
|
174
|
+
int32_t frac = ArrowArrayViewGetIntUnsafe(m_fraction, rowIndex);
|
|
175
|
+
return PyObject_CallMethod(m_context,
|
|
176
|
+
"TIMESTAMP_NTZ_TWO_FIELD_to_numpy_datetime64",
|
|
177
|
+
"Li", epoch, frac);
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
OneFieldTimeStampLTZConverter::OneFieldTimeStampLTZConverter(
|
|
181
|
+
ArrowArrayView* array, int32_t scale, PyObject* context)
|
|
182
|
+
: TimeStampBaseConverter(context, scale), m_array(array) {}
|
|
183
|
+
|
|
184
|
+
PyObject* OneFieldTimeStampLTZConverter::toPyObject(int64_t rowIndex) const {
|
|
185
|
+
if (ArrowArrayViewIsNull(m_array, rowIndex)) {
|
|
186
|
+
Py_RETURN_NONE;
|
|
187
|
+
}
|
|
188
|
+
int64_t val = ArrowArrayViewGetIntUnsafe(m_array, rowIndex);
|
|
189
|
+
internal::TimeSpec ts(val, m_scale);
|
|
190
|
+
|
|
191
|
+
static constexpr FormatArgs2<decltype(ts.seconds), decltype(ts.microseconds)>
|
|
192
|
+
format;
|
|
193
|
+
|
|
194
|
+
#ifdef _WIN32
|
|
195
|
+
return PyObject_CallMethod(m_context, "TIMESTAMP_LTZ_to_python_windows",
|
|
196
|
+
format.format, ts.seconds, ts.microseconds);
|
|
197
|
+
#else
|
|
198
|
+
return PyObject_CallMethod(m_context, "TIMESTAMP_LTZ_to_python",
|
|
199
|
+
format.format, ts.seconds, ts.microseconds);
|
|
200
|
+
#endif
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
TwoFieldTimeStampLTZConverter::TwoFieldTimeStampLTZConverter(
|
|
204
|
+
ArrowArrayView* array, ArrowSchemaView* schema, int32_t scale,
|
|
205
|
+
PyObject* context)
|
|
206
|
+
: TimeStampBaseConverter(context, scale), m_array(array) {
|
|
207
|
+
if (schema->schema->n_children != 2) {
|
|
208
|
+
std::string errorInfo = Logger::formatString(
|
|
209
|
+
"[Snowflake Exception] arrow schema field number does not match, "
|
|
210
|
+
"expected 2 but got %d instead",
|
|
211
|
+
schema->schema->n_children);
|
|
212
|
+
logger->error(__FILE__, __func__, __LINE__, errorInfo.c_str());
|
|
213
|
+
PyErr_SetString(PyExc_Exception, errorInfo.c_str());
|
|
214
|
+
return;
|
|
215
|
+
}
|
|
216
|
+
for (int i = 0; i < schema->schema->n_children; i += 1) {
|
|
217
|
+
ArrowSchema* c_schema = schema->schema->children[i];
|
|
218
|
+
if (std::strcmp(c_schema->name, internal::FIELD_NAME_EPOCH.c_str()) == 0) {
|
|
219
|
+
m_epoch = m_array->children[i];
|
|
220
|
+
} else if (std::strcmp(c_schema->name,
|
|
221
|
+
internal::FIELD_NAME_FRACTION.c_str()) == 0) {
|
|
222
|
+
m_fraction = m_array->children[i];
|
|
223
|
+
} else {
|
|
224
|
+
// do nothing
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
PyObject* TwoFieldTimeStampLTZConverter::toPyObject(int64_t rowIndex) const {
|
|
230
|
+
if (ArrowArrayViewIsNull(m_array, rowIndex)) {
|
|
231
|
+
Py_RETURN_NONE;
|
|
232
|
+
}
|
|
233
|
+
int64_t seconds = ArrowArrayViewGetIntUnsafe(m_epoch, rowIndex);
|
|
234
|
+
int64_t microseconds =
|
|
235
|
+
ArrowArrayViewGetIntUnsafe(m_fraction, rowIndex) / 1000;
|
|
236
|
+
|
|
237
|
+
static constexpr FormatArgs2<decltype(seconds), decltype(microseconds)>
|
|
238
|
+
format;
|
|
239
|
+
#ifdef _WIN32
|
|
240
|
+
return PyObject_CallMethod(m_context, "TIMESTAMP_LTZ_to_python_windows",
|
|
241
|
+
format.format, seconds, microseconds);
|
|
242
|
+
#else
|
|
243
|
+
return PyObject_CallMethod(m_context, "TIMESTAMP_LTZ_to_python",
|
|
244
|
+
format.format, seconds, microseconds);
|
|
245
|
+
#endif
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
TwoFieldTimeStampTZConverter::TwoFieldTimeStampTZConverter(
|
|
249
|
+
ArrowArrayView* array, ArrowSchemaView* schema, int32_t scale,
|
|
250
|
+
PyObject* context)
|
|
251
|
+
: TimeStampBaseConverter(context, scale), m_array(array) {
|
|
252
|
+
if (schema->schema->n_children != 2) {
|
|
253
|
+
std::string errorInfo = Logger::formatString(
|
|
254
|
+
"[Snowflake Exception] arrow schema field number does not match, "
|
|
255
|
+
"expected 2 but got %d instead",
|
|
256
|
+
schema->schema->n_children);
|
|
257
|
+
logger->error(__FILE__, __func__, __LINE__, errorInfo.c_str());
|
|
258
|
+
PyErr_SetString(PyExc_Exception, errorInfo.c_str());
|
|
259
|
+
return;
|
|
260
|
+
}
|
|
261
|
+
for (int i = 0; i < schema->schema->n_children; i += 1) {
|
|
262
|
+
ArrowSchema* c_schema = schema->schema->children[i];
|
|
263
|
+
if (std::strcmp(c_schema->name, internal::FIELD_NAME_EPOCH.c_str()) == 0) {
|
|
264
|
+
m_epoch = m_array->children[i];
|
|
265
|
+
} else if (std::strcmp(c_schema->name,
|
|
266
|
+
internal::FIELD_NAME_TIME_ZONE.c_str()) == 0) {
|
|
267
|
+
m_timezone = m_array->children[i];
|
|
268
|
+
} else {
|
|
269
|
+
// do nothing
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
PyObject* TwoFieldTimeStampTZConverter::toPyObject(int64_t rowIndex) const {
|
|
275
|
+
if (ArrowArrayViewIsNull(m_array, rowIndex)) {
|
|
276
|
+
Py_RETURN_NONE;
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
int32_t timezone = ArrowArrayViewGetIntUnsafe(m_timezone, rowIndex);
|
|
280
|
+
internal::TimeSpec ts(ArrowArrayViewGetIntUnsafe(m_epoch, rowIndex), m_scale);
|
|
281
|
+
|
|
282
|
+
static constexpr FormatArgs3<decltype(ts.seconds), decltype(ts.microseconds),
|
|
283
|
+
decltype(timezone)>
|
|
284
|
+
format;
|
|
285
|
+
#if _WIN32
|
|
286
|
+
return PyObject_CallMethod(m_context, "TIMESTAMP_TZ_to_python_windows",
|
|
287
|
+
format.format, ts.seconds, ts.microseconds,
|
|
288
|
+
timezone);
|
|
289
|
+
#else
|
|
290
|
+
return PyObject_CallMethod(m_context, "TIMESTAMP_TZ_to_python", format.format,
|
|
291
|
+
ts.seconds, ts.microseconds, timezone);
|
|
292
|
+
#endif
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
ThreeFieldTimeStampTZConverter::ThreeFieldTimeStampTZConverter(
|
|
296
|
+
ArrowArrayView* array, ArrowSchemaView* schema, int32_t scale,
|
|
297
|
+
PyObject* context)
|
|
298
|
+
: TimeStampBaseConverter(context, scale), m_array(array) {
|
|
299
|
+
if (schema->schema->n_children != 3) {
|
|
300
|
+
std::string errorInfo = Logger::formatString(
|
|
301
|
+
"[Snowflake Exception] arrow schema field number does not match, "
|
|
302
|
+
"expected 3 but got %d instead",
|
|
303
|
+
schema->schema->n_children);
|
|
304
|
+
logger->error(__FILE__, __func__, __LINE__, errorInfo.c_str());
|
|
305
|
+
PyErr_SetString(PyExc_Exception, errorInfo.c_str());
|
|
306
|
+
return;
|
|
307
|
+
}
|
|
308
|
+
for (int i = 0; i < schema->schema->n_children; i += 1) {
|
|
309
|
+
ArrowSchema* c_schema = schema->schema->children[i];
|
|
310
|
+
if (std::strcmp(c_schema->name, internal::FIELD_NAME_EPOCH.c_str()) == 0) {
|
|
311
|
+
m_epoch = m_array->children[i];
|
|
312
|
+
} else if (std::strcmp(c_schema->name,
|
|
313
|
+
internal::FIELD_NAME_TIME_ZONE.c_str()) == 0) {
|
|
314
|
+
m_timezone = m_array->children[i];
|
|
315
|
+
} else if (std::strcmp(c_schema->name,
|
|
316
|
+
internal::FIELD_NAME_FRACTION.c_str()) == 0) {
|
|
317
|
+
m_fraction = m_array->children[i];
|
|
318
|
+
} else {
|
|
319
|
+
// do nothing
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
PyObject* ThreeFieldTimeStampTZConverter::toPyObject(int64_t rowIndex) const {
|
|
325
|
+
if (ArrowArrayViewIsNull(m_array, rowIndex)) {
|
|
326
|
+
Py_RETURN_NONE;
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
int32_t timezone = ArrowArrayViewGetIntUnsafe(m_timezone, rowIndex);
|
|
330
|
+
int64_t seconds = ArrowArrayViewGetIntUnsafe(m_epoch, rowIndex);
|
|
331
|
+
int64_t microseconds =
|
|
332
|
+
ArrowArrayViewGetIntUnsafe(m_fraction, rowIndex) / 1000;
|
|
333
|
+
|
|
334
|
+
static constexpr FormatArgs3<decltype(seconds), decltype(microseconds),
|
|
335
|
+
decltype(timezone)>
|
|
336
|
+
format;
|
|
337
|
+
#ifdef _WIN32
|
|
338
|
+
return PyObject_CallMethod(m_context, "TIMESTAMP_TZ_to_python_windows",
|
|
339
|
+
format.format, seconds, microseconds, timezone);
|
|
340
|
+
#else
|
|
341
|
+
return PyObject_CallMethod(m_context, "TIMESTAMP_TZ_to_python", format.format,
|
|
342
|
+
seconds, microseconds, timezone);
|
|
343
|
+
#endif
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
} // namespace sf
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
#ifndef PC_TIMESTAMPCONVERTER_HPP
|
|
2
|
+
#define PC_TIMESTAMPCONVERTER_HPP
|
|
3
|
+
|
|
4
|
+
#include <memory>
|
|
5
|
+
|
|
6
|
+
#include "IColumnConverter.hpp"
|
|
7
|
+
#include "Python/Common.hpp"
|
|
8
|
+
#include "Python/Helpers.hpp"
|
|
9
|
+
#include "Util/time.hpp"
|
|
10
|
+
#include "logging.hpp"
|
|
11
|
+
#include "nanoarrow.h"
|
|
12
|
+
|
|
13
|
+
namespace sf {
|
|
14
|
+
|
|
15
|
+
// correspond to python datetime.time and datetime.time has only support 6 bit
|
|
16
|
+
// precision, which is millisecond
|
|
17
|
+
|
|
18
|
+
class TimeStampBaseConverter : public IColumnConverter {
|
|
19
|
+
public:
|
|
20
|
+
TimeStampBaseConverter(PyObject* context, int32_t scale);
|
|
21
|
+
virtual ~TimeStampBaseConverter() = default;
|
|
22
|
+
|
|
23
|
+
protected:
|
|
24
|
+
PyObject* m_context;
|
|
25
|
+
|
|
26
|
+
int32_t m_scale;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
class OneFieldTimeStampNTZConverter : public TimeStampBaseConverter {
|
|
30
|
+
public:
|
|
31
|
+
explicit OneFieldTimeStampNTZConverter(ArrowArrayView* array, int32_t scale,
|
|
32
|
+
PyObject* context);
|
|
33
|
+
|
|
34
|
+
PyObject* toPyObject(int64_t rowIndex) const override;
|
|
35
|
+
|
|
36
|
+
private:
|
|
37
|
+
ArrowArrayView* m_array;
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
class NumpyOneFieldTimeStampNTZConverter : public TimeStampBaseConverter {
|
|
41
|
+
public:
|
|
42
|
+
explicit NumpyOneFieldTimeStampNTZConverter(ArrowArrayView* array,
|
|
43
|
+
int32_t scale, PyObject* context);
|
|
44
|
+
|
|
45
|
+
PyObject* toPyObject(int64_t rowIndex) const override;
|
|
46
|
+
|
|
47
|
+
private:
|
|
48
|
+
ArrowArrayView* m_array;
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
class TwoFieldTimeStampNTZConverter : public TimeStampBaseConverter {
|
|
52
|
+
public:
|
|
53
|
+
explicit TwoFieldTimeStampNTZConverter(ArrowArrayView* array,
|
|
54
|
+
ArrowSchemaView* schema, int32_t scale,
|
|
55
|
+
PyObject* context);
|
|
56
|
+
|
|
57
|
+
PyObject* toPyObject(int64_t rowIndex) const override;
|
|
58
|
+
|
|
59
|
+
private:
|
|
60
|
+
ArrowArrayView* m_array;
|
|
61
|
+
ArrowArrayView* m_epoch;
|
|
62
|
+
ArrowArrayView* m_fraction;
|
|
63
|
+
|
|
64
|
+
static Logger* logger;
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
class NumpyTwoFieldTimeStampNTZConverter : public TimeStampBaseConverter {
|
|
68
|
+
public:
|
|
69
|
+
explicit NumpyTwoFieldTimeStampNTZConverter(ArrowArrayView* array,
|
|
70
|
+
ArrowSchemaView* schema,
|
|
71
|
+
int32_t scale, PyObject* context);
|
|
72
|
+
|
|
73
|
+
PyObject* toPyObject(int64_t rowIndex) const override;
|
|
74
|
+
|
|
75
|
+
private:
|
|
76
|
+
ArrowArrayView* m_array;
|
|
77
|
+
ArrowArrayView* m_epoch;
|
|
78
|
+
ArrowArrayView* m_fraction;
|
|
79
|
+
|
|
80
|
+
static Logger* logger;
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
class OneFieldTimeStampLTZConverter : public TimeStampBaseConverter {
|
|
84
|
+
public:
|
|
85
|
+
explicit OneFieldTimeStampLTZConverter(ArrowArrayView* array, int32_t scale,
|
|
86
|
+
PyObject* context);
|
|
87
|
+
|
|
88
|
+
PyObject* toPyObject(int64_t rowIndex) const override;
|
|
89
|
+
|
|
90
|
+
private:
|
|
91
|
+
ArrowArrayView* m_array;
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
class TwoFieldTimeStampLTZConverter : public TimeStampBaseConverter {
|
|
95
|
+
public:
|
|
96
|
+
explicit TwoFieldTimeStampLTZConverter(ArrowArrayView* array,
|
|
97
|
+
ArrowSchemaView* schema, int32_t scale,
|
|
98
|
+
PyObject* context);
|
|
99
|
+
|
|
100
|
+
PyObject* toPyObject(int64_t rowIndex) const override;
|
|
101
|
+
|
|
102
|
+
private:
|
|
103
|
+
ArrowArrayView* m_array;
|
|
104
|
+
ArrowArrayView* m_epoch;
|
|
105
|
+
ArrowArrayView* m_fraction;
|
|
106
|
+
|
|
107
|
+
static Logger* logger;
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
class TwoFieldTimeStampTZConverter : public TimeStampBaseConverter {
|
|
111
|
+
public:
|
|
112
|
+
explicit TwoFieldTimeStampTZConverter(ArrowArrayView* array,
|
|
113
|
+
ArrowSchemaView* schema, int32_t scale,
|
|
114
|
+
PyObject* context);
|
|
115
|
+
|
|
116
|
+
PyObject* toPyObject(int64_t rowIndex) const override;
|
|
117
|
+
|
|
118
|
+
private:
|
|
119
|
+
ArrowArrayView* m_array;
|
|
120
|
+
ArrowArrayView* m_epoch;
|
|
121
|
+
ArrowArrayView* m_timezone;
|
|
122
|
+
|
|
123
|
+
static Logger* logger;
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
class ThreeFieldTimeStampTZConverter : public TimeStampBaseConverter {
|
|
127
|
+
public:
|
|
128
|
+
explicit ThreeFieldTimeStampTZConverter(ArrowArrayView* array,
|
|
129
|
+
ArrowSchemaView* schema,
|
|
130
|
+
int32_t scale, PyObject* context);
|
|
131
|
+
|
|
132
|
+
PyObject* toPyObject(int64_t rowIndex) const override;
|
|
133
|
+
|
|
134
|
+
private:
|
|
135
|
+
ArrowArrayView* m_array;
|
|
136
|
+
ArrowArrayView* m_epoch;
|
|
137
|
+
ArrowArrayView* m_fraction;
|
|
138
|
+
ArrowArrayView* m_timezone;
|
|
139
|
+
|
|
140
|
+
static Logger* logger;
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
} // namespace sf
|
|
144
|
+
|
|
145
|
+
#endif // PC_TIMESTAMPCONVERTER_HPP
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
#ifndef PC_UTIL_MACROS_HPP
|
|
2
|
+
#define PC_UTIL_MACROS_HPP
|
|
3
|
+
|
|
4
|
+
/** the same macros as linux kernel's likely and unlikely. can help specific
|
|
5
|
+
* compiler to make branch prediction */
|
|
6
|
+
#if defined(__GNUC__)
|
|
7
|
+
#define LIKELY(x) (__builtin_expect(!!(x), 1))
|
|
8
|
+
#define UNLIKELY(x) (__builtin_expect(!!(x), 0))
|
|
9
|
+
#else
|
|
10
|
+
#define LIKELY(x) x
|
|
11
|
+
#define UNLIKELY(x) x
|
|
12
|
+
#endif // __GNUC__
|
|
13
|
+
|
|
14
|
+
#endif // PC_UTIL_MACROS_HPP
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
#include "time.hpp"
|
|
2
|
+
|
|
3
|
+
namespace sf {
|
|
4
|
+
|
|
5
|
+
namespace internal {
|
|
6
|
+
|
|
7
|
+
int32_t getHourFromSeconds(int64_t seconds, int32_t scale) {
|
|
8
|
+
return seconds / powTenSB4[scale] / SECONDS_PER_HOUR;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
int32_t getHourFromSeconds(int32_t seconds, int32_t scale) {
|
|
12
|
+
return seconds / powTenSB4[scale] / SECONDS_PER_HOUR;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
int32_t getMinuteFromSeconds(int64_t seconds, int32_t scale) {
|
|
16
|
+
return seconds / powTenSB4[scale] % SECONDS_PER_HOUR / SECONDS_PER_MINUTE;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
int32_t getMinuteFromSeconds(int32_t seconds, int32_t scale) {
|
|
20
|
+
return seconds / powTenSB4[scale] % SECONDS_PER_HOUR / SECONDS_PER_MINUTE;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
int32_t getSecondFromSeconds(int64_t seconds, int32_t scale) {
|
|
24
|
+
return seconds / powTenSB4[scale] % SECONDS_PER_MINUTE;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
int32_t getSecondFromSeconds(int32_t seconds, int32_t scale) {
|
|
28
|
+
return seconds / powTenSB4[scale] % SECONDS_PER_MINUTE;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
int32_t getMicrosecondFromSeconds(int64_t seconds, int32_t scale) {
|
|
32
|
+
int32_t microsec = seconds % powTenSB4[scale];
|
|
33
|
+
return scale > PYTHON_DATETIME_TIME_MICROSEC_DIGIT
|
|
34
|
+
? microsec /=
|
|
35
|
+
powTenSB4[scale - PYTHON_DATETIME_TIME_MICROSEC_DIGIT]
|
|
36
|
+
: microsec *=
|
|
37
|
+
powTenSB4[PYTHON_DATETIME_TIME_MICROSEC_DIGIT - scale];
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
TimeSpec::TimeSpec(int64_t units, int32_t scale) {
|
|
41
|
+
if (scale == 0) {
|
|
42
|
+
seconds = units;
|
|
43
|
+
microseconds = 0;
|
|
44
|
+
} else if (scale == 6) {
|
|
45
|
+
seconds = 0;
|
|
46
|
+
microseconds = units;
|
|
47
|
+
} else if (scale > 6) {
|
|
48
|
+
seconds = 0;
|
|
49
|
+
const int divider = internal::powTenSB4[scale - 6];
|
|
50
|
+
if (units < 0) {
|
|
51
|
+
units -= divider - 1;
|
|
52
|
+
}
|
|
53
|
+
microseconds = units / divider;
|
|
54
|
+
} else {
|
|
55
|
+
seconds = units / internal::powTenSB4[scale];
|
|
56
|
+
int64_t fractions = std::abs(units % internal::powTenSB4[scale]);
|
|
57
|
+
microseconds = fractions * internal::powTenSB4[6 - scale];
|
|
58
|
+
if (units < 0) {
|
|
59
|
+
microseconds = -microseconds;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
} // namespace internal
|
|
65
|
+
} // namespace sf
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
#ifndef PC_UTIL_TIME_HPP
|
|
2
|
+
#define PC_UTIL_TIME_HPP
|
|
3
|
+
|
|
4
|
+
#include <string>
|
|
5
|
+
|
|
6
|
+
#include "Python/Common.hpp"
|
|
7
|
+
|
|
8
|
+
#ifdef _WIN32
|
|
9
|
+
#include <algorithm>
|
|
10
|
+
#endif
|
|
11
|
+
|
|
12
|
+
namespace sf {
|
|
13
|
+
|
|
14
|
+
namespace internal {
|
|
15
|
+
/** python datetime.time has only support 6 bit precision, which is formated
|
|
16
|
+
* double in this file */
|
|
17
|
+
|
|
18
|
+
constexpr int SECONDS_PER_MINUTE = 60;
|
|
19
|
+
constexpr int MINUTES_PER_HOUR = 60;
|
|
20
|
+
constexpr int HOURS_PER_DAY = 24;
|
|
21
|
+
constexpr int SECONDS_PER_HOUR = MINUTES_PER_HOUR * SECONDS_PER_MINUTE;
|
|
22
|
+
|
|
23
|
+
constexpr int32_t PYTHON_DATETIME_TIME_MICROSEC_DIGIT = 6;
|
|
24
|
+
constexpr int32_t NANOSEC_DIGIT = 9;
|
|
25
|
+
|
|
26
|
+
constexpr int powTenSB4[]{1, 10, 100, 1000, 10000,
|
|
27
|
+
100000, 1000000, 10000000, 100000000, 1000000000};
|
|
28
|
+
|
|
29
|
+
/** if we use c++17 some day in the future, we can use 'constexpr
|
|
30
|
+
* std::string_view sv = "hello, world";' to replace this */
|
|
31
|
+
const std::string FIELD_NAME_EPOCH = "epoch";
|
|
32
|
+
const std::string FIELD_NAME_TIME_ZONE = "timezone";
|
|
33
|
+
const std::string FIELD_NAME_FRACTION = "fraction";
|
|
34
|
+
|
|
35
|
+
/** pow10Int means the return value should be int type. So user needs to take
|
|
36
|
+
* care not to cause int overflow by a huge parameter n.
|
|
37
|
+
* And since we are using -stdc++11 now, we can only use constexpr in this way.
|
|
38
|
+
* When we move to -stdc++14, we can have a more elegant way, e.g., loop. */
|
|
39
|
+
constexpr int pow10Int(int n) { return n == 0 ? 1 : 10 * pow10Int(n - 1); }
|
|
40
|
+
|
|
41
|
+
struct TimeSpec {
|
|
42
|
+
int64_t seconds;
|
|
43
|
+
int64_t microseconds;
|
|
44
|
+
TimeSpec(int64_t units, int32_t scale);
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
// TODO: I think we can just keep int64_t version, since we can call the
|
|
48
|
+
// function with implicit conversion from int32 to int64
|
|
49
|
+
int32_t getHourFromSeconds(int64_t seconds, int32_t scale);
|
|
50
|
+
|
|
51
|
+
int32_t getMinuteFromSeconds(int64_t seconds, int32_t scale);
|
|
52
|
+
|
|
53
|
+
int32_t getSecondFromSeconds(int64_t seconds, int32_t scale);
|
|
54
|
+
|
|
55
|
+
int32_t getMicrosecondFromSeconds(int64_t seconds, int32_t scale);
|
|
56
|
+
|
|
57
|
+
int32_t getHourFromSeconds(int32_t seconds, int32_t scale);
|
|
58
|
+
|
|
59
|
+
int32_t getMinuteFromSeconds(int32_t seconds, int32_t scale);
|
|
60
|
+
|
|
61
|
+
int32_t getSecondFromSeconds(int32_t seconds, int32_t scale);
|
|
62
|
+
|
|
63
|
+
int32_t getMicrosecondFromSeconds(int32_t seconds, int32_t scale);
|
|
64
|
+
|
|
65
|
+
} // namespace internal
|
|
66
|
+
} // namespace sf
|
|
67
|
+
|
|
68
|
+
#endif // PC_UTIL_TIME_HPP
|