duckdb 0.7.2-dev832.0 → 0.7.2-dev886.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 (63) hide show
  1. package/package.json +1 -1
  2. package/src/duckdb/src/catalog/catalog.cpp +21 -5
  3. package/src/duckdb/src/catalog/default/default_functions.cpp +3 -0
  4. package/src/duckdb/src/catalog/duck_catalog.cpp +34 -7
  5. package/src/duckdb/src/common/box_renderer.cpp +109 -23
  6. package/src/duckdb/src/common/types/value.cpp +0 -93
  7. package/src/duckdb/src/execution/operator/helper/physical_limit.cpp +3 -0
  8. package/src/duckdb/src/execution/physical_plan/plan_aggregate.cpp +5 -8
  9. package/src/duckdb/src/function/scalar/date/date_part.cpp +2 -2
  10. package/src/duckdb/src/function/scalar/date/date_trunc.cpp +2 -2
  11. package/src/duckdb/src/function/scalar/list/list_aggregates.cpp +1 -1
  12. package/src/duckdb/src/function/scalar/list/list_lambdas.cpp +4 -0
  13. package/src/duckdb/src/function/scalar/operators/arithmetic.cpp +8 -8
  14. package/src/duckdb/src/function/table/version/pragma_version.cpp +2 -2
  15. package/src/duckdb/src/include/duckdb/catalog/catalog.hpp +3 -0
  16. package/src/duckdb/src/include/duckdb/catalog/duck_catalog.hpp +2 -1
  17. package/src/duckdb/src/include/duckdb/common/box_renderer.hpp +8 -2
  18. package/src/duckdb/src/include/duckdb/common/types/value.hpp +0 -31
  19. package/src/duckdb/src/include/duckdb/optimizer/filter_pushdown.hpp +2 -0
  20. package/src/duckdb/src/include/duckdb/storage/statistics/numeric_stats.hpp +9 -52
  21. package/src/duckdb/src/include/duckdb/storage/statistics/numeric_stats_union.hpp +62 -0
  22. package/src/duckdb/src/include/duckdb/storage/table/column_checkpoint_state.hpp +2 -1
  23. package/src/duckdb/src/include/duckdb/storage/table/column_data.hpp +6 -3
  24. package/src/duckdb/src/include/duckdb/storage/table/column_data_checkpointer.hpp +3 -2
  25. package/src/duckdb/src/include/duckdb/storage/table/column_segment.hpp +5 -3
  26. package/src/duckdb/src/include/duckdb/storage/table/persistent_table_data.hpp +4 -1
  27. package/src/duckdb/src/include/duckdb/storage/table/row_group.hpp +6 -3
  28. package/src/duckdb/src/include/duckdb/storage/table/row_group_collection.hpp +5 -3
  29. package/src/duckdb/src/include/duckdb/storage/table/row_group_segment_tree.hpp +37 -0
  30. package/src/duckdb/src/include/duckdb/storage/table/scan_state.hpp +8 -1
  31. package/src/duckdb/src/include/duckdb/storage/table/segment_base.hpp +4 -3
  32. package/src/duckdb/src/include/duckdb/storage/table/segment_tree.hpp +271 -26
  33. package/src/duckdb/src/optimizer/filter_pushdown.cpp +11 -7
  34. package/src/duckdb/src/optimizer/pushdown/pushdown_left_join.cpp +1 -10
  35. package/src/duckdb/src/optimizer/pushdown/pushdown_mark_join.cpp +1 -1
  36. package/src/duckdb/src/optimizer/pushdown/pushdown_single_join.cpp +1 -1
  37. package/src/duckdb/src/parser/transform/expression/transform_array_access.cpp +11 -0
  38. package/src/duckdb/src/parser/transform/statement/transform_pivot_stmt.cpp +31 -6
  39. package/src/duckdb/src/planner/binder/expression/bind_function_expression.cpp +22 -4
  40. package/src/duckdb/src/planner/binder/tableref/bind_pivot.cpp +1 -1
  41. package/src/duckdb/src/storage/checkpoint/table_data_reader.cpp +3 -11
  42. package/src/duckdb/src/storage/checkpoint/table_data_writer.cpp +6 -0
  43. package/src/duckdb/src/storage/checkpoint_manager.cpp +1 -0
  44. package/src/duckdb/src/storage/compression/numeric_constant.cpp +2 -2
  45. package/src/duckdb/src/storage/data_table.cpp +1 -1
  46. package/src/duckdb/src/storage/statistics/numeric_stats.cpp +145 -83
  47. package/src/duckdb/src/storage/statistics/numeric_stats_union.cpp +65 -0
  48. package/src/duckdb/src/storage/storage_info.cpp +1 -1
  49. package/src/duckdb/src/storage/table/column_checkpoint_state.cpp +1 -6
  50. package/src/duckdb/src/storage/table/column_data.cpp +29 -35
  51. package/src/duckdb/src/storage/table/column_data_checkpointer.cpp +5 -5
  52. package/src/duckdb/src/storage/table/column_segment.cpp +8 -7
  53. package/src/duckdb/src/storage/table/list_column_data.cpp +2 -1
  54. package/src/duckdb/src/storage/table/persistent_table_data.cpp +2 -1
  55. package/src/duckdb/src/storage/table/row_group.cpp +9 -9
  56. package/src/duckdb/src/storage/table/row_group_collection.cpp +82 -66
  57. package/src/duckdb/src/storage/table/scan_state.cpp +22 -3
  58. package/src/duckdb/src/storage/table/standard_column_data.cpp +1 -0
  59. package/src/duckdb/src/storage/table/struct_column_data.cpp +1 -0
  60. package/src/duckdb/third_party/libpg_query/src_backend_parser_gram.cpp +11578 -11222
  61. package/src/duckdb/ub_src_storage_statistics.cpp +2 -0
  62. package/src/duckdb/ub_src_storage_table.cpp +0 -2
  63. package/src/duckdb/src/storage/table/segment_tree.cpp +0 -179
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-dev832.0",
5
+ "version": "0.7.2-dev886.0",
6
6
  "description": "DuckDB node.js API",
7
7
  "gypfile": true,
8
8
  "dependencies": {
@@ -63,20 +63,28 @@ Catalog &Catalog::GetSystemCatalog(ClientContext &context) {
63
63
  return Catalog::GetSystemCatalog(*context.db);
64
64
  }
65
65
 
66
- Catalog &Catalog::GetCatalog(ClientContext &context, const string &catalog_name) {
66
+ optional_ptr<Catalog> Catalog::GetCatalogEntry(ClientContext &context, const string &catalog_name) {
67
67
  auto &db_manager = DatabaseManager::Get(context);
68
68
  if (catalog_name == TEMP_CATALOG) {
69
- return ClientData::Get(context).temporary_objects->GetCatalog();
69
+ return &ClientData::Get(context).temporary_objects->GetCatalog();
70
70
  }
71
71
  if (catalog_name == SYSTEM_CATALOG) {
72
- return GetSystemCatalog(context);
72
+ return &GetSystemCatalog(context);
73
73
  }
74
74
  auto entry = db_manager.GetDatabase(
75
75
  context, IsInvalidCatalog(catalog_name) ? DatabaseManager::GetDefaultDatabase(context) : catalog_name);
76
76
  if (!entry) {
77
+ return nullptr;
78
+ }
79
+ return &entry->GetCatalog();
80
+ }
81
+
82
+ Catalog &Catalog::GetCatalog(ClientContext &context, const string &catalog_name) {
83
+ auto catalog = Catalog::GetCatalogEntry(context, catalog_name);
84
+ if (!catalog) {
77
85
  throw BinderException("Catalog \"%s\" does not exist!", catalog_name);
78
86
  }
79
- return entry->GetCatalog();
87
+ return *catalog;
80
88
  }
81
89
 
82
90
  //===--------------------------------------------------------------------===//
@@ -576,7 +584,15 @@ CatalogEntry *Catalog::GetEntry(ClientContext &context, CatalogType type, const
576
584
  vector<CatalogLookup> lookups;
577
585
  lookups.reserve(entries.size());
578
586
  for (auto &entry : entries) {
579
- lookups.emplace_back(Catalog::GetCatalog(context, entry.catalog), entry.schema);
587
+ if (if_exists_p) {
588
+ auto catalog_entry = Catalog::GetCatalogEntry(context, entry.catalog);
589
+ if (!catalog_entry) {
590
+ return nullptr;
591
+ }
592
+ lookups.emplace_back(*catalog_entry, entry.schema);
593
+ } else {
594
+ lookups.emplace_back(Catalog::GetCatalog(context, entry.catalog), entry.schema);
595
+ }
580
596
  }
581
597
  auto result = LookupEntry(context, lookups, type, name, if_exists_p, error_context);
582
598
  if (!result.Found()) {
@@ -131,6 +131,9 @@ static DefaultMacro internal_macros[] = {
131
131
  // nested list aggregates
132
132
  {DEFAULT_SCHEMA, "list_histogram", {"l", nullptr}, "list_aggr(l, 'histogram')"},
133
133
 
134
+ // date functions
135
+ {DEFAULT_SCHEMA, "date_add", {"date", "interval", nullptr}, "date + interval"},
136
+
134
137
  {nullptr, nullptr, {nullptr}, nullptr}
135
138
  };
136
139
 
@@ -46,32 +46,59 @@ bool DuckCatalog::IsDuckCatalog() {
46
46
  //===--------------------------------------------------------------------===//
47
47
  // Schema
48
48
  //===--------------------------------------------------------------------===//
49
- CatalogEntry *DuckCatalog::CreateSchema(CatalogTransaction transaction, CreateSchemaInfo *info) {
50
- D_ASSERT(!info->schema.empty());
49
+ CatalogEntry *DuckCatalog::CreateSchemaInternal(CatalogTransaction transaction, CreateSchemaInfo *info) {
51
50
  DependencyList dependencies;
52
51
  auto entry = make_unique<DuckSchemaEntry>(this, info->schema, info->internal);
53
52
  auto result = entry.get();
54
53
  if (!schemas->CreateEntry(transaction, info->schema, std::move(entry), dependencies)) {
55
- if (info->on_conflict == OnCreateConflict::ERROR_ON_CONFLICT) {
54
+ return nullptr;
55
+ }
56
+ return (CatalogEntry *)result;
57
+ }
58
+
59
+ CatalogEntry *DuckCatalog::CreateSchema(CatalogTransaction transaction, CreateSchemaInfo *info) {
60
+ D_ASSERT(!info->schema.empty());
61
+ auto result = CreateSchemaInternal(transaction, info);
62
+ if (!result) {
63
+ switch (info->on_conflict) {
64
+ case OnCreateConflict::ERROR_ON_CONFLICT:
56
65
  throw CatalogException("Schema with name %s already exists!", info->schema);
57
- } else {
58
- D_ASSERT(info->on_conflict == OnCreateConflict::IGNORE_ON_CONFLICT);
66
+ case OnCreateConflict::REPLACE_ON_CONFLICT: {
67
+ DropInfo drop_info;
68
+ drop_info.type = CatalogType::SCHEMA_ENTRY;
69
+ drop_info.catalog = info->catalog;
70
+ drop_info.name = info->schema;
71
+ DropSchema(transaction, &drop_info);
72
+ result = CreateSchemaInternal(transaction, info);
73
+ if (!result) {
74
+ throw InternalException("Failed to create schema entry in CREATE_OR_REPLACE");
75
+ }
76
+ break;
77
+ }
78
+ case OnCreateConflict::IGNORE_ON_CONFLICT:
79
+ break;
80
+ default:
81
+ throw InternalException("Unsupported OnCreateConflict for CreateSchema");
59
82
  }
60
83
  return nullptr;
61
84
  }
62
85
  return result;
63
86
  }
64
87
 
65
- void DuckCatalog::DropSchema(ClientContext &context, DropInfo *info) {
88
+ void DuckCatalog::DropSchema(CatalogTransaction transaction, DropInfo *info) {
66
89
  D_ASSERT(!info->name.empty());
67
90
  ModifyCatalog();
68
- if (!schemas->DropEntry(GetCatalogTransaction(context), info->name, info->cascade)) {
91
+ if (!schemas->DropEntry(transaction, info->name, info->cascade)) {
69
92
  if (!info->if_exists) {
70
93
  throw CatalogException("Schema with name \"%s\" does not exist!", info->name);
71
94
  }
72
95
  }
73
96
  }
74
97
 
98
+ void DuckCatalog::DropSchema(ClientContext &context, DropInfo *info) {
99
+ DropSchema(GetCatalogTransaction(context), info);
100
+ }
101
+
75
102
  void DuckCatalog::ScanSchemas(ClientContext &context, std::function<void(CatalogEntry *)> callback) {
76
103
  schemas->Scan(GetCatalogTransaction(context), [&](CatalogEntry *entry) { callback(entry); });
77
104
  }
@@ -197,6 +197,60 @@ list<ColumnDataCollection> BoxRenderer::FetchRenderCollections(ClientContext &co
197
197
  return collections;
198
198
  }
199
199
 
200
+ list<ColumnDataCollection> BoxRenderer::PivotCollections(ClientContext &context, list<ColumnDataCollection> input,
201
+ vector<string> &column_names,
202
+ vector<LogicalType> &result_types, idx_t row_count) {
203
+ auto &top = input.front();
204
+ auto &bottom = input.back();
205
+
206
+ vector<LogicalType> varchar_types;
207
+ vector<string> new_names;
208
+ new_names.emplace_back("Column");
209
+ new_names.emplace_back("Type");
210
+ varchar_types.emplace_back(LogicalType::VARCHAR);
211
+ varchar_types.emplace_back(LogicalType::VARCHAR);
212
+ for (idx_t r = 0; r < top.Count(); r++) {
213
+ new_names.emplace_back("Row " + to_string(r + 1));
214
+ varchar_types.emplace_back(LogicalType::VARCHAR);
215
+ }
216
+ for (idx_t r = 0; r < bottom.Count(); r++) {
217
+ auto row_index = row_count - bottom.Count() + r + 1;
218
+ new_names.emplace_back("Row " + to_string(row_index));
219
+ varchar_types.emplace_back(LogicalType::VARCHAR);
220
+ }
221
+ //
222
+ DataChunk row_chunk;
223
+ row_chunk.Initialize(Allocator::DefaultAllocator(), varchar_types);
224
+ std::list<ColumnDataCollection> result;
225
+ result.emplace_back(context, varchar_types);
226
+ result.emplace_back(context, varchar_types);
227
+ auto &res_coll = result.front();
228
+ ColumnDataAppendState append_state;
229
+ res_coll.InitializeAppend(append_state);
230
+ for (idx_t c = 0; c < top.ColumnCount(); c++) {
231
+ vector<column_t> column_ids {c};
232
+ auto row_index = row_chunk.size();
233
+ idx_t current_index = 0;
234
+ row_chunk.SetValue(current_index++, row_index, column_names[c]);
235
+ row_chunk.SetValue(current_index++, row_index, RenderType(result_types[c]));
236
+ for (auto &collection : input) {
237
+ for (auto &chunk : collection.Chunks(column_ids)) {
238
+ for (idx_t r = 0; r < chunk.size(); r++) {
239
+ row_chunk.SetValue(current_index++, row_index, chunk.GetValue(0, r));
240
+ }
241
+ }
242
+ }
243
+ row_chunk.SetCardinality(row_chunk.size() + 1);
244
+ if (row_chunk.size() == STANDARD_VECTOR_SIZE || c + 1 == top.ColumnCount()) {
245
+ res_coll.Append(append_state, row_chunk);
246
+ row_chunk.Reset();
247
+ }
248
+ }
249
+ column_names = std::move(new_names);
250
+ result_types = std::move(varchar_types);
251
+ return result;
252
+ }
253
+
200
254
  string ConvertRenderValue(const string &input) {
201
255
  return StringUtil::Replace(StringUtil::Replace(input, "\n", "\\n"), string("\0", 1), "\\0");
202
256
  }
@@ -213,11 +267,10 @@ string BoxRenderer::GetRenderValue(ColumnDataRowCollection &rows, idx_t c, idx_t
213
267
  }
214
268
  }
215
269
 
216
- vector<idx_t> BoxRenderer::ComputeRenderWidths(const vector<string> &names, const ColumnDataCollection &result,
270
+ vector<idx_t> BoxRenderer::ComputeRenderWidths(const vector<string> &names, const vector<LogicalType> &result_types,
217
271
  list<ColumnDataCollection> &collections, idx_t min_width,
218
272
  idx_t max_width, vector<idx_t> &column_map, idx_t &total_length) {
219
- auto column_count = result.ColumnCount();
220
- auto &result_types = result.Types();
273
+ auto column_count = result_types.size();
221
274
 
222
275
  vector<idx_t> widths;
223
276
  widths.reserve(column_count);
@@ -357,13 +410,15 @@ void BoxRenderer::RenderHeader(const vector<string> &names, const vector<Logical
357
410
  ss << std::endl;
358
411
 
359
412
  // render the types
360
- for (idx_t c = 0; c < column_count; c++) {
361
- auto column_idx = column_map[c];
362
- auto type = column_idx == SPLIT_COLUMN ? "" : RenderType(result_types[column_idx]);
363
- RenderValue(ss, type, widths[c]);
413
+ if (config.render_mode == RenderMode::ROWS) {
414
+ for (idx_t c = 0; c < column_count; c++) {
415
+ auto column_idx = column_map[c];
416
+ auto type = column_idx == SPLIT_COLUMN ? "" : RenderType(result_types[column_idx]);
417
+ RenderValue(ss, type, widths[c]);
418
+ }
419
+ ss << config.VERTICAL;
420
+ ss << std::endl;
364
421
  }
365
- ss << config.VERTICAL;
366
- ss << std::endl;
367
422
 
368
423
  // render the line under the header
369
424
  ss << config.LMIDDLE;
@@ -390,12 +445,14 @@ void BoxRenderer::RenderValues(const list<ColumnDataCollection> &collections, co
390
445
  auto column_count = column_map.size();
391
446
 
392
447
  vector<ValueRenderAlignment> alignments;
393
- for (idx_t c = 0; c < column_count; c++) {
394
- auto column_idx = column_map[c];
395
- if (column_idx == SPLIT_COLUMN) {
396
- alignments.push_back(ValueRenderAlignment::MIDDLE);
397
- } else {
398
- alignments.push_back(TypeAlignment(result_types[column_idx]));
448
+ if (config.render_mode == RenderMode::ROWS) {
449
+ for (idx_t c = 0; c < column_count; c++) {
450
+ auto column_idx = column_map[c];
451
+ if (column_idx == SPLIT_COLUMN) {
452
+ alignments.push_back(ValueRenderAlignment::MIDDLE);
453
+ } else {
454
+ alignments.push_back(TypeAlignment(result_types[column_idx]));
455
+ }
399
456
  }
400
457
  }
401
458
 
@@ -409,13 +466,28 @@ void BoxRenderer::RenderValues(const list<ColumnDataCollection> &collections, co
409
466
  } else {
410
467
  str = GetRenderValue(rows, column_idx, r);
411
468
  }
412
- RenderValue(ss, str, widths[c], alignments[c]);
469
+ ValueRenderAlignment alignment;
470
+ if (config.render_mode == RenderMode::ROWS) {
471
+ alignment = alignments[c];
472
+ } else {
473
+ if (c < 2) {
474
+ alignment = ValueRenderAlignment::LEFT;
475
+ } else if (c == SPLIT_COLUMN) {
476
+ alignment = ValueRenderAlignment::MIDDLE;
477
+ } else {
478
+ alignment = ValueRenderAlignment::RIGHT;
479
+ }
480
+ }
481
+ RenderValue(ss, str, widths[c], alignment);
413
482
  }
414
483
  ss << config.VERTICAL;
415
484
  ss << std::endl;
416
485
  }
417
486
 
418
487
  if (bottom_rows > 0) {
488
+ if (config.render_mode == RenderMode::COLUMNS) {
489
+ throw InternalException("Columns render mode does not support bottom rows");
490
+ }
419
491
  // render the bottom rows
420
492
  // first render the divider
421
493
  auto brows = bottom_collection.GetRows();
@@ -607,15 +679,19 @@ void BoxRenderer::Render(ClientContext &context, const vector<string> &names, co
607
679
 
608
680
  // fetch the top and bottom render collections from the result
609
681
  auto collections = FetchRenderCollections(context, result, top_rows, bottom_rows);
610
-
611
- auto &result_types = result.Types();
682
+ auto column_names = names;
683
+ auto result_types = result.Types();
684
+ if (config.render_mode == RenderMode::COLUMNS) {
685
+ collections = PivotCollections(context, std::move(collections), column_names, result_types, row_count);
686
+ }
612
687
 
613
688
  // for each column, figure out the width
614
689
  // start off by figuring out the name of the header by looking at the column name and column type
615
690
  idx_t min_width = has_hidden_rows || row_count == 0 ? minimum_row_length : 0;
616
691
  vector<idx_t> column_map;
617
692
  idx_t total_length;
618
- auto widths = ComputeRenderWidths(names, result, collections, min_width, max_width, column_map, total_length);
693
+ auto widths =
694
+ ComputeRenderWidths(column_names, result_types, collections, min_width, max_width, column_map, total_length);
619
695
 
620
696
  // render boundaries for the individual columns
621
697
  vector<idx_t> boundaries;
@@ -631,7 +707,7 @@ void BoxRenderer::Render(ClientContext &context, const vector<string> &names, co
631
707
 
632
708
  // now begin rendering
633
709
  // first render the header
634
- RenderHeader(names, result_types, column_map, widths, boundaries, total_length, row_count > 0, ss);
710
+ RenderHeader(column_names, result_types, column_map, widths, boundaries, total_length, row_count > 0, ss);
635
711
 
636
712
  // render the values, if there are any
637
713
  RenderValues(collections, column_map, widths, result_types, ss);
@@ -649,10 +725,20 @@ void BoxRenderer::Render(ClientContext &context, const vector<string> &names, co
649
725
  }
650
726
  }
651
727
  idx_t column_count = column_map.size();
652
- if (has_hidden_columns) {
653
- column_count--;
654
- column_count_str += " (" + to_string(column_count) + " shown)";
728
+ if (config.render_mode == RenderMode::COLUMNS) {
729
+ if (has_hidden_columns) {
730
+ has_hidden_rows = true;
731
+ shown_str = " (" + to_string(column_count - 3) + " shown)";
732
+ } else {
733
+ shown_str = string();
734
+ }
735
+ } else {
736
+ if (has_hidden_columns) {
737
+ column_count--;
738
+ column_count_str += " (" + to_string(column_count) + " shown)";
739
+ }
655
740
  }
741
+
656
742
  RenderRowCount(std::move(row_count_str), std::move(shown_str), column_count_str, boundaries, has_hidden_rows,
657
743
  has_hidden_columns, total_length, row_count, column_count, minimum_row_length, ss);
658
744
  }
@@ -1233,99 +1233,6 @@ interval_t Value::GetValueUnsafe() const {
1233
1233
  return value_.interval;
1234
1234
  }
1235
1235
 
1236
- //===--------------------------------------------------------------------===//
1237
- // GetReferenceUnsafe
1238
- //===--------------------------------------------------------------------===//
1239
- template <>
1240
- int8_t &Value::GetReferenceUnsafe() {
1241
- D_ASSERT(type_.InternalType() == PhysicalType::INT8 || type_.InternalType() == PhysicalType::BOOL);
1242
- return value_.tinyint;
1243
- }
1244
-
1245
- template <>
1246
- int16_t &Value::GetReferenceUnsafe() {
1247
- D_ASSERT(type_.InternalType() == PhysicalType::INT16);
1248
- return value_.smallint;
1249
- }
1250
-
1251
- template <>
1252
- int32_t &Value::GetReferenceUnsafe() {
1253
- D_ASSERT(type_.InternalType() == PhysicalType::INT32);
1254
- return value_.integer;
1255
- }
1256
-
1257
- template <>
1258
- int64_t &Value::GetReferenceUnsafe() {
1259
- D_ASSERT(type_.InternalType() == PhysicalType::INT64);
1260
- return value_.bigint;
1261
- }
1262
-
1263
- template <>
1264
- hugeint_t &Value::GetReferenceUnsafe() {
1265
- D_ASSERT(type_.InternalType() == PhysicalType::INT128);
1266
- return value_.hugeint;
1267
- }
1268
-
1269
- template <>
1270
- uint8_t &Value::GetReferenceUnsafe() {
1271
- D_ASSERT(type_.InternalType() == PhysicalType::UINT8);
1272
- return value_.utinyint;
1273
- }
1274
-
1275
- template <>
1276
- uint16_t &Value::GetReferenceUnsafe() {
1277
- D_ASSERT(type_.InternalType() == PhysicalType::UINT16);
1278
- return value_.usmallint;
1279
- }
1280
-
1281
- template <>
1282
- uint32_t &Value::GetReferenceUnsafe() {
1283
- D_ASSERT(type_.InternalType() == PhysicalType::UINT32);
1284
- return value_.uinteger;
1285
- }
1286
-
1287
- template <>
1288
- uint64_t &Value::GetReferenceUnsafe() {
1289
- D_ASSERT(type_.InternalType() == PhysicalType::UINT64);
1290
- return value_.ubigint;
1291
- }
1292
-
1293
- template <>
1294
- float &Value::GetReferenceUnsafe() {
1295
- D_ASSERT(type_.InternalType() == PhysicalType::FLOAT);
1296
- return value_.float_;
1297
- }
1298
-
1299
- template <>
1300
- double &Value::GetReferenceUnsafe() {
1301
- D_ASSERT(type_.InternalType() == PhysicalType::DOUBLE);
1302
- return value_.double_;
1303
- }
1304
-
1305
- template <>
1306
- date_t &Value::GetReferenceUnsafe() {
1307
- D_ASSERT(type_.InternalType() == PhysicalType::INT32);
1308
- return value_.date;
1309
- }
1310
-
1311
- template <>
1312
- dtime_t &Value::GetReferenceUnsafe() {
1313
- D_ASSERT(type_.InternalType() == PhysicalType::INT64);
1314
- return value_.time;
1315
- }
1316
-
1317
- template <>
1318
- timestamp_t &Value::GetReferenceUnsafe() {
1319
- D_ASSERT(type_.InternalType() == PhysicalType::INT64);
1320
- return value_.timestamp;
1321
- }
1322
-
1323
- template <>
1324
- interval_t &Value::GetReferenceUnsafe() {
1325
- D_ASSERT(type_.InternalType() == PhysicalType::INTERVAL);
1326
- return value_.interval;
1327
- }
1328
-
1329
1236
  //===--------------------------------------------------------------------===//
1330
1237
  // Hash
1331
1238
  //===--------------------------------------------------------------------===//
@@ -111,6 +111,9 @@ SinkResultType PhysicalLimit::Sink(ExecutionContext &context, GlobalSinkState &g
111
111
  }
112
112
  state.data.Append(input, lstate.batch_index);
113
113
  state.current_offset += input.size();
114
+ if (state.current_offset == max_element) {
115
+ return SinkResultType::FINISHED;
116
+ }
114
117
  return SinkResultType::NEED_MORE_INPUT;
115
118
  }
116
119
 
@@ -73,20 +73,17 @@ static bool CanUsePerfectHashAggregate(ClientContext &context, LogicalAggregate
73
73
  int64_t range;
74
74
  switch (group_type.InternalType()) {
75
75
  case PhysicalType::INT8:
76
- range = int64_t(NumericStats::GetMaxUnsafe<int8_t>(nstats)) -
77
- int64_t(NumericStats::GetMinUnsafe<int8_t>(nstats));
76
+ range = int64_t(NumericStats::GetMax<int8_t>(nstats)) - int64_t(NumericStats::GetMin<int8_t>(nstats));
78
77
  break;
79
78
  case PhysicalType::INT16:
80
- range = int64_t(NumericStats::GetMaxUnsafe<int16_t>(nstats)) -
81
- int64_t(NumericStats::GetMinUnsafe<int16_t>(nstats));
79
+ range = int64_t(NumericStats::GetMax<int16_t>(nstats)) - int64_t(NumericStats::GetMin<int16_t>(nstats));
82
80
  break;
83
81
  case PhysicalType::INT32:
84
- range = int64_t(NumericStats::GetMaxUnsafe<int32_t>(nstats)) -
85
- int64_t(NumericStats::GetMinUnsafe<int32_t>(nstats));
82
+ range = int64_t(NumericStats::GetMax<int32_t>(nstats)) - int64_t(NumericStats::GetMin<int32_t>(nstats));
86
83
  break;
87
84
  case PhysicalType::INT64:
88
- if (!TrySubtractOperator::Operation(NumericStats::GetMaxUnsafe<int64_t>(nstats),
89
- NumericStats::GetMinUnsafe<int64_t>(nstats), range)) {
85
+ if (!TrySubtractOperator::Operation(NumericStats::GetMax<int64_t>(nstats),
86
+ NumericStats::GetMin<int64_t>(nstats), range)) {
90
87
  return false;
91
88
  }
92
89
  break;
@@ -180,8 +180,8 @@ struct DatePart {
180
180
  return nullptr;
181
181
  }
182
182
  // run the operator on both the min and the max, this gives us the [min, max] bound
183
- auto min = NumericStats::GetMinUnsafe<T>(nstats);
184
- auto max = NumericStats::GetMaxUnsafe<T>(nstats);
183
+ auto min = NumericStats::GetMin<T>(nstats);
184
+ auto max = NumericStats::GetMax<T>(nstats);
185
185
  if (min > max) {
186
186
  return nullptr;
187
187
  }
@@ -594,8 +594,8 @@ static unique_ptr<BaseStatistics> DateTruncStatistics(vector<BaseStatistics> &ch
594
594
  return nullptr;
595
595
  }
596
596
  // run the operator on both the min and the max, this gives us the [min, max] bound
597
- auto min = NumericStats::GetMinUnsafe<TA>(nstats);
598
- auto max = NumericStats::GetMaxUnsafe<TA>(nstats);
597
+ auto min = NumericStats::GetMin<TA>(nstats);
598
+ auto max = NumericStats::GetMax<TA>(nstats);
599
599
  if (min > max) {
600
600
  return nullptr;
601
601
  }
@@ -507,7 +507,7 @@ ScalarFunction ListUniqueFun::GetFunction() {
507
507
  }
508
508
 
509
509
  void ListAggregateFun::RegisterFunction(BuiltinFunctions &set) {
510
- set.AddFunction({"list_aggregate", "array_aggregate", "list_aggr", "array_aggr"}, GetFunction());
510
+ set.AddFunction({"list_aggregate", "array_aggregate", "list_aggr", "array_aggr", "aggregate"}, GetFunction());
511
511
  }
512
512
 
513
513
  void ListDistinctFun::RegisterFunction(BuiltinFunctions &set) {
@@ -392,6 +392,8 @@ void ListTransformFun::RegisterFunction(BuiltinFunctions &set) {
392
392
  set.AddFunction(fun);
393
393
  fun.name = "array_apply";
394
394
  set.AddFunction(fun);
395
+ fun.name = "apply";
396
+ set.AddFunction(fun);
395
397
  }
396
398
 
397
399
  void ListFilterFun::RegisterFunction(BuiltinFunctions &set) {
@@ -405,6 +407,8 @@ void ListFilterFun::RegisterFunction(BuiltinFunctions &set) {
405
407
 
406
408
  fun.name = "array_filter";
407
409
  set.AddFunction(fun);
410
+ fun.name = "filter";
411
+ set.AddFunction(fun);
408
412
  }
409
413
 
410
414
  } // namespace duckdb
@@ -81,11 +81,11 @@ struct AddPropagateStatistics {
81
81
  Value &new_max) {
82
82
  T min, max;
83
83
  // new min is min+min
84
- if (!OP::Operation(NumericStats::GetMinUnsafe<T>(lstats), NumericStats::GetMinUnsafe<T>(rstats), min)) {
84
+ if (!OP::Operation(NumericStats::GetMin<T>(lstats), NumericStats::GetMin<T>(rstats), min)) {
85
85
  return true;
86
86
  }
87
87
  // new max is max+max
88
- if (!OP::Operation(NumericStats::GetMaxUnsafe<T>(lstats), NumericStats::GetMaxUnsafe<T>(rstats), max)) {
88
+ if (!OP::Operation(NumericStats::GetMax<T>(lstats), NumericStats::GetMax<T>(rstats), max)) {
89
89
  return true;
90
90
  }
91
91
  new_min = Value::Numeric(type, min);
@@ -99,10 +99,10 @@ struct SubtractPropagateStatistics {
99
99
  static bool Operation(LogicalType type, BaseStatistics &lstats, BaseStatistics &rstats, Value &new_min,
100
100
  Value &new_max) {
101
101
  T min, max;
102
- if (!OP::Operation(NumericStats::GetMinUnsafe<T>(lstats), NumericStats::GetMaxUnsafe<T>(rstats), min)) {
102
+ if (!OP::Operation(NumericStats::GetMin<T>(lstats), NumericStats::GetMax<T>(rstats), min)) {
103
103
  return true;
104
104
  }
105
- if (!OP::Operation(NumericStats::GetMaxUnsafe<T>(lstats), NumericStats::GetMinUnsafe<T>(rstats), max)) {
105
+ if (!OP::Operation(NumericStats::GetMax<T>(lstats), NumericStats::GetMin<T>(rstats), max)) {
106
106
  return true;
107
107
  }
108
108
  new_min = Value::Numeric(type, min);
@@ -489,8 +489,8 @@ unique_ptr<FunctionData> DecimalNegateBind(ClientContext &context, ScalarFunctio
489
489
  struct NegatePropagateStatistics {
490
490
  template <class T>
491
491
  static bool Operation(LogicalType type, BaseStatistics &istats, Value &new_min, Value &new_max) {
492
- auto max_value = NumericStats::GetMaxUnsafe<T>(istats);
493
- auto min_value = NumericStats::GetMinUnsafe<T>(istats);
492
+ auto max_value = NumericStats::GetMax<T>(istats);
493
+ auto min_value = NumericStats::GetMin<T>(istats);
494
494
  if (!NegateOperator::CanNegate<T>(min_value) || !NegateOperator::CanNegate<T>(max_value)) {
495
495
  return true;
496
496
  }
@@ -664,8 +664,8 @@ struct MultiplyPropagateStatistics {
664
664
  // etc
665
665
  // rather than doing all this switcheroo we just multiply all combinations of lmin/lmax with rmin/rmax
666
666
  // and check what the minimum/maximum value is
667
- T lvals[] {NumericStats::GetMinUnsafe<T>(lstats), NumericStats::GetMaxUnsafe<T>(lstats)};
668
- T rvals[] {NumericStats::GetMinUnsafe<T>(rstats), NumericStats::GetMaxUnsafe<T>(rstats)};
667
+ T lvals[] {NumericStats::GetMin<T>(lstats), NumericStats::GetMax<T>(lstats)};
668
+ T rvals[] {NumericStats::GetMin<T>(rstats), NumericStats::GetMax<T>(rstats)};
669
669
  T min = NumericLimits<T>::Maximum();
670
670
  T max = NumericLimits<T>::Minimum();
671
671
  // multiplications
@@ -1,8 +1,8 @@
1
1
  #ifndef DUCKDB_VERSION
2
- #define DUCKDB_VERSION "0.7.2-dev832"
2
+ #define DUCKDB_VERSION "0.7.2-dev886"
3
3
  #endif
4
4
  #ifndef DUCKDB_SOURCE_ID
5
- #define DUCKDB_SOURCE_ID "a12329e657"
5
+ #define DUCKDB_SOURCE_ID "7d73c6e6a8"
6
6
  #endif
7
7
  #include "duckdb/function/table/system_functions.hpp"
8
8
  #include "duckdb/main/database.hpp"
@@ -14,6 +14,7 @@
14
14
  #include "duckdb/catalog/catalog_transaction.hpp"
15
15
  #include "duckdb/common/unordered_set.hpp"
16
16
  #include "duckdb/common/atomic.hpp"
17
+ #include "duckdb/common/optional_ptr.hpp"
17
18
 
18
19
  #include <functional>
19
20
 
@@ -80,6 +81,8 @@ public:
80
81
  DUCKDB_API static Catalog &GetCatalog(ClientContext &context, const string &catalog_name);
81
82
  //! Get the specified Catalog from the DatabaseInstance
82
83
  DUCKDB_API static Catalog &GetCatalog(DatabaseInstance &db, const string &catalog_name);
84
+ //! Gets the specified Catalog from the database if it exists
85
+ DUCKDB_API static optional_ptr<Catalog> GetCatalogEntry(ClientContext &context, const string &catalog_name);
83
86
  //! Get the specific Catalog from the AttachedDatabase
84
87
  DUCKDB_API static Catalog &GetCatalog(AttachedDatabase &db);
85
88
 
@@ -59,8 +59,9 @@ public:
59
59
  DUCKDB_API string GetDBPath() override;
60
60
 
61
61
  private:
62
+ DUCKDB_API void DropSchema(CatalogTransaction transaction, DropInfo *info);
62
63
  DUCKDB_API void DropSchema(ClientContext &context, DropInfo *info) override;
63
-
64
+ CatalogEntry *CreateSchemaInternal(CatalogTransaction transaction, CreateSchemaInfo *info);
64
65
  void Verify() override;
65
66
 
66
67
  private:
@@ -18,6 +18,7 @@ class ColumnDataCollection;
18
18
  class ColumnDataRowCollection;
19
19
 
20
20
  enum class ValueRenderAlignment { LEFT, MIDDLE, RIGHT };
21
+ enum class RenderMode { ROWS, COLUMNS };
21
22
 
22
23
  struct BoxRendererConfig {
23
24
  // a max_width of 0 means we default to the terminal width
@@ -30,7 +31,10 @@ struct BoxRendererConfig {
30
31
  // the max col width determines the maximum size of a single column
31
32
  // note that the max col width is only used if the result does not fit on the screen
32
33
  idx_t max_col_width = 20;
34
+ //! how to render NULL values
33
35
  string null_value = "NULL";
36
+ //! Whether or not to render row-wise or column-wise
37
+ RenderMode render_mode = RenderMode::ROWS;
34
38
 
35
39
  #ifndef DUCKDB_ASCII_TREE_RENDERER
36
40
  const char *LTCORNER = "\342\224\214"; // "┌";
@@ -94,10 +98,12 @@ private:
94
98
  string RenderType(const LogicalType &type);
95
99
  ValueRenderAlignment TypeAlignment(const LogicalType &type);
96
100
  string GetRenderValue(ColumnDataRowCollection &rows, idx_t c, idx_t r);
97
-
98
101
  list<ColumnDataCollection> FetchRenderCollections(ClientContext &context, const ColumnDataCollection &result,
99
102
  idx_t top_rows, idx_t bottom_rows);
100
- vector<idx_t> ComputeRenderWidths(const vector<string> &names, const ColumnDataCollection &result,
103
+ list<ColumnDataCollection> PivotCollections(ClientContext &context, list<ColumnDataCollection> input,
104
+ vector<string> &column_names, vector<LogicalType> &result_types,
105
+ idx_t row_count);
106
+ vector<idx_t> ComputeRenderWidths(const vector<string> &names, const vector<LogicalType> &result_types,
101
107
  list<ColumnDataCollection> &collections, idx_t min_width, idx_t max_width,
102
108
  vector<idx_t> &column_map, idx_t &total_length);
103
109
  void RenderHeader(const vector<string> &names, const vector<LogicalType> &result_types,