overwrite constant target vectors.
if the source has list offsets, we need to append them to the target build a selection vector for the copied child elements
143520 {
143521 SelectionVector owned_sel;
143522 const SelectionVector *sel = &sel_p;
143523
143524 const Vector *source = &source_p;
143525 bool finished = false;
143526 while (!finished) {
143527 switch (source->GetVectorType()) {
143528 case VectorType::DICTIONARY_VECTOR: {
143529
143530 auto &child = DictionaryVector::Child(*source);
143531 auto &dict_sel = DictionaryVector::SelVector(*source);
143532
143533 auto new_buffer = dict_sel.Slice(*sel, source_count);
143534 owned_sel.Initialize(new_buffer);
143535 sel = &owned_sel;
143536 source = &child;
143537 break;
143538 }
143539 case VectorType::SEQUENCE_VECTOR: {
143541 Vector seq(source->GetType());
143542 SequenceVector::GetSequence(*source, start, increment);
143543 VectorOperations::GenerateSequence(seq, source_count, *sel, start, increment);
143544 VectorOperations::Copy(seq, target, *sel, source_count, source_offset, target_offset);
143545 return;
143546 }
143547 case VectorType::CONSTANT_VECTOR:
143548 sel = ConstantVector::ZeroSelectionVector(copy_count, owned_sel);
143549 finished = true;
143550 break;
143551 case VectorType::FSST_VECTOR:
143552 finished = true;
143553 break;
143554 case VectorType::FLAT_VECTOR:
143555 finished = true;
143556 break;
143557 default:
143558 throw NotImplementedException("FIXME unimplemented vector type for VectorOperations::Copy");
143559 }
143560 }
143561
143562 if (copy_count == 0) {
143563 return;
143564 }
143565
143566
143567 const auto target_vector_type = target.GetVectorType();
143568 if (copy_count == 1 && target_vector_type == VectorType::CONSTANT_VECTOR) {
143569 target_offset = 0;
143570 target.SetVectorType(VectorType::FLAT_VECTOR);
143571 }
143572 D_ASSERT(target.GetVectorType() == VectorType::FLAT_VECTOR);
143573
143574
143575 auto &tmask = FlatVector::Validity(target);
143576 if (source->GetVectorType() == VectorType::CONSTANT_VECTOR) {
143577 const bool valid = !ConstantVector::IsNull(*source);
143578 for (
idx_t i = 0; i < copy_count; i++) {
143579 tmask.Set(target_offset + i, valid);
143580 }
143581 } else {
143582 auto &smask = ExtractValidityMask(*source);
143583 tmask.CopySel(smask, *sel, source_offset, target_offset, copy_count);
143584 }
143585
143586 D_ASSERT(sel);
143587
143588
143589 if (source->GetVectorType() == VectorType::FSST_VECTOR) {
143591 return;
143592 }
143593
143594
143595 switch (source->GetType().InternalType()) {
143598 TemplatedCopy<int8_t>(*source, *sel, target, source_offset, target_offset, copy_count);
143599 break;
143601 TemplatedCopy<int16_t>(*source, *sel, target, source_offset, target_offset, copy_count);
143602 break;
143604 TemplatedCopy<int32_t>(*source, *sel, target, source_offset, target_offset, copy_count);
143605 break;
143607 TemplatedCopy<int64_t>(*source, *sel, target, source_offset, target_offset, copy_count);
143608 break;
143610 TemplatedCopy<uint8_t>(*source, *sel, target, source_offset, target_offset, copy_count);
143611 break;
143613 TemplatedCopy<uint16_t>(*source, *sel, target, source_offset, target_offset, copy_count);
143614 break;
143616 TemplatedCopy<uint32_t>(*source, *sel, target, source_offset, target_offset, copy_count);
143617 break;
143619 TemplatedCopy<uint64_t>(*source, *sel, target, source_offset, target_offset, copy_count);
143620 break;
143621 case PhysicalType::INT128:
143622 TemplatedCopy<hugeint_t>(*source, *sel, target, source_offset, target_offset, copy_count);
143623 break;
143624 case PhysicalType::UINT128:
143625 TemplatedCopy<uhugeint_t>(*source, *sel, target, source_offset, target_offset, copy_count);
143626 break;
143628 TemplatedCopy<float>(*source, *sel, target, source_offset, target_offset, copy_count);
143629 break;
143631 TemplatedCopy<double>(*source, *sel, target, source_offset, target_offset, copy_count);
143632 break;
143634 TemplatedCopy<interval_t>(*source, *sel, target, source_offset, target_offset, copy_count);
143635 break;
143637 auto ldata = FlatVector::GetData<string_t>(*source);
143638 auto tdata = FlatVector::GetData<string_t>(target);
143639 for (
idx_t i = 0; i < copy_count; i++) {
143640 auto source_idx = sel->get_index(source_offset + i);
143641 auto target_idx = target_offset + i;
143642 if (tmask.RowIsValid(target_idx)) {
143644 }
143645 }
143646 break;
143647 }
143649 auto &source_children = StructVector::GetEntries(*source);
143650 auto &target_children = StructVector::GetEntries(target);
143651 D_ASSERT(source_children.size() == target_children.size());
143652 for (
idx_t i = 0; i < source_children.size(); i++) {
143653 VectorOperations::Copy(*source_children[i], *target_children[i], sel_p, source_count, source_offset,
143654 target_offset, copy_count);
143655 }
143656 break;
143657 }
143658 case PhysicalType::ARRAY: {
143659 D_ASSERT(target.GetType().InternalType() == PhysicalType::ARRAY);
143660 D_ASSERT(ArrayType::GetSize(source->GetType()) == ArrayType::GetSize(target.GetType()));
143661
143664 auto array_size = ArrayType::GetSize(source->GetType());
143665
143666
143667 SelectionVector child_sel(source_count * array_size);
143668 for (
idx_t i = 0; i < copy_count; i++) {
143669 auto source_idx = sel->get_index(source_offset + i);
143670 for (
idx_t j = 0; j < array_size; j++) {
143671 child_sel.set_index((source_offset * array_size) + (i * array_size + j), source_idx * array_size + j);
143672 }
143673 }
143674 VectorOperations::Copy(source_child, target_child, child_sel, source_count * array_size,
143675 source_offset * array_size, target_offset * array_size);
143676 break;
143677 }
143680
143682 auto sdata = FlatVector::GetData<list_entry_t>(*source);
143683 auto tdata = FlatVector::GetData<list_entry_t>(target);
143684
143685 if (target_vector_type == VectorType::CONSTANT_VECTOR) {
143686
143687
143688 if (!tmask.RowIsValid(target_offset)) {
143689 break;
143690 }
143691 auto source_idx = sel->get_index(source_offset);
143692 auto &source_entry = sdata[source_idx];
143693 const idx_t source_child_size = source_entry.length + source_entry.offset;
143694
143698
143699 auto &target_entry = tdata[target_offset];
143700 target_entry.length = source_entry.length;
143701 target_entry.offset = 0;
143702 } else {
143705 vector<sel_t> child_rows;
143706 for (
idx_t i = 0; i < copy_count; ++i) {
143707 if (tmask.RowIsValid(target_offset + i)) {
143708 auto source_idx = sel->get_index(source_offset + i);
143709 auto &source_entry = sdata[source_idx];
143710 for (
idx_t j = 0; j < source_entry.length; ++j) {
143711 child_rows.emplace_back(source_entry.offset + j);
143712 }
143713 }
143714 }
143715 idx_t source_child_size = child_rows.size();
143716 SelectionVector child_sel(child_rows.data());
143717
143719
143722
143724 for (
idx_t i = 0; i < copy_count; i++) {
143725 auto source_idx = sel->get_index(source_offset + i);
143726 auto &source_entry = sdata[source_idx];
143727 auto &target_entry = tdata[target_offset + i];
143728
143729 target_entry.length = source_entry.length;
143730 target_entry.offset = old_target_child_len;
143731 if (tmask.RowIsValid(target_offset + i)) {
143732 old_target_child_len += target_entry.length;
143733 }
143734 }
143735 }
143736 break;
143737 }
143738 default:
143739 throw NotImplementedException("Unimplemented type '%s' for copy!",
143740 TypeIdToString(source->GetType().InternalType()));
143741 }
143742
143743 if (target_vector_type != VectorType::FLAT_VECTOR) {
143744 target.SetVectorType(target_vector_type);
143745 }
143746}
@ UINT32
Unsigned 32-bit little-endian integer.
Definition duckdb.hpp:2758
@ INTERVAL
YEAR_MONTH or DAY_TIME interval in SQL style.
Definition duckdb.hpp:2806
@ LIST
A list of some logical data type.
Definition duckdb.hpp:2813
@ UINT16
Unsigned 16-bit little-endian integer.
Definition duckdb.hpp:2752
@ UINT64
Unsigned 64-bit little-endian integer.
Definition duckdb.hpp:2764
@ BOOL
Boolean as 8 bit "bool" value.
Definition duckdb.hpp:2743
@ STRUCT
Struct of logical types.
Definition duckdb.hpp:2816
@ VARCHAR
DuckDB Extensions.
Definition duckdb.hpp:2847
@ FLOAT
4-byte floating point value
Definition duckdb.hpp:2773
@ UINT8
Unsigned 8-bit little-endian integer.
Definition duckdb.hpp:2746
@ DOUBLE
8-byte floating point value
Definition duckdb.hpp:2776
static DUCKDB_API const Vector & GetEntry(const Vector &vector)
Gets a reference to the underlying child-vector of an array.
Definition duckdb.cpp:138574
static void DecompressVector(const Vector &src, Vector &dst, idx_t src_offset, idx_t dst_offset, idx_t copy_count, const SelectionVector *sel)
Decompresses an FSST_VECTOR into a FLAT_VECTOR. Note: validity is not copied.
Definition duckdb.cpp:138054
static DUCKDB_API void Append(Vector &target, const Vector &source, idx_t source_size, idx_t source_offset=0)
Definition duckdb.cpp:138257
static DUCKDB_API const Vector & GetEntry(const Vector &vector)
Gets a reference to the underlying child-vector of a list.
Definition duckdb.cpp:138203
static DUCKDB_API void SetListSize(Vector &vec, idx_t size)
Sets the total size of the underlying child-vector of a list.
Definition duckdb.cpp:138248
static DUCKDB_API idx_t GetListSize(const Vector &vector)
Gets the total size of the underlying child-vector of a list.
Definition duckdb.cpp:138221
static DUCKDB_API string_t AddStringOrBlob(Vector &vector, const char *data, idx_t len)
Definition duckdb.cpp:137893