duckdb 0.2.10-dev360.0 → 0.2.10-dev441.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.2.10-dev360.0",
4
+ "version": "0.2.10-dev441.0",
5
5
  "description": "DuckDB node.js API",
6
6
  "gypfile": true,
7
7
  "dependencies": {
package/src/duckdb.cpp CHANGED
@@ -47804,12 +47804,15 @@ namespace duckdb {
47804
47804
 
47805
47805
  unique_ptr<ExpressionState> ExpressionExecutor::InitializeState(const BoundFunctionExpression &expr,
47806
47806
  ExpressionExecutorState &root) {
47807
- auto result = make_unique<ExpressionState>(expr, root);
47807
+ auto result = make_unique<ExecuteFunctionState>(expr, root);
47808
47808
  for (auto &child : expr.children) {
47809
47809
  result->AddChild(child.get());
47810
47810
  }
47811
47811
  result->Finalize();
47812
- return result;
47812
+ if (expr.function.init_local_state) {
47813
+ result->local_state = expr.function.init_local_state(expr, expr.bind_info.get());
47814
+ }
47815
+ return move(result);
47813
47816
  }
47814
47817
 
47815
47818
  void ExpressionExecutor::Execute(const BoundFunctionExpression &expr, ExpressionState *state,
@@ -64753,6 +64756,19 @@ void CheckForPerfectJoinOpt(LogicalComparisonJoin &op, PerfectHashJoinStats &joi
64753
64756
  return;
64754
64757
  }
64755
64758
 
64759
+ static void CanUseIndexJoin(TableScanBindData *tbl, Expression &expr, Index **result_index) {
64760
+ tbl->table->storage->info->indexes.Scan([&](Index &index) {
64761
+ if (index.unbound_expressions.size() != 1) {
64762
+ return false;
64763
+ }
64764
+ if (expr.alias == index.unbound_expressions[0]->alias) {
64765
+ *result_index = &index;
64766
+ return true;
64767
+ }
64768
+ return false;
64769
+ });
64770
+ }
64771
+
64756
64772
  void TransformIndexJoin(ClientContext &context, LogicalComparisonJoin &op, Index **left_index, Index **right_index,
64757
64773
  PhysicalOperator *left, PhysicalOperator *right) {
64758
64774
  auto &transaction = Transaction::GetTransaction(context);
@@ -64764,26 +64780,14 @@ void TransformIndexJoin(ClientContext &context, LogicalComparisonJoin &op, Index
64764
64780
  auto &tbl_scan = (PhysicalTableScan &)*left;
64765
64781
  auto tbl = dynamic_cast<TableScanBindData *>(tbl_scan.bind_data.get());
64766
64782
  if (CanPlanIndexJoin(transaction, tbl, tbl_scan)) {
64767
- tbl->table->storage->info->indexes.Scan([&](Index &index) {
64768
- if (index.unbound_expressions[0]->alias == op.conditions[0].left->alias) {
64769
- *left_index = &index;
64770
- return true;
64771
- }
64772
- return false;
64773
- });
64783
+ CanUseIndexJoin(tbl, *op.conditions[0].left, left_index);
64774
64784
  }
64775
64785
  }
64776
64786
  if (right->type == PhysicalOperatorType::TABLE_SCAN) {
64777
64787
  auto &tbl_scan = (PhysicalTableScan &)*right;
64778
64788
  auto tbl = dynamic_cast<TableScanBindData *>(tbl_scan.bind_data.get());
64779
64789
  if (CanPlanIndexJoin(transaction, tbl, tbl_scan)) {
64780
- tbl->table->storage->info->indexes.Scan([&](Index &index) {
64781
- if (index.unbound_expressions[0]->alias == op.conditions[0].right->alias) {
64782
- *right_index = &index;
64783
- return true;
64784
- }
64785
- return false;
64786
- });
64790
+ CanUseIndexJoin(tbl, *op.conditions[0].right, right_index);
64787
64791
  }
64788
64792
  }
64789
64793
  }
@@ -80388,20 +80392,20 @@ template <class OP>
80388
80392
  static void RegisterLeastGreatest(BuiltinFunctions &set, const string &fun_name) {
80389
80393
  ScalarFunctionSet fun_set(fun_name);
80390
80394
  fun_set.AddFunction(ScalarFunction({LogicalType::DATE}, LogicalType::DATE, LeastGreatestFunction<date_t, OP>, false,
80391
- nullptr, nullptr, nullptr, LogicalType::DATE));
80395
+ nullptr, nullptr, nullptr, nullptr, LogicalType::DATE));
80392
80396
  fun_set.AddFunction(ScalarFunction({LogicalType::TIMESTAMP}, LogicalType::TIMESTAMP,
80393
80397
  LeastGreatestFunction<timestamp_t, OP>, false, nullptr, nullptr, nullptr,
80394
- LogicalType::TIMESTAMP));
80398
+ nullptr, LogicalType::TIMESTAMP));
80395
80399
  fun_set.AddFunction(ScalarFunction({LogicalType::BIGINT}, LogicalType::BIGINT, LeastGreatestFunction<int64_t, OP>,
80396
- false, nullptr, nullptr, nullptr, LogicalType::BIGINT));
80400
+ false, nullptr, nullptr, nullptr, nullptr, LogicalType::BIGINT));
80397
80401
  fun_set.AddFunction(ScalarFunction({LogicalType::HUGEINT}, LogicalType::HUGEINT,
80398
- LeastGreatestFunction<hugeint_t, OP>, false, nullptr, nullptr, nullptr,
80402
+ LeastGreatestFunction<hugeint_t, OP>, false, nullptr, nullptr, nullptr, nullptr,
80399
80403
  LogicalType::HUGEINT));
80400
80404
  fun_set.AddFunction(ScalarFunction({LogicalType::DOUBLE}, LogicalType::DOUBLE, LeastGreatestFunction<double, OP>,
80401
- false, nullptr, nullptr, nullptr, LogicalType::DOUBLE));
80405
+ false, nullptr, nullptr, nullptr, nullptr, LogicalType::DOUBLE));
80402
80406
  fun_set.AddFunction(ScalarFunction({LogicalType::VARCHAR}, LogicalType::VARCHAR,
80403
80407
  LeastGreatestFunction<string_t, OP, true>, false, nullptr, nullptr, nullptr,
80404
- LogicalType::VARCHAR));
80408
+ nullptr, LogicalType::VARCHAR));
80405
80409
  set.AddFunction(fun_set);
80406
80410
  }
80407
80411
 
@@ -87958,7 +87962,7 @@ struct RegexpMatchesBindData : public FunctionData {
87958
87962
 
87959
87963
  duckdb_re2::RE2::Options options;
87960
87964
  string constant_string;
87961
- std::unique_ptr<duckdb_re2::RE2> constant_pattern;
87965
+ bool constant_pattern;
87962
87966
  string range_min;
87963
87967
  string range_max;
87964
87968
  bool range_success;
@@ -87980,13 +87984,14 @@ namespace duckdb {
87980
87984
 
87981
87985
  RegexpMatchesBindData::RegexpMatchesBindData(duckdb_re2::RE2::Options options, string constant_string_p)
87982
87986
  : options(options), constant_string(move(constant_string_p)) {
87983
- if (!constant_string.empty()) {
87984
- constant_pattern = make_unique<RE2>(constant_string, options);
87985
- if (!constant_pattern->ok()) {
87986
- throw Exception(constant_pattern->error());
87987
+ constant_pattern = !constant_string.empty();
87988
+ if (constant_pattern) {
87989
+ auto pattern = make_unique<RE2>(constant_string, options);
87990
+ if (!pattern->ok()) {
87991
+ throw Exception(pattern->error());
87987
87992
  }
87988
87993
 
87989
- range_success = constant_pattern->PossibleMatchRange(&range_min, &range_max, 1000);
87994
+ range_success = pattern->PossibleMatchRange(&range_min, &range_max, 1000);
87990
87995
  } else {
87991
87996
  range_success = false;
87992
87997
  }
@@ -88055,6 +88060,24 @@ struct RegexFullMatch {
88055
88060
  }
88056
88061
  };
88057
88062
 
88063
+ struct RegexLocalState : public FunctionData {
88064
+ explicit RegexLocalState(RegexpMatchesBindData &info)
88065
+ : constant_pattern(duckdb_re2::StringPiece(info.constant_string.c_str(), info.constant_string.size()),
88066
+ info.options) {
88067
+ D_ASSERT(info.constant_pattern);
88068
+ }
88069
+
88070
+ RE2 constant_pattern;
88071
+ };
88072
+
88073
+ static unique_ptr<FunctionData> RegexInitLocalState(const BoundFunctionExpression &expr, FunctionData *bind_data) {
88074
+ auto &info = (RegexpMatchesBindData &)*bind_data;
88075
+ if (info.constant_pattern) {
88076
+ return make_unique<RegexLocalState>(info);
88077
+ }
88078
+ return nullptr;
88079
+ }
88080
+
88058
88081
  template <class OP>
88059
88082
  static void RegexpMatchesFunction(DataChunk &args, ExpressionState &state, Vector &result) {
88060
88083
  auto &strings = args.data[0];
@@ -88064,8 +88087,9 @@ static void RegexpMatchesFunction(DataChunk &args, ExpressionState &state, Vecto
88064
88087
  auto &info = (RegexpMatchesBindData &)*func_expr.bind_info;
88065
88088
 
88066
88089
  if (info.constant_pattern) {
88090
+ auto &lstate = (RegexLocalState &)*ExecuteFunctionState::GetFunctionState(state);
88067
88091
  UnaryExecutor::Execute<string_t, bool>(strings, result, args.size(), [&](string_t input) {
88068
- return OP::Operation(CreateStringPiece(input), *info.constant_pattern);
88092
+ return OP::Operation(CreateStringPiece(input), lstate.constant_pattern);
88069
88093
  });
88070
88094
  } else {
88071
88095
  BinaryExecutor::Execute<string_t, string_t, bool>(strings, patterns, result, args.size(),
@@ -88152,18 +88176,19 @@ static unique_ptr<FunctionData> RegexReplaceBind(ClientContext &context, ScalarF
88152
88176
  void RegexpFun::RegisterFunction(BuiltinFunctions &set) {
88153
88177
  ScalarFunctionSet regexp_full_match("regexp_full_match");
88154
88178
  regexp_full_match.AddFunction(ScalarFunction({LogicalType::VARCHAR, LogicalType::VARCHAR}, LogicalType::BOOLEAN,
88155
- RegexpMatchesFunction<RegexFullMatch>, false, RegexpMatchesBind));
88179
+ RegexpMatchesFunction<RegexFullMatch>, false, RegexpMatchesBind,
88180
+ nullptr, nullptr, RegexInitLocalState));
88156
88181
  regexp_full_match.AddFunction(ScalarFunction({LogicalType::VARCHAR, LogicalType::VARCHAR, LogicalType::VARCHAR},
88157
88182
  LogicalType::BOOLEAN, RegexpMatchesFunction<RegexFullMatch>, false,
88158
- RegexpMatchesBind));
88183
+ RegexpMatchesBind, nullptr, nullptr, RegexInitLocalState));
88159
88184
 
88160
88185
  ScalarFunctionSet regexp_partial_match("regexp_matches");
88161
88186
  regexp_partial_match.AddFunction(ScalarFunction({LogicalType::VARCHAR, LogicalType::VARCHAR}, LogicalType::BOOLEAN,
88162
- RegexpMatchesFunction<RegexPartialMatch>, false,
88163
- RegexpMatchesBind));
88187
+ RegexpMatchesFunction<RegexPartialMatch>, false, RegexpMatchesBind,
88188
+ nullptr, nullptr, RegexInitLocalState));
88164
88189
  regexp_partial_match.AddFunction(ScalarFunction({LogicalType::VARCHAR, LogicalType::VARCHAR, LogicalType::VARCHAR},
88165
88190
  LogicalType::BOOLEAN, RegexpMatchesFunction<RegexPartialMatch>,
88166
- false, RegexpMatchesBind));
88191
+ false, RegexpMatchesBind, nullptr, nullptr, RegexInitLocalState));
88167
88192
 
88168
88193
  ScalarFunctionSet regexp_replace("regexp_replace");
88169
88194
  regexp_replace.AddFunction(ScalarFunction({LogicalType::VARCHAR, LogicalType::VARCHAR, LogicalType::VARCHAR},
@@ -129706,8 +129731,7 @@ SetScope ToSetScope(duckdb_libpgquery::VariableSetScope pg_scope) {
129706
129731
  case duckdb_libpgquery::VariableSetScope::VAR_SET_SCOPE_GLOBAL:
129707
129732
  return SetScope::GLOBAL;
129708
129733
  case duckdb_libpgquery::VariableSetScope::VAR_SET_SCOPE_DEFAULT:
129709
- // FIXME: This should be SESSION. See https://github.com/duckdb/duckdb/pull/2247
129710
- return SetScope::GLOBAL;
129734
+ return SetScope::SESSION;
129711
129735
  default:
129712
129736
  throw InternalException("Unexpected pg_scope: %d", pg_scope);
129713
129737
  }
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 "b6fb72563"
14
- #define DUCKDB_VERSION "0.2.10-dev360"
13
+ #define DUCKDB_SOURCE_ID "cd0b53211"
14
+ #define DUCKDB_VERSION "0.2.10-dev441"
15
15
  //===----------------------------------------------------------------------===//
16
16
  // DuckDB
17
17
  //
@@ -5014,40 +5014,6 @@ private:
5014
5014
  } // namespace duckdb
5015
5015
 
5016
5016
 
5017
-
5018
- namespace duckdb {
5019
- class Expression;
5020
- class ExpressionExecutor;
5021
- struct ExpressionExecutorState;
5022
-
5023
- struct ExpressionState {
5024
- ExpressionState(const Expression &expr, ExpressionExecutorState &root);
5025
- virtual ~ExpressionState() {
5026
- }
5027
-
5028
- const Expression &expr;
5029
- ExpressionExecutorState &root;
5030
- vector<unique_ptr<ExpressionState>> child_states;
5031
- vector<LogicalType> types;
5032
- DataChunk intermediate_chunk;
5033
- string name;
5034
- CycleCounter profiler;
5035
-
5036
- public:
5037
- void AddChild(Expression *expr);
5038
- void Finalize();
5039
- };
5040
-
5041
- struct ExpressionExecutorState {
5042
- explicit ExpressionExecutorState(const string &name);
5043
- unique_ptr<ExpressionState> root_state;
5044
- ExpressionExecutor *executor;
5045
- CycleCounter profiler;
5046
- string name;
5047
- };
5048
-
5049
- } // namespace duckdb
5050
-
5051
5017
  //===----------------------------------------------------------------------===//
5052
5018
  // DuckDB
5053
5019
  //
@@ -5711,6 +5677,53 @@ private:
5711
5677
 
5712
5678
  } // namespace duckdb
5713
5679
 
5680
+
5681
+ namespace duckdb {
5682
+ class Expression;
5683
+ class ExpressionExecutor;
5684
+ struct ExpressionExecutorState;
5685
+
5686
+ struct ExpressionState {
5687
+ ExpressionState(const Expression &expr, ExpressionExecutorState &root);
5688
+ virtual ~ExpressionState() {
5689
+ }
5690
+
5691
+ const Expression &expr;
5692
+ ExpressionExecutorState &root;
5693
+ vector<unique_ptr<ExpressionState>> child_states;
5694
+ vector<LogicalType> types;
5695
+ DataChunk intermediate_chunk;
5696
+ string name;
5697
+ CycleCounter profiler;
5698
+
5699
+ public:
5700
+ void AddChild(Expression *expr);
5701
+ void Finalize();
5702
+ };
5703
+
5704
+ struct ExecuteFunctionState : public ExpressionState {
5705
+ ExecuteFunctionState(const Expression &expr, ExpressionExecutorState &root) : ExpressionState(expr, root) {
5706
+ }
5707
+
5708
+ unique_ptr<FunctionData> local_state;
5709
+
5710
+ public:
5711
+ static FunctionData *GetFunctionState(ExpressionState &state) {
5712
+ return ((ExecuteFunctionState &)state).local_state.get();
5713
+ }
5714
+ };
5715
+
5716
+ struct ExpressionExecutorState {
5717
+ explicit ExpressionExecutorState(const string &name);
5718
+ unique_ptr<ExpressionState> root_state;
5719
+ ExpressionExecutor *executor;
5720
+ CycleCounter profiler;
5721
+ string name;
5722
+ };
5723
+
5724
+ } // namespace duckdb
5725
+
5726
+
5714
5727
  //===----------------------------------------------------------------------===//
5715
5728
  // DuckDB
5716
5729
  //
@@ -6296,6 +6309,7 @@ typedef std::function<void(DataChunk &, ExpressionState &, Vector &)> scalar_fun
6296
6309
  //! Binds the scalar function and creates the function data
6297
6310
  typedef unique_ptr<FunctionData> (*bind_scalar_function_t)(ClientContext &context, ScalarFunction &bound_function,
6298
6311
  vector<unique_ptr<Expression>> &arguments);
6312
+ typedef unique_ptr<FunctionData> (*init_local_state_t)(const BoundFunctionExpression &expr, FunctionData *bind_data);
6299
6313
  typedef unique_ptr<BaseStatistics> (*function_statistics_t)(ClientContext &context, BoundFunctionExpression &expr,
6300
6314
  FunctionData *bind_data,
6301
6315
  vector<unique_ptr<BaseStatistics>> &child_stats);
@@ -6307,23 +6321,27 @@ public:
6307
6321
  ScalarFunction(string name, vector<LogicalType> arguments, LogicalType return_type, scalar_function_t function,
6308
6322
  bool has_side_effects = false, bind_scalar_function_t bind = nullptr,
6309
6323
  dependency_function_t dependency = nullptr, function_statistics_t statistics = nullptr,
6324
+ init_local_state_t init_local_state = nullptr,
6310
6325
  LogicalType varargs = LogicalType(LogicalTypeId::INVALID))
6311
6326
  : BaseScalarFunction(name, arguments, return_type, has_side_effects, varargs), function(function), bind(bind),
6312
- dependency(dependency), statistics(statistics) {
6327
+ init_local_state(init_local_state), dependency(dependency), statistics(statistics) {
6313
6328
  }
6314
6329
 
6315
6330
  ScalarFunction(vector<LogicalType> arguments, LogicalType return_type, scalar_function_t function,
6316
6331
  bool has_side_effects = false, bind_scalar_function_t bind = nullptr,
6317
6332
  dependency_function_t dependency = nullptr, function_statistics_t statistics = nullptr,
6333
+ init_local_state_t init_local_state = nullptr,
6318
6334
  LogicalType varargs = LogicalType(LogicalTypeId::INVALID))
6319
6335
  : ScalarFunction(string(), arguments, return_type, function, has_side_effects, bind, dependency, statistics,
6320
- varargs) {
6336
+ init_local_state, varargs) {
6321
6337
  }
6322
6338
 
6323
6339
  //! The main scalar function to execute
6324
6340
  scalar_function_t function;
6325
6341
  //! The bind function (if any)
6326
6342
  bind_scalar_function_t bind;
6343
+ //! Init thread local state for the function (if any)
6344
+ init_local_state_t init_local_state;
6327
6345
  // The dependency function (if any)
6328
6346
  dependency_function_t dependency;
6329
6347
  //! The statistics propagation function (if any)