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.
Files changed (243) hide show
  1. package/binding.gyp +8 -8
  2. package/package.json +3 -1
  3. package/src/duckdb/extension/icu/icu-datepart.cpp +1 -1
  4. package/src/duckdb/extension/icu/icu-extension.cpp +1 -1
  5. package/src/duckdb/extension/icu/icu-makedate.cpp +5 -4
  6. package/src/duckdb/extension/icu/icu-strptime.cpp +1 -1
  7. package/src/duckdb/extension/icu/third_party/icu/i18n/nfsubs.cpp +0 -2
  8. package/src/duckdb/extension/json/buffered_json_reader.cpp +23 -14
  9. package/src/duckdb/extension/json/include/buffered_json_reader.hpp +6 -6
  10. package/src/duckdb/extension/json/include/json_common.hpp +12 -2
  11. package/src/duckdb/extension/json/include/json_scan.hpp +5 -2
  12. package/src/duckdb/extension/json/json_functions/json_contains.cpp +5 -0
  13. package/src/duckdb/extension/json/json_functions/json_create.cpp +10 -10
  14. package/src/duckdb/extension/json/json_functions/json_merge_patch.cpp +2 -2
  15. package/src/duckdb/extension/json/json_functions/json_serialize_sql.cpp +2 -2
  16. package/src/duckdb/extension/json/json_functions/json_structure.cpp +5 -3
  17. package/src/duckdb/extension/json/json_functions/json_transform.cpp +11 -11
  18. package/src/duckdb/extension/json/json_functions/read_json.cpp +2 -1
  19. package/src/duckdb/extension/json/json_functions.cpp +6 -3
  20. package/src/duckdb/extension/json/json_scan.cpp +43 -27
  21. package/src/duckdb/extension/parquet/column_reader.cpp +5 -1
  22. package/src/duckdb/extension/parquet/include/decode_utils.hpp +6 -0
  23. package/src/duckdb/extension/parquet/parquet-extension.cpp +26 -1
  24. package/src/duckdb/src/catalog/catalog.cpp +5 -17
  25. package/src/duckdb/src/catalog/catalog_entry/duck_table_entry.cpp +7 -1
  26. package/src/duckdb/src/catalog/catalog_entry/table_catalog_entry.cpp +121 -0
  27. package/src/duckdb/src/catalog/catalog_search_path.cpp +49 -12
  28. package/src/duckdb/src/catalog/default/default_types.cpp +9 -84
  29. package/src/duckdb/src/common/adbc/adbc.cpp +118 -12
  30. package/src/duckdb/src/common/adbc/driver_manager.cpp +0 -20
  31. package/src/duckdb/src/common/arrow/arrow_converter.cpp +11 -12
  32. package/src/duckdb/src/common/arrow/arrow_wrapper.cpp +4 -3
  33. package/src/duckdb/src/common/exception.cpp +4 -1
  34. package/src/duckdb/src/common/exception_format_value.cpp +24 -15
  35. package/src/duckdb/src/common/multi_file_reader.cpp +3 -0
  36. package/src/duckdb/src/common/random_engine.cpp +1 -1
  37. package/src/duckdb/src/common/types/row/row_data_collection_scanner.cpp +5 -4
  38. package/src/duckdb/src/common/types/row/tuple_data_scatter_gather.cpp +44 -7
  39. package/src/duckdb/src/common/types/time.cpp +2 -8
  40. package/src/duckdb/src/common/types/timestamp.cpp +37 -1
  41. package/src/duckdb/src/common/types/value.cpp +1 -0
  42. package/src/duckdb/src/common/types.cpp +4 -0
  43. package/src/duckdb/src/core_functions/aggregate/algebraic/avg.cpp +30 -33
  44. package/src/duckdb/src/core_functions/aggregate/algebraic/covar.cpp +0 -4
  45. package/src/duckdb/src/core_functions/aggregate/distributive/approx_count.cpp +30 -33
  46. package/src/duckdb/src/core_functions/aggregate/distributive/arg_min_max.cpp +52 -65
  47. package/src/duckdb/src/core_functions/aggregate/distributive/bitagg.cpp +48 -48
  48. package/src/duckdb/src/core_functions/aggregate/distributive/bitstring_agg.cpp +39 -40
  49. package/src/duckdb/src/core_functions/aggregate/distributive/bool.cpp +32 -32
  50. package/src/duckdb/src/core_functions/aggregate/distributive/entropy.cpp +34 -34
  51. package/src/duckdb/src/core_functions/aggregate/distributive/kurtosis.cpp +30 -31
  52. package/src/duckdb/src/core_functions/aggregate/distributive/minmax.cpp +88 -100
  53. package/src/duckdb/src/core_functions/aggregate/distributive/product.cpp +17 -17
  54. package/src/duckdb/src/core_functions/aggregate/distributive/skew.cpp +25 -27
  55. package/src/duckdb/src/core_functions/aggregate/distributive/string_agg.cpp +37 -38
  56. package/src/duckdb/src/core_functions/aggregate/distributive/sum.cpp +22 -22
  57. package/src/duckdb/src/core_functions/aggregate/holistic/approximate_quantile.cpp +44 -80
  58. package/src/duckdb/src/core_functions/aggregate/holistic/mode.cpp +49 -51
  59. package/src/duckdb/src/core_functions/aggregate/holistic/quantile.cpp +104 -122
  60. package/src/duckdb/src/core_functions/aggregate/holistic/reservoir_quantile.cpp +57 -93
  61. package/src/duckdb/src/core_functions/aggregate/nested/histogram.cpp +22 -23
  62. package/src/duckdb/src/core_functions/aggregate/nested/list.cpp +18 -19
  63. package/src/duckdb/src/core_functions/aggregate/regression/regr_avg.cpp +16 -18
  64. package/src/duckdb/src/core_functions/aggregate/regression/regr_intercept.cpp +22 -25
  65. package/src/duckdb/src/core_functions/aggregate/regression/regr_r2.cpp +19 -24
  66. package/src/duckdb/src/core_functions/aggregate/regression/regr_sxx_syy.cpp +18 -23
  67. package/src/duckdb/src/core_functions/aggregate/regression/regr_sxy.cpp +14 -18
  68. package/src/duckdb/src/core_functions/function_list.cpp +1 -0
  69. package/src/duckdb/src/core_functions/scalar/date/date_part.cpp +1 -1
  70. package/src/duckdb/src/core_functions/scalar/date/make_date.cpp +3 -0
  71. package/src/duckdb/src/core_functions/scalar/generic/system_functions.cpp +14 -0
  72. package/src/duckdb/src/core_functions/scalar/list/array_slice.cpp +1 -1
  73. package/src/duckdb/src/core_functions/scalar/list/list_aggregates.cpp +23 -6
  74. package/src/duckdb/src/core_functions/scalar/list/list_lambdas.cpp +1 -2
  75. package/src/duckdb/src/core_functions/scalar/map/map_concat.cpp +3 -0
  76. package/src/duckdb/src/core_functions/scalar/math/numeric.cpp +3 -3
  77. package/src/duckdb/src/execution/index/art/art.cpp +80 -7
  78. package/src/duckdb/src/execution/index/art/fixed_size_allocator.cpp +20 -1
  79. package/src/duckdb/src/execution/index/art/leaf.cpp +11 -11
  80. package/src/duckdb/src/execution/index/art/leaf_segment.cpp +10 -0
  81. package/src/duckdb/src/execution/index/art/node.cpp +48 -35
  82. package/src/duckdb/src/execution/index/art/node16.cpp +3 -0
  83. package/src/duckdb/src/execution/index/art/node256.cpp +1 -0
  84. package/src/duckdb/src/execution/index/art/node4.cpp +3 -0
  85. package/src/duckdb/src/execution/index/art/node48.cpp +2 -0
  86. package/src/duckdb/src/execution/index/art/prefix.cpp +2 -0
  87. package/src/duckdb/src/execution/join_hashtable.cpp +2 -0
  88. package/src/duckdb/src/execution/operator/aggregate/physical_window.cpp +26 -9
  89. package/src/duckdb/src/execution/operator/helper/physical_reset.cpp +5 -2
  90. package/src/duckdb/src/execution/operator/helper/physical_set.cpp +5 -1
  91. package/src/duckdb/src/execution/operator/join/physical_iejoin.cpp +3 -6
  92. package/src/duckdb/src/execution/operator/projection/physical_tableinout_function.cpp +1 -0
  93. package/src/duckdb/src/execution/operator/projection/physical_unnest.cpp +8 -3
  94. package/src/duckdb/src/execution/operator/schema/physical_attach.cpp +0 -1
  95. package/src/duckdb/src/execution/operator/schema/physical_create_index.cpp +29 -3
  96. package/src/duckdb/src/execution/reservoir_sample.cpp +18 -4
  97. package/src/duckdb/src/function/aggregate/distributive/count.cpp +159 -21
  98. package/src/duckdb/src/function/aggregate/distributive/first.cpp +67 -74
  99. package/src/duckdb/src/function/aggregate/sorted_aggregate_function.cpp +7 -7
  100. package/src/duckdb/src/function/cast/list_casts.cpp +2 -4
  101. package/src/duckdb/src/function/pragma/pragma_queries.cpp +33 -23
  102. package/src/duckdb/src/function/scalar/list/list_extract.cpp +1 -1
  103. package/src/duckdb/src/function/scalar/operators/arithmetic.cpp +1 -1
  104. package/src/duckdb/src/function/scalar/string/regexp/regexp_util.cpp +6 -2
  105. package/src/duckdb/src/function/scalar/system/aggregate_export.cpp +2 -2
  106. package/src/duckdb/src/function/table/arrow.cpp +2 -2
  107. package/src/duckdb/src/function/table/checkpoint.cpp +3 -0
  108. package/src/duckdb/src/function/table/read_csv.cpp +15 -17
  109. package/src/duckdb/src/function/table/repeat.cpp +3 -0
  110. package/src/duckdb/src/function/table/repeat_row.cpp +8 -1
  111. package/src/duckdb/src/function/table/system/pragma_storage_info.cpp +4 -4
  112. package/src/duckdb/src/function/table/system/test_vector_types.cpp +81 -25
  113. package/src/duckdb/src/function/table/table_scan.cpp +2 -2
  114. package/src/duckdb/src/function/table/version/pragma_version.cpp +2 -2
  115. package/src/duckdb/src/include/duckdb/catalog/catalog.hpp +0 -3
  116. package/src/duckdb/src/include/duckdb/catalog/catalog_entry/duck_table_entry.hpp +2 -0
  117. package/src/duckdb/src/include/duckdb/catalog/catalog_entry/table_catalog_entry.hpp +11 -1
  118. package/src/duckdb/src/include/duckdb/catalog/catalog_search_path.hpp +8 -2
  119. package/src/duckdb/src/include/duckdb/catalog/default/builtin_types/types.hpp +97 -0
  120. package/src/duckdb/src/include/duckdb/common/arrow/arrow_appender.hpp +1 -1
  121. package/src/duckdb/src/include/duckdb/common/arrow/arrow_converter.hpp +2 -3
  122. package/src/duckdb/src/include/duckdb/common/arrow/arrow_options.hpp +8 -1
  123. package/src/duckdb/src/include/duckdb/common/arrow/result_arrow_wrapper.hpp +0 -1
  124. package/src/duckdb/src/include/duckdb/common/bit_utils.hpp +16 -22
  125. package/src/duckdb/src/include/duckdb/common/exception.hpp +3 -0
  126. package/src/duckdb/src/include/duckdb/common/types/time.hpp +2 -0
  127. package/src/duckdb/src/include/duckdb/common/types/timestamp.hpp +4 -14
  128. package/src/duckdb/src/include/duckdb/common/vector_operations/aggregate_executor.hpp +92 -57
  129. package/src/duckdb/src/include/duckdb/core_functions/aggregate/algebraic/corr.hpp +20 -24
  130. package/src/duckdb/src/include/duckdb/core_functions/aggregate/algebraic/covar.hpp +36 -39
  131. package/src/duckdb/src/include/duckdb/core_functions/aggregate/algebraic/stddev.hpp +57 -53
  132. package/src/duckdb/src/include/duckdb/core_functions/aggregate/regression/regr_count.hpp +8 -9
  133. package/src/duckdb/src/include/duckdb/core_functions/aggregate/regression/regr_slope.hpp +16 -18
  134. package/src/duckdb/src/include/duckdb/core_functions/aggregate/sum_helpers.hpp +7 -8
  135. package/src/duckdb/src/include/duckdb/core_functions/scalar/generic_functions.hpp +9 -0
  136. package/src/duckdb/src/include/duckdb/core_functions/scalar/map_functions.hpp +2 -6
  137. package/src/duckdb/src/include/duckdb/core_functions/scalar/string_functions.hpp +16 -36
  138. package/src/duckdb/src/include/duckdb/execution/index/art/art.hpp +10 -4
  139. package/src/duckdb/src/include/duckdb/execution/index/art/fixed_size_allocator.hpp +3 -0
  140. package/src/duckdb/src/include/duckdb/execution/index/art/leaf.hpp +1 -1
  141. package/src/duckdb/src/include/duckdb/execution/index/art/leaf_segment.hpp +2 -0
  142. package/src/duckdb/src/include/duckdb/execution/index/art/node.hpp +13 -3
  143. package/src/duckdb/src/include/duckdb/execution/index/art/node48.hpp +1 -0
  144. package/src/duckdb/src/include/duckdb/function/aggregate_function.hpp +9 -30
  145. package/src/duckdb/src/include/duckdb/function/aggregate_state.hpp +95 -0
  146. package/src/duckdb/src/include/duckdb/function/function_serialization.hpp +4 -2
  147. package/src/duckdb/src/include/duckdb/function/scalar/nested_functions.hpp +1 -1
  148. package/src/duckdb/src/include/duckdb/function/scalar_function.hpp +2 -1
  149. package/src/duckdb/src/include/duckdb/function/table_function.hpp +3 -2
  150. package/src/duckdb/src/include/duckdb/main/attached_database.hpp +4 -1
  151. package/src/duckdb/src/include/duckdb/main/capi/capi_internal.hpp +3 -1
  152. package/src/duckdb/src/include/duckdb/main/config.hpp +5 -0
  153. package/src/duckdb/src/include/duckdb/main/database_manager.hpp +1 -0
  154. package/src/duckdb/src/include/duckdb/main/extension_entries.hpp +142 -136
  155. package/src/duckdb/src/include/duckdb/main/query_result.hpp +6 -0
  156. package/src/duckdb/src/include/duckdb/main/settings.hpp +19 -0
  157. package/src/duckdb/src/include/duckdb/optimizer/unnest_rewriter.hpp +4 -0
  158. package/src/duckdb/src/include/duckdb/parallel/meta_pipeline.hpp +12 -3
  159. package/src/duckdb/src/include/duckdb/parser/parser.hpp +2 -0
  160. package/src/duckdb/src/include/duckdb/parser/tableref/emptytableref.hpp +1 -1
  161. package/src/duckdb/src/include/duckdb/parser/tableref/pivotref.hpp +2 -2
  162. package/src/duckdb/src/include/duckdb/parser/transformer.hpp +0 -2
  163. package/src/duckdb/src/include/duckdb/planner/bind_context.hpp +1 -1
  164. package/src/duckdb/src/include/duckdb/planner/bound_result_modifier.hpp +3 -0
  165. package/src/duckdb/src/include/duckdb/planner/expression_binder.hpp +1 -1
  166. package/src/duckdb/src/include/duckdb/planner/logical_operator.hpp +5 -0
  167. package/src/duckdb/src/include/duckdb/planner/operator/logical_copy_to_file.hpp +6 -2
  168. package/src/duckdb/src/include/duckdb/planner/operator/logical_execute.hpp +4 -0
  169. package/src/duckdb/src/include/duckdb/planner/operator/logical_explain.hpp +5 -1
  170. package/src/duckdb/src/include/duckdb/planner/operator/logical_get.hpp +5 -1
  171. package/src/duckdb/src/include/duckdb/planner/operator/logical_pragma.hpp +6 -2
  172. package/src/duckdb/src/include/duckdb/planner/operator/logical_prepare.hpp +4 -0
  173. package/src/duckdb/src/include/duckdb/storage/compression/chimp/algorithm/byte_reader.hpp +4 -0
  174. package/src/duckdb/src/include/duckdb/storage/data_table.hpp +1 -1
  175. package/src/duckdb/src/include/duckdb/storage/in_memory_block_manager.hpp +13 -13
  176. package/src/duckdb/src/include/duckdb/storage/index.hpp +4 -2
  177. package/src/duckdb/src/include/duckdb/storage/storage_extension.hpp +0 -6
  178. package/src/duckdb/src/include/duckdb/storage/table/column_data.hpp +1 -1
  179. package/src/duckdb/src/include/duckdb/storage/table/list_column_data.hpp +2 -1
  180. package/src/duckdb/src/include/duckdb/storage/table/row_group.hpp +2 -2
  181. package/src/duckdb/src/include/duckdb/storage/table/row_group_collection.hpp +2 -1
  182. package/src/duckdb/src/include/duckdb/storage/table/standard_column_data.hpp +2 -1
  183. package/src/duckdb/src/include/duckdb/storage/table/struct_column_data.hpp +2 -1
  184. package/src/duckdb/src/include/duckdb/storage/table_storage_info.hpp +0 -2
  185. package/src/duckdb/src/main/attached_database.cpp +8 -0
  186. package/src/duckdb/src/main/capi/arrow-c.cpp +4 -4
  187. package/src/duckdb/src/main/capi/config-c.cpp +2 -5
  188. package/src/duckdb/src/main/client_context.cpp +4 -3
  189. package/src/duckdb/src/main/config.cpp +2 -0
  190. package/src/duckdb/src/main/database.cpp +1 -0
  191. package/src/duckdb/src/main/database_manager.cpp +21 -0
  192. package/src/duckdb/src/main/query_result.cpp +6 -2
  193. package/src/duckdb/src/main/settings/settings.cpp +41 -6
  194. package/src/duckdb/src/optimizer/unnest_rewriter.cpp +27 -16
  195. package/src/duckdb/src/parallel/executor.cpp +38 -14
  196. package/src/duckdb/src/parallel/meta_pipeline.cpp +17 -3
  197. package/src/duckdb/src/parser/column_definition.cpp +5 -8
  198. package/src/duckdb/src/parser/parsed_data/create_info.cpp +0 -3
  199. package/src/duckdb/src/parser/parser.cpp +95 -35
  200. package/src/duckdb/src/parser/transform/expression/transform_function.cpp +1 -0
  201. package/src/duckdb/src/parser/transform/expression/transform_operator.cpp +3 -0
  202. package/src/duckdb/src/parser/transform/helpers/nodetype_to_string.cpp +0 -2
  203. package/src/duckdb/src/parser/transform/statement/transform_drop.cpp +0 -3
  204. package/src/duckdb/src/parser/transform/tableref/transform_pivot.cpp +3 -0
  205. package/src/duckdb/src/parser/transformer.cpp +0 -2
  206. package/src/duckdb/src/planner/bind_context.cpp +3 -4
  207. package/src/duckdb/src/planner/binder/expression/bind_function_expression.cpp +0 -2
  208. package/src/duckdb/src/planner/binder/expression/bind_positional_reference_expression.cpp +8 -3
  209. package/src/duckdb/src/planner/binder/query_node/bind_select_node.cpp +31 -15
  210. package/src/duckdb/src/planner/binder/statement/bind_create.cpp +0 -27
  211. package/src/duckdb/src/planner/binder/statement/bind_create_table.cpp +18 -1
  212. package/src/duckdb/src/planner/binder/statement/bind_drop.cpp +0 -25
  213. package/src/duckdb/src/planner/binder/statement/bind_update.cpp +2 -114
  214. package/src/duckdb/src/planner/binder/tableref/bind_pivot.cpp +6 -1
  215. package/src/duckdb/src/planner/binder/tableref/bind_table_function.cpp +5 -0
  216. package/src/duckdb/src/planner/bound_result_modifier.cpp +14 -0
  217. package/src/duckdb/src/planner/expression/bound_aggregate_expression.cpp +6 -5
  218. package/src/duckdb/src/planner/expression/bound_default_expression.cpp +7 -1
  219. package/src/duckdb/src/planner/expression.cpp +3 -0
  220. package/src/duckdb/src/planner/expression_binder.cpp +3 -2
  221. package/src/duckdb/src/planner/operator/logical_distinct.cpp +5 -4
  222. package/src/duckdb/src/planner/operator/logical_pivot.cpp +14 -2
  223. package/src/duckdb/src/planner/planner.cpp +5 -15
  224. package/src/duckdb/src/storage/data_table.cpp +10 -8
  225. package/src/duckdb/src/storage/index.cpp +13 -0
  226. package/src/duckdb/src/storage/storage_manager.cpp +6 -0
  227. package/src/duckdb/src/storage/table/column_data.cpp +7 -3
  228. package/src/duckdb/src/storage/table/list_column_data.cpp +5 -4
  229. package/src/duckdb/src/storage/table/row_group.cpp +4 -3
  230. package/src/duckdb/src/storage/table/row_group_collection.cpp +6 -3
  231. package/src/duckdb/src/storage/table/standard_column_data.cpp +4 -3
  232. package/src/duckdb/src/storage/table/struct_column_data.cpp +4 -3
  233. package/src/duckdb/src/storage/wal_replay.cpp +4 -5
  234. package/src/duckdb/third_party/libpg_query/include/nodes/nodes.hpp +0 -1
  235. package/src/duckdb/third_party/libpg_query/include/nodes/parsenodes.hpp +0 -14
  236. package/src/duckdb/third_party/libpg_query/src_backend_parser_gram.cpp +12828 -12956
  237. package/src/duckdb/third_party/zstd/compress/zstd_compress.cpp +3 -0
  238. package/src/duckdb/third_party/zstd/include/zstd/compress/zstd_cwksp.h +4 -0
  239. package/src/duckdb/ub_extension_icu_third_party_icu_i18n.cpp +5 -5
  240. package/src/duckdb/ub_src_parser_transform_statement.cpp +0 -2
  241. package/test/extension.test.ts +11 -0
  242. package/src/duckdb/src/include/duckdb/parser/parsed_data/create_database_info.hpp +0 -46
  243. package/src/duckdb/src/parser/transform/statement/transform_create_database.cpp +0 -27
@@ -71,7 +71,7 @@ struct ReservoirQuantileBindData : public FunctionData {
71
71
  writer.WriteField<int32_t>(bind_data.sample_size);
72
72
  }
73
73
 
74
- static unique_ptr<FunctionData> Deserialize(ClientContext &context, FieldReader &reader,
74
+ static unique_ptr<FunctionData> Deserialize(PlanDeserializationState &state, FieldReader &reader,
75
75
  AggregateFunction &bound_function) {
76
76
  auto quantiles = reader.ReadRequiredList<double>();
77
77
  auto sample_size = reader.ReadRequired<int32_t>();
@@ -84,60 +84,59 @@ struct ReservoirQuantileBindData : public FunctionData {
84
84
 
85
85
  struct ReservoirQuantileOperation {
86
86
  template <class STATE>
87
- static void Initialize(STATE *state) {
88
- state->v = nullptr;
89
- state->len = 0;
90
- state->pos = 0;
91
- state->r_samp = nullptr;
87
+ static void Initialize(STATE &state) {
88
+ state.v = nullptr;
89
+ state.len = 0;
90
+ state.pos = 0;
91
+ state.r_samp = nullptr;
92
92
  }
93
93
 
94
94
  template <class INPUT_TYPE, class STATE, class OP>
95
- static void ConstantOperation(STATE *state, AggregateInputData &aggr_input_data, const INPUT_TYPE *input,
96
- ValidityMask &mask, idx_t count) {
95
+ static void ConstantOperation(STATE &state, const INPUT_TYPE &input, AggregateUnaryInput &unary_input,
96
+ idx_t count) {
97
97
  for (idx_t i = 0; i < count; i++) {
98
- Operation<INPUT_TYPE, STATE, OP>(state, aggr_input_data, input, mask, 0);
98
+ Operation<INPUT_TYPE, STATE, OP>(state, input, unary_input);
99
99
  }
100
100
  }
101
101
 
102
102
  template <class INPUT_TYPE, class STATE, class OP>
103
- static void Operation(STATE *state, AggregateInputData &aggr_input_data, const INPUT_TYPE *data, ValidityMask &mask,
104
- idx_t idx) {
105
- auto &bind_data = aggr_input_data.bind_data->template Cast<ReservoirQuantileBindData>();
106
- if (state->pos == 0) {
107
- state->Resize(bind_data.sample_size);
103
+ static void Operation(STATE &state, const INPUT_TYPE &input, AggregateUnaryInput &unary_input) {
104
+ auto &bind_data = unary_input.input.bind_data->template Cast<ReservoirQuantileBindData>();
105
+ if (state.pos == 0) {
106
+ state.Resize(bind_data.sample_size);
108
107
  }
109
- if (!state->r_samp) {
110
- state->r_samp = new BaseReservoirSampling();
108
+ if (!state.r_samp) {
109
+ state.r_samp = new BaseReservoirSampling();
111
110
  }
112
- D_ASSERT(state->v);
113
- state->FillReservoir(bind_data.sample_size, data[idx]);
111
+ D_ASSERT(state.v);
112
+ state.FillReservoir(bind_data.sample_size, input);
114
113
  }
115
114
 
116
115
  template <class STATE, class OP>
117
- static void Combine(const STATE &source, STATE *target, AggregateInputData &) {
116
+ static void Combine(const STATE &source, STATE &target, AggregateInputData &) {
118
117
  if (source.pos == 0) {
119
118
  return;
120
119
  }
121
- if (target->pos == 0) {
122
- target->Resize(source.len);
120
+ if (target.pos == 0) {
121
+ target.Resize(source.len);
123
122
  }
124
- if (!target->r_samp) {
125
- target->r_samp = new BaseReservoirSampling();
123
+ if (!target.r_samp) {
124
+ target.r_samp = new BaseReservoirSampling();
126
125
  }
127
126
  for (idx_t src_idx = 0; src_idx < source.pos; src_idx++) {
128
- target->FillReservoir(target->len, source.v[src_idx]);
127
+ target.FillReservoir(target.len, source.v[src_idx]);
129
128
  }
130
129
  }
131
130
 
132
131
  template <class STATE>
133
- static void Destroy(AggregateInputData &aggr_input_data, STATE *state) {
134
- if (state->v) {
135
- free(state->v);
136
- state->v = nullptr;
132
+ static void Destroy(STATE &state, AggregateInputData &aggr_input_data) {
133
+ if (state.v) {
134
+ free(state.v);
135
+ state.v = nullptr;
137
136
  }
138
- if (state->r_samp) {
139
- delete state->r_samp;
140
- state->r_samp = nullptr;
137
+ if (state.r_samp) {
138
+ delete state.r_samp;
139
+ state.r_samp = nullptr;
141
140
  }
142
141
  }
143
142
 
@@ -147,21 +146,20 @@ struct ReservoirQuantileOperation {
147
146
  };
148
147
 
149
148
  struct ReservoirQuantileScalarOperation : public ReservoirQuantileOperation {
150
- template <class TARGET_TYPE, class STATE>
151
- static void Finalize(Vector &result, AggregateInputData &aggr_input_data, STATE *state, TARGET_TYPE *target,
152
- ValidityMask &mask, idx_t idx) {
153
- if (state->pos == 0) {
154
- mask.SetInvalid(idx);
149
+ template <class T, class STATE>
150
+ static void Finalize(STATE &state, T &target, AggregateFinalizeData &finalize_data) {
151
+ if (state.pos == 0) {
152
+ finalize_data.ReturnNull();
155
153
  return;
156
154
  }
157
- D_ASSERT(state->v);
158
- D_ASSERT(aggr_input_data.bind_data);
159
- auto &bind_data = aggr_input_data.bind_data->template Cast<ReservoirQuantileBindData>();
160
- auto v_t = state->v;
155
+ D_ASSERT(state.v);
156
+ D_ASSERT(finalize_data.input.bind_data);
157
+ auto &bind_data = finalize_data.input.bind_data->template Cast<ReservoirQuantileBindData>();
158
+ auto v_t = state.v;
161
159
  D_ASSERT(bind_data.quantiles.size() == 1);
162
- auto offset = (idx_t)((double)(state->pos - 1) * bind_data.quantiles[0]);
163
- std::nth_element(v_t, v_t + offset, v_t + state->pos);
164
- target[idx] = v_t[offset];
160
+ auto offset = (idx_t)((double)(state.pos - 1) * bind_data.quantiles[0]);
161
+ std::nth_element(v_t, v_t + offset, v_t + state.pos);
162
+ target = v_t[offset];
165
163
  }
166
164
  };
167
165
 
@@ -206,69 +204,35 @@ AggregateFunction GetReservoirQuantileAggregateFunction(PhysicalType type) {
206
204
 
207
205
  template <class CHILD_TYPE>
208
206
  struct ReservoirQuantileListOperation : public ReservoirQuantileOperation {
209
-
210
- template <class RESULT_TYPE, class STATE>
211
- static void Finalize(Vector &result_list, AggregateInputData &aggr_input_data, STATE *state, RESULT_TYPE *target,
212
- ValidityMask &mask, idx_t idx) {
213
- if (state->pos == 0) {
214
- mask.SetInvalid(idx);
207
+ template <class T, class STATE>
208
+ static void Finalize(STATE &state, T &target, AggregateFinalizeData &finalize_data) {
209
+ if (state.pos == 0) {
210
+ finalize_data.ReturnNull();
215
211
  return;
216
212
  }
217
213
 
218
- D_ASSERT(aggr_input_data.bind_data);
219
- auto &bind_data = aggr_input_data.bind_data->template Cast<ReservoirQuantileBindData>();
214
+ D_ASSERT(finalize_data.input.bind_data);
215
+ auto &bind_data = finalize_data.input.bind_data->template Cast<ReservoirQuantileBindData>();
220
216
 
221
- auto &result = ListVector::GetEntry(result_list);
222
- auto ridx = ListVector::GetListSize(result_list);
223
- ListVector::Reserve(result_list, ridx + bind_data.quantiles.size());
217
+ auto &result = ListVector::GetEntry(finalize_data.result);
218
+ auto ridx = ListVector::GetListSize(finalize_data.result);
219
+ ListVector::Reserve(finalize_data.result, ridx + bind_data.quantiles.size());
224
220
  auto rdata = FlatVector::GetData<CHILD_TYPE>(result);
225
221
 
226
- auto v_t = state->v;
222
+ auto v_t = state.v;
227
223
  D_ASSERT(v_t);
228
224
 
229
- auto &entry = target[idx];
225
+ auto &entry = target;
230
226
  entry.offset = ridx;
231
227
  entry.length = bind_data.quantiles.size();
232
228
  for (size_t q = 0; q < entry.length; ++q) {
233
229
  const auto &quantile = bind_data.quantiles[q];
234
- auto offset = (idx_t)((double)(state->pos - 1) * quantile);
235
- std::nth_element(v_t, v_t + offset, v_t + state->pos);
230
+ auto offset = (idx_t)((double)(state.pos - 1) * quantile);
231
+ std::nth_element(v_t, v_t + offset, v_t + state.pos);
236
232
  rdata[ridx + q] = v_t[offset];
237
233
  }
238
234
 
239
- ListVector::SetListSize(result_list, entry.offset + entry.length);
240
- }
241
-
242
- template <class STATE_TYPE, class RESULT_TYPE>
243
- static void FinalizeList(Vector &states, AggregateInputData &aggr_input_data, Vector &result, idx_t count, // NOLINT
244
- idx_t offset) {
245
- D_ASSERT(result.GetType().id() == LogicalTypeId::LIST);
246
-
247
- D_ASSERT(aggr_input_data.bind_data);
248
- auto &bind_data = aggr_input_data.bind_data->Cast<ReservoirQuantileBindData>();
249
-
250
- if (states.GetVectorType() == VectorType::CONSTANT_VECTOR) {
251
- result.SetVectorType(VectorType::CONSTANT_VECTOR);
252
- ListVector::Reserve(result, bind_data.quantiles.size());
253
-
254
- auto sdata = ConstantVector::GetData<STATE_TYPE *>(states);
255
- auto rdata = ConstantVector::GetData<RESULT_TYPE>(result);
256
- auto &mask = ConstantVector::Validity(result);
257
- Finalize<RESULT_TYPE, STATE_TYPE>(result, aggr_input_data, sdata[0], rdata, mask, 0);
258
- } else {
259
- D_ASSERT(states.GetVectorType() == VectorType::FLAT_VECTOR);
260
- result.SetVectorType(VectorType::FLAT_VECTOR);
261
- ListVector::Reserve(result, (offset + count) * bind_data.quantiles.size());
262
-
263
- auto sdata = FlatVector::GetData<STATE_TYPE *>(states);
264
- auto rdata = FlatVector::GetData<RESULT_TYPE>(result);
265
- auto &mask = FlatVector::Validity(result);
266
- for (idx_t i = 0; i < count; i++) {
267
- Finalize<RESULT_TYPE, STATE_TYPE>(result, aggr_input_data, sdata[i], rdata, mask, i + offset);
268
- }
269
- }
270
-
271
- result.Verify(count);
235
+ ListVector::SetListSize(finalize_data.result, entry.offset + entry.length);
272
236
  }
273
237
  };
274
238
 
@@ -278,8 +242,8 @@ static AggregateFunction ReservoirQuantileListAggregate(const LogicalType &input
278
242
  return AggregateFunction(
279
243
  {input_type}, result_type, AggregateFunction::StateSize<STATE>, AggregateFunction::StateInitialize<STATE, OP>,
280
244
  AggregateFunction::UnaryScatterUpdate<STATE, INPUT_TYPE, OP>, AggregateFunction::StateCombine<STATE, OP>,
281
- OP::template FinalizeList<STATE, RESULT_TYPE>, AggregateFunction::UnaryUpdate<STATE, INPUT_TYPE, OP>, nullptr,
282
- AggregateFunction::StateDestroy<STATE, OP>);
245
+ AggregateFunction::StateFinalize<STATE, RESULT_TYPE, OP>, AggregateFunction::UnaryUpdate<STATE, INPUT_TYPE, OP>,
246
+ nullptr, AggregateFunction::StateDestroy<STATE, OP>);
283
247
  }
284
248
 
285
249
  template <typename INPUT_TYPE, typename SAVE_TYPE>
@@ -10,16 +10,15 @@ namespace duckdb {
10
10
  struct HistogramFunctor {
11
11
  template <class T, class MAP_TYPE = map<T, idx_t>>
12
12
  static void HistogramUpdate(UnifiedVectorFormat &sdata, UnifiedVectorFormat &input_data, idx_t count) {
13
-
14
13
  auto states = (HistogramAggState<T, MAP_TYPE> **)sdata.data;
15
14
  for (idx_t i = 0; i < count; i++) {
16
15
  if (input_data.validity.RowIsValid(input_data.sel->get_index(i))) {
17
- auto state = states[sdata.sel->get_index(i)];
18
- if (!state->hist) {
19
- state->hist = new MAP_TYPE();
16
+ auto &state = *states[sdata.sel->get_index(i)];
17
+ if (!state.hist) {
18
+ state.hist = new MAP_TYPE();
20
19
  }
21
20
  auto value = UnifiedVectorFormat::GetData<T>(input_data);
22
- (*state->hist)[value[input_data.sel->get_index(i)]]++;
21
+ (*state.hist)[value[input_data.sel->get_index(i)]]++;
23
22
  }
24
23
  }
25
24
  }
@@ -37,11 +36,11 @@ struct HistogramStringFunctor {
37
36
  auto input_strings = UnifiedVectorFormat::GetData<string_t>(input_data);
38
37
  for (idx_t i = 0; i < count; i++) {
39
38
  if (input_data.validity.RowIsValid(input_data.sel->get_index(i))) {
40
- auto state = states[sdata.sel->get_index(i)];
41
- if (!state->hist) {
42
- state->hist = new MAP_TYPE();
39
+ auto &state = *states[sdata.sel->get_index(i)];
40
+ if (!state.hist) {
41
+ state.hist = new MAP_TYPE();
43
42
  }
44
- (*state->hist)[input_strings[input_data.sel->get_index(i)].GetString()]++;
43
+ (*state.hist)[input_strings[input_data.sel->get_index(i)].GetString()]++;
45
44
  }
46
45
  }
47
46
  }
@@ -55,14 +54,14 @@ struct HistogramStringFunctor {
55
54
 
56
55
  struct HistogramFunction {
57
56
  template <class STATE>
58
- static void Initialize(STATE *state) {
59
- state->hist = nullptr;
57
+ static void Initialize(STATE &state) {
58
+ state.hist = nullptr;
60
59
  }
61
60
 
62
61
  template <class STATE>
63
- static void Destroy(AggregateInputData &aggr_input_data, STATE *state) {
64
- if (state->hist) {
65
- delete state->hist;
62
+ static void Destroy(STATE &state, AggregateInputData &aggr_input_data) {
63
+ if (state.hist) {
64
+ delete state.hist;
66
65
  }
67
66
  }
68
67
 
@@ -87,25 +86,25 @@ static void HistogramUpdateFunction(Vector inputs[], AggregateInputData &, idx_t
87
86
  }
88
87
 
89
88
  template <class T, class MAP_TYPE>
90
- static void HistogramCombineFunction(Vector &state, Vector &combined, AggregateInputData &, idx_t count) {
89
+ static void HistogramCombineFunction(Vector &state_vector, Vector &combined, AggregateInputData &, idx_t count) {
91
90
 
92
91
  UnifiedVectorFormat sdata;
93
- state.ToUnifiedFormat(count, sdata);
92
+ state_vector.ToUnifiedFormat(count, sdata);
94
93
  auto states_ptr = (HistogramAggState<T, MAP_TYPE> **)sdata.data;
95
94
 
96
95
  auto combined_ptr = FlatVector::GetData<HistogramAggState<T, MAP_TYPE> *>(combined);
97
96
 
98
97
  for (idx_t i = 0; i < count; i++) {
99
- auto state = states_ptr[sdata.sel->get_index(i)];
100
- if (!state->hist) {
98
+ auto &state = *states_ptr[sdata.sel->get_index(i)];
99
+ if (!state.hist) {
101
100
  continue;
102
101
  }
103
102
  if (!combined_ptr[i]->hist) {
104
103
  combined_ptr[i]->hist = new MAP_TYPE();
105
104
  }
106
105
  D_ASSERT(combined_ptr[i]->hist);
107
- D_ASSERT(state->hist);
108
- for (auto &entry : *state->hist) {
106
+ D_ASSERT(state.hist);
107
+ for (auto &entry : *state.hist) {
109
108
  (*combined_ptr[i]->hist)[entry.first] += entry.second;
110
109
  }
111
110
  }
@@ -124,13 +123,13 @@ static void HistogramFinalizeFunction(Vector &state_vector, AggregateInputData &
124
123
 
125
124
  for (idx_t i = 0; i < count; i++) {
126
125
  const auto rid = i + offset;
127
- auto state = states[sdata.sel->get_index(i)];
128
- if (!state->hist) {
126
+ auto &state = *states[sdata.sel->get_index(i)];
127
+ if (!state.hist) {
129
128
  mask.SetInvalid(rid);
130
129
  continue;
131
130
  }
132
131
 
133
- for (auto &entry : *state->hist) {
132
+ for (auto &entry : *state.hist) {
134
133
  Value bucket_value = OP::template HistogramFinalize<T>(entry.first);
135
134
  auto count_value = Value::CreateValue(entry.second);
136
135
  auto struct_value =
@@ -55,17 +55,16 @@ struct ListAggState {
55
55
 
56
56
  struct ListFunction {
57
57
  template <class STATE>
58
- static void Initialize(STATE *state) {
59
- state->linked_list.total_capacity = 0;
60
- state->linked_list.first_segment = nullptr;
61
- state->linked_list.last_segment = nullptr;
58
+ static void Initialize(STATE &state) {
59
+ state.linked_list.total_capacity = 0;
60
+ state.linked_list.first_segment = nullptr;
61
+ state.linked_list.last_segment = nullptr;
62
62
  }
63
63
 
64
64
  template <class STATE>
65
- static void Destroy(AggregateInputData &aggr_input_data, STATE *state) {
66
- D_ASSERT(state);
65
+ static void Destroy(STATE &state, AggregateInputData &aggr_input_data) {
67
66
  auto &list_bind_data = aggr_input_data.bind_data->Cast<ListBindData>();
68
- list_bind_data.functions.Destroy(aggr_input_data.allocator, state->linked_list);
67
+ list_bind_data.functions.Destroy(aggr_input_data.allocator, state.linked_list);
69
68
  }
70
69
  static bool IgnoreNull() {
71
70
  return false;
@@ -86,8 +85,8 @@ static void ListUpdateFunction(Vector inputs[], AggregateInputData &aggr_input_d
86
85
  auto &list_bind_data = aggr_input_data.bind_data->Cast<ListBindData>();
87
86
 
88
87
  for (idx_t i = 0; i < count; i++) {
89
- auto state = states[sdata.sel->get_index(i)];
90
- list_bind_data.functions.AppendRow(aggr_input_data.allocator, state->linked_list, input, i, count);
88
+ auto &state = *states[sdata.sel->get_index(i)];
89
+ list_bind_data.functions.AppendRow(aggr_input_data.allocator, state.linked_list, input, i, count);
91
90
  }
92
91
  }
93
92
 
@@ -100,15 +99,15 @@ static void ListCombineFunction(Vector &state, Vector &combined, AggregateInputD
100
99
 
101
100
  auto combined_ptr = FlatVector::GetData<ListAggState *>(combined);
102
101
  for (idx_t i = 0; i < count; i++) {
103
- auto state = states_ptr[sdata.sel->get_index(i)];
104
- if (state->linked_list.total_capacity == 0) {
102
+ auto &state = *states_ptr[sdata.sel->get_index(i)];
103
+ if (state.linked_list.total_capacity == 0) {
105
104
  // NULL, no need to append.
106
105
  continue;
107
106
  }
108
107
 
109
108
  // copy the linked list of the state
110
- auto copied_linked_list = LinkedList(state->linked_list.total_capacity, nullptr, nullptr);
111
- list_bind_data.functions.CopyLinkedList(state->linked_list, copied_linked_list, aggr_input_data.allocator);
109
+ auto copied_linked_list = LinkedList(state.linked_list.total_capacity, nullptr, nullptr);
110
+ list_bind_data.functions.CopyLinkedList(state.linked_list, copied_linked_list, aggr_input_data.allocator);
112
111
 
113
112
  // append the copied linked list to the combined state
114
113
  if (combined_ptr[i]->linked_list.last_segment) {
@@ -136,16 +135,16 @@ static void ListFinalize(Vector &state_vector, AggregateInputData &aggr_input_da
136
135
  auto &list_bind_data = aggr_input_data.bind_data->Cast<ListBindData>();
137
136
  // first iterate over all of the entries and set up the list entries, plus get the newly required total length
138
137
  for (idx_t i = 0; i < count; i++) {
139
- auto state = states[sdata.sel->get_index(i)];
138
+ auto &state = *states[sdata.sel->get_index(i)];
140
139
  const auto rid = i + offset;
141
140
  result_data[rid].offset = total_len;
142
- if (state->linked_list.total_capacity == 0) {
141
+ if (state.linked_list.total_capacity == 0) {
143
142
  mask.SetInvalid(rid);
144
143
  result_data[rid].length = 0;
145
144
  continue;
146
145
  }
147
146
  // set the length and offset of this list in the result vector
148
- auto total_capacity = state->linked_list.total_capacity;
147
+ auto total_capacity = state.linked_list.total_capacity;
149
148
  result_data[rid].length = total_capacity;
150
149
  total_len += total_capacity;
151
150
  }
@@ -153,14 +152,14 @@ static void ListFinalize(Vector &state_vector, AggregateInputData &aggr_input_da
153
152
  ListVector::Reserve(result, total_len);
154
153
  auto &result_child = ListVector::GetEntry(result);
155
154
  for (idx_t i = 0; i < count; i++) {
156
- auto state = states[sdata.sel->get_index(i)];
155
+ auto &state = *states[sdata.sel->get_index(i)];
157
156
  const auto rid = i + offset;
158
- if (state->linked_list.total_capacity == 0) {
157
+ if (state.linked_list.total_capacity == 0) {
159
158
  continue;
160
159
  }
161
160
 
162
161
  idx_t current_offset = result_data[rid].offset;
163
- list_bind_data.functions.BuildListVector(state->linked_list, result_child, current_offset);
162
+ list_bind_data.functions.BuildListVector(state.linked_list, result_child, current_offset);
164
163
  }
165
164
  ListVector::SetListSize(result, total_len);
166
165
  }
@@ -12,23 +12,23 @@ struct RegrState {
12
12
 
13
13
  struct RegrAvgFunction {
14
14
  template <class STATE>
15
- static void Initialize(STATE *state) {
16
- state->sum = 0;
17
- state->count = 0;
15
+ static void Initialize(STATE &state) {
16
+ state.sum = 0;
17
+ state.count = 0;
18
18
  }
19
19
 
20
20
  template <class STATE, class OP>
21
- static void Combine(const STATE &source, STATE *target, AggregateInputData &) {
22
- target->sum += source.sum;
23
- target->count += source.count;
21
+ static void Combine(const STATE &source, STATE &target, AggregateInputData &) {
22
+ target.sum += source.sum;
23
+ target.count += source.count;
24
24
  }
25
25
 
26
26
  template <class T, class STATE>
27
- static void Finalize(Vector &result, AggregateInputData &, STATE *state, T *target, ValidityMask &mask, idx_t idx) {
28
- if (state->count == 0) {
29
- mask.SetInvalid(idx);
27
+ static void Finalize(STATE &state, T &target, AggregateFinalizeData &finalize_data) {
28
+ if (state.count == 0) {
29
+ finalize_data.ReturnNull();
30
30
  } else {
31
- target[idx] = state->sum / (double)state->count;
31
+ target = state.sum / (double)state.count;
32
32
  }
33
33
  }
34
34
  static bool IgnoreNull() {
@@ -37,19 +37,17 @@ struct RegrAvgFunction {
37
37
  };
38
38
  struct RegrAvgXFunction : RegrAvgFunction {
39
39
  template <class A_TYPE, class B_TYPE, class STATE, class OP>
40
- static void Operation(STATE *state, AggregateInputData &, const A_TYPE *x_data, const B_TYPE *y_data,
41
- ValidityMask &amask, ValidityMask &bmask, idx_t xidx, idx_t yidx) {
42
- state->sum += y_data[yidx];
43
- state->count++;
40
+ static void Operation(STATE &state, const A_TYPE &x, const B_TYPE &y, AggregateBinaryInput &idata) {
41
+ state.sum += y;
42
+ state.count++;
44
43
  }
45
44
  };
46
45
 
47
46
  struct RegrAvgYFunction : RegrAvgFunction {
48
47
  template <class A_TYPE, class B_TYPE, class STATE, class OP>
49
- static void Operation(STATE *state, AggregateInputData &, const A_TYPE *x_data, const B_TYPE *y_data,
50
- ValidityMask &amask, ValidityMask &bmask, idx_t xidx, idx_t yidx) {
51
- state->sum += x_data[xidx];
52
- state->count++;
48
+ static void Operation(STATE &state, const A_TYPE &x, const B_TYPE &y, AggregateBinaryInput &idata) {
49
+ state.sum += x;
50
+ state.count++;
53
51
  }
54
52
  };
55
53
 
@@ -15,42 +15,39 @@ struct RegrInterceptState {
15
15
 
16
16
  struct RegrInterceptOperation {
17
17
  template <class STATE>
18
- static void Initialize(STATE *state) {
19
- state->count = 0;
20
- state->sum_x = 0;
21
- state->sum_y = 0;
22
- RegrSlopeOperation::Initialize<RegrSlopeState>(&state->slope);
18
+ static void Initialize(STATE &state) {
19
+ state.count = 0;
20
+ state.sum_x = 0;
21
+ state.sum_y = 0;
22
+ RegrSlopeOperation::Initialize<RegrSlopeState>(state.slope);
23
23
  }
24
24
 
25
25
  template <class A_TYPE, class B_TYPE, class STATE, class OP>
26
- static void Operation(STATE *state, AggregateInputData &aggr_input_data, const A_TYPE *x_data, const B_TYPE *y_data,
27
- ValidityMask &amask, ValidityMask &bmask, idx_t xidx, idx_t yidx) {
28
- state->count++;
29
- state->sum_x += y_data[yidx];
30
- state->sum_y += x_data[xidx];
31
- RegrSlopeOperation::Operation<A_TYPE, B_TYPE, RegrSlopeState, OP>(&state->slope, aggr_input_data, x_data,
32
- y_data, amask, bmask, xidx, yidx);
26
+ static void Operation(STATE &state, const A_TYPE &x, const B_TYPE &y, AggregateBinaryInput &idata) {
27
+ state.count++;
28
+ state.sum_x += y;
29
+ state.sum_y += x;
30
+ RegrSlopeOperation::Operation<A_TYPE, B_TYPE, RegrSlopeState, OP>(state.slope, x, y, idata);
33
31
  }
34
32
 
35
33
  template <class STATE, class OP>
36
- static void Combine(const STATE &source, STATE *target, AggregateInputData &aggr_input_data) {
37
- target->count += source.count;
38
- target->sum_x += source.sum_x;
39
- target->sum_y += source.sum_y;
40
- RegrSlopeOperation::Combine<RegrSlopeState, OP>(source.slope, &target->slope, aggr_input_data);
34
+ static void Combine(const STATE &source, STATE &target, AggregateInputData &aggr_input_data) {
35
+ target.count += source.count;
36
+ target.sum_x += source.sum_x;
37
+ target.sum_y += source.sum_y;
38
+ RegrSlopeOperation::Combine<RegrSlopeState, OP>(source.slope, target.slope, aggr_input_data);
41
39
  }
42
40
 
43
41
  template <class T, class STATE>
44
- static void Finalize(Vector &result, AggregateInputData &aggr_input_data, STATE *state, T *target,
45
- ValidityMask &mask, idx_t idx) {
46
- if (state->count == 0) {
47
- mask.SetInvalid(idx);
42
+ static void Finalize(STATE &state, T &target, AggregateFinalizeData &finalize_data) {
43
+ if (state.count == 0) {
44
+ finalize_data.ReturnNull();
48
45
  return;
49
46
  }
50
- RegrSlopeOperation::Finalize<T, RegrSlopeState>(result, aggr_input_data, &state->slope, target, mask, idx);
51
- auto x_avg = state->sum_x / state->count;
52
- auto y_avg = state->sum_y / state->count;
53
- target[idx] = y_avg - target[idx] * x_avg;
47
+ RegrSlopeOperation::Finalize<T, RegrSlopeState>(state.slope, target, finalize_data);
48
+ auto x_avg = state.sum_x / state.count;
49
+ auto y_avg = state.sum_y / state.count;
50
+ target = y_avg - target * x_avg;
54
51
  }
55
52
 
56
53
  static bool IgnoreNull() {
@@ -17,51 +17,46 @@ struct RegrR2State {
17
17
 
18
18
  struct RegrR2Operation {
19
19
  template <class STATE>
20
- static void Initialize(STATE *state) {
21
- CorrOperation::Initialize<CorrState>(&state->corr);
22
- STDDevBaseOperation::Initialize<StddevState>(&state->var_pop_x);
23
- STDDevBaseOperation::Initialize<StddevState>(&state->var_pop_y);
20
+ static void Initialize(STATE &state) {
21
+ CorrOperation::Initialize<CorrState>(state.corr);
22
+ STDDevBaseOperation::Initialize<StddevState>(state.var_pop_x);
23
+ STDDevBaseOperation::Initialize<StddevState>(state.var_pop_y);
24
24
  }
25
25
 
26
26
  template <class A_TYPE, class B_TYPE, class STATE, class OP>
27
- static void Operation(STATE *state, AggregateInputData &aggr_input_data, const A_TYPE *x_data, const B_TYPE *y_data,
28
- ValidityMask &amask, ValidityMask &bmask, idx_t xidx, idx_t yidx) {
29
- CorrOperation::Operation<A_TYPE, B_TYPE, CorrState, OP>(&state->corr, aggr_input_data, y_data, x_data, bmask,
30
- amask, yidx, xidx);
31
- STDDevBaseOperation::Operation<A_TYPE, StddevState, OP>(&state->var_pop_x, aggr_input_data, y_data, bmask,
32
- yidx);
33
- STDDevBaseOperation::Operation<A_TYPE, StddevState, OP>(&state->var_pop_y, aggr_input_data, x_data, amask,
34
- xidx);
27
+ static void Operation(STATE &state, const A_TYPE &x, const B_TYPE &y, AggregateBinaryInput &idata) {
28
+ CorrOperation::Operation<A_TYPE, B_TYPE, CorrState, OP>(state.corr, x, y, idata);
29
+ STDDevBaseOperation::Execute<A_TYPE, StddevState>(state.var_pop_x, y);
30
+ STDDevBaseOperation::Execute<A_TYPE, StddevState>(state.var_pop_y, x);
35
31
  }
36
32
 
37
33
  template <class STATE, class OP>
38
- static void Combine(const STATE &source, STATE *target, AggregateInputData &aggr_input_data) {
39
- CorrOperation::Combine<CorrState, OP>(source.corr, &target->corr, aggr_input_data);
40
- STDDevBaseOperation::Combine<StddevState, OP>(source.var_pop_x, &target->var_pop_x, aggr_input_data);
41
- STDDevBaseOperation::Combine<StddevState, OP>(source.var_pop_y, &target->var_pop_y, aggr_input_data);
34
+ static void Combine(const STATE &source, STATE &target, AggregateInputData &aggr_input_data) {
35
+ CorrOperation::Combine<CorrState, OP>(source.corr, target.corr, aggr_input_data);
36
+ STDDevBaseOperation::Combine<StddevState, OP>(source.var_pop_x, target.var_pop_x, aggr_input_data);
37
+ STDDevBaseOperation::Combine<StddevState, OP>(source.var_pop_y, target.var_pop_y, aggr_input_data);
42
38
  }
43
39
 
44
40
  template <class T, class STATE>
45
- static void Finalize(Vector &result, AggregateInputData &aggr_input_data, STATE *state, T *target,
46
- ValidityMask &mask, idx_t idx) {
47
- auto var_pop_x = state->var_pop_x.count > 1 ? (state->var_pop_x.dsquared / state->var_pop_x.count) : 0;
41
+ static void Finalize(STATE &state, T &target, AggregateFinalizeData &finalize_data) {
42
+ auto var_pop_x = state.var_pop_x.count > 1 ? (state.var_pop_x.dsquared / state.var_pop_x.count) : 0;
48
43
  if (!Value::DoubleIsFinite(var_pop_x)) {
49
44
  throw OutOfRangeException("VARPOP(X) is out of range!");
50
45
  }
51
46
  if (var_pop_x == 0) {
52
- mask.SetInvalid(idx);
47
+ finalize_data.ReturnNull();
53
48
  return;
54
49
  }
55
- auto var_pop_y = state->var_pop_y.count > 1 ? (state->var_pop_y.dsquared / state->var_pop_y.count) : 0;
50
+ auto var_pop_y = state.var_pop_y.count > 1 ? (state.var_pop_y.dsquared / state.var_pop_y.count) : 0;
56
51
  if (!Value::DoubleIsFinite(var_pop_y)) {
57
52
  throw OutOfRangeException("VARPOP(Y) is out of range!");
58
53
  }
59
54
  if (var_pop_y == 0) {
60
- target[idx] = 1;
55
+ target = 1;
61
56
  return;
62
57
  }
63
- CorrOperation::Finalize<T, CorrState>(result, aggr_input_data, &state->corr, target, mask, idx);
64
- target[idx] = pow(target[idx], 2);
58
+ CorrOperation::Finalize<T, CorrState>(state.corr, target, finalize_data);
59
+ target = pow(target, 2);
65
60
  }
66
61
 
67
62
  static bool IgnoreNull() {