duckdb 0.7.2-dev16.0 → 0.7.2-dev314.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 (242) hide show
  1. package/binding.gyp +2 -0
  2. package/package.json +1 -1
  3. package/src/duckdb/extension/icu/icu-extension.cpp +2 -0
  4. package/src/duckdb/extension/icu/icu-table-range.cpp +194 -0
  5. package/src/duckdb/extension/icu/include/icu-table-range.hpp +17 -0
  6. package/src/duckdb/extension/parquet/column_reader.cpp +5 -6
  7. package/src/duckdb/extension/parquet/column_writer.cpp +0 -1
  8. package/src/duckdb/extension/parquet/include/column_reader.hpp +1 -2
  9. package/src/duckdb/extension/parquet/include/generated_column_reader.hpp +1 -11
  10. package/src/duckdb/extension/parquet/parquet-extension.cpp +11 -2
  11. package/src/duckdb/extension/parquet/parquet_statistics.cpp +26 -32
  12. package/src/duckdb/src/catalog/catalog_entry/duck_schema_entry.cpp +4 -0
  13. package/src/duckdb/src/catalog/catalog_entry/scalar_function_catalog_entry.cpp +7 -6
  14. package/src/duckdb/src/catalog/catalog_entry/table_function_catalog_entry.cpp +20 -1
  15. package/src/duckdb/src/common/enums/statement_type.cpp +2 -0
  16. package/src/duckdb/src/common/sort/sort_state.cpp +5 -7
  17. package/src/duckdb/src/common/types/bit.cpp +95 -58
  18. package/src/duckdb/src/common/types/value.cpp +149 -53
  19. package/src/duckdb/src/common/types/vector.cpp +13 -10
  20. package/src/duckdb/src/execution/column_binding_resolver.cpp +6 -0
  21. package/src/duckdb/src/execution/operator/aggregate/physical_perfecthash_aggregate.cpp +4 -5
  22. package/src/duckdb/src/execution/operator/aggregate/physical_window.cpp +1 -1
  23. package/src/duckdb/src/execution/operator/helper/physical_vacuum.cpp +2 -3
  24. package/src/duckdb/src/execution/operator/join/physical_blockwise_nl_join.cpp +32 -6
  25. package/src/duckdb/src/execution/operator/persistent/buffered_csv_reader.cpp +1 -1
  26. package/src/duckdb/src/execution/physical_plan/plan_aggregate.cpp +15 -15
  27. package/src/duckdb/src/execution/physical_plan/plan_comparison_join.cpp +18 -12
  28. package/src/duckdb/src/function/aggregate/algebraic/avg.cpp +0 -6
  29. package/src/duckdb/src/function/aggregate/distributive/bitagg.cpp +99 -95
  30. package/src/duckdb/src/function/aggregate/distributive/bitstring_agg.cpp +254 -0
  31. package/src/duckdb/src/function/aggregate/distributive/count.cpp +2 -4
  32. package/src/duckdb/src/function/aggregate/distributive/sum.cpp +11 -16
  33. package/src/duckdb/src/function/aggregate/distributive_functions.cpp +1 -0
  34. package/src/duckdb/src/function/aggregate/sorted_aggregate_function.cpp +16 -5
  35. package/src/duckdb/src/function/cast/bit_cast.cpp +0 -2
  36. package/src/duckdb/src/function/cast/blob_cast.cpp +0 -1
  37. package/src/duckdb/src/function/scalar/bit/bitstring.cpp +99 -0
  38. package/src/duckdb/src/function/scalar/date/date_diff.cpp +0 -1
  39. package/src/duckdb/src/function/scalar/date/date_part.cpp +17 -25
  40. package/src/duckdb/src/function/scalar/date/date_sub.cpp +0 -1
  41. package/src/duckdb/src/function/scalar/date/date_trunc.cpp +10 -14
  42. package/src/duckdb/src/function/scalar/generic/stats.cpp +2 -4
  43. package/src/duckdb/src/function/scalar/list/flatten.cpp +5 -12
  44. package/src/duckdb/src/function/scalar/list/list_concat.cpp +3 -8
  45. package/src/duckdb/src/function/scalar/list/list_extract.cpp +5 -12
  46. package/src/duckdb/src/function/scalar/list/list_value.cpp +5 -9
  47. package/src/duckdb/src/function/scalar/map/map_entries.cpp +61 -0
  48. package/src/duckdb/src/function/scalar/map/map_keys_values.cpp +97 -0
  49. package/src/duckdb/src/function/scalar/math/numeric.cpp +14 -17
  50. package/src/duckdb/src/function/scalar/nested_functions.cpp +3 -0
  51. package/src/duckdb/src/function/scalar/operators/add.cpp +0 -9
  52. package/src/duckdb/src/function/scalar/operators/arithmetic.cpp +29 -48
  53. package/src/duckdb/src/function/scalar/operators/bitwise.cpp +0 -63
  54. package/src/duckdb/src/function/scalar/operators/multiply.cpp +0 -6
  55. package/src/duckdb/src/function/scalar/operators/subtract.cpp +0 -6
  56. package/src/duckdb/src/function/scalar/string/caseconvert.cpp +2 -6
  57. package/src/duckdb/src/function/scalar/string/instr.cpp +2 -6
  58. package/src/duckdb/src/function/scalar/string/length.cpp +2 -6
  59. package/src/duckdb/src/function/scalar/string/like.cpp +2 -6
  60. package/src/duckdb/src/function/scalar/string/substring.cpp +2 -6
  61. package/src/duckdb/src/function/scalar/string_functions.cpp +1 -0
  62. package/src/duckdb/src/function/scalar/struct/struct_extract.cpp +4 -9
  63. package/src/duckdb/src/function/scalar/struct/struct_insert.cpp +10 -13
  64. package/src/duckdb/src/function/scalar/struct/struct_pack.cpp +5 -6
  65. package/src/duckdb/src/function/table/read_csv.cpp +9 -0
  66. package/src/duckdb/src/function/table/version/pragma_version.cpp +2 -2
  67. package/src/duckdb/src/function/table_function.cpp +19 -0
  68. package/src/duckdb/src/include/duckdb/catalog/catalog_entry/table_function_catalog_entry.hpp +6 -8
  69. package/src/duckdb/src/include/duckdb/common/constants.hpp +0 -19
  70. package/src/duckdb/src/include/duckdb/common/enums/statement_type.hpp +2 -1
  71. package/src/duckdb/src/include/duckdb/common/enums/tableref_type.hpp +2 -1
  72. package/src/duckdb/src/include/duckdb/common/types/bit.hpp +5 -1
  73. package/src/duckdb/src/include/duckdb/common/types/value.hpp +2 -8
  74. package/src/duckdb/src/include/duckdb/common/types.hpp +1 -2
  75. package/src/duckdb/src/include/duckdb/execution/operator/aggregate/physical_perfecthash_aggregate.hpp +1 -1
  76. package/src/duckdb/src/include/duckdb/function/aggregate/distributive_functions.hpp +5 -0
  77. package/src/duckdb/src/include/duckdb/function/aggregate_function.hpp +12 -3
  78. package/src/duckdb/src/include/duckdb/function/scalar/bit_functions.hpp +4 -0
  79. package/src/duckdb/src/include/duckdb/function/scalar/nested_functions.hpp +12 -0
  80. package/src/duckdb/src/include/duckdb/function/scalar_function.hpp +2 -2
  81. package/src/duckdb/src/include/duckdb/function/table_function.hpp +2 -0
  82. package/src/duckdb/src/include/duckdb/main/capi/capi_internal.hpp +2 -0
  83. package/src/duckdb/src/include/duckdb/main/config.hpp +3 -0
  84. package/src/duckdb/src/include/duckdb/main/database.hpp +1 -0
  85. package/src/duckdb/src/include/duckdb/optimizer/join_order/cardinality_estimator.hpp +2 -2
  86. package/src/duckdb/src/include/duckdb/parser/common_table_expression_info.hpp +2 -0
  87. package/src/duckdb/src/include/duckdb/parser/parsed_data/alter_info.hpp +2 -1
  88. package/src/duckdb/src/include/duckdb/parser/parsed_data/{alter_function_info.hpp → alter_scalar_function_info.hpp} +13 -13
  89. package/src/duckdb/src/include/duckdb/parser/parsed_data/alter_table_function_info.hpp +47 -0
  90. package/src/duckdb/src/include/duckdb/parser/parsed_data/create_table_function_info.hpp +2 -1
  91. package/src/duckdb/src/include/duckdb/parser/query_node.hpp +2 -1
  92. package/src/duckdb/src/include/duckdb/parser/statement/multi_statement.hpp +28 -0
  93. package/src/duckdb/src/include/duckdb/parser/tableref/list.hpp +1 -0
  94. package/src/duckdb/src/include/duckdb/parser/tableref/pivotref.hpp +76 -0
  95. package/src/duckdb/src/include/duckdb/parser/tokens.hpp +2 -0
  96. package/src/duckdb/src/include/duckdb/parser/transformer.hpp +28 -0
  97. package/src/duckdb/src/include/duckdb/planner/bind_context.hpp +2 -0
  98. package/src/duckdb/src/include/duckdb/planner/binder.hpp +8 -0
  99. package/src/duckdb/src/include/duckdb/storage/buffer/block_handle.hpp +2 -0
  100. package/src/duckdb/src/include/duckdb/storage/buffer_manager.hpp +76 -44
  101. package/src/duckdb/src/include/duckdb/storage/checkpoint/table_data_writer.hpp +3 -2
  102. package/src/duckdb/src/include/duckdb/storage/compression/chimp/chimp_compress.hpp +2 -2
  103. package/src/duckdb/src/include/duckdb/storage/compression/chimp/chimp_fetch.hpp +1 -1
  104. package/src/duckdb/src/include/duckdb/storage/compression/chimp/chimp_scan.hpp +1 -1
  105. package/src/duckdb/src/include/duckdb/storage/compression/patas/patas_compress.hpp +2 -2
  106. package/src/duckdb/src/include/duckdb/storage/compression/patas/patas_fetch.hpp +1 -1
  107. package/src/duckdb/src/include/duckdb/storage/compression/patas/patas_scan.hpp +1 -1
  108. package/src/duckdb/src/include/duckdb/storage/data_pointer.hpp +5 -2
  109. package/src/duckdb/src/include/duckdb/storage/data_table.hpp +1 -1
  110. package/src/duckdb/src/include/duckdb/storage/statistics/base_statistics.hpp +93 -29
  111. package/src/duckdb/src/include/duckdb/storage/statistics/column_statistics.hpp +22 -3
  112. package/src/duckdb/src/include/duckdb/storage/statistics/distinct_statistics.hpp +6 -6
  113. package/src/duckdb/src/include/duckdb/storage/statistics/list_stats.hpp +41 -0
  114. package/src/duckdb/src/include/duckdb/storage/statistics/node_statistics.hpp +26 -0
  115. package/src/duckdb/src/include/duckdb/storage/statistics/numeric_stats.hpp +157 -0
  116. package/src/duckdb/src/include/duckdb/storage/statistics/segment_statistics.hpp +2 -7
  117. package/src/duckdb/src/include/duckdb/storage/statistics/string_stats.hpp +74 -0
  118. package/src/duckdb/src/include/duckdb/storage/statistics/struct_stats.hpp +42 -0
  119. package/src/duckdb/src/include/duckdb/storage/string_uncompressed.hpp +2 -3
  120. package/src/duckdb/src/include/duckdb/storage/table/column_segment.hpp +2 -2
  121. package/src/duckdb/src/include/duckdb/storage/table/list_column_data.hpp +1 -1
  122. package/src/duckdb/src/include/duckdb/storage/table/persistent_table_data.hpp +2 -1
  123. package/src/duckdb/src/include/duckdb/storage/table/row_group.hpp +4 -3
  124. package/src/duckdb/src/include/duckdb/storage/table/row_group_collection.hpp +3 -2
  125. package/src/duckdb/src/include/duckdb/storage/table/scan_state.hpp +2 -0
  126. package/src/duckdb/src/include/duckdb/storage/table/table_statistics.hpp +5 -0
  127. package/src/duckdb/src/include/duckdb.h +49 -1
  128. package/src/duckdb/src/include/duckdb.hpp +0 -1
  129. package/src/duckdb/src/main/capi/pending-c.cpp +16 -3
  130. package/src/duckdb/src/main/capi/result-c.cpp +27 -1
  131. package/src/duckdb/src/main/capi/stream-c.cpp +25 -0
  132. package/src/duckdb/src/main/client_context.cpp +8 -1
  133. package/src/duckdb/src/main/config.cpp +66 -1
  134. package/src/duckdb/src/main/database.cpp +10 -2
  135. package/src/duckdb/src/optimizer/join_order/cardinality_estimator.cpp +98 -67
  136. package/src/duckdb/src/optimizer/join_order/join_order_optimizer.cpp +16 -3
  137. package/src/duckdb/src/optimizer/statistics/expression/propagate_aggregate.cpp +9 -3
  138. package/src/duckdb/src/optimizer/statistics/expression/propagate_and_compress.cpp +6 -7
  139. package/src/duckdb/src/optimizer/statistics/expression/propagate_cast.cpp +14 -11
  140. package/src/duckdb/src/optimizer/statistics/expression/propagate_columnref.cpp +1 -1
  141. package/src/duckdb/src/optimizer/statistics/expression/propagate_comparison.cpp +13 -15
  142. package/src/duckdb/src/optimizer/statistics/expression/propagate_conjunction.cpp +0 -1
  143. package/src/duckdb/src/optimizer/statistics/expression/propagate_constant.cpp +3 -75
  144. package/src/duckdb/src/optimizer/statistics/expression/propagate_function.cpp +7 -2
  145. package/src/duckdb/src/optimizer/statistics/expression/propagate_operator.cpp +10 -0
  146. package/src/duckdb/src/optimizer/statistics/operator/propagate_aggregate.cpp +2 -3
  147. package/src/duckdb/src/optimizer/statistics/operator/propagate_filter.cpp +28 -31
  148. package/src/duckdb/src/optimizer/statistics/operator/propagate_join.cpp +4 -5
  149. package/src/duckdb/src/optimizer/statistics/operator/propagate_set_operation.cpp +3 -3
  150. package/src/duckdb/src/optimizer/statistics_propagator.cpp +1 -1
  151. package/src/duckdb/src/parser/parsed_data/alter_info.cpp +7 -3
  152. package/src/duckdb/src/parser/parsed_data/alter_scalar_function_info.cpp +56 -0
  153. package/src/duckdb/src/parser/parsed_data/alter_table_function_info.cpp +51 -0
  154. package/src/duckdb/src/parser/parsed_data/create_scalar_function_info.cpp +3 -2
  155. package/src/duckdb/src/parser/parsed_data/create_table_function_info.cpp +6 -0
  156. package/src/duckdb/src/parser/parsed_expression_iterator.cpp +8 -0
  157. package/src/duckdb/src/parser/query_node.cpp +1 -1
  158. package/src/duckdb/src/parser/statement/multi_statement.cpp +18 -0
  159. package/src/duckdb/src/parser/tableref/pivotref.cpp +296 -0
  160. package/src/duckdb/src/parser/tableref.cpp +3 -0
  161. package/src/duckdb/src/parser/transform/helpers/transform_alias.cpp +12 -6
  162. package/src/duckdb/src/parser/transform/helpers/transform_cte.cpp +24 -0
  163. package/src/duckdb/src/parser/transform/statement/transform_create_function.cpp +4 -0
  164. package/src/duckdb/src/parser/transform/statement/transform_create_view.cpp +4 -0
  165. package/src/duckdb/src/parser/transform/statement/transform_pivot_stmt.cpp +150 -0
  166. package/src/duckdb/src/parser/transform/statement/transform_select.cpp +8 -0
  167. package/src/duckdb/src/parser/transform/statement/transform_select_node.cpp +1 -1
  168. package/src/duckdb/src/parser/transform/tableref/transform_join.cpp +4 -0
  169. package/src/duckdb/src/parser/transform/tableref/transform_pivot.cpp +105 -0
  170. package/src/duckdb/src/parser/transform/tableref/transform_tableref.cpp +2 -0
  171. package/src/duckdb/src/parser/transformer.cpp +15 -3
  172. package/src/duckdb/src/planner/bind_context.cpp +16 -0
  173. package/src/duckdb/src/planner/binder/query_node/bind_select_node.cpp +11 -3
  174. package/src/duckdb/src/planner/binder/query_node/plan_select_node.cpp +0 -1
  175. package/src/duckdb/src/planner/binder/statement/bind_create.cpp +1 -1
  176. package/src/duckdb/src/planner/binder/statement/bind_logical_plan.cpp +17 -0
  177. package/src/duckdb/src/planner/binder/tableref/bind_joinref.cpp +9 -0
  178. package/src/duckdb/src/planner/binder/tableref/bind_pivot.cpp +365 -0
  179. package/src/duckdb/src/planner/binder.cpp +7 -1
  180. package/src/duckdb/src/planner/bound_result_modifier.cpp +1 -1
  181. package/src/duckdb/src/planner/expression/bound_window_expression.cpp +1 -1
  182. package/src/duckdb/src/planner/filter/constant_filter.cpp +4 -6
  183. package/src/duckdb/src/planner/pragma_handler.cpp +10 -2
  184. package/src/duckdb/src/storage/buffer_manager.cpp +44 -46
  185. package/src/duckdb/src/storage/checkpoint/row_group_writer.cpp +1 -1
  186. package/src/duckdb/src/storage/checkpoint/table_data_reader.cpp +1 -4
  187. package/src/duckdb/src/storage/checkpoint/table_data_writer.cpp +4 -4
  188. package/src/duckdb/src/storage/compression/bitpacking.cpp +28 -24
  189. package/src/duckdb/src/storage/compression/fixed_size_uncompressed.cpp +43 -45
  190. package/src/duckdb/src/storage/compression/numeric_constant.cpp +9 -10
  191. package/src/duckdb/src/storage/compression/patas.cpp +1 -1
  192. package/src/duckdb/src/storage/compression/rle.cpp +19 -15
  193. package/src/duckdb/src/storage/compression/validity_uncompressed.cpp +5 -5
  194. package/src/duckdb/src/storage/data_table.cpp +4 -6
  195. package/src/duckdb/src/storage/statistics/base_statistics.cpp +373 -128
  196. package/src/duckdb/src/storage/statistics/column_statistics.cpp +58 -3
  197. package/src/duckdb/src/storage/statistics/distinct_statistics.cpp +4 -9
  198. package/src/duckdb/src/storage/statistics/list_stats.cpp +117 -0
  199. package/src/duckdb/src/storage/statistics/numeric_stats.cpp +529 -0
  200. package/src/duckdb/src/storage/statistics/segment_statistics.cpp +2 -11
  201. package/src/duckdb/src/storage/statistics/string_stats.cpp +273 -0
  202. package/src/duckdb/src/storage/statistics/struct_stats.cpp +131 -0
  203. package/src/duckdb/src/storage/storage_info.cpp +1 -1
  204. package/src/duckdb/src/storage/table/column_checkpoint_state.cpp +3 -4
  205. package/src/duckdb/src/storage/table/column_data.cpp +16 -11
  206. package/src/duckdb/src/storage/table/column_data_checkpointer.cpp +2 -3
  207. package/src/duckdb/src/storage/table/column_segment.cpp +6 -8
  208. package/src/duckdb/src/storage/table/list_column_data.cpp +39 -58
  209. package/src/duckdb/src/storage/table/row_group.cpp +24 -23
  210. package/src/duckdb/src/storage/table/row_group_collection.cpp +12 -12
  211. package/src/duckdb/src/storage/table/standard_column_data.cpp +6 -6
  212. package/src/duckdb/src/storage/table/struct_column_data.cpp +15 -16
  213. package/src/duckdb/src/storage/table/table_statistics.cpp +27 -7
  214. package/src/duckdb/src/storage/table/update_segment.cpp +10 -12
  215. package/src/duckdb/third_party/libpg_query/include/nodes/nodes.hpp +3 -0
  216. package/src/duckdb/third_party/libpg_query/include/nodes/parsenodes.hpp +34 -1
  217. package/src/duckdb/third_party/libpg_query/include/parser/gram.hpp +1020 -530
  218. package/src/duckdb/third_party/libpg_query/include/parser/kwlist.hpp +7 -0
  219. package/src/duckdb/third_party/libpg_query/src_backend_parser_gram.cpp +23560 -22737
  220. package/src/duckdb/ub_src_function_aggregate_distributive.cpp +2 -0
  221. package/src/duckdb/ub_src_function_scalar_bit.cpp +2 -0
  222. package/src/duckdb/ub_src_function_scalar_map.cpp +4 -0
  223. package/src/duckdb/ub_src_main_capi.cpp +2 -0
  224. package/src/duckdb/ub_src_parser_parsed_data.cpp +4 -2
  225. package/src/duckdb/ub_src_parser_statement.cpp +2 -0
  226. package/src/duckdb/ub_src_parser_tableref.cpp +2 -0
  227. package/src/duckdb/ub_src_parser_transform_statement.cpp +2 -0
  228. package/src/duckdb/ub_src_parser_transform_tableref.cpp +2 -0
  229. package/src/duckdb/ub_src_planner_binder_tableref.cpp +2 -0
  230. package/src/duckdb/ub_src_storage_statistics.cpp +4 -6
  231. package/src/duckdb/src/include/duckdb/main/loadable_extension.hpp +0 -59
  232. package/src/duckdb/src/include/duckdb/storage/statistics/list_statistics.hpp +0 -36
  233. package/src/duckdb/src/include/duckdb/storage/statistics/numeric_statistics.hpp +0 -75
  234. package/src/duckdb/src/include/duckdb/storage/statistics/string_statistics.hpp +0 -49
  235. package/src/duckdb/src/include/duckdb/storage/statistics/struct_statistics.hpp +0 -36
  236. package/src/duckdb/src/include/duckdb/storage/statistics/validity_statistics.hpp +0 -45
  237. package/src/duckdb/src/parser/parsed_data/alter_function_info.cpp +0 -55
  238. package/src/duckdb/src/storage/statistics/list_statistics.cpp +0 -94
  239. package/src/duckdb/src/storage/statistics/numeric_statistics.cpp +0 -307
  240. package/src/duckdb/src/storage/statistics/string_statistics.cpp +0 -220
  241. package/src/duckdb/src/storage/statistics/struct_statistics.cpp +0 -108
  242. package/src/duckdb/src/storage/statistics/validity_statistics.cpp +0 -91
@@ -8,7 +8,6 @@
8
8
  #include "duckdb/common/types/value.hpp"
9
9
  #include "duckdb/common/string_util.hpp"
10
10
  #include "duckdb/execution/expression_executor.hpp"
11
- #include "duckdb/storage/statistics/numeric_statistics.hpp"
12
11
 
13
12
  namespace duckdb {
14
13
 
@@ -588,18 +587,15 @@ static void DateTruncFunction(DataChunk &args, ExpressionState &state, Vector &r
588
587
  }
589
588
 
590
589
  template <class TA, class TR, class OP>
591
- static unique_ptr<BaseStatistics> DateTruncStatistics(vector<unique_ptr<BaseStatistics>> &child_stats) {
590
+ static unique_ptr<BaseStatistics> DateTruncStatistics(vector<BaseStatistics> &child_stats) {
592
591
  // we can only propagate date stats if the child has stats
593
- if (!child_stats[1]) {
594
- return nullptr;
595
- }
596
- auto &nstats = (NumericStatistics &)*child_stats[1];
597
- if (nstats.min.IsNull() || nstats.max.IsNull()) {
592
+ auto &nstats = child_stats[1];
593
+ if (!NumericStats::HasMinMax(nstats)) {
598
594
  return nullptr;
599
595
  }
600
596
  // run the operator on both the min and the max, this gives us the [min, max] bound
601
- auto min = nstats.min.GetValueUnsafe<TA>();
602
- auto max = nstats.max.GetValueUnsafe<TA>();
597
+ auto min = NumericStats::GetMinUnsafe<TA>(nstats);
598
+ auto max = NumericStats::GetMaxUnsafe<TA>(nstats);
603
599
  if (min > max) {
604
600
  return nullptr;
605
601
  }
@@ -610,11 +606,11 @@ static unique_ptr<BaseStatistics> DateTruncStatistics(vector<unique_ptr<BaseStat
610
606
 
611
607
  auto min_value = Value::CreateValue(min_part);
612
608
  auto max_value = Value::CreateValue(max_part);
613
- auto result = make_unique<NumericStatistics>(min_value.type(), min_value, max_value, StatisticsType::LOCAL_STATS);
614
- if (child_stats[0]->validity_stats) {
615
- result->validity_stats = child_stats[1]->validity_stats->Copy();
616
- }
617
- return std::move(result);
609
+ auto result = NumericStats::CreateEmpty(min_value.type());
610
+ NumericStats::SetMin(result, min_value);
611
+ NumericStats::SetMax(result, max_value);
612
+ result.CopyValidity(child_stats[0]);
613
+ return result.ToUnique();
618
614
  }
619
615
 
620
616
  template <class TA, class TR, class OP>
@@ -38,10 +38,8 @@ unique_ptr<FunctionData> StatsBind(ClientContext &context, ScalarFunction &bound
38
38
  static unique_ptr<BaseStatistics> StatsPropagateStats(ClientContext &context, FunctionStatisticsInput &input) {
39
39
  auto &child_stats = input.child_stats;
40
40
  auto &bind_data = input.bind_data;
41
- if (child_stats[0]) {
42
- auto &info = (StatsBindData &)*bind_data;
43
- info.stats = child_stats[0]->ToString();
44
- }
41
+ auto &info = (StatsBindData &)*bind_data;
42
+ info.stats = child_stats[0].ToString();
45
43
  return nullptr;
46
44
  }
47
45
 
@@ -1,7 +1,7 @@
1
1
  #include "duckdb/common/types/data_chunk.hpp"
2
2
  #include "duckdb/function/scalar/nested_functions.hpp"
3
3
  #include "duckdb/planner/expression/bound_function_expression.hpp"
4
- #include "duckdb/storage/statistics/list_statistics.hpp"
4
+ #include "duckdb/storage/statistics/list_stats.hpp"
5
5
 
6
6
  namespace duckdb {
7
7
 
@@ -121,17 +121,10 @@ static unique_ptr<FunctionData> ListFlattenBind(ClientContext &context, ScalarFu
121
121
 
122
122
  static unique_ptr<BaseStatistics> ListFlattenStats(ClientContext &context, FunctionStatisticsInput &input) {
123
123
  auto &child_stats = input.child_stats;
124
- if (!child_stats[0]) {
125
- return nullptr;
126
- }
127
- auto &list_stats = (ListStatistics &)*child_stats[0];
128
- if (!list_stats.child_stats || list_stats.child_stats->type == LogicalTypeId::SQLNULL) {
129
- return nullptr;
130
- }
131
-
132
- auto child_copy = list_stats.child_stats->Copy();
133
- child_copy->validity_stats = make_unique<ValidityStatistics>(true);
134
- return child_copy;
124
+ auto &list_child_stats = ListStats::GetChildStats(child_stats[0]);
125
+ auto child_copy = list_child_stats.Copy();
126
+ child_copy.Set(StatsInfo::CAN_HAVE_NULL_VALUES);
127
+ return child_copy.ToUnique();
135
128
  }
136
129
 
137
130
  void ListFlattenFun::RegisterFunction(BuiltinFunctions &set) {
@@ -3,8 +3,6 @@
3
3
  #include "duckdb/planner/expression/bound_function_expression.hpp"
4
4
  #include "duckdb/planner/expression/bound_parameter_expression.hpp"
5
5
  #include "duckdb/planner/expression_binder.hpp"
6
- #include "duckdb/storage/statistics/list_statistics.hpp"
7
- #include "duckdb/storage/statistics/validity_statistics.hpp"
8
6
 
9
7
  namespace duckdb {
10
8
 
@@ -108,14 +106,11 @@ static unique_ptr<FunctionData> ListConcatBind(ClientContext &context, ScalarFun
108
106
  static unique_ptr<BaseStatistics> ListConcatStats(ClientContext &context, FunctionStatisticsInput &input) {
109
107
  auto &child_stats = input.child_stats;
110
108
  D_ASSERT(child_stats.size() == 2);
111
- if (!child_stats[0] || !child_stats[1]) {
112
- return nullptr;
113
- }
114
109
 
115
- auto &left_stats = (ListStatistics &)*child_stats[0];
116
- auto &right_stats = (ListStatistics &)*child_stats[1];
110
+ auto &left_stats = child_stats[0];
111
+ auto &right_stats = child_stats[1];
117
112
 
118
- auto stats = left_stats.Copy();
113
+ auto stats = left_stats.ToUnique();
119
114
  stats->Merge(right_stats);
120
115
 
121
116
  return stats;
@@ -7,8 +7,7 @@
7
7
  #include "duckdb/function/scalar/string_functions.hpp"
8
8
  #include "duckdb/parser/expression/bound_expression.hpp"
9
9
  #include "duckdb/planner/expression/bound_function_expression.hpp"
10
- #include "duckdb/storage/statistics/list_statistics.hpp"
11
- #include "duckdb/storage/statistics/validity_statistics.hpp"
10
+ #include "duckdb/storage/statistics/list_stats.hpp"
12
11
 
13
12
  namespace duckdb {
14
13
 
@@ -212,17 +211,11 @@ static unique_ptr<FunctionData> ListExtractBind(ClientContext &context, ScalarFu
212
211
 
213
212
  static unique_ptr<BaseStatistics> ListExtractStats(ClientContext &context, FunctionStatisticsInput &input) {
214
213
  auto &child_stats = input.child_stats;
215
- if (!child_stats[0]) {
216
- return nullptr;
217
- }
218
- auto &list_stats = (ListStatistics &)*child_stats[0];
219
- if (!list_stats.child_stats) {
220
- return nullptr;
221
- }
222
- auto child_copy = list_stats.child_stats->Copy();
214
+ auto &list_child_stats = ListStats::GetChildStats(child_stats[0]);
215
+ auto child_copy = list_child_stats.Copy();
223
216
  // list_extract always pushes a NULL, since if the offset is out of range for a list it inserts a null
224
- child_copy->validity_stats = make_unique<ValidityStatistics>(true);
225
- return child_copy;
217
+ child_copy.Set(StatsInfo::CAN_HAVE_NULL_VALUES);
218
+ return child_copy.ToUnique();
226
219
  }
227
220
 
228
221
  void ListExtractFun::RegisterFunction(BuiltinFunctions &set) {
@@ -4,7 +4,7 @@
4
4
  #include "duckdb/function/scalar/nested_functions.hpp"
5
5
  #include "duckdb/common/types/data_chunk.hpp"
6
6
  #include "duckdb/common/pair.hpp"
7
- #include "duckdb/storage/statistics/list_statistics.hpp"
7
+ #include "duckdb/storage/statistics/list_stats.hpp"
8
8
  #include "duckdb/planner/expression_binder.hpp"
9
9
 
10
10
  namespace duckdb {
@@ -49,16 +49,12 @@ static unique_ptr<FunctionData> ListValueBind(ClientContext &context, ScalarFunc
49
49
  unique_ptr<BaseStatistics> ListValueStats(ClientContext &context, FunctionStatisticsInput &input) {
50
50
  auto &child_stats = input.child_stats;
51
51
  auto &expr = input.expr;
52
- auto list_stats = make_unique<ListStatistics>(expr.return_type);
52
+ auto list_stats = ListStats::CreateEmpty(expr.return_type);
53
+ auto &list_child_stats = ListStats::GetChildStats(list_stats);
53
54
  for (idx_t i = 0; i < child_stats.size(); i++) {
54
- if (child_stats[i]) {
55
- list_stats->child_stats->Merge(*child_stats[i]);
56
- } else {
57
- list_stats->child_stats.reset();
58
- return std::move(list_stats);
59
- }
55
+ list_child_stats.Merge(child_stats[i]);
60
56
  }
61
- return std::move(list_stats);
57
+ return list_stats.ToUnique();
62
58
  }
63
59
 
64
60
  void ListValueFun::RegisterFunction(BuiltinFunctions &set) {
@@ -0,0 +1,61 @@
1
+ #include "duckdb/planner/expression/bound_function_expression.hpp"
2
+ #include "duckdb/common/string_util.hpp"
3
+ #include "duckdb/parser/expression/bound_expression.hpp"
4
+ #include "duckdb/function/scalar/nested_functions.hpp"
5
+ #include "duckdb/common/types/data_chunk.hpp"
6
+ #include "duckdb/common/pair.hpp"
7
+
8
+ namespace duckdb {
9
+
10
+ // Reverse of map_from_entries
11
+ static void MapEntriesFunction(DataChunk &args, ExpressionState &state, Vector &result) {
12
+ idx_t count = args.size();
13
+
14
+ result.Reinterpret(args.data[0]);
15
+
16
+ if (args.AllConstant()) {
17
+ result.SetVectorType(VectorType::CONSTANT_VECTOR);
18
+ }
19
+ result.Verify(count);
20
+ }
21
+
22
+ static unique_ptr<FunctionData> MapEntriesBind(ClientContext &context, ScalarFunction &bound_function,
23
+ vector<unique_ptr<Expression>> &arguments) {
24
+ child_list_t<LogicalType> child_types;
25
+
26
+ if (arguments.size() != 1) {
27
+ throw InvalidInputException("Too many arguments provided, only expecting a single map");
28
+ }
29
+ auto &map = arguments[0]->return_type;
30
+
31
+ if (map.id() == LogicalTypeId::UNKNOWN) {
32
+ // Prepared statement
33
+ bound_function.arguments.emplace_back(LogicalTypeId::UNKNOWN);
34
+ bound_function.return_type = LogicalType(LogicalTypeId::SQLNULL);
35
+ return nullptr;
36
+ }
37
+
38
+ if (map.id() != LogicalTypeId::MAP) {
39
+ throw InvalidInputException("The provided argument is not a map");
40
+ }
41
+ auto &key_type = MapType::KeyType(map);
42
+ auto &value_type = MapType::ValueType(map);
43
+
44
+ child_types.push_back(make_pair("k", key_type));
45
+ child_types.push_back(make_pair("v", value_type));
46
+
47
+ auto row_type = LogicalType::STRUCT(std::move(child_types));
48
+
49
+ bound_function.return_type = LogicalType::LIST(row_type);
50
+ return make_unique<VariableReturnBindData>(bound_function.return_type);
51
+ }
52
+
53
+ void MapEntriesFun::RegisterFunction(BuiltinFunctions &set) {
54
+ //! the arguments and return types are actually set in the binder function
55
+ ScalarFunction fun("map_entries", {}, LogicalTypeId::LIST, MapEntriesFunction, MapEntriesBind);
56
+ fun.null_handling = FunctionNullHandling::DEFAULT_NULL_HANDLING;
57
+ fun.varargs = LogicalType::ANY;
58
+ set.AddFunction(fun);
59
+ }
60
+
61
+ } // namespace duckdb
@@ -0,0 +1,97 @@
1
+ #include "duckdb/planner/expression/bound_function_expression.hpp"
2
+ #include "duckdb/common/string_util.hpp"
3
+ #include "duckdb/parser/expression/bound_expression.hpp"
4
+ #include "duckdb/function/scalar/nested_functions.hpp"
5
+ #include "duckdb/common/types/data_chunk.hpp"
6
+ #include "duckdb/common/pair.hpp"
7
+
8
+ namespace duckdb {
9
+
10
+ static void MapKeyValueFunction(DataChunk &args, ExpressionState &state, Vector &result,
11
+ Vector &(*get_child_vector)(Vector &)) {
12
+ D_ASSERT(result.GetType().id() == LogicalTypeId::LIST);
13
+ auto count = args.size();
14
+
15
+ auto &map = args.data[0];
16
+ D_ASSERT(map.GetType().id() == LogicalTypeId::MAP);
17
+ auto child = get_child_vector(map);
18
+
19
+ auto &entries = ListVector::GetEntry(result);
20
+ entries.Reference(child);
21
+
22
+ UnifiedVectorFormat map_data;
23
+ map.ToUnifiedFormat(count, map_data);
24
+
25
+ D_ASSERT(result.GetVectorType() == VectorType::FLAT_VECTOR);
26
+ FlatVector::SetData(result, map_data.data);
27
+ FlatVector::SetValidity(result, map_data.validity);
28
+ auto list_size = ListVector::GetListSize(map);
29
+ ListVector::SetListSize(result, list_size);
30
+ if (map.GetVectorType() == VectorType::DICTIONARY_VECTOR) {
31
+ result.Slice(*map_data.sel, count);
32
+ }
33
+ if (args.AllConstant()) {
34
+ result.SetVectorType(VectorType::CONSTANT_VECTOR);
35
+ }
36
+ result.Verify(count);
37
+ }
38
+
39
+ static void MapKeysFunction(DataChunk &args, ExpressionState &state, Vector &result) {
40
+ MapKeyValueFunction(args, state, result, MapVector::GetKeys);
41
+ }
42
+
43
+ static void MapValuesFunction(DataChunk &args, ExpressionState &state, Vector &result) {
44
+ MapKeyValueFunction(args, state, result, MapVector::GetValues);
45
+ }
46
+
47
+ static unique_ptr<FunctionData> MapKeyValueBind(ClientContext &context, ScalarFunction &bound_function,
48
+ vector<unique_ptr<Expression>> &arguments,
49
+ const LogicalType &(*type_func)(const LogicalType &)) {
50
+ if (arguments.size() != 1) {
51
+ throw InvalidInputException("Too many arguments provided, only expecting a single map");
52
+ }
53
+ auto &map = arguments[0]->return_type;
54
+
55
+ if (map.id() == LogicalTypeId::UNKNOWN) {
56
+ // Prepared statement
57
+ bound_function.arguments.emplace_back(LogicalTypeId::UNKNOWN);
58
+ bound_function.return_type = LogicalType(LogicalTypeId::SQLNULL);
59
+ return nullptr;
60
+ }
61
+
62
+ if (map.id() != LogicalTypeId::MAP) {
63
+ throw InvalidInputException("The provided argument is not a map");
64
+ }
65
+
66
+ auto &type = type_func(map);
67
+
68
+ bound_function.return_type = LogicalType::LIST(type);
69
+ return make_unique<VariableReturnBindData>(bound_function.return_type);
70
+ }
71
+
72
+ static unique_ptr<FunctionData> MapKeysBind(ClientContext &context, ScalarFunction &bound_function,
73
+ vector<unique_ptr<Expression>> &arguments) {
74
+ return MapKeyValueBind(context, bound_function, arguments, MapType::KeyType);
75
+ }
76
+
77
+ static unique_ptr<FunctionData> MapValuesBind(ClientContext &context, ScalarFunction &bound_function,
78
+ vector<unique_ptr<Expression>> &arguments) {
79
+ return MapKeyValueBind(context, bound_function, arguments, MapType::ValueType);
80
+ }
81
+
82
+ void MapKeysFun::RegisterFunction(BuiltinFunctions &set) {
83
+ //! the arguments and return types are actually set in the binder function
84
+ ScalarFunction fun("map_keys", {}, LogicalTypeId::LIST, MapKeysFunction, MapKeysBind);
85
+ fun.null_handling = FunctionNullHandling::DEFAULT_NULL_HANDLING;
86
+ fun.varargs = LogicalType::ANY;
87
+ set.AddFunction(fun);
88
+ }
89
+
90
+ void MapValuesFun::RegisterFunction(BuiltinFunctions &set) {
91
+ ScalarFunction fun("map_values", {}, LogicalTypeId::LIST, MapValuesFunction, MapValuesBind);
92
+ fun.null_handling = FunctionNullHandling::DEFAULT_NULL_HANDLING;
93
+ fun.varargs = LogicalType::ANY;
94
+ set.AddFunction(fun);
95
+ }
96
+
97
+ } // namespace duckdb
@@ -8,7 +8,6 @@
8
8
  #include "duckdb/common/algorithm.hpp"
9
9
  #include "duckdb/execution/expression_executor.hpp"
10
10
  #include "duckdb/common/likely.hpp"
11
- #include "duckdb/storage/statistics/numeric_statistics.hpp"
12
11
  #include "duckdb/common/types/bit.hpp"
13
12
  #include <cmath>
14
13
  #include <errno.h>
@@ -77,25 +76,22 @@ static unique_ptr<BaseStatistics> PropagateAbsStats(ClientContext &context, Func
77
76
  auto &expr = input.expr;
78
77
  D_ASSERT(child_stats.size() == 1);
79
78
  // can only propagate stats if the children have stats
80
- if (!child_stats[0]) {
81
- return nullptr;
82
- }
83
- auto &lstats = (NumericStatistics &)*child_stats[0];
79
+ auto &lstats = child_stats[0];
84
80
  Value new_min, new_max;
85
81
  bool potential_overflow = true;
86
- if (!lstats.min.IsNull() && !lstats.max.IsNull()) {
82
+ if (NumericStats::HasMinMax(lstats)) {
87
83
  switch (expr.return_type.InternalType()) {
88
84
  case PhysicalType::INT8:
89
- potential_overflow = lstats.min.GetValue<int8_t>() == NumericLimits<int8_t>::Minimum();
85
+ potential_overflow = NumericStats::Min(lstats).GetValue<int8_t>() == NumericLimits<int8_t>::Minimum();
90
86
  break;
91
87
  case PhysicalType::INT16:
92
- potential_overflow = lstats.min.GetValue<int16_t>() == NumericLimits<int16_t>::Minimum();
88
+ potential_overflow = NumericStats::Min(lstats).GetValue<int16_t>() == NumericLimits<int16_t>::Minimum();
93
89
  break;
94
90
  case PhysicalType::INT32:
95
- potential_overflow = lstats.min.GetValue<int32_t>() == NumericLimits<int32_t>::Minimum();
91
+ potential_overflow = NumericStats::Min(lstats).GetValue<int32_t>() == NumericLimits<int32_t>::Minimum();
96
92
  break;
97
93
  case PhysicalType::INT64:
98
- potential_overflow = lstats.min.GetValue<int64_t>() == NumericLimits<int64_t>::Minimum();
94
+ potential_overflow = NumericStats::Min(lstats).GetValue<int64_t>() == NumericLimits<int64_t>::Minimum();
99
95
  break;
100
96
  default:
101
97
  return nullptr;
@@ -108,8 +104,8 @@ static unique_ptr<BaseStatistics> PropagateAbsStats(ClientContext &context, Func
108
104
  // no potential overflow
109
105
 
110
106
  // compute stats
111
- auto current_min = lstats.min.GetValue<int64_t>();
112
- auto current_max = lstats.max.GetValue<int64_t>();
107
+ auto current_min = NumericStats::Min(lstats).GetValue<int64_t>();
108
+ auto current_max = NumericStats::Max(lstats).GetValue<int64_t>();
113
109
 
114
110
  int64_t min_val, max_val;
115
111
 
@@ -125,16 +121,17 @@ static unique_ptr<BaseStatistics> PropagateAbsStats(ClientContext &context, Func
125
121
  } else {
126
122
  // if both current_min and current_max are > 0, then the abs is a no-op and can be removed entirely
127
123
  *input.expr_ptr = std::move(input.expr.children[0]);
128
- return std::move(child_stats[0]);
124
+ return child_stats[0].ToUnique();
129
125
  }
130
126
  new_min = Value::Numeric(expr.return_type, min_val);
131
127
  new_max = Value::Numeric(expr.return_type, max_val);
132
128
  expr.function.function = ScalarFunction::GetScalarUnaryFunction<AbsOperator>(expr.return_type);
133
129
  }
134
- auto stats = make_unique<NumericStatistics>(expr.return_type, std::move(new_min), std::move(new_max),
135
- StatisticsType::LOCAL_STATS);
136
- stats->validity_stats = lstats.validity_stats->Copy();
137
- return std::move(stats);
130
+ auto stats = NumericStats::CreateEmpty(expr.return_type);
131
+ NumericStats::SetMin(stats, new_min);
132
+ NumericStats::SetMax(stats, new_max);
133
+ stats.CopyValidity(lstats);
134
+ return stats.ToUnique();
138
135
  }
139
136
 
140
137
  template <class OP>
@@ -22,6 +22,9 @@ void BuiltinFunctions::RegisterNestedFunctions() {
22
22
  Register<ListFlattenFun>();
23
23
  Register<MapFun>();
24
24
  Register<MapFromEntriesFun>();
25
+ Register<MapEntriesFun>();
26
+ Register<MapValuesFun>();
27
+ Register<MapKeysFun>();
25
28
  Register<MapExtractFun>();
26
29
  Register<UnionValueFun>();
27
30
  Register<UnionExtractFun>();
@@ -7,9 +7,6 @@
7
7
  #include "duckdb/common/types/interval.hpp"
8
8
  #include "duckdb/common/types/timestamp.hpp"
9
9
  #include "duckdb/common/types/hugeint.hpp"
10
- #include "duckdb/common/windows_undefs.hpp"
11
-
12
- #include <limits>
13
10
 
14
11
  namespace duckdb {
15
12
 
@@ -19,18 +16,12 @@ namespace duckdb {
19
16
  template <>
20
17
  float AddOperator::Operation(float left, float right) {
21
18
  auto result = left + right;
22
- if (!Value::FloatIsFinite(result)) {
23
- throw OutOfRangeException("Overflow in addition of float!");
24
- }
25
19
  return result;
26
20
  }
27
21
 
28
22
  template <>
29
23
  double AddOperator::Operation(double left, double right) {
30
24
  auto result = left + right;
31
- if (!Value::DoubleIsFinite(result)) {
32
- throw OutOfRangeException("Overflow in addition of double!");
33
- }
34
25
  return result;
35
26
  }
36
27
 
@@ -12,7 +12,6 @@
12
12
  #include "duckdb/common/vector_operations/vector_operations.hpp"
13
13
  #include "duckdb/function/scalar/operators.hpp"
14
14
  #include "duckdb/planner/expression/bound_function_expression.hpp"
15
- #include "duckdb/storage/statistics/numeric_statistics.hpp"
16
15
  #include "duckdb/function/scalar/nested_functions.hpp"
17
16
 
18
17
  #include <limits>
@@ -78,15 +77,15 @@ static scalar_function_t GetScalarBinaryFunction(PhysicalType type) {
78
77
  //===--------------------------------------------------------------------===//
79
78
  struct AddPropagateStatistics {
80
79
  template <class T, class OP>
81
- static bool Operation(LogicalType type, NumericStatistics &lstats, NumericStatistics &rstats, Value &new_min,
80
+ static bool Operation(LogicalType type, BaseStatistics &lstats, BaseStatistics &rstats, Value &new_min,
82
81
  Value &new_max) {
83
82
  T min, max;
84
83
  // new min is min+min
85
- if (!OP::Operation(lstats.min.GetValueUnsafe<T>(), rstats.min.GetValueUnsafe<T>(), min)) {
84
+ if (!OP::Operation(NumericStats::GetMinUnsafe<T>(lstats), NumericStats::GetMinUnsafe<T>(rstats), min)) {
86
85
  return true;
87
86
  }
88
87
  // new max is max+max
89
- if (!OP::Operation(lstats.max.GetValueUnsafe<T>(), rstats.max.GetValueUnsafe<T>(), max)) {
88
+ if (!OP::Operation(NumericStats::GetMaxUnsafe<T>(lstats), NumericStats::GetMaxUnsafe<T>(rstats), max)) {
90
89
  return true;
91
90
  }
92
91
  new_min = Value::Numeric(type, min);
@@ -97,13 +96,13 @@ struct AddPropagateStatistics {
97
96
 
98
97
  struct SubtractPropagateStatistics {
99
98
  template <class T, class OP>
100
- static bool Operation(LogicalType type, NumericStatistics &lstats, NumericStatistics &rstats, Value &new_min,
99
+ static bool Operation(LogicalType type, BaseStatistics &lstats, BaseStatistics &rstats, Value &new_min,
101
100
  Value &new_max) {
102
101
  T min, max;
103
- if (!OP::Operation(lstats.min.GetValueUnsafe<T>(), rstats.max.GetValueUnsafe<T>(), min)) {
102
+ if (!OP::Operation(NumericStats::GetMinUnsafe<T>(lstats), NumericStats::GetMaxUnsafe<T>(rstats), min)) {
104
103
  return true;
105
104
  }
106
- if (!OP::Operation(lstats.max.GetValueUnsafe<T>(), rstats.min.GetValueUnsafe<T>(), max)) {
105
+ if (!OP::Operation(NumericStats::GetMaxUnsafe<T>(lstats), NumericStats::GetMinUnsafe<T>(rstats), max)) {
107
106
  return true;
108
107
  }
109
108
  new_min = Value::Numeric(type, min);
@@ -136,14 +135,11 @@ static unique_ptr<BaseStatistics> PropagateNumericStats(ClientContext &context,
136
135
  auto &expr = input.expr;
137
136
  D_ASSERT(child_stats.size() == 2);
138
137
  // can only propagate stats if the children have stats
139
- if (!child_stats[0] || !child_stats[1]) {
140
- return nullptr;
141
- }
142
- auto &lstats = (NumericStatistics &)*child_stats[0];
143
- auto &rstats = (NumericStatistics &)*child_stats[1];
138
+ auto &lstats = child_stats[0];
139
+ auto &rstats = child_stats[1];
144
140
  Value new_min, new_max;
145
141
  bool potential_overflow = true;
146
- if (!lstats.min.IsNull() && !lstats.max.IsNull() && !rstats.min.IsNull() && !rstats.max.IsNull()) {
142
+ if (NumericStats::HasMinMax(lstats) && NumericStats::HasMinMax(rstats)) {
147
143
  switch (expr.return_type.InternalType()) {
148
144
  case PhysicalType::INT8:
149
145
  potential_overflow =
@@ -176,10 +172,11 @@ static unique_ptr<BaseStatistics> PropagateNumericStats(ClientContext &context,
176
172
  }
177
173
  expr.function.function = GetScalarIntegerFunction<BASEOP>(expr.return_type.InternalType());
178
174
  }
179
- auto stats = make_unique<NumericStatistics>(expr.return_type, std::move(new_min), std::move(new_max),
180
- StatisticsType::LOCAL_STATS);
181
- stats->validity_stats = ValidityStatistics::Combine(lstats.validity_stats, rstats.validity_stats);
182
- return std::move(stats);
175
+ auto result = NumericStats::CreateEmpty(expr.return_type);
176
+ NumericStats::SetMin(result, new_min);
177
+ NumericStats::SetMax(result, new_max);
178
+ result.CombineValidity(lstats, rstats);
179
+ return result.ToUnique();
183
180
  }
184
181
 
185
182
  template <class OP, class OPOVERFLOWCHECK, bool IS_SUBTRACT = false>
@@ -431,12 +428,12 @@ struct NegateOperator {
431
428
 
432
429
  template <>
433
430
  bool NegateOperator::CanNegate(float input) {
434
- return Value::FloatIsFinite(input);
431
+ return true;
435
432
  }
436
433
 
437
434
  template <>
438
435
  bool NegateOperator::CanNegate(double input) {
439
- return Value::DoubleIsFinite(input);
436
+ return true;
440
437
  }
441
438
 
442
439
  template <>
@@ -491,9 +488,9 @@ unique_ptr<FunctionData> DecimalNegateBind(ClientContext &context, ScalarFunctio
491
488
 
492
489
  struct NegatePropagateStatistics {
493
490
  template <class T>
494
- static bool Operation(LogicalType type, NumericStatistics &istats, Value &new_min, Value &new_max) {
495
- auto max_value = istats.max.GetValueUnsafe<T>();
496
- auto min_value = istats.min.GetValueUnsafe<T>();
491
+ static bool Operation(LogicalType type, BaseStatistics &istats, Value &new_min, Value &new_max) {
492
+ auto max_value = NumericStats::GetMaxUnsafe<T>(istats);
493
+ auto min_value = NumericStats::GetMinUnsafe<T>(istats);
497
494
  if (!NegateOperator::CanNegate<T>(min_value) || !NegateOperator::CanNegate<T>(max_value)) {
498
495
  return true;
499
496
  }
@@ -510,13 +507,10 @@ static unique_ptr<BaseStatistics> NegateBindStatistics(ClientContext &context, F
510
507
  auto &expr = input.expr;
511
508
  D_ASSERT(child_stats.size() == 1);
512
509
  // can only propagate stats if the children have stats
513
- if (!child_stats[0]) {
514
- return nullptr;
515
- }
516
- auto &istats = (NumericStatistics &)*child_stats[0];
510
+ auto &istats = child_stats[0];
517
511
  Value new_min, new_max;
518
512
  bool potential_overflow = true;
519
- if (!istats.min.IsNull() && !istats.max.IsNull()) {
513
+ if (NumericStats::HasMinMax(istats)) {
520
514
  switch (expr.return_type.InternalType()) {
521
515
  case PhysicalType::INT8:
522
516
  potential_overflow =
@@ -542,12 +536,11 @@ static unique_ptr<BaseStatistics> NegateBindStatistics(ClientContext &context, F
542
536
  new_min = Value(expr.return_type);
543
537
  new_max = Value(expr.return_type);
544
538
  }
545
- auto stats = make_unique<NumericStatistics>(expr.return_type, std::move(new_min), std::move(new_max),
546
- StatisticsType::LOCAL_STATS);
547
- if (istats.validity_stats) {
548
- stats->validity_stats = istats.validity_stats->Copy();
549
- }
550
- return std::move(stats);
539
+ auto stats = NumericStats::CreateEmpty(expr.return_type);
540
+ NumericStats::SetMin(stats, new_min);
541
+ NumericStats::SetMax(stats, new_max);
542
+ stats.CopyValidity(istats);
543
+ return stats.ToUnique();
551
544
  }
552
545
 
553
546
  ScalarFunction SubtractFun::GetFunction(const LogicalType &type) {
@@ -662,7 +655,7 @@ void SubtractFun::RegisterFunction(BuiltinFunctions &set) {
662
655
  //===--------------------------------------------------------------------===//
663
656
  struct MultiplyPropagateStatistics {
664
657
  template <class T, class OP>
665
- static bool Operation(LogicalType type, NumericStatistics &lstats, NumericStatistics &rstats, Value &new_min,
658
+ static bool Operation(LogicalType type, BaseStatistics &lstats, BaseStatistics &rstats, Value &new_min,
666
659
  Value &new_max) {
667
660
  // statistics propagation on the multiplication is slightly less straightforward because of negative numbers
668
661
  // the new min/max depend on the signs of the input types
@@ -671,8 +664,8 @@ struct MultiplyPropagateStatistics {
671
664
  // etc
672
665
  // rather than doing all this switcheroo we just multiply all combinations of lmin/lmax with rmin/rmax
673
666
  // and check what the minimum/maximum value is
674
- T lvals[] {lstats.min.GetValueUnsafe<T>(), lstats.max.GetValueUnsafe<T>()};
675
- T rvals[] {rstats.min.GetValueUnsafe<T>(), rstats.max.GetValueUnsafe<T>()};
667
+ T lvals[] {NumericStats::GetMinUnsafe<T>(lstats), NumericStats::GetMaxUnsafe<T>(lstats)};
668
+ T rvals[] {NumericStats::GetMinUnsafe<T>(rstats), NumericStats::GetMaxUnsafe<T>(rstats)};
676
669
  T min = NumericLimits<T>::Maximum();
677
670
  T max = NumericLimits<T>::Minimum();
678
671
  // multiplications
@@ -803,18 +796,12 @@ void MultiplyFun::RegisterFunction(BuiltinFunctions &set) {
803
796
  template <>
804
797
  float DivideOperator::Operation(float left, float right) {
805
798
  auto result = left / right;
806
- if (!Value::FloatIsFinite(result)) {
807
- throw OutOfRangeException("Overflow in division of float!");
808
- }
809
799
  return result;
810
800
  }
811
801
 
812
802
  template <>
813
803
  double DivideOperator::Operation(double left, double right) {
814
804
  auto result = left / right;
815
- if (!Value::DoubleIsFinite(result)) {
816
- throw OutOfRangeException("Overflow in division of double!");
817
- }
818
805
  return result;
819
806
  }
820
807
 
@@ -946,9 +933,6 @@ template <>
946
933
  float ModuloOperator::Operation(float left, float right) {
947
934
  D_ASSERT(right != 0);
948
935
  auto result = std::fmod(left, right);
949
- if (!Value::FloatIsFinite(result)) {
950
- throw OutOfRangeException("Overflow in modulo of float!");
951
- }
952
936
  return result;
953
937
  }
954
938
 
@@ -956,9 +940,6 @@ template <>
956
940
  double ModuloOperator::Operation(double left, double right) {
957
941
  D_ASSERT(right != 0);
958
942
  auto result = std::fmod(left, right);
959
- if (!Value::DoubleIsFinite(result)) {
960
- throw OutOfRangeException("Overflow in modulo of double!");
961
- }
962
943
  return result;
963
944
  }
964
945