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
@@ -16,67 +16,66 @@ struct KurtosisState {
|
|
16
16
|
|
17
17
|
struct KurtosisOperation {
|
18
18
|
template <class STATE>
|
19
|
-
static void Initialize(STATE
|
20
|
-
state
|
21
|
-
state
|
19
|
+
static void Initialize(STATE &state) {
|
20
|
+
state.n = 0;
|
21
|
+
state.sum = state.sum_sqr = state.sum_cub = state.sum_four = 0.0;
|
22
22
|
}
|
23
23
|
|
24
24
|
template <class INPUT_TYPE, class STATE, class OP>
|
25
|
-
static void ConstantOperation(STATE
|
26
|
-
|
25
|
+
static void ConstantOperation(STATE &state, const INPUT_TYPE &input, AggregateUnaryInput &unary_input,
|
26
|
+
idx_t count) {
|
27
27
|
for (idx_t i = 0; i < count; i++) {
|
28
|
-
Operation<INPUT_TYPE, STATE, OP>(state,
|
28
|
+
Operation<INPUT_TYPE, STATE, OP>(state, input, unary_input);
|
29
29
|
}
|
30
30
|
}
|
31
31
|
|
32
32
|
template <class INPUT_TYPE, class STATE, class OP>
|
33
|
-
static void Operation(STATE
|
34
|
-
state
|
35
|
-
state
|
36
|
-
state
|
37
|
-
state
|
38
|
-
state
|
33
|
+
static void Operation(STATE &state, const INPUT_TYPE &input, AggregateUnaryInput &unary_input) {
|
34
|
+
state.n++;
|
35
|
+
state.sum += input;
|
36
|
+
state.sum_sqr += pow(input, 2);
|
37
|
+
state.sum_cub += pow(input, 3);
|
38
|
+
state.sum_four += pow(input, 4);
|
39
39
|
}
|
40
40
|
|
41
41
|
template <class STATE, class OP>
|
42
|
-
static void Combine(const STATE &source, STATE
|
42
|
+
static void Combine(const STATE &source, STATE &target, AggregateInputData &) {
|
43
43
|
if (source.n == 0) {
|
44
44
|
return;
|
45
45
|
}
|
46
|
-
target
|
47
|
-
target
|
48
|
-
target
|
49
|
-
target
|
50
|
-
target
|
46
|
+
target.n += source.n;
|
47
|
+
target.sum += source.sum;
|
48
|
+
target.sum_sqr += source.sum_sqr;
|
49
|
+
target.sum_cub += source.sum_cub;
|
50
|
+
target.sum_four += source.sum_four;
|
51
51
|
}
|
52
52
|
|
53
53
|
template <class TARGET_TYPE, class STATE>
|
54
|
-
static void Finalize(
|
55
|
-
|
56
|
-
auto n = (double)state->n;
|
54
|
+
static void Finalize(STATE &state, TARGET_TYPE &target, AggregateFinalizeData &finalize_data) {
|
55
|
+
auto n = (double)state.n;
|
57
56
|
if (n <= 3) {
|
58
|
-
|
57
|
+
finalize_data.ReturnNull();
|
59
58
|
return;
|
60
59
|
}
|
61
60
|
double temp = 1 / n;
|
62
61
|
//! This is necessary due to linux 32 bits
|
63
62
|
long double temp_aux = 1 / n;
|
64
|
-
if (state
|
65
|
-
state
|
66
|
-
|
63
|
+
if (state.sum_sqr - state.sum * state.sum * temp == 0 ||
|
64
|
+
state.sum_sqr - state.sum * state.sum * temp_aux == 0) {
|
65
|
+
finalize_data.ReturnNull();
|
67
66
|
return;
|
68
67
|
}
|
69
68
|
double m4 =
|
70
|
-
temp * (state
|
71
|
-
6 * state
|
69
|
+
temp * (state.sum_four - 4 * state.sum_cub * state.sum * temp +
|
70
|
+
6 * state.sum_sqr * state.sum * state.sum * temp * temp - 3 * pow(state.sum, 4) * pow(temp, 3));
|
72
71
|
|
73
|
-
double m2 = temp * (state
|
72
|
+
double m2 = temp * (state.sum_sqr - state.sum * state.sum * temp);
|
74
73
|
if (m2 <= 0 || ((n - 2) * (n - 3)) == 0) { // m2 shouldn't be below 0 but floating points are weird
|
75
|
-
|
74
|
+
finalize_data.ReturnNull();
|
76
75
|
return;
|
77
76
|
}
|
78
|
-
target
|
79
|
-
if (!Value::DoubleIsFinite(target
|
77
|
+
target = (n - 1) * ((n + 1) * m4 / (m2 * m2) - 3 * (n - 1)) / ((n - 2) * (n - 3));
|
78
|
+
if (!Value::DoubleIsFinite(target)) {
|
80
79
|
throw OutOfRangeException("Kurtosis is out of range!");
|
81
80
|
}
|
82
81
|
}
|
@@ -49,30 +49,28 @@ static AggregateFunction GetUnaryAggregate(LogicalType type) {
|
|
49
49
|
|
50
50
|
struct MinMaxBase {
|
51
51
|
template <class STATE>
|
52
|
-
static void Initialize(STATE
|
53
|
-
state
|
52
|
+
static void Initialize(STATE &state) {
|
53
|
+
state.isset = false;
|
54
54
|
}
|
55
55
|
|
56
56
|
template <class INPUT_TYPE, class STATE, class OP>
|
57
|
-
static void ConstantOperation(STATE
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
state->isset = true;
|
57
|
+
static void ConstantOperation(STATE &state, const INPUT_TYPE &input, AggregateUnaryInput &unary_input,
|
58
|
+
idx_t count) {
|
59
|
+
if (!state.isset) {
|
60
|
+
OP::template Assign<INPUT_TYPE, STATE>(state, input, unary_input.input);
|
61
|
+
state.isset = true;
|
63
62
|
} else {
|
64
|
-
OP::template Execute<INPUT_TYPE, STATE>(state,
|
63
|
+
OP::template Execute<INPUT_TYPE, STATE>(state, input, unary_input.input);
|
65
64
|
}
|
66
65
|
}
|
67
66
|
|
68
67
|
template <class INPUT_TYPE, class STATE, class OP>
|
69
|
-
static void Operation(STATE
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
state->isset = true;
|
68
|
+
static void Operation(STATE &state, const INPUT_TYPE &input, AggregateUnaryInput &unary_input) {
|
69
|
+
if (!state.isset) {
|
70
|
+
OP::template Assign<INPUT_TYPE, STATE>(state, input, unary_input.input);
|
71
|
+
state.isset = true;
|
74
72
|
} else {
|
75
|
-
OP::template Execute<INPUT_TYPE, STATE>(state,
|
73
|
+
OP::template Execute<INPUT_TYPE, STATE>(state, input, unary_input.input);
|
76
74
|
}
|
77
75
|
}
|
78
76
|
|
@@ -83,125 +81,128 @@ struct MinMaxBase {
|
|
83
81
|
|
84
82
|
struct NumericMinMaxBase : public MinMaxBase {
|
85
83
|
template <class INPUT_TYPE, class STATE>
|
86
|
-
static void Assign(STATE
|
87
|
-
state
|
84
|
+
static void Assign(STATE &state, INPUT_TYPE input, AggregateInputData &) {
|
85
|
+
state.value = input;
|
88
86
|
}
|
89
87
|
|
90
88
|
template <class T, class STATE>
|
91
|
-
static void Finalize(
|
92
|
-
|
93
|
-
|
89
|
+
static void Finalize(STATE &state, T &target, AggregateFinalizeData &finalize_data) {
|
90
|
+
if (!state.isset) {
|
91
|
+
finalize_data.ReturnNull();
|
92
|
+
} else {
|
93
|
+
target = state.value;
|
94
|
+
}
|
94
95
|
}
|
95
96
|
};
|
96
97
|
|
97
98
|
struct MinOperation : public NumericMinMaxBase {
|
98
99
|
template <class INPUT_TYPE, class STATE>
|
99
|
-
static void Execute(STATE
|
100
|
-
if (LessThan::Operation<INPUT_TYPE>(input, state
|
101
|
-
state
|
100
|
+
static void Execute(STATE &state, INPUT_TYPE input, AggregateInputData &) {
|
101
|
+
if (LessThan::Operation<INPUT_TYPE>(input, state.value)) {
|
102
|
+
state.value = input;
|
102
103
|
}
|
103
104
|
}
|
104
105
|
|
105
106
|
template <class STATE, class OP>
|
106
|
-
static void Combine(const STATE &source, STATE
|
107
|
+
static void Combine(const STATE &source, STATE &target, AggregateInputData &) {
|
107
108
|
if (!source.isset) {
|
108
109
|
// source is NULL, nothing to do
|
109
110
|
return;
|
110
111
|
}
|
111
|
-
if (!target
|
112
|
+
if (!target.isset) {
|
112
113
|
// target is NULL, use source value directly
|
113
|
-
|
114
|
-
} else if (GreaterThan::Operation(target
|
115
|
-
target
|
114
|
+
target = source;
|
115
|
+
} else if (GreaterThan::Operation(target.value, source.value)) {
|
116
|
+
target.value = source.value;
|
116
117
|
}
|
117
118
|
}
|
118
119
|
};
|
119
120
|
|
120
121
|
struct MaxOperation : public NumericMinMaxBase {
|
121
122
|
template <class INPUT_TYPE, class STATE>
|
122
|
-
static void Execute(STATE
|
123
|
-
if (GreaterThan::Operation<INPUT_TYPE>(input, state
|
124
|
-
state
|
123
|
+
static void Execute(STATE &state, INPUT_TYPE input, AggregateInputData &) {
|
124
|
+
if (GreaterThan::Operation<INPUT_TYPE>(input, state.value)) {
|
125
|
+
state.value = input;
|
125
126
|
}
|
126
127
|
}
|
127
128
|
|
128
129
|
template <class STATE, class OP>
|
129
|
-
static void Combine(const STATE &source, STATE
|
130
|
+
static void Combine(const STATE &source, STATE &target, AggregateInputData &) {
|
130
131
|
if (!source.isset) {
|
131
132
|
// source is NULL, nothing to do
|
132
133
|
return;
|
133
134
|
}
|
134
|
-
if (!target
|
135
|
+
if (!target.isset) {
|
135
136
|
// target is NULL, use source value directly
|
136
|
-
|
137
|
-
} else if (LessThan::Operation(target
|
138
|
-
target
|
137
|
+
target = source;
|
138
|
+
} else if (LessThan::Operation(target.value, source.value)) {
|
139
|
+
target.value = source.value;
|
139
140
|
}
|
140
141
|
}
|
141
142
|
};
|
142
143
|
|
143
144
|
struct StringMinMaxBase : public MinMaxBase {
|
144
145
|
template <class STATE>
|
145
|
-
static void Destroy(
|
146
|
-
if (state
|
147
|
-
delete[] state
|
146
|
+
static void Destroy(STATE &state, AggregateInputData &aggr_input_data) {
|
147
|
+
if (state.isset && !state.value.IsInlined()) {
|
148
|
+
delete[] state.value.GetData();
|
148
149
|
}
|
149
150
|
}
|
150
151
|
|
151
152
|
template <class INPUT_TYPE, class STATE>
|
152
|
-
static void Assign(STATE
|
153
|
-
Destroy(
|
153
|
+
static void Assign(STATE &state, INPUT_TYPE input, AggregateInputData &input_data) {
|
154
|
+
Destroy(state, input_data);
|
154
155
|
if (input.IsInlined()) {
|
155
|
-
state
|
156
|
+
state.value = input;
|
156
157
|
} else {
|
157
158
|
// non-inlined string, need to allocate space for it
|
158
159
|
auto len = input.GetSize();
|
159
160
|
auto ptr = new char[len];
|
160
161
|
memcpy(ptr, input.GetData(), len);
|
161
162
|
|
162
|
-
state
|
163
|
+
state.value = string_t(ptr, len);
|
163
164
|
}
|
164
165
|
}
|
165
166
|
|
166
167
|
template <class T, class STATE>
|
167
|
-
static void Finalize(
|
168
|
-
if (!state
|
169
|
-
|
168
|
+
static void Finalize(STATE &state, T &target, AggregateFinalizeData &finalize_data) {
|
169
|
+
if (!state.isset) {
|
170
|
+
finalize_data.ReturnNull();
|
170
171
|
} else {
|
171
|
-
target
|
172
|
+
target = StringVector::AddStringOrBlob(finalize_data.result, state.value);
|
172
173
|
}
|
173
174
|
}
|
174
175
|
|
175
176
|
template <class STATE, class OP>
|
176
|
-
static void Combine(const STATE &source, STATE
|
177
|
+
static void Combine(const STATE &source, STATE &target, AggregateInputData &input_data) {
|
177
178
|
if (!source.isset) {
|
178
179
|
// source is NULL, nothing to do
|
179
180
|
return;
|
180
181
|
}
|
181
|
-
if (!target
|
182
|
+
if (!target.isset) {
|
182
183
|
// target is NULL, use source value directly
|
183
|
-
Assign(target,
|
184
|
-
target
|
184
|
+
Assign(target, source.value, input_data);
|
185
|
+
target.isset = true;
|
185
186
|
} else {
|
186
|
-
OP::template Execute<string_t, STATE>(target,
|
187
|
+
OP::template Execute<string_t, STATE>(target, source.value, input_data);
|
187
188
|
}
|
188
189
|
}
|
189
190
|
};
|
190
191
|
|
191
192
|
struct MinOperationString : public StringMinMaxBase {
|
192
193
|
template <class INPUT_TYPE, class STATE>
|
193
|
-
static void Execute(STATE
|
194
|
-
if (LessThan::Operation<INPUT_TYPE>(input, state
|
195
|
-
Assign(state,
|
194
|
+
static void Execute(STATE &state, INPUT_TYPE input, AggregateInputData &input_data) {
|
195
|
+
if (LessThan::Operation<INPUT_TYPE>(input, state.value)) {
|
196
|
+
Assign(state, input, input_data);
|
196
197
|
}
|
197
198
|
}
|
198
199
|
};
|
199
200
|
|
200
201
|
struct MaxOperationString : public StringMinMaxBase {
|
201
202
|
template <class INPUT_TYPE, class STATE>
|
202
|
-
static void Execute(STATE
|
203
|
-
if (GreaterThan::Operation<INPUT_TYPE>(input, state
|
204
|
-
Assign(state,
|
203
|
+
static void Execute(STATE &state, INPUT_TYPE input, AggregateInputData &input_data) {
|
204
|
+
if (GreaterThan::Operation<INPUT_TYPE>(input, state.value)) {
|
205
|
+
Assign(state, input, input_data);
|
205
206
|
}
|
206
207
|
}
|
207
208
|
};
|
@@ -379,31 +380,31 @@ struct VectorMinMaxBase {
|
|
379
380
|
}
|
380
381
|
|
381
382
|
template <class STATE>
|
382
|
-
static void Initialize(STATE
|
383
|
-
state
|
383
|
+
static void Initialize(STATE &state) {
|
384
|
+
state.value = nullptr;
|
384
385
|
}
|
385
386
|
|
386
387
|
template <class STATE>
|
387
|
-
static void Destroy(
|
388
|
-
if (state
|
389
|
-
delete state
|
388
|
+
static void Destroy(STATE &state, AggregateInputData &aggr_input_data) {
|
389
|
+
if (state.value) {
|
390
|
+
delete state.value;
|
390
391
|
}
|
391
|
-
state
|
392
|
+
state.value = nullptr;
|
392
393
|
}
|
393
394
|
|
394
395
|
template <class STATE>
|
395
|
-
static void Assign(STATE
|
396
|
-
if (!state
|
397
|
-
state
|
398
|
-
state
|
396
|
+
static void Assign(STATE &state, Vector &input, const idx_t idx) {
|
397
|
+
if (!state.value) {
|
398
|
+
state.value = new Vector(input.GetType());
|
399
|
+
state.value->SetVectorType(VectorType::CONSTANT_VECTOR);
|
399
400
|
}
|
400
401
|
sel_t selv = idx;
|
401
402
|
SelectionVector sel(&selv);
|
402
|
-
VectorOperations::Copy(input, *state
|
403
|
+
VectorOperations::Copy(input, *state.value, sel, 1, 0, 0);
|
403
404
|
}
|
404
405
|
|
405
406
|
template <class STATE>
|
406
|
-
static void Execute(STATE
|
407
|
+
static void Execute(STATE &state, Vector &input, const idx_t idx, const idx_t count) {
|
407
408
|
Assign(state, input, idx);
|
408
409
|
}
|
409
410
|
|
@@ -423,8 +424,8 @@ struct VectorMinMaxBase {
|
|
423
424
|
continue;
|
424
425
|
}
|
425
426
|
const auto sidx = sdata.sel->get_index(i);
|
426
|
-
auto state = states[sidx];
|
427
|
-
if (!state
|
427
|
+
auto &state = *states[sidx];
|
428
|
+
if (!state.value) {
|
428
429
|
Assign(state, input, i);
|
429
430
|
} else {
|
430
431
|
OP::template Execute(state, input, i, count);
|
@@ -433,34 +434,22 @@ struct VectorMinMaxBase {
|
|
433
434
|
}
|
434
435
|
|
435
436
|
template <class STATE, class OP>
|
436
|
-
static void Combine(const STATE &source, STATE
|
437
|
+
static void Combine(const STATE &source, STATE &target, AggregateInputData &) {
|
437
438
|
if (!source.value) {
|
438
439
|
return;
|
439
|
-
} else if (!target
|
440
|
+
} else if (!target.value) {
|
440
441
|
Assign(target, *source.value, 0);
|
441
442
|
} else {
|
442
443
|
OP::template Execute(target, *source.value, 0, 1);
|
443
444
|
}
|
444
445
|
}
|
445
446
|
|
446
|
-
template <class
|
447
|
-
static void Finalize(
|
448
|
-
if (!state
|
449
|
-
|
450
|
-
// since for STRUCT columns only setting the validity mask of the struct is incorrect
|
451
|
-
// as for a struct column, we need to also set ALL child columns to NULL
|
452
|
-
switch (result.GetVectorType()) {
|
453
|
-
case VectorType::FLAT_VECTOR:
|
454
|
-
FlatVector::SetNull(result, idx, true);
|
455
|
-
break;
|
456
|
-
case VectorType::CONSTANT_VECTOR:
|
457
|
-
ConstantVector::SetNull(result, true);
|
458
|
-
break;
|
459
|
-
default:
|
460
|
-
throw InternalException("Invalid result vector type for nested min/max");
|
461
|
-
}
|
447
|
+
template <class STATE>
|
448
|
+
static void Finalize(STATE &state, AggregateFinalizeData &finalize_data) {
|
449
|
+
if (!state.value) {
|
450
|
+
finalize_data.ReturnNull();
|
462
451
|
} else {
|
463
|
-
VectorOperations::Copy(*state
|
452
|
+
VectorOperations::Copy(*state.value, finalize_data.result, 1, 0, finalize_data.result_idx);
|
464
453
|
}
|
465
454
|
}
|
466
455
|
|
@@ -474,8 +463,8 @@ struct VectorMinMaxBase {
|
|
474
463
|
|
475
464
|
struct MinOperationVector : public VectorMinMaxBase {
|
476
465
|
template <class STATE>
|
477
|
-
static void Execute(STATE
|
478
|
-
if (TemplatedOptimumValue<DistinctLessThan>(input, idx, count, *state
|
466
|
+
static void Execute(STATE &state, Vector &input, const idx_t idx, const idx_t count) {
|
467
|
+
if (TemplatedOptimumValue<DistinctLessThan>(input, idx, count, *state.value, 0, 1)) {
|
479
468
|
Assign(state, input, idx);
|
480
469
|
}
|
481
470
|
}
|
@@ -483,8 +472,8 @@ struct MinOperationVector : public VectorMinMaxBase {
|
|
483
472
|
|
484
473
|
struct MaxOperationVector : public VectorMinMaxBase {
|
485
474
|
template <class STATE>
|
486
|
-
static void Execute(STATE
|
487
|
-
if (TemplatedOptimumValue<DistinctGreaterThan>(input, idx, count, *state
|
475
|
+
static void Execute(STATE &state, Vector &input, const idx_t idx, const idx_t count) {
|
476
|
+
if (TemplatedOptimumValue<DistinctGreaterThan>(input, idx, count, *state.value, 0, 1)) {
|
488
477
|
Assign(state, input, idx);
|
489
478
|
}
|
490
479
|
}
|
@@ -518,11 +507,10 @@ unique_ptr<FunctionData> BindDecimalMinMax(ClientContext &context, AggregateFunc
|
|
518
507
|
|
519
508
|
template <typename OP, typename STATE>
|
520
509
|
static AggregateFunction GetMinMaxFunction(const LogicalType &type) {
|
521
|
-
return AggregateFunction(
|
522
|
-
|
523
|
-
|
524
|
-
|
525
|
-
AggregateFunction::StateDestroy<STATE, OP>);
|
510
|
+
return AggregateFunction(
|
511
|
+
{type}, type, AggregateFunction::StateSize<STATE>, AggregateFunction::StateInitialize<STATE, OP>,
|
512
|
+
OP::template Update<STATE, OP>, AggregateFunction::StateCombine<STATE, OP>,
|
513
|
+
AggregateFunction::StateVoidFinalize<STATE, OP>, nullptr, OP::Bind, AggregateFunction::StateDestroy<STATE, OP>);
|
526
514
|
}
|
527
515
|
|
528
516
|
template <class OP, class OP_STRING, class OP_VECTOR>
|
@@ -13,38 +13,38 @@ struct ProductState {
|
|
13
13
|
|
14
14
|
struct ProductFunction {
|
15
15
|
template <class STATE>
|
16
|
-
static void Initialize(STATE
|
17
|
-
state
|
18
|
-
state
|
16
|
+
static void Initialize(STATE &state) {
|
17
|
+
state.val = 1;
|
18
|
+
state.empty = true;
|
19
19
|
}
|
20
20
|
|
21
21
|
template <class STATE, class OP>
|
22
|
-
static void Combine(const STATE &source, STATE
|
23
|
-
target
|
24
|
-
target
|
22
|
+
static void Combine(const STATE &source, STATE &target, AggregateInputData &) {
|
23
|
+
target.val *= source.val;
|
24
|
+
target.empty = target.empty && source.empty;
|
25
25
|
}
|
26
26
|
|
27
27
|
template <class T, class STATE>
|
28
|
-
static void Finalize(
|
29
|
-
if (state
|
30
|
-
|
28
|
+
static void Finalize(STATE &state, T &target, AggregateFinalizeData &finalize_data) {
|
29
|
+
if (state.empty) {
|
30
|
+
finalize_data.ReturnNull();
|
31
31
|
return;
|
32
32
|
}
|
33
|
-
target
|
33
|
+
target = state.val;
|
34
34
|
}
|
35
35
|
template <class INPUT_TYPE, class STATE, class OP>
|
36
|
-
static void Operation(STATE
|
37
|
-
if (state
|
38
|
-
state
|
36
|
+
static void Operation(STATE &state, const INPUT_TYPE &input, AggregateUnaryInput &unary_input) {
|
37
|
+
if (state.empty) {
|
38
|
+
state.empty = false;
|
39
39
|
}
|
40
|
-
state
|
40
|
+
state.val *= input;
|
41
41
|
}
|
42
42
|
|
43
43
|
template <class INPUT_TYPE, class STATE, class OP>
|
44
|
-
static void ConstantOperation(STATE
|
45
|
-
|
44
|
+
static void ConstantOperation(STATE &state, const INPUT_TYPE &input, AggregateUnaryInput &unary_input,
|
45
|
+
idx_t count) {
|
46
46
|
for (idx_t i = 0; i < count; i++) {
|
47
|
-
Operation<INPUT_TYPE, STATE, OP>(state,
|
47
|
+
Operation<INPUT_TYPE, STATE, OP>(state, input, unary_input);
|
48
48
|
}
|
49
49
|
}
|
50
50
|
|
@@ -15,62 +15,60 @@ struct SkewState {
|
|
15
15
|
|
16
16
|
struct SkewnessOperation {
|
17
17
|
template <class STATE>
|
18
|
-
static void Initialize(STATE
|
19
|
-
state
|
20
|
-
state
|
18
|
+
static void Initialize(STATE &state) {
|
19
|
+
state.n = 0;
|
20
|
+
state.sum = state.sum_sqr = state.sum_cub = 0;
|
21
21
|
}
|
22
22
|
|
23
23
|
template <class INPUT_TYPE, class STATE, class OP>
|
24
|
-
static void ConstantOperation(STATE
|
25
|
-
|
24
|
+
static void ConstantOperation(STATE &state, const INPUT_TYPE &input, AggregateUnaryInput &unary_input,
|
25
|
+
idx_t count) {
|
26
26
|
for (idx_t i = 0; i < count; i++) {
|
27
|
-
Operation<INPUT_TYPE, STATE, OP>(state,
|
27
|
+
Operation<INPUT_TYPE, STATE, OP>(state, input, unary_input);
|
28
28
|
}
|
29
29
|
}
|
30
30
|
|
31
31
|
template <class INPUT_TYPE, class STATE, class OP>
|
32
|
-
static void Operation(STATE
|
33
|
-
state
|
34
|
-
state
|
35
|
-
state
|
36
|
-
state
|
32
|
+
static void Operation(STATE &state, const INPUT_TYPE &input, AggregateUnaryInput &unary_input) {
|
33
|
+
state.n++;
|
34
|
+
state.sum += input;
|
35
|
+
state.sum_sqr += pow(input, 2);
|
36
|
+
state.sum_cub += pow(input, 3);
|
37
37
|
}
|
38
38
|
|
39
39
|
template <class STATE, class OP>
|
40
|
-
static void Combine(const STATE &source, STATE
|
40
|
+
static void Combine(const STATE &source, STATE &target, AggregateInputData &) {
|
41
41
|
if (source.n == 0) {
|
42
42
|
return;
|
43
43
|
}
|
44
44
|
|
45
|
-
target
|
46
|
-
target
|
47
|
-
target
|
48
|
-
target
|
45
|
+
target.n += source.n;
|
46
|
+
target.sum += source.sum;
|
47
|
+
target.sum_sqr += source.sum_sqr;
|
48
|
+
target.sum_cub += source.sum_cub;
|
49
49
|
}
|
50
50
|
|
51
51
|
template <class TARGET_TYPE, class STATE>
|
52
|
-
static void Finalize(
|
53
|
-
|
54
|
-
|
55
|
-
mask.SetInvalid(idx);
|
52
|
+
static void Finalize(STATE &state, TARGET_TYPE &target, AggregateFinalizeData &finalize_data) {
|
53
|
+
if (state.n <= 2) {
|
54
|
+
finalize_data.ReturnNull();
|
56
55
|
return;
|
57
56
|
}
|
58
|
-
double n = state
|
57
|
+
double n = state.n;
|
59
58
|
double temp = 1 / n;
|
60
|
-
auto p = std::pow(temp * (state
|
59
|
+
auto p = std::pow(temp * (state.sum_sqr - state.sum * state.sum * temp), 3);
|
61
60
|
if (p < 0) {
|
62
61
|
p = 0; // Shouldn't be below 0 but floating points are weird
|
63
62
|
}
|
64
63
|
double div = std::sqrt(p);
|
65
64
|
if (div == 0) {
|
66
|
-
|
65
|
+
finalize_data.ReturnNull();
|
67
66
|
return;
|
68
67
|
}
|
69
68
|
double temp1 = std::sqrt(n * (n - 1)) / (n - 2);
|
70
|
-
target
|
71
|
-
|
72
|
-
|
73
|
-
if (!Value::DoubleIsFinite(target[idx])) {
|
69
|
+
target = temp1 * temp *
|
70
|
+
(state.sum_cub - 3 * state.sum_sqr * state.sum * temp + 2 * pow(state.sum, 3) * temp * temp) / div;
|
71
|
+
if (!Value::DoubleIsFinite(target)) {
|
74
72
|
throw OutOfRangeException("SKEW is out of range!");
|
75
73
|
}
|
76
74
|
}
|