duckdb 0.6.1-dev8.0 → 0.6.1-dev83.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-dev8.0",
5
+ "version": "0.6.1-dev83.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);
@@ -96950,7 +96979,8 @@ struct Interpolator {
96950
96979
  template <>
96951
96980
  struct Interpolator<true> {
96952
96981
  Interpolator(const double q, const idx_t n_p)
96953
- : n(n_p), RN((double)(n_p - 1) * q), FRN(floor(RN)), CRN(FRN), begin(0), end(n_p) {
96982
+ : n(n_p), RN((double)(n_p * q)), FRN(MaxValue<idx_t>(1, n_p - floor(n_p - RN)) - 1), CRN(FRN), begin(0),
96983
+ end(n_p) {
96954
96984
  }
96955
96985
 
96956
96986
  template <class INPUT_TYPE, class TARGET_TYPE, typename ACCESSOR = QuantileDirect<INPUT_TYPE>>
@@ -106724,16 +106754,16 @@ struct StructDatePart {
106724
106754
  const auto idx = rdata.sel->get_index(i);
106725
106755
  if (arg_valid.RowIsValid(idx)) {
106726
106756
  if (Value::IsFinite(tdata[idx])) {
106727
- DatePart::StructOperator::Operation(part_values.data(), tdata[idx], idx, part_mask);
106757
+ DatePart::StructOperator::Operation(part_values.data(), tdata[idx], i, part_mask);
106728
106758
  } else {
106729
106759
  for (auto &child_entry : child_entries) {
106730
- FlatVector::Validity(*child_entry).SetInvalid(idx);
106760
+ FlatVector::Validity(*child_entry).SetInvalid(i);
106731
106761
  }
106732
106762
  }
106733
106763
  } else {
106734
- res_valid.SetInvalid(idx);
106764
+ res_valid.SetInvalid(i);
106735
106765
  for (auto &child_entry : child_entries) {
106736
- FlatVector::Validity(*child_entry).SetInvalid(idx);
106766
+ FlatVector::Validity(*child_entry).SetInvalid(i);
106737
106767
  }
106738
106768
  }
106739
106769
  }
@@ -131298,14 +131328,16 @@ void UDFWrapper::RegisterAggrFunction(AggregateFunction aggr_function, ClientCon
131298
131328
 
131299
131329
 
131300
131330
 
131331
+
131301
131332
  namespace duckdb {
131302
131333
 
131303
- BaseAppender::BaseAppender(Allocator &allocator) : allocator(allocator), column(0) {
131334
+ BaseAppender::BaseAppender(Allocator &allocator, AppenderType type_p)
131335
+ : allocator(allocator), column(0), appender_type(type_p) {
131304
131336
  }
131305
131337
 
131306
- BaseAppender::BaseAppender(Allocator &allocator_p, vector<LogicalType> types_p)
131338
+ BaseAppender::BaseAppender(Allocator &allocator_p, vector<LogicalType> types_p, AppenderType type_p)
131307
131339
  : allocator(allocator_p), types(move(types_p)), collection(make_unique<ColumnDataCollection>(allocator, types)),
131308
- column(0) {
131340
+ column(0), appender_type(type_p) {
131309
131341
  InitializeChunk();
131310
131342
  }
131311
131343
 
@@ -131325,7 +131357,8 @@ void BaseAppender::Destructor() {
131325
131357
  }
131326
131358
 
131327
131359
  InternalAppender::InternalAppender(ClientContext &context_p, TableCatalogEntry &table_p)
131328
- : BaseAppender(Allocator::DefaultAllocator(), table_p.GetTypes()), context(context_p), table(table_p) {
131360
+ : BaseAppender(Allocator::DefaultAllocator(), table_p.GetTypes(), AppenderType::PHYSICAL), context(context_p),
131361
+ table(table_p) {
131329
131362
  }
131330
131363
 
131331
131364
  InternalAppender::~InternalAppender() {
@@ -131333,7 +131366,7 @@ InternalAppender::~InternalAppender() {
131333
131366
  }
131334
131367
 
131335
131368
  Appender::Appender(Connection &con, const string &schema_name, const string &table_name)
131336
- : BaseAppender(Allocator::DefaultAllocator()), context(con.context) {
131369
+ : BaseAppender(Allocator::DefaultAllocator(), AppenderType::LOGICAL), context(con.context) {
131337
131370
  description = con.TableInfo(schema_name, table_name);
131338
131371
  if (!description) {
131339
131372
  // table could not be found
@@ -131377,6 +131410,27 @@ void BaseAppender::AppendValueInternal(Vector &col, SRC input) {
131377
131410
  FlatVector::GetData<DST>(col)[chunk.size()] = Cast::Operation<SRC, DST>(input);
131378
131411
  }
131379
131412
 
131413
+ template <class SRC, class DST>
131414
+ void BaseAppender::AppendDecimalValueInternal(Vector &col, SRC input) {
131415
+ switch (appender_type) {
131416
+ case AppenderType::LOGICAL: {
131417
+ auto &type = col.GetType();
131418
+ D_ASSERT(type.id() == LogicalTypeId::DECIMAL);
131419
+ auto width = DecimalType::GetWidth(type);
131420
+ auto scale = DecimalType::GetScale(type);
131421
+ TryCastToDecimal::Operation<SRC, DST>(input, FlatVector::GetData<DST>(col)[chunk.size()], nullptr, width,
131422
+ scale);
131423
+ return;
131424
+ }
131425
+ case AppenderType::PHYSICAL: {
131426
+ AppendValueInternal<SRC, DST>(col, input);
131427
+ return;
131428
+ }
131429
+ default:
131430
+ throw InternalException("Type not implemented for AppenderType");
131431
+ }
131432
+ }
131433
+
131380
131434
  template <class T>
131381
131435
  void BaseAppender::AppendValueInternal(T input) {
131382
131436
  if (column >= types.size()) {
@@ -131422,18 +131476,20 @@ void BaseAppender::AppendValueInternal(T input) {
131422
131476
  break;
131423
131477
  case LogicalTypeId::DECIMAL:
131424
131478
  switch (col.GetType().InternalType()) {
131425
- case PhysicalType::INT8:
131426
- AppendValueInternal<T, int8_t>(col, input);
131427
- break;
131428
131479
  case PhysicalType::INT16:
131429
- AppendValueInternal<T, int16_t>(col, input);
131480
+ AppendDecimalValueInternal<T, int16_t>(col, input);
131430
131481
  break;
131431
131482
  case PhysicalType::INT32:
131432
- AppendValueInternal<T, int32_t>(col, input);
131483
+ AppendDecimalValueInternal<T, int32_t>(col, input);
131433
131484
  break;
131434
- default:
131435
- AppendValueInternal<T, int64_t>(col, input);
131485
+ case PhysicalType::INT64:
131486
+ AppendDecimalValueInternal<T, int64_t>(col, input);
131487
+ break;
131488
+ case PhysicalType::INT128:
131489
+ AppendDecimalValueInternal<T, hugeint_t>(col, input);
131436
131490
  break;
131491
+ default:
131492
+ throw InternalException("Internal type not recognized for Decimal");
131437
131493
  }
131438
131494
  break;
131439
131495
  case LogicalTypeId::DATE:
@@ -138304,12 +138360,19 @@ public:
138304
138360
  //! Creates and caches a new DB Instance (Fails if a cached instance already exists)
138305
138361
  shared_ptr<DuckDB> CreateInstance(const string &database, DBConfig &config_dict, bool cache_instance = true);
138306
138362
 
138363
+ //! Creates and caches a new DB Instance (Fails if a cached instance already exists)
138364
+ shared_ptr<DuckDB> GetOrCreateInstance(const string &database, DBConfig &config_dict, bool cache_instance);
138365
+
138307
138366
  private:
138308
138367
  //! A map with the cached instances <absolute_path/instance>
138309
138368
  unordered_map<string, weak_ptr<DuckDB>> db_instances;
138310
138369
 
138311
138370
  //! Lock to alter cache
138312
138371
  mutex cache_lock;
138372
+
138373
+ private:
138374
+ shared_ptr<DuckDB> GetInstanceInternal(const string &database, const DBConfig &config_dict);
138375
+ shared_ptr<DuckDB> CreateInstanceInternal(const string &database, DBConfig &config_dict, bool cache_instance);
138313
138376
  };
138314
138377
  } // namespace duckdb
138315
138378
 
@@ -138330,8 +138393,7 @@ string GetDBAbsolutePath(const string &database) {
138330
138393
  return FileSystem::JoinPath(FileSystem::GetWorkingDirectory(), database);
138331
138394
  }
138332
138395
 
138333
- shared_ptr<DuckDB> DBInstanceCache::GetInstance(const string &database, const DBConfig &config) {
138334
- lock_guard<mutex> l(cache_lock);
138396
+ shared_ptr<DuckDB> DBInstanceCache::GetInstanceInternal(const string &database, const DBConfig &config) {
138335
138397
  shared_ptr<DuckDB> db_instance;
138336
138398
  auto abs_database_path = GetDBAbsolutePath(database);
138337
138399
  if (db_instances.find(abs_database_path) != db_instances.end()) {
@@ -138350,8 +138412,13 @@ shared_ptr<DuckDB> DBInstanceCache::GetInstance(const string &database, const DB
138350
138412
  return db_instance;
138351
138413
  }
138352
138414
 
138353
- shared_ptr<DuckDB> DBInstanceCache::CreateInstance(const string &database, DBConfig &config, bool cache_instance) {
138415
+ shared_ptr<DuckDB> DBInstanceCache::GetInstance(const string &database, const DBConfig &config) {
138354
138416
  lock_guard<mutex> l(cache_lock);
138417
+ return GetInstanceInternal(database, config);
138418
+ }
138419
+
138420
+ shared_ptr<DuckDB> DBInstanceCache::CreateInstanceInternal(const string &database, DBConfig &config,
138421
+ bool cache_instance) {
138355
138422
  auto abs_database_path = GetDBAbsolutePath(database);
138356
138423
  if (db_instances.find(abs_database_path) != db_instances.end()) {
138357
138424
  throw duckdb::Exception(ExceptionType::CONNECTION,
@@ -138369,6 +138436,23 @@ shared_ptr<DuckDB> DBInstanceCache::CreateInstance(const string &database, DBCon
138369
138436
  return db_instance;
138370
138437
  }
138371
138438
 
138439
+ shared_ptr<DuckDB> DBInstanceCache::CreateInstance(const string &database, DBConfig &config, bool cache_instance) {
138440
+ lock_guard<mutex> l(cache_lock);
138441
+ return CreateInstanceInternal(database, config, cache_instance);
138442
+ }
138443
+
138444
+ shared_ptr<DuckDB> DBInstanceCache::GetOrCreateInstance(const string &database, DBConfig &config_dict,
138445
+ bool cache_instance) {
138446
+ lock_guard<mutex> l(cache_lock);
138447
+ if (cache_instance) {
138448
+ auto instance = GetInstanceInternal(database, config_dict);
138449
+ if (instance) {
138450
+ return instance;
138451
+ }
138452
+ }
138453
+ return CreateInstanceInternal(database, config_dict, cache_instance);
138454
+ }
138455
+
138372
138456
  } // namespace duckdb
138373
138457
 
138374
138458
 
@@ -155444,7 +155528,6 @@ unique_ptr<LogicalOperator> FilterPullup::PullupJoin(unique_ptr<LogicalOperator>
155444
155528
  case JoinType::LEFT:
155445
155529
  case JoinType::ANTI:
155446
155530
  case JoinType::SEMI: {
155447
- can_add_column = true;
155448
155531
  return PullupFromLeft(move(op));
155449
155532
  }
155450
155533
  default:
@@ -157982,6 +158065,8 @@ unique_ptr<LogicalOperator> FilterPullup::PullupBothSide(unique_ptr<LogicalOpera
157982
158065
  FilterPullup right_pullup(true, can_add_column);
157983
158066
  op->children[0] = left_pullup.Rewrite(move(op->children[0]));
157984
158067
  op->children[1] = right_pullup.Rewrite(move(op->children[1]));
158068
+ D_ASSERT(left_pullup.can_add_column == can_add_column);
158069
+ D_ASSERT(right_pullup.can_add_column == can_add_column);
157985
158070
 
157986
158071
  // merging filter expressions
157987
158072
  for (idx_t i = 0; i < right_pullup.filters_expr_pullup.size(); ++i) {
@@ -158764,6 +158849,9 @@ unique_ptr<LogicalOperator> FilterPushdown::PushdownSetOperation(unique_ptr<Logi
158764
158849
  D_ASSERT(op->children.size() == 2);
158765
158850
  auto left_bindings = op->children[0]->GetColumnBindings();
158766
158851
  auto right_bindings = op->children[1]->GetColumnBindings();
158852
+ if (left_bindings.size() != right_bindings.size()) {
158853
+ throw InternalException("Filter pushdown - set operation LHS and RHS have incompatible counts");
158854
+ }
158767
158855
 
158768
158856
  // pushdown into set operation, we can duplicate the condition and pushdown the expressions into both sides
158769
158857
  FilterPushdown left_pushdown(optimizer), right_pushdown(optimizer);
@@ -182824,6 +182912,7 @@ bool Transformer::TransformGroupBy(duckdb_libpgquery::PGList *group, SelectNode
182824
182912
 
182825
182913
 
182826
182914
 
182915
+
182827
182916
  namespace duckdb {
182828
182917
 
182829
182918
  bool Transformer::TransformOrderBy(duckdb_libpgquery::PGList *order, vector<OrderByNode> &result) {
@@ -182857,6 +182946,13 @@ bool Transformer::TransformOrderBy(duckdb_libpgquery::PGList *order, vector<Orde
182857
182946
  throw NotImplementedException("Unimplemented order by type");
182858
182947
  }
182859
182948
  auto order_expression = TransformExpression(target);
182949
+ if (order_expression->GetExpressionClass() == ExpressionClass::STAR) {
182950
+ auto &star_expr = (StarExpression &)*order_expression;
182951
+ D_ASSERT(star_expr.relation_name.empty());
182952
+ if (star_expr.columns) {
182953
+ throw ParserException("COLUMNS expr is not supported in ORDER BY");
182954
+ }
182955
+ }
182860
182956
  result.emplace_back(type, null_order, move(order_expression));
182861
182957
  } else {
182862
182958
  throw NotImplementedException("ORDER BY list member type %d\n", temp->type);