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
@@ -13,11 +13,17 @@
13
13
  #include "duckdb/common/exception.hpp"
14
14
  #include "duckdb/common/helper.hpp"
15
15
  #include "duckdb/common/limits.hpp"
16
+ #include "duckdb/common/numeric_utils.hpp"
16
17
 
17
18
  namespace duckdb {
18
19
 
19
20
  using bitpacking_width_t = uint8_t;
20
21
 
22
+ struct HugeIntPacker {
23
+ static void Pack(const hugeint_t *__restrict in, uint32_t *__restrict out, bitpacking_width_t width);
24
+ static void Unpack(const uint32_t *__restrict in, hugeint_t *__restrict out, bitpacking_width_t width);
25
+ };
26
+
21
27
  class BitpackingPrimitives {
22
28
 
23
29
  public:
@@ -37,9 +43,7 @@ public:
37
43
  idx_t misaligned_count = count % BITPACKING_ALGORITHM_GROUP_SIZE;
38
44
  T tmp_buffer[BITPACKING_ALGORITHM_GROUP_SIZE]; // TODO maybe faster on the heap?
39
45
 
40
- if (misaligned_count) {
41
- count -= misaligned_count;
42
- }
46
+ count -= misaligned_count;
43
47
 
44
48
  for (idx_t i = 0; i < count; i += BITPACKING_ALGORITHM_GROUP_SIZE) {
45
49
  PackGroup<T>(dst + (i * width) / 8, src + i, width);
@@ -78,22 +82,22 @@ public:
78
82
  }
79
83
 
80
84
  // Calculates the minimum required number of bits per value that can store all values
81
- template <class T>
85
+ template <class T, bool is_signed = NumericLimits<T>::IsSigned()>
82
86
  inline static bitpacking_width_t MinimumBitWidth(T value) {
83
- return FindMinimumBitWidth<T, BYTE_ALIGNED>(value, value);
87
+ return FindMinimumBitWidth<T, is_signed, BYTE_ALIGNED>(value, value);
84
88
  }
85
89
 
86
90
  // Calculates the minimum required number of bits per value that can store all values
87
- template <class T>
91
+ template <class T, bool is_signed = NumericLimits<T>::IsSigned()>
88
92
  inline static bitpacking_width_t MinimumBitWidth(T *values, idx_t count) {
89
- return FindMinimumBitWidth<T, BYTE_ALIGNED>(values, count);
93
+ return FindMinimumBitWidth<T, is_signed, BYTE_ALIGNED>(values, count);
90
94
  }
91
95
 
92
96
  // Calculates the minimum required number of bits per value that can store all values,
93
97
  // given a predetermined minimum and maximum value of the buffer
94
- template <class T>
98
+ template <class T, bool is_signed = NumericLimits<T>::IsSigned()>
95
99
  inline static bitpacking_width_t MinimumBitWidth(T minimum, T maximum) {
96
- return FindMinimumBitWidth<T, BYTE_ALIGNED>(minimum, maximum);
100
+ return FindMinimumBitWidth<T, is_signed, BYTE_ALIGNED>(minimum, maximum);
97
101
  }
98
102
 
99
103
  inline static idx_t GetRequiredSize(idx_t count, bitpacking_width_t width) {
@@ -112,7 +116,7 @@ public:
112
116
  }
113
117
 
114
118
  private:
115
- template <class T, bool round_to_next_byte = false>
119
+ template <class T, bool is_signed, bool round_to_next_byte = false>
116
120
  static bitpacking_width_t FindMinimumBitWidth(T *values, idx_t count) {
117
121
  T min_value = values[0];
118
122
  T max_value = values[0];
@@ -122,7 +126,7 @@ private:
122
126
  max_value = values[i];
123
127
  }
124
128
 
125
- if (std::is_signed<T>::value) {
129
+ if (is_signed) {
126
130
  if (values[i] < min_value) {
127
131
  min_value = values[i];
128
132
  }
@@ -132,12 +136,12 @@ private:
132
136
  return FindMinimumBitWidth<T, round_to_next_byte>(min_value, max_value);
133
137
  }
134
138
 
135
- template <class T, bool round_to_next_byte = false>
139
+ template <class T, bool is_signed, bool round_to_next_byte = false>
136
140
  static bitpacking_width_t FindMinimumBitWidth(T min_value, T max_value) {
137
141
  bitpacking_width_t bitwidth;
138
142
  T value;
139
143
 
140
- if (std::is_signed<T>::value) {
144
+ if (is_signed) {
141
145
  if (min_value == NumericLimits<T>::Minimum()) {
142
146
  // handle special case of the minimal value, as it cannot be negated like all other values.
143
147
  return sizeof(T) * 8;
@@ -152,7 +156,7 @@ private:
152
156
  return 0;
153
157
  }
154
158
 
155
- if (std::is_signed<T>::value) {
159
+ if (is_signed) {
156
160
  bitwidth = 1;
157
161
  } else {
158
162
  bitwidth = 0;
@@ -168,58 +172,37 @@ private:
168
172
  // Assert results are correct
169
173
  #ifdef DEBUG
170
174
  if (bitwidth < sizeof(T) * 8 && bitwidth != 0) {
171
- if (std::is_signed<T>::value) {
172
- D_ASSERT((int64_t)max_value <= (int64_t)(1L << (bitwidth - 1)) - 1);
173
- D_ASSERT((int64_t)min_value >= (int64_t)(-1 * ((1L << (bitwidth - 1)) - 1) - 1));
175
+ if (is_signed) {
176
+ D_ASSERT(max_value <= (T(1) << (bitwidth - 1)) - 1);
177
+ D_ASSERT(min_value >= (T(-1) * ((T(1) << (bitwidth - 1)) - 1) - 1));
174
178
  } else {
175
- D_ASSERT((uint64_t)max_value <= (uint64_t)(1L << (bitwidth)) - 1);
179
+ D_ASSERT(max_value <= (T(1) << (bitwidth)) - 1);
176
180
  }
177
181
  }
178
182
  #endif
179
183
  if (round_to_next_byte) {
180
184
  return (bitwidth / 8 + (bitwidth % 8 != 0)) * 8;
181
- } else {
182
- return bitwidth;
183
185
  }
186
+ return bitwidth;
184
187
  }
185
188
 
186
189
  // Sign bit extension
187
- template <class T, class T_U = typename std::make_unsigned<T>::type>
190
+ template <class T, class T_U = typename MakeUnsigned<T>::type>
188
191
  static void SignExtend(data_ptr_t dst, bitpacking_width_t width) {
189
- T const mask = ((T_U)1) << (width - 1);
192
+ T const mask = T_U(1) << (width - 1);
190
193
  for (idx_t i = 0; i < BitpackingPrimitives::BITPACKING_ALGORITHM_GROUP_SIZE; ++i) {
191
194
  T value = Load<T>(dst + i * sizeof(T));
192
- value = value & ((((T_U)1) << width) - ((T_U)1));
195
+ value = value & ((T_U(1) << width) - T_U(1));
193
196
  T result = (value ^ mask) - mask;
194
197
  Store(result, dst + i * sizeof(T));
195
198
  }
196
199
  }
197
200
 
198
- template <class T>
199
- static void UnPackGroup(data_ptr_t dst, data_ptr_t src, bitpacking_width_t width,
200
- bool skip_sign_extension = false) {
201
- if (std::is_same<T, uint8_t>::value || std::is_same<T, int8_t>::value) {
202
- duckdb_fastpforlib::fastunpack((const uint8_t *)src, (uint8_t *)dst, (uint32_t)width);
203
- } else if (std::is_same<T, uint16_t>::value || std::is_same<T, int16_t>::value) {
204
- duckdb_fastpforlib::fastunpack((const uint16_t *)src, (uint16_t *)dst, (uint32_t)width);
205
- } else if (std::is_same<T, uint32_t>::value || std::is_same<T, int32_t>::value) {
206
- duckdb_fastpforlib::fastunpack((const uint32_t *)src, (uint32_t *)dst, (uint32_t)width);
207
- } else if (std::is_same<T, uint64_t>::value || std::is_same<T, int64_t>::value) {
208
- duckdb_fastpforlib::fastunpack((const uint32_t *)src, (uint64_t *)dst, (uint32_t)width);
209
- } else {
210
- throw InternalException("Unsupported type found in bitpacking.");
211
- }
212
-
213
- if (NumericLimits<T>::IsSigned() && !skip_sign_extension && width > 0 && width < sizeof(T) * 8) {
214
- SignExtend<T>(dst, width);
215
- }
216
- }
217
-
218
201
  // Prevent compression at widths that are ineffective
219
202
  template <class T>
220
203
  static bitpacking_width_t GetEffectiveWidth(bitpacking_width_t width) {
221
- auto bits_of_type = sizeof(T) * 8;
222
- auto type_size = sizeof(T);
204
+ bitpacking_width_t bits_of_type = sizeof(T) * 8;
205
+ bitpacking_width_t type_size = sizeof(T);
223
206
  if (width + type_size > bits_of_type) {
224
207
  return bits_of_type;
225
208
  }
@@ -227,17 +210,49 @@ private:
227
210
  }
228
211
 
229
212
  template <class T>
230
- static void PackGroup(data_ptr_t dst, T *values, bitpacking_width_t width) {
231
- if (std::is_same<T, uint8_t>::value || std::is_same<T, int8_t>::value) {
232
- duckdb_fastpforlib::fastpack((const uint8_t *)values, (uint8_t *)dst, (uint32_t)width);
233
- } else if (std::is_same<T, uint16_t>::value || std::is_same<T, int16_t>::value) {
234
- duckdb_fastpforlib::fastpack((const uint16_t *)values, (uint16_t *)dst, (uint32_t)width);
235
- } else if (std::is_same<T, uint32_t>::value || std::is_same<T, int32_t>::value) {
236
- duckdb_fastpforlib::fastpack((const uint32_t *)values, (uint32_t *)dst, (uint32_t)width);
237
- } else if (std::is_same<T, uint64_t>::value || std::is_same<T, int64_t>::value) {
238
- duckdb_fastpforlib::fastpack((const uint64_t *)values, (uint32_t *)dst, (uint32_t)width);
213
+ static inline void PackGroup(data_ptr_t dst, T *values, bitpacking_width_t width) {
214
+ if (std::is_same<T, int8_t>::value || std::is_same<T, uint8_t>::value) {
215
+ duckdb_fastpforlib::fastpack(reinterpret_cast<const uint8_t *>(values), reinterpret_cast<uint8_t *>(dst),
216
+ static_cast<uint32_t>(width));
217
+ } else if (std::is_same<T, int16_t>::value || std::is_same<T, uint16_t>::value) {
218
+ duckdb_fastpforlib::fastpack(reinterpret_cast<const uint16_t *>(values), reinterpret_cast<uint16_t *>(dst),
219
+ static_cast<uint32_t>(width));
220
+ } else if (std::is_same<T, int32_t>::value || std::is_same<T, uint32_t>::value) {
221
+ duckdb_fastpforlib::fastpack(reinterpret_cast<const uint32_t *>(values), reinterpret_cast<uint32_t *>(dst),
222
+ static_cast<uint32_t>(width));
223
+ } else if (std::is_same<T, int64_t>::value || std::is_same<T, uint64_t>::value) {
224
+ duckdb_fastpforlib::fastpack(reinterpret_cast<const uint64_t *>(values), reinterpret_cast<uint32_t *>(dst),
225
+ static_cast<uint32_t>(width));
226
+ } else if (std::is_same<T, hugeint_t>::value) {
227
+ HugeIntPacker::Pack(reinterpret_cast<const hugeint_t *>(values), reinterpret_cast<uint32_t *>(dst), width);
239
228
  } else {
240
- throw InternalException("Unsupported type found in bitpacking.");
229
+ throw InternalException("Unsupported type for bitpacking");
230
+ }
231
+ }
232
+
233
+ template <class T>
234
+ static inline void UnPackGroup(data_ptr_t dst, data_ptr_t src, bitpacking_width_t width,
235
+ bool skip_sign_extension = false) {
236
+ if (std::is_same<T, int8_t>::value || std::is_same<T, uint8_t>::value) {
237
+ duckdb_fastpforlib::fastunpack(reinterpret_cast<const uint8_t *>(src), reinterpret_cast<uint8_t *>(dst),
238
+ static_cast<uint32_t>(width));
239
+ } else if (std::is_same<T, int16_t>::value || std::is_same<T, uint16_t>::value) {
240
+ duckdb_fastpforlib::fastunpack(reinterpret_cast<const uint16_t *>(src), reinterpret_cast<uint16_t *>(dst),
241
+ static_cast<uint32_t>(width));
242
+ } else if (std::is_same<T, int32_t>::value || std::is_same<T, uint32_t>::value) {
243
+ duckdb_fastpforlib::fastunpack(reinterpret_cast<const uint32_t *>(src), reinterpret_cast<uint32_t *>(dst),
244
+ static_cast<uint32_t>(width));
245
+ } else if (std::is_same<T, int64_t>::value || std::is_same<T, uint64_t>::value) {
246
+ duckdb_fastpforlib::fastunpack(reinterpret_cast<const uint32_t *>(src), reinterpret_cast<uint64_t *>(dst),
247
+ static_cast<uint32_t>(width));
248
+ } else if (std::is_same<T, hugeint_t>::value) {
249
+ HugeIntPacker::Unpack(reinterpret_cast<const uint32_t *>(src), reinterpret_cast<hugeint_t *>(dst), width);
250
+ } else {
251
+ throw InternalException("Unsupported type for bitpacking");
252
+ }
253
+
254
+ if (NumericLimits<T>::IsSigned() && !skip_sign_extension && width > 0 && width < sizeof(T) * 8) {
255
+ SignExtend<T>(dst, width);
241
256
  }
242
257
  }
243
258
  };
@@ -214,6 +214,8 @@ enum class SetType : uint8_t;
214
214
 
215
215
  enum class SimplifiedTokenType : uint8_t;
216
216
 
217
+ enum class SinkCombineResultType : uint8_t;
218
+
217
219
  enum class SinkFinalizeType : uint8_t;
218
220
 
219
221
  enum class SinkResultType : uint8_t;
@@ -544,6 +546,9 @@ const char* EnumUtil::ToChars<SetType>(SetType value);
544
546
  template<>
545
547
  const char* EnumUtil::ToChars<SimplifiedTokenType>(SimplifiedTokenType value);
546
548
 
549
+ template<>
550
+ const char* EnumUtil::ToChars<SinkCombineResultType>(SinkCombineResultType value);
551
+
547
552
  template<>
548
553
  const char* EnumUtil::ToChars<SinkFinalizeType>(SinkFinalizeType value);
549
554
 
@@ -902,6 +907,9 @@ SetType EnumUtil::FromString<SetType>(const char *value);
902
907
  template<>
903
908
  SimplifiedTokenType EnumUtil::FromString<SimplifiedTokenType>(const char *value);
904
909
 
910
+ template<>
911
+ SinkCombineResultType EnumUtil::FromString<SinkCombineResultType>(const char *value);
912
+
905
913
  template<>
906
914
  SinkFinalizeType EnumUtil::FromString<SinkFinalizeType>(const char *value);
907
915
 
@@ -46,10 +46,14 @@ enum class SourceResultType : uint8_t { HAVE_MORE_OUTPUT, FINISHED, BLOCKED };
46
46
  //! BLOCKED means the sink is currently blocked, e.g. by some async I/O.
47
47
  enum class SinkResultType : uint8_t { NEED_MORE_INPUT, FINISHED, BLOCKED };
48
48
 
49
+ // todo comment
50
+ enum class SinkCombineResultType : uint8_t { FINISHED, BLOCKED };
51
+
49
52
  //! The SinkFinalizeType is used to indicate the result of a Finalize call on a sink
50
53
  //! There are two possible results:
51
54
  //! READY means the sink is ready for further processing
52
55
  //! NO_OUTPUT_POSSIBLE means the sink will never provide output, and any pipelines involving the sink can be skipped
53
- enum class SinkFinalizeType : uint8_t { READY, NO_OUTPUT_POSSIBLE };
56
+ //! BLOCKED means the finalize call to the sink is currently blocked, e.g. by some async I/O.
57
+ enum class SinkFinalizeType : uint8_t { READY, NO_OUTPUT_POSSIBLE, BLOCKED };
54
58
 
55
59
  } // namespace duckdb
@@ -3,6 +3,7 @@
3
3
  #include "duckdb/common/winapi.hpp"
4
4
  #include "duckdb/common/string.hpp"
5
5
  #include <stdint.h>
6
+ #include "duckdb/common/typedefs.hpp"
6
7
 
7
8
  namespace duckdb {
8
9
 
@@ -58,6 +59,20 @@ public:
58
59
  DUCKDB_API hugeint_t &operator&=(const hugeint_t &rhs);
59
60
  DUCKDB_API hugeint_t &operator|=(const hugeint_t &rhs);
60
61
  DUCKDB_API hugeint_t &operator^=(const hugeint_t &rhs);
62
+
63
+ // boolean operators
64
+ DUCKDB_API explicit operator bool() const;
65
+ DUCKDB_API bool operator!() const;
66
+
67
+ // cast operators
68
+ DUCKDB_API explicit operator uint8_t() const;
69
+ DUCKDB_API explicit operator uint16_t() const;
70
+ DUCKDB_API explicit operator uint32_t() const;
71
+ DUCKDB_API explicit operator uint64_t() const;
72
+ DUCKDB_API explicit operator int8_t() const;
73
+ DUCKDB_API explicit operator int16_t() const;
74
+ DUCKDB_API explicit operator int32_t() const;
75
+ DUCKDB_API explicit operator int64_t() const;
61
76
  };
62
77
 
63
78
  } // namespace duckdb
@@ -8,8 +8,11 @@
8
8
 
9
9
  #pragma once
10
10
 
11
+ #include "duckdb/common/hugeint.hpp"
11
12
  #include "duckdb/common/types.hpp"
12
13
 
14
+ #include <type_traits>
15
+
13
16
  // Undef annoying windows macro
14
17
  #undef max
15
18
 
@@ -21,75 +24,16 @@ template <class T>
21
24
  struct NumericLimits {
22
25
  static constexpr T Minimum() {
23
26
  return std::numeric_limits<T>::lowest();
24
- };
27
+ }
25
28
  static constexpr T Maximum() {
26
29
  return std::numeric_limits<T>::max();
27
- };
28
- DUCKDB_API static bool IsSigned();
29
- DUCKDB_API static idx_t Digits();
30
- };
31
-
32
- template <>
33
- struct NumericLimits<int8_t> {
34
- static constexpr int8_t Minimum() {
35
- return std::numeric_limits<int8_t>::lowest();
36
- };
37
- static constexpr int8_t Maximum() {
38
- return std::numeric_limits<int8_t>::max();
39
- };
40
- static bool IsSigned() {
41
- return true;
42
- }
43
- static idx_t Digits() {
44
- return 3;
45
- }
46
- };
47
- template <>
48
- struct NumericLimits<int16_t> {
49
- static constexpr int16_t Minimum() {
50
- return std::numeric_limits<int16_t>::lowest();
51
- };
52
- static constexpr int16_t Maximum() {
53
- return std::numeric_limits<int16_t>::max();
54
- };
55
- static bool IsSigned() {
56
- return true;
57
- }
58
- static idx_t Digits() {
59
- return 5;
60
- }
61
- };
62
- template <>
63
- struct NumericLimits<int32_t> {
64
- static constexpr int32_t Minimum() {
65
- return std::numeric_limits<int32_t>::lowest();
66
- };
67
- static constexpr int32_t Maximum() {
68
- return std::numeric_limits<int32_t>::max();
69
- };
70
- static bool IsSigned() {
71
- return true;
72
30
  }
73
- static idx_t Digits() {
74
- return 10;
31
+ DUCKDB_API static constexpr bool IsSigned() {
32
+ return std::is_signed<T>::value;
75
33
  }
34
+ DUCKDB_API static constexpr idx_t Digits();
76
35
  };
77
36
 
78
- template <>
79
- struct NumericLimits<int64_t> {
80
- static constexpr int64_t Minimum() {
81
- return std::numeric_limits<int64_t>::lowest();
82
- };
83
- static constexpr int64_t Maximum() {
84
- return std::numeric_limits<int64_t>::max();
85
- };
86
- static bool IsSigned() {
87
- return true;
88
- }
89
- static idx_t Digits() {
90
- return 19;
91
- }
92
- };
93
37
  template <>
94
38
  struct NumericLimits<hugeint_t> {
95
39
  static constexpr hugeint_t Minimum() {
@@ -98,104 +42,63 @@ struct NumericLimits<hugeint_t> {
98
42
  static constexpr hugeint_t Maximum() {
99
43
  return {std::numeric_limits<int64_t>::max(), std::numeric_limits<uint64_t>::max()};
100
44
  };
101
- static bool IsSigned() {
45
+ static constexpr bool IsSigned() {
102
46
  return true;
103
47
  }
104
- static idx_t Digits() {
48
+
49
+ static constexpr idx_t Digits() {
105
50
  return 39;
106
51
  }
107
52
  };
108
53
 
109
54
  template <>
110
- struct NumericLimits<uint8_t> {
111
- static constexpr uint8_t Minimum() {
112
- return std::numeric_limits<uint8_t>::lowest();
113
- };
114
- static constexpr uint8_t Maximum() {
115
- return std::numeric_limits<uint8_t>::max();
116
- };
117
- static bool IsSigned() {
118
- return false;
119
- }
120
- static idx_t Digits() {
121
- return 3;
122
- }
123
- };
55
+ constexpr idx_t NumericLimits<int8_t>::Digits() {
56
+ return 3;
57
+ }
124
58
 
125
59
  template <>
126
- struct NumericLimits<uint16_t> {
127
- static constexpr uint16_t Minimum() {
128
- return std::numeric_limits<uint16_t>::lowest();
129
- };
130
- static constexpr uint16_t Maximum() {
131
- return std::numeric_limits<uint16_t>::max();
132
- };
133
- static bool IsSigned() {
134
- return false;
135
- }
136
- static idx_t Digits() {
137
- return 5;
138
- }
139
- };
60
+ constexpr idx_t NumericLimits<int16_t>::Digits() {
61
+ return 5;
62
+ }
63
+
140
64
  template <>
141
- struct NumericLimits<uint32_t> {
142
- static constexpr uint32_t Minimum() {
143
- return std::numeric_limits<uint32_t>::lowest();
144
- };
145
- static constexpr uint32_t Maximum() {
146
- return std::numeric_limits<uint32_t>::max();
147
- };
148
- static bool IsSigned() {
149
- return false;
150
- }
151
- static idx_t Digits() {
152
- return 10;
153
- }
154
- };
65
+ constexpr idx_t NumericLimits<int32_t>::Digits() {
66
+ return 10;
67
+ }
68
+
155
69
  template <>
156
- struct NumericLimits<uint64_t> {
157
- static constexpr uint64_t Minimum() {
158
- return std::numeric_limits<uint64_t>::lowest();
159
- };
160
- static constexpr uint64_t Maximum() {
161
- return std::numeric_limits<uint64_t>::max();
162
- };
163
- static bool IsSigned() {
164
- return false;
165
- }
166
- static idx_t Digits() {
167
- return 20;
168
- }
169
- };
70
+ constexpr idx_t NumericLimits<int64_t>::Digits() {
71
+ return 19;
72
+ }
73
+
170
74
  template <>
171
- struct NumericLimits<float> {
172
- static constexpr float Minimum() {
173
- return std::numeric_limits<float>::lowest();
174
- };
175
- static constexpr float Maximum() {
176
- return std::numeric_limits<float>::max();
177
- };
178
- static bool IsSigned() {
179
- return true;
180
- }
181
- static idx_t Digits() {
182
- return 127;
183
- }
184
- };
75
+ constexpr idx_t NumericLimits<uint8_t>::Digits() {
76
+ return 3;
77
+ }
78
+
185
79
  template <>
186
- struct NumericLimits<double> {
187
- static constexpr double Minimum() {
188
- return std::numeric_limits<double>::lowest();
189
- };
190
- static constexpr double Maximum() {
191
- return std::numeric_limits<double>::max();
192
- };
193
- static bool IsSigned() {
194
- return true;
195
- }
196
- static idx_t Digits() {
197
- return 250;
198
- }
199
- };
80
+ constexpr idx_t NumericLimits<uint16_t>::Digits() {
81
+ return 5;
82
+ }
83
+
84
+ template <>
85
+ constexpr idx_t NumericLimits<uint32_t>::Digits() {
86
+ return 10;
87
+ }
88
+
89
+ template <>
90
+ constexpr idx_t NumericLimits<uint64_t>::Digits() {
91
+ return 20;
92
+ }
93
+
94
+ template <>
95
+ constexpr idx_t NumericLimits<float>::Digits() {
96
+ return 127;
97
+ }
98
+
99
+ template <>
100
+ constexpr idx_t NumericLimits<double>::Digits() {
101
+ return 250;
102
+ }
200
103
 
201
104
  } // namespace duckdb
@@ -0,0 +1,48 @@
1
+ //===----------------------------------------------------------------------===//
2
+ // DuckDB
3
+ //
4
+ // duckdb/common/numeric_utils.hpp
5
+ //
6
+ //
7
+ //===----------------------------------------------------------------------===//
8
+
9
+ #pragma once
10
+
11
+ #include <type_traits>
12
+ #include "duckdb/common/hugeint.hpp"
13
+
14
+ namespace duckdb {
15
+
16
+ template <class T>
17
+ struct MakeSigned {
18
+ using type = typename std::make_signed<T>::type;
19
+ };
20
+
21
+ template <>
22
+ struct MakeSigned<hugeint_t> {
23
+ using type = hugeint_t;
24
+ };
25
+
26
+ template <class T>
27
+ struct MakeUnsigned {
28
+ using type = typename std::make_unsigned<T>::type;
29
+ };
30
+
31
+ // hugeint_t does not actually have an unsigned variant (yet), but this is required to make compression work
32
+ // if an unsigned variant gets implemented this (probably) can be changed without breaking anything
33
+ template <>
34
+ struct MakeUnsigned<hugeint_t> {
35
+ using type = hugeint_t;
36
+ };
37
+
38
+ template <class T>
39
+ struct IsIntegral {
40
+ static constexpr bool value = std::is_integral<T>::value;
41
+ };
42
+
43
+ template <>
44
+ struct IsIntegral<hugeint_t> {
45
+ static constexpr bool value = true;
46
+ };
47
+
48
+ } // namespace duckdb
@@ -199,7 +199,7 @@ struct StringAggFun {
199
199
  static constexpr const char *Name = "string_agg";
200
200
  static constexpr const char *Parameters = "str,arg";
201
201
  static constexpr const char *Description = "Concatenates the column string values with an optional separator.";
202
- static constexpr const char *Example = "string_agg(A, '-)";
202
+ static constexpr const char *Example = "string_agg(A, '-')";
203
203
 
204
204
  static AggregateFunctionSet GetFunctions();
205
205
  };
@@ -28,7 +28,7 @@ struct BitwiseOrFun {
28
28
  static constexpr const char *Name = "|";
29
29
  static constexpr const char *Parameters = "left,right";
30
30
  static constexpr const char *Description = "Bitwise OR";
31
- static constexpr const char *Example = "32 & 3";
31
+ static constexpr const char *Example = "32 | 3";
32
32
 
33
33
  static ScalarFunctionSet GetFunctions();
34
34
  };
@@ -453,4 +453,13 @@ struct OrdFun {
453
453
  static constexpr const char *Name = "ord";
454
454
  };
455
455
 
456
+ struct ToBaseFun {
457
+ static constexpr const char *Name = "to_base";
458
+ static constexpr const char *Parameters = "number,radix,min_length";
459
+ static constexpr const char *Description = "Converts a value to a string in the given base radix, optionally padding with leading zeros to the minimum length";
460
+ static constexpr const char *Example = "to_base(42, 16)";
461
+
462
+ static ScalarFunctionSet GetFunctions();
463
+ };
464
+
456
465
  } // namespace duckdb
@@ -106,9 +106,9 @@ public:
106
106
  public:
107
107
  // Sink interface
108
108
  SinkResultType Sink(ExecutionContext &context, DataChunk &chunk, OperatorSinkInput &input) const override;
109
- void Combine(ExecutionContext &context, GlobalSinkState &state, LocalSinkState &lstate) const override;
109
+ SinkCombineResultType Combine(ExecutionContext &context, OperatorSinkCombineInput &input) const override;
110
110
  SinkFinalizeType Finalize(Pipeline &pipeline, Event &event, ClientContext &context,
111
- GlobalSinkState &gstate) const override;
111
+ OperatorSinkFinalizeInput &input) const override;
112
112
  SinkFinalizeType FinalizeInternal(Pipeline &pipeline, Event &event, ClientContext &context, GlobalSinkState &gstate,
113
113
  bool check_distinct) const;
114
114
 
@@ -141,7 +141,7 @@ private:
141
141
  SinkFinalizeType FinalizeDistinct(Pipeline &pipeline, Event &event, ClientContext &context,
142
142
  GlobalSinkState &gstate) const;
143
143
  //! Combine the distinct aggregates
144
- void CombineDistinct(ExecutionContext &context, GlobalSinkState &state, LocalSinkState &lstate) const;
144
+ void CombineDistinct(ExecutionContext &context, OperatorSinkCombineInput &input) const;
145
145
  //! Sink the distinct aggregates for a single grouping
146
146
  void SinkDistinctGrouping(ExecutionContext &context, DataChunk &chunk, OperatorSinkInput &input,
147
147
  idx_t grouping_idx) const;
@@ -46,7 +46,7 @@ public:
46
46
  public:
47
47
  // Sink interface
48
48
  SinkResultType Sink(ExecutionContext &context, DataChunk &chunk, OperatorSinkInput &input) const override;
49
- void Combine(ExecutionContext &context, GlobalSinkState &state, LocalSinkState &lstate) const override;
49
+ SinkCombineResultType Combine(ExecutionContext &context, OperatorSinkCombineInput &input) const override;
50
50
 
51
51
  unique_ptr<LocalSinkState> GetLocalSinkState(ExecutionContext &context) const override;
52
52
  unique_ptr<GlobalSinkState> GetGlobalSinkState(ClientContext &context) const override;