duckdb 0.8.1-dev194.0 → 0.8.1-dev219.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/binding.gyp CHANGED
@@ -237,18 +237,18 @@
237
237
  "src/duckdb/third_party/zstd/compress/zstd_lazy.cpp",
238
238
  "src/duckdb/third_party/zstd/compress/zstd_ldm.cpp",
239
239
  "src/duckdb/third_party/zstd/compress/zstd_opt.cpp",
240
- "src/duckdb/extension/icu/./icu-dateadd.cpp",
241
- "src/duckdb/extension/icu/./icu-datetrunc.cpp",
242
- "src/duckdb/extension/icu/./icu-datesub.cpp",
243
- "src/duckdb/extension/icu/./icu-table-range.cpp",
244
- "src/duckdb/extension/icu/./icu-timebucket.cpp",
245
240
  "src/duckdb/extension/icu/./icu-list-range.cpp",
241
+ "src/duckdb/extension/icu/./icu-datefunc.cpp",
246
242
  "src/duckdb/extension/icu/./icu-datepart.cpp",
247
- "src/duckdb/extension/icu/./icu-timezone.cpp",
243
+ "src/duckdb/extension/icu/./icu-datetrunc.cpp",
244
+ "src/duckdb/extension/icu/./icu-table-range.cpp",
245
+ "src/duckdb/extension/icu/./icu-dateadd.cpp",
248
246
  "src/duckdb/extension/icu/./icu-extension.cpp",
249
- "src/duckdb/extension/icu/./icu-makedate.cpp",
250
- "src/duckdb/extension/icu/./icu-datefunc.cpp",
251
247
  "src/duckdb/extension/icu/./icu-strptime.cpp",
248
+ "src/duckdb/extension/icu/./icu-datesub.cpp",
249
+ "src/duckdb/extension/icu/./icu-makedate.cpp",
250
+ "src/duckdb/extension/icu/./icu-timezone.cpp",
251
+ "src/duckdb/extension/icu/./icu-timebucket.cpp",
252
252
  "src/duckdb/ub_extension_icu_third_party_icu_common.cpp",
253
253
  "src/duckdb/ub_extension_icu_third_party_icu_i18n.cpp",
254
254
  "src/duckdb/extension/icu/third_party/icu/stubdata/stubdata.cpp",
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.8.1-dev194.0",
5
+ "version": "0.8.1-dev219.0",
6
6
  "description": "DuckDB node.js API",
7
7
  "gypfile": true,
8
8
  "dependencies": {
@@ -101,16 +101,17 @@ void RowDataCollectionScanner::AlignHeapBlocks(RowDataCollection &swizzled_block
101
101
  make_uniq<RowDataBlock>(buffer_manager, MaxValue<idx_t>(total_size, (idx_t)Storage::BLOCK_SIZE), 1));
102
102
  auto new_heap_handle = buffer_manager.Pin(swizzled_string_heap.blocks.back()->block);
103
103
  auto new_heap_ptr = new_heap_handle.Ptr();
104
+ for (auto &ptr_and_size : ptrs_and_sizes) {
105
+ memcpy(new_heap_ptr, ptr_and_size.first, ptr_and_size.second);
106
+ new_heap_ptr += ptr_and_size.second;
107
+ }
108
+ new_heap_ptr = new_heap_handle.Ptr();
104
109
  if (swizzled_string_heap.keep_pinned) {
105
110
  // Since the heap blocks are pinned, we can unswizzle the data again.
106
111
  swizzled_string_heap.pinned_blocks.emplace_back(std::move(new_heap_handle));
107
112
  RowOperations::UnswizzlePointers(layout, base_row_ptr, new_heap_ptr, data_block->count);
108
113
  RowOperations::UnswizzleHeapPointer(layout, base_row_ptr, new_heap_ptr, data_block->count);
109
114
  }
110
- for (auto &ptr_and_size : ptrs_and_sizes) {
111
- memcpy(new_heap_ptr, ptr_and_size.first, ptr_and_size.second);
112
- new_heap_ptr += ptr_and_size.second;
113
- }
114
115
  }
115
116
  }
116
117
 
@@ -62,8 +62,19 @@ inline string_t TupleDataWithinListValueLoad(const data_ptr_t &location, data_pt
62
62
  return result;
63
63
  }
64
64
 
65
+ static void ResetCombinedListData(vector<TupleDataVectorFormat> &vector_data) {
66
+ for (auto &vd : vector_data) {
67
+ vd.combined_list_data = nullptr;
68
+ ResetCombinedListData(vd.child_formats);
69
+ }
70
+ }
71
+
65
72
  void TupleDataCollection::ComputeHeapSizes(TupleDataChunkState &chunk_state, const DataChunk &new_chunk,
66
73
  const SelectionVector &append_sel, const idx_t append_count) {
74
+ #ifdef DEBUG
75
+ ResetCombinedListData(chunk_state.vector_data);
76
+ #endif
77
+
67
78
  auto heap_sizes = FlatVector::GetData<idx_t>(chunk_state.heap_sizes);
68
79
  std::fill_n(heap_sizes, new_chunk.size(), 0);
69
80
 
@@ -293,7 +304,12 @@ static void ApplySliceRecursive(const Vector &source_v, TupleDataVectorFormat &s
293
304
  for (idx_t struct_col_idx = 0; struct_col_idx < struct_sources.size(); struct_col_idx++) {
294
305
  auto &struct_source = *struct_sources[struct_col_idx];
295
306
  auto &struct_format = source_format.child_formats[struct_col_idx];
296
- struct_format.combined_list_data = make_uniq<CombinedListData>();
307
+ #ifdef DEBUG
308
+ D_ASSERT(!struct_format.combined_list_data);
309
+ #endif
310
+ if (!struct_format.combined_list_data) {
311
+ struct_format.combined_list_data = make_uniq<CombinedListData>();
312
+ }
297
313
  ApplySliceRecursive(struct_source, struct_format, *source_format.data.sel, count);
298
314
  }
299
315
  }
@@ -308,14 +324,15 @@ void TupleDataCollection::ListWithinListComputeHeapSizes(Vector &heap_sizes_v, c
308
324
  const auto list_entries = UnifiedVectorFormat::GetData<list_entry_t>(list_data);
309
325
  const auto &list_validity = list_data.validity;
310
326
 
311
- // Child list
327
+ // Child list ("source_v")
312
328
  const auto &child_list_data = source_format.data;
313
329
  const auto child_list_sel = *child_list_data.sel;
314
330
  const auto child_list_entries = UnifiedVectorFormat::GetData<list_entry_t>(child_list_data);
315
331
  const auto &child_list_validity = child_list_data.validity;
316
332
 
317
- // Figure out actual child list size (differs from ListVector::GetListSize if dict/const vector)
318
- idx_t child_list_child_count = ListVector::GetListSize(source_v);
333
+ // Figure out actual child list size (can differ from ListVector::GetListSize if dict/const vector),
334
+ // and we cannot use ConstantVector::ZeroSelectionVector because it may need to be longer than STANDARD_VECTOR_SIZE
335
+ idx_t sum_of_sizes = 0;
319
336
  for (idx_t i = 0; i < append_count; i++) {
320
337
  const auto list_idx = list_sel.get_index(append_sel.get_index(i));
321
338
  if (!list_validity.RowIsValid(list_idx)) {
@@ -324,15 +341,33 @@ void TupleDataCollection::ListWithinListComputeHeapSizes(Vector &heap_sizes_v, c
324
341
  const auto &list_entry = list_entries[list_idx];
325
342
  const auto &list_offset = list_entry.offset;
326
343
  const auto &list_length = list_entry.length;
327
- child_list_child_count = MaxValue<idx_t>(child_list_child_count, list_offset + list_length);
344
+
345
+ for (idx_t child_i = 0; child_i < list_length; child_i++) {
346
+ const auto child_list_idx = child_list_sel.get_index(list_offset + child_i);
347
+ if (!child_list_validity.RowIsValid(child_list_idx)) {
348
+ continue;
349
+ }
350
+
351
+ const auto &child_list_entry = child_list_entries[child_list_idx];
352
+ const auto &child_list_length = child_list_entry.length;
353
+
354
+ sum_of_sizes += child_list_length;
355
+ }
328
356
  }
357
+ const auto child_list_child_count = MaxValue<idx_t>(sum_of_sizes, ListVector::GetListSize(source_v));
329
358
 
330
359
  // Target
331
360
  auto heap_sizes = FlatVector::GetData<idx_t>(heap_sizes_v);
332
361
 
333
362
  // Construct combined list entries and a selection vector for the child list child
334
363
  auto &child_format = source_format.child_formats[0];
335
- child_format.combined_list_data = make_uniq<CombinedListData>();
364
+ #ifdef DEBUG
365
+ // In debug mode this should be deleted by ResetCombinedListData
366
+ D_ASSERT(!child_format.combined_list_data);
367
+ #endif
368
+ if (!child_format.combined_list_data) {
369
+ child_format.combined_list_data = make_uniq<CombinedListData>();
370
+ }
336
371
  auto &combined_list_data = *child_format.combined_list_data;
337
372
  auto &combined_list_entries = combined_list_data.combined_list_entries;
338
373
  SelectionVector combined_sel(child_list_child_count);
@@ -365,7 +400,7 @@ void TupleDataCollection::ListWithinListComputeHeapSizes(Vector &heap_sizes_v, c
365
400
  const auto &child_list_offset = child_list_entry.offset;
366
401
  const auto &child_list_length = child_list_entry.length;
367
402
 
368
- // Add this child's list entry's to the combined selection vector
403
+ // Add this child's list entries to the combined selection vector
369
404
  for (idx_t child_value_i = 0; child_value_i < child_list_length; child_value_i++) {
370
405
  auto idx = combined_list_offset + child_list_size + child_value_i;
371
406
  auto loc = child_list_offset + child_value_i;
@@ -199,7 +199,7 @@ unique_ptr<BaseStatistics> BitstringPropagateStats(ClientContext &context, Bound
199
199
  unique_ptr<FunctionData> BindBitstringAgg(ClientContext &context, AggregateFunction &function,
200
200
  vector<unique_ptr<Expression>> &arguments) {
201
201
  if (arguments.size() == 3) {
202
- if (!arguments[1]->IsFoldable() && !arguments[2]->IsFoldable()) {
202
+ if (!arguments[1]->IsFoldable() || !arguments[2]->IsFoldable()) {
203
203
  throw BinderException("bitstring_agg requires a constant min and max argument");
204
204
  }
205
205
  auto min = ExpressionExecutor::EvaluateScalar(context, *arguments[1]);
@@ -153,6 +153,9 @@ static unique_ptr<FunctionData> MapConcatBind(ClientContext &context, ScalarFunc
153
153
  // The maps are allowed to be NULL
154
154
  continue;
155
155
  }
156
+ if (map.id() != LogicalTypeId::MAP) {
157
+ throw InvalidInputException("MAP_CONCAT only takes map arguments");
158
+ }
156
159
  is_null = false;
157
160
  if (IsEmptyMap(map)) {
158
161
  // Map is allowed to be empty
@@ -25,7 +25,14 @@ static unique_ptr<FunctionData> RepeatRowBind(ClientContext &context, TableFunct
25
25
  return_types.push_back(inputs[input_idx].type());
26
26
  names.push_back("column" + std::to_string(input_idx));
27
27
  }
28
- return make_uniq<RepeatRowFunctionData>(inputs, input.named_parameters["num_rows"].GetValue<int64_t>());
28
+ auto entry = input.named_parameters.find("num_rows");
29
+ if (entry == input.named_parameters.end()) {
30
+ throw BinderException("repeat_rows requires num_rows to be specified");
31
+ }
32
+ if (inputs.empty()) {
33
+ throw BinderException("repeat_rows requires at least one column to be specified");
34
+ }
35
+ return make_uniq<RepeatRowFunctionData>(inputs, entry->second.GetValue<int64_t>());
29
36
  }
30
37
 
31
38
  static unique_ptr<GlobalTableFunctionState> RepeatRowInit(ClientContext &context, TableFunctionInitInput &input) {
@@ -1,8 +1,8 @@
1
1
  #ifndef DUCKDB_VERSION
2
- #define DUCKDB_VERSION "0.8.1-dev194"
2
+ #define DUCKDB_VERSION "0.8.1-dev219"
3
3
  #endif
4
4
  #ifndef DUCKDB_SOURCE_ID
5
- #define DUCKDB_SOURCE_ID "54a1955565"
5
+ #define DUCKDB_SOURCE_ID "fc724f980f"
6
6
  #endif
7
7
  #include "duckdb/function/table/system_functions.hpp"
8
8
  #include "duckdb/main/database.hpp"
@@ -56,7 +56,7 @@ public:
56
56
  //! or throws an exception if the column could not be bound.
57
57
  BindResult BindColumn(ColumnRefExpression &colref, idx_t depth);
58
58
  string BindColumn(PositionalReferenceExpression &ref, string &table_name, string &column_name);
59
- BindResult BindColumn(PositionalReferenceExpression &ref, idx_t depth);
59
+ unique_ptr<ColumnRefExpression> PositionToColumn(PositionalReferenceExpression &ref);
60
60
 
61
61
  unique_ptr<ParsedExpression> ExpandGeneratedColumn(const string &table_name, const string &column_name);
62
62
 
@@ -124,8 +124,8 @@ protected:
124
124
  const LogicalType &list_child_type);
125
125
  BindResult BindExpression(OperatorExpression &expr, idx_t depth);
126
126
  BindResult BindExpression(ParameterExpression &expr, idx_t depth);
127
- BindResult BindExpression(PositionalReferenceExpression &ref, idx_t depth);
128
127
  BindResult BindExpression(SubqueryExpression &expr, idx_t depth);
128
+ BindResult BindPositionalReference(unique_ptr<ParsedExpression> &expr, idx_t depth, bool root_expression);
129
129
 
130
130
  void TransformCapturedLambdaColumn(unique_ptr<Expression> &original, unique_ptr<Expression> &replacement,
131
131
  vector<unique_ptr<Expression>> &captures, LogicalType &list_child_type);
@@ -87,6 +87,9 @@ unique_ptr<TableRef> Transformer::TransformPivot(duckdb_libpgquery::PGPivotExpr
87
87
  result->unpivot_names = TransformStringList(root.unpivots);
88
88
  }
89
89
  result->pivots = TransformPivotList(*root.pivots);
90
+ if (!result->unpivot_names.empty() && result->pivots.size() > 1) {
91
+ throw ParserException("UNPIVOT requires a single pivot element");
92
+ }
90
93
  if (root.groups) {
91
94
  result->groups = TransformStringList(root.groups);
92
95
  }
@@ -286,15 +286,14 @@ string BindContext::BindColumn(PositionalReferenceExpression &ref, string &table
286
286
  return StringUtil::Format("Positional reference %d out of range (total %d columns)", ref.index, total_columns);
287
287
  }
288
288
 
289
- BindResult BindContext::BindColumn(PositionalReferenceExpression &ref, idx_t depth) {
289
+ unique_ptr<ColumnRefExpression> BindContext::PositionToColumn(PositionalReferenceExpression &ref) {
290
290
  string table_name, column_name;
291
291
 
292
292
  string error = BindColumn(ref, table_name, column_name);
293
293
  if (!error.empty()) {
294
- return BindResult(error);
294
+ throw BinderException(error);
295
295
  }
296
- auto column_ref = make_uniq<ColumnRefExpression>(column_name, table_name);
297
- return BindColumn(*column_ref, depth);
296
+ return make_uniq<ColumnRefExpression>(column_name, table_name);
298
297
  }
299
298
 
300
299
  bool BindContext::CheckExclusionList(StarExpression &expr, const string &column_name,
@@ -4,11 +4,16 @@
4
4
 
5
5
  namespace duckdb {
6
6
 
7
- BindResult ExpressionBinder::BindExpression(PositionalReferenceExpression &ref, idx_t depth) {
7
+ BindResult ExpressionBinder::BindPositionalReference(unique_ptr<ParsedExpression> &expr, idx_t depth,
8
+ bool root_expression) {
9
+ auto &ref = expr->Cast<PositionalReferenceExpression>();
8
10
  if (depth != 0) {
9
11
  return BindResult("Positional reference expression could not be bound");
10
12
  }
11
- return binder.bind_context.BindColumn(ref, depth);
13
+ // replace the positional reference with a column
14
+ auto column = binder.bind_context.PositionToColumn(ref);
15
+ expr = std::move(column);
16
+ return BindExpression(expr, depth, root_expression);
12
17
  }
13
18
 
14
19
  } // namespace duckdb
@@ -250,7 +250,9 @@ unique_ptr<BoundTableRef> Binder::BindBoundPivot(PivotRef &ref) {
250
250
  auto &aggregates = result->bound_pivot.aggregates;
251
251
  ExtractPivotAggregates(*result->child, aggregates);
252
252
  if (aggregates.size() != ref.bound_aggregate_names.size()) {
253
- throw InternalException("Pivot - aggregate count mismatch");
253
+ throw BinderException("Pivot aggregate count mismatch. Expected %llu aggregates but found %llu. Are all pivot "
254
+ "expressions aggregate functions?",
255
+ ref.bound_aggregate_names.size(), aggregates.size());
254
256
  }
255
257
 
256
258
  vector<string> child_names;
@@ -64,8 +64,9 @@ BindResult ExpressionBinder::BindExpression(unique_ptr<ParsedExpression> &expr,
64
64
  return BindExpression(expr_ref.Cast<SubqueryExpression>(), depth);
65
65
  case ExpressionClass::PARAMETER:
66
66
  return BindExpression(expr_ref.Cast<ParameterExpression>(), depth);
67
- case ExpressionClass::POSITIONAL_REFERENCE:
68
- return BindExpression(expr_ref.Cast<PositionalReferenceExpression>(), depth);
67
+ case ExpressionClass::POSITIONAL_REFERENCE: {
68
+ return BindPositionalReference(expr, depth, root_expression);
69
+ }
69
70
  case ExpressionClass::STAR:
70
71
  return BindResult(binder.FormatError(expr_ref, "STAR expression is not supported here"));
71
72
  default:
@@ -348,17 +348,17 @@
348
348
 
349
349
  #include "extension/icu/third_party/icu/i18n/wintzimpl.cpp"
350
350
 
351
- #include "extension/icu/third_party/icu/i18n/double-conversion-double-to-string.cpp"
352
-
353
351
  #include "extension/icu/third_party/icu/i18n/double-conversion-fast-dtoa.cpp"
354
352
 
355
- #include "extension/icu/third_party/icu/i18n/double-conversion-bignum.cpp"
353
+ #include "extension/icu/third_party/icu/i18n/double-conversion-double-to-string.cpp"
356
354
 
357
- #include "extension/icu/third_party/icu/i18n/double-conversion-string-to-double.cpp"
355
+ #include "extension/icu/third_party/icu/i18n/double-conversion-strtod.cpp"
358
356
 
359
357
  #include "extension/icu/third_party/icu/i18n/double-conversion-cached-powers.cpp"
360
358
 
359
+ #include "extension/icu/third_party/icu/i18n/double-conversion-string-to-double.cpp"
360
+
361
361
  #include "extension/icu/third_party/icu/i18n/double-conversion-bignum-dtoa.cpp"
362
362
 
363
- #include "extension/icu/third_party/icu/i18n/double-conversion-strtod.cpp"
363
+ #include "extension/icu/third_party/icu/i18n/double-conversion-bignum.cpp"
364
364