duckdb 0.7.2-dev2507.0 → 0.7.2-dev2552.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 (200) hide show
  1. package/package.json +1 -1
  2. package/src/connection.cpp +1 -1
  3. package/src/duckdb/extension/icu/icu-dateadd.cpp +3 -3
  4. package/src/duckdb/extension/icu/icu-datepart.cpp +3 -3
  5. package/src/duckdb/extension/icu/icu-datesub.cpp +2 -2
  6. package/src/duckdb/extension/icu/icu-datetrunc.cpp +1 -1
  7. package/src/duckdb/extension/icu/icu-extension.cpp +3 -3
  8. package/src/duckdb/extension/icu/icu-list-range.cpp +2 -2
  9. package/src/duckdb/extension/icu/icu-makedate.cpp +1 -1
  10. package/src/duckdb/extension/icu/icu-strptime.cpp +4 -4
  11. package/src/duckdb/extension/icu/icu-table-range.cpp +2 -2
  12. package/src/duckdb/extension/icu/icu-timebucket.cpp +1 -1
  13. package/src/duckdb/extension/icu/icu-timezone.cpp +4 -4
  14. package/src/duckdb/extension/json/json-extension.cpp +6 -6
  15. package/src/duckdb/extension/parquet/parquet-extension.cpp +9 -8
  16. package/src/duckdb/src/catalog/catalog.cpp +166 -127
  17. package/src/duckdb/src/catalog/catalog_entry/copy_function_catalog_entry.cpp +3 -3
  18. package/src/duckdb/src/catalog/catalog_entry/duck_index_entry.cpp +1 -1
  19. package/src/duckdb/src/catalog/catalog_entry/duck_schema_entry.cpp +90 -82
  20. package/src/duckdb/src/catalog/catalog_entry/duck_table_entry.cpp +65 -67
  21. package/src/duckdb/src/catalog/catalog_entry/index_catalog_entry.cpp +3 -3
  22. package/src/duckdb/src/catalog/catalog_entry/pragma_function_catalog_entry.cpp +4 -4
  23. package/src/duckdb/src/catalog/catalog_entry/scalar_function_catalog_entry.cpp +8 -8
  24. package/src/duckdb/src/catalog/catalog_entry/scalar_macro_catalog_entry.cpp +10 -10
  25. package/src/duckdb/src/catalog/catalog_entry/schema_catalog_entry.cpp +6 -6
  26. package/src/duckdb/src/catalog/catalog_entry/sequence_catalog_entry.cpp +6 -6
  27. package/src/duckdb/src/catalog/catalog_entry/table_catalog_entry.cpp +4 -4
  28. package/src/duckdb/src/catalog/catalog_entry/table_function_catalog_entry.cpp +9 -9
  29. package/src/duckdb/src/catalog/catalog_entry/type_catalog_entry.cpp +5 -5
  30. package/src/duckdb/src/catalog/catalog_entry/view_catalog_entry.cpp +23 -23
  31. package/src/duckdb/src/catalog/catalog_entry.cpp +27 -6
  32. package/src/duckdb/src/catalog/catalog_search_path.cpp +2 -2
  33. package/src/duckdb/src/catalog/catalog_set.cpp +84 -87
  34. package/src/duckdb/src/catalog/catalog_transaction.cpp +1 -1
  35. package/src/duckdb/src/catalog/default/default_functions.cpp +1 -1
  36. package/src/duckdb/src/catalog/default/default_schemas.cpp +1 -1
  37. package/src/duckdb/src/catalog/default/default_types.cpp +1 -1
  38. package/src/duckdb/src/catalog/default/default_views.cpp +1 -1
  39. package/src/duckdb/src/catalog/dependency_list.cpp +2 -2
  40. package/src/duckdb/src/catalog/dependency_manager.cpp +9 -10
  41. package/src/duckdb/src/catalog/duck_catalog.cpp +30 -26
  42. package/src/duckdb/src/catalog/similar_catalog_entry.cpp +1 -1
  43. package/src/duckdb/src/common/types.cpp +15 -27
  44. package/src/duckdb/src/execution/operator/join/physical_index_join.cpp +2 -2
  45. package/src/duckdb/src/execution/operator/persistent/physical_batch_insert.cpp +4 -3
  46. package/src/duckdb/src/execution/operator/persistent/physical_export.cpp +19 -18
  47. package/src/duckdb/src/execution/operator/persistent/physical_insert.cpp +5 -5
  48. package/src/duckdb/src/execution/operator/schema/physical_alter.cpp +1 -1
  49. package/src/duckdb/src/execution/operator/schema/physical_create_function.cpp +1 -1
  50. package/src/duckdb/src/execution/operator/schema/physical_create_index.cpp +6 -5
  51. package/src/duckdb/src/execution/operator/schema/physical_create_schema.cpp +1 -1
  52. package/src/duckdb/src/execution/operator/schema/physical_create_sequence.cpp +1 -1
  53. package/src/duckdb/src/execution/operator/schema/physical_create_table.cpp +2 -2
  54. package/src/duckdb/src/execution/operator/schema/physical_create_type.cpp +4 -3
  55. package/src/duckdb/src/execution/operator/schema/physical_create_view.cpp +1 -1
  56. package/src/duckdb/src/execution/operator/schema/physical_detach.cpp +1 -1
  57. package/src/duckdb/src/execution/operator/schema/physical_drop.cpp +2 -2
  58. package/src/duckdb/src/execution/physical_plan/plan_aggregate.cpp +1 -1
  59. package/src/duckdb/src/execution/physical_plan/plan_comparison_join.cpp +4 -4
  60. package/src/duckdb/src/execution/physical_plan/plan_create_table.cpp +4 -3
  61. package/src/duckdb/src/execution/physical_plan/plan_delete.cpp +1 -1
  62. package/src/duckdb/src/execution/physical_plan/plan_insert.cpp +1 -1
  63. package/src/duckdb/src/execution/physical_plan/plan_update.cpp +1 -1
  64. package/src/duckdb/src/function/built_in_functions.cpp +10 -10
  65. package/src/duckdb/src/function/function_binder.cpp +3 -3
  66. package/src/duckdb/src/function/scalar/list/list_aggregates.cpp +5 -6
  67. package/src/duckdb/src/function/scalar/operators/arithmetic.cpp +2 -2
  68. package/src/duckdb/src/function/scalar/sequence/nextval.cpp +9 -8
  69. package/src/duckdb/src/function/scalar/system/aggregate_export.cpp +6 -6
  70. package/src/duckdb/src/function/table/arrow.cpp +5 -5
  71. package/src/duckdb/src/function/table/system/duckdb_columns.cpp +8 -7
  72. package/src/duckdb/src/function/table/system/duckdb_constraints.cpp +14 -14
  73. package/src/duckdb/src/function/table/system/duckdb_databases.cpp +2 -2
  74. package/src/duckdb/src/function/table/system/duckdb_functions.cpp +26 -25
  75. package/src/duckdb/src/function/table/system/duckdb_indexes.cpp +13 -12
  76. package/src/duckdb/src/function/table/system/duckdb_schemas.cpp +7 -7
  77. package/src/duckdb/src/function/table/system/duckdb_sequences.cpp +8 -9
  78. package/src/duckdb/src/function/table/system/duckdb_tables.cpp +10 -9
  79. package/src/duckdb/src/function/table/system/duckdb_types.cpp +13 -13
  80. package/src/duckdb/src/function/table/system/duckdb_views.cpp +11 -10
  81. package/src/duckdb/src/function/table/system/pragma_collations.cpp +2 -2
  82. package/src/duckdb/src/function/table/system/pragma_database_size.cpp +5 -5
  83. package/src/duckdb/src/function/table/system/pragma_storage_info.cpp +3 -3
  84. package/src/duckdb/src/function/table/system/pragma_table_info.cpp +2 -2
  85. package/src/duckdb/src/function/table/table_scan.cpp +39 -37
  86. package/src/duckdb/src/function/table/version/pragma_version.cpp +2 -2
  87. package/src/duckdb/src/function/udf_function.cpp +2 -2
  88. package/src/duckdb/src/include/duckdb/catalog/catalog.hpp +122 -81
  89. package/src/duckdb/src/include/duckdb/catalog/catalog_entry/aggregate_function_catalog_entry.hpp +2 -3
  90. package/src/duckdb/src/include/duckdb/catalog/catalog_entry/collate_catalog_entry.hpp +3 -3
  91. package/src/duckdb/src/include/duckdb/catalog/catalog_entry/copy_function_catalog_entry.hpp +1 -1
  92. package/src/duckdb/src/include/duckdb/catalog/catalog_entry/duck_index_entry.hpp +1 -1
  93. package/src/duckdb/src/include/duckdb/catalog/catalog_entry/duck_schema_entry.hpp +24 -20
  94. package/src/duckdb/src/include/duckdb/catalog/catalog_entry/duck_table_entry.hpp +3 -3
  95. package/src/duckdb/src/include/duckdb/catalog/catalog_entry/index_catalog_entry.hpp +1 -1
  96. package/src/duckdb/src/include/duckdb/catalog/catalog_entry/macro_catalog_entry.hpp +2 -2
  97. package/src/duckdb/src/include/duckdb/catalog/catalog_entry/pragma_function_catalog_entry.hpp +1 -1
  98. package/src/duckdb/src/include/duckdb/catalog/catalog_entry/scalar_function_catalog_entry.hpp +2 -2
  99. package/src/duckdb/src/include/duckdb/catalog/catalog_entry/scalar_macro_catalog_entry.hpp +1 -1
  100. package/src/duckdb/src/include/duckdb/catalog/catalog_entry/schema_catalog_entry.hpp +22 -17
  101. package/src/duckdb/src/include/duckdb/catalog/catalog_entry/sequence_catalog_entry.hpp +1 -1
  102. package/src/duckdb/src/include/duckdb/catalog/catalog_entry/table_catalog_entry.hpp +1 -1
  103. package/src/duckdb/src/include/duckdb/catalog/catalog_entry/table_function_catalog_entry.hpp +2 -2
  104. package/src/duckdb/src/include/duckdb/catalog/catalog_entry/table_macro_catalog_entry.hpp +1 -1
  105. package/src/duckdb/src/include/duckdb/catalog/catalog_entry/type_catalog_entry.hpp +1 -1
  106. package/src/duckdb/src/include/duckdb/catalog/catalog_entry/view_catalog_entry.hpp +3 -3
  107. package/src/duckdb/src/include/duckdb/catalog/catalog_entry.hpp +28 -7
  108. package/src/duckdb/src/include/duckdb/catalog/catalog_set.hpp +20 -19
  109. package/src/duckdb/src/include/duckdb/catalog/duck_catalog.hpp +9 -9
  110. package/src/duckdb/src/include/duckdb/catalog/similar_catalog_entry.hpp +2 -1
  111. package/src/duckdb/src/include/duckdb/catalog/standard_entry.hpp +10 -4
  112. package/src/duckdb/src/include/duckdb/common/enums/on_entry_not_found.hpp +17 -0
  113. package/src/duckdb/src/include/duckdb/common/types.hpp +3 -4
  114. package/src/duckdb/src/include/duckdb/function/function_serialization.hpp +4 -4
  115. package/src/duckdb/src/include/duckdb/function/scalar_function.hpp +3 -2
  116. package/src/duckdb/src/include/duckdb/function/table/table_scan.hpp +5 -4
  117. package/src/duckdb/src/include/duckdb/function/table_function.hpp +28 -15
  118. package/src/duckdb/src/include/duckdb/main/attached_database.hpp +2 -0
  119. package/src/duckdb/src/include/duckdb/main/client_context.hpp +1 -1
  120. package/src/duckdb/src/include/duckdb/main/database_manager.hpp +3 -2
  121. package/src/duckdb/src/include/duckdb/parser/expression/bound_expression.hpp +2 -0
  122. package/src/duckdb/src/include/duckdb/parser/keyword_helper.hpp +2 -2
  123. package/src/duckdb/src/include/duckdb/parser/parsed_data/alter_info.hpp +7 -5
  124. package/src/duckdb/src/include/duckdb/parser/parsed_data/alter_table_info.hpp +1 -1
  125. package/src/duckdb/src/include/duckdb/parser/parsed_data/create_table_info.hpp +1 -1
  126. package/src/duckdb/src/include/duckdb/parser/parsed_data/create_view_info.hpp +1 -1
  127. package/src/duckdb/src/include/duckdb/parser/parsed_data/detach_info.hpp +3 -2
  128. package/src/duckdb/src/include/duckdb/parser/parsed_data/drop_info.hpp +5 -5
  129. package/src/duckdb/src/include/duckdb/parser/parsed_data/parse_info.hpp +13 -0
  130. package/src/duckdb/src/include/duckdb/parser/tableref.hpp +5 -2
  131. package/src/duckdb/src/include/duckdb/parser/transformer.hpp +2 -0
  132. package/src/duckdb/src/include/duckdb/planner/binder.hpp +2 -2
  133. package/src/duckdb/src/include/duckdb/planner/expression_binder/base_select_binder.hpp +1 -2
  134. package/src/duckdb/src/include/duckdb/planner/expression_binder.hpp +4 -7
  135. package/src/duckdb/src/include/duckdb/planner/operator/logical_get.hpp +1 -1
  136. package/src/duckdb/src/include/duckdb/transaction/transaction.hpp +12 -0
  137. package/src/duckdb/src/main/attached_database.cpp +12 -6
  138. package/src/duckdb/src/main/capi/table_function-c.cpp +17 -16
  139. package/src/duckdb/src/main/client_context.cpp +12 -11
  140. package/src/duckdb/src/main/database_manager.cpp +13 -12
  141. package/src/duckdb/src/optimizer/join_order/cardinality_estimator.cpp +1 -2
  142. package/src/duckdb/src/parser/parsed_data/alter_info.cpp +3 -3
  143. package/src/duckdb/src/parser/parsed_data/alter_scalar_function_info.cpp +2 -2
  144. package/src/duckdb/src/parser/parsed_data/alter_table_function_info.cpp +2 -2
  145. package/src/duckdb/src/parser/parsed_data/alter_table_info.cpp +9 -9
  146. package/src/duckdb/src/parser/parsed_data/create_scalar_function_info.cpp +2 -2
  147. package/src/duckdb/src/parser/parsed_data/create_table_function_info.cpp +2 -2
  148. package/src/duckdb/src/parser/parsed_data/create_table_info.cpp +2 -2
  149. package/src/duckdb/src/parser/parsed_data/create_view_info.cpp +2 -2
  150. package/src/duckdb/src/parser/transform/statement/transform_alter_sequence.cpp +3 -2
  151. package/src/duckdb/src/parser/transform/statement/transform_alter_table.cpp +5 -1
  152. package/src/duckdb/src/parser/transform/statement/transform_detach.cpp +1 -1
  153. package/src/duckdb/src/parser/transform/statement/transform_drop.cpp +1 -1
  154. package/src/duckdb/src/parser/transform/statement/transform_rename.cpp +1 -1
  155. package/src/duckdb/src/planner/binder/expression/bind_aggregate_expression.cpp +26 -27
  156. package/src/duckdb/src/planner/binder/expression/bind_between_expression.cpp +17 -17
  157. package/src/duckdb/src/planner/binder/expression/bind_case_expression.cpp +9 -9
  158. package/src/duckdb/src/planner/binder/expression/bind_cast_expression.cpp +6 -6
  159. package/src/duckdb/src/planner/binder/expression/bind_collate_expression.cpp +6 -6
  160. package/src/duckdb/src/planner/binder/expression/bind_columnref_expression.cpp +2 -2
  161. package/src/duckdb/src/planner/binder/expression/bind_comparison_expression.cpp +21 -21
  162. package/src/duckdb/src/planner/binder/expression/bind_conjunction_expression.cpp +2 -3
  163. package/src/duckdb/src/planner/binder/expression/bind_function_expression.cpp +33 -36
  164. package/src/duckdb/src/planner/binder/expression/bind_macro_expression.cpp +5 -5
  165. package/src/duckdb/src/planner/binder/expression/bind_operator_expression.cpp +23 -23
  166. package/src/duckdb/src/planner/binder/expression/bind_subquery_expression.cpp +4 -4
  167. package/src/duckdb/src/planner/binder/expression/bind_unnest_expression.cpp +7 -7
  168. package/src/duckdb/src/planner/binder/expression/bind_window_expression.cpp +23 -23
  169. package/src/duckdb/src/planner/binder/query_node/bind_table_macro_node.cpp +4 -4
  170. package/src/duckdb/src/planner/binder/statement/bind_copy.cpp +14 -13
  171. package/src/duckdb/src/planner/binder/statement/bind_create.cpp +36 -35
  172. package/src/duckdb/src/planner/binder/statement/bind_create_table.cpp +3 -3
  173. package/src/duckdb/src/planner/binder/statement/bind_delete.cpp +1 -1
  174. package/src/duckdb/src/planner/binder/statement/bind_drop.cpp +4 -4
  175. package/src/duckdb/src/planner/binder/statement/bind_export.cpp +10 -10
  176. package/src/duckdb/src/planner/binder/statement/bind_insert.cpp +2 -2
  177. package/src/duckdb/src/planner/binder/statement/bind_pragma.cpp +4 -4
  178. package/src/duckdb/src/planner/binder/statement/bind_simple.cpp +5 -4
  179. package/src/duckdb/src/planner/binder/statement/bind_update.cpp +1 -1
  180. package/src/duckdb/src/planner/binder/tableref/bind_basetableref.cpp +3 -3
  181. package/src/duckdb/src/planner/binder/tableref/bind_table_function.cpp +10 -12
  182. package/src/duckdb/src/planner/binder.cpp +2 -2
  183. package/src/duckdb/src/planner/expression/bound_expression.cpp +11 -2
  184. package/src/duckdb/src/planner/operator/logical_copy_to_file.cpp +2 -5
  185. package/src/duckdb/src/planner/operator/logical_create.cpp +2 -1
  186. package/src/duckdb/src/planner/operator/logical_create_index.cpp +2 -2
  187. package/src/duckdb/src/planner/operator/logical_delete.cpp +2 -2
  188. package/src/duckdb/src/planner/operator/logical_get.cpp +1 -1
  189. package/src/duckdb/src/planner/operator/logical_insert.cpp +2 -7
  190. package/src/duckdb/src/planner/operator/logical_update.cpp +2 -6
  191. package/src/duckdb/src/planner/parsed_data/bound_create_table_info.cpp +2 -2
  192. package/src/duckdb/src/planner/pragma_handler.cpp +3 -4
  193. package/src/duckdb/src/storage/checkpoint_manager.cpp +46 -46
  194. package/src/duckdb/src/storage/data_table.cpp +3 -6
  195. package/src/duckdb/src/storage/table/update_segment.cpp +1 -1
  196. package/src/duckdb/src/storage/wal_replay.cpp +28 -30
  197. package/src/duckdb/src/storage/write_ahead_log.cpp +8 -8
  198. package/src/duckdb/src/transaction/cleanup_state.cpp +1 -1
  199. package/src/duckdb/src/transaction/commit_state.cpp +3 -4
  200. package/src/duckdb/src/transaction/transaction_context.cpp +1 -1
@@ -25,6 +25,8 @@ struct CTableFunctionInfo : public TableFunctionInfo {
25
25
  };
26
26
 
27
27
  struct CTableBindData : public TableFunctionData {
28
+ CTableBindData(CTableFunctionInfo &info) : info(info) {
29
+ }
28
30
  ~CTableBindData() {
29
31
  if (bind_data && delete_callback) {
30
32
  delete_callback(bind_data);
@@ -33,7 +35,7 @@ struct CTableBindData : public TableFunctionData {
33
35
  delete_callback = nullptr;
34
36
  }
35
37
 
36
- CTableFunctionInfo *info = nullptr;
38
+ CTableFunctionInfo &info;
37
39
  void *bind_data = nullptr;
38
40
  duckdb_delete_callback_t delete_callback = nullptr;
39
41
  unique_ptr<NodeStatistics> stats;
@@ -84,14 +86,14 @@ struct CTableLocalInitData : public LocalTableFunctionState {
84
86
 
85
87
  struct CTableInternalInitInfo {
86
88
  CTableInternalInitInfo(const CTableBindData &bind_data, CTableInitData &init_data,
87
- const vector<column_t> &column_ids, TableFilterSet *filters)
89
+ const vector<column_t> &column_ids, optional_ptr<TableFilterSet> filters)
88
90
  : bind_data(bind_data), init_data(init_data), column_ids(column_ids), filters(filters), success(true) {
89
91
  }
90
92
 
91
93
  const CTableBindData &bind_data;
92
94
  CTableInitData &init_data;
93
95
  const vector<column_t> &column_ids;
94
- TableFilterSet *filters;
96
+ optional_ptr<TableFilterSet> filters;
95
97
  bool success;
96
98
  string error;
97
99
  };
@@ -110,16 +112,15 @@ struct CTableInternalFunctionInfo {
110
112
 
111
113
  unique_ptr<FunctionData> CTableFunctionBind(ClientContext &context, TableFunctionBindInput &input,
112
114
  vector<LogicalType> &return_types, vector<string> &names) {
113
- auto info = (CTableFunctionInfo *)input.info;
114
- D_ASSERT(info->bind && info->function && info->init);
115
- auto result = make_uniq<CTableBindData>();
116
- CTableInternalBindInfo bind_info(context, input, return_types, names, *result, *info);
117
- info->bind(&bind_info);
115
+ auto &info = input.info->Cast<CTableFunctionInfo>();
116
+ D_ASSERT(info.bind && info.function && info.init);
117
+ auto result = make_uniq<CTableBindData>(info);
118
+ CTableInternalBindInfo bind_info(context, input, return_types, names, *result, info);
119
+ info.bind(&bind_info);
118
120
  if (!bind_info.success) {
119
121
  throw Exception(bind_info.error);
120
122
  }
121
123
 
122
- result->info = info;
123
124
  return std::move(result);
124
125
  }
125
126
 
@@ -128,7 +129,7 @@ unique_ptr<GlobalTableFunctionState> CTableFunctionInit(ClientContext &context,
128
129
  auto result = make_uniq<CTableGlobalInitData>();
129
130
 
130
131
  CTableInternalInitInfo init_info(bind_data, result->init_data, data_p.column_ids, data_p.filters);
131
- bind_data.info->init(&init_info);
132
+ bind_data.info.init(&init_info);
132
133
  if (!init_info.success) {
133
134
  throw Exception(init_info.error);
134
135
  }
@@ -139,12 +140,12 @@ unique_ptr<LocalTableFunctionState> CTableFunctionLocalInit(ExecutionContext &co
139
140
  GlobalTableFunctionState *gstate) {
140
141
  auto &bind_data = data_p.bind_data->Cast<CTableBindData>();
141
142
  auto result = make_uniq<CTableLocalInitData>();
142
- if (!bind_data.info->local_init) {
143
+ if (!bind_data.info.local_init) {
143
144
  return std::move(result);
144
145
  }
145
146
 
146
147
  CTableInternalInitInfo init_info(bind_data, result->init_data, data_p.column_ids, data_p.filters);
147
- bind_data.info->local_init(&init_info);
148
+ bind_data.info.local_init(&init_info);
148
149
  if (!init_info.success) {
149
150
  throw Exception(init_info.error);
150
151
  }
@@ -164,7 +165,7 @@ void CTableFunction(ClientContext &context, TableFunctionInput &data_p, DataChun
164
165
  auto &global_data = (CTableGlobalInitData &)*data_p.global_state;
165
166
  auto &local_data = (CTableLocalInitData &)*data_p.local_state;
166
167
  CTableInternalFunctionInfo function_info(bind_data, global_data.init_data, local_data.init_data);
167
- bind_data.info->function(&function_info, reinterpret_cast<duckdb_data_chunk>(&output));
168
+ bind_data.info.function(&function_info, reinterpret_cast<duckdb_data_chunk>(&output));
168
169
  if (!function_info.success) {
169
170
  throw Exception(function_info.error);
170
171
  }
@@ -288,7 +289,7 @@ duckdb_state duckdb_register_table_function(duckdb_connection connection, duckdb
288
289
  duckdb::CreateTableFunctionInfo tf_info(*tf);
289
290
 
290
291
  // create the function in the catalog
291
- catalog.CreateTableFunction(*con->context, &tf_info);
292
+ catalog.CreateTableFunction(*con->context, tf_info);
292
293
  });
293
294
  return DuckDBSuccess;
294
295
  }
@@ -380,7 +381,7 @@ void *duckdb_init_get_extra_info(duckdb_init_info info) {
380
381
  return nullptr;
381
382
  }
382
383
  auto init_info = (duckdb::CTableInternalInitInfo *)info;
383
- return init_info->bind_data.info->extra_info;
384
+ return init_info->bind_data.info.extra_info;
384
385
  }
385
386
 
386
387
  void *duckdb_init_get_bind_data(duckdb_init_info info) {
@@ -444,7 +445,7 @@ void *duckdb_function_get_extra_info(duckdb_function_info info) {
444
445
  return nullptr;
445
446
  }
446
447
  auto function_info = (duckdb::CTableInternalFunctionInfo *)info;
447
- return function_info->bind_data.info->extra_info;
448
+ return function_info->bind_data.info.extra_info;
448
449
  }
449
450
 
450
451
  void *duckdb_function_get_bind_data(duckdb_function_info info) {
@@ -916,15 +916,15 @@ void ClientContext::DisableProfiling() {
916
916
  config.enable_profiler = false;
917
917
  }
918
918
 
919
- void ClientContext::RegisterFunction(CreateFunctionInfo *info) {
919
+ void ClientContext::RegisterFunction(CreateFunctionInfo &info) {
920
920
  RunFunctionInTransaction([&]() {
921
- auto existing_function =
922
- Catalog::GetEntry<ScalarFunctionCatalogEntry>(*this, INVALID_CATALOG, info->schema, info->name, true);
921
+ auto existing_function = Catalog::GetEntry<ScalarFunctionCatalogEntry>(*this, INVALID_CATALOG, info.schema,
922
+ info.name, OnEntryNotFound::RETURN_NULL);
923
923
  if (existing_function) {
924
- auto new_info = (CreateScalarFunctionInfo *)info;
925
- if (new_info->functions.MergeFunctionSet(existing_function->functions)) {
924
+ auto &new_info = (CreateScalarFunctionInfo &)info;
925
+ if (new_info.functions.MergeFunctionSet(existing_function->functions)) {
926
926
  // function info was updated from catalog entry, rewrite is needed
927
- info->on_conflict = OnCreateConflict::REPLACE_ON_CONFLICT;
927
+ info.on_conflict = OnCreateConflict::REPLACE_ON_CONFLICT;
928
928
  }
929
929
  }
930
930
  // create function
@@ -978,7 +978,8 @@ unique_ptr<TableDescription> ClientContext::TableInfo(const string &schema_name,
978
978
  unique_ptr<TableDescription> result;
979
979
  RunFunctionInTransaction([&]() {
980
980
  // obtain the table info
981
- auto table = Catalog::GetEntry<TableCatalogEntry>(*this, INVALID_CATALOG, schema_name, table_name, true);
981
+ auto table = Catalog::GetEntry<TableCatalogEntry>(*this, INVALID_CATALOG, schema_name, table_name,
982
+ OnEntryNotFound::RETURN_NULL);
982
983
  if (!table) {
983
984
  return;
984
985
  }
@@ -995,18 +996,18 @@ unique_ptr<TableDescription> ClientContext::TableInfo(const string &schema_name,
995
996
 
996
997
  void ClientContext::Append(TableDescription &description, ColumnDataCollection &collection) {
997
998
  RunFunctionInTransaction([&]() {
998
- auto table_entry =
999
+ auto &table_entry =
999
1000
  Catalog::GetEntry<TableCatalogEntry>(*this, INVALID_CATALOG, description.schema, description.table);
1000
1001
  // verify that the table columns and types match up
1001
- if (description.columns.size() != table_entry->GetColumns().PhysicalColumnCount()) {
1002
+ if (description.columns.size() != table_entry.GetColumns().PhysicalColumnCount()) {
1002
1003
  throw Exception("Failed to append: table entry has different number of columns!");
1003
1004
  }
1004
1005
  for (idx_t i = 0; i < description.columns.size(); i++) {
1005
- if (description.columns[i].Type() != table_entry->GetColumns().GetColumn(PhysicalIndex(i)).Type()) {
1006
+ if (description.columns[i].Type() != table_entry.GetColumns().GetColumn(PhysicalIndex(i)).Type()) {
1006
1007
  throw Exception("Failed to append: table entry has different number of columns!");
1007
1008
  }
1008
1009
  }
1009
- table_entry->GetStorage().LocalAppend(*table_entry, *this, collection);
1010
+ table_entry.GetStorage().LocalAppend(table_entry, *this, collection);
1010
1011
  });
1011
1012
  }
1012
1013
 
@@ -27,7 +27,7 @@ optional_ptr<AttachedDatabase> DatabaseManager::GetDatabase(ClientContext &conte
27
27
  if (StringUtil::Lower(name) == TEMP_CATALOG) {
28
28
  return context.client_data->temporary_objects.get();
29
29
  }
30
- return (AttachedDatabase *)databases->GetEntry(context, name);
30
+ return (AttachedDatabase *)databases->GetEntry(context, name).get();
31
31
  }
32
32
 
33
33
  void DatabaseManager::AddDatabase(ClientContext &context, unique_ptr<AttachedDatabase> db_instance) {
@@ -42,9 +42,9 @@ void DatabaseManager::AddDatabase(ClientContext &context, unique_ptr<AttachedDat
42
42
  }
43
43
  }
44
44
 
45
- void DatabaseManager::DetachDatabase(ClientContext &context, const string &name, bool if_exists) {
45
+ void DatabaseManager::DetachDatabase(ClientContext &context, const string &name, OnEntryNotFound if_not_found) {
46
46
  if (!databases->DropEntry(context, name, false, true)) {
47
- if (!if_exists) {
47
+ if (if_not_found == OnEntryNotFound::THROW_EXCEPTION) {
48
48
  throw BinderException("Failed to detach database with name \"%s\": database not found", name);
49
49
  }
50
50
  }
@@ -52,17 +52,18 @@ void DatabaseManager::DetachDatabase(ClientContext &context, const string &name,
52
52
 
53
53
  optional_ptr<AttachedDatabase> DatabaseManager::GetDatabaseFromPath(ClientContext &context, const string &path) {
54
54
  auto databases = GetDatabases(context);
55
- for (auto db : databases) {
56
- if (db->IsSystem()) {
55
+ for (auto &db_ref : databases) {
56
+ auto &db = db_ref.get();
57
+ if (db.IsSystem()) {
57
58
  continue;
58
59
  }
59
- auto &catalog = Catalog::GetCatalog(*db);
60
+ auto &catalog = Catalog::GetCatalog(db);
60
61
  if (catalog.InMemory()) {
61
62
  continue;
62
63
  }
63
64
  auto db_path = catalog.GetDBPath();
64
65
  if (StringUtil::CIEquals(path, db_path)) {
65
- return db;
66
+ return &db;
66
67
  }
67
68
  }
68
69
  return nullptr;
@@ -81,11 +82,11 @@ const string &DatabaseManager::GetDefaultDatabase(ClientContext &context) {
81
82
  return default_entry.catalog;
82
83
  }
83
84
 
84
- vector<optional_ptr<AttachedDatabase>> DatabaseManager::GetDatabases(ClientContext &context) {
85
- vector<optional_ptr<AttachedDatabase>> result;
86
- databases->Scan(context, [&](CatalogEntry *entry) { result.push_back((AttachedDatabase *)entry); });
87
- result.push_back(system.get());
88
- result.push_back(context.client_data->temporary_objects.get());
85
+ vector<reference<AttachedDatabase>> DatabaseManager::GetDatabases(ClientContext &context) {
86
+ vector<reference<AttachedDatabase>> result;
87
+ databases->Scan(context, [&](CatalogEntry &entry) { result.push_back(entry.Cast<AttachedDatabase>()); });
88
+ result.push_back(*system);
89
+ result.push_back(*context.client_data->temporary_objects);
89
90
  return result;
90
91
  }
91
92
 
@@ -15,8 +15,7 @@ namespace duckdb {
15
15
  static optional_ptr<TableCatalogEntry> GetCatalogTableEntry(LogicalOperator &op) {
16
16
  D_ASSERT(op.type == LogicalOperatorType::LOGICAL_GET);
17
17
  auto &get = op.Cast<LogicalGet>();
18
- TableCatalogEntry *entry = get.GetTable();
19
- return entry;
18
+ return get.GetTable();
20
19
  }
21
20
 
22
21
  // The filter was made on top of a logical sample or other projection,
@@ -7,8 +7,8 @@
7
7
 
8
8
  namespace duckdb {
9
9
 
10
- AlterInfo::AlterInfo(AlterType type, string catalog_p, string schema_p, string name_p, bool if_exists)
11
- : type(type), if_exists(if_exists), catalog(std::move(catalog_p)), schema(std::move(schema_p)),
10
+ AlterInfo::AlterInfo(AlterType type, string catalog_p, string schema_p, string name_p, OnEntryNotFound if_not_found)
11
+ : type(type), if_not_found(if_not_found), catalog(std::move(catalog_p)), schema(std::move(schema_p)),
12
12
  name(std::move(name_p)), allow_internal(false) {
13
13
  }
14
14
 
@@ -53,7 +53,7 @@ AlterEntryData AlterInfo::GetAlterEntryData() const {
53
53
  data.catalog = catalog;
54
54
  data.schema = schema;
55
55
  data.name = name;
56
- data.if_exists = if_exists;
56
+ data.if_not_found = if_not_found;
57
57
  return data;
58
58
  }
59
59
 
@@ -10,7 +10,7 @@ namespace duckdb {
10
10
  //===--------------------------------------------------------------------===//
11
11
  AlterScalarFunctionInfo::AlterScalarFunctionInfo(AlterScalarFunctionType type, AlterEntryData data)
12
12
  : AlterInfo(AlterType::ALTER_SCALAR_FUNCTION, std::move(data.catalog), std::move(data.schema), std::move(data.name),
13
- data.if_exists),
13
+ data.if_not_found),
14
14
  alter_scalar_function_type(type) {
15
15
  }
16
16
  AlterScalarFunctionInfo::~AlterScalarFunctionInfo() {
@@ -25,7 +25,7 @@ void AlterScalarFunctionInfo::Serialize(FieldWriter &writer) const {
25
25
  writer.WriteString(catalog);
26
26
  writer.WriteString(schema);
27
27
  writer.WriteString(name);
28
- writer.WriteField(if_exists);
28
+ writer.WriteField(if_not_found);
29
29
  }
30
30
 
31
31
  unique_ptr<AlterInfo> AlterScalarFunctionInfo::Deserialize(FieldReader &reader) {
@@ -10,7 +10,7 @@ namespace duckdb {
10
10
  //===--------------------------------------------------------------------===//
11
11
  AlterTableFunctionInfo::AlterTableFunctionInfo(AlterTableFunctionType type, AlterEntryData data)
12
12
  : AlterInfo(AlterType::ALTER_TABLE_FUNCTION, std::move(data.catalog), std::move(data.schema), std::move(data.name),
13
- data.if_exists),
13
+ data.if_not_found),
14
14
  alter_table_function_type(type) {
15
15
  }
16
16
  AlterTableFunctionInfo::~AlterTableFunctionInfo() {
@@ -25,7 +25,7 @@ void AlterTableFunctionInfo::Serialize(FieldWriter &writer) const {
25
25
  writer.WriteString(catalog);
26
26
  writer.WriteString(schema);
27
27
  writer.WriteString(name);
28
- writer.WriteField(if_exists);
28
+ writer.WriteField(if_not_found);
29
29
  }
30
30
 
31
31
  unique_ptr<AlterInfo> AlterTableFunctionInfo::Deserialize(FieldReader &reader) {
@@ -10,9 +10,9 @@ namespace duckdb {
10
10
  //===--------------------------------------------------------------------===//
11
11
  ChangeOwnershipInfo::ChangeOwnershipInfo(CatalogType entry_catalog_type, string entry_catalog_p, string entry_schema_p,
12
12
  string entry_name_p, string owner_schema_p, string owner_name_p,
13
- bool if_exists)
13
+ OnEntryNotFound if_not_found)
14
14
  : AlterInfo(AlterType::CHANGE_OWNERSHIP, std::move(entry_catalog_p), std::move(entry_schema_p),
15
- std::move(entry_name_p), if_exists),
15
+ std::move(entry_name_p), if_not_found),
16
16
  entry_catalog_type(entry_catalog_type), owner_schema(std::move(owner_schema_p)),
17
17
  owner_name(std::move(owner_name_p)) {
18
18
  }
@@ -23,7 +23,7 @@ CatalogType ChangeOwnershipInfo::GetCatalogType() const {
23
23
 
24
24
  unique_ptr<AlterInfo> ChangeOwnershipInfo::Copy() const {
25
25
  return make_uniq_base<AlterInfo, ChangeOwnershipInfo>(entry_catalog_type, catalog, schema, name, owner_schema,
26
- owner_name, if_exists);
26
+ owner_name, if_not_found);
27
27
  }
28
28
 
29
29
  void ChangeOwnershipInfo::Serialize(FieldWriter &writer) const {
@@ -35,7 +35,7 @@ void ChangeOwnershipInfo::Serialize(FieldWriter &writer) const {
35
35
  //===--------------------------------------------------------------------===//
36
36
  AlterTableInfo::AlterTableInfo(AlterTableType type, AlterEntryData data)
37
37
  : AlterInfo(AlterType::ALTER_TABLE, std::move(data.catalog), std::move(data.schema), std::move(data.name),
38
- data.if_exists),
38
+ data.if_not_found),
39
39
  alter_table_type(type) {
40
40
  }
41
41
  AlterTableInfo::~AlterTableInfo() {
@@ -50,7 +50,7 @@ void AlterTableInfo::Serialize(FieldWriter &writer) const {
50
50
  writer.WriteString(catalog);
51
51
  writer.WriteString(schema);
52
52
  writer.WriteString(name);
53
- writer.WriteField(if_exists);
53
+ writer.WriteField(if_not_found);
54
54
  SerializeAlterTable(writer);
55
55
  }
56
56
 
@@ -60,7 +60,7 @@ unique_ptr<AlterInfo> AlterTableInfo::Deserialize(FieldReader &reader) {
60
60
  data.catalog = reader.ReadRequired<string>();
61
61
  data.schema = reader.ReadRequired<string>();
62
62
  data.name = reader.ReadRequired<string>();
63
- data.if_exists = reader.ReadRequired<bool>();
63
+ data.if_not_found = reader.ReadRequired<OnEntryNotFound>();
64
64
 
65
65
  unique_ptr<AlterTableInfo> info;
66
66
  switch (type) {
@@ -330,7 +330,7 @@ unique_ptr<AlterInfo> AlterForeignKeyInfo::Deserialize(FieldReader &reader, Alte
330
330
  //===--------------------------------------------------------------------===//
331
331
  AlterViewInfo::AlterViewInfo(AlterViewType type, AlterEntryData data)
332
332
  : AlterInfo(AlterType::ALTER_VIEW, std::move(data.catalog), std::move(data.schema), std::move(data.name),
333
- data.if_exists),
333
+ data.if_not_found),
334
334
  alter_view_type(type) {
335
335
  }
336
336
  AlterViewInfo::~AlterViewInfo() {
@@ -345,7 +345,7 @@ void AlterViewInfo::Serialize(FieldWriter &writer) const {
345
345
  writer.WriteString(catalog);
346
346
  writer.WriteString(schema);
347
347
  writer.WriteString(name);
348
- writer.WriteField<bool>(if_exists);
348
+ writer.WriteField<OnEntryNotFound>(if_not_found);
349
349
  SerializeAlterView(writer);
350
350
  }
351
351
 
@@ -355,7 +355,7 @@ unique_ptr<AlterInfo> AlterViewInfo::Deserialize(FieldReader &reader) {
355
355
  data.catalog = reader.ReadRequired<string>();
356
356
  data.schema = reader.ReadRequired<string>();
357
357
  data.name = reader.ReadRequired<string>();
358
- data.if_exists = reader.ReadRequired<bool>();
358
+ data.if_not_found = reader.ReadRequired<OnEntryNotFound>();
359
359
  unique_ptr<AlterViewInfo> info;
360
360
  switch (type) {
361
361
  case AlterViewType::RENAME_VIEW:
@@ -27,8 +27,8 @@ unique_ptr<CreateInfo> CreateScalarFunctionInfo::Copy() const {
27
27
  }
28
28
 
29
29
  unique_ptr<AlterInfo> CreateScalarFunctionInfo::GetAlterInfo() const {
30
- return make_uniq_base<AlterInfo, AddScalarFunctionOverloadInfo>(AlterEntryData(catalog, schema, name, true),
31
- functions);
30
+ return make_uniq_base<AlterInfo, AddScalarFunctionOverloadInfo>(
31
+ AlterEntryData(catalog, schema, name, OnEntryNotFound::RETURN_NULL), functions);
32
32
  }
33
33
 
34
34
  } // namespace duckdb
@@ -27,8 +27,8 @@ unique_ptr<CreateInfo> CreateTableFunctionInfo::Copy() const {
27
27
  }
28
28
 
29
29
  unique_ptr<AlterInfo> CreateTableFunctionInfo::GetAlterInfo() const {
30
- return make_uniq_base<AlterInfo, AddTableFunctionOverloadInfo>(AlterEntryData(catalog, schema, name, true),
31
- functions);
30
+ return make_uniq_base<AlterInfo, AddTableFunctionOverloadInfo>(
31
+ AlterEntryData(catalog, schema, name, OnEntryNotFound::RETURN_NULL), functions);
32
32
  }
33
33
 
34
34
  } // namespace duckdb
@@ -12,8 +12,8 @@ CreateTableInfo::CreateTableInfo(string catalog_p, string schema_p, string name_
12
12
  : CreateInfo(CatalogType::TABLE_ENTRY, std::move(schema_p), std::move(catalog_p)), table(std::move(name_p)) {
13
13
  }
14
14
 
15
- CreateTableInfo::CreateTableInfo(SchemaCatalogEntry *schema, string name_p)
16
- : CreateTableInfo(schema->catalog->GetName(), schema->name, std::move(name_p)) {
15
+ CreateTableInfo::CreateTableInfo(SchemaCatalogEntry &schema, string name_p)
16
+ : CreateTableInfo(schema.catalog.GetName(), schema.name, std::move(name_p)) {
17
17
  }
18
18
 
19
19
  void CreateTableInfo::SerializeInternal(Serializer &serializer) const {
@@ -15,8 +15,8 @@ CreateViewInfo::CreateViewInfo(string catalog_p, string schema_p, string view_na
15
15
  view_name(std::move(view_name_p)) {
16
16
  }
17
17
 
18
- CreateViewInfo::CreateViewInfo(SchemaCatalogEntry *schema, string view_name)
19
- : CreateViewInfo(schema->catalog->GetName(), schema->name, std::move(view_name)) {
18
+ CreateViewInfo::CreateViewInfo(SchemaCatalogEntry &schema, string view_name)
19
+ : CreateViewInfo(schema.catalog.GetName(), schema.name, std::move(view_name)) {
20
20
  }
21
21
 
22
22
  unique_ptr<CreateInfo> CreateViewInfo::Copy() const {
@@ -61,13 +61,14 @@ unique_ptr<AlterStatement> Transformer::TransformAlterSequence(duckdb_libpgquery
61
61
  throw InternalException("Wrong argument for %s. Expected either <schema>.<name> or <name>", opt_name);
62
62
  }
63
63
  auto info = make_uniq<ChangeOwnershipInfo>(CatalogType::SEQUENCE_ENTRY, sequence_catalog, sequence_schema,
64
- sequence_name, owner_schema, owner_name, stmt->missing_ok);
64
+ sequence_name, owner_schema, owner_name,
65
+ TransformOnEntryNotFound(stmt->missing_ok));
65
66
  result->info = std::move(info);
66
67
  } else {
67
68
  throw NotImplementedException("ALTER SEQUENCE option not supported yet!");
68
69
  }
69
70
  }
70
- result->info->if_exists = stmt->missing_ok;
71
+ result->info->if_not_found = TransformOnEntryNotFound(stmt->missing_ok);
71
72
  return result;
72
73
  }
73
74
  } // namespace duckdb
@@ -6,6 +6,10 @@
6
6
 
7
7
  namespace duckdb {
8
8
 
9
+ OnEntryNotFound Transformer::TransformOnEntryNotFound(bool missing_ok) {
10
+ return missing_ok ? OnEntryNotFound::RETURN_NULL : OnEntryNotFound::THROW_EXCEPTION;
11
+ }
12
+
9
13
  unique_ptr<AlterStatement> Transformer::TransformAlter(duckdb_libpgquery::PGNode *node) {
10
14
  auto stmt = reinterpret_cast<duckdb_libpgquery::PGAlterTableStmt *>(node);
11
15
  D_ASSERT(stmt);
@@ -21,7 +25,7 @@ unique_ptr<AlterStatement> Transformer::TransformAlter(duckdb_libpgquery::PGNode
21
25
  // first we check the type of ALTER
22
26
  for (auto c = stmt->cmds->head; c != nullptr; c = c->next) {
23
27
  auto command = reinterpret_cast<duckdb_libpgquery::PGAlterTableCmd *>(lfirst(c));
24
- AlterEntryData data(qname.catalog, qname.schema, qname.name, stmt->missing_ok);
28
+ AlterEntryData data(qname.catalog, qname.schema, qname.name, TransformOnEntryNotFound(stmt->missing_ok));
25
29
  // TODO: Include more options for command->subtype
26
30
  switch (command->subtype) {
27
31
  case duckdb_libpgquery::PG_AT_AddColumn: {
@@ -10,7 +10,7 @@ unique_ptr<DetachStatement> Transformer::TransformDetach(duckdb_libpgquery::PGNo
10
10
  auto result = make_uniq<DetachStatement>();
11
11
  auto info = make_uniq<DetachInfo>();
12
12
  info->name = stmt->db_name;
13
- info->if_exists = stmt->missing_ok;
13
+ info->if_not_found = TransformOnEntryNotFound(stmt->missing_ok);
14
14
 
15
15
  result->info = std::move(info);
16
16
  return result;
@@ -80,7 +80,7 @@ unique_ptr<SQLStatement> Transformer::TransformDrop(duckdb_libpgquery::PGNode *n
80
80
  }
81
81
  }
82
82
  info.cascade = stmt->behavior == duckdb_libpgquery::PGDropBehavior::PG_DROP_CASCADE;
83
- info.if_exists = stmt->missing_ok;
83
+ info.if_not_found = TransformOnEntryNotFound(stmt->missing_ok);
84
84
  return std::move(result);
85
85
  }
86
86
 
@@ -13,7 +13,7 @@ unique_ptr<AlterStatement> Transformer::TransformRename(duckdb_libpgquery::PGNod
13
13
  unique_ptr<AlterInfo> info;
14
14
 
15
15
  AlterEntryData data;
16
- data.if_exists = stmt->missing_ok;
16
+ data.if_not_found = TransformOnEntryNotFound(stmt->missing_ok);
17
17
  data.catalog = stmt->relation->catalogname ? stmt->relation->catalogname : INVALID_CATALOG;
18
18
  data.schema = stmt->relation->schemaname ? stmt->relation->schemaname : INVALID_SCHEMA;
19
19
  if (stmt->relation->relname) {
@@ -60,13 +60,13 @@ static Value NegatePercentileValue(const Value &v, const bool desc) {
60
60
  static void NegatePercentileFractions(ClientContext &context, unique_ptr<ParsedExpression> &fractions, bool desc) {
61
61
  D_ASSERT(fractions.get());
62
62
  D_ASSERT(fractions->expression_class == ExpressionClass::BOUND_EXPRESSION);
63
- auto &bound = fractions->Cast<BoundExpression>();
63
+ auto &bound = BoundExpression::GetExpression(*fractions);
64
64
 
65
- if (!bound.expr->IsFoldable()) {
65
+ if (!bound->IsFoldable()) {
66
66
  return;
67
67
  }
68
68
 
69
- Value value = ExpressionExecutor::EvaluateScalar(context, *bound.expr);
69
+ Value value = ExpressionExecutor::EvaluateScalar(context, *bound);
70
70
  if (value.type().id() == LogicalTypeId::LIST) {
71
71
  vector<Value> values;
72
72
  for (const auto &element_val : ListValue::GetChildren(value)) {
@@ -75,14 +75,13 @@ static void NegatePercentileFractions(ClientContext &context, unique_ptr<ParsedE
75
75
  if (values.empty()) {
76
76
  throw BinderException("Empty list in percentile not allowed");
77
77
  }
78
- bound.expr = make_uniq<BoundConstantExpression>(Value::LIST(values));
78
+ bound = make_uniq<BoundConstantExpression>(Value::LIST(values));
79
79
  } else {
80
- bound.expr = make_uniq<BoundConstantExpression>(NegatePercentileValue(value, desc));
80
+ bound = make_uniq<BoundConstantExpression>(NegatePercentileValue(value, desc));
81
81
  }
82
82
  }
83
83
 
84
- BindResult BaseSelectBinder::BindAggregate(FunctionExpression &aggr, optional_ptr<AggregateFunctionCatalogEntry> func,
85
- idx_t depth) {
84
+ BindResult BaseSelectBinder::BindAggregate(FunctionExpression &aggr, AggregateFunctionCatalogEntry &func, idx_t depth) {
86
85
  // first bind the child of the aggregate expression (if any)
87
86
  this->bound_aggregate = true;
88
87
  unique_ptr<Expression> bound_filter;
@@ -138,8 +137,8 @@ BindResult BaseSelectBinder::BindAggregate(FunctionExpression &aggr, optional_pt
138
137
  if (!success) {
139
138
  throw BinderException(error);
140
139
  }
141
- auto &bound_expr = aggr.children[i]->Cast<BoundExpression>();
142
- ExtractCorrelatedExpressions(binder, *bound_expr.expr);
140
+ auto &bound_expr = BoundExpression::GetExpression(*aggr.children[i]);
141
+ ExtractCorrelatedExpressions(binder, *bound_expr);
143
142
  }
144
143
  if (aggr.filter) {
145
144
  bool success = aggregate_binder.BindCorrelatedColumns(aggr.filter);
@@ -147,8 +146,8 @@ BindResult BaseSelectBinder::BindAggregate(FunctionExpression &aggr, optional_pt
147
146
  if (!success) {
148
147
  throw BinderException(error);
149
148
  }
150
- auto &bound_expr = aggr.filter->Cast<BoundExpression>();
151
- ExtractCorrelatedExpressions(binder, *bound_expr.expr);
149
+ auto &bound_expr = BoundExpression::GetExpression(*aggr.filter);
150
+ ExtractCorrelatedExpressions(binder, *bound_expr);
152
151
  }
153
152
  if (aggr.order_bys && !aggr.order_bys->orders.empty()) {
154
153
  for (auto &order : aggr.order_bys->orders) {
@@ -156,8 +155,8 @@ BindResult BaseSelectBinder::BindAggregate(FunctionExpression &aggr, optional_pt
156
155
  if (!success) {
157
156
  throw BinderException(error);
158
157
  }
159
- auto &bound_expr = order.expression->Cast<BoundExpression>();
160
- ExtractCorrelatedExpressions(binder, *bound_expr.expr);
158
+ auto &bound_expr = BoundExpression::GetExpression(*order.expression);
159
+ ExtractCorrelatedExpressions(binder, *bound_expr);
161
160
  }
162
161
  }
163
162
  } else {
@@ -172,8 +171,8 @@ BindResult BaseSelectBinder::BindAggregate(FunctionExpression &aggr, optional_pt
172
171
  }
173
172
 
174
173
  if (aggr.filter) {
175
- auto &child = (BoundExpression &)*aggr.filter;
176
- bound_filter = BoundCastExpression::AddCastToType(context, std::move(child.expr), LogicalType::BOOLEAN);
174
+ auto &child = BoundExpression::GetExpression(*aggr.filter);
175
+ bound_filter = BoundCastExpression::AddCastToType(context, std::move(child), LogicalType::BOOLEAN);
177
176
  }
178
177
 
179
178
  // all children bound successfully
@@ -184,29 +183,29 @@ BindResult BaseSelectBinder::BindAggregate(FunctionExpression &aggr, optional_pt
184
183
 
185
184
  if (ordered_set_agg) {
186
185
  for (auto &order : aggr.order_bys->orders) {
187
- auto &child = (BoundExpression &)*order.expression;
188
- types.push_back(child.expr->return_type);
189
- arguments.push_back(child.expr->return_type);
190
- children.push_back(std::move(child.expr));
186
+ auto &child = BoundExpression::GetExpression(*order.expression);
187
+ types.push_back(child->return_type);
188
+ arguments.push_back(child->return_type);
189
+ children.push_back(std::move(child));
191
190
  }
192
191
  aggr.order_bys->orders.clear();
193
192
  }
194
193
 
195
194
  for (idx_t i = 0; i < aggr.children.size(); i++) {
196
- auto &child = (BoundExpression &)*aggr.children[i];
197
- types.push_back(child.expr->return_type);
198
- arguments.push_back(child.expr->return_type);
199
- children.push_back(std::move(child.expr));
195
+ auto &child = BoundExpression::GetExpression(*aggr.children[i]);
196
+ types.push_back(child->return_type);
197
+ arguments.push_back(child->return_type);
198
+ children.push_back(std::move(child));
200
199
  }
201
200
 
202
201
  // bind the aggregate
203
202
  FunctionBinder function_binder(context);
204
- idx_t best_function = function_binder.BindFunction(func->name, func->functions, types, error);
203
+ idx_t best_function = function_binder.BindFunction(func.name, func.functions, types, error);
205
204
  if (best_function == DConstants::INVALID_INDEX) {
206
205
  throw BinderException(binder.FormatError(aggr, error));
207
206
  }
208
207
  // found a matching function!
209
- auto bound_function = func->functions.GetFunctionByOffset(best_function);
208
+ auto bound_function = func.functions.GetFunctionByOffset(best_function);
210
209
 
211
210
  // Bind any sort columns, unless the aggregate is order-insensitive
212
211
  unique_ptr<BoundOrderModifier> order_bys;
@@ -214,10 +213,10 @@ BindResult BaseSelectBinder::BindAggregate(FunctionExpression &aggr, optional_pt
214
213
  order_bys = make_uniq<BoundOrderModifier>();
215
214
  auto &config = DBConfig::GetConfig(context);
216
215
  for (auto &order : aggr.order_bys->orders) {
217
- auto &order_expr = (BoundExpression &)*order.expression;
216
+ auto &order_expr = BoundExpression::GetExpression(*order.expression);
218
217
  const auto sense = config.ResolveOrder(order.type);
219
218
  const auto null_order = config.ResolveNullOrder(sense, order.null_order);
220
- order_bys->orders.emplace_back(sense, null_order, std::move(order_expr.expr));
219
+ order_bys->orders.emplace_back(sense, null_order, std::move(order_expr));
221
220
  }
222
221
  }
223
222