duckdb 0.6.1-dev254.0 → 0.6.1-dev263.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-dev254.0",
5
+ "version": "0.6.1-dev263.0",
6
6
  "description": "DuckDB node.js API",
7
7
  "gypfile": true,
8
8
  "dependencies": {
package/src/duckdb.cpp CHANGED
@@ -30953,7 +30953,7 @@ struct RowOperations {
30953
30953
  namespace duckdb {
30954
30954
 
30955
30955
  template <class OP, class RETURN_TYPE, typename... ARGS>
30956
- RETURN_TYPE RadixBitsSwitch(idx_t radix_bits, ARGS &&... args) {
30956
+ RETURN_TYPE RadixBitsSwitch(idx_t radix_bits, ARGS &&...args) {
30957
30957
  D_ASSERT(radix_bits <= sizeof(hash_t) * 8);
30958
30958
  switch (radix_bits) {
30959
30959
  case 1:
@@ -30982,7 +30982,7 @@ RETURN_TYPE RadixBitsSwitch(idx_t radix_bits, ARGS &&... args) {
30982
30982
  }
30983
30983
 
30984
30984
  template <class OP, class RETURN_TYPE, idx_t radix_bits_1, typename... ARGS>
30985
- RETURN_TYPE DoubleRadixBitsSwitch2(idx_t radix_bits_2, ARGS &&... args) {
30985
+ RETURN_TYPE DoubleRadixBitsSwitch2(idx_t radix_bits_2, ARGS &&...args) {
30986
30986
  D_ASSERT(radix_bits_2 <= sizeof(hash_t) * 8);
30987
30987
  switch (radix_bits_2) {
30988
30988
  case 1:
@@ -31011,7 +31011,7 @@ RETURN_TYPE DoubleRadixBitsSwitch2(idx_t radix_bits_2, ARGS &&... args) {
31011
31011
  }
31012
31012
 
31013
31013
  template <class OP, class RETURN_TYPE, typename... ARGS>
31014
- RETURN_TYPE DoubleRadixBitsSwitch1(idx_t radix_bits_1, idx_t radix_bits_2, ARGS &&... args) {
31014
+ RETURN_TYPE DoubleRadixBitsSwitch1(idx_t radix_bits_1, idx_t radix_bits_2, ARGS &&...args) {
31015
31015
  D_ASSERT(radix_bits_1 <= sizeof(hash_t) * 8);
31016
31016
  switch (radix_bits_1) {
31017
31017
  case 1:
@@ -99069,13 +99069,16 @@ struct LinkedList {
99069
99069
  // forward declarations
99070
99070
  struct WriteDataToSegment;
99071
99071
  struct ReadDataFromSegment;
99072
+ struct CopyDataFromSegment;
99072
99073
  typedef ListSegment *(*create_segment_t)(WriteDataToSegment &write_data_to_segment, Allocator &allocator,
99073
- vector<AllocatedData> &owning_vector, uint16_t &capacity);
99074
+ vector<AllocatedData> &owning_vector, const uint16_t &capacity);
99074
99075
  typedef void (*write_data_to_segment_t)(WriteDataToSegment &write_data_to_segment, Allocator &allocator,
99075
99076
  vector<AllocatedData> &owning_vector, ListSegment *segment, Vector &input,
99076
99077
  idx_t &entry_idx, idx_t &count);
99077
- typedef void (*read_data_from_segment_t)(ReadDataFromSegment &read_data_from_segment, ListSegment *segment,
99078
+ typedef void (*read_data_from_segment_t)(ReadDataFromSegment &read_data_from_segment, const ListSegment *segment,
99078
99079
  Vector &result, idx_t &total_count);
99080
+ typedef ListSegment *(*copy_data_from_segment_t)(CopyDataFromSegment &copy_data_from_segment, const ListSegment *source,
99081
+ Allocator &allocator, vector<AllocatedData> &owning_vector);
99079
99082
 
99080
99083
  struct WriteDataToSegment {
99081
99084
  create_segment_t create_segment;
@@ -99086,6 +99089,10 @@ struct ReadDataFromSegment {
99086
99089
  read_data_from_segment_t segment_function;
99087
99090
  vector<ReadDataFromSegment> child_functions;
99088
99091
  };
99092
+ struct CopyDataFromSegment {
99093
+ copy_data_from_segment_t segment_function;
99094
+ vector<CopyDataFromSegment> child_functions;
99095
+ };
99089
99096
 
99090
99097
  // forward declarations
99091
99098
  static void AppendRow(WriteDataToSegment &write_data_to_segment, Allocator &allocator,
@@ -99093,24 +99100,27 @@ static void AppendRow(WriteDataToSegment &write_data_to_segment, Allocator &allo
99093
99100
  idx_t &count);
99094
99101
  static void BuildListVector(ReadDataFromSegment &read_data_from_segment, LinkedList *linked_list, Vector &result,
99095
99102
  idx_t &initial_total_count);
99103
+ static void CopyLinkedList(CopyDataFromSegment &copy_data_from_segment, const LinkedList *source_list,
99104
+ LinkedList &target_list, Allocator &allocator, vector<AllocatedData> &owning_vector);
99096
99105
 
99097
99106
  template <class T>
99098
99107
  static data_ptr_t AllocatePrimitiveData(Allocator &allocator, vector<AllocatedData> &owning_vector,
99099
- uint16_t &capacity) {
99108
+ const uint16_t &capacity) {
99100
99109
 
99101
99110
  owning_vector.emplace_back(allocator.Allocate(sizeof(ListSegment) + capacity * (sizeof(bool) + sizeof(T))));
99102
99111
  return owning_vector.back().get();
99103
99112
  }
99104
99113
 
99105
- static data_ptr_t AllocateListData(Allocator &allocator, vector<AllocatedData> &owning_vector, uint16_t &capacity) {
99114
+ static data_ptr_t AllocateListData(Allocator &allocator, vector<AllocatedData> &owning_vector,
99115
+ const uint16_t &capacity) {
99106
99116
 
99107
99117
  owning_vector.emplace_back(
99108
99118
  allocator.Allocate(sizeof(ListSegment) + capacity * (sizeof(bool) + sizeof(uint64_t)) + sizeof(LinkedList)));
99109
99119
  return owning_vector.back().get();
99110
99120
  }
99111
99121
 
99112
- static data_ptr_t AllocateStructData(Allocator &allocator, vector<AllocatedData> &owning_vector, uint16_t &capacity,
99113
- idx_t child_count) {
99122
+ static data_ptr_t AllocateStructData(Allocator &allocator, vector<AllocatedData> &owning_vector,
99123
+ const uint16_t &capacity, const idx_t &child_count) {
99114
99124
 
99115
99125
  owning_vector.emplace_back(
99116
99126
  allocator.Allocate(sizeof(ListSegment) + capacity * sizeof(bool) + child_count * sizeof(ListSegment *)));
@@ -99118,28 +99128,28 @@ static data_ptr_t AllocateStructData(Allocator &allocator, vector<AllocatedData>
99118
99128
  }
99119
99129
 
99120
99130
  template <class T>
99121
- static T *GetPrimitiveData(ListSegment *segment) {
99131
+ static T *GetPrimitiveData(const ListSegment *segment) {
99122
99132
  return (T *)(((char *)segment) + sizeof(ListSegment) + segment->capacity * sizeof(bool));
99123
99133
  }
99124
99134
 
99125
- static uint64_t *GetListLengthData(ListSegment *segment) {
99135
+ static uint64_t *GetListLengthData(const ListSegment *segment) {
99126
99136
  return (uint64_t *)(((char *)segment) + sizeof(ListSegment) + segment->capacity * sizeof(bool));
99127
99137
  }
99128
99138
 
99129
- static LinkedList *GetListChildData(ListSegment *segment) {
99139
+ static LinkedList *GetListChildData(const ListSegment *segment) {
99130
99140
  return (LinkedList *)(((char *)segment) + sizeof(ListSegment) +
99131
99141
  segment->capacity * (sizeof(bool) + sizeof(uint64_t)));
99132
99142
  }
99133
99143
 
99134
- static ListSegment **GetStructData(ListSegment *segment) {
99144
+ static ListSegment **GetStructData(const ListSegment *segment) {
99135
99145
  return (ListSegment **)(((char *)segment) + sizeof(ListSegment) + segment->capacity * sizeof(bool));
99136
99146
  }
99137
99147
 
99138
- static bool *GetNullMask(ListSegment *segment) {
99148
+ static bool *GetNullMask(const ListSegment *segment) {
99139
99149
  return (bool *)(((char *)segment) + sizeof(ListSegment));
99140
99150
  }
99141
99151
 
99142
- static uint16_t GetCapacityForNewSegment(LinkedList *linked_list) {
99152
+ static uint16_t GetCapacityForNewSegment(const LinkedList *linked_list) {
99143
99153
 
99144
99154
  // consecutive segments grow by the power of two
99145
99155
  uint16_t capacity = 4;
@@ -99152,7 +99162,7 @@ static uint16_t GetCapacityForNewSegment(LinkedList *linked_list) {
99152
99162
 
99153
99163
  template <class T>
99154
99164
  static ListSegment *CreatePrimitiveSegment(WriteDataToSegment &, Allocator &allocator,
99155
- vector<AllocatedData> &owning_vector, uint16_t &capacity) {
99165
+ vector<AllocatedData> &owning_vector, const uint16_t &capacity) {
99156
99166
 
99157
99167
  // allocate data and set the header
99158
99168
  auto segment = (ListSegment *)AllocatePrimitiveData<T>(allocator, owning_vector, capacity);
@@ -99163,7 +99173,7 @@ static ListSegment *CreatePrimitiveSegment(WriteDataToSegment &, Allocator &allo
99163
99173
  }
99164
99174
 
99165
99175
  static ListSegment *CreateListSegment(WriteDataToSegment &, Allocator &allocator, vector<AllocatedData> &owning_vector,
99166
- uint16_t &capacity) {
99176
+ const uint16_t &capacity) {
99167
99177
 
99168
99178
  // allocate data and set the header
99169
99179
  auto segment = (ListSegment *)AllocateListData(allocator, owning_vector, capacity);
@@ -99180,7 +99190,7 @@ static ListSegment *CreateListSegment(WriteDataToSegment &, Allocator &allocator
99180
99190
  }
99181
99191
 
99182
99192
  static ListSegment *CreateStructSegment(WriteDataToSegment &write_data_to_segment, Allocator &allocator,
99183
- vector<AllocatedData> &owning_vector, uint16_t &capacity) {
99193
+ vector<AllocatedData> &owning_vector, const uint16_t &capacity) {
99184
99194
 
99185
99195
  // allocate data and set header
99186
99196
  auto segment = (ListSegment *)AllocateStructData(allocator, owning_vector, capacity,
@@ -99374,7 +99384,7 @@ static void AppendRow(WriteDataToSegment &write_data_to_segment, Allocator &allo
99374
99384
  }
99375
99385
 
99376
99386
  template <class T>
99377
- static void ReadDataFromPrimitiveSegment(ReadDataFromSegment &, ListSegment *segment, Vector &result,
99387
+ static void ReadDataFromPrimitiveSegment(ReadDataFromSegment &, const ListSegment *segment, Vector &result,
99378
99388
  idx_t &total_count) {
99379
99389
 
99380
99390
  auto &aggr_vector_validity = FlatVector::Validity(result);
@@ -99398,7 +99408,7 @@ static void ReadDataFromPrimitiveSegment(ReadDataFromSegment &, ListSegment *seg
99398
99408
  }
99399
99409
  }
99400
99410
 
99401
- static void ReadDataFromVarcharSegment(ReadDataFromSegment &, ListSegment *segment, Vector &result,
99411
+ static void ReadDataFromVarcharSegment(ReadDataFromSegment &, const ListSegment *segment, Vector &result,
99402
99412
  idx_t &total_count) {
99403
99413
 
99404
99414
  auto &aggr_vector_validity = FlatVector::Validity(result);
@@ -99439,8 +99449,8 @@ static void ReadDataFromVarcharSegment(ReadDataFromSegment &, ListSegment *segme
99439
99449
  }
99440
99450
  }
99441
99451
 
99442
- static void ReadDataFromListSegment(ReadDataFromSegment &read_data_from_segment, ListSegment *segment, Vector &result,
99443
- idx_t &total_count) {
99452
+ static void ReadDataFromListSegment(ReadDataFromSegment &read_data_from_segment, const ListSegment *segment,
99453
+ Vector &result, idx_t &total_count) {
99444
99454
 
99445
99455
  auto &aggr_vector_validity = FlatVector::Validity(result);
99446
99456
 
@@ -99479,8 +99489,8 @@ static void ReadDataFromListSegment(ReadDataFromSegment &read_data_from_segment,
99479
99489
  BuildListVector(read_data_from_segment.child_functions[0], &linked_child_list, child_vector, starting_offset);
99480
99490
  }
99481
99491
 
99482
- static void ReadDataFromStructSegment(ReadDataFromSegment &read_data_from_segment, ListSegment *segment, Vector &result,
99483
- idx_t &total_count) {
99492
+ static void ReadDataFromStructSegment(ReadDataFromSegment &read_data_from_segment, const ListSegment *segment,
99493
+ Vector &result, idx_t &total_count) {
99484
99494
 
99485
99495
  auto &aggr_vector_validity = FlatVector::Validity(result);
99486
99496
 
@@ -99519,6 +99529,86 @@ static void BuildListVector(ReadDataFromSegment &read_data_from_segment, LinkedL
99519
99529
  linked_list->last_segment = nullptr;
99520
99530
  }
99521
99531
 
99532
+ template <class T>
99533
+ static ListSegment *CopyDataFromPrimitiveSegment(CopyDataFromSegment &, const ListSegment *source, Allocator &allocator,
99534
+ vector<AllocatedData> &owning_vector) {
99535
+
99536
+ auto target = (ListSegment *)AllocatePrimitiveData<T>(allocator, owning_vector, source->capacity);
99537
+ memcpy(target, source, sizeof(ListSegment) + source->capacity * (sizeof(bool) + sizeof(T)));
99538
+ target->next = nullptr;
99539
+ return target;
99540
+ }
99541
+
99542
+ static ListSegment *CopyDataFromListSegment(CopyDataFromSegment &copy_data_from_segment, const ListSegment *source,
99543
+ Allocator &allocator, vector<AllocatedData> &owning_vector) {
99544
+
99545
+ // create an empty linked list for the child vector of target
99546
+ auto source_linked_child_list = Load<LinkedList>((data_ptr_t)GetListChildData(source));
99547
+
99548
+ // create the segment
99549
+ auto target = (ListSegment *)AllocateListData(allocator, owning_vector, source->capacity);
99550
+ memcpy(target, source,
99551
+ sizeof(ListSegment) + source->capacity * (sizeof(bool) + sizeof(uint64_t)) + sizeof(LinkedList));
99552
+ target->next = nullptr;
99553
+
99554
+ auto target_linked_list = GetListChildData(target);
99555
+ LinkedList linked_list(source_linked_child_list.total_capacity, nullptr, nullptr);
99556
+ Store<LinkedList>(linked_list, (data_ptr_t)target_linked_list);
99557
+
99558
+ // recurse to copy the linked child list
99559
+ auto target_linked_child_list = Load<LinkedList>((data_ptr_t)GetListChildData(target));
99560
+ D_ASSERT(copy_data_from_segment.child_functions.size() == 1);
99561
+ CopyLinkedList(copy_data_from_segment.child_functions[0], &source_linked_child_list, target_linked_child_list,
99562
+ allocator, owning_vector);
99563
+
99564
+ // store the updated linked list
99565
+ Store<LinkedList>(target_linked_child_list, (data_ptr_t)GetListChildData(target));
99566
+ return target;
99567
+ }
99568
+
99569
+ static ListSegment *CopyDataFromStructSegment(CopyDataFromSegment &copy_data_from_segment, const ListSegment *source,
99570
+ Allocator &allocator, vector<AllocatedData> &owning_vector) {
99571
+
99572
+ auto source_child_count = copy_data_from_segment.child_functions.size();
99573
+ auto target = (ListSegment *)AllocateStructData(allocator, owning_vector, source->capacity, source_child_count);
99574
+ memcpy(target, source,
99575
+ sizeof(ListSegment) + source->capacity * sizeof(bool) + source_child_count * sizeof(ListSegment *));
99576
+ target->next = nullptr;
99577
+
99578
+ // recurse and copy the children
99579
+ auto source_child_segments = GetStructData(source);
99580
+ auto target_child_segments = GetStructData(target);
99581
+
99582
+ for (idx_t i = 0; i < copy_data_from_segment.child_functions.size(); i++) {
99583
+ auto child_function = copy_data_from_segment.child_functions[i];
99584
+ auto source_child_segment = Load<ListSegment *>((data_ptr_t)(source_child_segments + i));
99585
+ auto target_child_segment =
99586
+ child_function.segment_function(child_function, source_child_segment, allocator, owning_vector);
99587
+ Store<ListSegment *>(target_child_segment, (data_ptr_t)(target_child_segments + i));
99588
+ }
99589
+ return target;
99590
+ }
99591
+
99592
+ static void CopyLinkedList(CopyDataFromSegment &copy_data_from_segment, const LinkedList *source_list,
99593
+ LinkedList &target_list, Allocator &allocator, vector<AllocatedData> &owning_vector) {
99594
+
99595
+ auto source_segment = source_list->first_segment;
99596
+
99597
+ while (source_segment) {
99598
+ auto target_segment =
99599
+ copy_data_from_segment.segment_function(copy_data_from_segment, source_segment, allocator, owning_vector);
99600
+ source_segment = source_segment->next;
99601
+
99602
+ if (!target_list.first_segment) {
99603
+ target_list.first_segment = target_segment;
99604
+ }
99605
+ if (target_list.last_segment) {
99606
+ target_list.last_segment->next = target_segment;
99607
+ }
99608
+ target_list.last_segment = target_segment;
99609
+ }
99610
+ }
99611
+
99522
99612
  static void InitializeValidities(Vector &vector, idx_t &capacity) {
99523
99613
 
99524
99614
  auto &validity_mask = FlatVector::Validity(vector);
@@ -99562,6 +99652,7 @@ struct ListBindData : public FunctionData {
99562
99652
  LogicalType stype;
99563
99653
  WriteDataToSegment write_data_to_segment;
99564
99654
  ReadDataFromSegment read_data_from_segment;
99655
+ CopyDataFromSegment copy_data_from_segment;
99565
99656
 
99566
99657
  unique_ptr<FunctionData> Copy() const override {
99567
99658
  return make_unique<ListBindData>(stype);
@@ -99574,7 +99665,8 @@ struct ListBindData : public FunctionData {
99574
99665
  };
99575
99666
 
99576
99667
  static void GetSegmentDataFunctions(WriteDataToSegment &write_data_to_segment,
99577
- ReadDataFromSegment &read_data_from_segment, const LogicalType &type) {
99668
+ ReadDataFromSegment &read_data_from_segment,
99669
+ CopyDataFromSegment &copy_data_from_segment, const LogicalType &type) {
99578
99670
 
99579
99671
  auto physical_type = type.InternalType();
99580
99672
  switch (physical_type) {
@@ -99583,113 +99675,135 @@ static void GetSegmentDataFunctions(WriteDataToSegment &write_data_to_segment,
99583
99675
  write_data_to_segment.create_segment = CreatePrimitiveSegment<bool>;
99584
99676
  write_data_to_segment.segment_function = WriteDataToPrimitiveSegment<bool>;
99585
99677
  read_data_from_segment.segment_function = ReadDataFromPrimitiveSegment<bool>;
99678
+ copy_data_from_segment.segment_function = CopyDataFromPrimitiveSegment<bool>;
99586
99679
  break;
99587
99680
  }
99588
99681
  case PhysicalType::INT8: {
99589
99682
  write_data_to_segment.create_segment = CreatePrimitiveSegment<int8_t>;
99590
99683
  write_data_to_segment.segment_function = WriteDataToPrimitiveSegment<int8_t>;
99591
99684
  read_data_from_segment.segment_function = ReadDataFromPrimitiveSegment<int8_t>;
99685
+ copy_data_from_segment.segment_function = CopyDataFromPrimitiveSegment<int8_t>;
99592
99686
  break;
99593
99687
  }
99594
99688
  case PhysicalType::INT16: {
99595
99689
  write_data_to_segment.create_segment = CreatePrimitiveSegment<int16_t>;
99596
99690
  write_data_to_segment.segment_function = WriteDataToPrimitiveSegment<int16_t>;
99597
99691
  read_data_from_segment.segment_function = ReadDataFromPrimitiveSegment<int16_t>;
99692
+ copy_data_from_segment.segment_function = CopyDataFromPrimitiveSegment<int16_t>;
99598
99693
  break;
99599
99694
  }
99600
99695
  case PhysicalType::INT32: {
99601
99696
  write_data_to_segment.create_segment = CreatePrimitiveSegment<int32_t>;
99602
99697
  write_data_to_segment.segment_function = WriteDataToPrimitiveSegment<int32_t>;
99603
99698
  read_data_from_segment.segment_function = ReadDataFromPrimitiveSegment<int32_t>;
99699
+ copy_data_from_segment.segment_function = CopyDataFromPrimitiveSegment<int32_t>;
99604
99700
  break;
99605
99701
  }
99606
99702
  case PhysicalType::INT64: {
99607
99703
  write_data_to_segment.create_segment = CreatePrimitiveSegment<int64_t>;
99608
99704
  write_data_to_segment.segment_function = WriteDataToPrimitiveSegment<int64_t>;
99609
99705
  read_data_from_segment.segment_function = ReadDataFromPrimitiveSegment<int64_t>;
99706
+ copy_data_from_segment.segment_function = CopyDataFromPrimitiveSegment<int64_t>;
99610
99707
  break;
99611
99708
  }
99612
99709
  case PhysicalType::UINT8: {
99613
99710
  write_data_to_segment.create_segment = CreatePrimitiveSegment<uint8_t>;
99614
99711
  write_data_to_segment.segment_function = WriteDataToPrimitiveSegment<uint8_t>;
99615
99712
  read_data_from_segment.segment_function = ReadDataFromPrimitiveSegment<uint8_t>;
99713
+ copy_data_from_segment.segment_function = CopyDataFromPrimitiveSegment<uint8_t>;
99616
99714
  break;
99617
99715
  }
99618
99716
  case PhysicalType::UINT16: {
99619
99717
  write_data_to_segment.create_segment = CreatePrimitiveSegment<uint16_t>;
99620
99718
  write_data_to_segment.segment_function = WriteDataToPrimitiveSegment<uint16_t>;
99621
99719
  read_data_from_segment.segment_function = ReadDataFromPrimitiveSegment<uint16_t>;
99720
+ copy_data_from_segment.segment_function = CopyDataFromPrimitiveSegment<uint16_t>;
99622
99721
  break;
99623
99722
  }
99624
99723
  case PhysicalType::UINT32: {
99625
99724
  write_data_to_segment.create_segment = CreatePrimitiveSegment<uint32_t>;
99626
99725
  write_data_to_segment.segment_function = WriteDataToPrimitiveSegment<uint32_t>;
99627
99726
  read_data_from_segment.segment_function = ReadDataFromPrimitiveSegment<uint32_t>;
99727
+ copy_data_from_segment.segment_function = CopyDataFromPrimitiveSegment<uint32_t>;
99628
99728
  break;
99629
99729
  }
99630
99730
  case PhysicalType::UINT64: {
99631
99731
  write_data_to_segment.create_segment = CreatePrimitiveSegment<uint64_t>;
99632
99732
  write_data_to_segment.segment_function = WriteDataToPrimitiveSegment<uint64_t>;
99633
99733
  read_data_from_segment.segment_function = ReadDataFromPrimitiveSegment<uint64_t>;
99734
+ copy_data_from_segment.segment_function = CopyDataFromPrimitiveSegment<uint64_t>;
99634
99735
  break;
99635
99736
  }
99636
99737
  case PhysicalType::FLOAT: {
99637
99738
  write_data_to_segment.create_segment = CreatePrimitiveSegment<float>;
99638
99739
  write_data_to_segment.segment_function = WriteDataToPrimitiveSegment<float>;
99639
99740
  read_data_from_segment.segment_function = ReadDataFromPrimitiveSegment<float>;
99741
+ copy_data_from_segment.segment_function = CopyDataFromPrimitiveSegment<float>;
99640
99742
  break;
99641
99743
  }
99642
99744
  case PhysicalType::DOUBLE: {
99643
99745
  write_data_to_segment.create_segment = CreatePrimitiveSegment<double>;
99644
99746
  write_data_to_segment.segment_function = WriteDataToPrimitiveSegment<double>;
99645
99747
  read_data_from_segment.segment_function = ReadDataFromPrimitiveSegment<double>;
99748
+ copy_data_from_segment.segment_function = CopyDataFromPrimitiveSegment<double>;
99646
99749
  break;
99647
99750
  }
99648
99751
  case PhysicalType::INT128: {
99649
99752
  write_data_to_segment.create_segment = CreatePrimitiveSegment<hugeint_t>;
99650
99753
  write_data_to_segment.segment_function = WriteDataToPrimitiveSegment<hugeint_t>;
99651
99754
  read_data_from_segment.segment_function = ReadDataFromPrimitiveSegment<hugeint_t>;
99755
+ copy_data_from_segment.segment_function = CopyDataFromPrimitiveSegment<hugeint_t>;
99652
99756
  break;
99653
99757
  }
99654
99758
  case PhysicalType::INTERVAL: {
99655
99759
  write_data_to_segment.create_segment = CreatePrimitiveSegment<interval_t>;
99656
99760
  write_data_to_segment.segment_function = WriteDataToPrimitiveSegment<interval_t>;
99657
99761
  read_data_from_segment.segment_function = ReadDataFromPrimitiveSegment<interval_t>;
99762
+ copy_data_from_segment.segment_function = CopyDataFromPrimitiveSegment<interval_t>;
99658
99763
  break;
99659
99764
  }
99660
99765
  case PhysicalType::VARCHAR: {
99661
99766
  write_data_to_segment.create_segment = CreateListSegment;
99662
99767
  write_data_to_segment.segment_function = WriteDataToVarcharSegment;
99663
99768
  read_data_from_segment.segment_function = ReadDataFromVarcharSegment;
99769
+ copy_data_from_segment.segment_function = CopyDataFromListSegment;
99664
99770
 
99665
99771
  write_data_to_segment.child_functions.emplace_back(WriteDataToSegment());
99666
99772
  write_data_to_segment.child_functions.back().create_segment = CreatePrimitiveSegment<char>;
99773
+ copy_data_from_segment.child_functions.emplace_back(CopyDataFromSegment());
99774
+ copy_data_from_segment.child_functions.back().segment_function = CopyDataFromPrimitiveSegment<char>;
99667
99775
  break;
99668
99776
  }
99669
99777
  case PhysicalType::LIST: {
99670
99778
  write_data_to_segment.create_segment = CreateListSegment;
99671
99779
  write_data_to_segment.segment_function = WriteDataToListSegment;
99672
99780
  read_data_from_segment.segment_function = ReadDataFromListSegment;
99781
+ copy_data_from_segment.segment_function = CopyDataFromListSegment;
99673
99782
 
99674
99783
  // recurse
99675
99784
  write_data_to_segment.child_functions.emplace_back(WriteDataToSegment());
99676
99785
  read_data_from_segment.child_functions.emplace_back(ReadDataFromSegment());
99786
+ copy_data_from_segment.child_functions.emplace_back(CopyDataFromSegment());
99677
99787
  GetSegmentDataFunctions(write_data_to_segment.child_functions.back(),
99678
- read_data_from_segment.child_functions.back(), ListType::GetChildType(type));
99788
+ read_data_from_segment.child_functions.back(),
99789
+ copy_data_from_segment.child_functions.back(), ListType::GetChildType(type));
99679
99790
  break;
99680
99791
  }
99681
99792
  case PhysicalType::STRUCT: {
99682
99793
  write_data_to_segment.create_segment = CreateStructSegment;
99683
99794
  write_data_to_segment.segment_function = WriteDataToStructSegment;
99684
99795
  read_data_from_segment.segment_function = ReadDataFromStructSegment;
99796
+ copy_data_from_segment.segment_function = CopyDataFromStructSegment;
99685
99797
 
99686
99798
  // recurse
99687
99799
  auto child_types = StructType::GetChildTypes(type);
99688
99800
  for (idx_t i = 0; i < child_types.size(); i++) {
99689
99801
  write_data_to_segment.child_functions.emplace_back(WriteDataToSegment());
99690
99802
  read_data_from_segment.child_functions.emplace_back(ReadDataFromSegment());
99803
+ copy_data_from_segment.child_functions.emplace_back(CopyDataFromSegment());
99691
99804
  GetSegmentDataFunctions(write_data_to_segment.child_functions.back(),
99692
- read_data_from_segment.child_functions.back(), child_types[i].second);
99805
+ read_data_from_segment.child_functions.back(),
99806
+ copy_data_from_segment.child_functions.back(), child_types[i].second);
99693
99807
  }
99694
99808
  break;
99695
99809
  }
@@ -99702,7 +99816,7 @@ ListBindData::ListBindData(const LogicalType &stype_p) : stype(stype_p) {
99702
99816
 
99703
99817
  // always unnest once because the result vector is of type LIST
99704
99818
  auto type = ListType::GetChildType(stype_p);
99705
- GetSegmentDataFunctions(write_data_to_segment, read_data_from_segment, type);
99819
+ GetSegmentDataFunctions(write_data_to_segment, read_data_from_segment, copy_data_from_segment, type);
99706
99820
  }
99707
99821
 
99708
99822
  ListBindData::~ListBindData() {
@@ -99770,11 +99884,13 @@ static void ListUpdateFunction(Vector inputs[], AggregateInputData &aggr_input_d
99770
99884
  }
99771
99885
  }
99772
99886
 
99773
- static void ListCombineFunction(Vector &state, Vector &combined, AggregateInputData &, idx_t count) {
99887
+ static void ListCombineFunction(Vector &state, Vector &combined, AggregateInputData &aggr_input_data, idx_t count) {
99774
99888
  UnifiedVectorFormat sdata;
99775
99889
  state.ToUnifiedFormat(count, sdata);
99776
99890
  auto states_ptr = (ListAggState **)sdata.data;
99777
99891
 
99892
+ auto &list_bind_data = (ListBindData &)*aggr_input_data.bind_data;
99893
+
99778
99894
  auto combined_ptr = FlatVector::GetData<ListAggState *>(combined);
99779
99895
  for (idx_t i = 0; i < count; i++) {
99780
99896
  auto state = states_ptr[sdata.sel->get_index(i)];
@@ -99784,32 +99900,27 @@ static void ListCombineFunction(Vector &state, Vector &combined, AggregateInputD
99784
99900
  }
99785
99901
  D_ASSERT(state->type);
99786
99902
  D_ASSERT(state->owning_vector);
99787
- if (!combined_ptr[i]->linked_list) {
99788
99903
 
99789
- // copy the linked list
99904
+ if (!combined_ptr[i]->linked_list) {
99790
99905
  combined_ptr[i]->linked_list = new LinkedList(0, nullptr, nullptr);
99791
- combined_ptr[i]->linked_list->first_segment = state->linked_list->first_segment;
99792
- combined_ptr[i]->linked_list->last_segment = state->linked_list->last_segment;
99793
- combined_ptr[i]->linked_list->total_capacity = state->linked_list->total_capacity;
99794
-
99795
- // copy the type
99906
+ combined_ptr[i]->owning_vector = new vector<AllocatedData>;
99796
99907
  combined_ptr[i]->type = new LogicalType(*state->type);
99908
+ }
99909
+ auto owning_vector = combined_ptr[i]->owning_vector;
99797
99910
 
99798
- // new owning_vector to hold the unique pointers
99799
- combined_ptr[i]->owning_vector = new vector<AllocatedData>;
99911
+ // copy the linked list of the state
99912
+ auto copied_linked_list = LinkedList(state->linked_list->total_capacity, nullptr, nullptr);
99913
+ CopyLinkedList(list_bind_data.copy_data_from_segment, state->linked_list, copied_linked_list,
99914
+ aggr_input_data.allocator, *owning_vector);
99800
99915
 
99916
+ // append the copied linked list to the combined state
99917
+ if (combined_ptr[i]->linked_list->last_segment) {
99918
+ combined_ptr[i]->linked_list->last_segment->next = copied_linked_list.first_segment;
99801
99919
  } else {
99802
- combined_ptr[i]->linked_list->last_segment->next = state->linked_list->first_segment;
99803
- combined_ptr[i]->linked_list->last_segment = state->linked_list->last_segment;
99804
- combined_ptr[i]->linked_list->total_capacity += state->linked_list->total_capacity;
99805
- }
99806
-
99807
- // copy the owning vector (and its unique pointers to the allocated data)
99808
- // FIXME: more efficient way of copying the unique pointers?
99809
- auto &owning_vector = *state->owning_vector;
99810
- for (idx_t j = 0; j < state->owning_vector->size(); j++) {
99811
- combined_ptr[i]->owning_vector->push_back(move(owning_vector[j]));
99920
+ combined_ptr[i]->linked_list->first_segment = copied_linked_list.first_segment;
99812
99921
  }
99922
+ combined_ptr[i]->linked_list->last_segment = copied_linked_list.last_segment;
99923
+ combined_ptr[i]->linked_list->total_capacity += copied_linked_list.total_capacity;
99813
99924
  }
99814
99925
  }
99815
99926
 
@@ -203117,7 +203228,9 @@ private:
203117
203228
  // as a result we can truncate the file
203118
203229
  auto max_index = index_manager.GetMaxIndex();
203119
203230
  auto &fs = FileSystem::GetFileSystem(db);
203231
+ #ifndef WIN32 // this ended up causing issues when sorting
203120
203232
  fs.Truncate(*handle, GetPositionInFile(max_index + 1));
203233
+ #endif
203121
203234
  }
203122
203235
  }
203123
203236
 
package/src/duckdb.hpp CHANGED
@@ -11,8 +11,8 @@ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLI
11
11
  #pragma once
12
12
  #define DUCKDB_AMALGAMATION 1
13
13
  #define DUCKDB_AMALGAMATION_EXTENDED 1
14
- #define DUCKDB_SOURCE_ID "8d4671cf50"
15
- #define DUCKDB_VERSION "v0.6.1-dev254"
14
+ #define DUCKDB_SOURCE_ID "dd324b443e"
15
+ #define DUCKDB_VERSION "v0.6.1-dev263"
16
16
  //===----------------------------------------------------------------------===//
17
17
  // DuckDB
18
18
  //
@@ -1684,7 +1684,7 @@ public:
1684
1684
  }
1685
1685
 
1686
1686
  template <class T, typename... ARGS>
1687
- void ReadList(vector<unique_ptr<T>> &list, ARGS &&... args) {
1687
+ void ReadList(vector<unique_ptr<T>> &list, ARGS &&...args) {
1688
1688
  auto select_count = Read<uint32_t>();
1689
1689
  for (uint32_t i = 0; i < select_count; i++) {
1690
1690
  auto child = T::Deserialize(*this, std::forward<ARGS>(args)...);
@@ -1693,7 +1693,7 @@ public:
1693
1693
  }
1694
1694
 
1695
1695
  template <class T, class RETURN_TYPE = T, typename... ARGS>
1696
- unique_ptr<RETURN_TYPE> ReadOptional(ARGS &&... args) {
1696
+ unique_ptr<RETURN_TYPE> ReadOptional(ARGS &&...args) {
1697
1697
  auto has_entry = Read<bool>();
1698
1698
  if (has_entry) {
1699
1699
  return T::Deserialize(*this, std::forward<ARGS>(args)...);
@@ -4333,7 +4333,7 @@ void DeleteArray(T *ptr, idx_t size) {
4333
4333
  }
4334
4334
 
4335
4335
  template <typename T, typename... ARGS>
4336
- T *AllocateObject(ARGS &&... args) {
4336
+ T *AllocateObject(ARGS &&...args) {
4337
4337
  auto data = Allocator::DefaultAllocator().AllocateData(sizeof(T));
4338
4338
  return new (data) T(std::forward<ARGS>(args)...);
4339
4339
  }
@@ -10433,7 +10433,7 @@ public:
10433
10433
  }
10434
10434
 
10435
10435
  template <class T, typename... ARGS>
10436
- unique_ptr<T> ReadOptional(unique_ptr<T> default_value, ARGS &&... args) {
10436
+ unique_ptr<T> ReadOptional(unique_ptr<T> default_value, ARGS &&...args) {
10437
10437
  if (field_count >= max_field_count) {
10438
10438
  // field is not there, read the default value
10439
10439
  return default_value;
@@ -10455,7 +10455,7 @@ public:
10455
10455
  }
10456
10456
 
10457
10457
  template <class T, class RETURN_TYPE = unique_ptr<T>, typename... ARGS>
10458
- RETURN_TYPE ReadSerializable(RETURN_TYPE default_value, ARGS &&... args) {
10458
+ RETURN_TYPE ReadSerializable(RETURN_TYPE default_value, ARGS &&...args) {
10459
10459
  if (field_count >= max_field_count) {
10460
10460
  // field is not there, read the default value
10461
10461
  return default_value;
@@ -10477,7 +10477,7 @@ public:
10477
10477
  }
10478
10478
 
10479
10479
  template <class T, class RETURN_TYPE = unique_ptr<T>, typename... ARGS>
10480
- RETURN_TYPE ReadRequiredSerializable(ARGS &&... args) {
10480
+ RETURN_TYPE ReadRequiredSerializable(ARGS &&...args) {
10481
10481
  if (field_count >= max_field_count) {
10482
10482
  // field is not there, throw an exception
10483
10483
  throw SerializationException("Attempting to read mandatory field, but field is missing");
@@ -10488,7 +10488,7 @@ public:
10488
10488
  }
10489
10489
 
10490
10490
  template <class T, class RETURN_TYPE = unique_ptr<T>, typename... ARGS>
10491
- vector<RETURN_TYPE> ReadRequiredSerializableList(ARGS &&... args) {
10491
+ vector<RETURN_TYPE> ReadRequiredSerializableList(ARGS &&...args) {
10492
10492
  if (field_count >= max_field_count) {
10493
10493
  // field is not there, throw an exception
10494
10494
  throw SerializationException("Attempting to read mandatory field, but field is missing");