duckdb 0.3.5-dev699.0 → 0.3.5-dev715.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
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "duckdb",
3
3
  "main": "./lib/duckdb.js",
4
- "version": "0.3.5-dev699.0",
4
+ "version": "0.3.5-dev715.0",
5
5
  "description": "DuckDB node.js API",
6
6
  "gypfile": true,
7
7
  "dependencies": {
@@ -363,6 +363,13 @@ struct ExecTask : public Task {
363
363
  }
364
364
  }
365
365
  }
366
+
367
+ void Callback() override {
368
+ auto env = object.Env();
369
+ Napi::HandleScope scope(env);
370
+ callback.Value().MakeCallback(object.Value(), {success ? env.Null() : Napi::String::New(env, error)});
371
+ };
372
+
366
373
  std::string sql;
367
374
  bool success;
368
375
  std::string error;
package/src/duckdb.cpp CHANGED
@@ -45325,7 +45325,7 @@ void Vector::Initialize(bool zero_data, idx_t capacity) {
45325
45325
  auto struct_buffer = make_unique<VectorStructBuffer>(type, capacity);
45326
45326
  auxiliary = move(struct_buffer);
45327
45327
  } else if (internal_type == PhysicalType::LIST) {
45328
- auto list_buffer = make_unique<VectorListBuffer>(type);
45328
+ auto list_buffer = make_unique<VectorListBuffer>(type, capacity);
45329
45329
  auxiliary = move(list_buffer);
45330
45330
  }
45331
45331
  auto type_size = GetTypeIdSize(internal_type);
@@ -46260,7 +46260,6 @@ const SelectionVector *ConstantVector::ZeroSelectionVector(idx_t count, Selectio
46260
46260
  }
46261
46261
 
46262
46262
  void ConstantVector::Reference(Vector &vector, Vector &source, idx_t position, idx_t count) {
46263
- D_ASSERT(position < count);
46264
46263
  auto &source_type = source.GetType();
46265
46264
  switch (source_type.InternalType()) {
46266
46265
  case PhysicalType::LIST: {
@@ -46308,7 +46307,7 @@ void ConstantVector::Reference(Vector &vector, Vector &source, idx_t position, i
46308
46307
  auto &source_entries = StructVector::GetEntries(source);
46309
46308
  auto &target_entries = StructVector::GetEntries(vector);
46310
46309
  for (idx_t i = 0; i < source_entries.size(); i++) {
46311
- ConstantVector::Reference(*target_entries[i], *source_entries[i], position, count);
46310
+ ConstantVector::Reference(*target_entries[i], *source_entries[i], struct_index, count);
46312
46311
  }
46313
46312
  vector.SetVectorType(VectorType::CONSTANT_VECTOR);
46314
46313
  break;
@@ -46676,18 +46675,14 @@ VectorListBuffer::VectorListBuffer(unique_ptr<Vector> vector, idx_t initial_capa
46676
46675
  }
46677
46676
 
46678
46677
  VectorListBuffer::VectorListBuffer(const LogicalType &list_type, idx_t initial_capacity)
46679
- : VectorBuffer(VectorBufferType::LIST_BUFFER) {
46680
- // FIXME: directly construct vector of correct size
46681
- child = make_unique<Vector>(ListType::GetChildType(list_type));
46682
- capacity = STANDARD_VECTOR_SIZE;
46683
- Reserve(initial_capacity);
46678
+ : VectorBuffer(VectorBufferType::LIST_BUFFER), capacity(initial_capacity),
46679
+ child(make_unique<Vector>(ListType::GetChildType(list_type), initial_capacity)) {
46684
46680
  }
46685
46681
 
46686
46682
  void VectorListBuffer::Reserve(idx_t to_reserve) {
46687
46683
  if (to_reserve > capacity) {
46688
- idx_t new_capacity = (to_reserve + STANDARD_VECTOR_SIZE - 1) / STANDARD_VECTOR_SIZE * STANDARD_VECTOR_SIZE;
46684
+ idx_t new_capacity = NextPowerOfTwo(to_reserve);
46689
46685
  D_ASSERT(new_capacity >= to_reserve);
46690
- D_ASSERT(new_capacity % STANDARD_VECTOR_SIZE == 0);
46691
46686
  child->Resize(capacity, new_capacity);
46692
46687
  capacity = new_capacity;
46693
46688
  }
@@ -51740,6 +51735,7 @@ static inline void TemplatedLoopHash(Vector &input, Vector &result, const Select
51740
51735
 
51741
51736
  template <bool HAS_RSEL, bool FIRST_HASH>
51742
51737
  static inline void StructLoopHash(Vector &input, Vector &hashes, const SelectionVector *rsel, idx_t count) {
51738
+ input.Normalify(count);
51743
51739
  auto &children = StructVector::GetEntries(input);
51744
51740
 
51745
51741
  D_ASSERT(!children.empty());
@@ -85972,7 +85968,9 @@ static void ListUpdateFunction(Vector inputs[], FunctionData *, idx_t input_coun
85972
85968
  for (idx_t i = 0; i < count; i++) {
85973
85969
  auto state = states[sdata.sel->get_index(i)];
85974
85970
  if (!state->list_vector) {
85975
- state->list_vector = new Vector(list_vector_type);
85971
+ // NOTE: any number bigger than 1 can cause DuckDB to run out of memory for specific queries
85972
+ // consisting of millions of groups in the group by and complex (nested) vectors
85973
+ state->list_vector = new Vector(list_vector_type, 1);
85976
85974
  }
85977
85975
  ListVector::Append(*state->list_vector, input, i + 1, i);
85978
85976
  }
@@ -85991,7 +85989,10 @@ static void ListCombineFunction(Vector &state, Vector &combined, FunctionData *b
85991
85989
  continue;
85992
85990
  }
85993
85991
  if (!combined_ptr[i]->list_vector) {
85994
- combined_ptr[i]->list_vector = new Vector(state->list_vector->GetType());
85992
+ // NOTE: initializing this with a capacity of ListVector::GetListSize(*state->list_vector) causes
85993
+ // DuckDB to run out of memory for multiple threads with millions of groups in the group by and complex
85994
+ // (nested) vectors
85995
+ combined_ptr[i]->list_vector = new Vector(state->list_vector->GetType(), 1);
85995
85996
  }
85996
85997
  ListVector::Append(*combined_ptr[i]->list_vector, ListVector::GetEntry(*state->list_vector),
85997
85998
  ListVector::GetListSize(*state->list_vector));
@@ -86006,6 +86007,7 @@ static void ListFinalize(Vector &state_vector, FunctionData *, Vector &result, i
86006
86007
  D_ASSERT(result.GetType().id() == LogicalTypeId::LIST);
86007
86008
 
86008
86009
  auto &mask = FlatVector::Validity(result);
86010
+ auto list_struct_data = FlatVector::GetData<list_entry_t>(result);
86009
86011
  size_t total_len = ListVector::GetListSize(result);
86010
86012
 
86011
86013
  for (idx_t i = 0; i < count; i++) {
@@ -86016,22 +86018,14 @@ static void ListFinalize(Vector &state_vector, FunctionData *, Vector &result, i
86016
86018
  continue;
86017
86019
  }
86018
86020
 
86019
- auto list_struct_data = FlatVector::GetData<list_entry_t>(result);
86020
86021
  auto &state_lv = *state->list_vector;
86021
86022
  auto state_lv_count = ListVector::GetListSize(state_lv);
86022
86023
  list_struct_data[rid].length = state_lv_count;
86023
86024
  list_struct_data[rid].offset = total_len;
86024
86025
  total_len += state_lv_count;
86025
- }
86026
86026
 
86027
- for (idx_t i = 0; i < count; i++) {
86028
- auto state = states[sdata.sel->get_index(i)];
86029
- if (!state->list_vector) {
86030
- continue;
86031
- }
86032
- auto &list_vec = *state->list_vector;
86033
- auto &list_vec_to_append = ListVector::GetEntry(list_vec);
86034
- ListVector::Append(result, list_vec_to_append, ListVector::GetListSize(list_vec));
86027
+ auto &list_vec_to_append = ListVector::GetEntry(state_lv);
86028
+ ListVector::Append(result, list_vec_to_append, state_lv_count);
86035
86029
  }
86036
86030
  }
86037
86031
 
@@ -114875,6 +114869,9 @@ void ClientContext::LogQueryInternal(ClientContextLock &, const string &query) {
114875
114869
 
114876
114870
  unique_ptr<QueryResult> ClientContext::Query(unique_ptr<SQLStatement> statement, bool allow_stream_result) {
114877
114871
  auto pending_query = PendingQuery(move(statement), allow_stream_result);
114872
+ if (!pending_query->success) {
114873
+ return make_unique<MaterializedQueryResult>(pending_query->error);
114874
+ }
114878
114875
  return pending_query->Execute();
114879
114876
  }
114880
114877