duckdb 0.3.1-dev254.0 → 0.3.1-dev287.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.
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "duckdb",
3
3
  "main": "./lib/duckdb.js",
4
- "version": "0.3.1-dev254.0",
4
+ "version": "0.3.1-dev287.0",
5
5
  "description": "DuckDB node.js API",
6
6
  "gypfile": true,
7
7
  "dependencies": {
package/src/duckdb.cpp CHANGED
@@ -74834,9 +74834,15 @@ hugeint_t operator*(const hugeint_t &h, const double &d) {
74834
74834
 
74835
74835
  using FrameBounds = std::pair<idx_t, idx_t>;
74836
74836
 
74837
+ template <typename SAVE_TYPE>
74837
74838
  struct QuantileState {
74838
- data_ptr_t v;
74839
- idx_t len;
74839
+ using SaveType = SAVE_TYPE;
74840
+
74841
+ // Regular aggregation
74842
+ std::vector<SaveType> v;
74843
+
74844
+ // Windowed Aggregation
74845
+ std::vector<idx_t> w;
74840
74846
  idx_t pos;
74841
74847
 
74842
74848
  // List temporaries
@@ -74844,26 +74850,17 @@ struct QuantileState {
74844
74850
  std::vector<idx_t> lower;
74845
74851
  std::vector<idx_t> upper;
74846
74852
 
74847
- QuantileState() : v(nullptr), len(0), pos(0) {
74853
+ QuantileState() : pos(0) {
74848
74854
  }
74849
74855
 
74850
74856
  ~QuantileState() {
74851
- if (v) {
74852
- free(v);
74853
- v = nullptr;
74854
- }
74855
74857
  }
74856
74858
 
74857
- template <typename T>
74858
- void Resize(idx_t new_len) {
74859
- if (new_len <= len) {
74860
- return;
74861
- }
74862
- v = (data_ptr_t)realloc(v, new_len * sizeof(T));
74863
- if (!v) {
74864
- throw InternalException("Memory allocation failure");
74859
+ inline void SetPos(size_t pos_p) {
74860
+ pos = pos_p;
74861
+ if (pos >= w.size()) {
74862
+ w.resize(pos);
74865
74863
  }
74866
- len = new_len;
74867
74864
  }
74868
74865
  };
74869
74866
 
@@ -74902,10 +74899,8 @@ void ReuseIndexes(idx_t *index, const FrameBounds &frame, const FrameBounds &pre
74902
74899
  }
74903
74900
  }
74904
74901
 
74905
- template <class STATE>
74906
- static idx_t ReplaceIndex(STATE *state, const FrameBounds &frame, const FrameBounds &prev) {
74907
- D_ASSERT(state->v);
74908
- auto index = (idx_t *)state->v;
74902
+ static idx_t ReplaceIndex(idx_t *index, const FrameBounds &frame, const FrameBounds &prev) {
74903
+ D_ASSERT(index);
74909
74904
 
74910
74905
  idx_t j = 0;
74911
74906
  for (idx_t p = 0; p < (prev.second - prev.first); ++p) {
@@ -74923,12 +74918,12 @@ static idx_t ReplaceIndex(STATE *state, const FrameBounds &frame, const FrameBou
74923
74918
  return j;
74924
74919
  }
74925
74920
 
74926
- template <class INPUT_TYPE, class STATE>
74927
- static inline bool CanReplace(STATE *state, const INPUT_TYPE *fdata, const idx_t j, const idx_t k0, const idx_t k1) {
74921
+ template <class INPUT_TYPE>
74922
+ static inline bool CanReplace(const idx_t *index, const INPUT_TYPE *fdata, const idx_t j, const idx_t k0,
74923
+ const idx_t k1) {
74928
74924
  auto same = false;
74929
74925
 
74930
- D_ASSERT(state->v);
74931
- auto index = (idx_t *)state->v;
74926
+ D_ASSERT(index);
74932
74927
 
74933
74928
  auto curr = fdata[index[j]];
74934
74929
  if (k1 < j) {
@@ -74965,31 +74960,49 @@ struct IndirectLess {
74965
74960
  const INPUT_TYPE *inputs;
74966
74961
  };
74967
74962
 
74963
+ struct CastInterpolation {
74964
+
74965
+ template <class INPUT_TYPE, class TARGET_TYPE>
74966
+ static TARGET_TYPE Cast(const INPUT_TYPE &src, Vector &result) {
74967
+ return Cast::Operation<INPUT_TYPE, TARGET_TYPE>(src);
74968
+ }
74969
+ };
74970
+
74971
+ template <>
74972
+ string_t CastInterpolation::Cast(const std::string &src, Vector &result) {
74973
+ return StringVector::AddString(result, src);
74974
+ }
74975
+
74976
+ template <>
74977
+ string_t CastInterpolation::Cast(const string_t &src, Vector &result) {
74978
+ return StringVector::AddString(result, src);
74979
+ }
74980
+
74968
74981
  template <class INPUT_TYPE, class TARGET_TYPE, bool DISCRETE>
74969
74982
  struct Interpolator {
74970
74983
  Interpolator(const double q, const idx_t n_p) : n(n_p), RN((double)(n_p - 1) * q), FRN(floor(RN)), CRN(ceil(RN)) {
74971
74984
  }
74972
74985
 
74973
- TARGET_TYPE operator()(INPUT_TYPE *v_t) const {
74986
+ TARGET_TYPE operator()(INPUT_TYPE *v_t, Vector &result) const {
74974
74987
  if (CRN == FRN) {
74975
74988
  std::nth_element(v_t, v_t + FRN, v_t + n);
74976
- return Cast::Operation<INPUT_TYPE, TARGET_TYPE>(v_t[FRN]);
74989
+ return CastInterpolation::Cast<INPUT_TYPE, TARGET_TYPE>(v_t[FRN], result);
74977
74990
  } else {
74978
74991
  std::nth_element(v_t, v_t + FRN, v_t + n);
74979
74992
  std::nth_element(v_t + FRN, v_t + CRN, v_t + n);
74980
- auto lo = Cast::Operation<INPUT_TYPE, TARGET_TYPE>(v_t[FRN]);
74981
- auto hi = Cast::Operation<INPUT_TYPE, TARGET_TYPE>(v_t[CRN]);
74993
+ auto lo = CastInterpolation::Cast<INPUT_TYPE, TARGET_TYPE>(v_t[FRN], result);
74994
+ auto hi = CastInterpolation::Cast<INPUT_TYPE, TARGET_TYPE>(v_t[CRN], result);
74982
74995
  auto delta = hi - lo;
74983
74996
  return lo + delta * (RN - FRN);
74984
74997
  }
74985
74998
  }
74986
74999
 
74987
- TARGET_TYPE operator()(const INPUT_TYPE *v_t, const idx_t *index) const {
75000
+ TARGET_TYPE operator()(const INPUT_TYPE *v_t, const idx_t *index, Vector &result) const {
74988
75001
  if (CRN == FRN) {
74989
- return Cast::Operation<INPUT_TYPE, TARGET_TYPE>(v_t[index[FRN]]);
75002
+ return CastInterpolation::Cast<INPUT_TYPE, TARGET_TYPE>(v_t[index[FRN]], result);
74990
75003
  } else {
74991
- auto lo = Cast::Operation<INPUT_TYPE, TARGET_TYPE>(v_t[index[FRN]]);
74992
- auto hi = Cast::Operation<INPUT_TYPE, TARGET_TYPE>(v_t[index[CRN]]);
75004
+ auto lo = CastInterpolation::Cast<INPUT_TYPE, TARGET_TYPE>(v_t[index[FRN]], result);
75005
+ auto hi = CastInterpolation::Cast<INPUT_TYPE, TARGET_TYPE>(v_t[index[CRN]], result);
74993
75006
  auto delta = hi - lo;
74994
75007
  return lo + delta * (RN - FRN);
74995
75008
  }
@@ -75006,13 +75019,13 @@ struct Interpolator<INPUT_TYPE, TARGET_TYPE, true> {
75006
75019
  Interpolator(const double q, const idx_t n_p) : n(n_p), RN((double)(n_p - 1) * q), FRN(floor(RN)), CRN(FRN) {
75007
75020
  }
75008
75021
 
75009
- TARGET_TYPE operator()(INPUT_TYPE *v_t) const {
75022
+ TARGET_TYPE operator()(INPUT_TYPE *v_t, Vector &result) const {
75010
75023
  std::nth_element(v_t, v_t + FRN, v_t + n);
75011
- return Cast::Operation<INPUT_TYPE, TARGET_TYPE>(v_t[FRN]);
75024
+ return CastInterpolation::Cast<INPUT_TYPE, TARGET_TYPE>(v_t[FRN], result);
75012
75025
  }
75013
75026
 
75014
- TARGET_TYPE operator()(const INPUT_TYPE *v_t, const idx_t *index) {
75015
- return Cast::Operation<INPUT_TYPE, TARGET_TYPE>(v_t[index[FRN]]);
75027
+ TARGET_TYPE operator()(const INPUT_TYPE *v_t, const idx_t *index, Vector &result) {
75028
+ return CastInterpolation::Cast<INPUT_TYPE, TARGET_TYPE>(v_t[index[FRN]], result);
75016
75029
  }
75017
75030
 
75018
75031
  const idx_t n;
@@ -75047,7 +75060,6 @@ struct QuantileBindData : public FunctionData {
75047
75060
  vector<idx_t> order;
75048
75061
  };
75049
75062
 
75050
- template <typename SAVE_TYPE>
75051
75063
  struct QuantileOperation {
75052
75064
  template <class STATE>
75053
75065
  static void Initialize(STATE *state) {
@@ -75064,22 +75076,15 @@ struct QuantileOperation {
75064
75076
 
75065
75077
  template <class INPUT_TYPE, class STATE, class OP>
75066
75078
  static void Operation(STATE *state, FunctionData *bind_data_p, INPUT_TYPE *data, ValidityMask &mask, idx_t idx) {
75067
- if (state->pos == state->len) {
75068
- // growing conservatively here since we could be running this on many small groups
75069
- state->template Resize<SAVE_TYPE>(state->len == 0 ? 1 : state->len * 2);
75070
- }
75071
- D_ASSERT(state->v);
75072
- ((SAVE_TYPE *)state->v)[state->pos++] = data[idx];
75079
+ state->v.emplace_back(data[idx]);
75073
75080
  }
75074
75081
 
75075
75082
  template <class STATE, class OP>
75076
75083
  static void Combine(const STATE &source, STATE *target) {
75077
- if (source.pos == 0) {
75084
+ if (source.v.empty()) {
75078
75085
  return;
75079
75086
  }
75080
- target->template Resize<SAVE_TYPE>(target->pos + source.pos);
75081
- memcpy(target->v + target->pos * sizeof(SAVE_TYPE), source.v, source.pos * sizeof(SAVE_TYPE));
75082
- target->pos += source.pos;
75087
+ target->v.insert(target->v.end(), source.v.begin(), source.v.end());
75083
75088
  }
75084
75089
 
75085
75090
  template <class STATE>
@@ -75134,23 +75139,21 @@ static AggregateFunction QuantileListAggregate(const LogicalType &input_type, co
75134
75139
  AggregateFunction::StateDestroy<STATE, OP>);
75135
75140
  }
75136
75141
 
75137
- template <class SAVE_TYPE, bool DISCRETE>
75138
- struct QuantileScalarOperation : public QuantileOperation<SAVE_TYPE> {
75142
+ template <bool DISCRETE>
75143
+ struct QuantileScalarOperation : public QuantileOperation {
75139
75144
 
75140
75145
  template <class RESULT_TYPE, class STATE>
75141
75146
  static void Finalize(Vector &result, FunctionData *bind_data_p, STATE *state, RESULT_TYPE *target,
75142
75147
  ValidityMask &mask, idx_t idx) {
75143
- if (state->pos == 0) {
75148
+ if (state->v.empty()) {
75144
75149
  mask.SetInvalid(idx);
75145
75150
  return;
75146
75151
  }
75147
- D_ASSERT(state->v);
75148
75152
  D_ASSERT(bind_data_p);
75149
75153
  auto bind_data = (QuantileBindData *)bind_data_p;
75150
75154
  D_ASSERT(bind_data->quantiles.size() == 1);
75151
- Interpolator<SAVE_TYPE, RESULT_TYPE, DISCRETE> interp(bind_data->quantiles[0], state->pos);
75152
- auto v_t = (SAVE_TYPE *)state->v;
75153
- target[idx] = interp(v_t);
75155
+ Interpolator<typename STATE::SaveType, RESULT_TYPE, DISCRETE> interp(bind_data->quantiles[0], state->v.size());
75156
+ target[idx] = interp(state->v.data(), result);
75154
75157
  }
75155
75158
 
75156
75159
  template <class STATE, class INPUT_TYPE, class RESULT_TYPE>
@@ -75161,11 +75164,10 @@ struct QuantileScalarOperation : public QuantileOperation<SAVE_TYPE> {
75161
75164
 
75162
75165
  // Lazily initialise frame state
75163
75166
  const auto prev_valid = state->pos == (prev.second - prev.first);
75164
- state->pos = frame.second - frame.first;
75165
- state->template Resize<idx_t>(state->pos);
75167
+ state->SetPos(frame.second - frame.first);
75166
75168
 
75167
- D_ASSERT(state->v);
75168
- auto index = (idx_t *)state->v;
75169
+ auto index = state->w.data();
75170
+ D_ASSERT(index);
75169
75171
 
75170
75172
  D_ASSERT(bind_data_p);
75171
75173
  auto bind_data = (QuantileBindData *)bind_data_p;
@@ -75176,15 +75178,16 @@ struct QuantileScalarOperation : public QuantileOperation<SAVE_TYPE> {
75176
75178
  bool same = false;
75177
75179
  if (prev_valid && dmask.AllValid() && frame.first == prev.first + 1 && frame.second == prev.second + 1) {
75178
75180
  // Fixed frame size
75179
- const auto j = ReplaceIndex(state, frame, prev);
75181
+ const auto j = ReplaceIndex(index, frame, prev);
75180
75182
  Interpolator<INPUT_TYPE, RESULT_TYPE, DISCRETE> interp(q, state->pos);
75181
- same = CanReplace(state, data, j, interp.FRN, interp.CRN);
75183
+ same = CanReplace(index, data, j, interp.FRN, interp.CRN);
75182
75184
  } else {
75183
75185
  ReuseIndexes(index, frame, prev);
75184
75186
  }
75185
75187
 
75186
75188
  if (!same) {
75187
75189
  if (!dmask.AllValid()) {
75190
+ // Remove the NULLs
75188
75191
  IndirectNotNull not_null(dmask, MinValue(frame.first, prev.first));
75189
75192
  state->pos = std::partition(index, index + state->pos, not_null) - index;
75190
75193
  }
@@ -75195,21 +75198,21 @@ struct QuantileScalarOperation : public QuantileOperation<SAVE_TYPE> {
75195
75198
  if (interp.CRN != interp.FRN) {
75196
75199
  std::nth_element(index + interp.CRN, index + interp.CRN, index + interp.n, lt);
75197
75200
  }
75198
- rdata[ridx] = interp(data, index);
75201
+ rdata[ridx] = interp(data, index, result);
75199
75202
  } else {
75200
75203
  rmask.Set(ridx, false);
75201
75204
  }
75202
75205
  } else {
75203
75206
  Interpolator<INPUT_TYPE, RESULT_TYPE, DISCRETE> interp(q, state->pos);
75204
- rdata[ridx] = interp(data, index);
75207
+ rdata[ridx] = interp(data, index, result);
75205
75208
  }
75206
75209
  }
75207
75210
  };
75208
75211
 
75209
- template <typename INPUT_TYPE>
75212
+ template <typename INPUT_TYPE, typename SAVED_TYPE>
75210
75213
  AggregateFunction GetTypedDiscreteQuantileAggregateFunction(const LogicalType &type) {
75211
- using STATE = QuantileState;
75212
- using OP = QuantileScalarOperation<INPUT_TYPE, true>;
75214
+ using STATE = QuantileState<SAVED_TYPE>;
75215
+ using OP = QuantileScalarOperation<true>;
75213
75216
  auto fun = AggregateFunction::UnaryAggregateDestructor<STATE, INPUT_TYPE, INPUT_TYPE, OP>(type, type);
75214
75217
  fun.window = AggregateFunction::UnaryWindow<STATE, INPUT_TYPE, INPUT_TYPE, OP>;
75215
75218
  return fun;
@@ -75218,56 +75221,59 @@ AggregateFunction GetTypedDiscreteQuantileAggregateFunction(const LogicalType &t
75218
75221
  AggregateFunction GetDiscreteQuantileAggregateFunction(const LogicalType &type) {
75219
75222
  switch (type.id()) {
75220
75223
  case LogicalTypeId::TINYINT:
75221
- return GetTypedDiscreteQuantileAggregateFunction<int8_t>(type);
75224
+ return GetTypedDiscreteQuantileAggregateFunction<int8_t, int8_t>(type);
75222
75225
  case LogicalTypeId::SMALLINT:
75223
- return GetTypedDiscreteQuantileAggregateFunction<int16_t>(type);
75226
+ return GetTypedDiscreteQuantileAggregateFunction<int16_t, int16_t>(type);
75224
75227
  case LogicalTypeId::INTEGER:
75225
- return GetTypedDiscreteQuantileAggregateFunction<int32_t>(type);
75228
+ return GetTypedDiscreteQuantileAggregateFunction<int32_t, int32_t>(type);
75226
75229
  case LogicalTypeId::BIGINT:
75227
- return GetTypedDiscreteQuantileAggregateFunction<int64_t>(type);
75230
+ return GetTypedDiscreteQuantileAggregateFunction<int64_t, int64_t>(type);
75228
75231
  case LogicalTypeId::HUGEINT:
75229
- return GetTypedDiscreteQuantileAggregateFunction<hugeint_t>(type);
75232
+ return GetTypedDiscreteQuantileAggregateFunction<hugeint_t, hugeint_t>(type);
75230
75233
 
75231
75234
  case LogicalTypeId::FLOAT:
75232
- return GetTypedDiscreteQuantileAggregateFunction<float>(type);
75235
+ return GetTypedDiscreteQuantileAggregateFunction<float, float>(type);
75233
75236
  case LogicalTypeId::DOUBLE:
75234
- return GetTypedDiscreteQuantileAggregateFunction<double>(type);
75237
+ return GetTypedDiscreteQuantileAggregateFunction<double, double>(type);
75235
75238
  case LogicalTypeId::DECIMAL:
75236
75239
  switch (type.InternalType()) {
75237
75240
  case PhysicalType::INT16:
75238
- return GetTypedDiscreteQuantileAggregateFunction<int16_t>(type);
75241
+ return GetTypedDiscreteQuantileAggregateFunction<int16_t, int16_t>(type);
75239
75242
  case PhysicalType::INT32:
75240
- return GetTypedDiscreteQuantileAggregateFunction<int32_t>(type);
75243
+ return GetTypedDiscreteQuantileAggregateFunction<int32_t, int32_t>(type);
75241
75244
  case PhysicalType::INT64:
75242
- return GetTypedDiscreteQuantileAggregateFunction<int64_t>(type);
75245
+ return GetTypedDiscreteQuantileAggregateFunction<int64_t, int64_t>(type);
75243
75246
  case PhysicalType::INT128:
75244
- return GetTypedDiscreteQuantileAggregateFunction<hugeint_t>(type);
75247
+ return GetTypedDiscreteQuantileAggregateFunction<hugeint_t, hugeint_t>(type);
75245
75248
  default:
75246
75249
  throw NotImplementedException("Unimplemented discrete quantile aggregate");
75247
75250
  }
75248
75251
  break;
75249
75252
 
75250
75253
  case LogicalTypeId::DATE:
75251
- return GetTypedDiscreteQuantileAggregateFunction<int32_t>(type);
75254
+ return GetTypedDiscreteQuantileAggregateFunction<int32_t, int32_t>(type);
75252
75255
  case LogicalTypeId::TIMESTAMP:
75253
- return GetTypedDiscreteQuantileAggregateFunction<int64_t>(type);
75256
+ return GetTypedDiscreteQuantileAggregateFunction<int64_t, int64_t>(type);
75254
75257
  case LogicalTypeId::TIME:
75255
- return GetTypedDiscreteQuantileAggregateFunction<int64_t>(type);
75258
+ return GetTypedDiscreteQuantileAggregateFunction<int64_t, int64_t>(type);
75256
75259
  case LogicalTypeId::INTERVAL:
75257
- return GetTypedDiscreteQuantileAggregateFunction<interval_t>(type);
75260
+ return GetTypedDiscreteQuantileAggregateFunction<interval_t, interval_t>(type);
75261
+
75262
+ case LogicalTypeId::VARCHAR:
75263
+ return GetTypedDiscreteQuantileAggregateFunction<string_t, std::string>(type);
75258
75264
 
75259
75265
  default:
75260
75266
  throw NotImplementedException("Unimplemented discrete quantile aggregate");
75261
75267
  }
75262
75268
  }
75263
75269
 
75264
- template <class SAVE_TYPE, class CHILD_TYPE, bool DISCRETE>
75265
- struct QuantileListOperation : public QuantileOperation<SAVE_TYPE> {
75270
+ template <class CHILD_TYPE, bool DISCRETE>
75271
+ struct QuantileListOperation : public QuantileOperation {
75266
75272
 
75267
75273
  template <class RESULT_TYPE, class STATE>
75268
75274
  static void Finalize(Vector &result_list, FunctionData *bind_data_p, STATE *state, RESULT_TYPE *target,
75269
75275
  ValidityMask &mask, idx_t idx) {
75270
- if (state->pos == 0) {
75276
+ if (state->v.empty()) {
75271
75277
  mask.SetInvalid(idx);
75272
75278
  return;
75273
75279
  }
@@ -75280,13 +75286,13 @@ struct QuantileListOperation : public QuantileOperation<SAVE_TYPE> {
75280
75286
  ListVector::Reserve(result_list, ridx + bind_data->quantiles.size());
75281
75287
  auto rdata = FlatVector::GetData<CHILD_TYPE>(result);
75282
75288
 
75283
- D_ASSERT(state->v);
75284
- auto v_t = (SAVE_TYPE *)state->v;
75289
+ auto v_t = state->v.data();
75290
+ D_ASSERT(v_t);
75285
75291
 
75286
75292
  target[idx].offset = ridx;
75287
75293
  for (const auto &quantile : bind_data->quantiles) {
75288
- Interpolator<SAVE_TYPE, CHILD_TYPE, DISCRETE> interp(quantile, state->pos);
75289
- rdata[ridx] = interp(v_t);
75294
+ Interpolator<typename STATE::SaveType, CHILD_TYPE, DISCRETE> interp(quantile, state->v.size());
75295
+ rdata[ridx] = interp(v_t, result);
75290
75296
  ++ridx;
75291
75297
  }
75292
75298
  target[idx].length = bind_data->quantiles.size();
@@ -75313,18 +75319,16 @@ struct QuantileListOperation : public QuantileOperation<SAVE_TYPE> {
75313
75319
  auto rdata = FlatVector::GetData<CHILD_TYPE>(result);
75314
75320
 
75315
75321
  // Lazily initialise frame state
75316
- const auto prev_valid = state->pos == (prev.second - prev.first);
75317
- state->pos = frame.second - frame.first;
75318
- state->template Resize<idx_t>(state->pos);
75322
+ const auto prev_valid = state->w.size() == (prev.second - prev.first);
75323
+ state->SetPos(frame.second - frame.first);
75319
75324
 
75320
- D_ASSERT(state->v);
75321
- auto index = (idx_t *)state->v;
75325
+ auto index = state->w.data();
75322
75326
 
75323
75327
  bool fixed = false;
75324
75328
  auto j = state->pos;
75325
75329
  if (prev_valid && dmask.AllValid() && frame.first == prev.first + 1 && frame.second == prev.second + 1) {
75326
75330
  // Fixed frame size
75327
- j = ReplaceIndex(state, frame, prev);
75331
+ j = ReplaceIndex(index, frame, prev);
75328
75332
  fixed = true;
75329
75333
  } else {
75330
75334
  ReuseIndexes(index, frame, prev);
@@ -75349,8 +75353,8 @@ struct QuantileListOperation : public QuantileOperation<SAVE_TYPE> {
75349
75353
  const auto &quantile = bind_data->quantiles[q];
75350
75354
  Interpolator<INPUT_TYPE, CHILD_TYPE, DISCRETE> interp(quantile, state->pos);
75351
75355
 
75352
- if (fixed && CanReplace(state, data, j, interp.FRN, interp.CRN)) {
75353
- rdata[lentry.offset + q] = interp(data, index);
75356
+ if (fixed && CanReplace(index, data, j, interp.FRN, interp.CRN)) {
75357
+ rdata[lentry.offset + q] = interp(data, index, result);
75354
75358
  state->upper.resize(state->lower.size(), interp.FRN);
75355
75359
  } else {
75356
75360
  state->disturbed.push_back(q);
@@ -75371,15 +75375,15 @@ struct QuantileListOperation : public QuantileOperation<SAVE_TYPE> {
75371
75375
  if (interp.CRN != interp.FRN) {
75372
75376
  std::nth_element(index + interp.CRN, index + interp.CRN, index + state->upper[i], lt);
75373
75377
  }
75374
- rdata[lentry.offset + q] = interp(data, index);
75378
+ rdata[lentry.offset + q] = interp(data, index, result);
75375
75379
  }
75376
75380
  }
75377
75381
  };
75378
75382
 
75379
- template <typename INPUT_TYPE>
75383
+ template <typename INPUT_TYPE, typename SAVE_TYPE>
75380
75384
  AggregateFunction GetTypedDiscreteQuantileListAggregateFunction(const LogicalType &type) {
75381
- using STATE = QuantileState;
75382
- using OP = QuantileListOperation<INPUT_TYPE, INPUT_TYPE, true>;
75385
+ using STATE = QuantileState<SAVE_TYPE>;
75386
+ using OP = QuantileListOperation<INPUT_TYPE, true>;
75383
75387
  auto fun = QuantileListAggregate<STATE, INPUT_TYPE, list_entry_t, OP>(type, type);
75384
75388
  fun.window = AggregateFunction::UnaryWindow<STATE, INPUT_TYPE, list_entry_t, OP>;
75385
75389
  return fun;
@@ -75388,43 +75392,46 @@ AggregateFunction GetTypedDiscreteQuantileListAggregateFunction(const LogicalTyp
75388
75392
  AggregateFunction GetDiscreteQuantileListAggregateFunction(const LogicalType &type) {
75389
75393
  switch (type.id()) {
75390
75394
  case LogicalTypeId::TINYINT:
75391
- return GetTypedDiscreteQuantileListAggregateFunction<int8_t>(type);
75395
+ return GetTypedDiscreteQuantileListAggregateFunction<int8_t, int8_t>(type);
75392
75396
  case LogicalTypeId::SMALLINT:
75393
- return GetTypedDiscreteQuantileListAggregateFunction<int16_t>(type);
75397
+ return GetTypedDiscreteQuantileListAggregateFunction<int16_t, int16_t>(type);
75394
75398
  case LogicalTypeId::INTEGER:
75395
- return GetTypedDiscreteQuantileListAggregateFunction<int32_t>(type);
75399
+ return GetTypedDiscreteQuantileListAggregateFunction<int32_t, int32_t>(type);
75396
75400
  case LogicalTypeId::BIGINT:
75397
- return GetTypedDiscreteQuantileListAggregateFunction<int64_t>(type);
75401
+ return GetTypedDiscreteQuantileListAggregateFunction<int64_t, int64_t>(type);
75398
75402
  case LogicalTypeId::HUGEINT:
75399
- return GetTypedDiscreteQuantileListAggregateFunction<hugeint_t>(type);
75403
+ return GetTypedDiscreteQuantileListAggregateFunction<hugeint_t, hugeint_t>(type);
75400
75404
 
75401
75405
  case LogicalTypeId::FLOAT:
75402
- return GetTypedDiscreteQuantileListAggregateFunction<float>(type);
75406
+ return GetTypedDiscreteQuantileListAggregateFunction<float, float>(type);
75403
75407
  case LogicalTypeId::DOUBLE:
75404
- return GetTypedDiscreteQuantileListAggregateFunction<double>(type);
75408
+ return GetTypedDiscreteQuantileListAggregateFunction<double, double>(type);
75405
75409
  case LogicalTypeId::DECIMAL:
75406
75410
  switch (type.InternalType()) {
75407
75411
  case PhysicalType::INT16:
75408
- return GetTypedDiscreteQuantileListAggregateFunction<int16_t>(type);
75412
+ return GetTypedDiscreteQuantileListAggregateFunction<int16_t, int16_t>(type);
75409
75413
  case PhysicalType::INT32:
75410
- return GetTypedDiscreteQuantileListAggregateFunction<int32_t>(type);
75414
+ return GetTypedDiscreteQuantileListAggregateFunction<int32_t, int32_t>(type);
75411
75415
  case PhysicalType::INT64:
75412
- return GetTypedDiscreteQuantileListAggregateFunction<int64_t>(type);
75416
+ return GetTypedDiscreteQuantileListAggregateFunction<int64_t, int64_t>(type);
75413
75417
  case PhysicalType::INT128:
75414
- return GetTypedDiscreteQuantileListAggregateFunction<hugeint_t>(type);
75418
+ return GetTypedDiscreteQuantileListAggregateFunction<hugeint_t, hugeint_t>(type);
75415
75419
  default:
75416
75420
  throw NotImplementedException("Unimplemented discrete quantile list aggregate");
75417
75421
  }
75418
75422
  break;
75419
75423
 
75420
75424
  case LogicalTypeId::DATE:
75421
- return GetTypedDiscreteQuantileListAggregateFunction<date_t>(type);
75425
+ return GetTypedDiscreteQuantileListAggregateFunction<date_t, date_t>(type);
75422
75426
  case LogicalTypeId::TIMESTAMP:
75423
- return GetTypedDiscreteQuantileListAggregateFunction<timestamp_t>(type);
75427
+ return GetTypedDiscreteQuantileListAggregateFunction<timestamp_t, timestamp_t>(type);
75424
75428
  case LogicalTypeId::TIME:
75425
- return GetTypedDiscreteQuantileListAggregateFunction<dtime_t>(type);
75429
+ return GetTypedDiscreteQuantileListAggregateFunction<dtime_t, dtime_t>(type);
75426
75430
  case LogicalTypeId::INTERVAL:
75427
- return GetTypedDiscreteQuantileListAggregateFunction<interval_t>(type);
75431
+ return GetTypedDiscreteQuantileListAggregateFunction<interval_t, interval_t>(type);
75432
+
75433
+ case LogicalTypeId::VARCHAR:
75434
+ return GetTypedDiscreteQuantileListAggregateFunction<string_t, std::string>(type);
75428
75435
 
75429
75436
  default:
75430
75437
  throw NotImplementedException("Unimplemented discrete quantile list aggregate");
@@ -75434,8 +75441,8 @@ AggregateFunction GetDiscreteQuantileListAggregateFunction(const LogicalType &ty
75434
75441
  template <typename INPUT_TYPE, typename TARGET_TYPE>
75435
75442
  AggregateFunction GetTypedContinuousQuantileAggregateFunction(const LogicalType &input_type,
75436
75443
  const LogicalType &target_type) {
75437
- using STATE = QuantileState;
75438
- using OP = QuantileScalarOperation<INPUT_TYPE, false>;
75444
+ using STATE = QuantileState<INPUT_TYPE>;
75445
+ using OP = QuantileScalarOperation<false>;
75439
75446
  auto fun = AggregateFunction::UnaryAggregateDestructor<STATE, INPUT_TYPE, TARGET_TYPE, OP>(input_type, target_type);
75440
75447
  fun.window = AggregateFunction::UnaryWindow<STATE, INPUT_TYPE, TARGET_TYPE, OP>;
75441
75448
  return fun;
@@ -75488,8 +75495,8 @@ AggregateFunction GetContinuousQuantileAggregateFunction(const LogicalType &type
75488
75495
  template <typename INPUT_TYPE, typename CHILD_TYPE>
75489
75496
  AggregateFunction GetTypedContinuousQuantileListAggregateFunction(const LogicalType &input_type,
75490
75497
  const LogicalType &result_type) {
75491
- using STATE = QuantileState;
75492
- using OP = QuantileListOperation<INPUT_TYPE, CHILD_TYPE, false>;
75498
+ using STATE = QuantileState<INPUT_TYPE>;
75499
+ using OP = QuantileListOperation<CHILD_TYPE, false>;
75493
75500
  auto fun = QuantileListAggregate<STATE, INPUT_TYPE, list_entry_t, OP>(input_type, result_type);
75494
75501
  fun.window = AggregateFunction::UnaryWindow<STATE, INPUT_TYPE, list_entry_t, OP>;
75495
75502
  return fun;
@@ -75614,9 +75621,19 @@ unique_ptr<FunctionData> BindContinuousQuantileDecimalList(ClientContext &contex
75614
75621
  return bind_data;
75615
75622
  }
75616
75623
 
75624
+ static bool CanInterpolate(const LogicalType &type) {
75625
+ switch (type.id()) {
75626
+ case LogicalTypeId::INTERVAL:
75627
+ case LogicalTypeId::VARCHAR:
75628
+ return false;
75629
+ default:
75630
+ return true;
75631
+ }
75632
+ }
75633
+
75617
75634
  AggregateFunction GetMedianAggregate(const LogicalType &type) {
75618
- auto fun = (type.id() != LogicalTypeId::INTERVAL) ? GetContinuousQuantileAggregateFunction(type)
75619
- : GetDiscreteQuantileAggregateFunction(type);
75635
+ auto fun = CanInterpolate(type) ? GetContinuousQuantileAggregateFunction(type)
75636
+ : GetDiscreteQuantileAggregateFunction(type);
75620
75637
  fun.bind = BindMedian;
75621
75638
  return fun;
75622
75639
  }
@@ -75659,7 +75676,7 @@ void QuantileFun::RegisterFunction(BuiltinFunctions &set) {
75659
75676
  const vector<LogicalType> QUANTILES = {LogicalType::TINYINT, LogicalType::SMALLINT, LogicalType::INTEGER,
75660
75677
  LogicalType::BIGINT, LogicalType::HUGEINT, LogicalType::FLOAT,
75661
75678
  LogicalType::DOUBLE, LogicalType::DATE, LogicalType::TIMESTAMP,
75662
- LogicalType::TIME, LogicalType::INTERVAL};
75679
+ LogicalType::TIME, LogicalType::INTERVAL, LogicalType::VARCHAR};
75663
75680
 
75664
75681
  AggregateFunctionSet median("median");
75665
75682
  median.AddFunction(AggregateFunction({LogicalTypeId::DECIMAL}, LogicalTypeId::DECIMAL, nullptr, nullptr, nullptr,
@@ -75685,7 +75702,7 @@ void QuantileFun::RegisterFunction(BuiltinFunctions &set) {
75685
75702
  median.AddFunction(GetMedianAggregate(type));
75686
75703
  quantile_disc.AddFunction(GetDiscreteQuantileAggregate(type));
75687
75704
  quantile_disc.AddFunction(GetDiscreteQuantileListAggregate(type));
75688
- if (type.id() != LogicalTypeId::INTERVAL) {
75705
+ if (CanInterpolate(type)) {
75689
75706
  quantile_cont.AddFunction(GetContinuousQuantileAggregate(type));
75690
75707
  quantile_cont.AddFunction(GetContinuousQuantileListAggregate(type));
75691
75708
  }
package/src/duckdb.hpp CHANGED
@@ -10,8 +10,8 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
10
10
 
11
11
  #pragma once
12
12
  #define DUCKDB_AMALGAMATION 1
13
- #define DUCKDB_SOURCE_ID "70aa62a69"
14
- #define DUCKDB_VERSION "0.3.1-dev254"
13
+ #define DUCKDB_SOURCE_ID "c96cc961e"
14
+ #define DUCKDB_VERSION "0.3.1-dev287"
15
15
  //===----------------------------------------------------------------------===//
16
16
  // DuckDB
17
17
  //