duckdb 0.7.2-dev614.0 → 0.7.2-dev717.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 (58) hide show
  1. package/package.json +1 -1
  2. package/src/duckdb/extension/json/include/json_functions.hpp +1 -0
  3. package/src/duckdb/extension/json/json_functions.cpp +11 -4
  4. package/src/duckdb/src/catalog/catalog_entry/table_catalog_entry.cpp +3 -3
  5. package/src/duckdb/src/catalog/dependency_list.cpp +12 -0
  6. package/src/duckdb/src/common/string_util.cpp +4 -1
  7. package/src/duckdb/src/common/types/column_data_collection_segment.cpp +11 -6
  8. package/src/duckdb/src/common/vector_operations/vector_cast.cpp +2 -1
  9. package/src/duckdb/src/execution/aggregate_hashtable.cpp +10 -5
  10. package/src/duckdb/src/execution/expression_executor/execute_cast.cpp +2 -1
  11. package/src/duckdb/src/execution/index/art/art.cpp +5 -5
  12. package/src/duckdb/src/execution/operator/aggregate/physical_window.cpp +3 -0
  13. package/src/duckdb/src/execution/operator/helper/physical_vacuum.cpp +3 -0
  14. package/src/duckdb/src/execution/operator/persistent/base_csv_reader.cpp +3 -0
  15. package/src/duckdb/src/execution/partitionable_hashtable.cpp +14 -2
  16. package/src/duckdb/src/execution/physical_plan/plan_comparison_join.cpp +3 -0
  17. package/src/duckdb/src/function/aggregate/distributive/bitstring_agg.cpp +22 -7
  18. package/src/duckdb/src/function/aggregate/distributive/first.cpp +1 -0
  19. package/src/duckdb/src/function/aggregate/holistic/approximate_quantile.cpp +5 -2
  20. package/src/duckdb/src/function/cast/cast_function_set.cpp +1 -1
  21. package/src/duckdb/src/function/cast/enum_casts.cpp +25 -3
  22. package/src/duckdb/src/function/cast/list_casts.cpp +17 -4
  23. package/src/duckdb/src/function/cast/map_cast.cpp +5 -2
  24. package/src/duckdb/src/function/cast/string_cast.cpp +36 -10
  25. package/src/duckdb/src/function/cast/struct_cast.cpp +23 -3
  26. package/src/duckdb/src/function/cast/union_casts.cpp +33 -7
  27. package/src/duckdb/src/function/table/checkpoint.cpp +5 -1
  28. package/src/duckdb/src/function/table/system/duckdb_constraints.cpp +2 -2
  29. package/src/duckdb/src/function/table/version/pragma_version.cpp +2 -2
  30. package/src/duckdb/src/include/duckdb/catalog/dependency_list.hpp +3 -0
  31. package/src/duckdb/src/include/duckdb/common/optional_ptr.hpp +45 -0
  32. package/src/duckdb/src/include/duckdb/execution/aggregate_hashtable.hpp +1 -0
  33. package/src/duckdb/src/include/duckdb/execution/index/art/art.hpp +2 -2
  34. package/src/duckdb/src/include/duckdb/execution/partitionable_hashtable.hpp +3 -0
  35. package/src/duckdb/src/include/duckdb/function/cast/bound_cast_data.hpp +84 -0
  36. package/src/duckdb/src/include/duckdb/function/cast/cast_function_set.hpp +2 -2
  37. package/src/duckdb/src/include/duckdb/function/cast/default_casts.hpp +28 -64
  38. package/src/duckdb/src/include/duckdb/parser/transformer.hpp +3 -0
  39. package/src/duckdb/src/include/duckdb/storage/data_table.hpp +2 -2
  40. package/src/duckdb/src/include/duckdb/storage/index.hpp +4 -3
  41. package/src/duckdb/src/include/duckdb/storage/statistics/distinct_statistics.hpp +2 -0
  42. package/src/duckdb/src/include/duckdb/transaction/local_storage.hpp +2 -2
  43. package/src/duckdb/src/optimizer/pushdown/pushdown_aggregate.cpp +33 -5
  44. package/src/duckdb/src/optimizer/rule/move_constants.cpp +8 -2
  45. package/src/duckdb/src/parser/transform/expression/transform_function.cpp +17 -1
  46. package/src/duckdb/src/parser/transform/statement/transform_select_node.cpp +1 -2
  47. package/src/duckdb/src/planner/binder/query_node/bind_select_node.cpp +25 -13
  48. package/src/duckdb/src/planner/binder/statement/bind_copy.cpp +5 -3
  49. package/src/duckdb/src/planner/binder/statement/bind_create_table.cpp +7 -0
  50. package/src/duckdb/src/planner/binder/statement/bind_insert.cpp +10 -6
  51. package/src/duckdb/src/planner/binder/statement/bind_update.cpp +3 -1
  52. package/src/duckdb/src/planner/expression_binder/having_binder.cpp +3 -0
  53. package/src/duckdb/src/storage/data_table.cpp +15 -13
  54. package/src/duckdb/src/storage/index.cpp +12 -1
  55. package/src/duckdb/src/storage/local_storage.cpp +20 -23
  56. package/src/duckdb/src/storage/statistics/column_statistics.cpp +1 -2
  57. package/src/duckdb/src/storage/statistics/distinct_statistics.cpp +4 -0
  58. package/src/duckdb/src/storage/table/row_group.cpp +6 -1
@@ -3,6 +3,7 @@
3
3
  #include "duckdb/common/pair.hpp"
4
4
  #include "duckdb/common/vector.hpp"
5
5
  #include "duckdb/function/scalar/nested_functions.hpp"
6
+ #include "duckdb/function/cast/bound_cast_data.hpp"
6
7
 
7
8
  namespace duckdb {
8
9
 
@@ -115,7 +116,9 @@ static BoundCastInfo VectorStringCastNumericSwitch(BindCastInput &input, const L
115
116
  }
116
117
  }
117
118
 
119
+ //===--------------------------------------------------------------------===//
118
120
  // string -> list casting
121
+ //===--------------------------------------------------------------------===//
119
122
  bool VectorStringToList::StringToNestedTypeCastLoop(string_t *source_data, ValidityMask &source_mask, Vector &result,
120
123
  ValidityMask &result_mask, idx_t count, CastParameters &parameters,
121
124
  const SelectionVector *sel) {
@@ -163,7 +166,7 @@ bool VectorStringToList::StringToNestedTypeCastLoop(string_t *source_data, Valid
163
166
 
164
167
  auto &result_child = ListVector::GetEntry(result);
165
168
  auto &cast_data = (ListBoundCastData &)*parameters.cast_data;
166
- CastParameters child_parameters(parameters, cast_data.child_cast_info.cast_data.get());
169
+ CastParameters child_parameters(parameters, cast_data.child_cast_info.cast_data, parameters.local_state);
167
170
  return cast_data.child_cast_info.function(varchar_vector, result_child, total_list_size, child_parameters) &&
168
171
  all_converted;
169
172
  }
@@ -177,11 +180,12 @@ static LogicalType InitVarcharStructType(const LogicalType &target) {
177
180
  return LogicalType::STRUCT(child_types);
178
181
  }
179
182
 
183
+ //===--------------------------------------------------------------------===//
180
184
  // string -> struct casting
185
+ //===--------------------------------------------------------------------===//
181
186
  bool VectorStringToStruct::StringToNestedTypeCastLoop(string_t *source_data, ValidityMask &source_mask, Vector &result,
182
187
  ValidityMask &result_mask, idx_t count,
183
188
  CastParameters &parameters, const SelectionVector *sel) {
184
-
185
189
  auto varchar_struct_type = InitVarcharStructType(result.GetType());
186
190
  Vector varchar_vector(varchar_struct_type, count);
187
191
  auto &child_vectors = StructVector::GetEntries(varchar_vector);
@@ -216,21 +220,39 @@ bool VectorStringToStruct::StringToNestedTypeCastLoop(string_t *source_data, Val
216
220
  }
217
221
 
218
222
  auto &cast_data = (StructBoundCastData &)*parameters.cast_data;
223
+ auto &lstate = (StructCastLocalState &)*parameters.local_state;
219
224
  D_ASSERT(cast_data.child_cast_info.size() == result_children.size());
220
225
 
221
226
  for (idx_t child_idx = 0; child_idx < result_children.size(); child_idx++) {
222
- auto &varchar_vector = *child_vectors[child_idx];
227
+ auto &child_varchar_vector = *child_vectors[child_idx];
223
228
  auto &result_child_vector = *result_children[child_idx];
224
229
  auto &child_cast_info = cast_data.child_cast_info[child_idx];
225
- CastParameters child_parameters(parameters, child_cast_info.cast_data.get());
226
- if (!child_cast_info.function(varchar_vector, result_child_vector, count, child_parameters)) {
230
+ CastParameters child_parameters(parameters, child_cast_info.cast_data, lstate.local_states[child_idx]);
231
+ if (!child_cast_info.function(child_varchar_vector, result_child_vector, count, child_parameters)) {
227
232
  all_converted = false;
228
233
  }
229
234
  }
230
235
  return all_converted;
231
236
  }
232
237
 
238
+ //===--------------------------------------------------------------------===//
233
239
  // string -> map casting
240
+ //===--------------------------------------------------------------------===//
241
+ unique_ptr<FunctionLocalState> InitMapCastLocalState(CastLocalStateParameters &parameters) {
242
+ auto &cast_data = (MapBoundCastData &)*parameters.cast_data;
243
+ auto result = make_unique<MapCastLocalState>();
244
+
245
+ if (cast_data.key_cast.init_local_state) {
246
+ CastLocalStateParameters child_params(parameters, cast_data.key_cast.cast_data);
247
+ result->key_state = cast_data.key_cast.init_local_state(child_params);
248
+ }
249
+ if (cast_data.value_cast.init_local_state) {
250
+ CastLocalStateParameters child_params(parameters, cast_data.value_cast.cast_data);
251
+ result->value_state = cast_data.value_cast.init_local_state(child_params);
252
+ }
253
+ return std::move(result);
254
+ }
255
+
234
256
  bool VectorStringToMap::StringToNestedTypeCastLoop(string_t *source_data, ValidityMask &source_mask, Vector &result,
235
257
  ValidityMask &result_mask, idx_t count, CastParameters &parameters,
236
258
  const SelectionVector *sel) {
@@ -282,12 +304,13 @@ bool VectorStringToMap::StringToNestedTypeCastLoop(string_t *source_data, Validi
282
304
  auto &result_key_child = MapVector::GetKeys(result);
283
305
  auto &result_val_child = MapVector::GetValues(result);
284
306
  auto &cast_data = (MapBoundCastData &)*parameters.cast_data;
307
+ auto &lstate = (MapCastLocalState &)*parameters.local_state;
285
308
 
286
- CastParameters key_params(parameters, cast_data.key_cast.cast_data.get());
309
+ CastParameters key_params(parameters, cast_data.key_cast.cast_data, lstate.key_state);
287
310
  if (!cast_data.key_cast.function(varchar_key_vector, result_key_child, total_elements, key_params)) {
288
311
  all_converted = false;
289
312
  }
290
- CastParameters val_params(parameters, cast_data.value_cast.cast_data.get());
313
+ CastParameters val_params(parameters, cast_data.value_cast.cast_data, lstate.value_state);
291
314
  if (!cast_data.value_cast.function(varchar_val_vector, result_val_child, total_elements, val_params)) {
292
315
  all_converted = false;
293
316
  }
@@ -373,14 +396,17 @@ BoundCastInfo DefaultCasts::StringCastSwitch(BindCastInput &input, const Logical
373
396
  // the second argument allows for a secondary casting function to be passed in the CastParameters
374
397
  return BoundCastInfo(
375
398
  &StringToNestedTypeCast<VectorStringToList>,
376
- ListBoundCastData::BindListToListCast(input, LogicalType::LIST(LogicalType::VARCHAR), target));
399
+ ListBoundCastData::BindListToListCast(input, LogicalType::LIST(LogicalType::VARCHAR), target),
400
+ ListBoundCastData::InitListLocalState);
377
401
  case LogicalTypeId::STRUCT:
378
402
  return BoundCastInfo(&StringToNestedTypeCast<VectorStringToStruct>,
379
- StructBoundCastData::BindStructToStructCast(input, InitVarcharStructType(target), target));
403
+ StructBoundCastData::BindStructToStructCast(input, InitVarcharStructType(target), target),
404
+ StructBoundCastData::InitStructCastLocalState);
380
405
  case LogicalTypeId::MAP:
381
406
  return BoundCastInfo(&StringToNestedTypeCast<VectorStringToMap>,
382
407
  MapBoundCastData::BindMapToMapCast(
383
- input, LogicalType::MAP(LogicalType::VARCHAR, LogicalType::VARCHAR), target));
408
+ input, LogicalType::MAP(LogicalType::VARCHAR, LogicalType::VARCHAR), target),
409
+ InitMapCastLocalState);
384
410
  default:
385
411
  return VectorStringCastNumericSwitch(input, source, target);
386
412
  }
@@ -1,5 +1,6 @@
1
1
  #include "duckdb/function/cast/default_casts.hpp"
2
2
  #include "duckdb/function/cast/cast_function_set.hpp"
3
+ #include "duckdb/function/cast/bound_cast_data.hpp"
3
4
 
4
5
  namespace duckdb {
5
6
 
@@ -18,8 +19,24 @@ unique_ptr<BoundCastData> StructBoundCastData::BindStructToStructCast(BindCastIn
18
19
  return make_unique<StructBoundCastData>(std::move(child_cast_info), target);
19
20
  }
20
21
 
22
+ unique_ptr<FunctionLocalState> StructBoundCastData::InitStructCastLocalState(CastLocalStateParameters &parameters) {
23
+ auto &cast_data = (StructBoundCastData &)*parameters.cast_data;
24
+ auto result = make_unique<StructCastLocalState>();
25
+
26
+ for (auto &entry : cast_data.child_cast_info) {
27
+ unique_ptr<FunctionLocalState> child_state;
28
+ if (entry.init_local_state) {
29
+ CastLocalStateParameters child_params(parameters, entry.cast_data);
30
+ child_state = entry.init_local_state(child_params);
31
+ }
32
+ result->local_states.push_back(std::move(child_state));
33
+ }
34
+ return std::move(result);
35
+ }
36
+
21
37
  static bool StructToStructCast(Vector &source, Vector &result, idx_t count, CastParameters &parameters) {
22
38
  auto &cast_data = (StructBoundCastData &)*parameters.cast_data;
39
+ auto &lstate = (StructCastLocalState &)*parameters.local_state;
23
40
  auto &source_child_types = StructType::GetChildTypes(source.GetType());
24
41
  auto &source_children = StructVector::GetEntries(source);
25
42
  D_ASSERT(source_children.size() == StructType::GetChildTypes(result.GetType()).size());
@@ -29,7 +46,8 @@ static bool StructToStructCast(Vector &source, Vector &result, idx_t count, Cast
29
46
  for (idx_t c_idx = 0; c_idx < source_child_types.size(); c_idx++) {
30
47
  auto &result_child_vector = *result_children[c_idx];
31
48
  auto &source_child_vector = *source_children[c_idx];
32
- CastParameters child_parameters(parameters, cast_data.child_cast_info[c_idx].cast_data.get());
49
+ CastParameters child_parameters(parameters, cast_data.child_cast_info[c_idx].cast_data,
50
+ lstate.local_states[c_idx]);
33
51
  if (!cast_data.child_cast_info[c_idx].function(source_child_vector, result_child_vector, count,
34
52
  child_parameters)) {
35
53
  all_converted = false;
@@ -121,7 +139,8 @@ BoundCastInfo DefaultCasts::StructCastSwitch(BindCastInput &input, const Logical
121
139
  const LogicalType &target) {
122
140
  switch (target.id()) {
123
141
  case LogicalTypeId::STRUCT:
124
- return BoundCastInfo(StructToStructCast, StructBoundCastData::BindStructToStructCast(input, source, target));
142
+ return BoundCastInfo(StructToStructCast, StructBoundCastData::BindStructToStructCast(input, source, target),
143
+ StructBoundCastData::InitStructCastLocalState);
125
144
  case LogicalTypeId::VARCHAR: {
126
145
  // bind a cast in which we convert all child entries to VARCHAR entries
127
146
  auto &struct_children = StructType::GetChildTypes(source);
@@ -131,7 +150,8 @@ BoundCastInfo DefaultCasts::StructCastSwitch(BindCastInput &input, const Logical
131
150
  }
132
151
  auto varchar_type = LogicalType::STRUCT(varchar_children);
133
152
  return BoundCastInfo(StructToVarcharCast,
134
- StructBoundCastData::BindStructToStructCast(input, source, varchar_type));
153
+ StructBoundCastData::BindStructToStructCast(input, source, varchar_type),
154
+ StructBoundCastData::InitStructCastLocalState);
135
155
  }
136
156
  default:
137
157
  return TryVectorNullCast;
@@ -1,6 +1,6 @@
1
1
  #include "duckdb/function/cast/cast_function_set.hpp"
2
2
  #include "duckdb/function/cast/default_casts.hpp"
3
- #include "duckdb/function/cast/vector_cast_helpers.hpp"
3
+ #include "duckdb/function/cast/bound_cast_data.hpp"
4
4
 
5
5
  #include <algorithm> // for std::sort
6
6
 
@@ -98,12 +98,21 @@ unique_ptr<BoundCastData> BindToUnionCast(BindCastInput &input, const LogicalTyp
98
98
  return make_unique<ToUnionBoundCastData>(std::move(selected_cast));
99
99
  }
100
100
 
101
+ unique_ptr<FunctionLocalState> InitToUnionLocalState(CastLocalStateParameters &parameters) {
102
+ auto &cast_data = (ToUnionBoundCastData &)*parameters.cast_data;
103
+ if (!cast_data.member_cast_info.init_local_state) {
104
+ return nullptr;
105
+ }
106
+ CastLocalStateParameters child_parameters(parameters, cast_data.member_cast_info.cast_data);
107
+ return cast_data.member_cast_info.init_local_state(child_parameters);
108
+ }
109
+
101
110
  static bool ToUnionCast(Vector &source, Vector &result, idx_t count, CastParameters &parameters) {
102
111
  D_ASSERT(result.GetType().id() == LogicalTypeId::UNION);
103
112
  auto &cast_data = (ToUnionBoundCastData &)*parameters.cast_data;
104
113
  auto &selected_member_vector = UnionVector::GetMember(result, cast_data.tag);
105
114
 
106
- CastParameters child_parameters(parameters, cast_data.member_cast_info.cast_data.get());
115
+ CastParameters child_parameters(parameters, cast_data.member_cast_info.cast_data, parameters.local_state);
107
116
  if (!cast_data.member_cast_info.function(source, selected_member_vector, count, child_parameters)) {
108
117
  return false;
109
118
  }
@@ -118,7 +127,7 @@ static bool ToUnionCast(Vector &source, Vector &result, idx_t count, CastParamet
118
127
 
119
128
  BoundCastInfo DefaultCasts::ImplicitToUnionCast(BindCastInput &input, const LogicalType &source,
120
129
  const LogicalType &target) {
121
- return BoundCastInfo(&ToUnionCast, BindToUnionCast(input, source, target));
130
+ return BoundCastInfo(&ToUnionCast, BindToUnionCast(input, source, target), InitToUnionLocalState);
122
131
  }
123
132
 
124
133
  //--------------------------------------------------------------------------------------------------
@@ -197,8 +206,24 @@ unique_ptr<BoundCastData> BindUnionToUnionCast(BindCastInput &input, const Logic
197
206
  return make_unique<UnionToUnionBoundCastData>(tag_map, std::move(member_casts), target);
198
207
  }
199
208
 
209
+ unique_ptr<FunctionLocalState> InitUnionToUnionLocalState(CastLocalStateParameters &parameters) {
210
+ auto &cast_data = (UnionToUnionBoundCastData &)*parameters.cast_data;
211
+ auto result = make_unique<StructCastLocalState>();
212
+
213
+ for (auto &entry : cast_data.member_casts) {
214
+ unique_ptr<FunctionLocalState> child_state;
215
+ if (entry.init_local_state) {
216
+ CastLocalStateParameters child_params(parameters, entry.cast_data);
217
+ child_state = entry.init_local_state(child_params);
218
+ }
219
+ result->local_states.push_back(std::move(child_state));
220
+ }
221
+ return std::move(result);
222
+ }
223
+
200
224
  static bool UnionToUnionCast(Vector &source, Vector &result, idx_t count, CastParameters &parameters) {
201
225
  auto &cast_data = (UnionToUnionBoundCastData &)*parameters.cast_data;
226
+ auto &lstate = (StructCastLocalState &)*parameters.local_state;
202
227
 
203
228
  auto source_member_count = UnionType::GetMemberCount(source.GetType());
204
229
  auto target_member_count = UnionType::GetMemberCount(result.GetType());
@@ -213,7 +238,7 @@ static bool UnionToUnionCast(Vector &source, Vector &result, idx_t count, CastPa
213
238
  auto &target_member_vector = UnionVector::GetMember(result, target_member_idx);
214
239
  auto &member_cast = cast_data.member_casts[member_idx];
215
240
 
216
- CastParameters child_parameters(parameters, member_cast.cast_data.get());
241
+ CastParameters child_parameters(parameters, member_cast.cast_data, lstate.local_states[member_idx]);
217
242
  if (!member_cast.function(source_member_vector, target_member_vector, count, child_parameters)) {
218
243
  return false;
219
244
  }
@@ -339,10 +364,11 @@ BoundCastInfo DefaultCasts::UnionCastSwitch(BindCastInput &input, const LogicalT
339
364
  varchar_members.push_back(make_pair(UnionType::GetMemberName(source, member_idx), LogicalType::VARCHAR));
340
365
  }
341
366
  auto varchar_type = LogicalType::UNION(std::move(varchar_members));
342
- return BoundCastInfo(UnionToVarcharCast, BindUnionToUnionCast(input, source, varchar_type));
343
- } break;
367
+ return BoundCastInfo(UnionToVarcharCast, BindUnionToUnionCast(input, source, varchar_type),
368
+ InitUnionToUnionLocalState);
369
+ }
344
370
  case LogicalTypeId::UNION:
345
- return BoundCastInfo(UnionToUnionCast, BindUnionToUnionCast(input, source, target));
371
+ return BoundCastInfo(UnionToUnionCast, BindUnionToUnionCast(input, source, target), InitUnionToUnionLocalState);
346
372
  default:
347
373
  return TryVectorNullCast;
348
374
  }
@@ -32,7 +32,11 @@ static unique_ptr<FunctionData> CheckpointBind(ClientContext &context, TableFunc
32
32
  AttachedDatabase *db;
33
33
  auto &db_manager = DatabaseManager::Get(context);
34
34
  if (!input.inputs.empty()) {
35
- db = db_manager.GetDatabase(context, StringValue::Get(input.inputs[0]));
35
+ auto &db_name = StringValue::Get(input.inputs[0]);
36
+ db = db_manager.GetDatabase(context, db_name);
37
+ if (!db) {
38
+ throw BinderException("Database \"%s\" not found", db_name);
39
+ }
36
40
  } else {
37
41
  db = db_manager.GetDatabase(context, DatabaseManager::GetDefaultDatabase(context));
38
42
  }
@@ -204,8 +204,8 @@ void DuckDBConstraintsFunction(ClientContext &context, TableFunctionInput &data_
204
204
  const auto &bound_foreign_key = (const BoundForeignKeyConstraint &)bound_constraint;
205
205
  const auto &info = bound_foreign_key.info;
206
206
  // find the other table
207
- auto table_entry =
208
- Catalog::GetEntry<TableCatalogEntry>(context, INVALID_CATALOG, info.schema, info.table, true);
207
+ auto table_entry = Catalog::GetEntry<TableCatalogEntry>(context, table.catalog->GetName(),
208
+ info.schema, info.table, true);
209
209
  if (!table_entry) {
210
210
  throw InternalException("dukdb_constraints: entry %s.%s referenced in foreign key not found",
211
211
  info.schema, info.table);
@@ -1,8 +1,8 @@
1
1
  #ifndef DUCKDB_VERSION
2
- #define DUCKDB_VERSION "0.7.2-dev614"
2
+ #define DUCKDB_VERSION "0.7.2-dev717"
3
3
  #endif
4
4
  #ifndef DUCKDB_SOURCE_ID
5
- #define DUCKDB_SOURCE_ID "40e91c8873"
5
+ #define DUCKDB_SOURCE_ID "cd47ad8e2d"
6
6
  #endif
7
7
  #include "duckdb/function/table/system_functions.hpp"
8
8
  #include "duckdb/main/database.hpp"
@@ -12,6 +12,7 @@
12
12
  #include "duckdb/common/unordered_set.hpp"
13
13
 
14
14
  namespace duckdb {
15
+ class Catalog;
15
16
  class CatalogEntry;
16
17
 
17
18
  //! The DependencyList
@@ -21,6 +22,8 @@ class DependencyList {
21
22
  public:
22
23
  DUCKDB_API void AddDependency(CatalogEntry *entry);
23
24
 
25
+ DUCKDB_API void VerifyDependencies(Catalog *catalog, const string &name);
26
+
24
27
  private:
25
28
  unordered_set<CatalogEntry *> set;
26
29
  };
@@ -0,0 +1,45 @@
1
+ //===----------------------------------------------------------------------===//
2
+ // DuckDB
3
+ //
4
+ // duckdb/common/optional_ptr.hpp
5
+ //
6
+ //
7
+ //===----------------------------------------------------------------------===//
8
+
9
+ #pragma once
10
+
11
+ #include "duckdb/common/exception.hpp"
12
+
13
+ namespace duckdb {
14
+
15
+ template <class T>
16
+ class optional_ptr {
17
+ public:
18
+ optional_ptr() : ptr(nullptr) {
19
+ }
20
+ optional_ptr(T *ptr_p) : ptr(ptr_p) { // NOLINT: allow implicit creation from pointer
21
+ }
22
+ optional_ptr(const unique_ptr<T> &ptr_p) : ptr(ptr_p.get()) { // NOLINT: allow implicit creation from unique pointer
23
+ }
24
+
25
+ operator bool() const {
26
+ return ptr;
27
+ }
28
+ T &operator*() {
29
+ if (!ptr) {
30
+ throw InternalException("Attempting to dereference an optional pointer that is not set");
31
+ }
32
+ return *ptr;
33
+ }
34
+ T *operator->() {
35
+ if (!ptr) {
36
+ throw InternalException("Attempting to call a method on an optional pointer that is not set");
37
+ }
38
+ return ptr;
39
+ }
40
+
41
+ private:
42
+ T *ptr;
43
+ };
44
+
45
+ } // namespace duckdb
@@ -113,6 +113,7 @@ public:
113
113
  }
114
114
 
115
115
  idx_t MaxCapacity();
116
+ static idx_t GetMaxCapacity(HtEntryType entry_type, idx_t tuple_size);
116
117
 
117
118
  void Partition(vector<GroupedAggregateHashTable *> &partition_hts, hash_t mask, idx_t shift);
118
119
 
@@ -72,7 +72,7 @@ public:
72
72
  vector<row_t> &result_ids) override;
73
73
 
74
74
  //! Called when data is appended to the index. The lock obtained from InitializeLock must be held
75
- bool Append(IndexLock &lock, DataChunk &entries, Vector &row_identifiers) override;
75
+ PreservedError Append(IndexLock &lock, DataChunk &entries, Vector &row_identifiers) override;
76
76
  //! Verify that data can be appended to the index without a constraint violation
77
77
  void VerifyAppend(DataChunk &chunk) override;
78
78
  //! Verify that data can be appended to the index without a constraint violation using the conflict manager
@@ -80,7 +80,7 @@ public:
80
80
  //! Delete a chunk of entries from the index. The lock obtained from InitializeLock must be held
81
81
  void Delete(IndexLock &lock, DataChunk &entries, Vector &row_identifiers) override;
82
82
  //! Insert a chunk of entries into the index
83
- bool Insert(IndexLock &lock, DataChunk &data, Vector &row_ids) override;
83
+ PreservedError Insert(IndexLock &lock, DataChunk &data, Vector &row_ids) override;
84
84
 
85
85
  //! Construct an ART from a vector of sorted keys
86
86
  bool ConstructFromSorted(idx_t count, vector<Key> &keys, Vector &row_identifiers);
@@ -57,9 +57,12 @@ private:
57
57
 
58
58
  HashTableList unpartitioned_hts;
59
59
  unordered_map<hash_t, HashTableList> radix_partitioned_hts;
60
+ idx_t tuple_size;
60
61
 
61
62
  private:
62
63
  idx_t ListAddChunk(HashTableList &list, DataChunk &groups, Vector &group_hashes, DataChunk &payload,
63
64
  const vector<idx_t> &filter);
65
+ //! Returns the HT entry size used for intermediate hash tables
66
+ HtEntryType GetHTEntrySize();
64
67
  };
65
68
  } // namespace duckdb
@@ -0,0 +1,84 @@
1
+ //===----------------------------------------------------------------------===//
2
+ // DuckDB
3
+ //
4
+ // duckdb/function/cast/bound_cast_data.hpp
5
+ //
6
+ //
7
+ //===----------------------------------------------------------------------===//
8
+
9
+ #pragma once
10
+
11
+ #include "duckdb/function/cast/default_casts.hpp"
12
+
13
+ namespace duckdb {
14
+
15
+ struct ListBoundCastData : public BoundCastData {
16
+ explicit ListBoundCastData(BoundCastInfo child_cast) : child_cast_info(std::move(child_cast)) {
17
+ }
18
+
19
+ BoundCastInfo child_cast_info;
20
+ static unique_ptr<BoundCastData> BindListToListCast(BindCastInput &input, const LogicalType &source,
21
+ const LogicalType &target);
22
+ static unique_ptr<FunctionLocalState> InitListLocalState(CastLocalStateParameters &parameters);
23
+
24
+ public:
25
+ unique_ptr<BoundCastData> Copy() const override {
26
+ return make_unique<ListBoundCastData>(child_cast_info.Copy());
27
+ }
28
+ };
29
+
30
+ struct ListCast {
31
+ static bool ListToListCast(Vector &source, Vector &result, idx_t count, CastParameters &parameters);
32
+ };
33
+
34
+ struct StructBoundCastData : public BoundCastData {
35
+ StructBoundCastData(vector<BoundCastInfo> child_casts, LogicalType target_p)
36
+ : child_cast_info(std::move(child_casts)), target(std::move(target_p)) {
37
+ }
38
+
39
+ vector<BoundCastInfo> child_cast_info;
40
+ LogicalType target;
41
+
42
+ static unique_ptr<BoundCastData> BindStructToStructCast(BindCastInput &input, const LogicalType &source,
43
+ const LogicalType &target);
44
+ static unique_ptr<FunctionLocalState> InitStructCastLocalState(CastLocalStateParameters &parameters);
45
+
46
+ public:
47
+ unique_ptr<BoundCastData> Copy() const override {
48
+ vector<BoundCastInfo> copy_info;
49
+ for (auto &info : child_cast_info) {
50
+ copy_info.push_back(info.Copy());
51
+ }
52
+ return make_unique<StructBoundCastData>(std::move(copy_info), target);
53
+ }
54
+ };
55
+
56
+ struct StructCastLocalState : public FunctionLocalState {
57
+ public:
58
+ vector<unique_ptr<FunctionLocalState>> local_states;
59
+ };
60
+
61
+ struct MapBoundCastData : public BoundCastData {
62
+ MapBoundCastData(BoundCastInfo key_cast, BoundCastInfo value_cast)
63
+ : key_cast(std::move(key_cast)), value_cast(std::move(value_cast)) {
64
+ }
65
+
66
+ BoundCastInfo key_cast;
67
+ BoundCastInfo value_cast;
68
+
69
+ static unique_ptr<BoundCastData> BindMapToMapCast(BindCastInput &input, const LogicalType &source,
70
+ const LogicalType &target);
71
+
72
+ public:
73
+ unique_ptr<BoundCastData> Copy() const override {
74
+ return make_unique<MapBoundCastData>(key_cast.Copy(), value_cast.Copy());
75
+ }
76
+ };
77
+
78
+ struct MapCastLocalState : public FunctionLocalState {
79
+ public:
80
+ unique_ptr<FunctionLocalState> key_state;
81
+ unique_ptr<FunctionLocalState> value_state;
82
+ };
83
+
84
+ } // namespace duckdb
@@ -19,12 +19,12 @@ typedef BoundCastInfo (*bind_cast_function_t)(BindCastInput &input, const Logica
19
19
  typedef int64_t (*implicit_cast_cost_t)(const LogicalType &from, const LogicalType &to);
20
20
 
21
21
  struct GetCastFunctionInput {
22
- GetCastFunctionInput(ClientContext *context = nullptr) : context(context) {
22
+ GetCastFunctionInput(optional_ptr<ClientContext> context = nullptr) : context(context) {
23
23
  }
24
24
  GetCastFunctionInput(ClientContext &context) : context(&context) {
25
25
  }
26
26
 
27
- ClientContext *context;
27
+ optional_ptr<ClientContext> context;
28
28
  };
29
29
 
30
30
  struct BindCastFunction {
@@ -10,6 +10,8 @@
10
10
 
11
11
  #include "duckdb/common/types.hpp"
12
12
  #include "duckdb/common/types/vector.hpp"
13
+ #include "duckdb/common/optional_ptr.hpp"
14
+ #include "duckdb/function/scalar_function.hpp"
13
15
 
14
16
  namespace duckdb {
15
17
 
@@ -31,25 +33,43 @@ struct BoundCastData {
31
33
  struct CastParameters {
32
34
  CastParameters() {
33
35
  }
34
- CastParameters(BoundCastData *cast_data, bool strict, string *error_message, FunctionLocalState *local_state)
36
+ CastParameters(BoundCastData *cast_data, bool strict, string *error_message,
37
+ optional_ptr<FunctionLocalState> local_state)
35
38
  : cast_data(cast_data), strict(strict), error_message(error_message), local_state(local_state) {
36
39
  }
37
- CastParameters(CastParameters &parent, BoundCastData *cast_data = nullptr)
38
- : cast_data(cast_data), strict(parent.strict), error_message(parent.error_message) {
40
+ CastParameters(CastParameters &parent, optional_ptr<BoundCastData> cast_data,
41
+ optional_ptr<FunctionLocalState> local_state)
42
+ : cast_data(cast_data), strict(parent.strict), error_message(parent.error_message), local_state(local_state) {
39
43
  }
40
44
 
41
45
  //! The bound cast data (if any)
42
- BoundCastData *cast_data = nullptr;
46
+ optional_ptr<BoundCastData> cast_data;
43
47
  //! whether or not to enable strict casting
44
48
  bool strict = false;
45
49
  // out: error message in case cast has failed
46
50
  string *error_message = nullptr;
47
51
  //! Local state
48
- FunctionLocalState *local_state = nullptr;
52
+ optional_ptr<FunctionLocalState> local_state;
53
+ };
54
+
55
+ struct CastLocalStateParameters {
56
+ CastLocalStateParameters(optional_ptr<ClientContext> context_p, optional_ptr<BoundCastData> cast_data_p)
57
+ : context(context_p), cast_data(cast_data_p) {
58
+ }
59
+ CastLocalStateParameters(ClientContext &context_p, optional_ptr<BoundCastData> cast_data_p)
60
+ : context(&context_p), cast_data(cast_data_p) {
61
+ }
62
+ CastLocalStateParameters(CastLocalStateParameters &parent, optional_ptr<BoundCastData> cast_data_p)
63
+ : context(parent.context), cast_data(cast_data_p) {
64
+ }
65
+
66
+ optional_ptr<ClientContext> context;
67
+ //! The bound cast data (if any)
68
+ optional_ptr<BoundCastData> cast_data;
49
69
  };
50
70
 
51
71
  typedef bool (*cast_function_t)(Vector &source, Vector &result, idx_t count, CastParameters &parameters);
52
- typedef unique_ptr<FunctionLocalState> (*init_cast_local_state_t)(ClientContext &context);
72
+ typedef unique_ptr<FunctionLocalState> (*init_cast_local_state_t)(CastLocalStateParameters &parameters);
53
73
 
54
74
  struct BoundCastInfo {
55
75
  DUCKDB_API
@@ -65,72 +85,16 @@ public:
65
85
  };
66
86
 
67
87
  struct BindCastInput {
68
- DUCKDB_API BindCastInput(CastFunctionSet &function_set, BindCastInfo *info, ClientContext *context);
88
+ DUCKDB_API BindCastInput(CastFunctionSet &function_set, BindCastInfo *info, optional_ptr<ClientContext> context);
69
89
 
70
90
  CastFunctionSet &function_set;
71
91
  BindCastInfo *info;
72
- ClientContext *context;
92
+ optional_ptr<ClientContext> context;
73
93
 
74
94
  public:
75
95
  DUCKDB_API BoundCastInfo GetCastFunction(const LogicalType &source, const LogicalType &target);
76
96
  };
77
97
 
78
- struct ListBoundCastData : public BoundCastData {
79
- explicit ListBoundCastData(BoundCastInfo child_cast) : child_cast_info(std::move(child_cast)) {
80
- }
81
-
82
- BoundCastInfo child_cast_info;
83
- static unique_ptr<BoundCastData> BindListToListCast(BindCastInput &input, const LogicalType &source,
84
- const LogicalType &target);
85
-
86
- public:
87
- unique_ptr<BoundCastData> Copy() const override {
88
- return make_unique<ListBoundCastData>(child_cast_info.Copy());
89
- }
90
- };
91
-
92
- struct ListCast {
93
- static bool ListToListCast(Vector &source, Vector &result, idx_t count, CastParameters &parameters);
94
- };
95
-
96
- struct StructBoundCastData : public BoundCastData {
97
- StructBoundCastData(vector<BoundCastInfo> child_casts, LogicalType target_p)
98
- : child_cast_info(std::move(child_casts)), target(std::move(target_p)) {
99
- }
100
-
101
- vector<BoundCastInfo> child_cast_info;
102
- LogicalType target;
103
-
104
- static unique_ptr<BoundCastData> BindStructToStructCast(BindCastInput &input, const LogicalType &source,
105
- const LogicalType &target);
106
-
107
- public:
108
- unique_ptr<BoundCastData> Copy() const override {
109
- vector<BoundCastInfo> copy_info;
110
- for (auto &info : child_cast_info) {
111
- copy_info.push_back(info.Copy());
112
- }
113
- return make_unique<StructBoundCastData>(std::move(copy_info), target);
114
- }
115
- };
116
-
117
- struct MapBoundCastData : public BoundCastData {
118
- MapBoundCastData(BoundCastInfo key_cast, BoundCastInfo value_cast)
119
- : key_cast(std::move(key_cast)), value_cast(std::move(value_cast)) {
120
- }
121
-
122
- BoundCastInfo key_cast;
123
- BoundCastInfo value_cast;
124
-
125
- static unique_ptr<BoundCastData> BindMapToMapCast(BindCastInput &input, const LogicalType &source,
126
- const LogicalType &target);
127
-
128
- public:
129
- unique_ptr<BoundCastData> Copy() const override {
130
- return make_unique<MapBoundCastData>(key_cast.Copy(), value_cast.Copy());
131
- }
132
- };
133
-
134
98
  struct DefaultCasts {
135
99
  DUCKDB_API static BoundCastInfo GetDefaultCastFunction(BindCastInput &input, const LogicalType &source,
136
100
  const LogicalType &target);
@@ -71,8 +71,11 @@ private:
71
71
  vector<unique_ptr<CreatePivotEntry>> pivot_entries;
72
72
  //! Sets of stored CTEs, if any
73
73
  vector<CommonTableExpressionMap *> stored_cte_map;
74
+ //! Whether or not we are currently binding a window definition
75
+ bool in_window_definition = false;
74
76
 
75
77
  void Clear();
78
+ bool InWindowDefinition();
76
79
 
77
80
  void SetParamCount(idx_t new_count) {
78
81
  if (parent) {