duckdb 0.8.1-dev96.0 → 0.8.1
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
@@ -42,53 +42,53 @@ static AggregateFunction GetBitfieldUnaryAggregate(LogicalType type) {
|
|
42
42
|
|
43
43
|
struct BitwiseOperation {
|
44
44
|
template <class STATE>
|
45
|
-
static void Initialize(STATE
|
45
|
+
static void Initialize(STATE &state) {
|
46
46
|
// If there are no matching rows, returns a null value.
|
47
|
-
state
|
47
|
+
state.is_set = false;
|
48
48
|
}
|
49
49
|
|
50
50
|
template <class INPUT_TYPE, class STATE, class OP>
|
51
|
-
static void Operation(STATE
|
52
|
-
if (!state
|
53
|
-
OP::template Assign(state, input
|
54
|
-
state
|
51
|
+
static void Operation(STATE &state, const INPUT_TYPE &input, AggregateUnaryInput &) {
|
52
|
+
if (!state.is_set) {
|
53
|
+
OP::template Assign(state, input);
|
54
|
+
state.is_set = true;
|
55
55
|
} else {
|
56
|
-
OP::template Execute(state, input
|
56
|
+
OP::template Execute(state, input);
|
57
57
|
}
|
58
58
|
}
|
59
59
|
|
60
60
|
template <class INPUT_TYPE, class STATE, class OP>
|
61
|
-
static void ConstantOperation(STATE
|
62
|
-
|
63
|
-
OP::template Operation<INPUT_TYPE, STATE, OP>(state,
|
61
|
+
static void ConstantOperation(STATE &state, const INPUT_TYPE &input, AggregateUnaryInput &unary_input,
|
62
|
+
idx_t count) {
|
63
|
+
OP::template Operation<INPUT_TYPE, STATE, OP>(state, input, unary_input);
|
64
64
|
}
|
65
65
|
|
66
66
|
template <class INPUT_TYPE, class STATE>
|
67
|
-
static void Assign(STATE
|
68
|
-
state
|
67
|
+
static void Assign(STATE &state, INPUT_TYPE input) {
|
68
|
+
state.value = input;
|
69
69
|
}
|
70
70
|
|
71
71
|
template <class STATE, class OP>
|
72
|
-
static void Combine(const STATE &source, STATE
|
72
|
+
static void Combine(const STATE &source, STATE &target, AggregateInputData &) {
|
73
73
|
if (!source.is_set) {
|
74
74
|
// source is NULL, nothing to do.
|
75
75
|
return;
|
76
76
|
}
|
77
|
-
if (!target
|
77
|
+
if (!target.is_set) {
|
78
78
|
// target is NULL, use source value directly.
|
79
79
|
OP::template Assign(target, source.value);
|
80
|
-
target
|
80
|
+
target.is_set = true;
|
81
81
|
} else {
|
82
82
|
OP::template Execute(target, source.value);
|
83
83
|
}
|
84
84
|
}
|
85
85
|
|
86
86
|
template <class T, class STATE>
|
87
|
-
static void Finalize(
|
88
|
-
if (!state
|
89
|
-
|
87
|
+
static void Finalize(STATE &state, T &target, AggregateFinalizeData &finalize_data) {
|
88
|
+
if (!state.is_set) {
|
89
|
+
finalize_data.ReturnNull();
|
90
90
|
} else {
|
91
|
-
target
|
91
|
+
target = state.value;
|
92
92
|
}
|
93
93
|
}
|
94
94
|
|
@@ -99,61 +99,61 @@ struct BitwiseOperation {
|
|
99
99
|
|
100
100
|
struct BitAndOperation : public BitwiseOperation {
|
101
101
|
template <class INPUT_TYPE, class STATE>
|
102
|
-
static void Execute(STATE
|
103
|
-
state
|
102
|
+
static void Execute(STATE &state, INPUT_TYPE input) {
|
103
|
+
state.value &= input;
|
104
104
|
}
|
105
105
|
};
|
106
106
|
|
107
107
|
struct BitOrOperation : public BitwiseOperation {
|
108
108
|
template <class INPUT_TYPE, class STATE>
|
109
|
-
static void Execute(STATE
|
110
|
-
state
|
109
|
+
static void Execute(STATE &state, INPUT_TYPE input) {
|
110
|
+
state.value |= input;
|
111
111
|
}
|
112
112
|
};
|
113
113
|
|
114
114
|
struct BitXorOperation : public BitwiseOperation {
|
115
115
|
template <class INPUT_TYPE, class STATE>
|
116
|
-
static void Execute(STATE
|
117
|
-
state
|
116
|
+
static void Execute(STATE &state, INPUT_TYPE input) {
|
117
|
+
state.value ^= input;
|
118
118
|
}
|
119
119
|
|
120
120
|
template <class INPUT_TYPE, class STATE, class OP>
|
121
|
-
static void ConstantOperation(STATE
|
122
|
-
|
121
|
+
static void ConstantOperation(STATE &state, const INPUT_TYPE &input, AggregateUnaryInput &unary_input,
|
122
|
+
idx_t count) {
|
123
123
|
for (idx_t i = 0; i < count; i++) {
|
124
|
-
Operation<INPUT_TYPE, STATE, OP>(state,
|
124
|
+
Operation<INPUT_TYPE, STATE, OP>(state, input, unary_input);
|
125
125
|
}
|
126
126
|
}
|
127
127
|
};
|
128
128
|
|
129
129
|
struct BitStringBitwiseOperation : public BitwiseOperation {
|
130
130
|
template <class STATE>
|
131
|
-
static void Destroy(
|
132
|
-
if (state
|
133
|
-
delete[] state
|
131
|
+
static void Destroy(STATE &state, AggregateInputData &aggr_input_data) {
|
132
|
+
if (state.is_set && !state.value.IsInlined()) {
|
133
|
+
delete[] state.value.GetData();
|
134
134
|
}
|
135
135
|
}
|
136
136
|
|
137
137
|
template <class INPUT_TYPE, class STATE>
|
138
|
-
static void Assign(STATE
|
139
|
-
D_ASSERT(state
|
138
|
+
static void Assign(STATE &state, INPUT_TYPE input) {
|
139
|
+
D_ASSERT(state.is_set == false);
|
140
140
|
if (input.IsInlined()) {
|
141
|
-
state
|
141
|
+
state.value = input;
|
142
142
|
} else { // non-inlined string, need to allocate space for it
|
143
143
|
auto len = input.GetSize();
|
144
144
|
auto ptr = new char[len];
|
145
145
|
memcpy(ptr, input.GetData(), len);
|
146
146
|
|
147
|
-
state
|
147
|
+
state.value = string_t(ptr, len);
|
148
148
|
}
|
149
149
|
}
|
150
150
|
|
151
151
|
template <class T, class STATE>
|
152
|
-
static void Finalize(
|
153
|
-
if (!state
|
154
|
-
|
152
|
+
static void Finalize(STATE &state, T &target, AggregateFinalizeData &finalize_data) {
|
153
|
+
if (!state.is_set) {
|
154
|
+
finalize_data.ReturnNull();
|
155
155
|
} else {
|
156
|
-
target
|
156
|
+
target = finalize_data.ReturnString(state.value);
|
157
157
|
}
|
158
158
|
}
|
159
159
|
};
|
@@ -161,30 +161,30 @@ struct BitStringBitwiseOperation : public BitwiseOperation {
|
|
161
161
|
struct BitStringAndOperation : public BitStringBitwiseOperation {
|
162
162
|
|
163
163
|
template <class INPUT_TYPE, class STATE>
|
164
|
-
static void Execute(STATE
|
165
|
-
Bit::BitwiseAnd(input, state
|
164
|
+
static void Execute(STATE &state, INPUT_TYPE input) {
|
165
|
+
Bit::BitwiseAnd(input, state.value, state.value);
|
166
166
|
}
|
167
167
|
};
|
168
168
|
|
169
169
|
struct BitStringOrOperation : public BitStringBitwiseOperation {
|
170
170
|
|
171
171
|
template <class INPUT_TYPE, class STATE>
|
172
|
-
static void Execute(STATE
|
173
|
-
Bit::BitwiseOr(input, state
|
172
|
+
static void Execute(STATE &state, INPUT_TYPE input) {
|
173
|
+
Bit::BitwiseOr(input, state.value, state.value);
|
174
174
|
}
|
175
175
|
};
|
176
176
|
|
177
177
|
struct BitStringXorOperation : public BitStringBitwiseOperation {
|
178
178
|
template <class INPUT_TYPE, class STATE>
|
179
|
-
static void Execute(STATE
|
180
|
-
Bit::BitwiseXor(input, state
|
179
|
+
static void Execute(STATE &state, INPUT_TYPE input) {
|
180
|
+
Bit::BitwiseXor(input, state.value, state.value);
|
181
181
|
}
|
182
182
|
|
183
183
|
template <class INPUT_TYPE, class STATE, class OP>
|
184
|
-
static void ConstantOperation(STATE
|
185
|
-
|
184
|
+
static void ConstantOperation(STATE &state, const INPUT_TYPE &input, AggregateUnaryInput &unary_input,
|
185
|
+
idx_t count) {
|
186
186
|
for (idx_t i = 0; i < count; i++) {
|
187
|
-
Operation<INPUT_TYPE, STATE, OP>(state,
|
187
|
+
Operation<INPUT_TYPE, STATE, OP>(state, input, unary_input);
|
188
188
|
}
|
189
189
|
}
|
190
190
|
};
|
@@ -48,49 +48,48 @@ struct BitStringAggOperation {
|
|
48
48
|
static constexpr const idx_t MAX_BIT_RANGE = 1000000000; // for now capped at 1 billion bits
|
49
49
|
|
50
50
|
template <class STATE>
|
51
|
-
static void Initialize(STATE
|
52
|
-
state
|
51
|
+
static void Initialize(STATE &state) {
|
52
|
+
state.is_set = false;
|
53
53
|
}
|
54
54
|
|
55
55
|
template <class INPUT_TYPE, class STATE, class OP>
|
56
|
-
static void Operation(STATE
|
57
|
-
|
58
|
-
|
59
|
-
if (!state->is_set) {
|
56
|
+
static void Operation(STATE &state, const INPUT_TYPE &input, AggregateUnaryInput &unary_input) {
|
57
|
+
auto &bind_agg_data = unary_input.input.bind_data->template Cast<BitstringAggBindData>();
|
58
|
+
if (!state.is_set) {
|
60
59
|
if (bind_agg_data.min.IsNull() || bind_agg_data.max.IsNull()) {
|
61
60
|
throw BinderException(
|
62
61
|
"Could not retrieve required statistics. Alternatively, try by providing the statistics "
|
63
62
|
"explicitly: BITSTRING_AGG(col, min, max) ");
|
64
63
|
}
|
65
|
-
state
|
66
|
-
state
|
64
|
+
state.min = bind_agg_data.min.GetValue<INPUT_TYPE>();
|
65
|
+
state.max = bind_agg_data.max.GetValue<INPUT_TYPE>();
|
67
66
|
idx_t bit_range =
|
68
67
|
GetRange(bind_agg_data.min.GetValue<INPUT_TYPE>(), bind_agg_data.max.GetValue<INPUT_TYPE>());
|
69
68
|
if (bit_range > MAX_BIT_RANGE) {
|
70
69
|
throw OutOfRangeException(
|
71
70
|
"The range between min and max value (%s <-> %s) is too large for bitstring aggregation",
|
72
|
-
NumericHelper::ToString(state
|
71
|
+
NumericHelper::ToString(state.min), NumericHelper::ToString(state.max));
|
73
72
|
}
|
74
73
|
idx_t len = Bit::ComputeBitstringLen(bit_range);
|
75
74
|
auto target = len > string_t::INLINE_LENGTH ? string_t(new char[len], len) : string_t(len);
|
76
75
|
Bit::SetEmptyBitString(target, bit_range);
|
77
76
|
|
78
|
-
state
|
79
|
-
state
|
77
|
+
state.value = target;
|
78
|
+
state.is_set = true;
|
80
79
|
}
|
81
|
-
if (input
|
82
|
-
Execute(state, input
|
80
|
+
if (input >= state.min && input <= state.max) {
|
81
|
+
Execute(state, input, bind_agg_data.min.GetValue<INPUT_TYPE>());
|
83
82
|
} else {
|
84
83
|
throw OutOfRangeException("Value %s is outside of provided min and max range (%s <-> %s)",
|
85
|
-
NumericHelper::ToString(input
|
86
|
-
NumericHelper::ToString(state
|
84
|
+
NumericHelper::ToString(input), NumericHelper::ToString(state.min),
|
85
|
+
NumericHelper::ToString(state.max));
|
87
86
|
}
|
88
87
|
}
|
89
88
|
|
90
89
|
template <class INPUT_TYPE, class STATE, class OP>
|
91
|
-
static void ConstantOperation(STATE
|
92
|
-
|
93
|
-
OP::template Operation<INPUT_TYPE, STATE, OP>(state,
|
90
|
+
static void ConstantOperation(STATE &state, const INPUT_TYPE &input, AggregateUnaryInput &unary_input,
|
91
|
+
idx_t count) {
|
92
|
+
OP::template Operation<INPUT_TYPE, STATE, OP>(state, input, unary_input);
|
94
93
|
}
|
95
94
|
|
96
95
|
template <class INPUT_TYPE>
|
@@ -108,51 +107,51 @@ struct BitStringAggOperation {
|
|
108
107
|
}
|
109
108
|
|
110
109
|
template <class INPUT_TYPE, class STATE>
|
111
|
-
static void Execute(STATE
|
112
|
-
Bit::SetBit(state
|
110
|
+
static void Execute(STATE &state, INPUT_TYPE input, INPUT_TYPE min) {
|
111
|
+
Bit::SetBit(state.value, input - min, 1);
|
113
112
|
}
|
114
113
|
|
115
114
|
template <class STATE, class OP>
|
116
|
-
static void Combine(const STATE &source, STATE
|
115
|
+
static void Combine(const STATE &source, STATE &target, AggregateInputData &) {
|
117
116
|
if (!source.is_set) {
|
118
117
|
return;
|
119
118
|
}
|
120
|
-
if (!target
|
119
|
+
if (!target.is_set) {
|
121
120
|
Assign(target, source.value);
|
122
|
-
target
|
123
|
-
target
|
124
|
-
target
|
121
|
+
target.is_set = true;
|
122
|
+
target.min = source.min;
|
123
|
+
target.max = source.max;
|
125
124
|
} else {
|
126
|
-
Bit::BitwiseOr(source.value, target
|
125
|
+
Bit::BitwiseOr(source.value, target.value, target.value);
|
127
126
|
}
|
128
127
|
}
|
129
128
|
|
130
129
|
template <class INPUT_TYPE, class STATE>
|
131
|
-
static void Assign(STATE
|
132
|
-
D_ASSERT(state
|
130
|
+
static void Assign(STATE &state, INPUT_TYPE input) {
|
131
|
+
D_ASSERT(state.is_set == false);
|
133
132
|
if (input.IsInlined()) {
|
134
|
-
state
|
133
|
+
state.value = input;
|
135
134
|
} else { // non-inlined string, need to allocate space for it
|
136
135
|
auto len = input.GetSize();
|
137
136
|
auto ptr = new char[len];
|
138
137
|
memcpy(ptr, input.GetData(), len);
|
139
|
-
state
|
138
|
+
state.value = string_t(ptr, len);
|
140
139
|
}
|
141
140
|
}
|
142
141
|
|
143
142
|
template <class T, class STATE>
|
144
|
-
static void Finalize(
|
145
|
-
if (!state
|
146
|
-
|
143
|
+
static void Finalize(STATE &state, T &target, AggregateFinalizeData &finalize_data) {
|
144
|
+
if (!state.is_set) {
|
145
|
+
finalize_data.ReturnNull();
|
147
146
|
} else {
|
148
|
-
target
|
147
|
+
target = StringVector::AddStringOrBlob(finalize_data.result, state.value);
|
149
148
|
}
|
150
149
|
}
|
151
150
|
|
152
151
|
template <class STATE>
|
153
|
-
static void Destroy(
|
154
|
-
if (state
|
155
|
-
delete[] state
|
152
|
+
static void Destroy(STATE &state, AggregateInputData &aggr_input_data) {
|
153
|
+
if (state.is_set && !state.value.IsInlined()) {
|
154
|
+
delete[] state.value.GetData();
|
156
155
|
}
|
157
156
|
}
|
158
157
|
|
@@ -162,10 +161,10 @@ struct BitStringAggOperation {
|
|
162
161
|
};
|
163
162
|
|
164
163
|
template <>
|
165
|
-
void BitStringAggOperation::Execute(BitAggState<hugeint_t>
|
164
|
+
void BitStringAggOperation::Execute(BitAggState<hugeint_t> &state, hugeint_t input, hugeint_t min) {
|
166
165
|
idx_t val;
|
167
166
|
if (Hugeint::TryCast(input - min, val)) {
|
168
|
-
Bit::SetBit(state
|
167
|
+
Bit::SetBit(state.value, val, 1);
|
169
168
|
} else {
|
170
169
|
throw OutOfRangeException("Range too large for bitstring aggregation");
|
171
170
|
}
|
@@ -200,7 +199,7 @@ unique_ptr<BaseStatistics> BitstringPropagateStats(ClientContext &context, Bound
|
|
200
199
|
unique_ptr<FunctionData> BindBitstringAgg(ClientContext &context, AggregateFunction &function,
|
201
200
|
vector<unique_ptr<Expression>> &arguments) {
|
202
201
|
if (arguments.size() == 3) {
|
203
|
-
if (!arguments[1]->IsFoldable()
|
202
|
+
if (!arguments[1]->IsFoldable() || !arguments[2]->IsFoldable()) {
|
204
203
|
throw BinderException("bitstring_agg requires a constant min and max argument");
|
205
204
|
}
|
206
205
|
auto min = ExpressionExecutor::EvaluateScalar(context, *arguments[1]);
|
@@ -13,37 +13,37 @@ struct BoolState {
|
|
13
13
|
|
14
14
|
struct BoolAndFunFunction {
|
15
15
|
template <class STATE>
|
16
|
-
static void Initialize(STATE
|
17
|
-
state
|
18
|
-
state
|
16
|
+
static void Initialize(STATE &state) {
|
17
|
+
state.val = true;
|
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 = 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
|
|
36
36
|
template <class INPUT_TYPE, class STATE, class OP>
|
37
|
-
static void Operation(STATE
|
38
|
-
state
|
39
|
-
state
|
37
|
+
static void Operation(STATE &state, const INPUT_TYPE &input, AggregateUnaryInput &unary_input) {
|
38
|
+
state.empty = false;
|
39
|
+
state.val = input && state.val;
|
40
40
|
}
|
41
41
|
|
42
42
|
template <class INPUT_TYPE, class STATE, class OP>
|
43
|
-
static void ConstantOperation(STATE
|
44
|
-
|
43
|
+
static void ConstantOperation(STATE &state, const INPUT_TYPE &input, AggregateUnaryInput &unary_input,
|
44
|
+
idx_t count) {
|
45
45
|
for (idx_t i = 0; i < count; i++) {
|
46
|
-
Operation<INPUT_TYPE, STATE, OP>(state,
|
46
|
+
Operation<INPUT_TYPE, STATE, OP>(state, input, unary_input);
|
47
47
|
}
|
48
48
|
}
|
49
49
|
static bool IgnoreNull() {
|
@@ -53,36 +53,36 @@ struct BoolAndFunFunction {
|
|
53
53
|
|
54
54
|
struct BoolOrFunFunction {
|
55
55
|
template <class STATE>
|
56
|
-
static void Initialize(STATE
|
57
|
-
state
|
58
|
-
state
|
56
|
+
static void Initialize(STATE &state) {
|
57
|
+
state.val = false;
|
58
|
+
state.empty = true;
|
59
59
|
}
|
60
60
|
|
61
61
|
template <class STATE, class OP>
|
62
|
-
static void Combine(const STATE &source, STATE
|
63
|
-
target
|
64
|
-
target
|
62
|
+
static void Combine(const STATE &source, STATE &target, AggregateInputData &) {
|
63
|
+
target.val = target.val || source.val;
|
64
|
+
target.empty = target.empty && source.empty;
|
65
65
|
}
|
66
66
|
|
67
67
|
template <class T, class STATE>
|
68
|
-
static void Finalize(
|
69
|
-
if (state
|
70
|
-
|
68
|
+
static void Finalize(STATE &state, T &target, AggregateFinalizeData &finalize_data) {
|
69
|
+
if (state.empty) {
|
70
|
+
finalize_data.ReturnNull();
|
71
71
|
return;
|
72
72
|
}
|
73
|
-
target
|
73
|
+
target = state.val;
|
74
74
|
}
|
75
75
|
template <class INPUT_TYPE, class STATE, class OP>
|
76
|
-
static void Operation(STATE
|
77
|
-
state
|
78
|
-
state
|
76
|
+
static void Operation(STATE &state, const INPUT_TYPE &input, AggregateUnaryInput &unary_input) {
|
77
|
+
state.empty = false;
|
78
|
+
state.val = input || state.val;
|
79
79
|
}
|
80
80
|
|
81
81
|
template <class INPUT_TYPE, class STATE, class OP>
|
82
|
-
static void ConstantOperation(STATE
|
83
|
-
|
82
|
+
static void ConstantOperation(STATE &state, const INPUT_TYPE &input, AggregateUnaryInput &unary_input,
|
83
|
+
idx_t count) {
|
84
84
|
for (idx_t i = 0; i < count; i++) {
|
85
|
-
Operation<INPUT_TYPE, STATE, OP>(state,
|
85
|
+
Operation<INPUT_TYPE, STATE, OP>(state, input, unary_input);
|
86
86
|
}
|
87
87
|
}
|
88
88
|
|
@@ -27,38 +27,38 @@ struct EntropyState {
|
|
27
27
|
|
28
28
|
struct EntropyFunctionBase {
|
29
29
|
template <class STATE>
|
30
|
-
static void Initialize(STATE
|
31
|
-
state
|
32
|
-
state
|
30
|
+
static void Initialize(STATE &state) {
|
31
|
+
state.distinct = nullptr;
|
32
|
+
state.count = 0;
|
33
33
|
}
|
34
34
|
|
35
35
|
template <class STATE, class OP>
|
36
|
-
static void Combine(const STATE &source, STATE
|
36
|
+
static void Combine(const STATE &source, STATE &target, AggregateInputData &) {
|
37
37
|
if (!source.distinct) {
|
38
38
|
return;
|
39
39
|
}
|
40
|
-
if (!target
|
41
|
-
target
|
40
|
+
if (!target.distinct) {
|
41
|
+
target.Assign(source);
|
42
42
|
return;
|
43
43
|
}
|
44
44
|
for (auto &val : *source.distinct) {
|
45
45
|
auto value = val.first;
|
46
|
-
(*target
|
46
|
+
(*target.distinct)[value] += val.second;
|
47
47
|
}
|
48
|
-
target
|
48
|
+
target.count += source.count;
|
49
49
|
}
|
50
50
|
|
51
51
|
template <class T, class STATE>
|
52
|
-
static void Finalize(
|
53
|
-
double count = state
|
54
|
-
if (state
|
52
|
+
static void Finalize(STATE &state, T &target, AggregateFinalizeData &finalize_data) {
|
53
|
+
double count = state.count;
|
54
|
+
if (state.distinct) {
|
55
55
|
double entropy = 0;
|
56
|
-
for (auto &val : *state
|
56
|
+
for (auto &val : *state.distinct) {
|
57
57
|
entropy += (val.second / count) * log2(count / val.second);
|
58
58
|
}
|
59
|
-
target
|
59
|
+
target = entropy;
|
60
60
|
} else {
|
61
|
-
target
|
61
|
+
target = 0;
|
62
62
|
}
|
63
63
|
}
|
64
64
|
|
@@ -66,47 +66,47 @@ struct EntropyFunctionBase {
|
|
66
66
|
return true;
|
67
67
|
}
|
68
68
|
template <class STATE>
|
69
|
-
static void Destroy(
|
70
|
-
if (state
|
71
|
-
delete state
|
69
|
+
static void Destroy(STATE &state, AggregateInputData &aggr_input_data) {
|
70
|
+
if (state.distinct) {
|
71
|
+
delete state.distinct;
|
72
72
|
}
|
73
73
|
}
|
74
74
|
};
|
75
75
|
|
76
76
|
struct EntropyFunction : EntropyFunctionBase {
|
77
77
|
template <class INPUT_TYPE, class STATE, class OP>
|
78
|
-
static void Operation(STATE
|
79
|
-
if (!state
|
80
|
-
state
|
78
|
+
static void Operation(STATE &state, const INPUT_TYPE &input, AggregateUnaryInput &unary_input) {
|
79
|
+
if (!state.distinct) {
|
80
|
+
state.distinct = new unordered_map<INPUT_TYPE, idx_t>();
|
81
81
|
}
|
82
|
-
(*state
|
83
|
-
state
|
82
|
+
(*state.distinct)[input]++;
|
83
|
+
state.count++;
|
84
84
|
}
|
85
85
|
template <class INPUT_TYPE, class STATE, class OP>
|
86
|
-
static void ConstantOperation(STATE
|
87
|
-
|
86
|
+
static void ConstantOperation(STATE &state, const INPUT_TYPE &input, AggregateUnaryInput &unary_input,
|
87
|
+
idx_t count) {
|
88
88
|
for (idx_t i = 0; i < count; i++) {
|
89
|
-
Operation<INPUT_TYPE, STATE, OP>(state,
|
89
|
+
Operation<INPUT_TYPE, STATE, OP>(state, input, unary_input);
|
90
90
|
}
|
91
91
|
}
|
92
92
|
};
|
93
93
|
|
94
94
|
struct EntropyFunctionString : EntropyFunctionBase {
|
95
95
|
template <class INPUT_TYPE, class STATE, class OP>
|
96
|
-
static void Operation(STATE
|
97
|
-
if (!state
|
98
|
-
state
|
96
|
+
static void Operation(STATE &state, const INPUT_TYPE &input, AggregateUnaryInput &unary_input) {
|
97
|
+
if (!state.distinct) {
|
98
|
+
state.distinct = new unordered_map<string, idx_t>();
|
99
99
|
}
|
100
|
-
auto value = input
|
101
|
-
(*state
|
102
|
-
state
|
100
|
+
auto value = input.GetString();
|
101
|
+
(*state.distinct)[value]++;
|
102
|
+
state.count++;
|
103
103
|
}
|
104
104
|
|
105
105
|
template <class INPUT_TYPE, class STATE, class OP>
|
106
|
-
static void ConstantOperation(STATE
|
107
|
-
|
106
|
+
static void ConstantOperation(STATE &state, const INPUT_TYPE &input, AggregateUnaryInput &unary_input,
|
107
|
+
idx_t count) {
|
108
108
|
for (idx_t i = 0; i < count; i++) {
|
109
|
-
Operation<INPUT_TYPE, STATE, OP>(state,
|
109
|
+
Operation<INPUT_TYPE, STATE, OP>(state, input, unary_input);
|
110
110
|
}
|
111
111
|
}
|
112
112
|
};
|