duckdb 0.6.1-dev5.0 → 0.6.1-dev71.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
@@ -2,7 +2,7 @@
2
2
  "name": "duckdb",
3
3
  "main": "./lib/duckdb.js",
4
4
  "types": "./lib/duckdb.d.ts",
5
- "version": "0.6.1-dev5.0",
5
+ "version": "0.6.1-dev71.0",
6
6
  "description": "DuckDB node.js API",
7
7
  "gypfile": true,
8
8
  "dependencies": {
package/src/duckdb.cpp CHANGED
@@ -6493,6 +6493,9 @@ AllocatedData::AllocatedData() : allocator(nullptr), pointer(nullptr), allocated
6493
6493
 
6494
6494
  AllocatedData::AllocatedData(Allocator &allocator, data_ptr_t pointer, idx_t allocated_size)
6495
6495
  : allocator(&allocator), pointer(pointer), allocated_size(allocated_size) {
6496
+ if (!pointer) {
6497
+ throw InternalException("AllocatedData object constructed with nullptr");
6498
+ }
6496
6499
  }
6497
6500
  AllocatedData::~AllocatedData() {
6498
6501
  Reset();
@@ -6584,11 +6587,19 @@ Allocator::~Allocator() {
6584
6587
 
6585
6588
  data_ptr_t Allocator::AllocateData(idx_t size) {
6586
6589
  D_ASSERT(size > 0);
6590
+ if (size >= MAXIMUM_ALLOC_SIZE) {
6591
+ D_ASSERT(false);
6592
+ throw InternalException("Requested allocation size of %llu is out of range - maximum allocation size is %llu",
6593
+ size, MAXIMUM_ALLOC_SIZE);
6594
+ }
6587
6595
  auto result = allocate_function(private_data.get(), size);
6588
6596
  #ifdef DEBUG
6589
6597
  D_ASSERT(private_data);
6590
6598
  private_data->debug_info->AllocateData(result, size);
6591
6599
  #endif
6600
+ if (!result) {
6601
+ throw std::bad_alloc();
6602
+ }
6592
6603
  return result;
6593
6604
  }
6594
6605
 
@@ -6608,11 +6619,20 @@ data_ptr_t Allocator::ReallocateData(data_ptr_t pointer, idx_t old_size, idx_t s
6608
6619
  if (!pointer) {
6609
6620
  return nullptr;
6610
6621
  }
6622
+ if (size >= MAXIMUM_ALLOC_SIZE) {
6623
+ D_ASSERT(false);
6624
+ throw InternalException(
6625
+ "Requested re-allocation size of %llu is out of range - maximum allocation size is %llu", size,
6626
+ MAXIMUM_ALLOC_SIZE);
6627
+ }
6611
6628
  auto new_pointer = reallocate_function(private_data.get(), pointer, old_size, size);
6612
6629
  #ifdef DEBUG
6613
6630
  D_ASSERT(private_data);
6614
6631
  private_data->debug_info->ReallocateData(pointer, new_pointer, old_size, size);
6615
6632
  #endif
6633
+ if (!new_pointer) {
6634
+ throw std::bad_alloc();
6635
+ }
6616
6636
  return new_pointer;
6617
6637
  }
6618
6638
 
@@ -18593,6 +18613,7 @@ FileType FileHandle::GetType() {
18593
18613
 
18594
18614
 
18595
18615
 
18616
+
18596
18617
  #include <limits>
18597
18618
  #include <cstring>
18598
18619
  #include <cmath>
@@ -22487,6 +22508,7 @@ unique_ptr<FileSystem> FileSystem::CreateLocal() {
22487
22508
 
22488
22509
 
22489
22510
 
22511
+
22490
22512
  namespace duckdb {
22491
22513
 
22492
22514
  struct ConvertToString {
@@ -24109,8 +24131,11 @@ string_t StringCastFromDecimal::Operation(hugeint_t input, uint8_t width, uint8_
24109
24131
 
24110
24132
 
24111
24133
 
24134
+
24112
24135
  namespace duckdb {
24113
24136
 
24137
+ struct interval_t;
24138
+
24114
24139
  struct MultiplyOperator {
24115
24140
  template <class TA, class TB, class TR>
24116
24141
  static inline TR Operation(TA left, TB right) {
@@ -45487,6 +45512,7 @@ string Decimal::ToString(hugeint_t value, uint8_t width, uint8_t scale) {
45487
45512
 
45488
45513
 
45489
45514
 
45515
+
45490
45516
  #include <functional>
45491
45517
  #include <cmath>
45492
45518
 
@@ -45627,6 +45653,7 @@ hash_t Hash(uint8_t *val, size_t size) {
45627
45653
 
45628
45654
 
45629
45655
 
45656
+
45630
45657
  #include <cmath>
45631
45658
  #include <limits>
45632
45659
 
@@ -46121,6 +46148,13 @@ bool Hugeint::TryConvert(int8_t value, hugeint_t &result) {
46121
46148
  return true;
46122
46149
  }
46123
46150
 
46151
+ template <>
46152
+ bool Hugeint::TryConvert(const char *value, hugeint_t &result) {
46153
+ auto len = strlen(value);
46154
+ string_t string_val(value, len);
46155
+ return TryCast::Operation<string_t, hugeint_t>(string_val, result, true);
46156
+ }
46157
+
46124
46158
  template <>
46125
46159
  bool Hugeint::TryConvert(int16_t value, hugeint_t &result) {
46126
46160
  result = HugeintConvertInteger<int16_t>(value);
@@ -46720,6 +46754,7 @@ DUCKDB_API DatePartSpecifier GetDatePartSpecifier(const string &specifier);
46720
46754
 
46721
46755
 
46722
46756
 
46757
+
46723
46758
  namespace duckdb {
46724
46759
 
46725
46760
  struct AddOperator {
@@ -46847,8 +46882,14 @@ dtime_t AddTimeOperator::Operation(interval_t left, dtime_t right);
46847
46882
 
46848
46883
 
46849
46884
 
46885
+
46850
46886
  namespace duckdb {
46851
46887
 
46888
+ struct interval_t;
46889
+ struct date_t;
46890
+ struct timestamp_t;
46891
+ struct dtime_t;
46892
+
46852
46893
  struct SubtractOperator {
46853
46894
  template <class TA, class TB, class TR>
46854
46895
  static inline TR Operation(TA left, TB right) {
@@ -82307,6 +82348,7 @@ public:
82307
82348
 
82308
82349
 
82309
82350
 
82351
+
82310
82352
  namespace duckdb {
82311
82353
 
82312
82354
  PhysicalBatchInsert::PhysicalBatchInsert(vector<LogicalType> types, TableCatalogEntry *table,
@@ -82349,22 +82391,9 @@ public:
82349
82391
  if (Empty()) {
82350
82392
  return nullptr;
82351
82393
  }
82352
- unique_ptr<RowGroupCollection> new_collection;
82353
- if (current_collections.size() == 1) {
82354
- // we have gathered only one row group collection: merge it directly
82355
- new_collection = move(current_collections[0]);
82356
- } else {
82394
+ unique_ptr<RowGroupCollection> new_collection = move(current_collections[0]);
82395
+ if (current_collections.size() > 1) {
82357
82396
  // we have gathered multiple collections: create one big collection and merge that
82358
- // find the biggest collection
82359
- idx_t biggest_index = 0;
82360
- for (idx_t i = 1; i < current_collections.size(); i++) {
82361
- D_ASSERT(current_collections[i]);
82362
- if (current_collections[i]->GetTotalRows() > current_collections[biggest_index]->GetTotalRows()) {
82363
- biggest_index = i;
82364
- }
82365
- }
82366
- // now append all the other collections to this collection
82367
- new_collection = move(current_collections[biggest_index]);
82368
82397
  auto &types = new_collection->GetTypes();
82369
82398
  TableAppendState append_state;
82370
82399
  new_collection->InitializeAppend(append_state);
@@ -106724,16 +106753,16 @@ struct StructDatePart {
106724
106753
  const auto idx = rdata.sel->get_index(i);
106725
106754
  if (arg_valid.RowIsValid(idx)) {
106726
106755
  if (Value::IsFinite(tdata[idx])) {
106727
- DatePart::StructOperator::Operation(part_values.data(), tdata[idx], idx, part_mask);
106756
+ DatePart::StructOperator::Operation(part_values.data(), tdata[idx], i, part_mask);
106728
106757
  } else {
106729
106758
  for (auto &child_entry : child_entries) {
106730
- FlatVector::Validity(*child_entry).SetInvalid(idx);
106759
+ FlatVector::Validity(*child_entry).SetInvalid(i);
106731
106760
  }
106732
106761
  }
106733
106762
  } else {
106734
- res_valid.SetInvalid(idx);
106763
+ res_valid.SetInvalid(i);
106735
106764
  for (auto &child_entry : child_entries) {
106736
- FlatVector::Validity(*child_entry).SetInvalid(idx);
106765
+ FlatVector::Validity(*child_entry).SetInvalid(i);
106737
106766
  }
106738
106767
  }
106739
106768
  }
@@ -131298,14 +131327,16 @@ void UDFWrapper::RegisterAggrFunction(AggregateFunction aggr_function, ClientCon
131298
131327
 
131299
131328
 
131300
131329
 
131330
+
131301
131331
  namespace duckdb {
131302
131332
 
131303
- BaseAppender::BaseAppender(Allocator &allocator) : allocator(allocator), column(0) {
131333
+ BaseAppender::BaseAppender(Allocator &allocator, AppenderType type_p)
131334
+ : allocator(allocator), column(0), appender_type(type_p) {
131304
131335
  }
131305
131336
 
131306
- BaseAppender::BaseAppender(Allocator &allocator_p, vector<LogicalType> types_p)
131337
+ BaseAppender::BaseAppender(Allocator &allocator_p, vector<LogicalType> types_p, AppenderType type_p)
131307
131338
  : allocator(allocator_p), types(move(types_p)), collection(make_unique<ColumnDataCollection>(allocator, types)),
131308
- column(0) {
131339
+ column(0), appender_type(type_p) {
131309
131340
  InitializeChunk();
131310
131341
  }
131311
131342
 
@@ -131325,7 +131356,8 @@ void BaseAppender::Destructor() {
131325
131356
  }
131326
131357
 
131327
131358
  InternalAppender::InternalAppender(ClientContext &context_p, TableCatalogEntry &table_p)
131328
- : BaseAppender(Allocator::DefaultAllocator(), table_p.GetTypes()), context(context_p), table(table_p) {
131359
+ : BaseAppender(Allocator::DefaultAllocator(), table_p.GetTypes(), AppenderType::PHYSICAL), context(context_p),
131360
+ table(table_p) {
131329
131361
  }
131330
131362
 
131331
131363
  InternalAppender::~InternalAppender() {
@@ -131333,7 +131365,7 @@ InternalAppender::~InternalAppender() {
131333
131365
  }
131334
131366
 
131335
131367
  Appender::Appender(Connection &con, const string &schema_name, const string &table_name)
131336
- : BaseAppender(Allocator::DefaultAllocator()), context(con.context) {
131368
+ : BaseAppender(Allocator::DefaultAllocator(), AppenderType::LOGICAL), context(con.context) {
131337
131369
  description = con.TableInfo(schema_name, table_name);
131338
131370
  if (!description) {
131339
131371
  // table could not be found
@@ -131377,6 +131409,27 @@ void BaseAppender::AppendValueInternal(Vector &col, SRC input) {
131377
131409
  FlatVector::GetData<DST>(col)[chunk.size()] = Cast::Operation<SRC, DST>(input);
131378
131410
  }
131379
131411
 
131412
+ template <class SRC, class DST>
131413
+ void BaseAppender::AppendDecimalValueInternal(Vector &col, SRC input) {
131414
+ switch (appender_type) {
131415
+ case AppenderType::LOGICAL: {
131416
+ auto &type = col.GetType();
131417
+ D_ASSERT(type.id() == LogicalTypeId::DECIMAL);
131418
+ auto width = DecimalType::GetWidth(type);
131419
+ auto scale = DecimalType::GetScale(type);
131420
+ TryCastToDecimal::Operation<SRC, DST>(input, FlatVector::GetData<DST>(col)[chunk.size()], nullptr, width,
131421
+ scale);
131422
+ return;
131423
+ }
131424
+ case AppenderType::PHYSICAL: {
131425
+ AppendValueInternal<SRC, DST>(col, input);
131426
+ return;
131427
+ }
131428
+ default:
131429
+ throw InternalException("Type not implemented for AppenderType");
131430
+ }
131431
+ }
131432
+
131380
131433
  template <class T>
131381
131434
  void BaseAppender::AppendValueInternal(T input) {
131382
131435
  if (column >= types.size()) {
@@ -131422,18 +131475,20 @@ void BaseAppender::AppendValueInternal(T input) {
131422
131475
  break;
131423
131476
  case LogicalTypeId::DECIMAL:
131424
131477
  switch (col.GetType().InternalType()) {
131425
- case PhysicalType::INT8:
131426
- AppendValueInternal<T, int8_t>(col, input);
131427
- break;
131428
131478
  case PhysicalType::INT16:
131429
- AppendValueInternal<T, int16_t>(col, input);
131479
+ AppendDecimalValueInternal<T, int16_t>(col, input);
131430
131480
  break;
131431
131481
  case PhysicalType::INT32:
131432
- AppendValueInternal<T, int32_t>(col, input);
131482
+ AppendDecimalValueInternal<T, int32_t>(col, input);
131433
131483
  break;
131434
- default:
131435
- AppendValueInternal<T, int64_t>(col, input);
131484
+ case PhysicalType::INT64:
131485
+ AppendDecimalValueInternal<T, int64_t>(col, input);
131486
+ break;
131487
+ case PhysicalType::INT128:
131488
+ AppendDecimalValueInternal<T, hugeint_t>(col, input);
131436
131489
  break;
131490
+ default:
131491
+ throw InternalException("Internal type not recognized for Decimal");
131437
131492
  }
131438
131493
  break;
131439
131494
  case LogicalTypeId::DATE:
@@ -138304,12 +138359,19 @@ public:
138304
138359
  //! Creates and caches a new DB Instance (Fails if a cached instance already exists)
138305
138360
  shared_ptr<DuckDB> CreateInstance(const string &database, DBConfig &config_dict, bool cache_instance = true);
138306
138361
 
138362
+ //! Creates and caches a new DB Instance (Fails if a cached instance already exists)
138363
+ shared_ptr<DuckDB> GetOrCreateInstance(const string &database, DBConfig &config_dict, bool cache_instance);
138364
+
138307
138365
  private:
138308
138366
  //! A map with the cached instances <absolute_path/instance>
138309
138367
  unordered_map<string, weak_ptr<DuckDB>> db_instances;
138310
138368
 
138311
138369
  //! Lock to alter cache
138312
138370
  mutex cache_lock;
138371
+
138372
+ private:
138373
+ shared_ptr<DuckDB> GetInstanceInternal(const string &database, const DBConfig &config_dict);
138374
+ shared_ptr<DuckDB> CreateInstanceInternal(const string &database, DBConfig &config_dict, bool cache_instance);
138313
138375
  };
138314
138376
  } // namespace duckdb
138315
138377
 
@@ -138330,8 +138392,7 @@ string GetDBAbsolutePath(const string &database) {
138330
138392
  return FileSystem::JoinPath(FileSystem::GetWorkingDirectory(), database);
138331
138393
  }
138332
138394
 
138333
- shared_ptr<DuckDB> DBInstanceCache::GetInstance(const string &database, const DBConfig &config) {
138334
- lock_guard<mutex> l(cache_lock);
138395
+ shared_ptr<DuckDB> DBInstanceCache::GetInstanceInternal(const string &database, const DBConfig &config) {
138335
138396
  shared_ptr<DuckDB> db_instance;
138336
138397
  auto abs_database_path = GetDBAbsolutePath(database);
138337
138398
  if (db_instances.find(abs_database_path) != db_instances.end()) {
@@ -138350,8 +138411,13 @@ shared_ptr<DuckDB> DBInstanceCache::GetInstance(const string &database, const DB
138350
138411
  return db_instance;
138351
138412
  }
138352
138413
 
138353
- shared_ptr<DuckDB> DBInstanceCache::CreateInstance(const string &database, DBConfig &config, bool cache_instance) {
138414
+ shared_ptr<DuckDB> DBInstanceCache::GetInstance(const string &database, const DBConfig &config) {
138354
138415
  lock_guard<mutex> l(cache_lock);
138416
+ return GetInstanceInternal(database, config);
138417
+ }
138418
+
138419
+ shared_ptr<DuckDB> DBInstanceCache::CreateInstanceInternal(const string &database, DBConfig &config,
138420
+ bool cache_instance) {
138355
138421
  auto abs_database_path = GetDBAbsolutePath(database);
138356
138422
  if (db_instances.find(abs_database_path) != db_instances.end()) {
138357
138423
  throw duckdb::Exception(ExceptionType::CONNECTION,
@@ -138369,6 +138435,23 @@ shared_ptr<DuckDB> DBInstanceCache::CreateInstance(const string &database, DBCon
138369
138435
  return db_instance;
138370
138436
  }
138371
138437
 
138438
+ shared_ptr<DuckDB> DBInstanceCache::CreateInstance(const string &database, DBConfig &config, bool cache_instance) {
138439
+ lock_guard<mutex> l(cache_lock);
138440
+ return CreateInstanceInternal(database, config, cache_instance);
138441
+ }
138442
+
138443
+ shared_ptr<DuckDB> DBInstanceCache::GetOrCreateInstance(const string &database, DBConfig &config_dict,
138444
+ bool cache_instance) {
138445
+ lock_guard<mutex> l(cache_lock);
138446
+ if (cache_instance) {
138447
+ auto instance = GetInstanceInternal(database, config_dict);
138448
+ if (instance) {
138449
+ return instance;
138450
+ }
138451
+ }
138452
+ return CreateInstanceInternal(database, config_dict, cache_instance);
138453
+ }
138454
+
138372
138455
  } // namespace duckdb
138373
138456
 
138374
138457
 
@@ -155444,7 +155527,6 @@ unique_ptr<LogicalOperator> FilterPullup::PullupJoin(unique_ptr<LogicalOperator>
155444
155527
  case JoinType::LEFT:
155445
155528
  case JoinType::ANTI:
155446
155529
  case JoinType::SEMI: {
155447
- can_add_column = true;
155448
155530
  return PullupFromLeft(move(op));
155449
155531
  }
155450
155532
  default:
@@ -157982,6 +158064,8 @@ unique_ptr<LogicalOperator> FilterPullup::PullupBothSide(unique_ptr<LogicalOpera
157982
158064
  FilterPullup right_pullup(true, can_add_column);
157983
158065
  op->children[0] = left_pullup.Rewrite(move(op->children[0]));
157984
158066
  op->children[1] = right_pullup.Rewrite(move(op->children[1]));
158067
+ D_ASSERT(left_pullup.can_add_column == can_add_column);
158068
+ D_ASSERT(right_pullup.can_add_column == can_add_column);
157985
158069
 
157986
158070
  // merging filter expressions
157987
158071
  for (idx_t i = 0; i < right_pullup.filters_expr_pullup.size(); ++i) {
@@ -158764,6 +158848,9 @@ unique_ptr<LogicalOperator> FilterPushdown::PushdownSetOperation(unique_ptr<Logi
158764
158848
  D_ASSERT(op->children.size() == 2);
158765
158849
  auto left_bindings = op->children[0]->GetColumnBindings();
158766
158850
  auto right_bindings = op->children[1]->GetColumnBindings();
158851
+ if (left_bindings.size() != right_bindings.size()) {
158852
+ throw InternalException("Filter pushdown - set operation LHS and RHS have incompatible counts");
158853
+ }
158767
158854
 
158768
158855
  // pushdown into set operation, we can duplicate the condition and pushdown the expressions into both sides
158769
158856
  FilterPushdown left_pushdown(optimizer), right_pushdown(optimizer);
@@ -182824,6 +182911,7 @@ bool Transformer::TransformGroupBy(duckdb_libpgquery::PGList *group, SelectNode
182824
182911
 
182825
182912
 
182826
182913
 
182914
+
182827
182915
  namespace duckdb {
182828
182916
 
182829
182917
  bool Transformer::TransformOrderBy(duckdb_libpgquery::PGList *order, vector<OrderByNode> &result) {
@@ -182857,6 +182945,13 @@ bool Transformer::TransformOrderBy(duckdb_libpgquery::PGList *order, vector<Orde
182857
182945
  throw NotImplementedException("Unimplemented order by type");
182858
182946
  }
182859
182947
  auto order_expression = TransformExpression(target);
182948
+ if (order_expression->GetExpressionClass() == ExpressionClass::STAR) {
182949
+ auto &star_expr = (StarExpression &)*order_expression;
182950
+ D_ASSERT(star_expr.relation_name.empty());
182951
+ if (star_expr.columns) {
182952
+ throw ParserException("COLUMNS expr is not supported in ORDER BY");
182953
+ }
182954
+ }
182860
182955
  result.emplace_back(type, null_order, move(order_expression));
182861
182956
  } else {
182862
182957
  throw NotImplementedException("ORDER BY list member type %d\n", temp->type);