duckdb 0.7.2-dev586.0 → 0.7.2-dev654.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.
Files changed (70) hide show
  1. package/package.json +1 -1
  2. package/src/duckdb/extension/icu/icu-table-range.cpp +7 -7
  3. package/src/duckdb/extension/parquet/parquet_reader.cpp +1 -1
  4. package/src/duckdb/src/catalog/catalog_entry/table_catalog_entry.cpp +3 -3
  5. package/src/duckdb/src/catalog/dependency_list.cpp +12 -0
  6. package/src/duckdb/src/common/string_util.cpp +4 -1
  7. package/src/duckdb/src/common/types/blob.cpp +1 -1
  8. package/src/duckdb/src/common/types/chunk_collection.cpp +2 -2
  9. package/src/duckdb/src/common/types/data_chunk.cpp +1 -1
  10. package/src/duckdb/src/common/types/value.cpp +8 -8
  11. package/src/duckdb/src/common/types.cpp +11 -11
  12. package/src/duckdb/src/execution/operator/aggregate/physical_window.cpp +15 -3
  13. package/src/duckdb/src/execution/operator/helper/physical_vacuum.cpp +3 -0
  14. package/src/duckdb/src/execution/operator/join/physical_iejoin.cpp +2 -2
  15. package/src/duckdb/src/execution/operator/join/physical_piecewise_merge_join.cpp +6 -11
  16. package/src/duckdb/src/execution/operator/join/physical_range_join.cpp +1 -1
  17. package/src/duckdb/src/execution/operator/persistent/physical_copy_to_file.cpp +2 -2
  18. package/src/duckdb/src/execution/physical_plan/plan_comparison_join.cpp +3 -0
  19. package/src/duckdb/src/function/aggregate/distributive/bitstring_agg.cpp +22 -7
  20. package/src/duckdb/src/function/aggregate/distributive/first.cpp +1 -0
  21. package/src/duckdb/src/function/aggregate/holistic/approximate_quantile.cpp +5 -2
  22. package/src/duckdb/src/function/aggregate/holistic/quantile.cpp +1 -1
  23. package/src/duckdb/src/function/aggregate/nested/list.cpp +8 -8
  24. package/src/duckdb/src/function/cast/struct_cast.cpp +1 -1
  25. package/src/duckdb/src/function/scalar/date/date_part.cpp +1 -1
  26. package/src/duckdb/src/function/scalar/list/list_concat.cpp +5 -4
  27. package/src/duckdb/src/function/scalar/list/list_lambdas.cpp +3 -3
  28. package/src/duckdb/src/function/scalar/list/list_value.cpp +1 -1
  29. package/src/duckdb/src/function/scalar/map/map_entries.cpp +1 -1
  30. package/src/duckdb/src/function/scalar/struct/struct_insert.cpp +1 -1
  31. package/src/duckdb/src/function/scalar/struct/struct_pack.cpp +1 -1
  32. package/src/duckdb/src/function/table/arrow.cpp +2 -2
  33. package/src/duckdb/src/function/table/checkpoint.cpp +5 -1
  34. package/src/duckdb/src/function/table/system/duckdb_constraints.cpp +2 -2
  35. package/src/duckdb/src/function/table/system/test_all_types.cpp +2 -2
  36. package/src/duckdb/src/function/table/version/pragma_version.cpp +2 -2
  37. package/src/duckdb/src/include/duckdb/catalog/dependency_list.hpp +3 -0
  38. package/src/duckdb/src/include/duckdb/common/types/value.hpp +3 -3
  39. package/src/duckdb/src/include/duckdb/common/types.hpp +3 -3
  40. package/src/duckdb/src/include/duckdb/parser/transformer.hpp +3 -0
  41. package/src/duckdb/src/include/duckdb/storage/statistics/distinct_statistics.hpp +2 -0
  42. package/src/duckdb/src/include/duckdb/storage/table/update_segment.hpp +0 -1
  43. package/src/duckdb/src/main/config.cpp +4 -0
  44. package/src/duckdb/src/optimizer/join_order/cardinality_estimator.cpp +3 -4
  45. package/src/duckdb/src/optimizer/join_order/join_order_optimizer.cpp +5 -3
  46. package/src/duckdb/src/optimizer/pushdown/pushdown_aggregate.cpp +33 -5
  47. package/src/duckdb/src/optimizer/rule/move_constants.cpp +8 -2
  48. package/src/duckdb/src/optimizer/unnest_rewriter.cpp +2 -2
  49. package/src/duckdb/src/parser/expression/conjunction_expression.cpp +2 -0
  50. package/src/duckdb/src/parser/transform/expression/transform_function.cpp +17 -1
  51. package/src/duckdb/src/parser/transform/helpers/transform_typename.cpp +3 -2
  52. package/src/duckdb/src/parser/transform/statement/transform_select_node.cpp +1 -2
  53. package/src/duckdb/src/planner/binder/expression/bind_aggregate_expression.cpp +1 -1
  54. package/src/duckdb/src/planner/binder/expression/bind_columnref_expression.cpp +4 -3
  55. package/src/duckdb/src/planner/binder/query_node/bind_select_node.cpp +25 -13
  56. package/src/duckdb/src/planner/binder/statement/bind_copy.cpp +2 -2
  57. package/src/duckdb/src/planner/binder/statement/bind_create.cpp +2 -1
  58. package/src/duckdb/src/planner/binder/statement/bind_create_table.cpp +9 -1
  59. package/src/duckdb/src/planner/binder/statement/bind_insert.cpp +10 -6
  60. package/src/duckdb/src/planner/binder/statement/bind_update.cpp +3 -1
  61. package/src/duckdb/src/planner/binder/tableref/bind_pivot.cpp +1 -0
  62. package/src/duckdb/src/planner/binder/tableref/plan_cteref.cpp +1 -0
  63. package/src/duckdb/src/planner/expression_binder/having_binder.cpp +3 -0
  64. package/src/duckdb/src/planner/expression_binder.cpp +1 -1
  65. package/src/duckdb/src/storage/statistics/column_statistics.cpp +1 -2
  66. package/src/duckdb/src/storage/statistics/distinct_statistics.cpp +4 -0
  67. package/src/duckdb/src/storage/statistics/list_stats.cpp +6 -2
  68. package/src/duckdb/src/storage/statistics/struct_stats.cpp +3 -1
  69. package/src/duckdb/src/storage/table/row_group.cpp +6 -1
  70. package/src/duckdb/src/storage/table/update_segment.cpp +11 -7
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "duckdb",
3
3
  "main": "./lib/duckdb.js",
4
4
  "types": "./lib/duckdb.d.ts",
5
- "version": "0.7.2-dev586.0",
5
+ "version": "0.7.2-dev654.0",
6
6
  "description": "DuckDB node.js API",
7
7
  "gypfile": true,
8
8
  "dependencies": {
@@ -13,13 +13,13 @@ struct ICUTableRange {
13
13
  using CalendarPtr = unique_ptr<icu::Calendar>;
14
14
 
15
15
  struct BindData : public TableFunctionData {
16
- explicit BindData(const BindData &other)
17
- : tz_setting(other.tz_setting), cal_setting(other.cal_setting), calendar(other.calendar->clone()),
18
- start(other.start), end(other.end), increment(other.increment), inclusive_bound(other.inclusive_bound),
19
- greater_than_check(other.greater_than_check) {
16
+ BindData(const BindData &other)
17
+ : TableFunctionData(other), tz_setting(other.tz_setting), cal_setting(other.cal_setting),
18
+ calendar(other.calendar->clone()), start(other.start), end(other.end), increment(other.increment),
19
+ inclusive_bound(other.inclusive_bound), greater_than_check(other.greater_than_check) {
20
20
  }
21
21
 
22
- BindData(ClientContext &context) {
22
+ explicit BindData(ClientContext &context) {
23
23
  Value tz_value;
24
24
  if (context.TryGetCurrentSetting("TimeZone", tz_value)) {
25
25
  tz_setting = tz_value.ToString();
@@ -54,14 +54,14 @@ struct ICUTableRange {
54
54
  bool inclusive_bound;
55
55
  bool greater_than_check;
56
56
 
57
- bool Equals(const FunctionData &other_p) const {
57
+ bool Equals(const FunctionData &other_p) const override {
58
58
  auto &other = (const BindData &)other_p;
59
59
  return other.start == start && other.end == end && other.increment == increment &&
60
60
  other.inclusive_bound == inclusive_bound && other.greater_than_check == greater_than_check &&
61
61
  *calendar == *other.calendar;
62
62
  }
63
63
 
64
- unique_ptr<FunctionData> Copy() const {
64
+ unique_ptr<FunctionData> Copy() const override {
65
65
  return make_unique<BindData>(*this);
66
66
  }
67
67
 
@@ -320,7 +320,7 @@ unique_ptr<ColumnReader> ParquetReader::CreateReaderRecursive(const FileMetaData
320
320
  std::move(struct_reader));
321
321
  }
322
322
  if (child_types.size() > 1 || (!is_list && !is_map && !is_repeated)) {
323
- result_type = LogicalType::STRUCT(std::move(child_types));
323
+ result_type = LogicalType::STRUCT(child_types);
324
324
  result = make_unique<StructColumnReader>(*this, result_type, s_ele, this_idx, max_define, max_repeat,
325
325
  std::move(child_readers));
326
326
  } else {
@@ -193,14 +193,14 @@ const vector<unique_ptr<Constraint>> &TableCatalogEntry::GetConstraints() {
193
193
  }
194
194
 
195
195
  DataTable &TableCatalogEntry::GetStorage() {
196
- throw InternalException("Calling GetStorage on a TableCatalogEntry that is not a DTableCatalogEntry");
196
+ throw InternalException("Calling GetStorage on a TableCatalogEntry that is not a DuckTableEntry");
197
197
  }
198
198
 
199
199
  DataTable *TableCatalogEntry::GetStoragePtr() {
200
- throw InternalException("Calling GetStoragePtr on a TableCatalogEntry that is not a DTableCatalogEntry");
200
+ throw InternalException("Calling GetStoragePtr on a TableCatalogEntry that is not a DuckTableEntry");
201
201
  }
202
202
 
203
203
  const vector<unique_ptr<BoundConstraint>> &TableCatalogEntry::GetBoundConstraints() {
204
- throw InternalException("Calling GetBoundConstraints on a TableCatalogEntry that is not a DTableCatalogEntry");
204
+ throw InternalException("Calling GetBoundConstraints on a TableCatalogEntry that is not a DuckTableEntry");
205
205
  }
206
206
  } // namespace duckdb
@@ -1,5 +1,6 @@
1
1
  #include "duckdb/catalog/dependency_list.hpp"
2
2
  #include "duckdb/catalog/catalog_entry.hpp"
3
+ #include "duckdb/catalog/catalog.hpp"
3
4
 
4
5
  namespace duckdb {
5
6
 
@@ -10,4 +11,15 @@ void DependencyList::AddDependency(CatalogEntry *entry) {
10
11
  set.insert(entry);
11
12
  }
12
13
 
14
+ void DependencyList::VerifyDependencies(Catalog *catalog, const string &name) {
15
+ for (auto &dep : set) {
16
+ if (dep->catalog != catalog) {
17
+ throw DependencyException(
18
+ "Error adding dependency for object \"%s\" - dependency \"%s\" is in catalog "
19
+ "\"%s\", which does not match the catalog \"%s\".\nCross catalog dependencies are not supported.",
20
+ name, dep->name, dep->catalog->GetName(), catalog->GetName());
21
+ }
22
+ }
23
+ }
24
+
13
25
  } // namespace duckdb
@@ -191,11 +191,14 @@ vector<string> StringUtil::Split(const string &input, const string &split) {
191
191
 
192
192
  // Push the substring [last, next) on to splits
193
193
  string substr = input.substr(last, next - last);
194
- if (substr.empty() == false) {
194
+ if (!substr.empty()) {
195
195
  splits.push_back(substr);
196
196
  }
197
197
  last = next + split_len;
198
198
  }
199
+ if (splits.empty()) {
200
+ splits.push_back(input);
201
+ }
199
202
  return splits;
200
203
  }
201
204
 
@@ -20,7 +20,7 @@ const int Blob::HEX_MAP[256] = {
20
20
  -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1};
21
21
 
22
22
  bool IsRegularCharacter(data_t c) {
23
- return c >= 32 && c <= 127 && c != '\\' && c != '\'' && c != '"';
23
+ return c >= 32 && c <= 126 && c != '\\' && c != '\'' && c != '"';
24
24
  }
25
25
 
26
26
  idx_t Blob::GetStringSize(string_t blob) {
@@ -143,7 +143,7 @@ void ChunkCollection::Fuse(ChunkCollection &other) {
143
143
  auto &rhs = other.GetChunk(chunk_idx);
144
144
  lhs->data.reserve(rhs.data.size());
145
145
  for (auto &v : rhs.data) {
146
- lhs->data.emplace_back(Vector(v));
146
+ lhs->data.emplace_back(v);
147
147
  }
148
148
  lhs->SetCardinality(rhs.size());
149
149
  chunks.push_back(std::move(lhs));
@@ -156,7 +156,7 @@ void ChunkCollection::Fuse(ChunkCollection &other) {
156
156
  auto &rhs = other.GetChunk(chunk_idx);
157
157
  D_ASSERT(lhs.size() == rhs.size());
158
158
  for (auto &v : rhs.data) {
159
- lhs.data.emplace_back(Vector(v));
159
+ lhs.data.emplace_back(v);
160
160
  }
161
161
  }
162
162
  }
@@ -62,7 +62,7 @@ void DataChunk::InitializeEmpty(vector<LogicalType>::const_iterator begin, vecto
62
62
  D_ASSERT(data.empty()); // can only be initialized once
63
63
  D_ASSERT(std::distance(begin, end) != 0); // empty chunk not allowed
64
64
  for (; begin != end; begin++) {
65
- data.emplace_back(Vector(*begin, nullptr));
65
+ data.emplace_back(*begin, nullptr);
66
66
  }
67
67
  }
68
68
 
@@ -604,22 +604,22 @@ Value Value::STRUCT(child_list_t<Value> values) {
604
604
  struct_values.push_back(std::move(child.second));
605
605
  }
606
606
  result.value_info_ = make_shared<NestedValueInfo>(std::move(struct_values));
607
- result.type_ = LogicalType::STRUCT(std::move(child_types));
607
+ result.type_ = LogicalType::STRUCT(child_types);
608
608
  result.is_null = false;
609
609
  return result;
610
610
  }
611
611
 
612
- Value Value::MAP(LogicalType child_type, vector<Value> values) {
612
+ Value Value::MAP(const LogicalType &child_type, vector<Value> values) {
613
613
  Value result;
614
614
 
615
- result.type_ = LogicalType::MAP(std::move(child_type));
615
+ result.type_ = LogicalType::MAP(child_type);
616
616
  result.is_null = false;
617
617
  result.value_info_ = make_shared<NestedValueInfo>(std::move(values));
618
618
  return result;
619
619
  }
620
620
 
621
621
  Value Value::UNION(child_list_t<LogicalType> members, uint8_t tag, Value value) {
622
- D_ASSERT(members.size() > 0);
622
+ D_ASSERT(!members.empty());
623
623
  D_ASSERT(members.size() <= UnionType::MAX_UNION_MEMBERS);
624
624
  D_ASSERT(members.size() > tag);
625
625
 
@@ -660,9 +660,9 @@ Value Value::LIST(vector<Value> values) {
660
660
  return result;
661
661
  }
662
662
 
663
- Value Value::LIST(LogicalType child_type, vector<Value> values) {
663
+ Value Value::LIST(const LogicalType &child_type, vector<Value> values) {
664
664
  if (values.empty()) {
665
- return Value::EMPTYLIST(std::move(child_type));
665
+ return Value::EMPTYLIST(child_type);
666
666
  }
667
667
  for (auto &val : values) {
668
668
  val = val.DefaultCastAs(child_type);
@@ -670,9 +670,9 @@ Value Value::LIST(LogicalType child_type, vector<Value> values) {
670
670
  return Value::LIST(std::move(values));
671
671
  }
672
672
 
673
- Value Value::EMPTYLIST(LogicalType child_type) {
673
+ Value Value::EMPTYLIST(const LogicalType &child_type) {
674
674
  Value result;
675
- result.type_ = LogicalType::LIST(std::move(child_type));
675
+ result.type_ = LogicalType::LIST(child_type);
676
676
  result.value_info_ = make_shared<NestedValueInfo>();
677
677
  result.is_null = false;
678
678
  return result;
@@ -522,7 +522,7 @@ LogicalType GetUserTypeRecursive(const LogicalType &type, ClientContext &context
522
522
  for (auto &child : StructType::GetChildTypes(type)) {
523
523
  children.emplace_back(child.first, GetUserTypeRecursive(child.second, context));
524
524
  }
525
- return LogicalType::STRUCT(std::move(children));
525
+ return LogicalType::STRUCT(children);
526
526
  }
527
527
  if (type.id() == LogicalTypeId::LIST) {
528
528
  return LogicalType::LIST(GetUserTypeRecursive(ListType::GetChildType(type), context));
@@ -773,12 +773,12 @@ LogicalType LogicalType::MaxLogicalType(const LogicalType &left, const LogicalTy
773
773
  if (type_id == LogicalTypeId::LIST) {
774
774
  // list: perform max recursively on child type
775
775
  auto new_child = MaxLogicalType(ListType::GetChildType(left), ListType::GetChildType(right));
776
- return LogicalType::LIST(std::move(new_child));
776
+ return LogicalType::LIST(new_child);
777
777
  }
778
778
  if (type_id == LogicalTypeId::MAP) {
779
779
  // list: perform max recursively on child type
780
780
  auto new_child = MaxLogicalType(ListType::GetChildType(left), ListType::GetChildType(right));
781
- return LogicalType::MAP(std::move(new_child));
781
+ return LogicalType::MAP(new_child);
782
782
  }
783
783
  if (type_id == LogicalTypeId::STRUCT) {
784
784
  // struct: perform recursively
@@ -795,7 +795,7 @@ LogicalType LogicalType::MaxLogicalType(const LogicalType &left, const LogicalTy
795
795
  child_types.emplace_back(left_child_types[i].first, std::move(child_type));
796
796
  }
797
797
 
798
- return LogicalType::STRUCT(std::move(child_types));
798
+ return LogicalType::STRUCT(child_types);
799
799
  }
800
800
  if (type_id == LogicalTypeId::UNION) {
801
801
  auto left_member_count = UnionType::GetMemberCount(left);
@@ -1076,8 +1076,8 @@ const LogicalType &ListType::GetChildType(const LogicalType &type) {
1076
1076
  return ((ListTypeInfo &)*info).child_type;
1077
1077
  }
1078
1078
 
1079
- LogicalType LogicalType::LIST(LogicalType child) {
1080
- auto info = make_shared<ListTypeInfo>(std::move(child));
1079
+ LogicalType LogicalType::LIST(const LogicalType &child) {
1080
+ auto info = make_shared<ListTypeInfo>(child);
1081
1081
  return LogicalType(LogicalTypeId::LIST, std::move(info));
1082
1082
  }
1083
1083
 
@@ -1207,8 +1207,8 @@ idx_t StructType::GetChildCount(const LogicalType &type) {
1207
1207
  return StructType::GetChildTypes(type).size();
1208
1208
  }
1209
1209
 
1210
- LogicalType LogicalType::STRUCT(child_list_t<LogicalType> children) {
1211
- auto info = make_shared<StructTypeInfo>(std::move(children));
1210
+ LogicalType LogicalType::STRUCT(const child_list_t<LogicalType> &children) {
1211
+ auto info = make_shared<StructTypeInfo>(children);
1212
1212
  return LogicalType(LogicalTypeId::STRUCT, std::move(info));
1213
1213
  }
1214
1214
 
@@ -1220,8 +1220,8 @@ LogicalType LogicalType::AGGREGATE_STATE(aggregate_state_t state_type) { // NOLI
1220
1220
  //===--------------------------------------------------------------------===//
1221
1221
  // Map Type
1222
1222
  //===--------------------------------------------------------------------===//
1223
- LogicalType LogicalType::MAP(LogicalType child) {
1224
- auto info = make_shared<ListTypeInfo>(std::move(child));
1223
+ LogicalType LogicalType::MAP(const LogicalType &child) {
1224
+ auto info = make_shared<ListTypeInfo>(child);
1225
1225
  return LogicalType(LogicalTypeId::MAP, std::move(info));
1226
1226
  }
1227
1227
 
@@ -1229,7 +1229,7 @@ LogicalType LogicalType::MAP(LogicalType key, LogicalType value) {
1229
1229
  child_list_t<LogicalType> child_types;
1230
1230
  child_types.emplace_back("key", std::move(key));
1231
1231
  child_types.emplace_back("value", std::move(value));
1232
- return LogicalType::MAP(LogicalType::STRUCT(std::move(child_types)));
1232
+ return LogicalType::MAP(LogicalType::STRUCT(child_types));
1233
1233
  }
1234
1234
 
1235
1235
  const LogicalType &MapType::KeyType(const LogicalType &type) {
@@ -1289,15 +1289,24 @@ void WindowExecutor::Evaluate(idx_t row_idx, DataChunk &input_chunk, Vector &res
1289
1289
  break;
1290
1290
  }
1291
1291
  case ExpressionType::WINDOW_FIRST_VALUE: {
1292
+ // Same as NTH_VALUE(..., 1)
1292
1293
  idx_t n = 1;
1293
1294
  const auto first_idx = FindNextStart(ignore_nulls, bounds.window_start, bounds.window_end, n);
1294
- CopyCell(payload_collection, 0, first_idx, result, output_offset);
1295
+ if (!n) {
1296
+ CopyCell(payload_collection, 0, first_idx, result, output_offset);
1297
+ } else {
1298
+ FlatVector::SetNull(result, output_offset, true);
1299
+ }
1295
1300
  break;
1296
1301
  }
1297
1302
  case ExpressionType::WINDOW_LAST_VALUE: {
1298
1303
  idx_t n = 1;
1299
- CopyCell(payload_collection, 0, FindPrevStart(ignore_nulls, bounds.window_start, bounds.window_end, n),
1300
- result, output_offset);
1304
+ const auto last_idx = FindPrevStart(ignore_nulls, bounds.window_start, bounds.window_end, n);
1305
+ if (!n) {
1306
+ CopyCell(payload_collection, 0, last_idx, result, output_offset);
1307
+ } else {
1308
+ FlatVector::SetNull(result, output_offset, true);
1309
+ }
1301
1310
  break;
1302
1311
  }
1303
1312
  case ExpressionType::WINDOW_NTH_VALUE: {
@@ -1550,6 +1559,9 @@ TaskExecutionResult WindowMergeTask::ExecuteTask(TaskExecutionMode mode) {
1550
1559
  size_t sorted = 0;
1551
1560
  while (sorted < hash_groups.states.size()) {
1552
1561
  // First check if there is an unfinished task for this thread
1562
+ if (executor.HasError()) {
1563
+ return TaskExecutionResult::TASK_ERROR;
1564
+ }
1553
1565
  if (!local_state.TaskFinished()) {
1554
1566
  local_state.ExecuteTask();
1555
1567
  continue;
@@ -49,6 +49,9 @@ SinkResultType PhysicalVacuum::Sink(ExecutionContext &context, GlobalSinkState &
49
49
  D_ASSERT(lstate.column_distinct_stats.size() == info->column_id_map.size());
50
50
 
51
51
  for (idx_t col_idx = 0; col_idx < input.data.size(); col_idx++) {
52
+ if (!DistinctStatistics::TypeIsSupported(input.data[col_idx].GetType())) {
53
+ continue;
54
+ }
52
55
  lstate.column_distinct_stats[col_idx]->Update(input.data[col_idx], input.size(), false);
53
56
  }
54
57
 
@@ -386,7 +386,7 @@ IEJoinUnion::IEJoinUnion(ClientContext &context, const PhysicalIEJoin &op, Sorte
386
386
  // Sort on the first expression
387
387
  auto ref = make_unique<BoundReferenceExpression>(order1.expression->return_type, 0);
388
388
  vector<BoundOrderByNode> orders;
389
- orders.emplace_back(BoundOrderByNode(order1.type, order1.null_order, std::move(ref)));
389
+ orders.emplace_back(order1.type, order1.null_order, std::move(ref));
390
390
 
391
391
  l1 = make_unique<SortedTable>(context, orders, payload_layout);
392
392
 
@@ -422,7 +422,7 @@ IEJoinUnion::IEJoinUnion(ClientContext &context, const PhysicalIEJoin &op, Sorte
422
422
  // Sort on the first expression
423
423
  orders.clear();
424
424
  ref = make_unique<BoundReferenceExpression>(order2.expression->return_type, 0);
425
- orders.emplace_back(BoundOrderByNode(order2.type, order2.null_order, std::move(ref)));
425
+ orders.emplace_back(order2.type, order2.null_order, std::move(ref));
426
426
 
427
427
  ExpressionExecutor executor(context);
428
428
  executor.AddExpression(*orders[0].expression);
@@ -30,25 +30,20 @@ PhysicalPiecewiseMergeJoin::PhysicalPiecewiseMergeJoin(LogicalOperator &op, uniq
30
30
  switch (cond.comparison) {
31
31
  case ExpressionType::COMPARE_LESSTHAN:
32
32
  case ExpressionType::COMPARE_LESSTHANOREQUALTO:
33
- lhs_orders.emplace_back(
34
- BoundOrderByNode(OrderType::ASCENDING, OrderByNullType::NULLS_LAST, std::move(left)));
35
- rhs_orders.emplace_back(
36
- BoundOrderByNode(OrderType::ASCENDING, OrderByNullType::NULLS_LAST, std::move(right)));
33
+ lhs_orders.emplace_back(OrderType::ASCENDING, OrderByNullType::NULLS_LAST, std::move(left));
34
+ rhs_orders.emplace_back(OrderType::ASCENDING, OrderByNullType::NULLS_LAST, std::move(right));
37
35
  break;
38
36
  case ExpressionType::COMPARE_GREATERTHAN:
39
37
  case ExpressionType::COMPARE_GREATERTHANOREQUALTO:
40
- lhs_orders.emplace_back(
41
- BoundOrderByNode(OrderType::DESCENDING, OrderByNullType::NULLS_LAST, std::move(left)));
42
- rhs_orders.emplace_back(
43
- BoundOrderByNode(OrderType::DESCENDING, OrderByNullType::NULLS_LAST, std::move(right)));
38
+ lhs_orders.emplace_back(OrderType::DESCENDING, OrderByNullType::NULLS_LAST, std::move(left));
39
+ rhs_orders.emplace_back(OrderType::DESCENDING, OrderByNullType::NULLS_LAST, std::move(right));
44
40
  break;
45
41
  case ExpressionType::COMPARE_NOTEQUAL:
46
42
  case ExpressionType::COMPARE_DISTINCT_FROM:
47
43
  // Allowed in multi-predicate joins, but can't be first/sort.
48
44
  D_ASSERT(!lhs_orders.empty());
49
- lhs_orders.emplace_back(BoundOrderByNode(OrderType::INVALID, OrderByNullType::NULLS_LAST, std::move(left)));
50
- rhs_orders.emplace_back(
51
- BoundOrderByNode(OrderType::INVALID, OrderByNullType::NULLS_LAST, std::move(right)));
45
+ lhs_orders.emplace_back(OrderType::INVALID, OrderByNullType::NULLS_LAST, std::move(left));
46
+ rhs_orders.emplace_back(OrderType::INVALID, OrderByNullType::NULLS_LAST, std::move(right));
52
47
  break;
53
48
 
54
49
  default:
@@ -46,7 +46,7 @@ void PhysicalRangeJoin::LocalSortedTable::Sink(DataChunk &input, GlobalSortState
46
46
 
47
47
  // Only sort the primary key
48
48
  DataChunk join_head;
49
- join_head.data.emplace_back(Vector(keys.data[0]));
49
+ join_head.data.emplace_back(keys.data[0]);
50
50
  join_head.SetCardinality(keys.size());
51
51
 
52
52
  // Sink the data into the local sort state
@@ -85,8 +85,8 @@ static string CreateDirRecursive(const vector<idx_t> &cols, const vector<string>
85
85
  CreateDir(path, fs);
86
86
 
87
87
  for (idx_t i = 0; i < cols.size(); i++) {
88
- auto partition_col_name = names[cols[i]];
89
- auto partition_value = values[i];
88
+ const auto &partition_col_name = names[cols[i]];
89
+ const auto &partition_value = values[i];
90
90
  string p_dir = partition_col_name + "=" + partition_value.ToString();
91
91
  path = fs.JoinPath(path, p_dir);
92
92
  CreateDir(path, fs);
@@ -154,6 +154,9 @@ static void CanUseIndexJoin(TableScanBindData *tbl, Expression &expr, Index **re
154
154
 
155
155
  void TransformIndexJoin(ClientContext &context, LogicalComparisonJoin &op, Index **left_index, Index **right_index,
156
156
  PhysicalOperator *left, PhysicalOperator *right) {
157
+ if (op.type == LogicalOperatorType::LOGICAL_DELIM_JOIN) {
158
+ return;
159
+ }
157
160
  // check if one of the tables has an index on column
158
161
  if (op.join_type == JoinType::INNER && op.conditions.size() == 1) {
159
162
  // check if one of the children are table scans and if they have an index in the join attribute
@@ -6,6 +6,7 @@
6
6
  #include "duckdb/storage/statistics/base_statistics.hpp"
7
7
  #include "duckdb/execution/expression_executor.hpp"
8
8
  #include "duckdb/common/types/cast_helpers.hpp"
9
+ #include "duckdb/common/operator/subtract.hpp"
9
10
 
10
11
  namespace duckdb {
11
12
 
@@ -93,7 +94,16 @@ struct BitStringAggOperation {
93
94
 
94
95
  template <class INPUT_TYPE>
95
96
  static idx_t GetRange(INPUT_TYPE min, INPUT_TYPE max) {
96
- return max - min + 1;
97
+ D_ASSERT(max >= min);
98
+ INPUT_TYPE result;
99
+ if (!TrySubtractOperator::Operation(max, min, result)) {
100
+ return NumericLimits<idx_t>::Maximum();
101
+ }
102
+ idx_t val(result);
103
+ if (val == NumericLimits<idx_t>::Maximum()) {
104
+ return val;
105
+ }
106
+ return val + 1;
97
107
  }
98
108
 
99
109
  template <class INPUT_TYPE, class STATE>
@@ -162,12 +172,15 @@ void BitStringAggOperation::Execute(BitAggState<hugeint_t> *state, hugeint_t inp
162
172
 
163
173
  template <>
164
174
  idx_t BitStringAggOperation::GetRange(hugeint_t min, hugeint_t max) {
165
- idx_t val;
166
- if (Hugeint::TryCast(max - min + 1, val)) {
167
- return val;
168
- } else {
169
- throw OutOfRangeException("Range too large for bitstring aggregation");
175
+ hugeint_t result;
176
+ if (!TrySubtractOperator::Operation(max, min, result)) {
177
+ return NumericLimits<idx_t>::Maximum();
178
+ }
179
+ idx_t range;
180
+ if (!Hugeint::TryCast(result + 1, range)) {
181
+ return NumericLimits<idx_t>::Maximum();
170
182
  }
183
+ return range;
171
184
  }
172
185
 
173
186
  unique_ptr<BaseStatistics> BitstringPropagateStats(ClientContext &context, BoundAggregateExpression &expr,
@@ -185,8 +198,10 @@ unique_ptr<BaseStatistics> BitstringPropagateStats(ClientContext &context, Bound
185
198
 
186
199
  unique_ptr<FunctionData> BindBitstringAgg(ClientContext &context, AggregateFunction &function,
187
200
  vector<unique_ptr<Expression>> &arguments) {
188
-
189
201
  if (arguments.size() == 3) {
202
+ if (!arguments[1]->IsFoldable() && !arguments[2]->IsFoldable()) {
203
+ throw BinderException("bitstring_agg requires a constant min and max argument");
204
+ }
190
205
  auto min = ExpressionExecutor::EvaluateScalar(context, *arguments[1]);
191
206
  auto max = ExpressionExecutor::EvaluateScalar(context, *arguments[2]);
192
207
  Function::EraseArgument(function, arguments, 2);
@@ -79,6 +79,7 @@ struct FirstFunctionString : public FirstFunctionBase {
79
79
  }
80
80
  } else {
81
81
  state->is_set = true;
82
+ state->is_null = false;
82
83
  if (value.IsInlined()) {
83
84
  state->value = value;
84
85
  } else {
@@ -70,11 +70,14 @@ struct ApproxQuantileOperation {
70
70
 
71
71
  template <class INPUT_TYPE, class STATE, class OP>
72
72
  static void Operation(STATE *state, AggregateInputData &, INPUT_TYPE *data, ValidityMask &mask, idx_t idx) {
73
+ auto val = Cast::template Operation<INPUT_TYPE, SAVE_TYPE>(data[idx]);
74
+ if (!Value::DoubleIsFinite(val)) {
75
+ return;
76
+ }
73
77
  if (!state->h) {
74
78
  state->h = new duckdb_tdigest::TDigest(100);
75
79
  }
76
-
77
- state->h->add(Cast::template Operation<INPUT_TYPE, SAVE_TYPE>(data[idx]));
80
+ state->h->add(val);
78
81
  state->pos++;
79
82
  }
80
83
 
@@ -414,7 +414,7 @@ struct QuantileBindData : public FunctionData {
414
414
  size_t pos = 0;
415
415
  size_t neg = 0;
416
416
  for (idx_t i = 0; i < quantiles_p.size(); ++i) {
417
- const auto q = quantiles_p[i];
417
+ const auto &q = quantiles_p[i];
418
418
  pos += (q > 0);
419
419
  neg += (q < 0);
420
420
  quantiles.emplace_back(QuantileAbs(q));
@@ -723,9 +723,9 @@ static void GetSegmentDataFunctions(WriteDataToSegment &write_data_to_segment,
723
723
  read_data_from_segment.segment_function = ReadDataFromVarcharSegment;
724
724
  copy_data_from_segment.segment_function = CopyDataFromListSegment;
725
725
 
726
- write_data_to_segment.child_functions.emplace_back(WriteDataToSegment());
726
+ write_data_to_segment.child_functions.emplace_back();
727
727
  write_data_to_segment.child_functions.back().create_segment = CreatePrimitiveSegment<char>;
728
- copy_data_from_segment.child_functions.emplace_back(CopyDataFromSegment());
728
+ copy_data_from_segment.child_functions.emplace_back();
729
729
  copy_data_from_segment.child_functions.back().segment_function = CopyDataFromPrimitiveSegment<char>;
730
730
  break;
731
731
  }
@@ -736,9 +736,9 @@ static void GetSegmentDataFunctions(WriteDataToSegment &write_data_to_segment,
736
736
  copy_data_from_segment.segment_function = CopyDataFromListSegment;
737
737
 
738
738
  // recurse
739
- write_data_to_segment.child_functions.emplace_back(WriteDataToSegment());
740
- read_data_from_segment.child_functions.emplace_back(ReadDataFromSegment());
741
- copy_data_from_segment.child_functions.emplace_back(CopyDataFromSegment());
739
+ write_data_to_segment.child_functions.emplace_back();
740
+ read_data_from_segment.child_functions.emplace_back();
741
+ copy_data_from_segment.child_functions.emplace_back();
742
742
  GetSegmentDataFunctions(write_data_to_segment.child_functions.back(),
743
743
  read_data_from_segment.child_functions.back(),
744
744
  copy_data_from_segment.child_functions.back(), ListType::GetChildType(type));
@@ -753,9 +753,9 @@ static void GetSegmentDataFunctions(WriteDataToSegment &write_data_to_segment,
753
753
  // recurse
754
754
  auto child_types = StructType::GetChildTypes(type);
755
755
  for (idx_t i = 0; i < child_types.size(); i++) {
756
- write_data_to_segment.child_functions.emplace_back(WriteDataToSegment());
757
- read_data_from_segment.child_functions.emplace_back(ReadDataFromSegment());
758
- copy_data_from_segment.child_functions.emplace_back(CopyDataFromSegment());
756
+ write_data_to_segment.child_functions.emplace_back();
757
+ read_data_from_segment.child_functions.emplace_back();
758
+ copy_data_from_segment.child_functions.emplace_back();
759
759
  GetSegmentDataFunctions(write_data_to_segment.child_functions.back(),
760
760
  read_data_from_segment.child_functions.back(),
761
761
  copy_data_from_segment.child_functions.back(), child_types[i].second);
@@ -129,7 +129,7 @@ BoundCastInfo DefaultCasts::StructCastSwitch(BindCastInput &input, const Logical
129
129
  for (auto &child_entry : struct_children) {
130
130
  varchar_children.push_back(make_pair(child_entry.first, LogicalType::VARCHAR));
131
131
  }
132
- auto varchar_type = LogicalType::STRUCT(std::move(varchar_children));
132
+ auto varchar_type = LogicalType::STRUCT(varchar_children);
133
133
  return BoundCastInfo(StructToVarcharCast,
134
134
  StructBoundCastData::BindStructToStructCast(input, source, varchar_type));
135
135
  }
@@ -1332,7 +1332,7 @@ struct StructDatePart {
1332
1332
  }
1333
1333
 
1334
1334
  Function::EraseArgument(bound_function, arguments, 0);
1335
- bound_function.return_type = LogicalType::STRUCT(std::move(struct_children));
1335
+ bound_function.return_type = LogicalType::STRUCT(struct_children);
1336
1336
  return make_unique<BindData>(bound_function.return_type, part_codes);
1337
1337
  }
1338
1338
 
@@ -82,9 +82,10 @@ static unique_ptr<FunctionData> ListConcatBind(ClientContext &context, ScalarFun
82
82
  throw ParameterNotResolvedException();
83
83
  } else if (lhs.id() == LogicalTypeId::SQLNULL || rhs.id() == LogicalTypeId::SQLNULL) {
84
84
  // we mimic postgres behaviour: list_concat(NULL, my_list) = my_list
85
- bound_function.arguments[0] = lhs;
86
- bound_function.arguments[1] = rhs;
87
- bound_function.return_type = rhs.id() == LogicalTypeId::SQLNULL ? lhs : rhs;
85
+ auto return_type = rhs.id() == LogicalTypeId::SQLNULL ? lhs : rhs;
86
+ bound_function.arguments[0] = return_type;
87
+ bound_function.arguments[1] = return_type;
88
+ bound_function.return_type = return_type;
88
89
  } else {
89
90
  D_ASSERT(lhs.id() == LogicalTypeId::LIST);
90
91
  D_ASSERT(rhs.id() == LogicalTypeId::LIST);
@@ -94,7 +95,7 @@ static unique_ptr<FunctionData> ListConcatBind(ClientContext &context, ScalarFun
94
95
  for (const auto &argument : arguments) {
95
96
  child_type = LogicalType::MaxLogicalType(child_type, ListType::GetChildType(argument->return_type));
96
97
  }
97
- auto list_type = LogicalType::LIST(std::move(child_type));
98
+ auto list_type = LogicalType::LIST(child_type);
98
99
 
99
100
  bound_function.arguments[0] = list_type;
100
101
  bound_function.arguments[1] = list_type;
@@ -124,7 +124,7 @@ static void ExecuteExpression(vector<LogicalType> &types, vector<LogicalType> &r
124
124
  // set the other vectors
125
125
  vector<Vector> slices;
126
126
  for (idx_t col_idx = 0; col_idx < args.ColumnCount() - 1; col_idx++) {
127
- slices.emplace_back(Vector(args.data[col_idx + 1], sel_vectors[col_idx], elem_cnt));
127
+ slices.emplace_back(args.data[col_idx + 1], sel_vectors[col_idx], elem_cnt);
128
128
  slices[col_idx].Flatten(elem_cnt);
129
129
  input_chunk.data[col_idx + 2].Reference(slices[col_idx]);
130
130
  }
@@ -195,10 +195,10 @@ static void ListLambdaFunction(DataChunk &args, ExpressionState &state, Vector &
195
195
 
196
196
  // skip the list column
197
197
  for (idx_t i = 1; i < args.ColumnCount(); i++) {
198
- columns.emplace_back(UnifiedVectorFormat());
198
+ columns.emplace_back();
199
199
  args.data[i].ToUnifiedFormat(count, columns[i - 1]);
200
200
  indexes.push_back(0);
201
- sel_vectors.emplace_back(SelectionVector(STANDARD_VECTOR_SIZE));
201
+ sel_vectors.emplace_back(STANDARD_VECTOR_SIZE);
202
202
  types.push_back(args.data[i].GetType());
203
203
  }
204
204
 
@@ -42,7 +42,7 @@ static unique_ptr<FunctionData> ListValueBind(ClientContext &context, ScalarFunc
42
42
 
43
43
  // this is more for completeness reasons
44
44
  bound_function.varargs = child_type;
45
- bound_function.return_type = LogicalType::LIST(std::move(child_type));
45
+ bound_function.return_type = LogicalType::LIST(child_type);
46
46
  return make_unique<VariableReturnBindData>(bound_function.return_type);
47
47
  }
48
48
 
@@ -44,7 +44,7 @@ static unique_ptr<FunctionData> MapEntriesBind(ClientContext &context, ScalarFun
44
44
  child_types.push_back(make_pair("k", key_type));
45
45
  child_types.push_back(make_pair("v", value_type));
46
46
 
47
- auto row_type = LogicalType::STRUCT(std::move(child_types));
47
+ auto row_type = LogicalType::STRUCT(child_types);
48
48
 
49
49
  bound_function.return_type = LogicalType::LIST(row_type);
50
50
  return make_unique<VariableReturnBindData>(bound_function.return_type);