duckdb 0.7.2-dev2507.0 → 0.7.2-dev2675.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 (254) hide show
  1. package/binding.gyp +7 -7
  2. package/package.json +2 -2
  3. package/src/connection.cpp +1 -1
  4. package/src/duckdb/extension/icu/icu-dateadd.cpp +3 -3
  5. package/src/duckdb/extension/icu/icu-datepart.cpp +3 -3
  6. package/src/duckdb/extension/icu/icu-datesub.cpp +2 -2
  7. package/src/duckdb/extension/icu/icu-datetrunc.cpp +1 -1
  8. package/src/duckdb/extension/icu/icu-extension.cpp +3 -3
  9. package/src/duckdb/extension/icu/icu-list-range.cpp +2 -2
  10. package/src/duckdb/extension/icu/icu-makedate.cpp +1 -1
  11. package/src/duckdb/extension/icu/icu-strptime.cpp +4 -4
  12. package/src/duckdb/extension/icu/icu-table-range.cpp +2 -2
  13. package/src/duckdb/extension/icu/icu-timebucket.cpp +1 -1
  14. package/src/duckdb/extension/icu/icu-timezone.cpp +4 -4
  15. package/src/duckdb/extension/json/json-extension.cpp +6 -6
  16. package/src/duckdb/extension/parquet/parquet-extension.cpp +9 -8
  17. package/src/duckdb/extension/parquet/parquet_statistics.cpp +3 -0
  18. package/src/duckdb/src/catalog/catalog.cpp +166 -127
  19. package/src/duckdb/src/catalog/catalog_entry/copy_function_catalog_entry.cpp +3 -3
  20. package/src/duckdb/src/catalog/catalog_entry/duck_index_entry.cpp +1 -1
  21. package/src/duckdb/src/catalog/catalog_entry/duck_schema_entry.cpp +90 -82
  22. package/src/duckdb/src/catalog/catalog_entry/duck_table_entry.cpp +65 -67
  23. package/src/duckdb/src/catalog/catalog_entry/index_catalog_entry.cpp +3 -3
  24. package/src/duckdb/src/catalog/catalog_entry/pragma_function_catalog_entry.cpp +4 -4
  25. package/src/duckdb/src/catalog/catalog_entry/scalar_function_catalog_entry.cpp +8 -8
  26. package/src/duckdb/src/catalog/catalog_entry/scalar_macro_catalog_entry.cpp +10 -10
  27. package/src/duckdb/src/catalog/catalog_entry/schema_catalog_entry.cpp +6 -6
  28. package/src/duckdb/src/catalog/catalog_entry/sequence_catalog_entry.cpp +6 -6
  29. package/src/duckdb/src/catalog/catalog_entry/table_catalog_entry.cpp +4 -4
  30. package/src/duckdb/src/catalog/catalog_entry/table_function_catalog_entry.cpp +9 -9
  31. package/src/duckdb/src/catalog/catalog_entry/type_catalog_entry.cpp +5 -5
  32. package/src/duckdb/src/catalog/catalog_entry/view_catalog_entry.cpp +23 -23
  33. package/src/duckdb/src/catalog/catalog_entry.cpp +27 -6
  34. package/src/duckdb/src/catalog/catalog_search_path.cpp +2 -2
  35. package/src/duckdb/src/catalog/catalog_set.cpp +84 -87
  36. package/src/duckdb/src/catalog/catalog_transaction.cpp +1 -1
  37. package/src/duckdb/src/catalog/default/default_functions.cpp +1 -1
  38. package/src/duckdb/src/catalog/default/default_schemas.cpp +1 -1
  39. package/src/duckdb/src/catalog/default/default_types.cpp +1 -1
  40. package/src/duckdb/src/catalog/default/default_views.cpp +1 -1
  41. package/src/duckdb/src/catalog/dependency_list.cpp +2 -2
  42. package/src/duckdb/src/catalog/dependency_manager.cpp +9 -10
  43. package/src/duckdb/src/catalog/duck_catalog.cpp +30 -26
  44. package/src/duckdb/src/catalog/similar_catalog_entry.cpp +1 -1
  45. package/src/duckdb/src/common/radix_partitioning.cpp +1 -1
  46. package/src/duckdb/src/common/types.cpp +15 -27
  47. package/src/duckdb/src/execution/index/art/art.cpp +286 -269
  48. package/src/duckdb/src/execution/index/art/art_key.cpp +22 -32
  49. package/src/duckdb/src/execution/index/art/fixed_size_allocator.cpp +224 -0
  50. package/src/duckdb/src/execution/index/art/iterator.cpp +142 -123
  51. package/src/duckdb/src/execution/index/art/leaf.cpp +319 -170
  52. package/src/duckdb/src/execution/index/art/leaf_segment.cpp +42 -0
  53. package/src/duckdb/src/execution/index/art/node.cpp +444 -379
  54. package/src/duckdb/src/execution/index/art/node16.cpp +178 -114
  55. package/src/duckdb/src/execution/index/art/node256.cpp +117 -79
  56. package/src/duckdb/src/execution/index/art/node4.cpp +169 -114
  57. package/src/duckdb/src/execution/index/art/node48.cpp +175 -105
  58. package/src/duckdb/src/execution/index/art/prefix.cpp +405 -127
  59. package/src/duckdb/src/execution/index/art/prefix_segment.cpp +42 -0
  60. package/src/duckdb/src/execution/index/art/swizzleable_pointer.cpp +10 -85
  61. package/src/duckdb/src/execution/operator/join/physical_index_join.cpp +4 -3
  62. package/src/duckdb/src/execution/operator/persistent/base_csv_reader.cpp +2 -2
  63. package/src/duckdb/src/execution/operator/persistent/csv_reader_options.cpp +2 -0
  64. package/src/duckdb/src/execution/operator/persistent/physical_batch_insert.cpp +4 -3
  65. package/src/duckdb/src/execution/operator/persistent/physical_export.cpp +19 -18
  66. package/src/duckdb/src/execution/operator/persistent/physical_insert.cpp +5 -5
  67. package/src/duckdb/src/execution/operator/schema/physical_alter.cpp +1 -1
  68. package/src/duckdb/src/execution/operator/schema/physical_create_function.cpp +1 -1
  69. package/src/duckdb/src/execution/operator/schema/physical_create_index.cpp +17 -17
  70. package/src/duckdb/src/execution/operator/schema/physical_create_schema.cpp +1 -1
  71. package/src/duckdb/src/execution/operator/schema/physical_create_sequence.cpp +1 -1
  72. package/src/duckdb/src/execution/operator/schema/physical_create_table.cpp +2 -2
  73. package/src/duckdb/src/execution/operator/schema/physical_create_type.cpp +4 -3
  74. package/src/duckdb/src/execution/operator/schema/physical_create_view.cpp +1 -1
  75. package/src/duckdb/src/execution/operator/schema/physical_detach.cpp +1 -1
  76. package/src/duckdb/src/execution/operator/schema/physical_drop.cpp +2 -2
  77. package/src/duckdb/src/execution/physical_plan/plan_aggregate.cpp +1 -1
  78. package/src/duckdb/src/execution/physical_plan/plan_comparison_join.cpp +4 -4
  79. package/src/duckdb/src/execution/physical_plan/plan_create_table.cpp +4 -3
  80. package/src/duckdb/src/execution/physical_plan/plan_delete.cpp +1 -1
  81. package/src/duckdb/src/execution/physical_plan/plan_insert.cpp +1 -1
  82. package/src/duckdb/src/execution/physical_plan/plan_update.cpp +1 -1
  83. package/src/duckdb/src/function/built_in_functions.cpp +10 -10
  84. package/src/duckdb/src/function/function_binder.cpp +3 -3
  85. package/src/duckdb/src/function/scalar/list/list_aggregates.cpp +5 -6
  86. package/src/duckdb/src/function/scalar/operators/arithmetic.cpp +2 -2
  87. package/src/duckdb/src/function/scalar/sequence/nextval.cpp +9 -8
  88. package/src/duckdb/src/function/scalar/system/aggregate_export.cpp +6 -6
  89. package/src/duckdb/src/function/table/arrow.cpp +5 -5
  90. package/src/duckdb/src/function/table/read_csv.cpp +5 -1
  91. package/src/duckdb/src/function/table/system/duckdb_columns.cpp +8 -7
  92. package/src/duckdb/src/function/table/system/duckdb_constraints.cpp +14 -14
  93. package/src/duckdb/src/function/table/system/duckdb_databases.cpp +2 -2
  94. package/src/duckdb/src/function/table/system/duckdb_functions.cpp +26 -25
  95. package/src/duckdb/src/function/table/system/duckdb_indexes.cpp +13 -12
  96. package/src/duckdb/src/function/table/system/duckdb_schemas.cpp +7 -7
  97. package/src/duckdb/src/function/table/system/duckdb_sequences.cpp +8 -9
  98. package/src/duckdb/src/function/table/system/duckdb_tables.cpp +10 -9
  99. package/src/duckdb/src/function/table/system/duckdb_types.cpp +13 -13
  100. package/src/duckdb/src/function/table/system/duckdb_views.cpp +11 -10
  101. package/src/duckdb/src/function/table/system/pragma_collations.cpp +2 -2
  102. package/src/duckdb/src/function/table/system/pragma_database_size.cpp +5 -5
  103. package/src/duckdb/src/function/table/system/pragma_storage_info.cpp +3 -3
  104. package/src/duckdb/src/function/table/system/pragma_table_info.cpp +2 -2
  105. package/src/duckdb/src/function/table/table_scan.cpp +39 -37
  106. package/src/duckdb/src/function/table/version/pragma_version.cpp +2 -2
  107. package/src/duckdb/src/function/udf_function.cpp +2 -2
  108. package/src/duckdb/src/include/duckdb/catalog/catalog.hpp +122 -81
  109. package/src/duckdb/src/include/duckdb/catalog/catalog_entry/aggregate_function_catalog_entry.hpp +2 -3
  110. package/src/duckdb/src/include/duckdb/catalog/catalog_entry/collate_catalog_entry.hpp +3 -3
  111. package/src/duckdb/src/include/duckdb/catalog/catalog_entry/copy_function_catalog_entry.hpp +1 -1
  112. package/src/duckdb/src/include/duckdb/catalog/catalog_entry/duck_index_entry.hpp +1 -1
  113. package/src/duckdb/src/include/duckdb/catalog/catalog_entry/duck_schema_entry.hpp +24 -20
  114. package/src/duckdb/src/include/duckdb/catalog/catalog_entry/duck_table_entry.hpp +3 -3
  115. package/src/duckdb/src/include/duckdb/catalog/catalog_entry/index_catalog_entry.hpp +1 -1
  116. package/src/duckdb/src/include/duckdb/catalog/catalog_entry/macro_catalog_entry.hpp +2 -2
  117. package/src/duckdb/src/include/duckdb/catalog/catalog_entry/pragma_function_catalog_entry.hpp +1 -1
  118. package/src/duckdb/src/include/duckdb/catalog/catalog_entry/scalar_function_catalog_entry.hpp +2 -2
  119. package/src/duckdb/src/include/duckdb/catalog/catalog_entry/scalar_macro_catalog_entry.hpp +1 -1
  120. package/src/duckdb/src/include/duckdb/catalog/catalog_entry/schema_catalog_entry.hpp +22 -17
  121. package/src/duckdb/src/include/duckdb/catalog/catalog_entry/sequence_catalog_entry.hpp +1 -1
  122. package/src/duckdb/src/include/duckdb/catalog/catalog_entry/table_catalog_entry.hpp +1 -1
  123. package/src/duckdb/src/include/duckdb/catalog/catalog_entry/table_function_catalog_entry.hpp +2 -2
  124. package/src/duckdb/src/include/duckdb/catalog/catalog_entry/table_macro_catalog_entry.hpp +1 -1
  125. package/src/duckdb/src/include/duckdb/catalog/catalog_entry/type_catalog_entry.hpp +1 -1
  126. package/src/duckdb/src/include/duckdb/catalog/catalog_entry/view_catalog_entry.hpp +3 -3
  127. package/src/duckdb/src/include/duckdb/catalog/catalog_entry.hpp +28 -7
  128. package/src/duckdb/src/include/duckdb/catalog/catalog_set.hpp +20 -19
  129. package/src/duckdb/src/include/duckdb/catalog/duck_catalog.hpp +9 -9
  130. package/src/duckdb/src/include/duckdb/catalog/similar_catalog_entry.hpp +2 -1
  131. package/src/duckdb/src/include/duckdb/catalog/standard_entry.hpp +10 -4
  132. package/src/duckdb/src/include/duckdb/common/enums/on_entry_not_found.hpp +17 -0
  133. package/src/duckdb/src/include/duckdb/common/queue.hpp +1 -1
  134. package/src/duckdb/src/include/duckdb/common/types.hpp +3 -4
  135. package/src/duckdb/src/include/duckdb/execution/index/art/art.hpp +53 -45
  136. package/src/duckdb/src/include/duckdb/execution/index/art/art_key.hpp +29 -24
  137. package/src/duckdb/src/include/duckdb/execution/index/art/fixed_size_allocator.hpp +114 -0
  138. package/src/duckdb/src/include/duckdb/execution/index/art/iterator.hpp +26 -20
  139. package/src/duckdb/src/include/duckdb/execution/index/art/leaf.hpp +63 -39
  140. package/src/duckdb/src/include/duckdb/execution/index/art/leaf_segment.hpp +36 -0
  141. package/src/duckdb/src/include/duckdb/execution/index/art/node.hpp +98 -116
  142. package/src/duckdb/src/include/duckdb/execution/index/art/node16.hpp +48 -36
  143. package/src/duckdb/src/include/duckdb/execution/index/art/node256.hpp +52 -35
  144. package/src/duckdb/src/include/duckdb/execution/index/art/node4.hpp +46 -36
  145. package/src/duckdb/src/include/duckdb/execution/index/art/node48.hpp +57 -35
  146. package/src/duckdb/src/include/duckdb/execution/index/art/prefix.hpp +57 -50
  147. package/src/duckdb/src/include/duckdb/execution/index/art/prefix_segment.hpp +40 -0
  148. package/src/duckdb/src/include/duckdb/execution/index/art/swizzleable_pointer.hpp +38 -31
  149. package/src/duckdb/src/include/duckdb/execution/operator/persistent/csv_file_handle.hpp +2 -1
  150. package/src/duckdb/src/include/duckdb/execution/operator/persistent/csv_reader_options.hpp +2 -0
  151. package/src/duckdb/src/include/duckdb/function/function_serialization.hpp +4 -4
  152. package/src/duckdb/src/include/duckdb/function/scalar_function.hpp +3 -2
  153. package/src/duckdb/src/include/duckdb/function/table/table_scan.hpp +5 -4
  154. package/src/duckdb/src/include/duckdb/function/table_function.hpp +28 -15
  155. package/src/duckdb/src/include/duckdb/main/attached_database.hpp +2 -0
  156. package/src/duckdb/src/include/duckdb/main/client_context.hpp +1 -1
  157. package/src/duckdb/src/include/duckdb/main/database_manager.hpp +3 -2
  158. package/src/duckdb/src/include/duckdb/parser/expression/bound_expression.hpp +2 -0
  159. package/src/duckdb/src/include/duckdb/parser/keyword_helper.hpp +2 -2
  160. package/src/duckdb/src/include/duckdb/parser/parsed_data/alter_info.hpp +7 -5
  161. package/src/duckdb/src/include/duckdb/parser/parsed_data/alter_table_info.hpp +1 -1
  162. package/src/duckdb/src/include/duckdb/parser/parsed_data/create_table_info.hpp +1 -1
  163. package/src/duckdb/src/include/duckdb/parser/parsed_data/create_view_info.hpp +1 -1
  164. package/src/duckdb/src/include/duckdb/parser/parsed_data/detach_info.hpp +3 -2
  165. package/src/duckdb/src/include/duckdb/parser/parsed_data/drop_info.hpp +5 -5
  166. package/src/duckdb/src/include/duckdb/parser/parsed_data/parse_info.hpp +13 -0
  167. package/src/duckdb/src/include/duckdb/parser/statement/insert_statement.hpp +4 -1
  168. package/src/duckdb/src/include/duckdb/parser/tableref.hpp +5 -2
  169. package/src/duckdb/src/include/duckdb/parser/transformer.hpp +4 -1
  170. package/src/duckdb/src/include/duckdb/planner/binder.hpp +2 -2
  171. package/src/duckdb/src/include/duckdb/planner/expression_binder/base_select_binder.hpp +1 -2
  172. package/src/duckdb/src/include/duckdb/planner/expression_binder.hpp +4 -7
  173. package/src/duckdb/src/include/duckdb/planner/operator/logical_get.hpp +1 -1
  174. package/src/duckdb/src/include/duckdb/storage/buffer_manager.hpp +0 -5
  175. package/src/duckdb/src/include/duckdb/storage/index.hpp +13 -28
  176. package/src/duckdb/src/include/duckdb/storage/standard_buffer_manager.hpp +0 -2
  177. package/src/duckdb/src/include/duckdb/transaction/cleanup_state.hpp +5 -0
  178. package/src/duckdb/src/include/duckdb/transaction/transaction.hpp +12 -0
  179. package/src/duckdb/src/include/duckdb.h +26 -0
  180. package/src/duckdb/src/main/attached_database.cpp +12 -6
  181. package/src/duckdb/src/main/capi/helper-c.cpp +7 -0
  182. package/src/duckdb/src/main/capi/table_function-c.cpp +17 -16
  183. package/src/duckdb/src/main/client_context.cpp +12 -11
  184. package/src/duckdb/src/main/database_manager.cpp +13 -12
  185. package/src/duckdb/src/optimizer/join_order/cardinality_estimator.cpp +1 -2
  186. package/src/duckdb/src/parser/parsed_data/alter_info.cpp +3 -3
  187. package/src/duckdb/src/parser/parsed_data/alter_scalar_function_info.cpp +2 -2
  188. package/src/duckdb/src/parser/parsed_data/alter_table_function_info.cpp +2 -2
  189. package/src/duckdb/src/parser/parsed_data/alter_table_info.cpp +9 -9
  190. package/src/duckdb/src/parser/parsed_data/create_scalar_function_info.cpp +2 -2
  191. package/src/duckdb/src/parser/parsed_data/create_table_function_info.cpp +2 -2
  192. package/src/duckdb/src/parser/parsed_data/create_table_info.cpp +2 -2
  193. package/src/duckdb/src/parser/parsed_data/create_view_info.cpp +2 -2
  194. package/src/duckdb/src/parser/statement/insert_statement.cpp +15 -6
  195. package/src/duckdb/src/parser/transform/constraint/transform_constraint.cpp +1 -1
  196. package/src/duckdb/src/parser/transform/expression/transform_function.cpp +18 -5
  197. package/src/duckdb/src/parser/transform/statement/transform_alter_sequence.cpp +3 -2
  198. package/src/duckdb/src/parser/transform/statement/transform_alter_table.cpp +5 -1
  199. package/src/duckdb/src/parser/transform/statement/transform_detach.cpp +1 -1
  200. package/src/duckdb/src/parser/transform/statement/transform_drop.cpp +1 -1
  201. package/src/duckdb/src/parser/transform/statement/transform_insert.cpp +5 -7
  202. package/src/duckdb/src/parser/transform/statement/transform_rename.cpp +1 -1
  203. package/src/duckdb/src/planner/binder/expression/bind_aggregate_expression.cpp +26 -27
  204. package/src/duckdb/src/planner/binder/expression/bind_between_expression.cpp +17 -17
  205. package/src/duckdb/src/planner/binder/expression/bind_case_expression.cpp +9 -9
  206. package/src/duckdb/src/planner/binder/expression/bind_cast_expression.cpp +6 -6
  207. package/src/duckdb/src/planner/binder/expression/bind_collate_expression.cpp +6 -6
  208. package/src/duckdb/src/planner/binder/expression/bind_columnref_expression.cpp +2 -2
  209. package/src/duckdb/src/planner/binder/expression/bind_comparison_expression.cpp +21 -21
  210. package/src/duckdb/src/planner/binder/expression/bind_conjunction_expression.cpp +2 -3
  211. package/src/duckdb/src/planner/binder/expression/bind_function_expression.cpp +33 -36
  212. package/src/duckdb/src/planner/binder/expression/bind_macro_expression.cpp +5 -5
  213. package/src/duckdb/src/planner/binder/expression/bind_operator_expression.cpp +23 -23
  214. package/src/duckdb/src/planner/binder/expression/bind_subquery_expression.cpp +4 -4
  215. package/src/duckdb/src/planner/binder/expression/bind_unnest_expression.cpp +7 -7
  216. package/src/duckdb/src/planner/binder/expression/bind_window_expression.cpp +23 -23
  217. package/src/duckdb/src/planner/binder/query_node/bind_table_macro_node.cpp +4 -4
  218. package/src/duckdb/src/planner/binder/statement/bind_copy.cpp +14 -13
  219. package/src/duckdb/src/planner/binder/statement/bind_create.cpp +56 -42
  220. package/src/duckdb/src/planner/binder/statement/bind_create_table.cpp +3 -3
  221. package/src/duckdb/src/planner/binder/statement/bind_delete.cpp +1 -1
  222. package/src/duckdb/src/planner/binder/statement/bind_drop.cpp +4 -4
  223. package/src/duckdb/src/planner/binder/statement/bind_export.cpp +10 -10
  224. package/src/duckdb/src/planner/binder/statement/bind_insert.cpp +16 -11
  225. package/src/duckdb/src/planner/binder/statement/bind_pragma.cpp +4 -4
  226. package/src/duckdb/src/planner/binder/statement/bind_simple.cpp +5 -4
  227. package/src/duckdb/src/planner/binder/statement/bind_update.cpp +1 -1
  228. package/src/duckdb/src/planner/binder/tableref/bind_basetableref.cpp +3 -3
  229. package/src/duckdb/src/planner/binder/tableref/bind_table_function.cpp +10 -12
  230. package/src/duckdb/src/planner/binder.cpp +2 -2
  231. package/src/duckdb/src/planner/expression/bound_expression.cpp +11 -2
  232. package/src/duckdb/src/planner/operator/logical_copy_to_file.cpp +2 -5
  233. package/src/duckdb/src/planner/operator/logical_create.cpp +2 -1
  234. package/src/duckdb/src/planner/operator/logical_create_index.cpp +2 -2
  235. package/src/duckdb/src/planner/operator/logical_delete.cpp +2 -2
  236. package/src/duckdb/src/planner/operator/logical_get.cpp +1 -1
  237. package/src/duckdb/src/planner/operator/logical_insert.cpp +2 -7
  238. package/src/duckdb/src/planner/operator/logical_update.cpp +2 -6
  239. package/src/duckdb/src/planner/parsed_data/bound_create_table_info.cpp +2 -2
  240. package/src/duckdb/src/planner/pragma_handler.cpp +3 -4
  241. package/src/duckdb/src/storage/checkpoint_manager.cpp +57 -55
  242. package/src/duckdb/src/storage/data_table.cpp +9 -9
  243. package/src/duckdb/src/storage/index.cpp +18 -6
  244. package/src/duckdb/src/storage/local_storage.cpp +8 -2
  245. package/src/duckdb/src/storage/standard_buffer_manager.cpp +0 -9
  246. package/src/duckdb/src/storage/table/update_segment.cpp +1 -1
  247. package/src/duckdb/src/storage/wal_replay.cpp +29 -31
  248. package/src/duckdb/src/storage/write_ahead_log.cpp +8 -8
  249. package/src/duckdb/src/transaction/cleanup_state.cpp +7 -1
  250. package/src/duckdb/src/transaction/commit_state.cpp +3 -4
  251. package/src/duckdb/src/transaction/transaction_context.cpp +1 -1
  252. package/src/duckdb/src/transaction/undo_buffer.cpp +8 -0
  253. package/src/duckdb/ub_extension_icu_third_party_icu_i18n.cpp +4 -4
  254. package/src/duckdb/ub_src_execution_index_art.cpp +7 -1
@@ -1,5 +1,7 @@
1
1
  #include "duckdb/catalog/catalog.hpp"
2
+ #include "duckdb/catalog/catalog_entry/aggregate_function_catalog_entry.hpp"
2
3
  #include "duckdb/catalog/catalog_entry/scalar_function_catalog_entry.hpp"
4
+ #include "duckdb/catalog/catalog_entry/scalar_macro_catalog_entry.hpp"
3
5
  #include "duckdb/execution/expression_executor.hpp"
4
6
  #include "duckdb/function/function_binder.hpp"
5
7
  #include "duckdb/parser/expression/function_expression.hpp"
@@ -19,11 +21,12 @@ BindResult ExpressionBinder::BindExpression(FunctionExpression &function, idx_t
19
21
  // lookup the function in the catalog
20
22
  QueryErrorContext error_context(binder.root_statement, function.query_location);
21
23
  auto func = Catalog::GetEntry(context, CatalogType::SCALAR_FUNCTION_ENTRY, function.catalog, function.schema,
22
- function.function_name, true, error_context);
24
+ function.function_name, OnEntryNotFound::RETURN_NULL, error_context);
23
25
  if (!func) {
24
26
  // function was not found - check if we this is a table function
25
- auto table_func = Catalog::GetEntry(context, CatalogType::TABLE_FUNCTION_ENTRY, function.catalog,
26
- function.schema, function.function_name, true, error_context);
27
+ auto table_func =
28
+ Catalog::GetEntry(context, CatalogType::TABLE_FUNCTION_ENTRY, function.catalog, function.schema,
29
+ function.function_name, OnEntryNotFound::RETURN_NULL, error_context);
27
30
  if (table_func) {
28
31
  throw BinderException(binder.FormatError(
29
32
  function,
@@ -52,7 +55,7 @@ BindResult ExpressionBinder::BindExpression(FunctionExpression &function, idx_t
52
55
  }
53
56
  // rebind the function
54
57
  func = Catalog::GetEntry(context, CatalogType::SCALAR_FUNCTION_ENTRY, function.catalog, function.schema,
55
- function.function_name, false, error_context);
58
+ function.function_name, OnEntryNotFound::THROW_EXCEPTION, error_context);
56
59
  }
57
60
 
58
61
  if (func->type != CatalogType::AGGREGATE_FUNCTION_ENTRY &&
@@ -70,25 +73,24 @@ BindResult ExpressionBinder::BindExpression(FunctionExpression &function, idx_t
70
73
  if (function.function_name != "->>") {
71
74
  for (auto &child : function.children) {
72
75
  if (child->expression_class == ExpressionClass::LAMBDA) {
73
- return BindLambdaFunction(function, (ScalarFunctionCatalogEntry *)func, depth);
76
+ return BindLambdaFunction(function, func->Cast<ScalarFunctionCatalogEntry>(), depth);
74
77
  }
75
78
  }
76
79
  }
77
80
 
78
81
  // other scalar function
79
- return BindFunction(function, (ScalarFunctionCatalogEntry *)func, depth);
82
+ return BindFunction(function, func->Cast<ScalarFunctionCatalogEntry>(), depth);
80
83
 
81
84
  case CatalogType::MACRO_ENTRY:
82
85
  // macro function
83
- return BindMacro(function, (ScalarMacroCatalogEntry *)func, depth, expr_ptr);
86
+ return BindMacro(function, func->Cast<ScalarMacroCatalogEntry>(), depth, expr_ptr);
84
87
  default:
85
88
  // aggregate function
86
- return BindAggregate(function, (AggregateFunctionCatalogEntry *)func, depth);
89
+ return BindAggregate(function, func->Cast<AggregateFunctionCatalogEntry>(), depth);
87
90
  }
88
91
  }
89
92
 
90
- BindResult ExpressionBinder::BindFunction(FunctionExpression &function, optional_ptr<ScalarFunctionCatalogEntry> func,
91
- idx_t depth) {
93
+ BindResult ExpressionBinder::BindFunction(FunctionExpression &function, ScalarFunctionCatalogEntry &func, idx_t depth) {
92
94
 
93
95
  // bind the children of the function expression
94
96
  string error;
@@ -109,22 +111,21 @@ BindResult ExpressionBinder::BindFunction(FunctionExpression &function, optional
109
111
  // extract the children and types
110
112
  vector<unique_ptr<Expression>> children;
111
113
  for (idx_t i = 0; i < function.children.size(); i++) {
112
- auto &child = (BoundExpression &)*function.children[i];
113
- D_ASSERT(child.expr);
114
- children.push_back(std::move(child.expr));
114
+ auto &child = BoundExpression::GetExpression(*function.children[i]);
115
+ children.push_back(std::move(child));
115
116
  }
116
117
 
117
118
  FunctionBinder function_binder(context);
118
119
  unique_ptr<Expression> result =
119
- function_binder.BindScalarFunction(*func, std::move(children), error, function.is_operator, &binder);
120
+ function_binder.BindScalarFunction(func, std::move(children), error, function.is_operator, &binder);
120
121
  if (!result) {
121
122
  throw BinderException(binder.FormatError(function, error));
122
123
  }
123
124
  return BindResult(std::move(result));
124
125
  }
125
126
 
126
- BindResult ExpressionBinder::BindLambdaFunction(FunctionExpression &function,
127
- optional_ptr<ScalarFunctionCatalogEntry> func, idx_t depth) {
127
+ BindResult ExpressionBinder::BindLambdaFunction(FunctionExpression &function, ScalarFunctionCatalogEntry &func,
128
+ idx_t depth) {
128
129
 
129
130
  // bind the children of the function expression
130
131
  string error;
@@ -141,18 +142,16 @@ BindResult ExpressionBinder::BindLambdaFunction(FunctionExpression &function,
141
142
  }
142
143
 
143
144
  // get the logical type of the children of the list
144
- auto &list_child = function.children[0]->Cast<BoundExpression>();
145
-
146
- if (list_child.expr->return_type.id() != LogicalTypeId::LIST &&
147
- list_child.expr->return_type.id() != LogicalTypeId::SQLNULL &&
148
- list_child.expr->return_type.id() != LogicalTypeId::UNKNOWN) {
145
+ auto &list_child = BoundExpression::GetExpression(*function.children[0]);
146
+ if (list_child->return_type.id() != LogicalTypeId::LIST && list_child->return_type.id() != LogicalTypeId::SQLNULL &&
147
+ list_child->return_type.id() != LogicalTypeId::UNKNOWN) {
149
148
  throw BinderException(" Invalid LIST argument to " + function.function_name + "!");
150
149
  }
151
150
 
152
- LogicalType list_child_type = list_child.expr->return_type.id();
153
- if (list_child.expr->return_type.id() != LogicalTypeId::SQLNULL &&
154
- list_child.expr->return_type.id() != LogicalTypeId::UNKNOWN) {
155
- list_child_type = ListType::GetChildType(list_child.expr->return_type);
151
+ LogicalType list_child_type = list_child->return_type.id();
152
+ if (list_child->return_type.id() != LogicalTypeId::SQLNULL &&
153
+ list_child->return_type.id() != LogicalTypeId::UNKNOWN) {
154
+ list_child_type = ListType::GetChildType(list_child->return_type);
156
155
  }
157
156
 
158
157
  // bind the lambda parameter
@@ -164,12 +163,11 @@ BindResult ExpressionBinder::BindLambdaFunction(FunctionExpression &function,
164
163
  } else {
165
164
  // successfully bound: replace the node with a BoundExpression
166
165
  auto alias = function.children[1]->alias;
167
- function.children[1] = make_uniq<BoundExpression>(std::move(bind_lambda_result.expression));
168
- auto &be = function.children[1]->Cast<BoundExpression>();
169
- be.alias = alias;
166
+ bind_lambda_result.expression->alias = alias;
170
167
  if (!alias.empty()) {
171
- be.expr->alias = alias;
168
+ bind_lambda_result.expression->alias = alias;
172
169
  }
170
+ function.children[1] = make_uniq<BoundExpression>(std::move(bind_lambda_result.expression));
173
171
  }
174
172
 
175
173
  if (!error.empty()) {
@@ -183,9 +181,8 @@ BindResult ExpressionBinder::BindLambdaFunction(FunctionExpression &function,
183
181
  // extract the children and types
184
182
  vector<unique_ptr<Expression>> children;
185
183
  for (idx_t i = 0; i < function.children.size(); i++) {
186
- auto &child = (BoundExpression &)*function.children[i];
187
- D_ASSERT(child.expr);
188
- children.push_back(std::move(child.expr));
184
+ auto &child = BoundExpression::GetExpression(*function.children[i]);
185
+ children.push_back(std::move(child));
189
186
  }
190
187
 
191
188
  // capture the (lambda) columns
@@ -194,7 +191,7 @@ BindResult ExpressionBinder::BindLambdaFunction(FunctionExpression &function,
194
191
 
195
192
  FunctionBinder function_binder(context);
196
193
  unique_ptr<Expression> result =
197
- function_binder.BindScalarFunction(*func, std::move(children), error, function.is_operator, &binder);
194
+ function_binder.BindScalarFunction(func, std::move(children), error, function.is_operator, &binder);
198
195
  if (!result) {
199
196
  throw BinderException(binder.FormatError(function, error));
200
197
  }
@@ -205,7 +202,7 @@ BindResult ExpressionBinder::BindLambdaFunction(FunctionExpression &function,
205
202
  // remove the lambda expression from the children
206
203
  auto lambda = std::move(bound_function_expr.children.back());
207
204
  bound_function_expr.children.pop_back();
208
- auto &bound_lambda = (BoundLambdaExpression &)*lambda;
205
+ auto &bound_lambda = lambda->Cast<BoundLambdaExpression>();
209
206
 
210
207
  // push back (in reverse order) any nested lambda parameters so that we can later use them in the lambda expression
211
208
  // (rhs)
@@ -234,8 +231,8 @@ BindResult ExpressionBinder::BindLambdaFunction(FunctionExpression &function,
234
231
  return BindResult(std::move(result));
235
232
  }
236
233
 
237
- BindResult ExpressionBinder::BindAggregate(FunctionExpression &expr,
238
- optional_ptr<AggregateFunctionCatalogEntry> function, idx_t depth) {
234
+ BindResult ExpressionBinder::BindAggregate(FunctionExpression &expr, AggregateFunctionCatalogEntry &function,
235
+ idx_t depth) {
239
236
  return BindResult(binder.FormatError(expr, UnsupportedAggregateMessage()));
240
237
  }
241
238
 
@@ -44,17 +44,17 @@ void ExpressionBinder::ReplaceMacroParametersRecursive(unique_ptr<ParsedExpressi
44
44
  *expr, [&](unique_ptr<ParsedExpression> &child) { ReplaceMacroParametersRecursive(child); });
45
45
  }
46
46
 
47
- BindResult ExpressionBinder::BindMacro(FunctionExpression &function, optional_ptr<ScalarMacroCatalogEntry> macro_func,
48
- idx_t depth, unique_ptr<ParsedExpression> &expr) {
47
+ BindResult ExpressionBinder::BindMacro(FunctionExpression &function, ScalarMacroCatalogEntry &macro_func, idx_t depth,
48
+ unique_ptr<ParsedExpression> &expr) {
49
49
  // recast function so we can access the scalar member function->expression
50
- auto &macro_def = macro_func->function->Cast<ScalarMacroFunction>();
50
+ auto &macro_def = macro_func.function->Cast<ScalarMacroFunction>();
51
51
 
52
52
  // validate the arguments and separate positional and default arguments
53
53
  vector<unique_ptr<ParsedExpression>> positionals;
54
54
  unordered_map<string, unique_ptr<ParsedExpression>> defaults;
55
55
 
56
56
  string error =
57
- MacroFunction::ValidateArguments(*macro_func->function, macro_func->name, function, positionals, defaults);
57
+ MacroFunction::ValidateArguments(*macro_func.function, macro_func.name, function, positionals, defaults);
58
58
  if (!error.empty()) {
59
59
  throw BinderException(binder.FormatError(*expr, error));
60
60
  }
@@ -75,7 +75,7 @@ BindResult ExpressionBinder::BindMacro(FunctionExpression &function, optional_pt
75
75
  // now push the defaults into the positionals
76
76
  positionals.push_back(std::move(defaults[it->first]));
77
77
  }
78
- auto new_macro_binding = make_uniq<DummyBinding>(types, names, macro_func->name);
78
+ auto new_macro_binding = make_uniq<DummyBinding>(types, names, macro_func.name);
79
79
  new_macro_binding->arguments = &positionals;
80
80
  macro_binding = new_macro_binding.get();
81
81
 
@@ -8,27 +8,27 @@
8
8
 
9
9
  namespace duckdb {
10
10
 
11
- static LogicalType ResolveNotType(OperatorExpression &op, vector<BoundExpression *> &children) {
11
+ static LogicalType ResolveNotType(OperatorExpression &op, vector<unique_ptr<Expression>> &children) {
12
12
  // NOT expression, cast child to BOOLEAN
13
13
  D_ASSERT(children.size() == 1);
14
- children[0]->expr = BoundCastExpression::AddDefaultCastToType(std::move(children[0]->expr), LogicalType::BOOLEAN);
14
+ children[0] = BoundCastExpression::AddDefaultCastToType(std::move(children[0]), LogicalType::BOOLEAN);
15
15
  return LogicalType(LogicalTypeId::BOOLEAN);
16
16
  }
17
17
 
18
- static LogicalType ResolveInType(OperatorExpression &op, vector<BoundExpression *> &children) {
18
+ static LogicalType ResolveInType(OperatorExpression &op, vector<unique_ptr<Expression>> &children) {
19
19
  if (children.empty()) {
20
20
  throw InternalException("IN requires at least a single child node");
21
21
  }
22
22
  // get the maximum type from the children
23
- LogicalType max_type = children[0]->expr->return_type;
24
- bool any_varchar = children[0]->expr->return_type == LogicalType::VARCHAR;
25
- bool any_enum = children[0]->expr->return_type.id() == LogicalTypeId::ENUM;
23
+ LogicalType max_type = children[0]->return_type;
24
+ bool any_varchar = children[0]->return_type == LogicalType::VARCHAR;
25
+ bool any_enum = children[0]->return_type.id() == LogicalTypeId::ENUM;
26
26
  for (idx_t i = 1; i < children.size(); i++) {
27
- max_type = LogicalType::MaxLogicalType(max_type, children[i]->expr->return_type);
28
- if (children[i]->expr->return_type == LogicalType::VARCHAR) {
27
+ max_type = LogicalType::MaxLogicalType(max_type, children[i]->return_type);
28
+ if (children[i]->return_type == LogicalType::VARCHAR) {
29
29
  any_varchar = true;
30
30
  }
31
- if (children[i]->expr->return_type.id() == LogicalTypeId::ENUM) {
31
+ if (children[i]->return_type.id() == LogicalTypeId::ENUM) {
32
32
  any_enum = true;
33
33
  }
34
34
  }
@@ -40,18 +40,18 @@ static LogicalType ResolveInType(OperatorExpression &op, vector<BoundExpression
40
40
 
41
41
  // cast all children to the same type
42
42
  for (idx_t i = 0; i < children.size(); i++) {
43
- children[i]->expr = BoundCastExpression::AddDefaultCastToType(std::move(children[i]->expr), max_type);
43
+ children[i] = BoundCastExpression::AddDefaultCastToType(std::move(children[i]), max_type);
44
44
  }
45
45
  // (NOT) IN always returns a boolean
46
46
  return LogicalType::BOOLEAN;
47
47
  }
48
48
 
49
- static LogicalType ResolveOperatorType(OperatorExpression &op, vector<BoundExpression *> &children) {
49
+ static LogicalType ResolveOperatorType(OperatorExpression &op, vector<unique_ptr<Expression>> &children) {
50
50
  switch (op.type) {
51
51
  case ExpressionType::OPERATOR_IS_NULL:
52
52
  case ExpressionType::OPERATOR_IS_NOT_NULL:
53
53
  // IS (NOT) NULL always returns a boolean, and does not cast its children
54
- if (!children[0]->expr->return_type.IsValid()) {
54
+ if (!children[0]->return_type.IsValid()) {
55
55
  throw ParameterNotResolvedException();
56
56
  }
57
57
  return LogicalType::BOOLEAN;
@@ -60,7 +60,7 @@ static LogicalType ResolveOperatorType(OperatorExpression &op, vector<BoundExpre
60
60
  return ResolveInType(op, children);
61
61
  case ExpressionType::OPERATOR_COALESCE: {
62
62
  ResolveInType(op, children);
63
- return children[0]->expr->return_type;
63
+ return children[0]->return_type;
64
64
  }
65
65
  case ExpressionType::OPERATOR_NOT:
66
66
  return ResolveNotType(op, children);
@@ -90,8 +90,8 @@ BindResult ExpressionBinder::BindExpression(OperatorExpression &op, idx_t depth)
90
90
  switch (op.type) {
91
91
  case ExpressionType::ARRAY_EXTRACT: {
92
92
  D_ASSERT(op.children[0]->expression_class == ExpressionClass::BOUND_EXPRESSION);
93
- auto &b_exp = (BoundExpression &)*op.children[0];
94
- if (b_exp.expr->return_type.id() == LogicalTypeId::MAP) {
93
+ auto &b_exp = BoundExpression::GetExpression(*op.children[0]);
94
+ if (b_exp->return_type.id() == LogicalTypeId::MAP) {
95
95
  function_name = "map_extract";
96
96
  } else {
97
97
  function_name = "array_extract";
@@ -105,14 +105,14 @@ BindResult ExpressionBinder::BindExpression(OperatorExpression &op, idx_t depth)
105
105
  D_ASSERT(op.children.size() == 2);
106
106
  D_ASSERT(op.children[0]->expression_class == ExpressionClass::BOUND_EXPRESSION);
107
107
  D_ASSERT(op.children[1]->expression_class == ExpressionClass::BOUND_EXPRESSION);
108
- auto &extract_exp = (BoundExpression &)*op.children[0];
109
- auto &name_exp = (BoundExpression &)*op.children[1];
110
- auto extract_expr_type = extract_exp.expr->return_type.id();
108
+ auto &extract_exp = BoundExpression::GetExpression(*op.children[0]);
109
+ auto &name_exp = BoundExpression::GetExpression(*op.children[1]);
110
+ auto extract_expr_type = extract_exp->return_type.id();
111
111
  if (extract_expr_type != LogicalTypeId::STRUCT && extract_expr_type != LogicalTypeId::UNION &&
112
112
  extract_expr_type != LogicalTypeId::SQLNULL) {
113
113
  return BindResult(StringUtil::Format(
114
114
  "Cannot extract field %s from expression \"%s\" because it is not a struct or a union",
115
- name_exp.ToString(), extract_exp.ToString()));
115
+ name_exp->ToString(), extract_exp->ToString()));
116
116
  }
117
117
  function_name = extract_expr_type == LogicalTypeId::UNION ? "union_extract" : "struct_extract";
118
118
  break;
@@ -131,10 +131,10 @@ BindResult ExpressionBinder::BindExpression(OperatorExpression &op, idx_t depth)
131
131
  return BindExpression(function, depth, false);
132
132
  }
133
133
 
134
- vector<BoundExpression *> children;
134
+ vector<unique_ptr<Expression>> children;
135
135
  for (idx_t i = 0; i < op.children.size(); i++) {
136
136
  D_ASSERT(op.children[i]->expression_class == ExpressionClass::BOUND_EXPRESSION);
137
- children.push_back((BoundExpression *)op.children[i].get());
137
+ children.push_back(std::move(BoundExpression::GetExpression(*op.children[i])));
138
138
  }
139
139
  // now resolve the types
140
140
  LogicalType result_type = ResolveOperatorType(op, children);
@@ -143,13 +143,13 @@ BindResult ExpressionBinder::BindExpression(OperatorExpression &op, idx_t depth)
143
143
  throw BinderException("COALESCE needs at least one child");
144
144
  }
145
145
  if (children.size() == 1) {
146
- return BindResult(std::move(children[0]->expr));
146
+ return BindResult(std::move(children[0]));
147
147
  }
148
148
  }
149
149
 
150
150
  auto result = make_uniq<BoundOperatorExpression>(op.type, result_type);
151
151
  for (auto &child : children) {
152
- result->children.push_back(std::move(child->expr));
152
+ result->children.push_back(std::move(child));
153
153
  }
154
154
  return BindResult(std::move(result));
155
155
  }
@@ -75,7 +75,6 @@ BindResult ExpressionBinder::BindExpression(SubqueryExpression &expr, idx_t dept
75
75
  // both binding the child and binding the subquery was successful
76
76
  D_ASSERT(expr.subquery->node->type == QueryNodeType::BOUND_SUBQUERY_NODE);
77
77
  auto bound_subquery = (BoundSubqueryNode *)expr.subquery->node.get();
78
- auto child = (BoundExpression *)expr.child.get();
79
78
  auto subquery_binder = std::move(bound_subquery->subquery_binder);
80
79
  auto bound_node = std::move(bound_subquery->bound_node);
81
80
  LogicalType return_type =
@@ -89,15 +88,16 @@ BindResult ExpressionBinder::BindExpression(SubqueryExpression &expr, idx_t dept
89
88
  // ANY comparison
90
89
  // cast child and subquery child to equivalent types
91
90
  D_ASSERT(bound_node->types.size() == 1);
92
- auto compare_type = LogicalType::MaxLogicalType(child->expr->return_type, bound_node->types[0]);
93
- child->expr = BoundCastExpression::AddCastToType(context, std::move(child->expr), compare_type);
91
+ auto &child = BoundExpression::GetExpression(*expr.child);
92
+ auto compare_type = LogicalType::MaxLogicalType(child->return_type, bound_node->types[0]);
93
+ child = BoundCastExpression::AddCastToType(context, std::move(child), compare_type);
94
94
  result->child_type = bound_node->types[0];
95
95
  result->child_target = compare_type;
96
+ result->child = std::move(child);
96
97
  }
97
98
  result->binder = std::move(subquery_binder);
98
99
  result->subquery = std::move(bound_node);
99
100
  result->subquery_type = expr.subquery_type;
100
- result->child = child ? std::move(child->expr) : nullptr;
101
101
  result->comparison_type = expr.comparison_type;
102
102
 
103
103
  return BindResult(std::move(result));
@@ -57,8 +57,8 @@ BindResult SelectBinder::BindUnnest(FunctionExpression &function, idx_t depth, b
57
57
  if (!error.empty()) {
58
58
  return BindResult(error);
59
59
  }
60
- auto &const_child = (BoundExpression &)*function.children[i];
61
- auto value = ExpressionExecutor::EvaluateScalar(context, *const_child.expr, true);
60
+ auto &const_child = BoundExpression::GetExpression(*function.children[i]);
61
+ auto value = ExpressionExecutor::EvaluateScalar(context, *const_child, true);
62
62
  if (alias == "recursive") {
63
63
  auto recursive = value.GetValue<bool>();
64
64
  if (recursive) {
@@ -90,11 +90,11 @@ BindResult SelectBinder::BindUnnest(FunctionExpression &function, idx_t depth, b
90
90
  if (!BindCorrelatedColumns(function.children[0])) {
91
91
  return BindResult(error);
92
92
  }
93
- auto bound_expr = (BoundExpression *)function.children[0].get();
94
- ExtractCorrelatedExpressions(binder, *bound_expr->expr);
93
+ auto &bound_expr = BoundExpression::GetExpression(*function.children[0]);
94
+ ExtractCorrelatedExpressions(binder, *bound_expr);
95
95
  }
96
- auto &child = (BoundExpression &)*function.children[0];
97
- auto &child_type = child.expr->return_type;
96
+ auto &child = BoundExpression::GetExpression(*function.children[0]);
97
+ auto &child_type = child->return_type;
98
98
  unnest_level--;
99
99
 
100
100
  if (unnest_level > 0) {
@@ -116,7 +116,7 @@ BindResult SelectBinder::BindUnnest(FunctionExpression &function, idx_t depth, b
116
116
  idx_t list_unnests;
117
117
  idx_t struct_unnests = 0;
118
118
 
119
- auto unnest_expr = std::move(child.expr);
119
+ auto unnest_expr = std::move(child);
120
120
  if (child_type.id() == LogicalTypeId::SQLNULL) {
121
121
  list_unnests = 1;
122
122
  } else {
@@ -70,7 +70,7 @@ static unique_ptr<Expression> GetExpression(unique_ptr<ParsedExpression> &expr)
70
70
  }
71
71
  D_ASSERT(expr.get());
72
72
  D_ASSERT(expr->expression_class == ExpressionClass::BOUND_EXPRESSION);
73
- return std::move(((BoundExpression &)*expr).expr);
73
+ return std::move(BoundExpression::GetExpression(*expr));
74
74
  }
75
75
 
76
76
  static unique_ptr<Expression> CastWindowExpression(unique_ptr<ParsedExpression> &expr, const LogicalType &type) {
@@ -80,10 +80,10 @@ static unique_ptr<Expression> CastWindowExpression(unique_ptr<ParsedExpression>
80
80
  D_ASSERT(expr.get());
81
81
  D_ASSERT(expr->expression_class == ExpressionClass::BOUND_EXPRESSION);
82
82
 
83
- auto &bound = (BoundExpression &)*expr;
84
- bound.expr = BoundCastExpression::AddDefaultCastToType(std::move(bound.expr), type);
83
+ auto &bound = BoundExpression::GetExpression(*expr);
84
+ bound = BoundCastExpression::AddDefaultCastToType(std::move(bound), type);
85
85
 
86
- return std::move(bound.expr);
86
+ return std::move(bound);
87
87
  }
88
88
 
89
89
  static LogicalType BindRangeExpression(ClientContext &context, const string &name, unique_ptr<ParsedExpression> &expr,
@@ -93,13 +93,13 @@ static LogicalType BindRangeExpression(ClientContext &context, const string &nam
93
93
 
94
94
  D_ASSERT(order_expr.get());
95
95
  D_ASSERT(order_expr->expression_class == ExpressionClass::BOUND_EXPRESSION);
96
- auto &bound_order = (BoundExpression &)*order_expr;
97
- children.emplace_back(bound_order.expr->Copy());
96
+ auto &bound_order = BoundExpression::GetExpression(*order_expr);
97
+ children.emplace_back(bound_order->Copy());
98
98
 
99
99
  D_ASSERT(expr.get());
100
100
  D_ASSERT(expr->expression_class == ExpressionClass::BOUND_EXPRESSION);
101
- auto &bound = (BoundExpression &)*expr;
102
- children.emplace_back(std::move(bound.expr));
101
+ auto &bound = BoundExpression::GetExpression(*expr);
102
+ children.emplace_back(std::move(bound));
103
103
 
104
104
  string error;
105
105
  FunctionBinder function_binder(context);
@@ -107,8 +107,8 @@ static LogicalType BindRangeExpression(ClientContext &context, const string &nam
107
107
  if (!function) {
108
108
  throw BinderException(error);
109
109
  }
110
- bound.expr = std::move(function);
111
- return bound.expr->return_type;
110
+ bound = std::move(function);
111
+ return bound->return_type;
112
112
  }
113
113
 
114
114
  BindResult BaseSelectBinder::BindWindow(WindowExpression &window, idx_t depth) {
@@ -157,26 +157,26 @@ BindResult BaseSelectBinder::BindWindow(WindowExpression &window, idx_t depth) {
157
157
  for (auto &child : window.children) {
158
158
  D_ASSERT(child.get());
159
159
  D_ASSERT(child->expression_class == ExpressionClass::BOUND_EXPRESSION);
160
- auto &bound = (BoundExpression &)*child;
160
+ auto &bound = BoundExpression::GetExpression(*child);
161
161
  // Add casts for positional arguments
162
162
  const auto argno = children.size();
163
163
  switch (window.type) {
164
164
  case ExpressionType::WINDOW_NTILE:
165
165
  // ntile(bigint)
166
166
  if (argno == 0) {
167
- bound.expr = BoundCastExpression::AddCastToType(context, std::move(bound.expr), LogicalType::BIGINT);
167
+ bound = BoundCastExpression::AddCastToType(context, std::move(bound), LogicalType::BIGINT);
168
168
  }
169
169
  break;
170
170
  case ExpressionType::WINDOW_NTH_VALUE:
171
171
  // nth_value(<expr>, index)
172
172
  if (argno == 1) {
173
- bound.expr = BoundCastExpression::AddCastToType(context, std::move(bound.expr), LogicalType::BIGINT);
173
+ bound = BoundCastExpression::AddCastToType(context, std::move(bound), LogicalType::BIGINT);
174
174
  }
175
175
  default:
176
176
  break;
177
177
  }
178
- types.push_back(bound.expr->return_type);
179
- children.push_back(std::move(bound.expr));
178
+ types.push_back(bound->return_type);
179
+ children.push_back(std::move(bound));
180
180
  }
181
181
  // Determine the function type.
182
182
  LogicalType sql_type;
@@ -184,19 +184,19 @@ BindResult BaseSelectBinder::BindWindow(WindowExpression &window, idx_t depth) {
184
184
  unique_ptr<FunctionData> bind_info;
185
185
  if (window.type == ExpressionType::WINDOW_AGGREGATE) {
186
186
  // Look up the aggregate function in the catalog
187
- auto func = Catalog::GetEntry<AggregateFunctionCatalogEntry>(context, window.catalog, window.schema,
188
- window.function_name, false, error_context);
189
- D_ASSERT(func->type == CatalogType::AGGREGATE_FUNCTION_ENTRY);
187
+ auto &func = Catalog::GetEntry<AggregateFunctionCatalogEntry>(context, window.catalog, window.schema,
188
+ window.function_name, error_context);
189
+ D_ASSERT(func.type == CatalogType::AGGREGATE_FUNCTION_ENTRY);
190
190
 
191
191
  // bind the aggregate
192
192
  string error;
193
193
  FunctionBinder function_binder(context);
194
- auto best_function = function_binder.BindFunction(func->name, func->functions, types, error);
194
+ auto best_function = function_binder.BindFunction(func.name, func.functions, types, error);
195
195
  if (best_function == DConstants::INVALID_INDEX) {
196
196
  throw BinderException(binder.FormatError(window, error));
197
197
  }
198
198
  // found a matching function! bind it as an aggregate
199
- auto bound_function = func->functions.GetFunctionByOffset(best_function);
199
+ auto bound_function = func.functions.GetFunctionByOffset(best_function);
200
200
  auto bound_aggregate = function_binder.BindAggregateFunction(bound_function, std::move(children));
201
201
  // create the aggregate
202
202
  aggregate = make_uniq<AggregateFunction>(bound_aggregate->function);
@@ -253,8 +253,8 @@ BindResult BaseSelectBinder::BindWindow(WindowExpression &window, idx_t depth) {
253
253
  auto &order_expr = window.orders[0].expression;
254
254
  D_ASSERT(order_expr.get());
255
255
  D_ASSERT(order_expr->expression_class == ExpressionClass::BOUND_EXPRESSION);
256
- auto &bound_order = (BoundExpression &)*order_expr;
257
- auto order_type = bound_order.expr->return_type;
256
+ auto &bound_order = BoundExpression::GetExpression(*order_expr);
257
+ auto order_type = bound_order->return_type;
258
258
  if (window.start_expr) {
259
259
  order_type = LogicalType::MaxLogicalType(order_type, start_type);
260
260
  }
@@ -263,7 +263,7 @@ BindResult BaseSelectBinder::BindWindow(WindowExpression &window, idx_t depth) {
263
263
  }
264
264
 
265
265
  // Cast all three to match
266
- bound_order.expr = BoundCastExpression::AddCastToType(context, std::move(bound_order.expr), order_type);
266
+ bound_order = BoundCastExpression::AddCastToType(context, std::move(bound_order), order_type);
267
267
  start_type = end_type = order_type;
268
268
  }
269
269
 
@@ -16,10 +16,10 @@
16
16
 
17
17
  namespace duckdb {
18
18
 
19
- unique_ptr<QueryNode> Binder::BindTableMacro(FunctionExpression &function, TableMacroCatalogEntry *macro_func,
19
+ unique_ptr<QueryNode> Binder::BindTableMacro(FunctionExpression &function, TableMacroCatalogEntry &macro_func,
20
20
  idx_t depth) {
21
21
 
22
- auto &macro_def = macro_func->function->Cast<TableMacroFunction>();
22
+ auto &macro_def = macro_func.function->Cast<TableMacroFunction>();
23
23
  auto node = macro_def.query_node->Copy();
24
24
 
25
25
  // auto &macro_def = *macro_func->function;
@@ -28,7 +28,7 @@ unique_ptr<QueryNode> Binder::BindTableMacro(FunctionExpression &function, Table
28
28
  vector<unique_ptr<ParsedExpression>> positionals;
29
29
  unordered_map<string, unique_ptr<ParsedExpression>> defaults;
30
30
  string error =
31
- MacroFunction::ValidateArguments(*macro_func->function, macro_func->name, function, positionals, defaults);
31
+ MacroFunction::ValidateArguments(*macro_func.function, macro_func.name, function, positionals, defaults);
32
32
  if (!error.empty()) {
33
33
  // cannot use error below as binder rnot in scope
34
34
  // return BindResult(binder. FormatError(*expr->get(), error));
@@ -51,7 +51,7 @@ unique_ptr<QueryNode> Binder::BindTableMacro(FunctionExpression &function, Table
51
51
  // now push the defaults into the positionals
52
52
  positionals.push_back(std::move(defaults[it->first]));
53
53
  }
54
- auto new_macro_binding = make_uniq<DummyBinding>(types, names, macro_func->name);
54
+ auto new_macro_binding = make_uniq<DummyBinding>(types, names, macro_func.name);
55
55
  new_macro_binding->arguments = &positionals;
56
56
 
57
57
  // We need an ExpressionBinder so that we can call ExpressionBinder::ReplaceMacroParametersRecursive()
@@ -63,17 +63,17 @@ BoundStatement Binder::BindCopyTo(CopyStatement &stmt) {
63
63
  result.names = {"Count"};
64
64
 
65
65
  // lookup the format in the catalog
66
- auto copy_function =
66
+ auto &copy_function =
67
67
  Catalog::GetEntry<CopyFunctionCatalogEntry>(context, INVALID_CATALOG, DEFAULT_SCHEMA, stmt.info->format);
68
- if (copy_function->function.plan) {
68
+ if (copy_function.function.plan) {
69
69
  // plan rewrite COPY TO
70
- return copy_function->function.plan(*this, stmt);
70
+ return copy_function.function.plan(*this, stmt);
71
71
  }
72
72
 
73
73
  // bind the select statement
74
74
  auto select_node = Bind(*stmt.select_statement);
75
75
 
76
- if (!copy_function->function.copy_to_bind) {
76
+ if (!copy_function.function.copy_to_bind) {
77
77
  throw NotImplementedException("COPY TO is not supported for FORMAT \"%s\"", stmt.info->format);
78
78
  }
79
79
  bool use_tmp_file = true;
@@ -138,9 +138,9 @@ BoundStatement Binder::BindCopyTo(CopyStatement &stmt) {
138
138
  auto unique_column_names = GetUniqueNames(select_node.names);
139
139
 
140
140
  auto function_data =
141
- copy_function->function.copy_to_bind(context, *stmt.info, unique_column_names, select_node.types);
141
+ copy_function.function.copy_to_bind(context, *stmt.info, unique_column_names, select_node.types);
142
142
  // now create the copy information
143
- auto copy = make_uniq<LogicalCopyToFile>(copy_function->function, std::move(function_data));
143
+ auto copy = make_uniq<LogicalCopyToFile>(copy_function.function, std::move(function_data));
144
144
  copy->file_path = stmt.info->file_path;
145
145
  copy->use_tmp_file = use_tmp_file;
146
146
  copy->overwrite_or_ignore = overwrite_or_ignore;
@@ -187,17 +187,18 @@ BoundStatement Binder::BindCopyFrom(CopyStatement &stmt) {
187
187
 
188
188
  // lookup the format in the catalog
189
189
  auto &catalog = Catalog::GetSystemCatalog(context);
190
- auto copy_function = catalog.GetEntry<CopyFunctionCatalogEntry>(context, DEFAULT_SCHEMA, stmt.info->format);
191
- if (!copy_function->function.copy_from_bind) {
190
+ auto &copy_function = catalog.GetEntry<CopyFunctionCatalogEntry>(context, DEFAULT_SCHEMA, stmt.info->format);
191
+ if (!copy_function.function.copy_from_bind) {
192
192
  throw NotImplementedException("COPY FROM is not supported for FORMAT \"%s\"", stmt.info->format);
193
193
  }
194
194
  // lookup the table to copy into
195
195
  BindSchemaOrCatalog(stmt.info->catalog, stmt.info->schema);
196
- auto table = Catalog::GetEntry<TableCatalogEntry>(context, stmt.info->catalog, stmt.info->schema, stmt.info->table);
196
+ auto &table =
197
+ Catalog::GetEntry<TableCatalogEntry>(context, stmt.info->catalog, stmt.info->schema, stmt.info->table);
197
198
  vector<string> expected_names;
198
199
  if (!bound_insert.column_index_map.empty()) {
199
200
  expected_names.resize(bound_insert.expected_types.size());
200
- for (auto &col : table->GetColumns().Physical()) {
201
+ for (auto &col : table.GetColumns().Physical()) {
201
202
  auto i = col.Physical();
202
203
  if (bound_insert.column_index_map[i] != DConstants::INVALID_INDEX) {
203
204
  expected_names[bound_insert.column_index_map[i]] = col.Name();
@@ -205,14 +206,14 @@ BoundStatement Binder::BindCopyFrom(CopyStatement &stmt) {
205
206
  }
206
207
  } else {
207
208
  expected_names.reserve(bound_insert.expected_types.size());
208
- for (auto &col : table->GetColumns().Physical()) {
209
+ for (auto &col : table.GetColumns().Physical()) {
209
210
  expected_names.push_back(col.Name());
210
211
  }
211
212
  }
212
213
 
213
214
  auto function_data =
214
- copy_function->function.copy_from_bind(context, *stmt.info, expected_names, bound_insert.expected_types);
215
- auto get = make_uniq<LogicalGet>(GenerateTableIndex(), copy_function->function.copy_from_function,
215
+ copy_function.function.copy_from_bind(context, *stmt.info, expected_names, bound_insert.expected_types);
216
+ auto get = make_uniq<LogicalGet>(GenerateTableIndex(), copy_function.function.copy_from_function,
216
217
  std::move(function_data), bound_insert.expected_types, expected_names);
217
218
  for (idx_t i = 0; i < bound_insert.expected_types.size(); i++) {
218
219
  get->column_ids.push_back(i);