duckdb 0.3.1-dev247.0 → 0.3.1-dev283.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-dev247.0",
4
+ "version": "0.3.1-dev283.0",
5
5
  "description": "DuckDB node.js API",
6
6
  "gypfile": true,
7
7
  "dependencies": {
package/src/duckdb.cpp CHANGED
@@ -71414,10 +71414,10 @@ template <class OP, class T>
71414
71414
  AggregateFunction GetArgMinMaxFunctionArg2(LogicalTypeId arg_2, const LogicalType &arg) {
71415
71415
  switch (arg_2) {
71416
71416
  case LogicalTypeId::INTEGER:
71417
- return AggregateFunction::BinaryAggregate<ArgMinMaxState<T, int>, T, int, T, OP>(arg, LogicalType::INTEGER,
71418
- arg);
71417
+ return AggregateFunction::BinaryAggregate<ArgMinMaxState<T, int32_t>, T, int32_t, T, OP>(
71418
+ arg, LogicalType::INTEGER, arg);
71419
71419
  case LogicalTypeId::BIGINT:
71420
- return AggregateFunction::BinaryAggregate<ArgMinMaxState<T, uint64_t>, T, uint64_t, T, OP>(
71420
+ return AggregateFunction::BinaryAggregate<ArgMinMaxState<T, int64_t>, T, int64_t, T, OP>(
71421
71421
  arg, LogicalType::BIGINT, arg);
71422
71422
  case LogicalTypeId::DOUBLE:
71423
71423
  return AggregateFunction::BinaryAggregate<ArgMinMaxState<T, double>, T, double, T, OP>(arg, LogicalType::DOUBLE,
@@ -71426,10 +71426,10 @@ AggregateFunction GetArgMinMaxFunctionArg2(LogicalTypeId arg_2, const LogicalTyp
71426
71426
  return AggregateFunction::BinaryAggregate<ArgMinMaxState<T, string_t>, T, string_t, T, OP>(
71427
71427
  arg, LogicalType::VARCHAR, arg);
71428
71428
  case LogicalTypeId::DATE:
71429
- return AggregateFunction::BinaryAggregate<ArgMinMaxState<T, uint64_t>, T, uint64_t, T, OP>(
71430
- arg, LogicalType::DATE, arg);
71429
+ return AggregateFunction::BinaryAggregate<ArgMinMaxState<T, date_t>, T, date_t, T, OP>(arg, LogicalType::DATE,
71430
+ arg);
71431
71431
  case LogicalTypeId::TIMESTAMP:
71432
- return AggregateFunction::BinaryAggregate<ArgMinMaxState<T, uint64_t>, T, uint64_t, T, OP>(
71432
+ return AggregateFunction::BinaryAggregate<ArgMinMaxState<T, timestamp_t>, T, timestamp_t, T, OP>(
71433
71433
  arg, LogicalType::TIMESTAMP, arg);
71434
71434
  case LogicalTypeId::BLOB:
71435
71435
  return AggregateFunction::BinaryAggregate<ArgMinMaxState<T, string_t>, T, string_t, T, OP>(
@@ -71443,13 +71443,13 @@ template <class OP>
71443
71443
  void GetArgMinMaxFunction(LogicalTypeId arg_1, AggregateFunctionSet &fun) {
71444
71444
  switch (arg_1) {
71445
71445
  case LogicalTypeId::INTEGER:
71446
- fun.AddFunction(GetArgMinMaxFunctionArg2<OP, int>(LogicalTypeId::INTEGER, LogicalType::INTEGER));
71447
- fun.AddFunction(GetArgMinMaxFunctionArg2<OP, int>(LogicalTypeId::BIGINT, LogicalType::INTEGER));
71448
- fun.AddFunction(GetArgMinMaxFunctionArg2<OP, int>(LogicalTypeId::DOUBLE, LogicalType::INTEGER));
71449
- fun.AddFunction(GetArgMinMaxFunctionArg2<OP, int>(LogicalTypeId::VARCHAR, LogicalType::INTEGER));
71450
- fun.AddFunction(GetArgMinMaxFunctionArg2<OP, int>(LogicalTypeId::DATE, LogicalType::INTEGER));
71451
- fun.AddFunction(GetArgMinMaxFunctionArg2<OP, int>(LogicalTypeId::TIMESTAMP, LogicalType::INTEGER));
71452
- fun.AddFunction(GetArgMinMaxFunctionArg2<OP, int>(LogicalTypeId::BLOB, LogicalType::INTEGER));
71446
+ fun.AddFunction(GetArgMinMaxFunctionArg2<OP, int32_t>(LogicalTypeId::INTEGER, LogicalType::INTEGER));
71447
+ fun.AddFunction(GetArgMinMaxFunctionArg2<OP, int32_t>(LogicalTypeId::BIGINT, LogicalType::INTEGER));
71448
+ fun.AddFunction(GetArgMinMaxFunctionArg2<OP, int32_t>(LogicalTypeId::DOUBLE, LogicalType::INTEGER));
71449
+ fun.AddFunction(GetArgMinMaxFunctionArg2<OP, int32_t>(LogicalTypeId::VARCHAR, LogicalType::INTEGER));
71450
+ fun.AddFunction(GetArgMinMaxFunctionArg2<OP, int32_t>(LogicalTypeId::DATE, LogicalType::INTEGER));
71451
+ fun.AddFunction(GetArgMinMaxFunctionArg2<OP, int32_t>(LogicalTypeId::TIMESTAMP, LogicalType::INTEGER));
71452
+ fun.AddFunction(GetArgMinMaxFunctionArg2<OP, int32_t>(LogicalTypeId::BLOB, LogicalType::INTEGER));
71453
71453
  break;
71454
71454
  case LogicalTypeId::BIGINT:
71455
71455
  fun.AddFunction(GetArgMinMaxFunctionArg2<OP, int64_t>(LogicalTypeId::INTEGER, LogicalType::BIGINT));
@@ -71479,22 +71479,22 @@ void GetArgMinMaxFunction(LogicalTypeId arg_1, AggregateFunctionSet &fun) {
71479
71479
  fun.AddFunction(GetArgMinMaxFunctionArg2<OP, string_t>(LogicalTypeId::BLOB, LogicalType::VARCHAR));
71480
71480
  break;
71481
71481
  case LogicalTypeId::DATE:
71482
- fun.AddFunction(GetArgMinMaxFunctionArg2<OP, int64_t>(LogicalTypeId::INTEGER, LogicalType::DATE));
71483
- fun.AddFunction(GetArgMinMaxFunctionArg2<OP, int64_t>(LogicalTypeId::BIGINT, LogicalType::DATE));
71484
- fun.AddFunction(GetArgMinMaxFunctionArg2<OP, int64_t>(LogicalTypeId::DOUBLE, LogicalType::DATE));
71485
- fun.AddFunction(GetArgMinMaxFunctionArg2<OP, int64_t>(LogicalTypeId::VARCHAR, LogicalType::DATE));
71486
- fun.AddFunction(GetArgMinMaxFunctionArg2<OP, int64_t>(LogicalTypeId::DATE, LogicalType::DATE));
71487
- fun.AddFunction(GetArgMinMaxFunctionArg2<OP, int64_t>(LogicalTypeId::TIMESTAMP, LogicalType::DATE));
71488
- fun.AddFunction(GetArgMinMaxFunctionArg2<OP, int64_t>(LogicalTypeId::BLOB, LogicalType::DATE));
71482
+ fun.AddFunction(GetArgMinMaxFunctionArg2<OP, date_t>(LogicalTypeId::INTEGER, LogicalType::DATE));
71483
+ fun.AddFunction(GetArgMinMaxFunctionArg2<OP, date_t>(LogicalTypeId::BIGINT, LogicalType::DATE));
71484
+ fun.AddFunction(GetArgMinMaxFunctionArg2<OP, date_t>(LogicalTypeId::DOUBLE, LogicalType::DATE));
71485
+ fun.AddFunction(GetArgMinMaxFunctionArg2<OP, date_t>(LogicalTypeId::VARCHAR, LogicalType::DATE));
71486
+ fun.AddFunction(GetArgMinMaxFunctionArg2<OP, date_t>(LogicalTypeId::DATE, LogicalType::DATE));
71487
+ fun.AddFunction(GetArgMinMaxFunctionArg2<OP, date_t>(LogicalTypeId::TIMESTAMP, LogicalType::DATE));
71488
+ fun.AddFunction(GetArgMinMaxFunctionArg2<OP, date_t>(LogicalTypeId::BLOB, LogicalType::DATE));
71489
71489
  break;
71490
71490
  case LogicalTypeId::TIMESTAMP:
71491
- fun.AddFunction(GetArgMinMaxFunctionArg2<OP, int64_t>(LogicalTypeId::INTEGER, LogicalType::TIMESTAMP));
71492
- fun.AddFunction(GetArgMinMaxFunctionArg2<OP, int64_t>(LogicalTypeId::BIGINT, LogicalType::TIMESTAMP));
71493
- fun.AddFunction(GetArgMinMaxFunctionArg2<OP, int64_t>(LogicalTypeId::DOUBLE, LogicalType::TIMESTAMP));
71494
- fun.AddFunction(GetArgMinMaxFunctionArg2<OP, int64_t>(LogicalTypeId::VARCHAR, LogicalType::TIMESTAMP));
71495
- fun.AddFunction(GetArgMinMaxFunctionArg2<OP, int64_t>(LogicalTypeId::DATE, LogicalType::TIMESTAMP));
71496
- fun.AddFunction(GetArgMinMaxFunctionArg2<OP, int64_t>(LogicalTypeId::TIMESTAMP, LogicalType::TIMESTAMP));
71497
- fun.AddFunction(GetArgMinMaxFunctionArg2<OP, int64_t>(LogicalTypeId::BLOB, LogicalType::TIMESTAMP));
71491
+ fun.AddFunction(GetArgMinMaxFunctionArg2<OP, timestamp_t>(LogicalTypeId::INTEGER, LogicalType::TIMESTAMP));
71492
+ fun.AddFunction(GetArgMinMaxFunctionArg2<OP, timestamp_t>(LogicalTypeId::BIGINT, LogicalType::TIMESTAMP));
71493
+ fun.AddFunction(GetArgMinMaxFunctionArg2<OP, timestamp_t>(LogicalTypeId::DOUBLE, LogicalType::TIMESTAMP));
71494
+ fun.AddFunction(GetArgMinMaxFunctionArg2<OP, timestamp_t>(LogicalTypeId::VARCHAR, LogicalType::TIMESTAMP));
71495
+ fun.AddFunction(GetArgMinMaxFunctionArg2<OP, timestamp_t>(LogicalTypeId::DATE, LogicalType::TIMESTAMP));
71496
+ fun.AddFunction(GetArgMinMaxFunctionArg2<OP, timestamp_t>(LogicalTypeId::TIMESTAMP, LogicalType::TIMESTAMP));
71497
+ fun.AddFunction(GetArgMinMaxFunctionArg2<OP, timestamp_t>(LogicalTypeId::BLOB, LogicalType::TIMESTAMP));
71498
71498
  break;
71499
71499
  case LogicalTypeId::BLOB:
71500
71500
  fun.AddFunction(GetArgMinMaxFunctionArg2<OP, string_t>(LogicalTypeId::INTEGER, LogicalType::BLOB));
@@ -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,44 @@ 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
+
74968
74976
  template <class INPUT_TYPE, class TARGET_TYPE, bool DISCRETE>
74969
74977
  struct Interpolator {
74970
74978
  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
74979
  }
74972
74980
 
74973
- TARGET_TYPE operator()(INPUT_TYPE *v_t) const {
74981
+ TARGET_TYPE operator()(INPUT_TYPE *v_t, Vector &result) const {
74974
74982
  if (CRN == FRN) {
74975
74983
  std::nth_element(v_t, v_t + FRN, v_t + n);
74976
- return Cast::Operation<INPUT_TYPE, TARGET_TYPE>(v_t[FRN]);
74984
+ return CastInterpolation::Cast<INPUT_TYPE, TARGET_TYPE>(v_t[FRN], result);
74977
74985
  } else {
74978
74986
  std::nth_element(v_t, v_t + FRN, v_t + n);
74979
74987
  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]);
74988
+ auto lo = CastInterpolation::Cast<INPUT_TYPE, TARGET_TYPE>(v_t[FRN], result);
74989
+ auto hi = CastInterpolation::Cast<INPUT_TYPE, TARGET_TYPE>(v_t[CRN], result);
74982
74990
  auto delta = hi - lo;
74983
74991
  return lo + delta * (RN - FRN);
74984
74992
  }
74985
74993
  }
74986
74994
 
74987
- TARGET_TYPE operator()(const INPUT_TYPE *v_t, const idx_t *index) const {
74995
+ TARGET_TYPE operator()(const INPUT_TYPE *v_t, const idx_t *index, Vector &result) const {
74988
74996
  if (CRN == FRN) {
74989
- return Cast::Operation<INPUT_TYPE, TARGET_TYPE>(v_t[index[FRN]]);
74997
+ return CastInterpolation::Cast<INPUT_TYPE, TARGET_TYPE>(v_t[index[FRN]], result);
74990
74998
  } 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]]);
74999
+ auto lo = CastInterpolation::Cast<INPUT_TYPE, TARGET_TYPE>(v_t[index[FRN]], result);
75000
+ auto hi = CastInterpolation::Cast<INPUT_TYPE, TARGET_TYPE>(v_t[index[CRN]], result);
74993
75001
  auto delta = hi - lo;
74994
75002
  return lo + delta * (RN - FRN);
74995
75003
  }
@@ -75006,13 +75014,13 @@ struct Interpolator<INPUT_TYPE, TARGET_TYPE, true> {
75006
75014
  Interpolator(const double q, const idx_t n_p) : n(n_p), RN((double)(n_p - 1) * q), FRN(floor(RN)), CRN(FRN) {
75007
75015
  }
75008
75016
 
75009
- TARGET_TYPE operator()(INPUT_TYPE *v_t) const {
75017
+ TARGET_TYPE operator()(INPUT_TYPE *v_t, Vector &result) const {
75010
75018
  std::nth_element(v_t, v_t + FRN, v_t + n);
75011
- return Cast::Operation<INPUT_TYPE, TARGET_TYPE>(v_t[FRN]);
75019
+ return CastInterpolation::Cast<INPUT_TYPE, TARGET_TYPE>(v_t[FRN], result);
75012
75020
  }
75013
75021
 
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]]);
75022
+ TARGET_TYPE operator()(const INPUT_TYPE *v_t, const idx_t *index, Vector &result) {
75023
+ return CastInterpolation::Cast<INPUT_TYPE, TARGET_TYPE>(v_t[index[FRN]], result);
75016
75024
  }
75017
75025
 
75018
75026
  const idx_t n;
@@ -75047,7 +75055,6 @@ struct QuantileBindData : public FunctionData {
75047
75055
  vector<idx_t> order;
75048
75056
  };
75049
75057
 
75050
- template <typename SAVE_TYPE>
75051
75058
  struct QuantileOperation {
75052
75059
  template <class STATE>
75053
75060
  static void Initialize(STATE *state) {
@@ -75064,22 +75071,15 @@ struct QuantileOperation {
75064
75071
 
75065
75072
  template <class INPUT_TYPE, class STATE, class OP>
75066
75073
  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];
75074
+ state->v.emplace_back(data[idx]);
75073
75075
  }
75074
75076
 
75075
75077
  template <class STATE, class OP>
75076
75078
  static void Combine(const STATE &source, STATE *target) {
75077
- if (source.pos == 0) {
75079
+ if (source.v.empty()) {
75078
75080
  return;
75079
75081
  }
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;
75082
+ target->v.insert(target->v.end(), source.v.begin(), source.v.end());
75083
75083
  }
75084
75084
 
75085
75085
  template <class STATE>
@@ -75134,23 +75134,21 @@ static AggregateFunction QuantileListAggregate(const LogicalType &input_type, co
75134
75134
  AggregateFunction::StateDestroy<STATE, OP>);
75135
75135
  }
75136
75136
 
75137
- template <class SAVE_TYPE, bool DISCRETE>
75138
- struct QuantileScalarOperation : public QuantileOperation<SAVE_TYPE> {
75137
+ template <bool DISCRETE>
75138
+ struct QuantileScalarOperation : public QuantileOperation {
75139
75139
 
75140
75140
  template <class RESULT_TYPE, class STATE>
75141
75141
  static void Finalize(Vector &result, FunctionData *bind_data_p, STATE *state, RESULT_TYPE *target,
75142
75142
  ValidityMask &mask, idx_t idx) {
75143
- if (state->pos == 0) {
75143
+ if (state->v.empty()) {
75144
75144
  mask.SetInvalid(idx);
75145
75145
  return;
75146
75146
  }
75147
- D_ASSERT(state->v);
75148
75147
  D_ASSERT(bind_data_p);
75149
75148
  auto bind_data = (QuantileBindData *)bind_data_p;
75150
75149
  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);
75150
+ Interpolator<typename STATE::SaveType, RESULT_TYPE, DISCRETE> interp(bind_data->quantiles[0], state->v.size());
75151
+ target[idx] = interp(state->v.data(), result);
75154
75152
  }
75155
75153
 
75156
75154
  template <class STATE, class INPUT_TYPE, class RESULT_TYPE>
@@ -75161,11 +75159,10 @@ struct QuantileScalarOperation : public QuantileOperation<SAVE_TYPE> {
75161
75159
 
75162
75160
  // Lazily initialise frame state
75163
75161
  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);
75162
+ state->SetPos(frame.second - frame.first);
75166
75163
 
75167
- D_ASSERT(state->v);
75168
- auto index = (idx_t *)state->v;
75164
+ auto index = state->w.data();
75165
+ D_ASSERT(index);
75169
75166
 
75170
75167
  D_ASSERT(bind_data_p);
75171
75168
  auto bind_data = (QuantileBindData *)bind_data_p;
@@ -75176,15 +75173,16 @@ struct QuantileScalarOperation : public QuantileOperation<SAVE_TYPE> {
75176
75173
  bool same = false;
75177
75174
  if (prev_valid && dmask.AllValid() && frame.first == prev.first + 1 && frame.second == prev.second + 1) {
75178
75175
  // Fixed frame size
75179
- const auto j = ReplaceIndex(state, frame, prev);
75176
+ const auto j = ReplaceIndex(index, frame, prev);
75180
75177
  Interpolator<INPUT_TYPE, RESULT_TYPE, DISCRETE> interp(q, state->pos);
75181
- same = CanReplace(state, data, j, interp.FRN, interp.CRN);
75178
+ same = CanReplace(index, data, j, interp.FRN, interp.CRN);
75182
75179
  } else {
75183
75180
  ReuseIndexes(index, frame, prev);
75184
75181
  }
75185
75182
 
75186
75183
  if (!same) {
75187
75184
  if (!dmask.AllValid()) {
75185
+ // Remove the NULLs
75188
75186
  IndirectNotNull not_null(dmask, MinValue(frame.first, prev.first));
75189
75187
  state->pos = std::partition(index, index + state->pos, not_null) - index;
75190
75188
  }
@@ -75195,21 +75193,21 @@ struct QuantileScalarOperation : public QuantileOperation<SAVE_TYPE> {
75195
75193
  if (interp.CRN != interp.FRN) {
75196
75194
  std::nth_element(index + interp.CRN, index + interp.CRN, index + interp.n, lt);
75197
75195
  }
75198
- rdata[ridx] = interp(data, index);
75196
+ rdata[ridx] = interp(data, index, result);
75199
75197
  } else {
75200
75198
  rmask.Set(ridx, false);
75201
75199
  }
75202
75200
  } else {
75203
75201
  Interpolator<INPUT_TYPE, RESULT_TYPE, DISCRETE> interp(q, state->pos);
75204
- rdata[ridx] = interp(data, index);
75202
+ rdata[ridx] = interp(data, index, result);
75205
75203
  }
75206
75204
  }
75207
75205
  };
75208
75206
 
75209
- template <typename INPUT_TYPE>
75207
+ template <typename INPUT_TYPE, typename SAVED_TYPE>
75210
75208
  AggregateFunction GetTypedDiscreteQuantileAggregateFunction(const LogicalType &type) {
75211
- using STATE = QuantileState;
75212
- using OP = QuantileScalarOperation<INPUT_TYPE, true>;
75209
+ using STATE = QuantileState<SAVED_TYPE>;
75210
+ using OP = QuantileScalarOperation<true>;
75213
75211
  auto fun = AggregateFunction::UnaryAggregateDestructor<STATE, INPUT_TYPE, INPUT_TYPE, OP>(type, type);
75214
75212
  fun.window = AggregateFunction::UnaryWindow<STATE, INPUT_TYPE, INPUT_TYPE, OP>;
75215
75213
  return fun;
@@ -75218,56 +75216,59 @@ AggregateFunction GetTypedDiscreteQuantileAggregateFunction(const LogicalType &t
75218
75216
  AggregateFunction GetDiscreteQuantileAggregateFunction(const LogicalType &type) {
75219
75217
  switch (type.id()) {
75220
75218
  case LogicalTypeId::TINYINT:
75221
- return GetTypedDiscreteQuantileAggregateFunction<int8_t>(type);
75219
+ return GetTypedDiscreteQuantileAggregateFunction<int8_t, int8_t>(type);
75222
75220
  case LogicalTypeId::SMALLINT:
75223
- return GetTypedDiscreteQuantileAggregateFunction<int16_t>(type);
75221
+ return GetTypedDiscreteQuantileAggregateFunction<int16_t, int16_t>(type);
75224
75222
  case LogicalTypeId::INTEGER:
75225
- return GetTypedDiscreteQuantileAggregateFunction<int32_t>(type);
75223
+ return GetTypedDiscreteQuantileAggregateFunction<int32_t, int32_t>(type);
75226
75224
  case LogicalTypeId::BIGINT:
75227
- return GetTypedDiscreteQuantileAggregateFunction<int64_t>(type);
75225
+ return GetTypedDiscreteQuantileAggregateFunction<int64_t, int64_t>(type);
75228
75226
  case LogicalTypeId::HUGEINT:
75229
- return GetTypedDiscreteQuantileAggregateFunction<hugeint_t>(type);
75227
+ return GetTypedDiscreteQuantileAggregateFunction<hugeint_t, hugeint_t>(type);
75230
75228
 
75231
75229
  case LogicalTypeId::FLOAT:
75232
- return GetTypedDiscreteQuantileAggregateFunction<float>(type);
75230
+ return GetTypedDiscreteQuantileAggregateFunction<float, float>(type);
75233
75231
  case LogicalTypeId::DOUBLE:
75234
- return GetTypedDiscreteQuantileAggregateFunction<double>(type);
75232
+ return GetTypedDiscreteQuantileAggregateFunction<double, double>(type);
75235
75233
  case LogicalTypeId::DECIMAL:
75236
75234
  switch (type.InternalType()) {
75237
75235
  case PhysicalType::INT16:
75238
- return GetTypedDiscreteQuantileAggregateFunction<int16_t>(type);
75236
+ return GetTypedDiscreteQuantileAggregateFunction<int16_t, int16_t>(type);
75239
75237
  case PhysicalType::INT32:
75240
- return GetTypedDiscreteQuantileAggregateFunction<int32_t>(type);
75238
+ return GetTypedDiscreteQuantileAggregateFunction<int32_t, int32_t>(type);
75241
75239
  case PhysicalType::INT64:
75242
- return GetTypedDiscreteQuantileAggregateFunction<int64_t>(type);
75240
+ return GetTypedDiscreteQuantileAggregateFunction<int64_t, int64_t>(type);
75243
75241
  case PhysicalType::INT128:
75244
- return GetTypedDiscreteQuantileAggregateFunction<hugeint_t>(type);
75242
+ return GetTypedDiscreteQuantileAggregateFunction<hugeint_t, hugeint_t>(type);
75245
75243
  default:
75246
75244
  throw NotImplementedException("Unimplemented discrete quantile aggregate");
75247
75245
  }
75248
75246
  break;
75249
75247
 
75250
75248
  case LogicalTypeId::DATE:
75251
- return GetTypedDiscreteQuantileAggregateFunction<int32_t>(type);
75249
+ return GetTypedDiscreteQuantileAggregateFunction<int32_t, int32_t>(type);
75252
75250
  case LogicalTypeId::TIMESTAMP:
75253
- return GetTypedDiscreteQuantileAggregateFunction<int64_t>(type);
75251
+ return GetTypedDiscreteQuantileAggregateFunction<int64_t, int64_t>(type);
75254
75252
  case LogicalTypeId::TIME:
75255
- return GetTypedDiscreteQuantileAggregateFunction<int64_t>(type);
75253
+ return GetTypedDiscreteQuantileAggregateFunction<int64_t, int64_t>(type);
75256
75254
  case LogicalTypeId::INTERVAL:
75257
- return GetTypedDiscreteQuantileAggregateFunction<interval_t>(type);
75255
+ return GetTypedDiscreteQuantileAggregateFunction<interval_t, interval_t>(type);
75256
+
75257
+ case LogicalTypeId::VARCHAR:
75258
+ return GetTypedDiscreteQuantileAggregateFunction<string_t, std::string>(type);
75258
75259
 
75259
75260
  default:
75260
75261
  throw NotImplementedException("Unimplemented discrete quantile aggregate");
75261
75262
  }
75262
75263
  }
75263
75264
 
75264
- template <class SAVE_TYPE, class CHILD_TYPE, bool DISCRETE>
75265
- struct QuantileListOperation : public QuantileOperation<SAVE_TYPE> {
75265
+ template <class CHILD_TYPE, bool DISCRETE>
75266
+ struct QuantileListOperation : public QuantileOperation {
75266
75267
 
75267
75268
  template <class RESULT_TYPE, class STATE>
75268
75269
  static void Finalize(Vector &result_list, FunctionData *bind_data_p, STATE *state, RESULT_TYPE *target,
75269
75270
  ValidityMask &mask, idx_t idx) {
75270
- if (state->pos == 0) {
75271
+ if (state->v.empty()) {
75271
75272
  mask.SetInvalid(idx);
75272
75273
  return;
75273
75274
  }
@@ -75280,13 +75281,13 @@ struct QuantileListOperation : public QuantileOperation<SAVE_TYPE> {
75280
75281
  ListVector::Reserve(result_list, ridx + bind_data->quantiles.size());
75281
75282
  auto rdata = FlatVector::GetData<CHILD_TYPE>(result);
75282
75283
 
75283
- D_ASSERT(state->v);
75284
- auto v_t = (SAVE_TYPE *)state->v;
75284
+ auto v_t = state->v.data();
75285
+ D_ASSERT(v_t);
75285
75286
 
75286
75287
  target[idx].offset = ridx;
75287
75288
  for (const auto &quantile : bind_data->quantiles) {
75288
- Interpolator<SAVE_TYPE, CHILD_TYPE, DISCRETE> interp(quantile, state->pos);
75289
- rdata[ridx] = interp(v_t);
75289
+ Interpolator<typename STATE::SaveType, CHILD_TYPE, DISCRETE> interp(quantile, state->v.size());
75290
+ rdata[ridx] = interp(v_t, result);
75290
75291
  ++ridx;
75291
75292
  }
75292
75293
  target[idx].length = bind_data->quantiles.size();
@@ -75313,18 +75314,16 @@ struct QuantileListOperation : public QuantileOperation<SAVE_TYPE> {
75313
75314
  auto rdata = FlatVector::GetData<CHILD_TYPE>(result);
75314
75315
 
75315
75316
  // 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);
75317
+ const auto prev_valid = state->w.size() == (prev.second - prev.first);
75318
+ state->SetPos(frame.second - frame.first);
75319
75319
 
75320
- D_ASSERT(state->v);
75321
- auto index = (idx_t *)state->v;
75320
+ auto index = state->w.data();
75322
75321
 
75323
75322
  bool fixed = false;
75324
75323
  auto j = state->pos;
75325
75324
  if (prev_valid && dmask.AllValid() && frame.first == prev.first + 1 && frame.second == prev.second + 1) {
75326
75325
  // Fixed frame size
75327
- j = ReplaceIndex(state, frame, prev);
75326
+ j = ReplaceIndex(index, frame, prev);
75328
75327
  fixed = true;
75329
75328
  } else {
75330
75329
  ReuseIndexes(index, frame, prev);
@@ -75349,8 +75348,8 @@ struct QuantileListOperation : public QuantileOperation<SAVE_TYPE> {
75349
75348
  const auto &quantile = bind_data->quantiles[q];
75350
75349
  Interpolator<INPUT_TYPE, CHILD_TYPE, DISCRETE> interp(quantile, state->pos);
75351
75350
 
75352
- if (fixed && CanReplace(state, data, j, interp.FRN, interp.CRN)) {
75353
- rdata[lentry.offset + q] = interp(data, index);
75351
+ if (fixed && CanReplace(index, data, j, interp.FRN, interp.CRN)) {
75352
+ rdata[lentry.offset + q] = interp(data, index, result);
75354
75353
  state->upper.resize(state->lower.size(), interp.FRN);
75355
75354
  } else {
75356
75355
  state->disturbed.push_back(q);
@@ -75371,15 +75370,15 @@ struct QuantileListOperation : public QuantileOperation<SAVE_TYPE> {
75371
75370
  if (interp.CRN != interp.FRN) {
75372
75371
  std::nth_element(index + interp.CRN, index + interp.CRN, index + state->upper[i], lt);
75373
75372
  }
75374
- rdata[lentry.offset + q] = interp(data, index);
75373
+ rdata[lentry.offset + q] = interp(data, index, result);
75375
75374
  }
75376
75375
  }
75377
75376
  };
75378
75377
 
75379
- template <typename INPUT_TYPE>
75378
+ template <typename INPUT_TYPE, typename SAVE_TYPE>
75380
75379
  AggregateFunction GetTypedDiscreteQuantileListAggregateFunction(const LogicalType &type) {
75381
- using STATE = QuantileState;
75382
- using OP = QuantileListOperation<INPUT_TYPE, INPUT_TYPE, true>;
75380
+ using STATE = QuantileState<SAVE_TYPE>;
75381
+ using OP = QuantileListOperation<INPUT_TYPE, true>;
75383
75382
  auto fun = QuantileListAggregate<STATE, INPUT_TYPE, list_entry_t, OP>(type, type);
75384
75383
  fun.window = AggregateFunction::UnaryWindow<STATE, INPUT_TYPE, list_entry_t, OP>;
75385
75384
  return fun;
@@ -75388,43 +75387,46 @@ AggregateFunction GetTypedDiscreteQuantileListAggregateFunction(const LogicalTyp
75388
75387
  AggregateFunction GetDiscreteQuantileListAggregateFunction(const LogicalType &type) {
75389
75388
  switch (type.id()) {
75390
75389
  case LogicalTypeId::TINYINT:
75391
- return GetTypedDiscreteQuantileListAggregateFunction<int8_t>(type);
75390
+ return GetTypedDiscreteQuantileListAggregateFunction<int8_t, int8_t>(type);
75392
75391
  case LogicalTypeId::SMALLINT:
75393
- return GetTypedDiscreteQuantileListAggregateFunction<int16_t>(type);
75392
+ return GetTypedDiscreteQuantileListAggregateFunction<int16_t, int16_t>(type);
75394
75393
  case LogicalTypeId::INTEGER:
75395
- return GetTypedDiscreteQuantileListAggregateFunction<int32_t>(type);
75394
+ return GetTypedDiscreteQuantileListAggregateFunction<int32_t, int32_t>(type);
75396
75395
  case LogicalTypeId::BIGINT:
75397
- return GetTypedDiscreteQuantileListAggregateFunction<int64_t>(type);
75396
+ return GetTypedDiscreteQuantileListAggregateFunction<int64_t, int64_t>(type);
75398
75397
  case LogicalTypeId::HUGEINT:
75399
- return GetTypedDiscreteQuantileListAggregateFunction<hugeint_t>(type);
75398
+ return GetTypedDiscreteQuantileListAggregateFunction<hugeint_t, hugeint_t>(type);
75400
75399
 
75401
75400
  case LogicalTypeId::FLOAT:
75402
- return GetTypedDiscreteQuantileListAggregateFunction<float>(type);
75401
+ return GetTypedDiscreteQuantileListAggregateFunction<float, float>(type);
75403
75402
  case LogicalTypeId::DOUBLE:
75404
- return GetTypedDiscreteQuantileListAggregateFunction<double>(type);
75403
+ return GetTypedDiscreteQuantileListAggregateFunction<double, double>(type);
75405
75404
  case LogicalTypeId::DECIMAL:
75406
75405
  switch (type.InternalType()) {
75407
75406
  case PhysicalType::INT16:
75408
- return GetTypedDiscreteQuantileListAggregateFunction<int16_t>(type);
75407
+ return GetTypedDiscreteQuantileListAggregateFunction<int16_t, int16_t>(type);
75409
75408
  case PhysicalType::INT32:
75410
- return GetTypedDiscreteQuantileListAggregateFunction<int32_t>(type);
75409
+ return GetTypedDiscreteQuantileListAggregateFunction<int32_t, int32_t>(type);
75411
75410
  case PhysicalType::INT64:
75412
- return GetTypedDiscreteQuantileListAggregateFunction<int64_t>(type);
75411
+ return GetTypedDiscreteQuantileListAggregateFunction<int64_t, int64_t>(type);
75413
75412
  case PhysicalType::INT128:
75414
- return GetTypedDiscreteQuantileListAggregateFunction<hugeint_t>(type);
75413
+ return GetTypedDiscreteQuantileListAggregateFunction<hugeint_t, hugeint_t>(type);
75415
75414
  default:
75416
75415
  throw NotImplementedException("Unimplemented discrete quantile list aggregate");
75417
75416
  }
75418
75417
  break;
75419
75418
 
75420
75419
  case LogicalTypeId::DATE:
75421
- return GetTypedDiscreteQuantileListAggregateFunction<date_t>(type);
75420
+ return GetTypedDiscreteQuantileListAggregateFunction<date_t, date_t>(type);
75422
75421
  case LogicalTypeId::TIMESTAMP:
75423
- return GetTypedDiscreteQuantileListAggregateFunction<timestamp_t>(type);
75422
+ return GetTypedDiscreteQuantileListAggregateFunction<timestamp_t, timestamp_t>(type);
75424
75423
  case LogicalTypeId::TIME:
75425
- return GetTypedDiscreteQuantileListAggregateFunction<dtime_t>(type);
75424
+ return GetTypedDiscreteQuantileListAggregateFunction<dtime_t, dtime_t>(type);
75426
75425
  case LogicalTypeId::INTERVAL:
75427
- return GetTypedDiscreteQuantileListAggregateFunction<interval_t>(type);
75426
+ return GetTypedDiscreteQuantileListAggregateFunction<interval_t, interval_t>(type);
75427
+
75428
+ case LogicalTypeId::VARCHAR:
75429
+ return GetTypedDiscreteQuantileListAggregateFunction<string_t, std::string>(type);
75428
75430
 
75429
75431
  default:
75430
75432
  throw NotImplementedException("Unimplemented discrete quantile list aggregate");
@@ -75434,8 +75436,8 @@ AggregateFunction GetDiscreteQuantileListAggregateFunction(const LogicalType &ty
75434
75436
  template <typename INPUT_TYPE, typename TARGET_TYPE>
75435
75437
  AggregateFunction GetTypedContinuousQuantileAggregateFunction(const LogicalType &input_type,
75436
75438
  const LogicalType &target_type) {
75437
- using STATE = QuantileState;
75438
- using OP = QuantileScalarOperation<INPUT_TYPE, false>;
75439
+ using STATE = QuantileState<INPUT_TYPE>;
75440
+ using OP = QuantileScalarOperation<false>;
75439
75441
  auto fun = AggregateFunction::UnaryAggregateDestructor<STATE, INPUT_TYPE, TARGET_TYPE, OP>(input_type, target_type);
75440
75442
  fun.window = AggregateFunction::UnaryWindow<STATE, INPUT_TYPE, TARGET_TYPE, OP>;
75441
75443
  return fun;
@@ -75488,8 +75490,8 @@ AggregateFunction GetContinuousQuantileAggregateFunction(const LogicalType &type
75488
75490
  template <typename INPUT_TYPE, typename CHILD_TYPE>
75489
75491
  AggregateFunction GetTypedContinuousQuantileListAggregateFunction(const LogicalType &input_type,
75490
75492
  const LogicalType &result_type) {
75491
- using STATE = QuantileState;
75492
- using OP = QuantileListOperation<INPUT_TYPE, CHILD_TYPE, false>;
75493
+ using STATE = QuantileState<INPUT_TYPE>;
75494
+ using OP = QuantileListOperation<CHILD_TYPE, false>;
75493
75495
  auto fun = QuantileListAggregate<STATE, INPUT_TYPE, list_entry_t, OP>(input_type, result_type);
75494
75496
  fun.window = AggregateFunction::UnaryWindow<STATE, INPUT_TYPE, list_entry_t, OP>;
75495
75497
  return fun;
@@ -75614,9 +75616,19 @@ unique_ptr<FunctionData> BindContinuousQuantileDecimalList(ClientContext &contex
75614
75616
  return bind_data;
75615
75617
  }
75616
75618
 
75619
+ static bool CanInterpolate(const LogicalType &type) {
75620
+ switch (type.id()) {
75621
+ case LogicalTypeId::INTERVAL:
75622
+ case LogicalTypeId::VARCHAR:
75623
+ return false;
75624
+ default:
75625
+ return true;
75626
+ }
75627
+ }
75628
+
75617
75629
  AggregateFunction GetMedianAggregate(const LogicalType &type) {
75618
- auto fun = (type.id() != LogicalTypeId::INTERVAL) ? GetContinuousQuantileAggregateFunction(type)
75619
- : GetDiscreteQuantileAggregateFunction(type);
75630
+ auto fun = CanInterpolate(type) ? GetContinuousQuantileAggregateFunction(type)
75631
+ : GetDiscreteQuantileAggregateFunction(type);
75620
75632
  fun.bind = BindMedian;
75621
75633
  return fun;
75622
75634
  }
@@ -75659,7 +75671,7 @@ void QuantileFun::RegisterFunction(BuiltinFunctions &set) {
75659
75671
  const vector<LogicalType> QUANTILES = {LogicalType::TINYINT, LogicalType::SMALLINT, LogicalType::INTEGER,
75660
75672
  LogicalType::BIGINT, LogicalType::HUGEINT, LogicalType::FLOAT,
75661
75673
  LogicalType::DOUBLE, LogicalType::DATE, LogicalType::TIMESTAMP,
75662
- LogicalType::TIME, LogicalType::INTERVAL};
75674
+ LogicalType::TIME, LogicalType::INTERVAL, LogicalType::VARCHAR};
75663
75675
 
75664
75676
  AggregateFunctionSet median("median");
75665
75677
  median.AddFunction(AggregateFunction({LogicalTypeId::DECIMAL}, LogicalTypeId::DECIMAL, nullptr, nullptr, nullptr,
@@ -75685,7 +75697,7 @@ void QuantileFun::RegisterFunction(BuiltinFunctions &set) {
75685
75697
  median.AddFunction(GetMedianAggregate(type));
75686
75698
  quantile_disc.AddFunction(GetDiscreteQuantileAggregate(type));
75687
75699
  quantile_disc.AddFunction(GetDiscreteQuantileListAggregate(type));
75688
- if (type.id() != LogicalTypeId::INTERVAL) {
75700
+ if (CanInterpolate(type)) {
75689
75701
  quantile_cont.AddFunction(GetContinuousQuantileAggregate(type));
75690
75702
  quantile_cont.AddFunction(GetContinuousQuantileListAggregate(type));
75691
75703
  }
@@ -77677,6 +77689,7 @@ CompressionFunction *DBConfig::GetCompressionFunction(CompressionType type, Phys
77677
77689
 
77678
77690
 
77679
77691
 
77692
+
77680
77693
 
77681
77694
 
77682
77695
  namespace duckdb {
@@ -77975,25 +77988,38 @@ idx_t Function::BindFunction(const string &name, vector<TableFunction> &function
77975
77988
  return Function::BindFunction(name, functions, types, error);
77976
77989
  }
77977
77990
 
77991
+ enum class LogicalTypeComparisonResult { IDENTICAL_TYPE, TARGET_IS_ANY, DIFFERENT_TYPES };
77992
+
77993
+ LogicalTypeComparisonResult RequiresCast(const LogicalType &source_type, const LogicalType &target_type) {
77994
+ if (target_type.id() == LogicalTypeId::ANY) {
77995
+ return LogicalTypeComparisonResult::TARGET_IS_ANY;
77996
+ }
77997
+ if (source_type == target_type) {
77998
+ return LogicalTypeComparisonResult::IDENTICAL_TYPE;
77999
+ }
78000
+ if (source_type.id() == LogicalTypeId::LIST && target_type.id() == LogicalTypeId::LIST) {
78001
+ return RequiresCast(ListType::GetChildType(source_type), ListType::GetChildType(target_type));
78002
+ }
78003
+ return LogicalTypeComparisonResult::DIFFERENT_TYPES;
78004
+ }
78005
+
77978
78006
  void BaseScalarFunction::CastToFunctionArguments(vector<unique_ptr<Expression>> &children) {
77979
78007
  for (idx_t i = 0; i < children.size(); i++) {
77980
78008
  auto target_type = i < this->arguments.size() ? this->arguments[i] : this->varargs;
77981
78009
  target_type.Verify();
77982
78010
  // check if the type of child matches the type of function argument
77983
78011
  // if not we need to add a cast
77984
- bool require_cast = children[i]->return_type != target_type;
78012
+ auto cast_result = RequiresCast(children[i]->return_type, target_type);
77985
78013
  // except for one special case: if the function accepts ANY argument
77986
78014
  // in that case we don't add a cast
77987
- if (target_type.id() == LogicalTypeId::ANY) {
78015
+ if (cast_result == LogicalTypeComparisonResult::TARGET_IS_ANY) {
77988
78016
  if (children[i]->return_type.id() == LogicalTypeId::UNKNOWN) {
77989
78017
  // UNLESS the child is a prepared statement parameter
77990
78018
  // in that case we default the prepared statement parameter to VARCHAR
77991
- target_type = LogicalType::VARCHAR;
77992
- } else {
77993
- require_cast = false;
78019
+ children[i]->return_type =
78020
+ ExpressionBinder::ExchangeType(target_type, LogicalTypeId::ANY, LogicalType::VARCHAR);
77994
78021
  }
77995
- }
77996
- if (require_cast) {
78022
+ } else if (cast_result == LogicalTypeComparisonResult::DIFFERENT_TYPES) {
77997
78023
  children[i] = BoundCastExpression::AddCastToType(move(children[i]), target_type);
77998
78024
  }
77999
78025
  }
@@ -83186,6 +83212,10 @@ static void ListExtractFunction(DataChunk &args, ExpressionState &state, Vector
83186
83212
  case LogicalTypeId::VARCHAR:
83187
83213
  ExecuteStringExtract(result, base, subscript, count);
83188
83214
  break;
83215
+ case LogicalTypeId::SQLNULL:
83216
+ result.SetVectorType(VectorType::CONSTANT_VECTOR);
83217
+ ConstantVector::SetNull(result, true);
83218
+ break;
83189
83219
  default:
83190
83220
  throw NotImplementedException("Specifier type not implemented");
83191
83221
  }
@@ -83194,10 +83224,14 @@ static void ListExtractFunction(DataChunk &args, ExpressionState &state, Vector
83194
83224
  static unique_ptr<FunctionData> ListExtractBind(ClientContext &context, ScalarFunction &bound_function,
83195
83225
  vector<unique_ptr<Expression>> &arguments) {
83196
83226
  D_ASSERT(bound_function.arguments.size() == 2);
83197
- D_ASSERT(LogicalTypeId::LIST == arguments[0]->return_type.id());
83198
- // list extract returns the child type of the list as return type
83199
- bound_function.return_type = ListType::GetChildType(arguments[0]->return_type);
83200
-
83227
+ if (arguments[0]->return_type.id() == LogicalTypeId::SQLNULL) {
83228
+ bound_function.arguments[0] = LogicalType::SQLNULL;
83229
+ bound_function.return_type = LogicalType::SQLNULL;
83230
+ } else {
83231
+ D_ASSERT(LogicalTypeId::LIST == arguments[0]->return_type.id());
83232
+ // list extract returns the child type of the list as return type
83233
+ bound_function.return_type = ListType::GetChildType(arguments[0]->return_type);
83234
+ }
83201
83235
  return make_unique<VariableReturnBindData>(bound_function.return_type);
83202
83236
  }
83203
83237
 
@@ -87869,7 +87903,7 @@ static unique_ptr<FunctionData> ListLengthBind(ClientContext &context, ScalarFun
87869
87903
 
87870
87904
  void LengthFun::RegisterFunction(BuiltinFunctions &set) {
87871
87905
  ScalarFunction array_length_unary = ScalarFunction(
87872
- {LogicalTypeId::LIST}, LogicalType::BIGINT,
87906
+ {LogicalType::LIST(LogicalType::ANY)}, LogicalType::BIGINT,
87873
87907
  ScalarFunction::UnaryFunction<list_entry_t, int64_t, ArrayLengthOperator>, false, ListLengthBind);
87874
87908
  ScalarFunctionSet length("length");
87875
87909
  length.AddFunction(ScalarFunction({LogicalType::VARCHAR}, LogicalType::BIGINT,
@@ -87883,7 +87917,7 @@ void LengthFun::RegisterFunction(BuiltinFunctions &set) {
87883
87917
  ScalarFunctionSet array_length("array_length");
87884
87918
  array_length.AddFunction(array_length_unary);
87885
87919
  array_length.AddFunction(
87886
- ScalarFunction({LogicalTypeId::LIST, LogicalType::BIGINT}, LogicalType::BIGINT,
87920
+ ScalarFunction({LogicalType::LIST(LogicalType::ANY), LogicalType::BIGINT}, LogicalType::BIGINT,
87887
87921
  ScalarFunction::BinaryFunction<list_entry_t, int64_t, int64_t, ArrayLengthBinaryOperator>, false,
87888
87922
  ListLengthBind));
87889
87923
  set.AddFunction(array_length);
@@ -143674,7 +143708,7 @@ void Planner::CreatePlan(SQLStatement &statement) {
143674
143708
  for (auto &expr : bound_parameters) {
143675
143709
  // check if the type of the parameter could be resolved
143676
143710
  if (expr->return_type.id() == LogicalTypeId::INVALID || expr->return_type.id() == LogicalTypeId::UNKNOWN) {
143677
- throw InternalException("Could not determine type of parameters");
143711
+ throw BinderException("Could not determine type of parameters");
143678
143712
  }
143679
143713
  auto value = make_unique<Value>(expr->return_type);
143680
143714
  expr->value = value.get();
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 "b63b69fcd"
14
- #define DUCKDB_VERSION "0.3.1-dev247"
13
+ #define DUCKDB_SOURCE_ID "9000dfec2"
14
+ #define DUCKDB_VERSION "0.3.1-dev283"
15
15
  //===----------------------------------------------------------------------===//
16
16
  // DuckDB
17
17
  //