duckdb 0.8.2-dev1859.0 → 0.8.2-dev1968.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 (83) hide show
  1. package/binding.gyp +9 -9
  2. package/package.json +1 -1
  3. package/src/duckdb/src/common/enum_util.cpp +28 -0
  4. package/src/duckdb/src/common/types/hugeint.cpp +40 -0
  5. package/src/duckdb/src/core_functions/function_list.cpp +1 -0
  6. package/src/duckdb/src/core_functions/scalar/string/to_base.cpp +66 -0
  7. package/src/duckdb/src/execution/operator/aggregate/physical_hash_aggregate.cpp +14 -11
  8. package/src/duckdb/src/execution/operator/aggregate/physical_perfecthash_aggregate.cpp +6 -4
  9. package/src/duckdb/src/execution/operator/aggregate/physical_ungrouped_aggregate.cpp +14 -12
  10. package/src/duckdb/src/execution/operator/aggregate/physical_window.cpp +6 -4
  11. package/src/duckdb/src/execution/operator/helper/physical_batch_collector.cpp +8 -6
  12. package/src/duckdb/src/execution/operator/helper/physical_explain_analyze.cpp +2 -2
  13. package/src/duckdb/src/execution/operator/helper/physical_limit.cpp +5 -3
  14. package/src/duckdb/src/execution/operator/helper/physical_materialized_collector.cpp +7 -5
  15. package/src/duckdb/src/execution/operator/helper/physical_vacuum.cpp +7 -5
  16. package/src/duckdb/src/execution/operator/join/physical_asof_join.cpp +5 -4
  17. package/src/duckdb/src/execution/operator/join/physical_blockwise_nl_join.cpp +2 -2
  18. package/src/duckdb/src/execution/operator/join/physical_delim_join.cpp +13 -6
  19. package/src/duckdb/src/execution/operator/join/physical_hash_join.cpp +7 -5
  20. package/src/duckdb/src/execution/operator/join/physical_iejoin.cpp +7 -5
  21. package/src/duckdb/src/execution/operator/join/physical_nested_loop_join.cpp +7 -4
  22. package/src/duckdb/src/execution/operator/join/physical_piecewise_merge_join.cpp +8 -6
  23. package/src/duckdb/src/execution/operator/order/physical_order.cpp +7 -5
  24. package/src/duckdb/src/execution/operator/order/physical_top_n.cpp +7 -5
  25. package/src/duckdb/src/execution/operator/persistent/physical_batch_copy_to_file.cpp +8 -6
  26. package/src/duckdb/src/execution/operator/persistent/physical_batch_insert.cpp +8 -7
  27. package/src/duckdb/src/execution/operator/persistent/physical_copy_to_file.cpp +8 -6
  28. package/src/duckdb/src/execution/operator/persistent/physical_fixed_batch_copy.cpp +11 -9
  29. package/src/duckdb/src/execution/operator/persistent/physical_insert.cpp +10 -10
  30. package/src/duckdb/src/execution/operator/persistent/physical_update.cpp +4 -2
  31. package/src/duckdb/src/execution/operator/schema/physical_create_index.cpp +7 -6
  32. package/src/duckdb/src/execution/physical_operator.cpp +3 -2
  33. package/src/duckdb/src/function/table/read_csv.cpp +4 -3
  34. package/src/duckdb/src/function/table/version/pragma_version.cpp +2 -2
  35. package/src/duckdb/src/include/duckdb/common/bitpacking.hpp +70 -55
  36. package/src/duckdb/src/include/duckdb/common/enum_util.hpp +8 -0
  37. package/src/duckdb/src/include/duckdb/common/enums/operator_result_type.hpp +5 -1
  38. package/src/duckdb/src/include/duckdb/common/hugeint.hpp +15 -0
  39. package/src/duckdb/src/include/duckdb/common/limits.hpp +52 -149
  40. package/src/duckdb/src/include/duckdb/common/numeric_utils.hpp +48 -0
  41. package/src/duckdb/src/include/duckdb/core_functions/aggregate/distributive_functions.hpp +1 -1
  42. package/src/duckdb/src/include/duckdb/core_functions/scalar/operators_functions.hpp +1 -1
  43. package/src/duckdb/src/include/duckdb/core_functions/scalar/string_functions.hpp +9 -0
  44. package/src/duckdb/src/include/duckdb/execution/operator/aggregate/physical_hash_aggregate.hpp +3 -3
  45. package/src/duckdb/src/include/duckdb/execution/operator/aggregate/physical_perfecthash_aggregate.hpp +1 -1
  46. package/src/duckdb/src/include/duckdb/execution/operator/aggregate/physical_ungrouped_aggregate.hpp +3 -3
  47. package/src/duckdb/src/include/duckdb/execution/operator/aggregate/physical_window.hpp +2 -2
  48. package/src/duckdb/src/include/duckdb/execution/operator/helper/physical_batch_collector.hpp +2 -2
  49. package/src/duckdb/src/include/duckdb/execution/operator/helper/physical_explain_analyze.hpp +1 -1
  50. package/src/duckdb/src/include/duckdb/execution/operator/helper/physical_limit.hpp +1 -1
  51. package/src/duckdb/src/include/duckdb/execution/operator/helper/physical_materialized_collector.hpp +1 -1
  52. package/src/duckdb/src/include/duckdb/execution/operator/helper/physical_vacuum.hpp +2 -2
  53. package/src/duckdb/src/include/duckdb/execution/operator/join/physical_asof_join.hpp +2 -2
  54. package/src/duckdb/src/include/duckdb/execution/operator/join/physical_blockwise_nl_join.hpp +1 -1
  55. package/src/duckdb/src/include/duckdb/execution/operator/join/physical_delim_join.hpp +2 -2
  56. package/src/duckdb/src/include/duckdb/execution/operator/join/physical_hash_join.hpp +2 -2
  57. package/src/duckdb/src/include/duckdb/execution/operator/join/physical_iejoin.hpp +2 -2
  58. package/src/duckdb/src/include/duckdb/execution/operator/join/physical_nested_loop_join.hpp +2 -2
  59. package/src/duckdb/src/include/duckdb/execution/operator/join/physical_piecewise_merge_join.hpp +2 -2
  60. package/src/duckdb/src/include/duckdb/execution/operator/order/physical_order.hpp +2 -2
  61. package/src/duckdb/src/include/duckdb/execution/operator/order/physical_top_n.hpp +2 -2
  62. package/src/duckdb/src/include/duckdb/execution/operator/persistent/physical_batch_copy_to_file.hpp +2 -2
  63. package/src/duckdb/src/include/duckdb/execution/operator/persistent/physical_batch_insert.hpp +2 -2
  64. package/src/duckdb/src/include/duckdb/execution/operator/persistent/physical_copy_to_file.hpp +2 -2
  65. package/src/duckdb/src/include/duckdb/execution/operator/persistent/physical_fixed_batch_copy.hpp +2 -2
  66. package/src/duckdb/src/include/duckdb/execution/operator/persistent/physical_insert.hpp +2 -2
  67. package/src/duckdb/src/include/duckdb/execution/operator/persistent/physical_update.hpp +1 -1
  68. package/src/duckdb/src/include/duckdb/execution/operator/schema/physical_create_index.hpp +2 -2
  69. package/src/duckdb/src/include/duckdb/execution/physical_operator.hpp +3 -3
  70. package/src/duckdb/src/include/duckdb/execution/physical_operator_states.hpp +11 -0
  71. package/src/duckdb/src/include/duckdb/main/extension_entries.hpp +3 -0
  72. package/src/duckdb/src/include/duckdb/parallel/pipeline.hpp +0 -3
  73. package/src/duckdb/src/include/duckdb/parallel/pipeline_executor.hpp +3 -2
  74. package/src/duckdb/src/main/relation/join_relation.cpp +1 -1
  75. package/src/duckdb/src/parallel/pipeline.cpp +0 -17
  76. package/src/duckdb/src/parallel/pipeline_executor.cpp +26 -7
  77. package/src/duckdb/src/parallel/pipeline_finish_event.cpp +55 -1
  78. package/src/duckdb/src/planner/binder/tableref/bind_basetableref.cpp +13 -3
  79. package/src/duckdb/src/storage/compression/bitpacking.cpp +87 -63
  80. package/src/duckdb/src/storage/compression/bitpacking_hugeint.cpp +295 -0
  81. package/src/duckdb/ub_extension_icu_third_party_icu_i18n.cpp +6 -6
  82. package/src/duckdb/ub_src_core_functions_scalar_string.cpp +2 -0
  83. package/src/duckdb/ub_src_storage_compression.cpp +2 -0
package/binding.gyp CHANGED
@@ -241,18 +241,18 @@
241
241
  "src/duckdb/third_party/zstd/compress/zstd_lazy.cpp",
242
242
  "src/duckdb/third_party/zstd/compress/zstd_ldm.cpp",
243
243
  "src/duckdb/third_party/zstd/compress/zstd_opt.cpp",
244
- "src/duckdb/extension/icu/./icu-list-range.cpp",
245
- "src/duckdb/extension/icu/./icu-table-range.cpp",
246
- "src/duckdb/extension/icu/./icu-datesub.cpp",
247
- "src/duckdb/extension/icu/./icu-dateadd.cpp",
248
- "src/duckdb/extension/icu/./icu-timebucket.cpp",
249
- "src/duckdb/extension/icu/./icu-makedate.cpp",
250
- "src/duckdb/extension/icu/./icu-timezone.cpp",
251
- "src/duckdb/extension/icu/./icu-datefunc.cpp",
252
- "src/duckdb/extension/icu/./icu-datepart.cpp",
253
244
  "src/duckdb/extension/icu/./icu_extension.cpp",
254
245
  "src/duckdb/extension/icu/./icu-datetrunc.cpp",
246
+ "src/duckdb/extension/icu/./icu-datepart.cpp",
255
247
  "src/duckdb/extension/icu/./icu-strptime.cpp",
248
+ "src/duckdb/extension/icu/./icu-table-range.cpp",
249
+ "src/duckdb/extension/icu/./icu-makedate.cpp",
250
+ "src/duckdb/extension/icu/./icu-datefunc.cpp",
251
+ "src/duckdb/extension/icu/./icu-list-range.cpp",
252
+ "src/duckdb/extension/icu/./icu-timebucket.cpp",
253
+ "src/duckdb/extension/icu/./icu-dateadd.cpp",
254
+ "src/duckdb/extension/icu/./icu-timezone.cpp",
255
+ "src/duckdb/extension/icu/./icu-datesub.cpp",
256
256
  "src/duckdb/ub_extension_icu_third_party_icu_common.cpp",
257
257
  "src/duckdb/ub_extension_icu_third_party_icu_i18n.cpp",
258
258
  "src/duckdb/extension/icu/third_party/icu/stubdata/stubdata.cpp",
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "duckdb",
3
3
  "main": "./lib/duckdb.js",
4
4
  "types": "./lib/duckdb.d.ts",
5
- "version": "0.8.2-dev1859.0",
5
+ "version": "0.8.2-dev1968.0",
6
6
  "description": "DuckDB node.js API",
7
7
  "gypfile": true,
8
8
  "dependencies": {
@@ -4718,6 +4718,29 @@ SimplifiedTokenType EnumUtil::FromString<SimplifiedTokenType>(const char *value)
4718
4718
  throw NotImplementedException(StringUtil::Format("Enum value: '%s' not implemented", value));
4719
4719
  }
4720
4720
 
4721
+ template<>
4722
+ const char* EnumUtil::ToChars<SinkCombineResultType>(SinkCombineResultType value) {
4723
+ switch(value) {
4724
+ case SinkCombineResultType::FINISHED:
4725
+ return "FINISHED";
4726
+ case SinkCombineResultType::BLOCKED:
4727
+ return "BLOCKED";
4728
+ default:
4729
+ throw NotImplementedException(StringUtil::Format("Enum value: '%d' not implemented", value));
4730
+ }
4731
+ }
4732
+
4733
+ template<>
4734
+ SinkCombineResultType EnumUtil::FromString<SinkCombineResultType>(const char *value) {
4735
+ if (StringUtil::Equals(value, "FINISHED")) {
4736
+ return SinkCombineResultType::FINISHED;
4737
+ }
4738
+ if (StringUtil::Equals(value, "BLOCKED")) {
4739
+ return SinkCombineResultType::BLOCKED;
4740
+ }
4741
+ throw NotImplementedException(StringUtil::Format("Enum value: '%s' not implemented", value));
4742
+ }
4743
+
4721
4744
  template<>
4722
4745
  const char* EnumUtil::ToChars<SinkFinalizeType>(SinkFinalizeType value) {
4723
4746
  switch(value) {
@@ -4725,6 +4748,8 @@ const char* EnumUtil::ToChars<SinkFinalizeType>(SinkFinalizeType value) {
4725
4748
  return "READY";
4726
4749
  case SinkFinalizeType::NO_OUTPUT_POSSIBLE:
4727
4750
  return "NO_OUTPUT_POSSIBLE";
4751
+ case SinkFinalizeType::BLOCKED:
4752
+ return "BLOCKED";
4728
4753
  default:
4729
4754
  throw NotImplementedException(StringUtil::Format("Enum value: '%d' not implemented", value));
4730
4755
  }
@@ -4738,6 +4763,9 @@ SinkFinalizeType EnumUtil::FromString<SinkFinalizeType>(const char *value) {
4738
4763
  if (StringUtil::Equals(value, "NO_OUTPUT_POSSIBLE")) {
4739
4764
  return SinkFinalizeType::NO_OUTPUT_POSSIBLE;
4740
4765
  }
4766
+ if (StringUtil::Equals(value, "BLOCKED")) {
4767
+ return SinkFinalizeType::BLOCKED;
4768
+ }
4741
4769
  throw NotImplementedException(StringUtil::Format("Enum value: '%s' not implemented", value));
4742
4770
  }
4743
4771
 
@@ -1,6 +1,7 @@
1
1
  #include "duckdb/common/types/hugeint.hpp"
2
2
  #include "duckdb/common/exception.hpp"
3
3
  #include "duckdb/common/algorithm.hpp"
4
+ #include "duckdb/common/hugeint.hpp"
4
5
  #include "duckdb/common/limits.hpp"
5
6
  #include "duckdb/common/windows_undefs.hpp"
6
7
  #include "duckdb/common/types/value.hpp"
@@ -763,6 +764,45 @@ hugeint_t &hugeint_t::operator^=(const hugeint_t &rhs) {
763
764
  return *this;
764
765
  }
765
766
 
767
+ bool hugeint_t::operator!() const {
768
+ return *this == 0;
769
+ }
770
+
771
+ hugeint_t::operator bool() const {
772
+ return *this != 0;
773
+ }
774
+
775
+ template <class T>
776
+ static T NarrowCast(const hugeint_t &input) {
777
+ // NarrowCast is supposed to truncate (take lower)
778
+ return static_cast<T>(input.lower);
779
+ }
780
+
781
+ hugeint_t::operator uint8_t() const {
782
+ return NarrowCast<uint8_t>(*this);
783
+ }
784
+ hugeint_t::operator uint16_t() const {
785
+ return NarrowCast<uint16_t>(*this);
786
+ }
787
+ hugeint_t::operator uint32_t() const {
788
+ return NarrowCast<uint32_t>(*this);
789
+ }
790
+ hugeint_t::operator uint64_t() const {
791
+ return NarrowCast<uint64_t>(*this);
792
+ }
793
+ hugeint_t::operator int8_t() const {
794
+ return NarrowCast<int8_t>(*this);
795
+ }
796
+ hugeint_t::operator int16_t() const {
797
+ return NarrowCast<int16_t>(*this);
798
+ }
799
+ hugeint_t::operator int32_t() const {
800
+ return NarrowCast<int32_t>(*this);
801
+ }
802
+ hugeint_t::operator int64_t() const {
803
+ return NarrowCast<int64_t>(*this);
804
+ }
805
+
766
806
  string hugeint_t::ToString() const {
767
807
  return Hugeint::ToString(*this);
768
808
  }
@@ -310,6 +310,7 @@ static StaticFunctionDefinition internal_functions[] = {
310
310
  DUCKDB_SCALAR_FUNCTION_SET(TimezoneFun),
311
311
  DUCKDB_SCALAR_FUNCTION_SET(TimezoneHourFun),
312
312
  DUCKDB_SCALAR_FUNCTION_SET(TimezoneMinuteFun),
313
+ DUCKDB_SCALAR_FUNCTION_SET(ToBaseFun),
313
314
  DUCKDB_SCALAR_FUNCTION(ToBase64Fun),
314
315
  DUCKDB_SCALAR_FUNCTION_SET_ALIAS(ToBinaryFun),
315
316
  DUCKDB_SCALAR_FUNCTION(ToDaysFun),
@@ -0,0 +1,66 @@
1
+ #include "duckdb/core_functions/scalar/string_functions.hpp"
2
+ #include "duckdb/common/vector_operations/vector_operations.hpp"
3
+ #include "duckdb/planner/expression/bound_constant_expression.hpp"
4
+
5
+ namespace duckdb {
6
+
7
+ static const char alphabet[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
8
+
9
+ static unique_ptr<FunctionData> ToBaseBind(ClientContext &context, ScalarFunction &bound_function,
10
+ vector<unique_ptr<Expression>> &arguments) {
11
+ // If no min_length is specified, default to 0
12
+ D_ASSERT(arguments.size() == 2 || arguments.size() == 3);
13
+ if (arguments.size() == 2) {
14
+ arguments.push_back(make_uniq_base<Expression, BoundConstantExpression>(Value::INTEGER(0)));
15
+ }
16
+ return nullptr;
17
+ }
18
+
19
+ static void ToBaseFunction(DataChunk &args, ExpressionState &state, Vector &result) {
20
+ auto &input = args.data[0];
21
+ auto &radix = args.data[1];
22
+ auto &min_length = args.data[2];
23
+ auto count = args.size();
24
+
25
+ TernaryExecutor::Execute<int64_t, int32_t, int32_t, string_t>(
26
+ input, radix, min_length, result, count, [&](int64_t input, int32_t radix, int32_t min_length) {
27
+ if (input < 0) {
28
+ throw InvalidInputException("'to_base' number must be greater than or equal to 0");
29
+ }
30
+ if (radix < 2 || radix > 36) {
31
+ throw InvalidInputException("'to_base' radix must be between 2 and 36");
32
+ }
33
+ if (min_length > 64 || min_length < 0) {
34
+ throw InvalidInputException("'to_base' min_length must be between 0 and 64");
35
+ }
36
+
37
+ char buf[64];
38
+ char *end = buf + sizeof(buf);
39
+ char *ptr = end;
40
+ do {
41
+ *--ptr = alphabet[input % radix];
42
+ input /= radix;
43
+ } while (input > 0);
44
+
45
+ auto length = end - ptr;
46
+ while (length < min_length) {
47
+ *--ptr = '0';
48
+ length++;
49
+ }
50
+
51
+ return StringVector::AddString(result, ptr, end - ptr);
52
+ });
53
+ }
54
+
55
+ ScalarFunctionSet ToBaseFun::GetFunctions() {
56
+ ScalarFunctionSet set("to_base");
57
+
58
+ set.AddFunction(
59
+ ScalarFunction({LogicalType::BIGINT, LogicalType::INTEGER}, LogicalType::VARCHAR, ToBaseFunction, ToBaseBind));
60
+ set.AddFunction(ScalarFunction({LogicalType::BIGINT, LogicalType::INTEGER, LogicalType::INTEGER},
61
+ LogicalType::VARCHAR, ToBaseFunction, ToBaseBind));
62
+
63
+ return set;
64
+ }
65
+
66
+ } // namespace duckdb
@@ -396,10 +396,10 @@ SinkResultType PhysicalHashAggregate::Sink(ExecutionContext &context, DataChunk
396
396
  return SinkResultType::NEED_MORE_INPUT;
397
397
  }
398
398
 
399
- void PhysicalHashAggregate::CombineDistinct(ExecutionContext &context, GlobalSinkState &state,
400
- LocalSinkState &lstate) const {
401
- auto &global_sink = state.Cast<HashAggregateGlobalState>();
402
- auto &sink = lstate.Cast<HashAggregateLocalState>();
399
+ void PhysicalHashAggregate::CombineDistinct(ExecutionContext &context, OperatorSinkCombineInput &input) const {
400
+
401
+ auto &global_sink = input.global_state.Cast<HashAggregateGlobalState>();
402
+ auto &sink = input.local_state.Cast<HashAggregateLocalState>();
403
403
 
404
404
  if (!distinct_collection_info) {
405
405
  return;
@@ -425,14 +425,15 @@ void PhysicalHashAggregate::CombineDistinct(ExecutionContext &context, GlobalSin
425
425
  }
426
426
  }
427
427
 
428
- void PhysicalHashAggregate::Combine(ExecutionContext &context, GlobalSinkState &state, LocalSinkState &lstate) const {
429
- auto &gstate = state.Cast<HashAggregateGlobalState>();
430
- auto &llstate = lstate.Cast<HashAggregateLocalState>();
428
+ SinkCombineResultType PhysicalHashAggregate::Combine(ExecutionContext &context, OperatorSinkCombineInput &input) const {
429
+ auto &gstate = input.global_state.Cast<HashAggregateGlobalState>();
430
+ auto &llstate = input.local_state.Cast<HashAggregateLocalState>();
431
431
 
432
- CombineDistinct(context, state, lstate);
432
+ OperatorSinkCombineInput combine_distinct_input {gstate, llstate, input.interrupt_state};
433
+ CombineDistinct(context, combine_distinct_input);
433
434
 
434
435
  if (CanSkipRegularSink()) {
435
- return;
436
+ return SinkCombineResultType::FINISHED;
436
437
  }
437
438
  for (idx_t i = 0; i < groupings.size(); i++) {
438
439
  auto &grouping_gstate = gstate.grouping_states[i];
@@ -442,6 +443,8 @@ void PhysicalHashAggregate::Combine(ExecutionContext &context, GlobalSinkState &
442
443
  auto &table = grouping.table_data;
443
444
  table.Combine(context, *grouping_gstate.table_state, *grouping_lstate.table_state);
444
445
  }
446
+
447
+ return SinkCombineResultType::FINISHED;
445
448
  }
446
449
 
447
450
  //! REGULAR FINALIZE EVENT
@@ -818,8 +821,8 @@ SinkFinalizeType PhysicalHashAggregate::FinalizeInternal(Pipeline &pipeline, Eve
818
821
  }
819
822
 
820
823
  SinkFinalizeType PhysicalHashAggregate::Finalize(Pipeline &pipeline, Event &event, ClientContext &context,
821
- GlobalSinkState &gstate_p) const {
822
- return FinalizeInternal(pipeline, event, context, gstate_p, true);
824
+ OperatorSinkFinalizeInput &input) const {
825
+ return FinalizeInternal(pipeline, event, context, input.global_state, true);
823
826
  }
824
827
 
825
828
  //===--------------------------------------------------------------------===//
@@ -159,13 +159,15 @@ SinkResultType PhysicalPerfectHashAggregate::Sink(ExecutionContext &context, Dat
159
159
  //===--------------------------------------------------------------------===//
160
160
  // Combine
161
161
  //===--------------------------------------------------------------------===//
162
- void PhysicalPerfectHashAggregate::Combine(ExecutionContext &context, GlobalSinkState &gstate_p,
163
- LocalSinkState &lstate_p) const {
164
- auto &lstate = lstate_p.Cast<PerfectHashAggregateLocalState>();
165
- auto &gstate = gstate_p.Cast<PerfectHashAggregateGlobalState>();
162
+ SinkCombineResultType PhysicalPerfectHashAggregate::Combine(ExecutionContext &context,
163
+ OperatorSinkCombineInput &input) const {
164
+ auto &lstate = input.local_state.Cast<PerfectHashAggregateLocalState>();
165
+ auto &gstate = input.global_state.Cast<PerfectHashAggregateGlobalState>();
166
166
 
167
167
  lock_guard<mutex> l(gstate.lock);
168
168
  gstate.ht->Combine(*lstate.ht);
169
+
170
+ return SinkCombineResultType::FINISHED;
169
171
  }
170
172
 
171
173
  //===--------------------------------------------------------------------===//
@@ -299,10 +299,9 @@ SinkResultType PhysicalUngroupedAggregate::Sink(ExecutionContext &context, DataC
299
299
  // Finalize
300
300
  //===--------------------------------------------------------------------===//
301
301
 
302
- void PhysicalUngroupedAggregate::CombineDistinct(ExecutionContext &context, GlobalSinkState &state,
303
- LocalSinkState &lstate) const {
304
- auto &global_sink = state.Cast<UngroupedAggregateGlobalState>();
305
- auto &source = lstate.Cast<UngroupedAggregateLocalState>();
302
+ void PhysicalUngroupedAggregate::CombineDistinct(ExecutionContext &context, OperatorSinkCombineInput &input) const {
303
+ auto &global_sink = input.global_state.Cast<UngroupedAggregateGlobalState>();
304
+ auto &source = input.local_state.Cast<UngroupedAggregateLocalState>();
306
305
 
307
306
  if (!distinct_data) {
308
307
  return;
@@ -319,10 +318,10 @@ void PhysicalUngroupedAggregate::CombineDistinct(ExecutionContext &context, Glob
319
318
  }
320
319
  }
321
320
 
322
- void PhysicalUngroupedAggregate::Combine(ExecutionContext &context, GlobalSinkState &state,
323
- LocalSinkState &lstate) const {
324
- auto &gstate = state.Cast<UngroupedAggregateGlobalState>();
325
- auto &source = lstate.Cast<UngroupedAggregateLocalState>();
321
+ SinkCombineResultType PhysicalUngroupedAggregate::Combine(ExecutionContext &context,
322
+ OperatorSinkCombineInput &input) const {
323
+ auto &gstate = input.global_state.Cast<UngroupedAggregateGlobalState>();
324
+ auto &source = input.local_state.Cast<UngroupedAggregateLocalState>();
326
325
  D_ASSERT(!gstate.finished);
327
326
 
328
327
  // finalize: combine the local state into the global state
@@ -330,7 +329,8 @@ void PhysicalUngroupedAggregate::Combine(ExecutionContext &context, GlobalSinkSt
330
329
  // use the combine method to combine the partial aggregates
331
330
  lock_guard<mutex> glock(gstate.lock);
332
331
 
333
- CombineDistinct(context, state, lstate);
332
+ OperatorSinkCombineInput distinct_input {gstate, source, input.interrupt_state};
333
+ CombineDistinct(context, distinct_input);
334
334
 
335
335
  for (idx_t aggr_idx = 0; aggr_idx < aggregates.size(); aggr_idx++) {
336
336
  auto &aggregate = aggregates[aggr_idx]->Cast<BoundAggregateExpression>();
@@ -353,6 +353,8 @@ void PhysicalUngroupedAggregate::Combine(ExecutionContext &context, GlobalSinkSt
353
353
  auto &client_profiler = QueryProfiler::Get(context.client);
354
354
  context.thread.profiler.Flush(*this, source.child_executor, "child_executor", 0);
355
355
  client_profiler.Flush(context.thread.profiler);
356
+
357
+ return SinkCombineResultType::FINISHED;
356
358
  }
357
359
 
358
360
  class UngroupedDistinctAggregateFinalizeTask : public ExecutorTask {
@@ -536,11 +538,11 @@ SinkFinalizeType PhysicalUngroupedAggregate::FinalizeDistinct(Pipeline &pipeline
536
538
  }
537
539
 
538
540
  SinkFinalizeType PhysicalUngroupedAggregate::Finalize(Pipeline &pipeline, Event &event, ClientContext &context,
539
- GlobalSinkState &gstate_p) const {
540
- auto &gstate = gstate_p.Cast<UngroupedAggregateGlobalState>();
541
+ OperatorSinkFinalizeInput &input) const {
542
+ auto &gstate = input.global_state.Cast<UngroupedAggregateGlobalState>();
541
543
 
542
544
  if (distinct_data) {
543
- return FinalizeDistinct(pipeline, event, context, gstate_p);
545
+ return FinalizeDistinct(pipeline, event, context, input.global_state);
544
546
  }
545
547
 
546
548
  D_ASSERT(!gstate.finished);
@@ -124,9 +124,11 @@ SinkResultType PhysicalWindow::Sink(ExecutionContext &context, DataChunk &chunk,
124
124
  return SinkResultType::NEED_MORE_INPUT;
125
125
  }
126
126
 
127
- void PhysicalWindow::Combine(ExecutionContext &context, GlobalSinkState &gstate_p, LocalSinkState &lstate_p) const {
128
- auto &lstate = lstate_p.Cast<WindowLocalSinkState>();
127
+ SinkCombineResultType PhysicalWindow::Combine(ExecutionContext &context, OperatorSinkCombineInput &input) const {
128
+ auto &lstate = input.local_state.Cast<WindowLocalSinkState>();
129
129
  lstate.Combine();
130
+
131
+ return SinkCombineResultType::FINISHED;
130
132
  }
131
133
 
132
134
  unique_ptr<LocalSinkState> PhysicalWindow::GetLocalSinkState(ExecutionContext &context) const {
@@ -139,8 +141,8 @@ unique_ptr<GlobalSinkState> PhysicalWindow::GetGlobalSinkState(ClientContext &co
139
141
  }
140
142
 
141
143
  SinkFinalizeType PhysicalWindow::Finalize(Pipeline &pipeline, Event &event, ClientContext &context,
142
- GlobalSinkState &gstate_p) const {
143
- auto &state = gstate_p.Cast<WindowGlobalSinkState>();
144
+ OperatorSinkFinalizeInput &input) const {
145
+ auto &state = input.global_state.Cast<WindowGlobalSinkState>();
144
146
 
145
147
  // Did we get any data?
146
148
  if (!state.global_partition->count) {
@@ -37,18 +37,20 @@ SinkResultType PhysicalBatchCollector::Sink(ExecutionContext &context, DataChunk
37
37
  return SinkResultType::NEED_MORE_INPUT;
38
38
  }
39
39
 
40
- void PhysicalBatchCollector::Combine(ExecutionContext &context, GlobalSinkState &gstate_p,
41
- LocalSinkState &lstate_p) const {
42
- auto &gstate = gstate_p.Cast<BatchCollectorGlobalState>();
43
- auto &state = lstate_p.Cast<BatchCollectorLocalState>();
40
+ SinkCombineResultType PhysicalBatchCollector::Combine(ExecutionContext &context,
41
+ OperatorSinkCombineInput &input) const {
42
+ auto &gstate = input.global_state.Cast<BatchCollectorGlobalState>();
43
+ auto &state = input.local_state.Cast<BatchCollectorLocalState>();
44
44
 
45
45
  lock_guard<mutex> lock(gstate.glock);
46
46
  gstate.data.Merge(state.data);
47
+
48
+ return SinkCombineResultType::FINISHED;
47
49
  }
48
50
 
49
51
  SinkFinalizeType PhysicalBatchCollector::Finalize(Pipeline &pipeline, Event &event, ClientContext &context,
50
- GlobalSinkState &gstate_p) const {
51
- auto &gstate = gstate_p.Cast<BatchCollectorGlobalState>();
52
+ OperatorSinkFinalizeInput &input) const {
53
+ auto &gstate = input.global_state.Cast<BatchCollectorGlobalState>();
52
54
  auto collection = gstate.data.FetchCollection();
53
55
  D_ASSERT(collection);
54
56
  auto result = make_uniq<MaterializedQueryResult>(statement_type, properties, names, std::move(collection),
@@ -18,8 +18,8 @@ SinkResultType PhysicalExplainAnalyze::Sink(ExecutionContext &context, DataChunk
18
18
  }
19
19
 
20
20
  SinkFinalizeType PhysicalExplainAnalyze::Finalize(Pipeline &pipeline, Event &event, ClientContext &context,
21
- GlobalSinkState &gstate_p) const {
22
- auto &gstate = gstate_p.Cast<ExplainAnalyzeStateGlobalState>();
21
+ OperatorSinkFinalizeInput &input) const {
22
+ auto &gstate = input.global_state.Cast<ExplainAnalyzeStateGlobalState>();
23
23
  auto &profiler = QueryProfiler::Get(context);
24
24
  gstate.analyzed_plan = profiler.ToString();
25
25
  return SinkFinalizeType::READY;
@@ -116,14 +116,16 @@ SinkResultType PhysicalLimit::Sink(ExecutionContext &context, DataChunk &chunk,
116
116
  return SinkResultType::NEED_MORE_INPUT;
117
117
  }
118
118
 
119
- void PhysicalLimit::Combine(ExecutionContext &context, GlobalSinkState &gstate_p, LocalSinkState &lstate_p) const {
120
- auto &gstate = gstate_p.Cast<LimitGlobalState>();
121
- auto &state = lstate_p.Cast<LimitLocalState>();
119
+ SinkCombineResultType PhysicalLimit::Combine(ExecutionContext &context, OperatorSinkCombineInput &input) const {
120
+ auto &gstate = input.global_state.Cast<LimitGlobalState>();
121
+ auto &state = input.local_state.Cast<LimitLocalState>();
122
122
 
123
123
  lock_guard<mutex> lock(gstate.glock);
124
124
  gstate.limit = state.limit;
125
125
  gstate.offset = state.offset;
126
126
  gstate.data.Merge(state.data);
127
+
128
+ return SinkCombineResultType::FINISHED;
127
129
  }
128
130
 
129
131
  //===--------------------------------------------------------------------===//
@@ -32,12 +32,12 @@ SinkResultType PhysicalMaterializedCollector::Sink(ExecutionContext &context, Da
32
32
  return SinkResultType::NEED_MORE_INPUT;
33
33
  }
34
34
 
35
- void PhysicalMaterializedCollector::Combine(ExecutionContext &context, GlobalSinkState &gstate_p,
36
- LocalSinkState &lstate_p) const {
37
- auto &gstate = gstate_p.Cast<MaterializedCollectorGlobalState>();
38
- auto &lstate = lstate_p.Cast<MaterializedCollectorLocalState>();
35
+ SinkCombineResultType PhysicalMaterializedCollector::Combine(ExecutionContext &context,
36
+ OperatorSinkCombineInput &input) const {
37
+ auto &gstate = input.global_state.Cast<MaterializedCollectorGlobalState>();
38
+ auto &lstate = input.local_state.Cast<MaterializedCollectorLocalState>();
39
39
  if (lstate.collection->Count() == 0) {
40
- return;
40
+ return SinkCombineResultType::FINISHED;
41
41
  }
42
42
 
43
43
  lock_guard<mutex> l(gstate.glock);
@@ -46,6 +46,8 @@ void PhysicalMaterializedCollector::Combine(ExecutionContext &context, GlobalSin
46
46
  } else {
47
47
  gstate.collection->Combine(*lstate.collection);
48
48
  }
49
+
50
+ return SinkCombineResultType::FINISHED;
49
51
  }
50
52
 
51
53
  unique_ptr<GlobalSinkState> PhysicalMaterializedCollector::GetGlobalSinkState(ClientContext &context) const {
@@ -57,20 +57,22 @@ SinkResultType PhysicalVacuum::Sink(ExecutionContext &context, DataChunk &chunk,
57
57
  return SinkResultType::NEED_MORE_INPUT;
58
58
  }
59
59
 
60
- void PhysicalVacuum::Combine(ExecutionContext &context, GlobalSinkState &gstate_p, LocalSinkState &lstate_p) const {
61
- auto &gstate = gstate_p.Cast<VacuumGlobalSinkState>();
62
- auto &lstate = lstate_p.Cast<VacuumLocalSinkState>();
60
+ SinkCombineResultType PhysicalVacuum::Combine(ExecutionContext &context, OperatorSinkCombineInput &input) const {
61
+ auto &gstate = input.global_state.Cast<VacuumGlobalSinkState>();
62
+ auto &lstate = input.local_state.Cast<VacuumLocalSinkState>();
63
63
 
64
64
  lock_guard<mutex> lock(gstate.stats_lock);
65
65
  D_ASSERT(gstate.column_distinct_stats.size() == lstate.column_distinct_stats.size());
66
66
  for (idx_t col_idx = 0; col_idx < gstate.column_distinct_stats.size(); col_idx++) {
67
67
  gstate.column_distinct_stats[col_idx]->Merge(*lstate.column_distinct_stats[col_idx]);
68
68
  }
69
+
70
+ return SinkCombineResultType::FINISHED;
69
71
  }
70
72
 
71
73
  SinkFinalizeType PhysicalVacuum::Finalize(Pipeline &pipeline, Event &event, ClientContext &context,
72
- GlobalSinkState &gstate) const {
73
- auto &sink = gstate.Cast<VacuumGlobalSinkState>();
74
+ OperatorSinkFinalizeInput &input) const {
75
+ auto &sink = input.global_state.Cast<VacuumGlobalSinkState>();
74
76
 
75
77
  auto table = info->table;
76
78
  for (idx_t col_idx = 0; col_idx < sink.column_distinct_stats.size(); col_idx++) {
@@ -143,17 +143,18 @@ SinkResultType PhysicalAsOfJoin::Sink(ExecutionContext &context, DataChunk &chun
143
143
  return SinkResultType::NEED_MORE_INPUT;
144
144
  }
145
145
 
146
- void PhysicalAsOfJoin::Combine(ExecutionContext &context, GlobalSinkState &gstate_p, LocalSinkState &lstate_p) const {
147
- auto &lstate = lstate_p.Cast<AsOfLocalSinkState>();
146
+ SinkCombineResultType PhysicalAsOfJoin::Combine(ExecutionContext &context, OperatorSinkCombineInput &input) const {
147
+ auto &lstate = input.local_state.Cast<AsOfLocalSinkState>();
148
148
  lstate.Combine();
149
+ return SinkCombineResultType::FINISHED;
149
150
  }
150
151
 
151
152
  //===--------------------------------------------------------------------===//
152
153
  // Finalize
153
154
  //===--------------------------------------------------------------------===//
154
155
  SinkFinalizeType PhysicalAsOfJoin::Finalize(Pipeline &pipeline, Event &event, ClientContext &context,
155
- GlobalSinkState &gstate_p) const {
156
- auto &gstate = gstate_p.Cast<AsOfGlobalSinkState>();
156
+ OperatorSinkFinalizeInput &input) const {
157
+ auto &gstate = input.global_state.Cast<AsOfGlobalSinkState>();
157
158
 
158
159
  // The data is all in so we can initialise the left partitioning.
159
160
  const vector<unique_ptr<BaseStatistics>> partitions_stats;
@@ -62,8 +62,8 @@ SinkResultType PhysicalBlockwiseNLJoin::Sink(ExecutionContext &context, DataChun
62
62
  // Finalize
63
63
  //===--------------------------------------------------------------------===//
64
64
  SinkFinalizeType PhysicalBlockwiseNLJoin::Finalize(Pipeline &pipeline, Event &event, ClientContext &context,
65
- GlobalSinkState &gstate_p) const {
66
- auto &gstate = gstate_p.Cast<BlockwiseNLJoinGlobalState>();
65
+ OperatorSinkFinalizeInput &input) const {
66
+ auto &gstate = input.global_state.Cast<BlockwiseNLJoinGlobalState>();
67
67
  gstate.right_outer.Initialize(gstate.right_chunks.Count());
68
68
 
69
69
  if (gstate.right_chunks.Count() == 0 && EmptyResultIfRHSIsEmpty()) {
@@ -98,18 +98,25 @@ SinkResultType PhysicalDelimJoin::Sink(ExecutionContext &context, DataChunk &chu
98
98
  return SinkResultType::NEED_MORE_INPUT;
99
99
  }
100
100
 
101
- void PhysicalDelimJoin::Combine(ExecutionContext &context, GlobalSinkState &state, LocalSinkState &lstate_p) const {
102
- auto &lstate = lstate_p.Cast<DelimJoinLocalState>();
103
- auto &gstate = state.Cast<DelimJoinGlobalState>();
101
+ SinkCombineResultType PhysicalDelimJoin::Combine(ExecutionContext &context, OperatorSinkCombineInput &input) const {
102
+ auto &lstate = input.local_state.Cast<DelimJoinLocalState>();
103
+ auto &gstate = input.global_state.Cast<DelimJoinGlobalState>();
104
104
  gstate.Merge(lstate.lhs_data);
105
- distinct->Combine(context, *distinct->sink_state, *lstate.distinct_state);
105
+
106
+ OperatorSinkCombineInput distinct_combine_input {*distinct->sink_state, *lstate.distinct_state,
107
+ input.interrupt_state};
108
+ distinct->Combine(context, distinct_combine_input);
109
+
110
+ return SinkCombineResultType::FINISHED;
106
111
  }
107
112
 
108
113
  SinkFinalizeType PhysicalDelimJoin::Finalize(Pipeline &pipeline, Event &event, ClientContext &client,
109
- GlobalSinkState &gstate) const {
114
+ OperatorSinkFinalizeInput &input) const {
110
115
  // finalize the distinct HT
111
116
  D_ASSERT(distinct);
112
- distinct->Finalize(pipeline, event, client, *distinct->sink_state);
117
+
118
+ OperatorSinkFinalizeInput finalize_input {*distinct->sink_state, input.interrupt_state};
119
+ distinct->Finalize(pipeline, event, client, finalize_input);
113
120
  return SinkFinalizeType::READY;
114
121
  }
115
122
 
@@ -210,9 +210,9 @@ SinkResultType PhysicalHashJoin::Sink(ExecutionContext &context, DataChunk &chun
210
210
  return SinkResultType::NEED_MORE_INPUT;
211
211
  }
212
212
 
213
- void PhysicalHashJoin::Combine(ExecutionContext &context, GlobalSinkState &gstate_p, LocalSinkState &lstate_p) const {
214
- auto &gstate = gstate_p.Cast<HashJoinGlobalSinkState>();
215
- auto &lstate = lstate_p.Cast<HashJoinLocalSinkState>();
213
+ SinkCombineResultType PhysicalHashJoin::Combine(ExecutionContext &context, OperatorSinkCombineInput &input) const {
214
+ auto &gstate = input.global_state.Cast<HashJoinGlobalSinkState>();
215
+ auto &lstate = input.local_state.Cast<HashJoinLocalSinkState>();
216
216
  if (lstate.hash_table) {
217
217
  lstate.hash_table->GetSinkCollection().FlushAppendState(lstate.append_state);
218
218
  lock_guard<mutex> local_ht_lock(gstate.lock);
@@ -221,6 +221,8 @@ void PhysicalHashJoin::Combine(ExecutionContext &context, GlobalSinkState &gstat
221
221
  auto &client_profiler = QueryProfiler::Get(context.client);
222
222
  context.thread.profiler.Flush(*this, lstate.build_executor, "build_executor", 1);
223
223
  client_profiler.Flush(context.thread.profiler);
224
+
225
+ return SinkCombineResultType::FINISHED;
224
226
  }
225
227
 
226
228
  //===--------------------------------------------------------------------===//
@@ -362,8 +364,8 @@ public:
362
364
  };
363
365
 
364
366
  SinkFinalizeType PhysicalHashJoin::Finalize(Pipeline &pipeline, Event &event, ClientContext &context,
365
- GlobalSinkState &gstate) const {
366
- auto &sink = gstate.Cast<HashJoinGlobalSinkState>();
367
+ OperatorSinkFinalizeInput &input) const {
368
+ auto &sink = input.global_state.Cast<HashJoinGlobalSinkState>();
367
369
  auto &ht = *sink.hash_table;
368
370
 
369
371
  sink.external = ht.RequiresExternalJoin(context.config, sink.local_hash_tables);
@@ -143,22 +143,24 @@ SinkResultType PhysicalIEJoin::Sink(ExecutionContext &context, DataChunk &chunk,
143
143
  return SinkResultType::NEED_MORE_INPUT;
144
144
  }
145
145
 
146
- void PhysicalIEJoin::Combine(ExecutionContext &context, GlobalSinkState &gstate_p, LocalSinkState &lstate_p) const {
147
- auto &gstate = gstate_p.Cast<IEJoinGlobalState>();
148
- auto &lstate = lstate_p.Cast<IEJoinLocalState>();
146
+ SinkCombineResultType PhysicalIEJoin::Combine(ExecutionContext &context, OperatorSinkCombineInput &input) const {
147
+ auto &gstate = input.global_state.Cast<IEJoinGlobalState>();
148
+ auto &lstate = input.local_state.Cast<IEJoinLocalState>();
149
149
  gstate.tables[gstate.child]->Combine(lstate.table);
150
150
  auto &client_profiler = QueryProfiler::Get(context.client);
151
151
 
152
152
  context.thread.profiler.Flush(*this, lstate.table.executor, gstate.child ? "rhs_executor" : "lhs_executor", 1);
153
153
  client_profiler.Flush(context.thread.profiler);
154
+
155
+ return SinkCombineResultType::FINISHED;
154
156
  }
155
157
 
156
158
  //===--------------------------------------------------------------------===//
157
159
  // Finalize
158
160
  //===--------------------------------------------------------------------===//
159
161
  SinkFinalizeType PhysicalIEJoin::Finalize(Pipeline &pipeline, Event &event, ClientContext &context,
160
- GlobalSinkState &gstate_p) const {
161
- auto &gstate = gstate_p.Cast<IEJoinGlobalState>();
162
+ OperatorSinkFinalizeInput &input) const {
163
+ auto &gstate = input.global_state.Cast<IEJoinGlobalState>();
162
164
  auto &table = *gstate.tables[gstate.child];
163
165
  auto &global_sort_state = table.global_sort_state;
164
166