Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions vortex-duckdb/cpp/include/duckdb_vx/vector.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ DUCKDB_INCLUDES_END
extern "C" {
#endif

// Create a vector that slices another vector between a pair of offsets [offset, end)
duckdb_vector duckdb_vx_vector_slice(duckdb_vector ffi_vector, idx_t offset, idx_t end);

/// Slice the vector to a new dictionary vector, using the current vector's values and
/// the provided selection vector.
///
Expand Down
7 changes: 6 additions & 1 deletion vortex-duckdb/cpp/vector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,16 @@ DUCKDB_INCLUDES_BEGIN
#include "duckdb/common/types/vector.hpp"
DUCKDB_INCLUDES_END

#include "duckdb_vx.h"
#include "duckdb_vx/vector_buffer.hpp"

using namespace duckdb;

extern "C" duckdb_vector duckdb_vx_vector_slice(duckdb_vector ffi_vector, idx_t offset, idx_t end) {
const Vector &vector = *reinterpret_cast<Vector *>(ffi_vector);
Vector *const sliced = new Vector(vector, offset, end);
return reinterpret_cast<duckdb_vector>(sliced);
}

extern "C" void duckdb_vx_vector_slice_to_dictionary(duckdb_vector ffi_vector,
duckdb_selection_vector ffi_sel_vec,
idx_t selection_vector_length) {
Expand Down
2 changes: 2 additions & 0 deletions vortex-duckdb/src/convert/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ mod scalar;
mod table_filter;
mod vector;

#[cfg(test)]
pub use dtype::FromLogicalType;
Comment thread
myrrc marked this conversation as resolved.
pub use dtype::from_duckdb_table;
pub use expr::try_from_bound_expression;
pub use scalar::*;
Expand Down
17 changes: 17 additions & 0 deletions vortex-duckdb/src/duckdb/vector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

use std::ffi::CStr;
use std::ffi::c_void;
use std::ops::Range;
use std::ptr;

use bitvec::macros::internal::funty::Fundamental;
Expand Down Expand Up @@ -62,6 +63,18 @@ impl Vector {
pub fn with_capacity(logical_type: &LogicalTypeRef, len: usize) -> Self {
unsafe { Self::own(cpp::duckdb_create_vector(logical_type.as_ptr(), len as _)) }
}

/// Create a new vector that references other's element range.
/// Both vectors share the same buffer.
pub fn slice(other: &VectorRef, range: Range<u64>) -> Self {
unsafe {
Self::own(cpp::duckdb_vx_vector_slice(
other.as_ptr(),
range.start,
range.end,
))
}
}
}

impl VectorRef {
Expand Down Expand Up @@ -307,6 +320,10 @@ impl VectorRef {
unsafe { Vector::borrow_mut(cpp::duckdb_array_vector_get_child(self.as_ptr())) }
}

pub fn list_vector_get_size(&self) -> u64 {
unsafe { cpp::duckdb_list_vector_get_size(self.as_ptr()) }
}

pub fn list_vector_set_size(&self, size: u64) -> VortexResult<()> {
let state = unsafe { cpp::duckdb_list_vector_set_size(self.as_ptr(), size) };
match state {
Expand Down
4 changes: 3 additions & 1 deletion vortex-duckdb/src/e2e_test/vortex_scan_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -982,8 +982,10 @@ fn test_vortex_encodings_roundtrip() {
assert_eq!(list_entries[4].offset, 10);

// Get child vector and verify actual values
let list_child_len = list_vec.list_vector_get_size();
assert_eq!(list_child_len, 10);
let list_child = list_vec.list_vector_get_child();
let child_values = list_child.as_slice_with_len::<i32>(10); // 10 total child elements
let child_values = list_child.as_slice_with_len::<i32>(list_child_len.as_());
assert_eq!(child_values, [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);

// Verify fixed-size list column (column 9)
Expand Down
Loading
Loading