duckdb 0.3.2-dev324.0 → 0.3.2-dev337.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.2-dev324.0",
4
+ "version": "0.3.2-dev337.0",
5
5
  "description": "DuckDB node.js API",
6
6
  "gypfile": true,
7
7
  "dependencies": {
package/src/duckdb.cpp CHANGED
@@ -49529,7 +49529,9 @@ idx_t GroupedAggregateHashTable::Scan(idx_t &scan_position, DataChunk &result) {
49529
49529
  }
49530
49530
 
49531
49531
  void GroupedAggregateHashTable::Finalize() {
49532
- D_ASSERT(!is_finalized);
49532
+ if (is_finalized) {
49533
+ return;
49534
+ }
49533
49535
 
49534
49536
  // early release hashes, not needed for partition/scan
49535
49537
  hashes_hdl.reset();
@@ -65967,18 +65969,11 @@ public:
65967
65969
  vector<vector<unique_ptr<Expression>>> expressions;
65968
65970
 
65969
65971
  public:
65970
- unique_ptr<GlobalSourceState> GetGlobalSourceState(ClientContext &context) const override;
65971
- void GetData(ExecutionContext &context, DataChunk &chunk, GlobalSourceState &gstate,
65972
- LocalSourceState &lstate) const override;
65973
-
65974
- public:
65975
- // Sink interface
65976
- SinkResultType Sink(ExecutionContext &context, GlobalSinkState &gstate, LocalSinkState &lstate,
65977
- DataChunk &input) const override;
65978
-
65979
- unique_ptr<GlobalSinkState> GetGlobalSinkState(ClientContext &context) const override;
65972
+ unique_ptr<OperatorState> GetOperatorState(ClientContext &context) const override;
65973
+ OperatorResultType Execute(ExecutionContext &context, DataChunk &input, DataChunk &chunk,
65974
+ OperatorState &state) const override;
65980
65975
 
65981
- bool IsSink() const override {
65976
+ bool ParallelOperator() const override {
65982
65977
  return true;
65983
65978
  }
65984
65979
 
@@ -65994,7 +65989,7 @@ public:
65994
65989
 
65995
65990
  namespace duckdb {
65996
65991
 
65997
- class ExpressionScanState : public GlobalSourceState {
65992
+ class ExpressionScanState : public OperatorState {
65998
65993
  public:
65999
65994
  explicit ExpressionScanState(const PhysicalExpressionScan &op) : expression_index(0) {
66000
65995
  temp_chunk.Initialize(op.GetTypes());
@@ -66006,16 +66001,26 @@ public:
66006
66001
  DataChunk temp_chunk;
66007
66002
  };
66008
66003
 
66009
- class ExpressionSinkState : public GlobalSinkState {
66010
- public:
66011
- ExpressionSinkState() {
66012
- }
66004
+ unique_ptr<OperatorState> PhysicalExpressionScan::GetOperatorState(ClientContext &context) const {
66005
+ return make_unique<ExpressionScanState>(*this);
66006
+ }
66013
66007
 
66014
- DataChunk child_chunk;
66015
- };
66008
+ OperatorResultType PhysicalExpressionScan::Execute(ExecutionContext &context, DataChunk &input, DataChunk &chunk,
66009
+ OperatorState &state_p) const {
66010
+ auto &state = (ExpressionScanState &)state_p;
66016
66011
 
66017
- unique_ptr<GlobalSourceState> PhysicalExpressionScan::GetGlobalSourceState(ClientContext &context) const {
66018
- return make_unique<ExpressionScanState>(*this);
66012
+ for (; chunk.size() + input.size() <= STANDARD_VECTOR_SIZE && state.expression_index < expressions.size();
66013
+ state.expression_index++) {
66014
+ state.temp_chunk.Reset();
66015
+ EvaluateExpression(state.expression_index, &input, state.temp_chunk);
66016
+ chunk.Append(state.temp_chunk);
66017
+ }
66018
+ if (state.expression_index < expressions.size()) {
66019
+ return OperatorResultType::HAVE_MORE_OUTPUT;
66020
+ } else {
66021
+ state.expression_index = 0;
66022
+ return OperatorResultType::NEED_MORE_INPUT;
66023
+ }
66019
66024
  }
66020
66025
 
66021
66026
  void PhysicalExpressionScan::EvaluateExpression(idx_t expression_idx, DataChunk *child_chunk, DataChunk &result) const {
@@ -66028,20 +66033,6 @@ void PhysicalExpressionScan::EvaluateExpression(idx_t expression_idx, DataChunk
66028
66033
  }
66029
66034
  }
66030
66035
 
66031
- void PhysicalExpressionScan::GetData(ExecutionContext &context, DataChunk &chunk, GlobalSourceState &gstate_p,
66032
- LocalSourceState &lstate) const {
66033
- D_ASSERT(sink_state);
66034
- auto &state = (ExpressionScanState &)gstate_p;
66035
- auto &gstate = (ExpressionSinkState &)*sink_state;
66036
-
66037
- for (; chunk.size() < STANDARD_VECTOR_SIZE && state.expression_index < expressions.size();
66038
- state.expression_index++) {
66039
- state.temp_chunk.Reset();
66040
- EvaluateExpression(state.expression_index, &gstate.child_chunk, state.temp_chunk);
66041
- chunk.Append(state.temp_chunk);
66042
- }
66043
- }
66044
-
66045
66036
  bool PhysicalExpressionScan::IsFoldable() const {
66046
66037
  for (auto &expr_list : expressions) {
66047
66038
  for (auto &expr : expr_list) {
@@ -66053,24 +66044,6 @@ bool PhysicalExpressionScan::IsFoldable() const {
66053
66044
  return true;
66054
66045
  }
66055
66046
 
66056
- SinkResultType PhysicalExpressionScan::Sink(ExecutionContext &context, GlobalSinkState &gstate_p,
66057
- LocalSinkState &lstate, DataChunk &input) const {
66058
- auto &gstate = (ExpressionSinkState &)gstate_p;
66059
-
66060
- D_ASSERT(children.size() == 1);
66061
- D_ASSERT(gstate.child_chunk.size() == 0);
66062
- if (input.size() != 1) {
66063
- throw InternalException("Expected expression scan child to have exactly one element");
66064
- }
66065
- gstate.child_chunk.Move(input);
66066
- gstate.child_chunk.Verify();
66067
- return SinkResultType::FINISHED;
66068
- }
66069
-
66070
- unique_ptr<GlobalSinkState> PhysicalExpressionScan::GetGlobalSinkState(ClientContext &context) const {
66071
- return make_unique<ExpressionSinkState>();
66072
- }
66073
-
66074
66047
  } // namespace duckdb
66075
66048
 
66076
66049
 
@@ -84826,14 +84799,7 @@ static void LeastGreatestFunction(DataChunk &args, ExpressionState &state, Vecto
84826
84799
  }
84827
84800
  auto result_type = VectorType::CONSTANT_VECTOR;
84828
84801
  for (idx_t col_idx = 0; col_idx < args.ColumnCount(); col_idx++) {
84829
- if (args.data[col_idx].GetVectorType() == VectorType::CONSTANT_VECTOR) {
84830
- if (ConstantVector::IsNull(args.data[col_idx])) {
84831
- // constant NULL: result is constant NULL
84832
- result.SetVectorType(VectorType::CONSTANT_VECTOR);
84833
- ConstantVector::SetNull(result, true);
84834
- return;
84835
- }
84836
- } else {
84802
+ if (args.data[col_idx].GetVectorType() != VectorType::CONSTANT_VECTOR) {
84837
84803
  // non-constant input: result is not a constant vector
84838
84804
  result_type = VectorType::FLAT_VECTOR;
84839
84805
  }
@@ -84843,60 +84809,67 @@ static void LeastGreatestFunction(DataChunk &args, ExpressionState &state, Vecto
84843
84809
  }
84844
84810
  }
84845
84811
 
84846
- // we start off performing a binary operation between the first two inputs, where we store the lowest (or highest)
84847
- // directly in the result
84848
- BinaryExecutor::ExecuteGeneric<T, T, T, BinarySingleArgumentOperatorWrapper, LeastOperator<OP>, bool>(
84849
- args.data[0], args.data[1], result, args.size(), false);
84850
-
84851
- // now we loop over the other columns and compare it to the stored result
84852
84812
  auto result_data = FlatVector::GetData<T>(result);
84853
84813
  auto &result_mask = FlatVector::Validity(result);
84854
- SelectionVector rsel;
84855
- idx_t rcount = 0;
84856
- // create a selection vector from the mask
84857
- rsel.Initialize();
84858
- for (idx_t i = 0; i < args.size(); i++) {
84859
- if (result_mask.RowIsValid(i)) {
84860
- rsel.set_index(rcount++, i);
84814
+ // copy over the first column
84815
+ bool result_has_value[STANDARD_VECTOR_SIZE];
84816
+ {
84817
+ VectorData vdata;
84818
+ args.data[0].Orrify(args.size(), vdata);
84819
+ auto input_data = (T *)vdata.data;
84820
+ for (idx_t i = 0; i < args.size(); i++) {
84821
+ auto vindex = vdata.sel->get_index(i);
84822
+ if (vdata.validity.RowIsValid(vindex)) {
84823
+ result_data[i] = input_data[vindex];
84824
+ result_has_value[i] = true;
84825
+ } else {
84826
+ result_has_value[i] = false;
84827
+ }
84861
84828
  }
84862
84829
  }
84863
- for (idx_t col_idx = 2; col_idx < args.ColumnCount(); col_idx++) {
84830
+ // now handle the remainder of the columns
84831
+ for (idx_t col_idx = 1; col_idx < args.ColumnCount(); col_idx++) {
84832
+ if (args.data[col_idx].GetVectorType() == VectorType::CONSTANT_VECTOR &&
84833
+ ConstantVector::IsNull(args.data[col_idx])) {
84834
+ // ignore null vector
84835
+ continue;
84836
+ }
84837
+
84864
84838
  VectorData vdata;
84865
84839
  args.data[col_idx].Orrify(args.size(), vdata);
84866
84840
 
84867
84841
  auto input_data = (T *)vdata.data;
84868
84842
  if (!vdata.validity.AllValid()) {
84869
84843
  // potential new null entries: have to check the null mask
84870
- idx_t new_count = 0;
84871
- for (idx_t i = 0; i < rcount; i++) {
84872
- auto rindex = rsel.get_index(i);
84873
- auto vindex = vdata.sel->get_index(rindex);
84874
- if (!vdata.validity.RowIsValid(vindex)) {
84875
- // new null entry: set nullmask
84876
- result_mask.SetInvalid(rindex);
84877
- } else {
84844
+ for (idx_t i = 0; i < args.size(); i++) {
84845
+ auto vindex = vdata.sel->get_index(i);
84846
+ if (vdata.validity.RowIsValid(vindex)) {
84878
84847
  // not a null entry: perform the operation and add to new set
84879
84848
  auto ivalue = input_data[vindex];
84880
- if (OP::template Operation<T>(ivalue, result_data[rindex])) {
84881
- result_data[rindex] = ivalue;
84849
+ if (!result_has_value[i] || OP::template Operation<T>(ivalue, result_data[i])) {
84850
+ result_has_value[i] = true;
84851
+ result_data[i] = ivalue;
84882
84852
  }
84883
- rsel.set_index(new_count++, rindex);
84884
84853
  }
84885
84854
  }
84886
- rcount = new_count;
84887
84855
  } else {
84888
84856
  // no new null entries: only need to perform the operation
84889
- for (idx_t i = 0; i < rcount; i++) {
84890
- auto rindex = rsel.get_index(i);
84891
- auto vindex = vdata.sel->get_index(rindex);
84857
+ for (idx_t i = 0; i < args.size(); i++) {
84858
+ auto vindex = vdata.sel->get_index(i);
84892
84859
 
84893
84860
  auto ivalue = input_data[vindex];
84894
- if (OP::template Operation<T>(ivalue, result_data[rindex])) {
84895
- result_data[rindex] = ivalue;
84861
+ if (!result_has_value[i] || OP::template Operation<T>(ivalue, result_data[i])) {
84862
+ result_has_value[i] = true;
84863
+ result_data[i] = ivalue;
84896
84864
  }
84897
84865
  }
84898
84866
  }
84899
84867
  }
84868
+ for (idx_t i = 0; i < args.size(); i++) {
84869
+ if (!result_has_value[i]) {
84870
+ result_mask.SetInvalid(i);
84871
+ }
84872
+ }
84900
84873
  result.SetVectorType(result_type);
84901
84874
  }
84902
84875
 
@@ -126069,7 +126042,6 @@ void Executor::BuildPipelines(PhysicalOperator *op, Pipeline *current) {
126069
126042
  case PhysicalOperatorType::TOP_N:
126070
126043
  case PhysicalOperatorType::COPY_TO_FILE:
126071
126044
  case PhysicalOperatorType::LIMIT:
126072
- case PhysicalOperatorType::EXPRESSION_SCAN:
126073
126045
  case PhysicalOperatorType::EXPLAIN_ANALYZE:
126074
126046
  D_ASSERT(op->children.size() == 1);
126075
126047
  // single operator:
@@ -154822,6 +154794,15 @@ void ExpressionIterator::EnumerateTableRefChildren(BoundTableRef &ref,
154822
154794
  EnumerateTableRefChildren(*bound_crossproduct.right, callback);
154823
154795
  break;
154824
154796
  }
154797
+ case TableReferenceType::EXPRESSION_LIST: {
154798
+ auto &bound_expr_list = (BoundExpressionListRef &)ref;
154799
+ for (auto &expr_list : bound_expr_list.values) {
154800
+ for (auto &expr : expr_list) {
154801
+ EnumerateExpression(expr, callback);
154802
+ }
154803
+ }
154804
+ break;
154805
+ }
154825
154806
  case TableReferenceType::JOIN: {
154826
154807
  auto &bound_join = (BoundJoinRef &)ref;
154827
154808
  EnumerateExpression(bound_join.condition, callback);
@@ -156577,6 +156558,29 @@ unique_ptr<LogicalOperator> FlattenDependentJoins::PushDownDependentJoinInternal
156577
156558
  case LogicalOperatorType::LOGICAL_DISTINCT:
156578
156559
  plan->children[0] = PushDownDependentJoin(move(plan->children[0]));
156579
156560
  return plan;
156561
+ case LogicalOperatorType::LOGICAL_EXPRESSION_GET: {
156562
+ // expression get
156563
+ // first we flatten the dependent join in the child
156564
+ plan->children[0] = PushDownDependentJoinInternal(move(plan->children[0]));
156565
+ // then we replace any correlated expressions with the corresponding entry in the correlated_map
156566
+ RewriteCorrelatedExpressions rewriter(base_binding, correlated_map);
156567
+ rewriter.VisitOperator(*plan);
156568
+ // now we add all the correlated columns to each of the expressions of the expression scan
156569
+ auto expr_get = (LogicalExpressionGet *)plan.get();
156570
+ for (idx_t i = 0; i < correlated_columns.size(); i++) {
156571
+ for (auto &expr_list : expr_get->expressions) {
156572
+ auto colref = make_unique<BoundColumnRefExpression>(
156573
+ correlated_columns[i].type, ColumnBinding(base_binding.table_index, base_binding.column_index + i));
156574
+ expr_list.push_back(move(colref));
156575
+ }
156576
+ expr_get->expr_types.push_back(correlated_columns[i].type);
156577
+ }
156578
+
156579
+ base_binding.table_index = expr_get->table_index;
156580
+ this->delim_offset = base_binding.column_index = expr_get->expr_types.size() - correlated_columns.size();
156581
+ this->data_offset = 0;
156582
+ return plan;
156583
+ }
156580
156584
  case LogicalOperatorType::LOGICAL_ORDER_BY:
156581
156585
  throw ParserException("ORDER BY not supported in correlated subquery");
156582
156586
  default:
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 "5d577b5d9"
14
- #define DUCKDB_VERSION "0.3.2-dev324"
13
+ #define DUCKDB_SOURCE_ID "c69ecbf73"
14
+ #define DUCKDB_VERSION "0.3.2-dev337"
15
15
  //===----------------------------------------------------------------------===//
16
16
  // DuckDB
17
17
  //