duckdb 0.3.2-dev1302.0 → 0.3.2-dev1312.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-dev1302.0",
4
+ "version": "0.3.2-dev1312.0",
5
5
  "description": "DuckDB node.js API",
6
6
  "gypfile": true,
7
7
  "dependencies": {
package/src/duckdb.cpp CHANGED
@@ -80656,17 +80656,11 @@ static void ArraySliceFunction(DataChunk &args, ExpressionState &state, Vector &
80656
80656
  D_ASSERT(args.data.size() == 3);
80657
80657
  auto count = args.size();
80658
80658
 
80659
- result.SetVectorType(VectorType::CONSTANT_VECTOR);
80660
- for (idx_t i = 0; i < args.ColumnCount(); i++) {
80661
- if (args.data[i].GetVectorType() != VectorType::CONSTANT_VECTOR) {
80662
- result.SetVectorType(VectorType::FLAT_VECTOR);
80663
- }
80664
- }
80665
-
80666
80659
  Vector &s = args.data[0];
80667
80660
  Vector &b = args.data[1];
80668
80661
  Vector &e = args.data[2];
80669
80662
 
80663
+ s.Normalify(count);
80670
80664
  switch (result.GetType().id()) {
80671
80665
  case LogicalTypeId::LIST:
80672
80666
  // Share the value dictionary as we are just going to slice it
@@ -80679,6 +80673,14 @@ static void ArraySliceFunction(DataChunk &args, ExpressionState &state, Vector &
80679
80673
  default:
80680
80674
  throw NotImplementedException("Specifier type not implemented");
80681
80675
  }
80676
+
80677
+ result.SetVectorType(VectorType::CONSTANT_VECTOR);
80678
+ for (idx_t i = 0; i < args.ColumnCount(); i++) {
80679
+ if (args.data[i].GetVectorType() != VectorType::CONSTANT_VECTOR) {
80680
+ result.SetVectorType(VectorType::FLAT_VECTOR);
80681
+ break;
80682
+ }
80683
+ }
80682
80684
  }
80683
80685
 
80684
80686
  static unique_ptr<FunctionData> ArraySliceBind(ClientContext &context, ScalarFunction &bound_function,
@@ -121268,6 +121270,10 @@ unique_ptr<NodeStatistics> StatisticsPropagator::PropagateStatistics(LogicalCros
121268
121270
 
121269
121271
  namespace duckdb {
121270
121272
 
121273
+ static bool IsCompareDistinct(ExpressionType type) {
121274
+ return type == ExpressionType::COMPARE_DISTINCT_FROM || type == ExpressionType::COMPARE_NOT_DISTINCT_FROM;
121275
+ }
121276
+
121271
121277
  bool StatisticsPropagator::ExpressionIsConstant(Expression &expr, const Value &val) {
121272
121278
  if (expr.GetExpressionClass() != ExpressionClass::BOUND_CONSTANT) {
121273
121279
  return false;
@@ -121295,8 +121301,10 @@ void StatisticsPropagator::SetStatisticsNotNull(ColumnBinding binding) {
121295
121301
 
121296
121302
  void StatisticsPropagator::UpdateFilterStatistics(BaseStatistics &stats, ExpressionType comparison_type,
121297
121303
  const Value &constant) {
121298
- // any comparison filter removes all null values
121299
- stats.validity_stats = make_unique<ValidityStatistics>(false);
121304
+ // regular comparisons removes all null values
121305
+ if (!IsCompareDistinct(comparison_type)) {
121306
+ stats.validity_stats = make_unique<ValidityStatistics>(false);
121307
+ }
121300
121308
  if (!stats.type.IsNumeric()) {
121301
121309
  // don't handle non-numeric columns here (yet)
121302
121310
  return;
@@ -121332,9 +121340,11 @@ void StatisticsPropagator::UpdateFilterStatistics(BaseStatistics &stats, Express
121332
121340
 
121333
121341
  void StatisticsPropagator::UpdateFilterStatistics(BaseStatistics &lstats, BaseStatistics &rstats,
121334
121342
  ExpressionType comparison_type) {
121335
- // any comparison filter removes all null values
121336
- lstats.validity_stats = make_unique<ValidityStatistics>(false);
121337
- rstats.validity_stats = make_unique<ValidityStatistics>(false);
121343
+ // regular comparisons removes all null values
121344
+ if (!IsCompareDistinct(comparison_type)) {
121345
+ lstats.validity_stats = make_unique<ValidityStatistics>(false);
121346
+ rstats.validity_stats = make_unique<ValidityStatistics>(false);
121347
+ }
121338
121348
  D_ASSERT(lstats.type == rstats.type);
121339
121349
  if (!lstats.type.IsNumeric()) {
121340
121350
  // don't handle non-numeric columns here (yet)
@@ -121380,6 +121390,7 @@ void StatisticsPropagator::UpdateFilterStatistics(BaseStatistics &lstats, BaseSt
121380
121390
  }
121381
121391
  break;
121382
121392
  case ExpressionType::COMPARE_EQUAL:
121393
+ case ExpressionType::COMPARE_NOT_DISTINCT_FROM:
121383
121394
  // LEFT = RIGHT
121384
121395
  // only the tightest bounds pass
121385
121396
  // so if we have e.g. left = [-50, 250] and right = [-100, 100]
@@ -121405,10 +121416,11 @@ void StatisticsPropagator::UpdateFilterStatistics(BaseStatistics &lstats, BaseSt
121405
121416
  void StatisticsPropagator::UpdateFilterStatistics(Expression &left, Expression &right, ExpressionType comparison_type) {
121406
121417
  // first check if either side is a bound column ref
121407
121418
  // any column ref involved in a comparison will not be null after the comparison
121408
- if (left.type == ExpressionType::BOUND_COLUMN_REF) {
121419
+ bool compare_distinct = IsCompareDistinct(comparison_type);
121420
+ if (!compare_distinct && left.type == ExpressionType::BOUND_COLUMN_REF) {
121409
121421
  SetStatisticsNotNull(((BoundColumnRefExpression &)left).binding);
121410
121422
  }
121411
- if (right.type == ExpressionType::BOUND_COLUMN_REF) {
121423
+ if (!compare_distinct && right.type == ExpressionType::BOUND_COLUMN_REF) {
121412
121424
  SetStatisticsNotNull(((BoundColumnRefExpression &)right).binding);
121413
121425
  }
121414
121426
  // check if this is a comparison between a constant and a column ref
@@ -153545,8 +153557,9 @@ unique_ptr<LogicalOperator> FlattenDependentJoins::PushDownDependentJoinInternal
153545
153557
  join->children.push_back(move(plan->children[1]));
153546
153558
  return move(join);
153547
153559
  }
153560
+ case LogicalOperatorType::LOGICAL_ANY_JOIN:
153548
153561
  case LogicalOperatorType::LOGICAL_COMPARISON_JOIN: {
153549
- auto &join = (LogicalComparisonJoin &)*plan;
153562
+ auto &join = (LogicalJoin &)*plan;
153550
153563
  D_ASSERT(plan->children.size() == 2);
153551
153564
  // check the correlated expressions in the children of the join
153552
153565
  bool left_has_correlation = has_correlated_expressions.find(plan->children[0].get())->second;
@@ -153571,6 +153584,13 @@ unique_ptr<LogicalOperator> FlattenDependentJoins::PushDownDependentJoinInternal
153571
153584
  plan->children[0] = PushDownDependentJoinInternal(move(plan->children[0]));
153572
153585
  return plan;
153573
153586
  }
153587
+ } else if (join.join_type == JoinType::RIGHT) {
153588
+ // left outer join
153589
+ if (!left_has_correlation) {
153590
+ // only right has correlation: push into right
153591
+ plan->children[1] = PushDownDependentJoinInternal(move(plan->children[1]));
153592
+ return plan;
153593
+ }
153574
153594
  } else if (join.join_type == JoinType::MARK) {
153575
153595
  if (right_has_correlation) {
153576
153596
  throw Exception("MARK join with correlation in RHS not supported");
@@ -153586,27 +153606,42 @@ unique_ptr<LogicalOperator> FlattenDependentJoins::PushDownDependentJoinInternal
153586
153606
  }
153587
153607
  // both sides have correlation
153588
153608
  // push into both sides
153589
- // NOTE: for OUTER JOINS it matters what the BASE BINDING is after the join
153590
- // for the LEFT OUTER JOIN, we want the LEFT side to be the base binding after we push
153591
- // because the RIGHT binding might contain NULL values
153592
153609
  plan->children[0] = PushDownDependentJoinInternal(move(plan->children[0]));
153593
153610
  auto left_binding = this->base_binding;
153594
153611
  plan->children[1] = PushDownDependentJoinInternal(move(plan->children[1]));
153595
153612
  auto right_binding = this->base_binding;
153613
+ // NOTE: for OUTER JOINS it matters what the BASE BINDING is after the join
153614
+ // for the LEFT OUTER JOIN, we want the LEFT side to be the base binding after we push
153615
+ // because the RIGHT binding might contain NULL values
153596
153616
  if (join.join_type == JoinType::LEFT) {
153597
153617
  this->base_binding = left_binding;
153618
+ } else if (join.join_type == JoinType::RIGHT) {
153619
+ this->base_binding = right_binding;
153598
153620
  }
153599
153621
  // add the correlated columns to the join conditions
153600
153622
  for (idx_t i = 0; i < correlated_columns.size(); i++) {
153601
- JoinCondition cond;
153602
-
153603
- cond.left = make_unique<BoundColumnRefExpression>(
153623
+ auto left = make_unique<BoundColumnRefExpression>(
153604
153624
  correlated_columns[i].type, ColumnBinding(left_binding.table_index, left_binding.column_index + i));
153605
- cond.right = make_unique<BoundColumnRefExpression>(
153625
+ auto right = make_unique<BoundColumnRefExpression>(
153606
153626
  correlated_columns[i].type, ColumnBinding(right_binding.table_index, right_binding.column_index + i));
153607
- cond.comparison = ExpressionType::COMPARE_EQUAL;
153608
- cond.null_values_are_equal = true;
153609
- join.conditions.push_back(move(cond));
153627
+
153628
+ if (join.type == LogicalOperatorType::LOGICAL_COMPARISON_JOIN) {
153629
+ JoinCondition cond;
153630
+ cond.left = move(left);
153631
+ cond.right = move(right);
153632
+ cond.comparison = ExpressionType::COMPARE_EQUAL;
153633
+ cond.null_values_are_equal = true;
153634
+
153635
+ auto &comparison_join = (LogicalComparisonJoin &)join;
153636
+ comparison_join.conditions.push_back(move(cond));
153637
+ } else {
153638
+ auto &any_join = (LogicalAnyJoin &)join;
153639
+ auto comparison = make_unique<BoundComparisonExpression>(ExpressionType::COMPARE_NOT_DISTINCT_FROM,
153640
+ move(left), move(right));
153641
+ auto conjunction = make_unique<BoundConjunctionExpression>(ExpressionType::CONJUNCTION_AND,
153642
+ move(comparison), move(any_join.condition));
153643
+ any_join.condition = move(conjunction);
153644
+ }
153610
153645
  }
153611
153646
  // then we replace any correlated expressions with the corresponding entry in the correlated_map
153612
153647
  RewriteCorrelatedExpressions rewriter(right_binding, correlated_map);
@@ -222811,12 +222846,17 @@ static void allocate_new(parser_state *state, size_t n) {
222811
222846
 
222812
222847
  void *palloc(size_t n) {
222813
222848
  // we need to align our pointers for the sanitizer
222814
- auto aligned_n = ((n + 7) / 8) * 8;
222849
+ auto allocate_n = n + sizeof(size_t);
222850
+ auto aligned_n = ((allocate_n + 7) / 8) * 8;
222815
222851
  if (pg_parser_state.malloc_pos + aligned_n > PG_MALLOC_SIZE) {
222816
222852
  allocate_new(&pg_parser_state, aligned_n);
222817
222853
  }
222818
222854
 
222819
- void *ptr = pg_parser_state.malloc_ptrs[pg_parser_state.malloc_ptr_idx - 1] + pg_parser_state.malloc_pos;
222855
+ // store the length of the allocation
222856
+ char *base_ptr = pg_parser_state.malloc_ptrs[pg_parser_state.malloc_ptr_idx - 1] + pg_parser_state.malloc_pos;
222857
+ memcpy(base_ptr, &n, sizeof(size_t));
222858
+ // store the actual pointer
222859
+ char *ptr = (char*) base_ptr + sizeof(size_t);
222820
222860
  memset(ptr, 0, n);
222821
222861
  pg_parser_state.malloc_pos += aligned_n;
222822
222862
  return ptr;
@@ -222929,7 +222969,14 @@ void *palloc0fast(size_t n) { // very fast
222929
222969
  return palloc(n);
222930
222970
  }
222931
222971
  void *repalloc(void *ptr, size_t n) {
222932
- return palloc(n);
222972
+ // get the length of the allocation
222973
+ size_t old_len;
222974
+ char *old_len_ptr = (char *) ptr - sizeof(size_t);
222975
+ memcpy((void *) &old_len, old_len_ptr, sizeof(size_t));
222976
+ // re-allocate and copy the data
222977
+ void *new_buf = palloc(n);
222978
+ memcpy(new_buf, ptr, old_len);
222979
+ return new_buf;
222933
222980
  }
222934
222981
  char *NameListToString(PGList *names) {
222935
222982
  throw std::runtime_error("NameListToString NOT IMPLEMENTED");
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 "506b05a10"
15
- #define DUCKDB_VERSION "v0.3.2-dev1302"
14
+ #define DUCKDB_SOURCE_ID "ab13af6cf"
15
+ #define DUCKDB_VERSION "v0.3.2-dev1312"
16
16
  //===----------------------------------------------------------------------===//
17
17
  // DuckDB
18
18
  //