duckdb 0.4.1-dev223.0 → 0.4.1-dev247.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.4.1-dev223.0",
4
+ "version": "0.4.1-dev247.0",
5
5
  "description": "DuckDB node.js API",
6
6
  "gypfile": true,
7
7
  "dependencies": {
package/src/duckdb.cpp CHANGED
@@ -88559,21 +88559,19 @@ void BaseScalarFunction::CastToFunctionArguments(vector<unique_ptr<Expression>>
88559
88559
  }
88560
88560
  }
88561
88561
 
88562
- unique_ptr<BoundFunctionExpression> ScalarFunction::BindScalarFunction(ClientContext &context, const string &schema,
88563
- const string &name,
88564
- vector<unique_ptr<Expression>> children,
88565
- string &error, bool is_operator) {
88562
+ unique_ptr<Expression> ScalarFunction::BindScalarFunction(ClientContext &context, const string &schema,
88563
+ const string &name, vector<unique_ptr<Expression>> children,
88564
+ string &error, bool is_operator, Binder *binder) {
88566
88565
  // bind the function
88567
88566
  auto function = Catalog::GetCatalog(context).GetEntry(context, CatalogType::SCALAR_FUNCTION_ENTRY, schema, name);
88568
88567
  D_ASSERT(function && function->type == CatalogType::SCALAR_FUNCTION_ENTRY);
88569
88568
  return ScalarFunction::BindScalarFunction(context, (ScalarFunctionCatalogEntry &)*function, move(children), error,
88570
- is_operator);
88569
+ is_operator, binder);
88571
88570
  }
88572
88571
 
88573
- unique_ptr<BoundFunctionExpression> ScalarFunction::BindScalarFunction(ClientContext &context,
88574
- ScalarFunctionCatalogEntry &func,
88575
- vector<unique_ptr<Expression>> children,
88576
- string &error, bool is_operator) {
88572
+ unique_ptr<Expression> ScalarFunction::BindScalarFunction(ClientContext &context, ScalarFunctionCatalogEntry &func,
88573
+ vector<unique_ptr<Expression>> children, string &error,
88574
+ bool is_operator, Binder *binder) {
88577
88575
  // bind the function
88578
88576
  bool cast_parameters;
88579
88577
  idx_t best_function = Function::BindFunction(func.name, func.functions, children, error, cast_parameters);
@@ -88583,6 +88581,18 @@ unique_ptr<BoundFunctionExpression> ScalarFunction::BindScalarFunction(ClientCon
88583
88581
 
88584
88582
  // found a matching function!
88585
88583
  auto &bound_function = func.functions[best_function];
88584
+
88585
+ if (bound_function.null_handling == FunctionNullHandling::NULL_IN_NULL_OUT) {
88586
+ for (auto &child : children) {
88587
+ if (child->return_type == LogicalTypeId::SQLNULL) {
88588
+ if (binder) {
88589
+ binder->RemoveParameters(children);
88590
+ }
88591
+ return make_unique<BoundConstantExpression>(Value(LogicalType::SQLNULL));
88592
+ }
88593
+ }
88594
+ }
88595
+
88586
88596
  return ScalarFunction::BindScalarFunction(context, bound_function, move(children), is_operator, cast_parameters);
88587
88597
  }
88588
88598
 
@@ -92756,11 +92766,6 @@ void MakeDateFun::RegisterFunction(BuiltinFunctions &set) {
92756
92766
 
92757
92767
 
92758
92768
 
92759
-
92760
-
92761
-
92762
-
92763
-
92764
92769
  #include <cctype>
92765
92770
 
92766
92771
  namespace duckdb {
@@ -94055,8 +94060,10 @@ static void StrpTimeFunction(DataChunk &args, ExpressionState &state, Vector &re
94055
94060
  void StrpTimeFun::RegisterFunction(BuiltinFunctions &set) {
94056
94061
  ScalarFunctionSet strptime("strptime");
94057
94062
 
94058
- strptime.AddFunction(ScalarFunction({LogicalType::VARCHAR, LogicalType::VARCHAR}, LogicalType::TIMESTAMP,
94059
- StrpTimeFunction, false, false, StrpTimeBindFunction));
94063
+ auto fun = ScalarFunction({LogicalType::VARCHAR, LogicalType::VARCHAR}, LogicalType::TIMESTAMP, StrpTimeFunction,
94064
+ false, false, StrpTimeBindFunction);
94065
+ fun.null_handling = FunctionNullHandling::SPECIAL_HANDLING;
94066
+ strptime.AddFunction(fun);
94060
94067
 
94061
94068
  set.AddFunction(strptime);
94062
94069
  }
@@ -94352,9 +94359,11 @@ void EnumRange::RegisterFunction(BuiltinFunctions &set) {
94352
94359
  }
94353
94360
 
94354
94361
  void EnumRangeBoundary::RegisterFunction(BuiltinFunctions &set) {
94355
- set.AddFunction(ScalarFunction("enum_range_boundary", {LogicalType::ANY, LogicalType::ANY},
94356
- LogicalType::LIST(LogicalType::VARCHAR), EnumRangeBoundaryFunction, false,
94357
- BindEnumRangeBoundaryFunction));
94362
+ auto fun = ScalarFunction("enum_range_boundary", {LogicalType::ANY, LogicalType::ANY},
94363
+ LogicalType::LIST(LogicalType::VARCHAR), EnumRangeBoundaryFunction, false,
94364
+ BindEnumRangeBoundaryFunction);
94365
+ fun.null_handling = FunctionNullHandling::SPECIAL_HANDLING;
94366
+ set.AddFunction(fun);
94358
94367
  }
94359
94368
 
94360
94369
  } // namespace duckdb
@@ -94599,8 +94608,10 @@ unique_ptr<FunctionData> CurrentSettingBind(ClientContext &context, ScalarFuncti
94599
94608
  }
94600
94609
 
94601
94610
  void CurrentSettingFun::RegisterFunction(BuiltinFunctions &set) {
94602
- set.AddFunction(ScalarFunction("current_setting", {LogicalType::VARCHAR}, LogicalType::ANY, CurrentSettingFunction,
94603
- false, CurrentSettingBind));
94611
+ auto fun = ScalarFunction("current_setting", {LogicalType::VARCHAR}, LogicalType::ANY, CurrentSettingFunction,
94612
+ false, CurrentSettingBind);
94613
+ fun.null_handling = FunctionNullHandling::SPECIAL_HANDLING;
94614
+ set.AddFunction(fun);
94604
94615
  }
94605
94616
 
94606
94617
  } // namespace duckdb
@@ -94718,22 +94729,24 @@ static void LeastGreatestFunction(DataChunk &args, ExpressionState &state, Vecto
94718
94729
  template <typename T, class OP>
94719
94730
  ScalarFunction GetLeastGreatestFunction(const LogicalType &type) {
94720
94731
  return ScalarFunction({type}, type, LeastGreatestFunction<T, OP>, true, false, nullptr, nullptr, nullptr, nullptr,
94721
- type);
94732
+ type, FunctionNullHandling::SPECIAL_HANDLING);
94722
94733
  }
94723
94734
 
94724
94735
  template <class OP>
94725
94736
  static void RegisterLeastGreatest(BuiltinFunctions &set, const string &fun_name) {
94726
94737
  ScalarFunctionSet fun_set(fun_name);
94727
94738
  fun_set.AddFunction(ScalarFunction({LogicalType::BIGINT}, LogicalType::BIGINT, LeastGreatestFunction<int64_t, OP>,
94728
- true, false, nullptr, nullptr, nullptr, nullptr, LogicalType::BIGINT));
94739
+ true, false, nullptr, nullptr, nullptr, nullptr, LogicalType::BIGINT,
94740
+ FunctionNullHandling::SPECIAL_HANDLING));
94729
94741
  fun_set.AddFunction(ScalarFunction({LogicalType::HUGEINT}, LogicalType::HUGEINT,
94730
94742
  LeastGreatestFunction<hugeint_t, OP>, true, false, nullptr, nullptr, nullptr,
94731
- nullptr, LogicalType::HUGEINT));
94743
+ nullptr, LogicalType::HUGEINT, FunctionNullHandling::SPECIAL_HANDLING));
94732
94744
  fun_set.AddFunction(ScalarFunction({LogicalType::DOUBLE}, LogicalType::DOUBLE, LeastGreatestFunction<double, OP>,
94733
- true, false, nullptr, nullptr, nullptr, nullptr, LogicalType::DOUBLE));
94745
+ true, false, nullptr, nullptr, nullptr, nullptr, LogicalType::DOUBLE,
94746
+ FunctionNullHandling::SPECIAL_HANDLING));
94734
94747
  fun_set.AddFunction(ScalarFunction({LogicalType::VARCHAR}, LogicalType::VARCHAR,
94735
94748
  LeastGreatestFunction<string_t, OP, true>, true, false, nullptr, nullptr,
94736
- nullptr, nullptr, LogicalType::VARCHAR));
94749
+ nullptr, nullptr, LogicalType::VARCHAR, FunctionNullHandling::SPECIAL_HANDLING));
94737
94750
 
94738
94751
  fun_set.AddFunction(GetLeastGreatestFunction<timestamp_t, OP>(LogicalType::TIMESTAMP));
94739
94752
  fun_set.AddFunction(GetLeastGreatestFunction<time_t, OP>(LogicalType::TIME));
@@ -95023,6 +95036,7 @@ static unique_ptr<FunctionData> ArraySliceBind(ClientContext &context, ScalarFun
95023
95036
  bound_function.arguments[1] = LogicalType::INTEGER;
95024
95037
  bound_function.arguments[2] = LogicalType::INTEGER;
95025
95038
  break;
95039
+ case LogicalTypeId::SQLNULL:
95026
95040
  case LogicalTypeId::UNKNOWN:
95027
95041
  bound_function.arguments[0] = LogicalTypeId::UNKNOWN;
95028
95042
  bound_function.return_type = LogicalType::SQLNULL;
@@ -95039,6 +95053,7 @@ void ArraySliceFun::RegisterFunction(BuiltinFunctions &set) {
95039
95053
  ScalarFunction fun({LogicalType::ANY, LogicalType::BIGINT, LogicalType::BIGINT}, LogicalType::ANY,
95040
95054
  ArraySliceFunction, false, false, ArraySliceBind);
95041
95055
  fun.varargs = LogicalType::ANY;
95056
+ fun.null_handling = FunctionNullHandling::SPECIAL_HANDLING;
95042
95057
  set.AddFunction({"array_slice", "list_slice"}, fun);
95043
95058
  }
95044
95059
 
@@ -95214,17 +95229,7 @@ static unique_ptr<FunctionData> ListContainsOrPositionBind(ClientContext &contex
95214
95229
 
95215
95230
  const auto &list = arguments[0]->return_type; // change to list
95216
95231
  const auto &value = arguments[1]->return_type;
95217
- if (list.id() == LogicalTypeId::SQLNULL && value.id() == LogicalTypeId::SQLNULL) {
95218
- bound_function.arguments[0] = LogicalType::SQLNULL;
95219
- bound_function.arguments[1] = LogicalType::SQLNULL;
95220
- bound_function.return_type = LogicalType::SQLNULL;
95221
- } else if (list.id() == LogicalTypeId::SQLNULL || value.id() == LogicalTypeId::SQLNULL) {
95222
- // In case either the list or the value is NULL, return NULL
95223
- // Similar to behaviour of prestoDB
95224
- bound_function.arguments[0] = list;
95225
- bound_function.arguments[1] = value;
95226
- bound_function.return_type = LogicalTypeId::SQLNULL;
95227
- } else if (list.id() == LogicalTypeId::UNKNOWN) {
95232
+ if (list.id() == LogicalTypeId::UNKNOWN) {
95228
95233
  bound_function.return_type = RETURN_TYPE;
95229
95234
  if (value.id() != LogicalTypeId::UNKNOWN) {
95230
95235
  // only list is a parameter, cast it to a list of value type
@@ -95412,10 +95417,6 @@ static unique_ptr<FunctionData> ListFlattenBind(ClientContext &context, ScalarFu
95412
95417
 
95413
95418
  auto &input_type = arguments[0]->return_type;
95414
95419
  bound_function.arguments[0] = input_type;
95415
- if (input_type.id() == LogicalTypeId::SQLNULL) {
95416
- bound_function.return_type = LogicalType(LogicalTypeId::SQLNULL);
95417
- return make_unique<VariableReturnBindData>(bound_function.return_type);
95418
- }
95419
95420
  if (input_type.id() == LogicalTypeId::UNKNOWN) {
95420
95421
  bound_function.arguments[0] = LogicalType(LogicalTypeId::UNKNOWN);
95421
95422
  bound_function.return_type = LogicalType(LogicalTypeId::SQLNULL);
@@ -95820,7 +95821,6 @@ static unique_ptr<FunctionData> ListAggregatesBindFunction(ClientContext &contex
95820
95821
  template <bool IS_AGGR = false>
95821
95822
  static unique_ptr<FunctionData> ListAggregatesBind(ClientContext &context, ScalarFunction &bound_function,
95822
95823
  vector<unique_ptr<Expression>> &arguments) {
95823
-
95824
95824
  if (arguments[0]->return_type.id() == LogicalTypeId::SQLNULL) {
95825
95825
  bound_function.arguments[0] = LogicalType::SQLNULL;
95826
95826
  bound_function.return_type = LogicalType::SQLNULL;
@@ -95907,8 +95907,10 @@ static unique_ptr<FunctionData> ListUniqueBind(ClientContext &context, ScalarFun
95907
95907
  }
95908
95908
 
95909
95909
  ScalarFunction ListAggregateFun::GetFunction() {
95910
- return ScalarFunction({LogicalType::LIST(LogicalType::ANY), LogicalType::VARCHAR}, LogicalType::ANY,
95911
- ListAggregateFunction, false, false, ListAggregateBind);
95910
+ auto result = ScalarFunction({LogicalType::LIST(LogicalType::ANY), LogicalType::VARCHAR}, LogicalType::ANY,
95911
+ ListAggregateFunction, false, false, ListAggregateBind);
95912
+ result.null_handling = FunctionNullHandling::SPECIAL_HANDLING;
95913
+ return result;
95912
95914
  }
95913
95915
 
95914
95916
  ScalarFunction ListDistinctFun::GetFunction() {
@@ -96015,9 +96017,7 @@ static unique_ptr<FunctionData> ListConcatBind(ClientContext &context, ScalarFun
96015
96017
 
96016
96018
  auto &lhs = arguments[0]->return_type;
96017
96019
  auto &rhs = arguments[1]->return_type;
96018
- if (lhs.id() == LogicalTypeId::SQLNULL && rhs.id() == LogicalTypeId::SQLNULL) {
96019
- bound_function.return_type = LogicalType::SQLNULL;
96020
- } else if (lhs.id() == LogicalTypeId::SQLNULL || rhs.id() == LogicalTypeId::SQLNULL) {
96020
+ if (lhs.id() == LogicalTypeId::SQLNULL || rhs.id() == LogicalTypeId::SQLNULL) {
96021
96021
  // we mimic postgres behaviour: list_concat(NULL, my_list) = my_list
96022
96022
  bound_function.arguments[0] = lhs;
96023
96023
  bound_function.arguments[1] = rhs;
@@ -96058,9 +96058,11 @@ static unique_ptr<BaseStatistics> ListConcatStats(ClientContext &context, Functi
96058
96058
 
96059
96059
  ScalarFunction ListConcatFun::GetFunction() {
96060
96060
  // the arguments and return types are actually set in the binder function
96061
- return ScalarFunction({LogicalType::LIST(LogicalType::ANY), LogicalType::LIST(LogicalType::ANY)},
96062
- LogicalType::LIST(LogicalType::ANY), ListConcatFunction, false, false, ListConcatBind,
96063
- nullptr, ListConcatStats);
96061
+ auto fun = ScalarFunction({LogicalType::LIST(LogicalType::ANY), LogicalType::LIST(LogicalType::ANY)},
96062
+ LogicalType::LIST(LogicalType::ANY), ListConcatFunction, false, false, ListConcatBind,
96063
+ nullptr, ListConcatStats);
96064
+ fun.null_handling = FunctionNullHandling::SPECIAL_HANDLING;
96065
+ return fun;
96064
96066
  }
96065
96067
 
96066
96068
  void ListConcatFun::RegisterFunction(BuiltinFunctions &set) {
@@ -96268,14 +96270,9 @@ static void ListExtractFunction(DataChunk &args, ExpressionState &state, Vector
96268
96270
  static unique_ptr<FunctionData> ListExtractBind(ClientContext &context, ScalarFunction &bound_function,
96269
96271
  vector<unique_ptr<Expression>> &arguments) {
96270
96272
  D_ASSERT(bound_function.arguments.size() == 2);
96271
- if (arguments[0]->return_type.id() == LogicalTypeId::SQLNULL) {
96272
- bound_function.arguments[0] = LogicalType::SQLNULL;
96273
- bound_function.return_type = LogicalType::SQLNULL;
96274
- } else {
96275
- D_ASSERT(LogicalTypeId::LIST == arguments[0]->return_type.id());
96276
- // list extract returns the child type of the list as return type
96277
- bound_function.return_type = ListType::GetChildType(arguments[0]->return_type);
96278
- }
96273
+ D_ASSERT(LogicalTypeId::LIST == arguments[0]->return_type.id());
96274
+ // list extract returns the child type of the list as return type
96275
+ bound_function.return_type = ListType::GetChildType(arguments[0]->return_type);
96279
96276
  return make_unique<VariableReturnBindData>(bound_function.return_type);
96280
96277
  }
96281
96278
 
@@ -96554,13 +96551,6 @@ static void ListSortFunction(DataChunk &args, ExpressionState &state, Vector &re
96554
96551
  static unique_ptr<FunctionData> ListSortBind(ClientContext &context, ScalarFunction &bound_function,
96555
96552
  vector<unique_ptr<Expression>> &arguments, OrderType &order,
96556
96553
  OrderByNullType &null_order) {
96557
-
96558
- if (arguments[0]->return_type.id() == LogicalTypeId::SQLNULL) {
96559
- bound_function.arguments[0] = LogicalType::SQLNULL;
96560
- bound_function.return_type = LogicalType::SQLNULL;
96561
- return make_unique<VariableReturnBindData>(bound_function.return_type);
96562
- }
96563
-
96564
96554
  bound_function.arguments[0] = arguments[0]->return_type;
96565
96555
  bound_function.return_type = arguments[0]->return_type;
96566
96556
  auto child_type = ListType::GetChildType(arguments[0]->return_type);
@@ -96762,6 +96752,7 @@ void ListValueFun::RegisterFunction(BuiltinFunctions &set) {
96762
96752
  ScalarFunction fun("list_value", {}, LogicalTypeId::LIST, ListValueFunction, false, ListValueBind, nullptr,
96763
96753
  ListValueStats);
96764
96754
  fun.varargs = LogicalType::ANY;
96755
+ fun.null_handling = FunctionNullHandling::SPECIAL_HANDLING;
96765
96756
  set.AddFunction(fun);
96766
96757
  fun.name = "list_pack";
96767
96758
  set.AddFunction(fun);
@@ -97082,6 +97073,7 @@ void CardinalityFun::RegisterFunction(BuiltinFunctions &set) {
97082
97073
  ScalarFunction fun("cardinality", {LogicalType::ANY}, LogicalType::UBIGINT, CardinalityFunction, false,
97083
97074
  CardinalityBind);
97084
97075
  fun.varargs = LogicalType::ANY;
97076
+ fun.null_handling = FunctionNullHandling::SPECIAL_HANDLING;
97085
97077
  set.AddFunction(fun);
97086
97078
  }
97087
97079
 
@@ -97274,6 +97266,7 @@ void MapFun::RegisterFunction(BuiltinFunctions &set) {
97274
97266
  //! the arguments and return types are actually set in the binder function
97275
97267
  ScalarFunction fun("map", {}, LogicalTypeId::MAP, MapFunction, false, MapBind);
97276
97268
  fun.varargs = LogicalType::ANY;
97269
+ fun.null_handling = FunctionNullHandling::SPECIAL_HANDLING;
97277
97270
  set.AddFunction(fun);
97278
97271
  }
97279
97272
 
@@ -97350,6 +97343,7 @@ void MapExtractFun::RegisterFunction(BuiltinFunctions &set) {
97350
97343
  ScalarFunction fun("map_extract", {LogicalType::ANY, LogicalType::ANY}, LogicalType::ANY, MapExtractFunction, false,
97351
97344
  MapExtractBind);
97352
97345
  fun.varargs = LogicalType::ANY;
97346
+ fun.null_handling = FunctionNullHandling::SPECIAL_HANDLING;
97353
97347
  set.AddFunction(fun);
97354
97348
  fun.name = "element_at";
97355
97349
  set.AddFunction(fun);
@@ -101195,7 +101189,6 @@ void CHR::RegisterFunction(BuiltinFunctions &set) {
101195
101189
 
101196
101190
 
101197
101191
 
101198
-
101199
101192
  #include <string.h>
101200
101193
 
101201
101194
  namespace duckdb {
@@ -101436,6 +101429,7 @@ void ConcatFun::RegisterFunction(BuiltinFunctions &set) {
101436
101429
  // concat_ws(',', '', '') = ","
101437
101430
  ScalarFunction concat = ScalarFunction("concat", {LogicalType::VARCHAR}, LogicalType::VARCHAR, ConcatFunction);
101438
101431
  concat.varargs = LogicalType::VARCHAR;
101432
+ concat.null_handling = FunctionNullHandling::SPECIAL_HANDLING;
101439
101433
  set.AddFunction(concat);
101440
101434
 
101441
101435
  ScalarFunctionSet concat_op("||");
@@ -101443,11 +101437,15 @@ void ConcatFun::RegisterFunction(BuiltinFunctions &set) {
101443
101437
  ScalarFunction({LogicalType::VARCHAR, LogicalType::VARCHAR}, LogicalType::VARCHAR, ConcatOperator));
101444
101438
  concat_op.AddFunction(ScalarFunction({LogicalType::BLOB, LogicalType::BLOB}, LogicalType::BLOB, ConcatOperator));
101445
101439
  concat_op.AddFunction(ListConcatFun::GetFunction());
101440
+ for (auto &fun : concat_op.functions) {
101441
+ fun.null_handling = FunctionNullHandling::SPECIAL_HANDLING;
101442
+ }
101446
101443
  set.AddFunction(concat_op);
101447
101444
 
101448
101445
  ScalarFunction concat_ws = ScalarFunction("concat_ws", {LogicalType::VARCHAR, LogicalType::VARCHAR},
101449
101446
  LogicalType::VARCHAR, ConcatWSFunction);
101450
101447
  concat_ws.varargs = LogicalType::VARCHAR;
101448
+ concat_ws.null_handling = FunctionNullHandling::SPECIAL_HANDLING;
101451
101449
  set.AddFunction(concat_ws);
101452
101450
  }
101453
101451
 
@@ -103502,19 +103500,22 @@ void RegexpFun::RegisterFunction(BuiltinFunctions &set) {
103502
103500
  ScalarFunctionSet regexp_full_match("regexp_full_match");
103503
103501
  regexp_full_match.AddFunction(ScalarFunction({LogicalType::VARCHAR, LogicalType::VARCHAR}, LogicalType::BOOLEAN,
103504
103502
  RegexpMatchesFunction<RegexFullMatch>, false, false, RegexpMatchesBind,
103505
- nullptr, nullptr, RegexInitLocalState));
103503
+ nullptr, nullptr, RegexInitLocalState, LogicalType::INVALID,
103504
+ FunctionNullHandling::SPECIAL_HANDLING));
103506
103505
  regexp_full_match.AddFunction(ScalarFunction({LogicalType::VARCHAR, LogicalType::VARCHAR, LogicalType::VARCHAR},
103507
103506
  LogicalType::BOOLEAN, RegexpMatchesFunction<RegexFullMatch>, false,
103508
- false, RegexpMatchesBind, nullptr, nullptr, RegexInitLocalState));
103507
+ false, RegexpMatchesBind, nullptr, nullptr, RegexInitLocalState,
103508
+ LogicalType::INVALID, FunctionNullHandling::SPECIAL_HANDLING));
103509
103509
 
103510
103510
  ScalarFunctionSet regexp_partial_match("regexp_matches");
103511
103511
  regexp_partial_match.AddFunction(ScalarFunction({LogicalType::VARCHAR, LogicalType::VARCHAR}, LogicalType::BOOLEAN,
103512
103512
  RegexpMatchesFunction<RegexPartialMatch>, false, false,
103513
- RegexpMatchesBind, nullptr, nullptr, RegexInitLocalState));
103514
- regexp_partial_match.AddFunction(ScalarFunction({LogicalType::VARCHAR, LogicalType::VARCHAR, LogicalType::VARCHAR},
103515
- LogicalType::BOOLEAN, RegexpMatchesFunction<RegexPartialMatch>,
103516
- false, false, RegexpMatchesBind, nullptr, nullptr,
103517
- RegexInitLocalState));
103513
+ RegexpMatchesBind, nullptr, nullptr, RegexInitLocalState,
103514
+ LogicalType::INVALID, FunctionNullHandling::SPECIAL_HANDLING));
103515
+ regexp_partial_match.AddFunction(
103516
+ ScalarFunction({LogicalType::VARCHAR, LogicalType::VARCHAR, LogicalType::VARCHAR}, LogicalType::BOOLEAN,
103517
+ RegexpMatchesFunction<RegexPartialMatch>, false, false, RegexpMatchesBind, nullptr, nullptr,
103518
+ RegexInitLocalState, LogicalType::INVALID, FunctionNullHandling::SPECIAL_HANDLING));
103518
103519
 
103519
103520
  ScalarFunctionSet regexp_replace("regexp_replace");
103520
103521
  regexp_replace.AddFunction(ScalarFunction({LogicalType::VARCHAR, LogicalType::VARCHAR, LogicalType::VARCHAR},
@@ -103527,10 +103528,12 @@ void RegexpFun::RegisterFunction(BuiltinFunctions &set) {
103527
103528
  ScalarFunctionSet regexp_extract("regexp_extract");
103528
103529
  regexp_extract.AddFunction(ScalarFunction({LogicalType::VARCHAR, LogicalType::VARCHAR}, LogicalType::VARCHAR,
103529
103530
  RegexExtractFunction, false, false, RegexExtractBind, nullptr, nullptr,
103530
- RegexExtractInitLocalState));
103531
+ RegexExtractInitLocalState, LogicalType::INVALID,
103532
+ FunctionNullHandling::SPECIAL_HANDLING));
103531
103533
  regexp_extract.AddFunction(ScalarFunction({LogicalType::VARCHAR, LogicalType::VARCHAR, LogicalType::INTEGER},
103532
103534
  LogicalType::VARCHAR, RegexExtractFunction, false, false,
103533
- RegexExtractBind, nullptr, nullptr, RegexExtractInitLocalState));
103535
+ RegexExtractBind, nullptr, nullptr, RegexExtractInitLocalState,
103536
+ LogicalType::INVALID, FunctionNullHandling::SPECIAL_HANDLING));
103534
103537
 
103535
103538
  set.AddFunction(regexp_full_match);
103536
103539
  set.AddFunction(regexp_partial_match);
@@ -103736,8 +103739,6 @@ void ReverseFun::RegisterFunction(BuiltinFunctions &set) {
103736
103739
 
103737
103740
 
103738
103741
 
103739
-
103740
-
103741
103742
  namespace duckdb {
103742
103743
 
103743
103744
  struct StringSplitIterator {
@@ -103978,12 +103979,15 @@ static void StringSplitRegexFunction(DataChunk &args, ExpressionState &state, Ve
103978
103979
  void StringSplitFun::RegisterFunction(BuiltinFunctions &set) {
103979
103980
  auto varchar_list_type = LogicalType::LIST(LogicalType::VARCHAR);
103980
103981
 
103981
- set.AddFunction(
103982
- {"string_split", "str_split", "string_to_array", "split"},
103983
- ScalarFunction({LogicalType::VARCHAR, LogicalType::VARCHAR}, varchar_list_type, StringSplitFunction));
103984
- set.AddFunction(
103985
- {"string_split_regex", "str_split_regex", "regexp_split_to_array"},
103986
- ScalarFunction({LogicalType::VARCHAR, LogicalType::VARCHAR}, varchar_list_type, StringSplitRegexFunction));
103982
+ auto regular_fun =
103983
+ ScalarFunction({LogicalType::VARCHAR, LogicalType::VARCHAR}, varchar_list_type, StringSplitFunction);
103984
+ regular_fun.null_handling = FunctionNullHandling::SPECIAL_HANDLING;
103985
+ set.AddFunction({"string_split", "str_split", "string_to_array", "split"}, regular_fun);
103986
+
103987
+ auto regex_fun =
103988
+ ScalarFunction({LogicalType::VARCHAR, LogicalType::VARCHAR}, varchar_list_type, StringSplitRegexFunction);
103989
+ regex_fun.null_handling = FunctionNullHandling::SPECIAL_HANDLING;
103990
+ set.AddFunction({"string_split_regex", "str_split_regex", "regexp_split_to_array"}, regex_fun);
103987
103991
  }
103988
103992
 
103989
103993
  } // namespace duckdb
@@ -104558,12 +104562,6 @@ static void StructExtractFunction(DataChunk &args, ExpressionState &state, Vecto
104558
104562
  static unique_ptr<FunctionData> StructExtractBind(ClientContext &context, ScalarFunction &bound_function,
104559
104563
  vector<unique_ptr<Expression>> &arguments) {
104560
104564
  D_ASSERT(bound_function.arguments.size() == 2);
104561
- if (arguments[0]->return_type.id() == LogicalTypeId::SQLNULL ||
104562
- arguments[1]->return_type.id() == LogicalTypeId::SQLNULL) {
104563
- bound_function.return_type = LogicalType::SQLNULL;
104564
- bound_function.arguments[0] = LogicalType::SQLNULL;
104565
- return make_unique<StructExtractBindData>("", 0, LogicalType::SQLNULL);
104566
- }
104567
104565
  D_ASSERT(LogicalTypeId::STRUCT == arguments[0]->return_type.id());
104568
104566
  auto &struct_children = StructType::GetChildTypes(arguments[0]->return_type);
104569
104567
  if (struct_children.empty()) {
@@ -104821,6 +104819,7 @@ void StructPackFun::RegisterFunction(BuiltinFunctions &set) {
104821
104819
  ScalarFunction fun("struct_pack", {}, LogicalTypeId::STRUCT, StructPackFunction, false, StructPackBind, nullptr,
104822
104820
  StructPackStats);
104823
104821
  fun.varargs = LogicalType::ANY;
104822
+ fun.null_handling = FunctionNullHandling::SPECIAL_HANDLING;
104824
104823
  set.AddFunction(fun);
104825
104824
  fun.name = "row";
104826
104825
  set.AddFunction(fun);
@@ -105119,14 +105118,19 @@ ExportAggregateFunction::Bind(unique_ptr<BoundAggregateExpression> child_aggrega
105119
105118
  }
105120
105119
 
105121
105120
  ScalarFunction ExportAggregateFunction::GetFinalize() {
105122
- return ScalarFunction("finalize", {LogicalTypeId::AGGREGATE_STATE}, LogicalTypeId::INVALID, AggregateStateFinalize,
105123
- false, BindAggregateState, nullptr, nullptr, InitFinalizeState);
105121
+ auto result =
105122
+ ScalarFunction("finalize", {LogicalTypeId::AGGREGATE_STATE}, LogicalTypeId::INVALID, AggregateStateFinalize,
105123
+ false, BindAggregateState, nullptr, nullptr, InitFinalizeState);
105124
+ result.null_handling = FunctionNullHandling::SPECIAL_HANDLING;
105125
+ return result;
105124
105126
  }
105125
105127
 
105126
105128
  ScalarFunction ExportAggregateFunction::GetCombine() {
105127
- return ScalarFunction("combine", {LogicalTypeId::AGGREGATE_STATE, LogicalTypeId::ANY},
105128
- LogicalTypeId::AGGREGATE_STATE, AggregateStateCombine, false, BindAggregateState, nullptr,
105129
- nullptr, InitCombineState);
105129
+ auto result =
105130
+ ScalarFunction("combine", {LogicalTypeId::AGGREGATE_STATE, LogicalTypeId::ANY}, LogicalTypeId::AGGREGATE_STATE,
105131
+ AggregateStateCombine, false, BindAggregateState, nullptr, nullptr, InitCombineState);
105132
+ result.null_handling = FunctionNullHandling::SPECIAL_HANDLING;
105133
+ return result;
105130
105134
  }
105131
105135
 
105132
105136
  } // namespace duckdb
@@ -105246,19 +105250,21 @@ FunctionLocalState::~FunctionLocalState() {
105246
105250
  ScalarFunction::ScalarFunction(string name, vector<LogicalType> arguments, LogicalType return_type,
105247
105251
  scalar_function_t function, bool has_side_effects, bind_scalar_function_t bind,
105248
105252
  dependency_function_t dependency, function_statistics_t statistics,
105249
- init_local_state_t init_local_state, LogicalType varargs, bool propagate_null_values)
105253
+ init_local_state_t init_local_state, LogicalType varargs, bool propagate_null_values,
105254
+ FunctionNullHandling null_handling)
105250
105255
  : BaseScalarFunction(move(name), move(arguments), move(return_type), has_side_effects, move(varargs),
105251
105256
  propagate_null_values),
105252
105257
  function(move(function)), bind(bind), init_local_state(init_local_state), dependency(dependency),
105253
- statistics(statistics) {
105258
+ statistics(statistics), null_handling(null_handling) {
105254
105259
  }
105255
105260
 
105256
105261
  ScalarFunction::ScalarFunction(vector<LogicalType> arguments, LogicalType return_type, scalar_function_t function,
105257
105262
  bool propagate_null_values, bool has_side_effects, bind_scalar_function_t bind,
105258
105263
  dependency_function_t dependency, function_statistics_t statistics,
105259
- init_local_state_t init_local_state, LogicalType varargs)
105264
+ init_local_state_t init_local_state, LogicalType varargs,
105265
+ FunctionNullHandling null_handling)
105260
105266
  : ScalarFunction(string(), move(arguments), move(return_type), move(function), has_side_effects, bind, dependency,
105261
- statistics, init_local_state, move(varargs), propagate_null_values) {
105267
+ statistics, init_local_state, move(varargs), propagate_null_values, null_handling) {
105262
105268
  }
105263
105269
 
105264
105270
  bool ScalarFunction::operator==(const ScalarFunction &rhs) const {
@@ -138153,7 +138159,7 @@ unique_ptr<Expression> DatePartSimplificationRule::Apply(LogicalOperator &op, ve
138153
138159
  if (!function) {
138154
138160
  throw BinderException(error);
138155
138161
  }
138156
- return move(function);
138162
+ return function;
138157
138163
  }
138158
138164
 
138159
138165
  } // namespace duckdb
@@ -164364,7 +164370,7 @@ BindResult ExpressionBinder::BindFunction(FunctionExpression &function, ScalarFu
164364
164370
  children.push_back(move(child.expr));
164365
164371
  }
164366
164372
  unique_ptr<Expression> result =
164367
- ScalarFunction::BindScalarFunction(context, *func, move(children), error, function.is_operator);
164373
+ ScalarFunction::BindScalarFunction(context, *func, move(children), error, function.is_operator, &binder);
164368
164374
  if (!result) {
164369
164375
  throw BinderException(binder.FormatError(function, error));
164370
164376
  }
@@ -170460,9 +170466,9 @@ unique_ptr<LogicalOperator> Binder::CreatePlan(BoundTableFunction &ref) {
170460
170466
 
170461
170467
 
170462
170468
 
170463
- #include <algorithm>
170464
170469
 
170465
170470
 
170471
+ #include <algorithm>
170466
170472
 
170467
170473
  namespace duckdb {
170468
170474
 
@@ -170823,6 +170829,22 @@ const unordered_set<string> &Binder::GetTableNames() {
170823
170829
  return table_names;
170824
170830
  }
170825
170831
 
170832
+ void Binder::RemoveParameters(vector<unique_ptr<Expression>> &expressions) {
170833
+ for (auto &expr : expressions) {
170834
+ if (!expr->HasParameter()) {
170835
+ continue;
170836
+ }
170837
+ ExpressionIterator::EnumerateExpression(expr, [&](Expression &child) {
170838
+ for (auto param_it = parameters->begin(); param_it != parameters->end(); param_it++) {
170839
+ if (expr->Equals(*param_it)) {
170840
+ parameters->erase(param_it);
170841
+ break;
170842
+ }
170843
+ }
170844
+ });
170845
+ }
170846
+ }
170847
+
170826
170848
  string Binder::FormatError(ParsedExpression &expr_context, const string &message) {
170827
170849
  return FormatError(expr_context.query_location, message);
170828
170850
  }
package/src/duckdb.hpp CHANGED
@@ -11,8 +11,8 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
11
11
  #pragma once
12
12
  #define DUCKDB_AMALGAMATION 1
13
13
  #define DUCKDB_AMALGAMATION_EXTENDED 1
14
- #define DUCKDB_SOURCE_ID "4d39f040c"
15
- #define DUCKDB_VERSION "v0.4.1-dev223"
14
+ #define DUCKDB_SOURCE_ID "78199c403"
15
+ #define DUCKDB_VERSION "v0.4.1-dev247"
16
16
  //===----------------------------------------------------------------------===//
17
17
  // DuckDB
18
18
  //
@@ -7392,6 +7392,9 @@ struct FunctionLocalState {
7392
7392
  DUCKDB_API virtual ~FunctionLocalState();
7393
7393
  };
7394
7394
 
7395
+ enum class FunctionNullHandling : uint8_t { NULL_IN_NULL_OUT = 0, SPECIAL_HANDLING = 1 };
7396
+
7397
+ class Binder;
7395
7398
  class BoundFunctionExpression;
7396
7399
  class ScalarFunctionCatalogEntry;
7397
7400
 
@@ -7425,13 +7428,15 @@ public:
7425
7428
  bind_scalar_function_t bind = nullptr, dependency_function_t dependency = nullptr,
7426
7429
  function_statistics_t statistics = nullptr, init_local_state_t init_local_state = nullptr,
7427
7430
  LogicalType varargs = LogicalType(LogicalTypeId::INVALID),
7428
- bool propagate_null_values = false);
7431
+ bool propagate_null_values = false,
7432
+ FunctionNullHandling null_handling = FunctionNullHandling::NULL_IN_NULL_OUT);
7429
7433
 
7430
7434
  DUCKDB_API ScalarFunction(vector<LogicalType> arguments, LogicalType return_type, scalar_function_t function,
7431
7435
  bool propagate_null_values = false, bool has_side_effects = false,
7432
7436
  bind_scalar_function_t bind = nullptr, dependency_function_t dependency = nullptr,
7433
7437
  function_statistics_t statistics = nullptr, init_local_state_t init_local_state = nullptr,
7434
- LogicalType varargs = LogicalType(LogicalTypeId::INVALID));
7438
+ LogicalType varargs = LogicalType(LogicalTypeId::INVALID),
7439
+ FunctionNullHandling null_handling = FunctionNullHandling::NULL_IN_NULL_OUT);
7435
7440
 
7436
7441
  //! The main scalar function to execute
7437
7442
  scalar_function_t function;
@@ -7443,15 +7448,17 @@ public:
7443
7448
  dependency_function_t dependency;
7444
7449
  //! The statistics propagation function (if any)
7445
7450
  function_statistics_t statistics;
7446
-
7447
- DUCKDB_API static unique_ptr<BoundFunctionExpression> BindScalarFunction(ClientContext &context,
7448
- const string &schema, const string &name,
7449
- vector<unique_ptr<Expression>> children,
7450
- string &error, bool is_operator = false);
7451
- DUCKDB_API static unique_ptr<BoundFunctionExpression> BindScalarFunction(ClientContext &context,
7452
- ScalarFunctionCatalogEntry &function,
7453
- vector<unique_ptr<Expression>> children,
7454
- string &error, bool is_operator = false);
7451
+ //! How this function handles NULL values
7452
+ FunctionNullHandling null_handling;
7453
+
7454
+ DUCKDB_API static unique_ptr<Expression> BindScalarFunction(ClientContext &context, const string &schema,
7455
+ const string &name,
7456
+ vector<unique_ptr<Expression>> children, string &error,
7457
+ bool is_operator = false, Binder *binder = nullptr);
7458
+ DUCKDB_API static unique_ptr<Expression> BindScalarFunction(ClientContext &context,
7459
+ ScalarFunctionCatalogEntry &function,
7460
+ vector<unique_ptr<Expression>> children, string &error,
7461
+ bool is_operator = false, Binder *binder = nullptr);
7455
7462
 
7456
7463
  DUCKDB_API static unique_ptr<BoundFunctionExpression>
7457
7464
  BindScalarFunction(ClientContext &context, ScalarFunction bound_function, vector<unique_ptr<Expression>> children,
@@ -12929,7 +12936,7 @@ public:
12929
12936
  vector<unique_ptr<Expression>> arguments, unique_ptr<FunctionData> bind_info,
12930
12937
  bool is_operator = false);
12931
12938
 
12932
- // The bound function expression
12939
+ //! The bound function expression
12933
12940
  ScalarFunction function;
12934
12941
  //! List of child-expressions of the function
12935
12942
  vector<unique_ptr<Expression>> children;
@@ -14324,6 +14331,9 @@ public:
14324
14331
  void AddTableName(string table_name);
14325
14332
  const unordered_set<string> &GetTableNames();
14326
14333
 
14334
+ //! Removes the BoundParameterExpressions from Binder::parameters if they occur in 'expressions'
14335
+ void RemoveParameters(vector<unique_ptr<Expression>> &expressions);
14336
+
14327
14337
  private:
14328
14338
  //! The parent binder (if any)
14329
14339
  shared_ptr<Binder> parent;