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.
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
@@ -16,67 +16,66 @@ struct KurtosisState {
16
16
 
17
17
  struct KurtosisOperation {
18
18
  template <class 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;
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 *state, AggregateInputData &aggr_input_data, const INPUT_TYPE *input,
26
- ValidityMask &mask, idx_t count) {
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, aggr_input_data, input, mask, 0);
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 *state, AggregateInputData &, const INPUT_TYPE *data, ValidityMask &mask, idx_t idx) {
34
- state->n++;
35
- state->sum += data[idx];
36
- state->sum_sqr += pow(data[idx], 2);
37
- state->sum_cub += pow(data[idx], 3);
38
- state->sum_four += pow(data[idx], 4);
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 *target, AggregateInputData &) {
42
+ static void Combine(const STATE &source, STATE &target, AggregateInputData &) {
43
43
  if (source.n == 0) {
44
44
  return;
45
45
  }
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;
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(Vector &result, AggregateInputData &, STATE *state, TARGET_TYPE *target, ValidityMask &mask,
55
- idx_t idx) {
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
- mask.SetInvalid(idx);
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->sum_sqr - state->sum * state->sum * temp == 0 ||
65
- state->sum_sqr - state->sum * state->sum * temp_aux == 0) {
66
- mask.SetInvalid(idx);
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->sum_four - 4 * state->sum_cub * state->sum * temp +
71
- 6 * state->sum_sqr * state->sum * state->sum * temp * temp - 3 * pow(state->sum, 4) * pow(temp, 3));
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->sum_sqr - state->sum * state->sum * temp);
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
- mask.SetInvalid(idx);
74
+ finalize_data.ReturnNull();
76
75
  return;
77
76
  }
78
- target[idx] = (n - 1) * ((n + 1) * m4 / (m2 * m2) - 3 * (n - 1)) / ((n - 2) * (n - 3));
79
- if (!Value::DoubleIsFinite(target[idx])) {
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 *state) {
53
- state->isset = false;
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 *state, AggregateInputData &input_data, const INPUT_TYPE *input,
58
- ValidityMask &mask, idx_t count) {
59
- D_ASSERT(mask.RowIsValid(0));
60
- if (!state->isset) {
61
- OP::template Assign<INPUT_TYPE, STATE>(state, input_data, input[0]);
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, input_data, input[0]);
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 *state, AggregateInputData &input_data, const INPUT_TYPE *input, ValidityMask &mask,
70
- idx_t idx) {
71
- if (!state->isset) {
72
- OP::template Assign<INPUT_TYPE, STATE>(state, input_data, input[idx]);
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, input_data, input[idx]);
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 *state, AggregateInputData &, INPUT_TYPE input) {
87
- state->value = input;
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(Vector &result, AggregateInputData &, STATE *state, T *target, ValidityMask &mask, idx_t idx) {
92
- mask.Set(idx, state->isset);
93
- target[idx] = state->value;
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 *state, AggregateInputData &, INPUT_TYPE input) {
100
- if (LessThan::Operation<INPUT_TYPE>(input, state->value)) {
101
- state->value = input;
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 *target, AggregateInputData &) {
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->isset) {
112
+ if (!target.isset) {
112
113
  // target is NULL, use source value directly
113
- *target = source;
114
- } else if (GreaterThan::Operation(target->value, source.value)) {
115
- target->value = source.value;
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 *state, AggregateInputData &, INPUT_TYPE input) {
123
- if (GreaterThan::Operation<INPUT_TYPE>(input, state->value)) {
124
- state->value = input;
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 *target, AggregateInputData &) {
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->isset) {
135
+ if (!target.isset) {
135
136
  // target is NULL, use source value directly
136
- *target = source;
137
- } else if (LessThan::Operation(target->value, source.value)) {
138
- target->value = source.value;
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(AggregateInputData &aggr_input_data, STATE *state) {
146
- if (state->isset && !state->value.IsInlined()) {
147
- delete[] state->value.GetData();
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 *state, AggregateInputData &input_data, INPUT_TYPE input) {
153
- Destroy(input_data, state);
153
+ static void Assign(STATE &state, INPUT_TYPE input, AggregateInputData &input_data) {
154
+ Destroy(state, input_data);
154
155
  if (input.IsInlined()) {
155
- state->value = input;
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->value = string_t(ptr, len);
163
+ state.value = string_t(ptr, len);
163
164
  }
164
165
  }
165
166
 
166
167
  template <class T, class STATE>
167
- static void Finalize(Vector &result, AggregateInputData &, STATE *state, T *target, ValidityMask &mask, idx_t idx) {
168
- if (!state->isset) {
169
- mask.SetInvalid(idx);
168
+ static void Finalize(STATE &state, T &target, AggregateFinalizeData &finalize_data) {
169
+ if (!state.isset) {
170
+ finalize_data.ReturnNull();
170
171
  } else {
171
- target[idx] = StringVector::AddStringOrBlob(result, state->value);
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 *target, AggregateInputData &input_data) {
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->isset) {
182
+ if (!target.isset) {
182
183
  // target is NULL, use source value directly
183
- Assign(target, input_data, source.value);
184
- target->isset = true;
184
+ Assign(target, source.value, input_data);
185
+ target.isset = true;
185
186
  } else {
186
- OP::template Execute<string_t, STATE>(target, input_data, source.value);
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 *state, AggregateInputData &input_data, INPUT_TYPE input) {
194
- if (LessThan::Operation<INPUT_TYPE>(input, state->value)) {
195
- Assign(state, input_data, input);
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 *state, AggregateInputData &input_data, INPUT_TYPE input) {
203
- if (GreaterThan::Operation<INPUT_TYPE>(input, state->value)) {
204
- Assign(state, input_data, input);
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 *state) {
383
- state->value = nullptr;
383
+ static void Initialize(STATE &state) {
384
+ state.value = nullptr;
384
385
  }
385
386
 
386
387
  template <class STATE>
387
- static void Destroy(AggregateInputData &aggr_input_data, STATE *state) {
388
- if (state->value) {
389
- delete state->value;
388
+ static void Destroy(STATE &state, AggregateInputData &aggr_input_data) {
389
+ if (state.value) {
390
+ delete state.value;
390
391
  }
391
- state->value = nullptr;
392
+ state.value = nullptr;
392
393
  }
393
394
 
394
395
  template <class STATE>
395
- static void Assign(STATE *state, Vector &input, const idx_t idx) {
396
- if (!state->value) {
397
- state->value = new Vector(input.GetType());
398
- state->value->SetVectorType(VectorType::CONSTANT_VECTOR);
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->value, sel, 1, 0, 0);
403
+ VectorOperations::Copy(input, *state.value, sel, 1, 0, 0);
403
404
  }
404
405
 
405
406
  template <class STATE>
406
- static void Execute(STATE *state, Vector &input, const idx_t idx, const idx_t count) {
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->value) {
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 *target, AggregateInputData &) {
437
+ static void Combine(const STATE &source, STATE &target, AggregateInputData &) {
437
438
  if (!source.value) {
438
439
  return;
439
- } else if (!target->value) {
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 T, class STATE>
447
- static void Finalize(Vector &result, AggregateInputData &, STATE *state, T *target, ValidityMask &mask, idx_t idx) {
448
- if (!state->value) {
449
- // we need to use SetNull here
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->value, result, 1, 0, idx);
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 *state, Vector &input, const idx_t idx, const idx_t count) {
478
- if (TemplatedOptimumValue<DistinctLessThan>(input, idx, count, *state->value, 0, 1)) {
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 *state, Vector &input, const idx_t idx, const idx_t count) {
487
- if (TemplatedOptimumValue<DistinctGreaterThan>(input, idx, count, *state->value, 0, 1)) {
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({type}, type, AggregateFunction::StateSize<STATE>,
522
- AggregateFunction::StateInitialize<STATE, OP>, OP::template Update<STATE, OP>,
523
- AggregateFunction::StateCombine<STATE, OP>,
524
- AggregateFunction::StateFinalize<STATE, void, OP>, nullptr, OP::Bind,
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 *state) {
17
- state->val = 1;
18
- state->empty = true;
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 *target, AggregateInputData &) {
23
- target->val *= source.val;
24
- target->empty = target->empty && source.empty;
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(Vector &result, AggregateInputData &, STATE *state, T *target, ValidityMask &mask, idx_t idx) {
29
- if (state->empty) {
30
- mask.SetInvalid(idx);
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[idx] = state->val;
33
+ target = state.val;
34
34
  }
35
35
  template <class INPUT_TYPE, class STATE, class OP>
36
- static void Operation(STATE *state, AggregateInputData &, const INPUT_TYPE *input, ValidityMask &mask, idx_t idx) {
37
- if (state->empty) {
38
- state->empty = false;
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->val *= input[idx];
40
+ state.val *= input;
41
41
  }
42
42
 
43
43
  template <class INPUT_TYPE, class STATE, class OP>
44
- static void ConstantOperation(STATE *state, AggregateInputData &aggr_input_data, const INPUT_TYPE *input,
45
- ValidityMask &mask, idx_t count) {
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, aggr_input_data, input, mask, 0);
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 *state) {
19
- state->n = 0;
20
- state->sum = state->sum_sqr = state->sum_cub = 0;
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 *state, AggregateInputData &aggr_input_data, const INPUT_TYPE *input,
25
- ValidityMask &mask, idx_t count) {
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, aggr_input_data, input, mask, 0);
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 *state, AggregateInputData &, const INPUT_TYPE *data, ValidityMask &mask, idx_t idx) {
33
- state->n++;
34
- state->sum += data[idx];
35
- state->sum_sqr += pow(data[idx], 2);
36
- state->sum_cub += pow(data[idx], 3);
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 *target, AggregateInputData &) {
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->n += source.n;
46
- target->sum += source.sum;
47
- target->sum_sqr += source.sum_sqr;
48
- target->sum_cub += source.sum_cub;
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(Vector &result, AggregateInputData &, STATE *state, TARGET_TYPE *target, ValidityMask &mask,
53
- idx_t idx) {
54
- if (state->n <= 2) {
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->n;
57
+ double n = state.n;
59
58
  double temp = 1 / n;
60
- auto p = std::pow(temp * (state->sum_sqr - state->sum * state->sum * temp), 3);
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
- mask.SetInvalid(idx);
65
+ finalize_data.ReturnNull();
67
66
  return;
68
67
  }
69
68
  double temp1 = std::sqrt(n * (n - 1)) / (n - 2);
70
- target[idx] = temp1 * temp *
71
- (state->sum_cub - 3 * state->sum_sqr * state->sum * temp + 2 * pow(state->sum, 3) * temp * temp) /
72
- div;
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
  }