duckdb 0.8.1-dev96.0 → 0.8.2-dev1.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/binding.gyp +8 -8
- package/package.json +3 -1
- package/src/duckdb/extension/icu/icu-datepart.cpp +1 -1
- package/src/duckdb/extension/icu/icu-extension.cpp +1 -1
- package/src/duckdb/extension/icu/icu-makedate.cpp +5 -4
- package/src/duckdb/extension/icu/icu-strptime.cpp +1 -1
- package/src/duckdb/extension/icu/third_party/icu/i18n/nfsubs.cpp +0 -2
- package/src/duckdb/extension/json/buffered_json_reader.cpp +23 -14
- package/src/duckdb/extension/json/include/buffered_json_reader.hpp +6 -6
- package/src/duckdb/extension/json/include/json_common.hpp +12 -2
- package/src/duckdb/extension/json/include/json_scan.hpp +5 -2
- package/src/duckdb/extension/json/json_functions/json_contains.cpp +5 -0
- package/src/duckdb/extension/json/json_functions/json_create.cpp +10 -10
- package/src/duckdb/extension/json/json_functions/json_merge_patch.cpp +2 -2
- package/src/duckdb/extension/json/json_functions/json_serialize_sql.cpp +2 -2
- package/src/duckdb/extension/json/json_functions/json_structure.cpp +5 -3
- package/src/duckdb/extension/json/json_functions/json_transform.cpp +11 -11
- package/src/duckdb/extension/json/json_functions/read_json.cpp +2 -1
- package/src/duckdb/extension/json/json_functions.cpp +6 -3
- package/src/duckdb/extension/json/json_scan.cpp +43 -27
- package/src/duckdb/extension/parquet/column_reader.cpp +5 -1
- package/src/duckdb/extension/parquet/include/decode_utils.hpp +6 -0
- package/src/duckdb/extension/parquet/parquet-extension.cpp +26 -1
- package/src/duckdb/src/catalog/catalog.cpp +5 -17
- package/src/duckdb/src/catalog/catalog_entry/duck_table_entry.cpp +7 -1
- package/src/duckdb/src/catalog/catalog_entry/table_catalog_entry.cpp +121 -0
- package/src/duckdb/src/catalog/catalog_search_path.cpp +49 -12
- package/src/duckdb/src/catalog/default/default_types.cpp +9 -84
- package/src/duckdb/src/common/adbc/adbc.cpp +118 -12
- package/src/duckdb/src/common/adbc/driver_manager.cpp +0 -20
- package/src/duckdb/src/common/arrow/arrow_converter.cpp +11 -12
- package/src/duckdb/src/common/arrow/arrow_wrapper.cpp +4 -3
- package/src/duckdb/src/common/exception.cpp +4 -1
- package/src/duckdb/src/common/exception_format_value.cpp +24 -15
- package/src/duckdb/src/common/multi_file_reader.cpp +3 -0
- package/src/duckdb/src/common/random_engine.cpp +1 -1
- package/src/duckdb/src/common/types/row/row_data_collection_scanner.cpp +5 -4
- package/src/duckdb/src/common/types/row/tuple_data_scatter_gather.cpp +44 -7
- package/src/duckdb/src/common/types/time.cpp +2 -8
- package/src/duckdb/src/common/types/timestamp.cpp +37 -1
- package/src/duckdb/src/common/types/value.cpp +1 -0
- package/src/duckdb/src/common/types.cpp +4 -0
- package/src/duckdb/src/core_functions/aggregate/algebraic/avg.cpp +30 -33
- package/src/duckdb/src/core_functions/aggregate/algebraic/covar.cpp +0 -4
- package/src/duckdb/src/core_functions/aggregate/distributive/approx_count.cpp +30 -33
- package/src/duckdb/src/core_functions/aggregate/distributive/arg_min_max.cpp +52 -65
- package/src/duckdb/src/core_functions/aggregate/distributive/bitagg.cpp +48 -48
- package/src/duckdb/src/core_functions/aggregate/distributive/bitstring_agg.cpp +39 -40
- package/src/duckdb/src/core_functions/aggregate/distributive/bool.cpp +32 -32
- package/src/duckdb/src/core_functions/aggregate/distributive/entropy.cpp +34 -34
- package/src/duckdb/src/core_functions/aggregate/distributive/kurtosis.cpp +30 -31
- package/src/duckdb/src/core_functions/aggregate/distributive/minmax.cpp +88 -100
- package/src/duckdb/src/core_functions/aggregate/distributive/product.cpp +17 -17
- package/src/duckdb/src/core_functions/aggregate/distributive/skew.cpp +25 -27
- package/src/duckdb/src/core_functions/aggregate/distributive/string_agg.cpp +37 -38
- package/src/duckdb/src/core_functions/aggregate/distributive/sum.cpp +22 -22
- package/src/duckdb/src/core_functions/aggregate/holistic/approximate_quantile.cpp +44 -80
- package/src/duckdb/src/core_functions/aggregate/holistic/mode.cpp +49 -51
- package/src/duckdb/src/core_functions/aggregate/holistic/quantile.cpp +104 -122
- package/src/duckdb/src/core_functions/aggregate/holistic/reservoir_quantile.cpp +57 -93
- package/src/duckdb/src/core_functions/aggregate/nested/histogram.cpp +22 -23
- package/src/duckdb/src/core_functions/aggregate/nested/list.cpp +18 -19
- package/src/duckdb/src/core_functions/aggregate/regression/regr_avg.cpp +16 -18
- package/src/duckdb/src/core_functions/aggregate/regression/regr_intercept.cpp +22 -25
- package/src/duckdb/src/core_functions/aggregate/regression/regr_r2.cpp +19 -24
- package/src/duckdb/src/core_functions/aggregate/regression/regr_sxx_syy.cpp +18 -23
- package/src/duckdb/src/core_functions/aggregate/regression/regr_sxy.cpp +14 -18
- package/src/duckdb/src/core_functions/function_list.cpp +1 -0
- package/src/duckdb/src/core_functions/scalar/date/date_part.cpp +1 -1
- package/src/duckdb/src/core_functions/scalar/date/make_date.cpp +3 -0
- package/src/duckdb/src/core_functions/scalar/generic/system_functions.cpp +14 -0
- package/src/duckdb/src/core_functions/scalar/list/array_slice.cpp +1 -1
- package/src/duckdb/src/core_functions/scalar/list/list_aggregates.cpp +23 -6
- package/src/duckdb/src/core_functions/scalar/list/list_lambdas.cpp +1 -2
- package/src/duckdb/src/core_functions/scalar/map/map_concat.cpp +3 -0
- package/src/duckdb/src/core_functions/scalar/math/numeric.cpp +3 -3
- package/src/duckdb/src/execution/index/art/art.cpp +80 -7
- package/src/duckdb/src/execution/index/art/fixed_size_allocator.cpp +20 -1
- package/src/duckdb/src/execution/index/art/leaf.cpp +11 -11
- package/src/duckdb/src/execution/index/art/leaf_segment.cpp +10 -0
- package/src/duckdb/src/execution/index/art/node.cpp +48 -35
- package/src/duckdb/src/execution/index/art/node16.cpp +3 -0
- package/src/duckdb/src/execution/index/art/node256.cpp +1 -0
- package/src/duckdb/src/execution/index/art/node4.cpp +3 -0
- package/src/duckdb/src/execution/index/art/node48.cpp +2 -0
- package/src/duckdb/src/execution/index/art/prefix.cpp +2 -0
- package/src/duckdb/src/execution/join_hashtable.cpp +2 -0
- package/src/duckdb/src/execution/operator/aggregate/physical_window.cpp +26 -9
- package/src/duckdb/src/execution/operator/helper/physical_reset.cpp +5 -2
- package/src/duckdb/src/execution/operator/helper/physical_set.cpp +5 -1
- package/src/duckdb/src/execution/operator/join/physical_iejoin.cpp +3 -6
- package/src/duckdb/src/execution/operator/projection/physical_tableinout_function.cpp +1 -0
- package/src/duckdb/src/execution/operator/projection/physical_unnest.cpp +8 -3
- package/src/duckdb/src/execution/operator/schema/physical_attach.cpp +0 -1
- package/src/duckdb/src/execution/operator/schema/physical_create_index.cpp +29 -3
- package/src/duckdb/src/execution/reservoir_sample.cpp +18 -4
- package/src/duckdb/src/function/aggregate/distributive/count.cpp +159 -21
- package/src/duckdb/src/function/aggregate/distributive/first.cpp +67 -74
- package/src/duckdb/src/function/aggregate/sorted_aggregate_function.cpp +7 -7
- package/src/duckdb/src/function/cast/list_casts.cpp +2 -4
- package/src/duckdb/src/function/pragma/pragma_queries.cpp +33 -23
- package/src/duckdb/src/function/scalar/list/list_extract.cpp +1 -1
- package/src/duckdb/src/function/scalar/operators/arithmetic.cpp +1 -1
- package/src/duckdb/src/function/scalar/string/regexp/regexp_util.cpp +6 -2
- package/src/duckdb/src/function/scalar/system/aggregate_export.cpp +2 -2
- package/src/duckdb/src/function/table/arrow.cpp +2 -2
- package/src/duckdb/src/function/table/checkpoint.cpp +3 -0
- package/src/duckdb/src/function/table/read_csv.cpp +15 -17
- package/src/duckdb/src/function/table/repeat.cpp +3 -0
- package/src/duckdb/src/function/table/repeat_row.cpp +8 -1
- package/src/duckdb/src/function/table/system/pragma_storage_info.cpp +4 -4
- package/src/duckdb/src/function/table/system/test_vector_types.cpp +81 -25
- package/src/duckdb/src/function/table/table_scan.cpp +2 -2
- package/src/duckdb/src/function/table/version/pragma_version.cpp +2 -2
- package/src/duckdb/src/include/duckdb/catalog/catalog.hpp +0 -3
- package/src/duckdb/src/include/duckdb/catalog/catalog_entry/duck_table_entry.hpp +2 -0
- package/src/duckdb/src/include/duckdb/catalog/catalog_entry/table_catalog_entry.hpp +11 -1
- package/src/duckdb/src/include/duckdb/catalog/catalog_search_path.hpp +8 -2
- package/src/duckdb/src/include/duckdb/catalog/default/builtin_types/types.hpp +97 -0
- package/src/duckdb/src/include/duckdb/common/arrow/arrow_appender.hpp +1 -1
- package/src/duckdb/src/include/duckdb/common/arrow/arrow_converter.hpp +2 -3
- package/src/duckdb/src/include/duckdb/common/arrow/arrow_options.hpp +8 -1
- package/src/duckdb/src/include/duckdb/common/arrow/result_arrow_wrapper.hpp +0 -1
- package/src/duckdb/src/include/duckdb/common/bit_utils.hpp +16 -22
- package/src/duckdb/src/include/duckdb/common/exception.hpp +3 -0
- package/src/duckdb/src/include/duckdb/common/types/time.hpp +2 -0
- package/src/duckdb/src/include/duckdb/common/types/timestamp.hpp +4 -14
- package/src/duckdb/src/include/duckdb/common/vector_operations/aggregate_executor.hpp +92 -57
- package/src/duckdb/src/include/duckdb/core_functions/aggregate/algebraic/corr.hpp +20 -24
- package/src/duckdb/src/include/duckdb/core_functions/aggregate/algebraic/covar.hpp +36 -39
- package/src/duckdb/src/include/duckdb/core_functions/aggregate/algebraic/stddev.hpp +57 -53
- package/src/duckdb/src/include/duckdb/core_functions/aggregate/regression/regr_count.hpp +8 -9
- package/src/duckdb/src/include/duckdb/core_functions/aggregate/regression/regr_slope.hpp +16 -18
- package/src/duckdb/src/include/duckdb/core_functions/aggregate/sum_helpers.hpp +7 -8
- package/src/duckdb/src/include/duckdb/core_functions/scalar/generic_functions.hpp +9 -0
- package/src/duckdb/src/include/duckdb/core_functions/scalar/map_functions.hpp +2 -6
- package/src/duckdb/src/include/duckdb/core_functions/scalar/string_functions.hpp +16 -36
- package/src/duckdb/src/include/duckdb/execution/index/art/art.hpp +10 -4
- package/src/duckdb/src/include/duckdb/execution/index/art/fixed_size_allocator.hpp +3 -0
- package/src/duckdb/src/include/duckdb/execution/index/art/leaf.hpp +1 -1
- package/src/duckdb/src/include/duckdb/execution/index/art/leaf_segment.hpp +2 -0
- package/src/duckdb/src/include/duckdb/execution/index/art/node.hpp +13 -3
- package/src/duckdb/src/include/duckdb/execution/index/art/node48.hpp +1 -0
- package/src/duckdb/src/include/duckdb/function/aggregate_function.hpp +9 -30
- package/src/duckdb/src/include/duckdb/function/aggregate_state.hpp +95 -0
- package/src/duckdb/src/include/duckdb/function/function_serialization.hpp +4 -2
- package/src/duckdb/src/include/duckdb/function/scalar/nested_functions.hpp +1 -1
- package/src/duckdb/src/include/duckdb/function/scalar_function.hpp +2 -1
- package/src/duckdb/src/include/duckdb/function/table_function.hpp +3 -2
- package/src/duckdb/src/include/duckdb/main/attached_database.hpp +4 -1
- package/src/duckdb/src/include/duckdb/main/capi/capi_internal.hpp +3 -1
- package/src/duckdb/src/include/duckdb/main/config.hpp +5 -0
- package/src/duckdb/src/include/duckdb/main/database_manager.hpp +1 -0
- package/src/duckdb/src/include/duckdb/main/extension_entries.hpp +142 -136
- package/src/duckdb/src/include/duckdb/main/query_result.hpp +6 -0
- package/src/duckdb/src/include/duckdb/main/settings.hpp +19 -0
- package/src/duckdb/src/include/duckdb/optimizer/unnest_rewriter.hpp +4 -0
- package/src/duckdb/src/include/duckdb/parallel/meta_pipeline.hpp +12 -3
- package/src/duckdb/src/include/duckdb/parser/parser.hpp +2 -0
- package/src/duckdb/src/include/duckdb/parser/tableref/emptytableref.hpp +1 -1
- package/src/duckdb/src/include/duckdb/parser/tableref/pivotref.hpp +2 -2
- package/src/duckdb/src/include/duckdb/parser/transformer.hpp +0 -2
- package/src/duckdb/src/include/duckdb/planner/bind_context.hpp +1 -1
- package/src/duckdb/src/include/duckdb/planner/bound_result_modifier.hpp +3 -0
- package/src/duckdb/src/include/duckdb/planner/expression_binder.hpp +1 -1
- package/src/duckdb/src/include/duckdb/planner/logical_operator.hpp +5 -0
- package/src/duckdb/src/include/duckdb/planner/operator/logical_copy_to_file.hpp +6 -2
- package/src/duckdb/src/include/duckdb/planner/operator/logical_execute.hpp +4 -0
- package/src/duckdb/src/include/duckdb/planner/operator/logical_explain.hpp +5 -1
- package/src/duckdb/src/include/duckdb/planner/operator/logical_get.hpp +5 -1
- package/src/duckdb/src/include/duckdb/planner/operator/logical_pragma.hpp +6 -2
- package/src/duckdb/src/include/duckdb/planner/operator/logical_prepare.hpp +4 -0
- package/src/duckdb/src/include/duckdb/storage/compression/chimp/algorithm/byte_reader.hpp +4 -0
- package/src/duckdb/src/include/duckdb/storage/data_table.hpp +1 -1
- package/src/duckdb/src/include/duckdb/storage/in_memory_block_manager.hpp +13 -13
- package/src/duckdb/src/include/duckdb/storage/index.hpp +4 -2
- package/src/duckdb/src/include/duckdb/storage/storage_extension.hpp +0 -6
- package/src/duckdb/src/include/duckdb/storage/table/column_data.hpp +1 -1
- package/src/duckdb/src/include/duckdb/storage/table/list_column_data.hpp +2 -1
- package/src/duckdb/src/include/duckdb/storage/table/row_group.hpp +2 -2
- package/src/duckdb/src/include/duckdb/storage/table/row_group_collection.hpp +2 -1
- package/src/duckdb/src/include/duckdb/storage/table/standard_column_data.hpp +2 -1
- package/src/duckdb/src/include/duckdb/storage/table/struct_column_data.hpp +2 -1
- package/src/duckdb/src/include/duckdb/storage/table_storage_info.hpp +0 -2
- package/src/duckdb/src/main/attached_database.cpp +8 -0
- package/src/duckdb/src/main/capi/arrow-c.cpp +4 -4
- package/src/duckdb/src/main/capi/config-c.cpp +2 -5
- package/src/duckdb/src/main/client_context.cpp +4 -3
- package/src/duckdb/src/main/config.cpp +2 -0
- package/src/duckdb/src/main/database.cpp +1 -0
- package/src/duckdb/src/main/database_manager.cpp +21 -0
- package/src/duckdb/src/main/query_result.cpp +6 -2
- package/src/duckdb/src/main/settings/settings.cpp +41 -6
- package/src/duckdb/src/optimizer/unnest_rewriter.cpp +27 -16
- package/src/duckdb/src/parallel/executor.cpp +38 -14
- package/src/duckdb/src/parallel/meta_pipeline.cpp +17 -3
- package/src/duckdb/src/parser/column_definition.cpp +5 -8
- package/src/duckdb/src/parser/parsed_data/create_info.cpp +0 -3
- package/src/duckdb/src/parser/parser.cpp +95 -35
- package/src/duckdb/src/parser/transform/expression/transform_function.cpp +1 -0
- package/src/duckdb/src/parser/transform/expression/transform_operator.cpp +3 -0
- package/src/duckdb/src/parser/transform/helpers/nodetype_to_string.cpp +0 -2
- package/src/duckdb/src/parser/transform/statement/transform_drop.cpp +0 -3
- package/src/duckdb/src/parser/transform/tableref/transform_pivot.cpp +3 -0
- package/src/duckdb/src/parser/transformer.cpp +0 -2
- package/src/duckdb/src/planner/bind_context.cpp +3 -4
- package/src/duckdb/src/planner/binder/expression/bind_function_expression.cpp +0 -2
- package/src/duckdb/src/planner/binder/expression/bind_positional_reference_expression.cpp +8 -3
- package/src/duckdb/src/planner/binder/query_node/bind_select_node.cpp +31 -15
- package/src/duckdb/src/planner/binder/statement/bind_create.cpp +0 -27
- package/src/duckdb/src/planner/binder/statement/bind_create_table.cpp +18 -1
- package/src/duckdb/src/planner/binder/statement/bind_drop.cpp +0 -25
- package/src/duckdb/src/planner/binder/statement/bind_update.cpp +2 -114
- package/src/duckdb/src/planner/binder/tableref/bind_pivot.cpp +6 -1
- package/src/duckdb/src/planner/binder/tableref/bind_table_function.cpp +5 -0
- package/src/duckdb/src/planner/bound_result_modifier.cpp +14 -0
- package/src/duckdb/src/planner/expression/bound_aggregate_expression.cpp +6 -5
- package/src/duckdb/src/planner/expression/bound_default_expression.cpp +7 -1
- package/src/duckdb/src/planner/expression.cpp +3 -0
- package/src/duckdb/src/planner/expression_binder.cpp +3 -2
- package/src/duckdb/src/planner/operator/logical_distinct.cpp +5 -4
- package/src/duckdb/src/planner/operator/logical_pivot.cpp +14 -2
- package/src/duckdb/src/planner/planner.cpp +5 -15
- package/src/duckdb/src/storage/data_table.cpp +10 -8
- package/src/duckdb/src/storage/index.cpp +13 -0
- package/src/duckdb/src/storage/storage_manager.cpp +6 -0
- package/src/duckdb/src/storage/table/column_data.cpp +7 -3
- package/src/duckdb/src/storage/table/list_column_data.cpp +5 -4
- package/src/duckdb/src/storage/table/row_group.cpp +4 -3
- package/src/duckdb/src/storage/table/row_group_collection.cpp +6 -3
- package/src/duckdb/src/storage/table/standard_column_data.cpp +4 -3
- package/src/duckdb/src/storage/table/struct_column_data.cpp +4 -3
- package/src/duckdb/src/storage/wal_replay.cpp +4 -5
- package/src/duckdb/third_party/libpg_query/include/nodes/nodes.hpp +0 -1
- package/src/duckdb/third_party/libpg_query/include/nodes/parsenodes.hpp +0 -14
- package/src/duckdb/third_party/libpg_query/src_backend_parser_gram.cpp +12828 -12956
- package/src/duckdb/third_party/zstd/compress/zstd_compress.cpp +3 -0
- package/src/duckdb/third_party/zstd/include/zstd/compress/zstd_cwksp.h +4 -0
- package/src/duckdb/ub_extension_icu_third_party_icu_i18n.cpp +5 -5
- package/src/duckdb/ub_src_parser_transform_statement.cpp +0 -2
- package/test/extension.test.ts +11 -0
- package/src/duckdb/src/include/duckdb/parser/parsed_data/create_database_info.hpp +0 -46
- package/src/duckdb/src/parser/transform/statement/transform_create_database.cpp +0 -27
@@ -112,35 +112,29 @@ struct CountZeros<uint64_t> {
|
|
112
112
|
template <>
|
113
113
|
struct CountZeros<hugeint_t> {
|
114
114
|
inline static int Leading(hugeint_t value) {
|
115
|
-
|
115
|
+
const uint64_t upper = (uint64_t)value.upper;
|
116
|
+
const uint64_t lower = value.lower;
|
117
|
+
|
118
|
+
if (upper) {
|
119
|
+
return __builtin_clzll(upper);
|
120
|
+
} else if (lower) {
|
121
|
+
return 64 + __builtin_clzll(lower);
|
122
|
+
} else {
|
116
123
|
return 128;
|
117
124
|
}
|
118
|
-
|
119
|
-
uint64_t upper = (uint64_t)value.upper;
|
120
|
-
uint64_t lower = value.lower;
|
121
|
-
|
122
|
-
int res = __builtin_clzll(upper);
|
123
|
-
if (res == 64) {
|
124
|
-
res += __builtin_clzll(lower);
|
125
|
-
}
|
126
|
-
|
127
|
-
return res;
|
128
125
|
}
|
129
126
|
|
130
127
|
inline static int Trailing(hugeint_t value) {
|
131
|
-
|
128
|
+
const uint64_t upper = (uint64_t)value.upper;
|
129
|
+
const uint64_t lower = value.lower;
|
130
|
+
|
131
|
+
if (lower) {
|
132
|
+
return __builtin_ctzll(lower);
|
133
|
+
} else if (upper) {
|
134
|
+
return 64 + __builtin_ctzll(upper);
|
135
|
+
} else {
|
132
136
|
return 128;
|
133
137
|
}
|
134
|
-
|
135
|
-
uint64_t upper = (uint64_t)value.upper;
|
136
|
-
uint64_t lower = value.lower;
|
137
|
-
|
138
|
-
int res = __builtin_ctzll(lower);
|
139
|
-
if (res == 64) {
|
140
|
-
res += __builtin_ctzll(upper);
|
141
|
-
}
|
142
|
-
|
143
|
-
return res;
|
144
138
|
}
|
145
139
|
};
|
146
140
|
|
@@ -105,6 +105,9 @@ public:
|
|
105
105
|
|
106
106
|
template <typename... Args>
|
107
107
|
static string ConstructMessage(const string &msg, Args... params) {
|
108
|
+
const std::size_t num_args = sizeof...(Args);
|
109
|
+
if (num_args == 0)
|
110
|
+
return msg;
|
108
111
|
std::vector<ExceptionFormatValue> values;
|
109
112
|
return ConstructMessageRecursive(msg, values, params...);
|
110
113
|
}
|
@@ -42,6 +42,8 @@ public:
|
|
42
42
|
DUCKDB_API static dtime_t FromTimeMs(int64_t time_ms);
|
43
43
|
DUCKDB_API static dtime_t FromTimeNs(int64_t time_ns);
|
44
44
|
|
45
|
+
DUCKDB_API static bool IsValidTime(int32_t hour, int32_t minute, int32_t second, int32_t microseconds);
|
46
|
+
|
45
47
|
private:
|
46
48
|
static bool TryConvertInternal(const char *buf, idx_t len, idx_t &pos, dtime_t &result, bool strict);
|
47
49
|
};
|
@@ -59,22 +59,12 @@ struct timestamp_t { // NOLINT
|
|
59
59
|
};
|
60
60
|
|
61
61
|
// arithmetic operators
|
62
|
-
|
63
|
-
|
64
|
-
};
|
65
|
-
inline int64_t operator-(const timestamp_t &other) const {
|
66
|
-
return this->value - other.value;
|
67
|
-
};
|
62
|
+
timestamp_t operator+(const double &value) const;
|
63
|
+
int64_t operator-(const timestamp_t &other) const;
|
68
64
|
|
69
65
|
// in-place operators
|
70
|
-
|
71
|
-
|
72
|
-
return *this;
|
73
|
-
};
|
74
|
-
inline timestamp_t &operator-=(const int64_t &value) {
|
75
|
-
this->value -= value;
|
76
|
-
return *this;
|
77
|
-
};
|
66
|
+
timestamp_t &operator+=(const int64_t &delta);
|
67
|
+
timestamp_t &operator-=(const int64_t &delta);
|
78
68
|
|
79
69
|
// special values
|
80
70
|
static timestamp_t infinity() { // NOLINT
|
@@ -11,6 +11,7 @@
|
|
11
11
|
#include "duckdb/common/exception.hpp"
|
12
12
|
#include "duckdb/common/types/vector.hpp"
|
13
13
|
#include "duckdb/common/vector_operations/vector_operations.hpp"
|
14
|
+
#include "duckdb/function/aggregate_state.hpp"
|
14
15
|
|
15
16
|
namespace duckdb {
|
16
17
|
|
@@ -24,7 +25,7 @@ private:
|
|
24
25
|
static inline void NullaryFlatLoop(STATE_TYPE **__restrict states, AggregateInputData &aggr_input_data,
|
25
26
|
idx_t count) {
|
26
27
|
for (idx_t i = 0; i < count; i++) {
|
27
|
-
OP::template Operation<STATE_TYPE, OP>(states[i], aggr_input_data, i);
|
28
|
+
OP::template Operation<STATE_TYPE, OP>(*states[i], aggr_input_data, i);
|
28
29
|
}
|
29
30
|
}
|
30
31
|
|
@@ -34,24 +35,25 @@ private:
|
|
34
35
|
|
35
36
|
for (idx_t i = 0; i < count; i++) {
|
36
37
|
auto sidx = ssel.get_index(i);
|
37
|
-
OP::template Operation<STATE_TYPE, OP>(states[sidx], aggr_input_data, sidx);
|
38
|
+
OP::template Operation<STATE_TYPE, OP>(*states[sidx], aggr_input_data, sidx);
|
38
39
|
}
|
39
40
|
}
|
40
41
|
|
41
42
|
template <class STATE_TYPE, class INPUT_TYPE, class OP>
|
42
43
|
static inline void UnaryFlatLoop(const INPUT_TYPE *__restrict idata, AggregateInputData &aggr_input_data,
|
43
44
|
STATE_TYPE **__restrict states, ValidityMask &mask, idx_t count) {
|
44
|
-
if (!mask.AllValid()) {
|
45
|
-
|
45
|
+
if (OP::IgnoreNull() && !mask.AllValid()) {
|
46
|
+
AggregateUnaryInput input(aggr_input_data, mask);
|
47
|
+
auto &base_idx = input.input_idx;
|
48
|
+
base_idx = 0;
|
46
49
|
auto entry_count = ValidityMask::EntryCount(count);
|
47
50
|
for (idx_t entry_idx = 0; entry_idx < entry_count; entry_idx++) {
|
48
51
|
auto validity_entry = mask.GetValidityEntry(entry_idx);
|
49
52
|
idx_t next = MinValue<idx_t>(base_idx + ValidityMask::BITS_PER_VALUE, count);
|
50
|
-
if (
|
53
|
+
if (ValidityMask::AllValid(validity_entry)) {
|
51
54
|
// all valid: perform operation
|
52
55
|
for (; base_idx < next; base_idx++) {
|
53
|
-
OP::template Operation<INPUT_TYPE, STATE_TYPE, OP>(states[base_idx],
|
54
|
-
mask, base_idx);
|
56
|
+
OP::template Operation<INPUT_TYPE, STATE_TYPE, OP>(*states[base_idx], idata[base_idx], input);
|
55
57
|
}
|
56
58
|
} else if (ValidityMask::NoneValid(validity_entry)) {
|
57
59
|
// nothing valid: skip all
|
@@ -62,15 +64,17 @@ private:
|
|
62
64
|
idx_t start = base_idx;
|
63
65
|
for (; base_idx < next; base_idx++) {
|
64
66
|
if (ValidityMask::RowIsValid(validity_entry, base_idx - start)) {
|
65
|
-
OP::template Operation<INPUT_TYPE, STATE_TYPE, OP>(states[base_idx],
|
66
|
-
|
67
|
+
OP::template Operation<INPUT_TYPE, STATE_TYPE, OP>(*states[base_idx], idata[base_idx],
|
68
|
+
input);
|
67
69
|
}
|
68
70
|
}
|
69
71
|
}
|
70
72
|
}
|
71
73
|
} else {
|
72
|
-
|
73
|
-
|
74
|
+
AggregateUnaryInput input(aggr_input_data, mask);
|
75
|
+
auto &i = input.input_idx;
|
76
|
+
for (i = 0; i < count; i++) {
|
77
|
+
OP::template Operation<INPUT_TYPE, STATE_TYPE, OP>(*states[i], idata[i], input);
|
74
78
|
}
|
75
79
|
}
|
76
80
|
}
|
@@ -81,19 +85,21 @@ private:
|
|
81
85
|
const SelectionVector &ssel, ValidityMask &mask, idx_t count) {
|
82
86
|
if (OP::IgnoreNull() && !mask.AllValid()) {
|
83
87
|
// potential NULL values and NULL values are ignored
|
88
|
+
AggregateUnaryInput input(aggr_input_data, mask);
|
84
89
|
for (idx_t i = 0; i < count; i++) {
|
85
|
-
|
90
|
+
input.input_idx = isel.get_index(i);
|
86
91
|
auto sidx = ssel.get_index(i);
|
87
|
-
if (mask.RowIsValid(
|
88
|
-
OP::template Operation<INPUT_TYPE, STATE_TYPE, OP>(states[sidx],
|
92
|
+
if (mask.RowIsValid(input.input_idx)) {
|
93
|
+
OP::template Operation<INPUT_TYPE, STATE_TYPE, OP>(*states[sidx], idata[input.input_idx], input);
|
89
94
|
}
|
90
95
|
}
|
91
96
|
} else {
|
92
97
|
// quick path: no NULL values or NULL values are not ignored
|
98
|
+
AggregateUnaryInput input(aggr_input_data, mask);
|
93
99
|
for (idx_t i = 0; i < count; i++) {
|
94
|
-
|
100
|
+
input.input_idx = isel.get_index(i);
|
95
101
|
auto sidx = ssel.get_index(i);
|
96
|
-
OP::template Operation<INPUT_TYPE, STATE_TYPE, OP>(states[sidx],
|
102
|
+
OP::template Operation<INPUT_TYPE, STATE_TYPE, OP>(*states[sidx], idata[input.input_idx], input);
|
97
103
|
}
|
98
104
|
}
|
99
105
|
}
|
@@ -101,7 +107,9 @@ private:
|
|
101
107
|
template <class STATE_TYPE, class INPUT_TYPE, class OP>
|
102
108
|
static inline void UnaryFlatUpdateLoop(const INPUT_TYPE *__restrict idata, AggregateInputData &aggr_input_data,
|
103
109
|
STATE_TYPE *__restrict state, idx_t count, ValidityMask &mask) {
|
104
|
-
|
110
|
+
AggregateUnaryInput input(aggr_input_data, mask);
|
111
|
+
auto &base_idx = input.input_idx;
|
112
|
+
base_idx = 0;
|
105
113
|
auto entry_count = ValidityMask::EntryCount(count);
|
106
114
|
for (idx_t entry_idx = 0; entry_idx < entry_count; entry_idx++) {
|
107
115
|
auto validity_entry = mask.GetValidityEntry(entry_idx);
|
@@ -109,7 +117,7 @@ private:
|
|
109
117
|
if (!OP::IgnoreNull() || ValidityMask::AllValid(validity_entry)) {
|
110
118
|
// all valid: perform operation
|
111
119
|
for (; base_idx < next; base_idx++) {
|
112
|
-
OP::template Operation<INPUT_TYPE, STATE_TYPE, OP>(state,
|
120
|
+
OP::template Operation<INPUT_TYPE, STATE_TYPE, OP>(*state, idata[base_idx], input);
|
113
121
|
}
|
114
122
|
} else if (ValidityMask::NoneValid(validity_entry)) {
|
115
123
|
// nothing valid: skip all
|
@@ -120,8 +128,7 @@ private:
|
|
120
128
|
idx_t start = base_idx;
|
121
129
|
for (; base_idx < next; base_idx++) {
|
122
130
|
if (ValidityMask::RowIsValid(validity_entry, base_idx - start)) {
|
123
|
-
OP::template Operation<INPUT_TYPE, STATE_TYPE, OP>(state,
|
124
|
-
base_idx);
|
131
|
+
OP::template Operation<INPUT_TYPE, STATE_TYPE, OP>(*state, idata[base_idx], input);
|
125
132
|
}
|
126
133
|
}
|
127
134
|
}
|
@@ -132,19 +139,20 @@ private:
|
|
132
139
|
static inline void UnaryUpdateLoop(const INPUT_TYPE *__restrict idata, AggregateInputData &aggr_input_data,
|
133
140
|
STATE_TYPE *__restrict state, idx_t count, ValidityMask &mask,
|
134
141
|
const SelectionVector &__restrict sel_vector) {
|
142
|
+
AggregateUnaryInput input(aggr_input_data, mask);
|
135
143
|
if (OP::IgnoreNull() && !mask.AllValid()) {
|
136
144
|
// potential NULL values and NULL values are ignored
|
137
145
|
for (idx_t i = 0; i < count; i++) {
|
138
|
-
|
139
|
-
if (mask.RowIsValid(
|
140
|
-
OP::template Operation<INPUT_TYPE, STATE_TYPE, OP>(state,
|
146
|
+
input.input_idx = sel_vector.get_index(i);
|
147
|
+
if (mask.RowIsValid(input.input_idx)) {
|
148
|
+
OP::template Operation<INPUT_TYPE, STATE_TYPE, OP>(*state, idata[input.input_idx], input);
|
141
149
|
}
|
142
150
|
}
|
143
151
|
} else {
|
144
152
|
// quick path: no NULL values or NULL values are not ignored
|
145
153
|
for (idx_t i = 0; i < count; i++) {
|
146
|
-
|
147
|
-
OP::template Operation<INPUT_TYPE, STATE_TYPE, OP>(state,
|
154
|
+
input.input_idx = sel_vector.get_index(i);
|
155
|
+
OP::template Operation<INPUT_TYPE, STATE_TYPE, OP>(*state, idata[input.input_idx], input);
|
148
156
|
}
|
149
157
|
}
|
150
158
|
}
|
@@ -155,25 +163,26 @@ private:
|
|
155
163
|
const SelectionVector &asel, const SelectionVector &bsel,
|
156
164
|
const SelectionVector &ssel, ValidityMask &avalidity,
|
157
165
|
ValidityMask &bvalidity) {
|
166
|
+
AggregateBinaryInput input(aggr_input_data, avalidity, bvalidity);
|
158
167
|
if (OP::IgnoreNull() && (!avalidity.AllValid() || !bvalidity.AllValid())) {
|
159
168
|
// potential NULL values and NULL values are ignored
|
160
169
|
for (idx_t i = 0; i < count; i++) {
|
161
|
-
|
162
|
-
|
170
|
+
input.lidx = asel.get_index(i);
|
171
|
+
input.ridx = bsel.get_index(i);
|
163
172
|
auto sidx = ssel.get_index(i);
|
164
|
-
if (avalidity.RowIsValid(
|
165
|
-
OP::template Operation<A_TYPE, B_TYPE, STATE_TYPE, OP>(states[sidx],
|
166
|
-
|
173
|
+
if (avalidity.RowIsValid(input.lidx) && bvalidity.RowIsValid(input.ridx)) {
|
174
|
+
OP::template Operation<A_TYPE, B_TYPE, STATE_TYPE, OP>(*states[sidx], adata[input.lidx],
|
175
|
+
bdata[input.ridx], input);
|
167
176
|
}
|
168
177
|
}
|
169
178
|
} else {
|
170
179
|
// quick path: no NULL values or NULL values are not ignored
|
171
180
|
for (idx_t i = 0; i < count; i++) {
|
172
|
-
|
173
|
-
|
181
|
+
input.lidx = asel.get_index(i);
|
182
|
+
input.ridx = bsel.get_index(i);
|
174
183
|
auto sidx = ssel.get_index(i);
|
175
|
-
OP::template Operation<A_TYPE, B_TYPE, STATE_TYPE, OP>(states[sidx],
|
176
|
-
|
184
|
+
OP::template Operation<A_TYPE, B_TYPE, STATE_TYPE, OP>(*states[sidx], adata[input.lidx],
|
185
|
+
bdata[input.ridx], input);
|
177
186
|
}
|
178
187
|
}
|
179
188
|
}
|
@@ -183,23 +192,24 @@ private:
|
|
183
192
|
const B_TYPE *__restrict bdata, STATE_TYPE *__restrict state, idx_t count,
|
184
193
|
const SelectionVector &asel, const SelectionVector &bsel,
|
185
194
|
ValidityMask &avalidity, ValidityMask &bvalidity) {
|
195
|
+
AggregateBinaryInput input(aggr_input_data, avalidity, bvalidity);
|
186
196
|
if (OP::IgnoreNull() && (!avalidity.AllValid() || !bvalidity.AllValid())) {
|
187
197
|
// potential NULL values and NULL values are ignored
|
188
198
|
for (idx_t i = 0; i < count; i++) {
|
189
|
-
|
190
|
-
|
191
|
-
if (avalidity.RowIsValid(
|
192
|
-
OP::template Operation<A_TYPE, B_TYPE, STATE_TYPE, OP>(state,
|
193
|
-
|
199
|
+
input.lidx = asel.get_index(i);
|
200
|
+
input.ridx = bsel.get_index(i);
|
201
|
+
if (avalidity.RowIsValid(input.lidx) && bvalidity.RowIsValid(input.ridx)) {
|
202
|
+
OP::template Operation<A_TYPE, B_TYPE, STATE_TYPE, OP>(*state, adata[input.lidx], bdata[input.ridx],
|
203
|
+
input);
|
194
204
|
}
|
195
205
|
}
|
196
206
|
} else {
|
197
207
|
// quick path: no NULL values or NULL values are not ignored
|
198
208
|
for (idx_t i = 0; i < count; i++) {
|
199
|
-
|
200
|
-
|
201
|
-
OP::template Operation<A_TYPE, B_TYPE, STATE_TYPE, OP>(state,
|
202
|
-
|
209
|
+
input.lidx = asel.get_index(i);
|
210
|
+
input.ridx = bsel.get_index(i);
|
211
|
+
OP::template Operation<A_TYPE, B_TYPE, STATE_TYPE, OP>(*state, adata[input.lidx], bdata[input.ridx],
|
212
|
+
input);
|
203
213
|
}
|
204
214
|
}
|
205
215
|
}
|
@@ -209,7 +219,7 @@ public:
|
|
209
219
|
static void NullaryScatter(Vector &states, AggregateInputData &aggr_input_data, idx_t count) {
|
210
220
|
if (states.GetVectorType() == VectorType::CONSTANT_VECTOR) {
|
211
221
|
auto sdata = ConstantVector::GetData<STATE_TYPE *>(states);
|
212
|
-
OP::template ConstantOperation<STATE_TYPE, OP>(
|
222
|
+
OP::template ConstantOperation<STATE_TYPE, OP>(**sdata, aggr_input_data, count);
|
213
223
|
} else if (states.GetVectorType() == VectorType::FLAT_VECTOR) {
|
214
224
|
auto sdata = FlatVector::GetData<STATE_TYPE *>(states);
|
215
225
|
NullaryFlatLoop<STATE_TYPE, OP>(sdata, aggr_input_data, count);
|
@@ -222,7 +232,7 @@ public:
|
|
222
232
|
|
223
233
|
template <class STATE_TYPE, class OP>
|
224
234
|
static void NullaryUpdate(data_ptr_t state, AggregateInputData &aggr_input_data, idx_t count) {
|
225
|
-
OP::template ConstantOperation<STATE_TYPE, OP>(
|
235
|
+
OP::template ConstantOperation<STATE_TYPE, OP>(*reinterpret_cast<STATE_TYPE *>(state), aggr_input_data, count);
|
226
236
|
}
|
227
237
|
|
228
238
|
template <class STATE_TYPE, class INPUT_TYPE, class OP>
|
@@ -236,8 +246,8 @@ public:
|
|
236
246
|
// regular constant: get first state
|
237
247
|
auto idata = ConstantVector::GetData<INPUT_TYPE>(input);
|
238
248
|
auto sdata = ConstantVector::GetData<STATE_TYPE *>(states);
|
239
|
-
|
240
|
-
|
249
|
+
AggregateUnaryInput input_data(aggr_input_data, ConstantVector::Validity(input));
|
250
|
+
OP::template ConstantOperation<INPUT_TYPE, STATE_TYPE, OP>(**sdata, *idata, input_data, count);
|
241
251
|
} else if (input.GetVectorType() == VectorType::FLAT_VECTOR &&
|
242
252
|
states.GetVectorType() == VectorType::FLAT_VECTOR) {
|
243
253
|
auto idata = FlatVector::GetData<INPUT_TYPE>(input);
|
@@ -262,8 +272,9 @@ public:
|
|
262
272
|
return;
|
263
273
|
}
|
264
274
|
auto idata = ConstantVector::GetData<INPUT_TYPE>(input);
|
265
|
-
|
266
|
-
|
275
|
+
AggregateUnaryInput input_data(aggr_input_data, ConstantVector::Validity(input));
|
276
|
+
OP::template ConstantOperation<INPUT_TYPE, STATE_TYPE, OP>(*reinterpret_cast<STATE_TYPE *>(state), *idata,
|
277
|
+
input_data, count);
|
267
278
|
break;
|
268
279
|
}
|
269
280
|
case VectorType::FLAT_VECTOR: {
|
@@ -315,7 +326,7 @@ public:
|
|
315
326
|
auto tdata = FlatVector::GetData<STATE_TYPE *>(target);
|
316
327
|
|
317
328
|
for (idx_t i = 0; i < count; i++) {
|
318
|
-
OP::template Combine<STATE_TYPE, OP>(*sdata[i], tdata[i], aggr_input_data);
|
329
|
+
OP::template Combine<STATE_TYPE, OP>(*sdata[i], *tdata[i], aggr_input_data);
|
319
330
|
}
|
320
331
|
}
|
321
332
|
|
@@ -327,17 +338,41 @@ public:
|
|
327
338
|
|
328
339
|
auto sdata = ConstantVector::GetData<STATE_TYPE *>(states);
|
329
340
|
auto rdata = ConstantVector::GetData<RESULT_TYPE>(result);
|
330
|
-
|
331
|
-
|
341
|
+
AggregateFinalizeData finalize_data(result, aggr_input_data);
|
342
|
+
OP::template Finalize<RESULT_TYPE, STATE_TYPE>(**sdata, *rdata, finalize_data);
|
332
343
|
} else {
|
333
344
|
D_ASSERT(states.GetVectorType() == VectorType::FLAT_VECTOR);
|
334
345
|
result.SetVectorType(VectorType::FLAT_VECTOR);
|
335
346
|
|
336
347
|
auto sdata = FlatVector::GetData<STATE_TYPE *>(states);
|
337
348
|
auto rdata = FlatVector::GetData<RESULT_TYPE>(result);
|
349
|
+
AggregateFinalizeData finalize_data(result, aggr_input_data);
|
350
|
+
for (idx_t i = 0; i < count; i++) {
|
351
|
+
finalize_data.result_idx = i + offset;
|
352
|
+
OP::template Finalize<RESULT_TYPE, STATE_TYPE>(*sdata[i], rdata[finalize_data.result_idx],
|
353
|
+
finalize_data);
|
354
|
+
}
|
355
|
+
}
|
356
|
+
}
|
357
|
+
|
358
|
+
template <class STATE_TYPE, class OP>
|
359
|
+
static void VoidFinalize(Vector &states, AggregateInputData &aggr_input_data, Vector &result, idx_t count,
|
360
|
+
idx_t offset) {
|
361
|
+
if (states.GetVectorType() == VectorType::CONSTANT_VECTOR) {
|
362
|
+
result.SetVectorType(VectorType::CONSTANT_VECTOR);
|
363
|
+
|
364
|
+
auto sdata = ConstantVector::GetData<STATE_TYPE *>(states);
|
365
|
+
AggregateFinalizeData finalize_data(result, aggr_input_data);
|
366
|
+
OP::template Finalize<STATE_TYPE>(**sdata, finalize_data);
|
367
|
+
} else {
|
368
|
+
D_ASSERT(states.GetVectorType() == VectorType::FLAT_VECTOR);
|
369
|
+
result.SetVectorType(VectorType::FLAT_VECTOR);
|
370
|
+
|
371
|
+
auto sdata = FlatVector::GetData<STATE_TYPE *>(states);
|
372
|
+
AggregateFinalizeData finalize_data(result, aggr_input_data);
|
338
373
|
for (idx_t i = 0; i < count; i++) {
|
339
|
-
|
340
|
-
|
374
|
+
finalize_data.result_idx = i + offset;
|
375
|
+
OP::template Finalize<STATE_TYPE>(*sdata[i], finalize_data);
|
341
376
|
}
|
342
377
|
}
|
343
378
|
}
|
@@ -349,15 +384,15 @@ public:
|
|
349
384
|
|
350
385
|
auto idata = FlatVector::GetData<const INPUT_TYPE>(input) - bias;
|
351
386
|
const auto &ivalid = FlatVector::Validity(input);
|
352
|
-
OP::template Window<STATE, INPUT_TYPE, RESULT_TYPE>(
|
353
|
-
|
387
|
+
OP::template Window<STATE, INPUT_TYPE, RESULT_TYPE>(
|
388
|
+
idata, ifilter, ivalid, aggr_input_data, *reinterpret_cast<STATE *>(state), frame, prev, result, rid, bias);
|
354
389
|
}
|
355
390
|
|
356
391
|
template <class STATE_TYPE, class OP>
|
357
392
|
static void Destroy(Vector &states, AggregateInputData &aggr_input_data, idx_t count) {
|
358
393
|
auto sdata = FlatVector::GetData<STATE_TYPE *>(states);
|
359
394
|
for (idx_t i = 0; i < count; i++) {
|
360
|
-
OP::template Destroy<STATE_TYPE>(
|
395
|
+
OP::template Destroy<STATE_TYPE>(*sdata[i], aggr_input_data);
|
361
396
|
}
|
362
397
|
}
|
363
398
|
};
|
@@ -24,49 +24,45 @@ struct CorrState {
|
|
24
24
|
// CORR(y, x) = COVAR_POP(y, x) / (STDDEV_POP(x) * STDDEV_POP(y))
|
25
25
|
struct CorrOperation {
|
26
26
|
template <class STATE>
|
27
|
-
static void Initialize(STATE
|
28
|
-
CovarOperation::Initialize<CovarState>(
|
29
|
-
STDDevBaseOperation::Initialize<StddevState>(
|
30
|
-
STDDevBaseOperation::Initialize<StddevState>(
|
27
|
+
static void Initialize(STATE &state) {
|
28
|
+
CovarOperation::Initialize<CovarState>(state.cov_pop);
|
29
|
+
STDDevBaseOperation::Initialize<StddevState>(state.dev_pop_x);
|
30
|
+
STDDevBaseOperation::Initialize<StddevState>(state.dev_pop_y);
|
31
31
|
}
|
32
32
|
|
33
33
|
template <class A_TYPE, class B_TYPE, class STATE, class OP>
|
34
|
-
static void Operation(STATE
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
STDDevBaseOperation::Operation<A_TYPE, StddevState, OP>(&state->dev_pop_x, aggr_input_data, x_data, amask,
|
39
|
-
xidx);
|
40
|
-
STDDevBaseOperation::Operation<B_TYPE, StddevState, OP>(&state->dev_pop_y, aggr_input_data, y_data, bmask,
|
41
|
-
yidx);
|
34
|
+
static void Operation(STATE &state, const A_TYPE &x_input, const B_TYPE &y_input, AggregateBinaryInput &idata) {
|
35
|
+
CovarOperation::Operation<A_TYPE, B_TYPE, CovarState, OP>(state.cov_pop, x_input, y_input, idata);
|
36
|
+
STDDevBaseOperation::Execute<A_TYPE, StddevState>(state.dev_pop_x, x_input);
|
37
|
+
STDDevBaseOperation::Execute<B_TYPE, StddevState>(state.dev_pop_y, y_input);
|
42
38
|
}
|
43
39
|
|
44
40
|
template <class STATE, class OP>
|
45
|
-
static void Combine(const STATE &source, STATE
|
46
|
-
CovarOperation::Combine<CovarState, OP>(source.cov_pop,
|
47
|
-
STDDevBaseOperation::Combine<StddevState, OP>(source.dev_pop_x,
|
48
|
-
STDDevBaseOperation::Combine<StddevState, OP>(source.dev_pop_y,
|
41
|
+
static void Combine(const STATE &source, STATE &target, AggregateInputData &aggr_input_data) {
|
42
|
+
CovarOperation::Combine<CovarState, OP>(source.cov_pop, target.cov_pop, aggr_input_data);
|
43
|
+
STDDevBaseOperation::Combine<StddevState, OP>(source.dev_pop_x, target.dev_pop_x, aggr_input_data);
|
44
|
+
STDDevBaseOperation::Combine<StddevState, OP>(source.dev_pop_y, target.dev_pop_y, aggr_input_data);
|
49
45
|
}
|
50
46
|
|
51
47
|
template <class T, class STATE>
|
52
|
-
static void Finalize(
|
53
|
-
if (state
|
54
|
-
|
48
|
+
static void Finalize(STATE &state, T &target, AggregateFinalizeData &finalize_data) {
|
49
|
+
if (state.cov_pop.count == 0 || state.dev_pop_x.count == 0 || state.dev_pop_y.count == 0) {
|
50
|
+
finalize_data.ReturnNull();
|
55
51
|
} else {
|
56
|
-
auto cov = state
|
57
|
-
auto std_x = state
|
52
|
+
auto cov = state.cov_pop.co_moment / state.cov_pop.count;
|
53
|
+
auto std_x = state.dev_pop_x.count > 1 ? sqrt(state.dev_pop_x.dsquared / state.dev_pop_x.count) : 0;
|
58
54
|
if (!Value::DoubleIsFinite(std_x)) {
|
59
55
|
throw OutOfRangeException("STDDEV_POP for X is out of range!");
|
60
56
|
}
|
61
|
-
auto std_y = state
|
57
|
+
auto std_y = state.dev_pop_y.count > 1 ? sqrt(state.dev_pop_y.dsquared / state.dev_pop_y.count) : 0;
|
62
58
|
if (!Value::DoubleIsFinite(std_y)) {
|
63
59
|
throw OutOfRangeException("STDDEV_POP for Y is out of range!");
|
64
60
|
}
|
65
61
|
if (std_x * std_y == 0) {
|
66
|
-
|
62
|
+
finalize_data.ReturnNull();
|
67
63
|
return;
|
68
64
|
}
|
69
|
-
target
|
65
|
+
target = cov / (std_x * std_y);
|
70
66
|
}
|
71
67
|
}
|
72
68
|
|
@@ -21,51 +21,48 @@ struct CovarState {
|
|
21
21
|
|
22
22
|
struct CovarOperation {
|
23
23
|
template <class STATE>
|
24
|
-
static void Initialize(STATE
|
25
|
-
state
|
26
|
-
state
|
27
|
-
state
|
28
|
-
state
|
24
|
+
static void Initialize(STATE &state) {
|
25
|
+
state.count = 0;
|
26
|
+
state.meanx = 0;
|
27
|
+
state.meany = 0;
|
28
|
+
state.co_moment = 0;
|
29
29
|
}
|
30
30
|
|
31
31
|
template <class A_TYPE, class B_TYPE, class STATE, class OP>
|
32
|
-
static void Operation(STATE
|
33
|
-
ValidityMask &bmask, idx_t xidx, idx_t yidx) {
|
32
|
+
static void Operation(STATE &state, const A_TYPE &x, const B_TYPE &y, AggregateBinaryInput &idata) {
|
34
33
|
// update running mean and d^2
|
35
|
-
const uint64_t n = ++(state
|
34
|
+
const uint64_t n = ++(state.count);
|
36
35
|
|
37
|
-
const
|
38
|
-
const double
|
39
|
-
const double meanx = state->meanx + dx / n;
|
36
|
+
const double dx = (x - state.meanx);
|
37
|
+
const double meanx = state.meanx + dx / n;
|
40
38
|
|
41
|
-
const
|
42
|
-
const double
|
43
|
-
const double meany = state->meany + dy / n;
|
39
|
+
const double dy = (y - state.meany);
|
40
|
+
const double meany = state.meany + dy / n;
|
44
41
|
|
45
|
-
const double C = state
|
42
|
+
const double C = state.co_moment + dx * (y - meany);
|
46
43
|
|
47
|
-
state
|
48
|
-
state
|
49
|
-
state
|
44
|
+
state.meanx = meanx;
|
45
|
+
state.meany = meany;
|
46
|
+
state.co_moment = C;
|
50
47
|
}
|
51
48
|
|
52
49
|
template <class STATE, class OP>
|
53
|
-
static void Combine(const STATE &source, STATE
|
54
|
-
if (target
|
55
|
-
|
50
|
+
static void Combine(const STATE &source, STATE &target, AggregateInputData &) {
|
51
|
+
if (target.count == 0) {
|
52
|
+
target = source;
|
56
53
|
} else if (source.count > 0) {
|
57
|
-
const auto count = target
|
58
|
-
const auto meanx = (source.count * source.meanx + target
|
59
|
-
const auto meany = (source.count * source.meany + target
|
54
|
+
const auto count = target.count + source.count;
|
55
|
+
const auto meanx = (source.count * source.meanx + target.count * target.meanx) / count;
|
56
|
+
const auto meany = (source.count * source.meany + target.count * target.meany) / count;
|
60
57
|
|
61
58
|
// Schubert and Gertz SSDBM 2018, equation 21
|
62
|
-
const auto deltax = target
|
63
|
-
const auto deltay = target
|
64
|
-
target
|
65
|
-
source.co_moment + target
|
66
|
-
target
|
67
|
-
target
|
68
|
-
target
|
59
|
+
const auto deltax = target.meanx - source.meanx;
|
60
|
+
const auto deltay = target.meany - source.meany;
|
61
|
+
target.co_moment =
|
62
|
+
source.co_moment + target.co_moment + deltax * deltay * source.count * target.count / count;
|
63
|
+
target.meanx = meanx;
|
64
|
+
target.meany = meany;
|
65
|
+
target.count = count;
|
69
66
|
}
|
70
67
|
}
|
71
68
|
|
@@ -76,22 +73,22 @@ struct CovarOperation {
|
|
76
73
|
|
77
74
|
struct CovarPopOperation : public CovarOperation {
|
78
75
|
template <class T, class STATE>
|
79
|
-
static void Finalize(
|
80
|
-
if (state
|
81
|
-
|
76
|
+
static void Finalize(STATE &state, T &target, AggregateFinalizeData &finalize_data) {
|
77
|
+
if (state.count == 0) {
|
78
|
+
finalize_data.ReturnNull();
|
82
79
|
} else {
|
83
|
-
target
|
80
|
+
target = state.co_moment / state.count;
|
84
81
|
}
|
85
82
|
}
|
86
83
|
};
|
87
84
|
|
88
85
|
struct CovarSampOperation : public CovarOperation {
|
89
86
|
template <class T, class STATE>
|
90
|
-
static void Finalize(
|
91
|
-
if (
|
92
|
-
|
87
|
+
static void Finalize(STATE &state, T &target, AggregateFinalizeData &finalize_data) {
|
88
|
+
if (state.count < 2) {
|
89
|
+
finalize_data.ReturnNull();
|
93
90
|
} else {
|
94
|
-
target
|
91
|
+
target = state.co_moment / (state.count - 1);
|
95
92
|
}
|
96
93
|
}
|
97
94
|
};
|