duckdb 1.1.4-dev9.0 → 1.2.1-dev4.0
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.
- package/LICENSE +1 -1
- package/binding.gyp +1 -0
- package/package.json +2 -2
- package/src/connection.cpp +42 -15
- package/src/duckdb/extension/core_functions/function_list.cpp +1 -0
- package/src/duckdb/extension/core_functions/include/core_functions/scalar/map_functions.hpp +9 -0
- package/src/duckdb/extension/core_functions/scalar/date/current.cpp +1 -0
- package/src/duckdb/extension/core_functions/scalar/generic/can_implicitly_cast.cpp +2 -2
- package/src/duckdb/extension/core_functions/scalar/generic/typeof.cpp +1 -1
- package/src/duckdb/extension/core_functions/scalar/list/flatten.cpp +91 -61
- package/src/duckdb/extension/core_functions/scalar/map/map_extract.cpp +89 -8
- package/src/duckdb/extension/icu/icu-current.cpp +63 -0
- package/src/duckdb/extension/icu/icu-makedate.cpp +43 -39
- package/src/duckdb/extension/icu/icu-timezone.cpp +63 -63
- package/src/duckdb/extension/icu/icu_extension.cpp +2 -0
- package/src/duckdb/extension/icu/include/icu-casts.hpp +39 -0
- package/src/duckdb/extension/icu/include/icu-current.hpp +17 -0
- package/src/duckdb/extension/icu/third_party/icu/stubdata/stubdata.cpp +1 -1
- package/src/duckdb/extension/json/json_functions/json_structure.cpp +3 -1
- package/src/duckdb/extension/parquet/column_writer.cpp +26 -18
- package/src/duckdb/extension/parquet/include/parquet_reader.hpp +0 -6
- package/src/duckdb/extension/parquet/include/parquet_writer.hpp +15 -1
- package/src/duckdb/extension/parquet/include/resizable_buffer.hpp +1 -0
- package/src/duckdb/extension/parquet/parquet_extension.cpp +67 -15
- package/src/duckdb/extension/parquet/parquet_reader.cpp +5 -3
- package/src/duckdb/extension/parquet/parquet_writer.cpp +5 -6
- package/src/duckdb/src/catalog/catalog.cpp +21 -8
- package/src/duckdb/src/catalog/catalog_search_path.cpp +17 -1
- package/src/duckdb/src/catalog/catalog_set.cpp +1 -1
- package/src/duckdb/src/catalog/default/default_functions.cpp +0 -3
- package/src/duckdb/src/catalog/dependency_list.cpp +7 -0
- package/src/duckdb/src/common/adbc/adbc.cpp +1 -56
- package/src/duckdb/src/common/arrow/arrow_converter.cpp +3 -2
- package/src/duckdb/src/common/arrow/arrow_type_extension.cpp +58 -28
- package/src/duckdb/src/common/arrow/schema_metadata.cpp +1 -1
- package/src/duckdb/src/common/compressed_file_system.cpp +6 -2
- package/src/duckdb/src/common/enum_util.cpp +26 -22
- package/src/duckdb/src/common/error_data.cpp +3 -2
- package/src/duckdb/src/common/gzip_file_system.cpp +8 -8
- package/src/duckdb/src/common/local_file_system.cpp +2 -2
- package/src/duckdb/src/common/multi_file_reader.cpp +1 -1
- package/src/duckdb/src/common/random_engine.cpp +4 -1
- package/src/duckdb/src/common/serializer/memory_stream.cpp +23 -19
- package/src/duckdb/src/common/serializer/serializer.cpp +1 -1
- package/src/duckdb/src/common/types/bit.cpp +1 -1
- package/src/duckdb/src/common/types/column/column_data_allocator.cpp +0 -5
- package/src/duckdb/src/common/types/column/column_data_collection.cpp +4 -1
- package/src/duckdb/src/common/types/data_chunk.cpp +2 -1
- package/src/duckdb/src/common/types/row/tuple_data_segment.cpp +0 -4
- package/src/duckdb/src/common/types.cpp +1 -1
- package/src/duckdb/src/execution/index/art/art.cpp +52 -42
- package/src/duckdb/src/execution/index/art/leaf.cpp +4 -9
- package/src/duckdb/src/execution/index/art/node.cpp +13 -13
- package/src/duckdb/src/execution/index/art/prefix.cpp +21 -16
- package/src/duckdb/src/execution/index/bound_index.cpp +6 -8
- package/src/duckdb/src/execution/index/fixed_size_allocator.cpp +39 -34
- package/src/duckdb/src/execution/index/fixed_size_buffer.cpp +2 -1
- package/src/duckdb/src/execution/index/unbound_index.cpp +10 -0
- package/src/duckdb/src/execution/operator/aggregate/physical_streaming_window.cpp +62 -44
- package/src/duckdb/src/execution/operator/csv_scanner/scanner/column_count_scanner.cpp +26 -0
- package/src/duckdb/src/execution/operator/csv_scanner/scanner/string_value_scanner.cpp +69 -40
- package/src/duckdb/src/execution/operator/csv_scanner/sniffer/dialect_detection.cpp +3 -7
- package/src/duckdb/src/execution/operator/csv_scanner/sniffer/header_detection.cpp +11 -5
- package/src/duckdb/src/execution/operator/csv_scanner/sniffer/type_detection.cpp +4 -0
- package/src/duckdb/src/execution/operator/csv_scanner/state_machine/csv_state_machine_cache.cpp +8 -8
- package/src/duckdb/src/execution/operator/csv_scanner/util/csv_error.cpp +36 -12
- package/src/duckdb/src/execution/operator/csv_scanner/util/csv_reader_options.cpp +12 -9
- package/src/duckdb/src/execution/operator/join/physical_hash_join.cpp +0 -1
- package/src/duckdb/src/execution/operator/persistent/physical_copy_database.cpp +29 -1
- package/src/duckdb/src/execution/operator/persistent/physical_delete.cpp +58 -10
- package/src/duckdb/src/execution/operator/persistent/physical_insert.cpp +58 -35
- package/src/duckdb/src/execution/operator/schema/physical_create_art_index.cpp +2 -1
- package/src/duckdb/src/execution/radix_partitioned_hashtable.cpp +9 -4
- package/src/duckdb/src/execution/sample/reservoir_sample.cpp +7 -6
- package/src/duckdb/src/function/compression_config.cpp +4 -0
- package/src/duckdb/src/function/function_binder.cpp +1 -1
- package/src/duckdb/src/function/scalar/system/write_log.cpp +2 -2
- package/src/duckdb/src/function/table/arrow/arrow_duck_schema.cpp +15 -2
- package/src/duckdb/src/function/table/arrow_conversion.cpp +10 -10
- package/src/duckdb/src/function/table/copy_csv.cpp +8 -5
- package/src/duckdb/src/function/table/read_csv.cpp +21 -4
- package/src/duckdb/src/function/table/sniff_csv.cpp +7 -0
- package/src/duckdb/src/function/table/system/duckdb_extensions.cpp +4 -0
- package/src/duckdb/src/function/table/system/duckdb_secret_types.cpp +71 -0
- package/src/duckdb/src/function/table/system_functions.cpp +1 -0
- package/src/duckdb/src/function/table/table_scan.cpp +120 -36
- package/src/duckdb/src/function/table/version/pragma_version.cpp +4 -4
- package/src/duckdb/src/function/window/window_aggregate_function.cpp +6 -1
- package/src/duckdb/src/function/window/window_boundaries_state.cpp +135 -11
- package/src/duckdb/src/function/window/window_segment_tree.cpp +50 -22
- package/src/duckdb/src/function/window/window_token_tree.cpp +4 -3
- package/src/duckdb/src/include/duckdb/catalog/catalog.hpp +4 -0
- package/src/duckdb/src/include/duckdb/catalog/catalog_search_path.hpp +2 -0
- package/src/duckdb/src/include/duckdb/catalog/dependency_list.hpp +1 -0
- package/src/duckdb/src/include/duckdb/common/arrow/arrow_type_extension.hpp +4 -2
- package/src/duckdb/src/include/duckdb/common/enum_util.hpp +8 -8
- package/src/duckdb/src/include/duckdb/common/multi_file_reader.hpp +0 -2
- package/src/duckdb/src/include/duckdb/common/serializer/deserializer.hpp +8 -3
- package/src/duckdb/src/include/duckdb/common/serializer/memory_stream.hpp +6 -1
- package/src/duckdb/src/include/duckdb/common/serializer/serialization_data.hpp +25 -0
- package/src/duckdb/src/include/duckdb/common/serializer/serializer.hpp +9 -3
- package/src/duckdb/src/include/duckdb/common/types/selection_vector.hpp +1 -1
- package/src/duckdb/src/include/duckdb/execution/index/art/art.hpp +11 -14
- package/src/duckdb/src/include/duckdb/execution/index/art/prefix.hpp +5 -4
- package/src/duckdb/src/include/duckdb/execution/index/bound_index.hpp +21 -10
- package/src/duckdb/src/include/duckdb/execution/index/fixed_size_allocator.hpp +6 -5
- package/src/duckdb/src/include/duckdb/execution/index/fixed_size_buffer.hpp +37 -32
- package/src/duckdb/src/include/duckdb/execution/operator/csv_scanner/base_scanner.hpp +36 -1
- package/src/duckdb/src/include/duckdb/execution/operator/csv_scanner/column_count_scanner.hpp +3 -0
- package/src/duckdb/src/include/duckdb/execution/operator/csv_scanner/sniffer/csv_sniffer.hpp +2 -0
- package/src/duckdb/src/include/duckdb/execution/operator/csv_scanner/state_machine_options.hpp +5 -5
- package/src/duckdb/src/include/duckdb/execution/operator/csv_scanner/string_value_scanner.hpp +5 -30
- package/src/duckdb/src/include/duckdb/execution/reservoir_sample.hpp +7 -1
- package/src/duckdb/src/include/duckdb/function/scalar_function.hpp +3 -3
- package/src/duckdb/src/include/duckdb/function/table/arrow/arrow_duck_schema.hpp +1 -0
- package/src/duckdb/src/include/duckdb/function/table/system_functions.hpp +4 -0
- package/src/duckdb/src/include/duckdb/function/window/window_boundaries_state.hpp +2 -2
- package/src/duckdb/src/include/duckdb/logging/logger.hpp +40 -119
- package/src/duckdb/src/include/duckdb/logging/logging.hpp +0 -2
- package/src/duckdb/src/include/duckdb/main/config.hpp +5 -0
- package/src/duckdb/src/include/duckdb/main/connection.hpp +0 -8
- package/src/duckdb/src/include/duckdb/main/connection_manager.hpp +2 -1
- package/src/duckdb/src/include/duckdb/main/extension.hpp +1 -0
- package/src/duckdb/src/include/duckdb/main/extension_entries.hpp +11 -7
- package/src/duckdb/src/include/duckdb/main/extension_helper.hpp +1 -0
- package/src/duckdb/src/include/duckdb/main/secret/secret.hpp +2 -0
- package/src/duckdb/src/include/duckdb/main/secret/secret_manager.hpp +3 -0
- package/src/duckdb/src/include/duckdb/main/settings.hpp +10 -0
- package/src/duckdb/src/include/duckdb/parser/constraint.hpp +9 -0
- package/src/duckdb/src/include/duckdb/parser/expression/window_expression.hpp +36 -9
- package/src/duckdb/src/include/duckdb/parser/parsed_data/create_view_info.hpp +2 -1
- package/src/duckdb/src/include/duckdb/parser/query_node/set_operation_node.hpp +8 -2
- package/src/duckdb/src/include/duckdb/planner/binder.hpp +4 -0
- package/src/duckdb/src/include/duckdb/planner/expression/bound_parameter_data.hpp +9 -1
- package/src/duckdb/src/include/duckdb/planner/filter/constant_filter.hpp +1 -0
- package/src/duckdb/src/include/duckdb/planner/filter/in_filter.hpp +0 -2
- package/src/duckdb/src/include/duckdb/planner/filter/optional_filter.hpp +4 -4
- package/src/duckdb/src/include/duckdb/planner/table_filter.hpp +1 -1
- package/src/duckdb/src/include/duckdb/storage/data_table.hpp +14 -10
- package/src/duckdb/src/include/duckdb/storage/index_storage_info.hpp +4 -0
- package/src/duckdb/src/include/duckdb/storage/single_file_block_manager.hpp +6 -1
- package/src/duckdb/src/include/duckdb/storage/storage_info.hpp +7 -2
- package/src/duckdb/src/include/duckdb/storage/storage_manager.hpp +9 -0
- package/src/duckdb/src/include/duckdb/storage/storage_options.hpp +2 -0
- package/src/duckdb/src/include/duckdb/storage/string_uncompressed.hpp +4 -3
- package/src/duckdb/src/include/duckdb/storage/table/column_data.hpp +2 -0
- package/src/duckdb/src/include/duckdb/storage/table/table_index_list.hpp +6 -4
- package/src/duckdb/src/include/duckdb/storage/table/table_statistics.hpp +1 -1
- package/src/duckdb/src/include/duckdb/storage/write_ahead_log.hpp +2 -0
- package/src/duckdb/src/include/duckdb/transaction/local_storage.hpp +2 -0
- package/src/duckdb/src/include/duckdb/transaction/meta_transaction.hpp +1 -1
- package/src/duckdb/src/logging/logger.cpp +8 -66
- package/src/duckdb/src/main/attached_database.cpp +3 -1
- package/src/duckdb/src/main/client_context.cpp +4 -2
- package/src/duckdb/src/main/config.cpp +20 -2
- package/src/duckdb/src/main/connection.cpp +2 -29
- package/src/duckdb/src/main/connection_manager.cpp +5 -3
- package/src/duckdb/src/main/database.cpp +2 -2
- package/src/duckdb/src/main/extension/extension_helper.cpp +4 -5
- package/src/duckdb/src/main/extension/extension_install.cpp +23 -10
- package/src/duckdb/src/main/extension/extension_load.cpp +6 -7
- package/src/duckdb/src/main/extension.cpp +27 -9
- package/src/duckdb/src/main/secret/secret_manager.cpp +11 -0
- package/src/duckdb/src/main/settings/custom_settings.cpp +44 -0
- package/src/duckdb/src/optimizer/column_lifetime_analyzer.cpp +6 -0
- package/src/duckdb/src/optimizer/filter_combiner.cpp +13 -3
- package/src/duckdb/src/optimizer/filter_pushdown.cpp +33 -6
- package/src/duckdb/src/optimizer/late_materialization.cpp +14 -3
- package/src/duckdb/src/optimizer/remove_unused_columns.cpp +0 -3
- package/src/duckdb/src/parser/parsed_data/attach_info.cpp +5 -1
- package/src/duckdb/src/parser/parsed_data/create_view_info.cpp +6 -3
- package/src/duckdb/src/parser/query_node/set_operation_node.cpp +49 -0
- package/src/duckdb/src/parser/transform/expression/transform_columnref.cpp +1 -0
- package/src/duckdb/src/parser/transform/expression/transform_function.cpp +50 -12
- package/src/duckdb/src/planner/binder/expression/bind_columnref_expression.cpp +7 -5
- package/src/duckdb/src/planner/binder/expression/bind_comparison_expression.cpp +1 -0
- package/src/duckdb/src/planner/binder/expression/bind_operator_expression.cpp +2 -2
- package/src/duckdb/src/planner/binder/expression/bind_star_expression.cpp +12 -2
- package/src/duckdb/src/planner/binder/statement/bind_copy_database.cpp +0 -1
- package/src/duckdb/src/planner/binder/statement/bind_create.cpp +55 -39
- package/src/duckdb/src/planner/binder/statement/bind_execute.cpp +2 -1
- package/src/duckdb/src/planner/binder/tableref/bind_basetableref.cpp +15 -7
- package/src/duckdb/src/planner/binder/tableref/bind_showref.cpp +13 -8
- package/src/duckdb/src/planner/binder/tableref/bind_table_function.cpp +8 -3
- package/src/duckdb/src/planner/expression/bound_function_expression.cpp +17 -1
- package/src/duckdb/src/planner/expression_binder/index_binder.cpp +1 -0
- package/src/duckdb/src/planner/filter/conjunction_filter.cpp +1 -0
- package/src/duckdb/src/planner/filter/constant_filter.cpp +21 -0
- package/src/duckdb/src/planner/filter/in_filter.cpp +4 -7
- package/src/duckdb/src/planner/logical_operator.cpp +5 -3
- package/src/duckdb/src/planner/planner.cpp +1 -1
- package/src/duckdb/src/planner/subquery/flatten_dependent_join.cpp +2 -0
- package/src/duckdb/src/storage/checkpoint/table_data_writer.cpp +3 -4
- package/src/duckdb/src/storage/checkpoint_manager.cpp +3 -5
- package/src/duckdb/src/storage/compression/dictionary/decompression.cpp +4 -4
- package/src/duckdb/src/storage/compression/fsst.cpp +2 -2
- package/src/duckdb/src/storage/compression/roaring/common.cpp +10 -1
- package/src/duckdb/src/storage/compression/string_uncompressed.cpp +11 -6
- package/src/duckdb/src/storage/compression/validity_uncompressed.cpp +4 -0
- package/src/duckdb/src/storage/compression/zstd.cpp +6 -0
- package/src/duckdb/src/storage/data_table.cpp +104 -109
- package/src/duckdb/src/storage/local_storage.cpp +8 -6
- package/src/duckdb/src/storage/magic_bytes.cpp +1 -1
- package/src/duckdb/src/storage/serialization/serialize_dependency.cpp +3 -3
- package/src/duckdb/src/storage/serialization/serialize_nodes.cpp +3 -3
- package/src/duckdb/src/storage/serialization/serialize_query_node.cpp +7 -5
- package/src/duckdb/src/storage/single_file_block_manager.cpp +95 -28
- package/src/duckdb/src/storage/storage_info.cpp +38 -0
- package/src/duckdb/src/storage/storage_manager.cpp +11 -0
- package/src/duckdb/src/storage/table/column_data.cpp +4 -0
- package/src/duckdb/src/storage/table/column_data_checkpointer.cpp +3 -3
- package/src/duckdb/src/storage/table/row_group_collection.cpp +67 -68
- package/src/duckdb/src/storage/table/table_statistics.cpp +4 -4
- package/src/duckdb/src/storage/table_index_list.cpp +41 -15
- package/src/duckdb/src/storage/wal_replay.cpp +3 -1
- package/src/duckdb/src/storage/write_ahead_log.cpp +11 -4
- package/src/duckdb/src/transaction/meta_transaction.cpp +1 -1
- package/src/duckdb/src/verification/deserialized_statement_verifier.cpp +2 -1
- package/src/duckdb/third_party/httplib/httplib.hpp +0 -1
- package/src/duckdb/third_party/re2/util/logging.h +10 -10
- package/src/duckdb/ub_src_function_table_system.cpp +2 -0
@@ -9,6 +9,7 @@
|
|
9
9
|
#include "duckdb/function/cast/cast_function_set.hpp"
|
10
10
|
#include "duckdb/main/extension_util.hpp"
|
11
11
|
#include "duckdb/parser/parsed_data/create_scalar_function_info.hpp"
|
12
|
+
#include "include/icu-casts.hpp"
|
12
13
|
#include "include/icu-datefunc.hpp"
|
13
14
|
#include "include/icu-datetrunc.hpp"
|
14
15
|
|
@@ -16,55 +17,58 @@
|
|
16
17
|
|
17
18
|
namespace duckdb {
|
18
19
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
}
|
24
|
-
|
25
|
-
// Extract the time zone parts
|
26
|
-
SetTime(calendar, instant);
|
27
|
-
const auto era = ExtractField(calendar, UCAL_ERA);
|
28
|
-
const auto year = ExtractField(calendar, UCAL_YEAR);
|
29
|
-
const auto mm = ExtractField(calendar, UCAL_MONTH) + 1;
|
30
|
-
const auto dd = ExtractField(calendar, UCAL_DATE);
|
31
|
-
|
32
|
-
const auto yyyy = era ? year : (-year + 1);
|
33
|
-
date_t result;
|
34
|
-
if (!Date::TryFromDate(yyyy, mm, dd, result)) {
|
35
|
-
throw ConversionException("Unable to convert TIMESTAMPTZ to DATE");
|
36
|
-
}
|
20
|
+
date_t ICUMakeDate::Operation(icu::Calendar *calendar, timestamp_t instant) {
|
21
|
+
if (!Timestamp::IsFinite(instant)) {
|
22
|
+
return Timestamp::GetDate(instant);
|
23
|
+
}
|
37
24
|
|
38
|
-
|
25
|
+
// Extract the time zone parts
|
26
|
+
SetTime(calendar, instant);
|
27
|
+
const auto era = ExtractField(calendar, UCAL_ERA);
|
28
|
+
const auto year = ExtractField(calendar, UCAL_YEAR);
|
29
|
+
const auto mm = ExtractField(calendar, UCAL_MONTH) + 1;
|
30
|
+
const auto dd = ExtractField(calendar, UCAL_DATE);
|
31
|
+
|
32
|
+
const auto yyyy = era ? year : (-year + 1);
|
33
|
+
date_t result;
|
34
|
+
if (!Date::TryFromDate(yyyy, mm, dd, result)) {
|
35
|
+
throw ConversionException("Unable to convert TIMESTAMPTZ to DATE");
|
39
36
|
}
|
40
37
|
|
41
|
-
|
42
|
-
|
43
|
-
auto &info = cast_data.info->Cast<BindData>();
|
44
|
-
CalendarPtr calendar(info.calendar->clone());
|
38
|
+
return result;
|
39
|
+
}
|
45
40
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
41
|
+
date_t ICUMakeDate::ToDate(ClientContext &context, timestamp_t instant) {
|
42
|
+
ICUDateFunc::BindData data(context);
|
43
|
+
return Operation(data.calendar.get(), instant);
|
44
|
+
}
|
50
45
|
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
46
|
+
bool ICUMakeDate::CastToDate(Vector &source, Vector &result, idx_t count, CastParameters ¶meters) {
|
47
|
+
auto &cast_data = parameters.cast_data->Cast<CastData>();
|
48
|
+
auto &info = cast_data.info->Cast<BindData>();
|
49
|
+
CalendarPtr calendar(info.calendar->clone());
|
55
50
|
|
56
|
-
|
51
|
+
UnaryExecutor::Execute<timestamp_t, date_t>(source, result, count,
|
52
|
+
[&](timestamp_t input) { return Operation(calendar.get(), input); });
|
53
|
+
return true;
|
54
|
+
}
|
57
55
|
|
58
|
-
|
56
|
+
BoundCastInfo ICUMakeDate::BindCastToDate(BindCastInput &input, const LogicalType &source, const LogicalType &target) {
|
57
|
+
if (!input.context) {
|
58
|
+
throw InternalException("Missing context for TIMESTAMPTZ to DATE cast.");
|
59
59
|
}
|
60
60
|
|
61
|
-
|
62
|
-
auto &config = DBConfig::GetConfig(db);
|
63
|
-
auto &casts = config.GetCastFunctions();
|
61
|
+
auto cast_data = make_uniq<CastData>(make_uniq<BindData>(*input.context));
|
64
62
|
|
65
|
-
|
66
|
-
|
67
|
-
|
63
|
+
return BoundCastInfo(CastToDate, std::move(cast_data));
|
64
|
+
}
|
65
|
+
|
66
|
+
void ICUMakeDate::AddCasts(DatabaseInstance &db) {
|
67
|
+
auto &config = DBConfig::GetConfig(db);
|
68
|
+
auto &casts = config.GetCastFunctions();
|
69
|
+
|
70
|
+
casts.RegisterCastFunction(LogicalType::TIMESTAMP_TZ, LogicalType::DATE, BindCastToDate);
|
71
|
+
}
|
68
72
|
|
69
73
|
struct ICUMakeTimestampTZFunc : public ICUDateFunc {
|
70
74
|
template <typename T>
|
@@ -7,6 +7,7 @@
|
|
7
7
|
#include "duckdb/main/extension_util.hpp"
|
8
8
|
#include "duckdb/parser/parsed_data/create_scalar_function_info.hpp"
|
9
9
|
#include "duckdb/parser/parsed_data/create_table_function_info.hpp"
|
10
|
+
#include "include/icu-casts.hpp"
|
10
11
|
#include "include/icu-datefunc.hpp"
|
11
12
|
#include "duckdb/transaction/meta_transaction.hpp"
|
12
13
|
#include "duckdb/common/operator/cast_operators.hpp"
|
@@ -326,82 +327,81 @@ struct ICULocalTimeFunc : public ICUDateFunc {
|
|
326
327
|
}
|
327
328
|
};
|
328
329
|
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
auto time = Time::NormalizeTimeTZ(timetz);
|
330
|
+
dtime_tz_t ICUToTimeTZ::Operation(icu::Calendar *calendar, dtime_tz_t timetz) {
|
331
|
+
// Normalise to +00:00, add TZ offset, then set offset to TZ
|
332
|
+
auto time = Time::NormalizeTimeTZ(timetz);
|
333
333
|
|
334
|
-
|
335
|
-
|
336
|
-
|
334
|
+
auto offset = ExtractField(calendar, UCAL_ZONE_OFFSET);
|
335
|
+
offset += ExtractField(calendar, UCAL_DST_OFFSET);
|
336
|
+
offset /= Interval::MSECS_PER_SEC;
|
337
337
|
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
|
338
|
+
date_t date(0);
|
339
|
+
time = Interval::Add(time, {0, 0, offset * Interval::MICROS_PER_SEC}, date);
|
340
|
+
return dtime_tz_t(time, offset);
|
341
|
+
}
|
342
342
|
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
343
|
+
bool ICUToTimeTZ::ToTimeTZ(icu::Calendar *calendar, timestamp_t instant, dtime_tz_t &result) {
|
344
|
+
if (!ICUIsFinite(instant)) {
|
345
|
+
return false;
|
346
|
+
}
|
347
347
|
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
348
|
+
// Time in current TZ
|
349
|
+
auto micros = int32_t(SetTime(calendar, instant));
|
350
|
+
const auto hour = ExtractField(calendar, UCAL_HOUR_OF_DAY);
|
351
|
+
const auto minute = ExtractField(calendar, UCAL_MINUTE);
|
352
|
+
const auto second = ExtractField(calendar, UCAL_SECOND);
|
353
|
+
const auto millis = ExtractField(calendar, UCAL_MILLISECOND);
|
354
|
+
micros += millis * int32_t(Interval::MICROS_PER_MSEC);
|
355
|
+
if (!Time::IsValidTime(hour, minute, second, micros)) {
|
356
|
+
return false;
|
357
|
+
}
|
358
|
+
const auto time = Time::FromTime(hour, minute, second, micros);
|
359
359
|
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
360
|
+
// Offset in current TZ
|
361
|
+
auto offset = ExtractField(calendar, UCAL_ZONE_OFFSET);
|
362
|
+
offset += ExtractField(calendar, UCAL_DST_OFFSET);
|
363
|
+
offset /= Interval::MSECS_PER_SEC;
|
364
364
|
|
365
|
-
|
366
|
-
|
367
|
-
|
365
|
+
result = dtime_tz_t(time, offset);
|
366
|
+
return true;
|
367
|
+
}
|
368
368
|
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
369
|
+
bool ICUToTimeTZ::CastToTimeTZ(Vector &source, Vector &result, idx_t count, CastParameters ¶meters) {
|
370
|
+
auto &cast_data = parameters.cast_data->Cast<CastData>();
|
371
|
+
auto &info = cast_data.info->Cast<BindData>();
|
372
|
+
CalendarPtr calendar(info.calendar->clone());
|
373
|
+
|
374
|
+
UnaryExecutor::ExecuteWithNulls<timestamp_t, dtime_tz_t>(source, result, count,
|
375
|
+
[&](timestamp_t input, ValidityMask &mask, idx_t idx) {
|
376
|
+
dtime_tz_t output;
|
377
|
+
if (ToTimeTZ(calendar.get(), input, output)) {
|
378
|
+
return output;
|
379
|
+
} else {
|
380
|
+
mask.SetInvalid(idx);
|
381
|
+
return dtime_tz_t();
|
382
|
+
}
|
383
|
+
});
|
384
|
+
return true;
|
385
|
+
}
|
373
386
|
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
return output;
|
379
|
-
} else {
|
380
|
-
mask.SetInvalid(idx);
|
381
|
-
return dtime_tz_t();
|
382
|
-
}
|
383
|
-
});
|
384
|
-
return true;
|
387
|
+
BoundCastInfo ICUToTimeTZ::BindCastToTimeTZ(BindCastInput &input, const LogicalType &source,
|
388
|
+
const LogicalType &target) {
|
389
|
+
if (!input.context) {
|
390
|
+
throw InternalException("Missing context for TIMESTAMPTZ to TIMETZ cast.");
|
385
391
|
}
|
386
392
|
|
387
|
-
|
388
|
-
if (!input.context) {
|
389
|
-
throw InternalException("Missing context for TIMESTAMPTZ to TIMETZ cast.");
|
390
|
-
}
|
391
|
-
|
392
|
-
auto cast_data = make_uniq<CastData>(make_uniq<BindData>(*input.context));
|
393
|
+
auto cast_data = make_uniq<CastData>(make_uniq<BindData>(*input.context));
|
393
394
|
|
394
|
-
|
395
|
-
|
395
|
+
return BoundCastInfo(CastToTimeTZ, std::move(cast_data));
|
396
|
+
}
|
396
397
|
|
397
|
-
|
398
|
-
|
399
|
-
|
398
|
+
void ICUToTimeTZ::AddCasts(DatabaseInstance &db) {
|
399
|
+
auto &config = DBConfig::GetConfig(db);
|
400
|
+
auto &casts = config.GetCastFunctions();
|
400
401
|
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
};
|
402
|
+
const auto implicit_cost = CastRules::ImplicitCast(LogicalType::TIMESTAMP_TZ, LogicalType::TIME_TZ);
|
403
|
+
casts.RegisterCastFunction(LogicalType::TIMESTAMP_TZ, LogicalType::TIME_TZ, BindCastToTimeTZ, implicit_cost);
|
404
|
+
}
|
405
405
|
|
406
406
|
struct ICUTimeZoneFunc : public ICUDateFunc {
|
407
407
|
template <typename OP, typename T>
|
@@ -13,6 +13,7 @@
|
|
13
13
|
#include "duckdb/parser/parsed_data/create_scalar_function_info.hpp"
|
14
14
|
#include "duckdb/parser/parsed_data/create_table_function_info.hpp"
|
15
15
|
#include "duckdb/planner/expression/bound_function_expression.hpp"
|
16
|
+
#include "include/icu-current.hpp"
|
16
17
|
#include "include/icu-dateadd.hpp"
|
17
18
|
#include "include/icu-datepart.hpp"
|
18
19
|
#include "include/icu-datesub.hpp"
|
@@ -382,6 +383,7 @@ static void LoadInternal(DuckDB &ddb) {
|
|
382
383
|
config.AddExtensionOption("TimeZone", "The current time zone", LogicalType::VARCHAR, Value(tz_string),
|
383
384
|
SetICUTimeZone);
|
384
385
|
|
386
|
+
RegisterICUCurrentFunctions(db);
|
385
387
|
RegisterICUDateAddFunctions(db);
|
386
388
|
RegisterICUDatePartFunctions(db);
|
387
389
|
RegisterICUDateSubFunctions(db);
|
@@ -0,0 +1,39 @@
|
|
1
|
+
//===----------------------------------------------------------------------===//
|
2
|
+
// DuckDB
|
3
|
+
//
|
4
|
+
// icu-datefunc.hpp
|
5
|
+
//
|
6
|
+
//
|
7
|
+
//===----------------------------------------------------------------------===//
|
8
|
+
|
9
|
+
#pragma once
|
10
|
+
|
11
|
+
#include "icu-datefunc.hpp"
|
12
|
+
|
13
|
+
namespace duckdb {
|
14
|
+
|
15
|
+
struct ICUMakeDate : public ICUDateFunc {
|
16
|
+
static date_t Operation(icu::Calendar *calendar, timestamp_t instant);
|
17
|
+
|
18
|
+
static bool CastToDate(Vector &source, Vector &result, idx_t count, CastParameters ¶meters);
|
19
|
+
|
20
|
+
static BoundCastInfo BindCastToDate(BindCastInput &input, const LogicalType &source, const LogicalType &target);
|
21
|
+
|
22
|
+
static void AddCasts(DatabaseInstance &db);
|
23
|
+
|
24
|
+
static date_t ToDate(ClientContext &context, timestamp_t instant);
|
25
|
+
};
|
26
|
+
|
27
|
+
struct ICUToTimeTZ : public ICUDateFunc {
|
28
|
+
static dtime_tz_t Operation(icu::Calendar *calendar, dtime_tz_t timetz);
|
29
|
+
|
30
|
+
static bool ToTimeTZ(icu::Calendar *calendar, timestamp_t instant, dtime_tz_t &result);
|
31
|
+
|
32
|
+
static bool CastToTimeTZ(Vector &source, Vector &result, idx_t count, CastParameters ¶meters);
|
33
|
+
|
34
|
+
static BoundCastInfo BindCastToTimeTZ(BindCastInput &input, const LogicalType &source, const LogicalType &target);
|
35
|
+
|
36
|
+
static void AddCasts(DatabaseInstance &db);
|
37
|
+
};
|
38
|
+
|
39
|
+
} // namespace duckdb
|
@@ -0,0 +1,17 @@
|
|
1
|
+
//===----------------------------------------------------------------------===//
|
2
|
+
// DuckDB
|
3
|
+
//
|
4
|
+
// icu-current.hpp
|
5
|
+
//
|
6
|
+
//
|
7
|
+
//===----------------------------------------------------------------------===//
|
8
|
+
|
9
|
+
#pragma once
|
10
|
+
|
11
|
+
#include "duckdb.hpp"
|
12
|
+
|
13
|
+
namespace duckdb {
|
14
|
+
|
15
|
+
void RegisterICUCurrentFunctions(DatabaseInstance &db);
|
16
|
+
|
17
|
+
} // namespace duckdb
|