MCPcopy Create free account
hub / github.com/NodeDB-Lab/nodedb / extract_column_to_arrow

Function extract_column_to_arrow

nodedb-strict/src/arrow_extract.rs:31–72  ·  view source on GitHub ↗

Extract a single column from a batch of tuples into an Arrow `ArrayRef`. `tuples` is a slice of raw tuple byte slices (as stored in redb). `col_idx` is the column index in the schema. Returns an appropriately-typed Arrow array (Int64Array, StringArray, etc.) with a null bitmap derived from the tuples' null bitmaps.

(
    schema: &StrictSchema,
    decoder: &TupleDecoder,
    tuples: &[&[u8]],
    col_idx: usize,
)

Source from the content-addressed store, hash-verified

29/// Returns an appropriately-typed Arrow array (Int64Array, StringArray, etc.)
30/// with a null bitmap derived from the tuples' null bitmaps.
31pub fn extract_column_to_arrow(
32 schema: &StrictSchema,
33 decoder: &TupleDecoder,
34 tuples: &[&[u8]],
35 col_idx: usize,
36) -> Result<ArrayRef, StrictError> {
37 if col_idx >= schema.columns.len() {
38 return Err(StrictError::ColumnOutOfRange {
39 index: col_idx,
40 count: schema.columns.len(),
41 });
42 }
43
44 let col_type = &schema.columns[col_idx].column_type;
45 let n = tuples.len();
46
47 match col_type {
48 ColumnType::Int64 => extract_int64(decoder, tuples, col_idx, n),
49 ColumnType::Float64 => extract_float64(decoder, tuples, col_idx, n),
50 ColumnType::Bool => extract_bool(decoder, tuples, col_idx, n),
51 ColumnType::Timestamp | ColumnType::Timestamptz | ColumnType::SystemTimestamp => {
52 extract_timestamp(decoder, tuples, col_idx, n)
53 }
54 ColumnType::String => extract_string(decoder, tuples, col_idx, n),
55 ColumnType::Bytes
56 | ColumnType::Geometry
57 | ColumnType::Json
58 | ColumnType::Array
59 | ColumnType::Set
60 | ColumnType::Range
61 | ColumnType::Record => extract_binary(decoder, tuples, col_idx, n),
62 ColumnType::Decimal { .. } => extract_decimal_as_string(decoder, tuples, col_idx, n),
63 ColumnType::Uuid => extract_uuid(decoder, tuples, col_idx, n),
64 ColumnType::Ulid => extract_uuid(decoder, tuples, col_idx, n), // same 16-byte layout
65 ColumnType::Duration => extract_int64(decoder, tuples, col_idx, n), // i64 microseconds
66 ColumnType::Regex => extract_string(decoder, tuples, col_idx, n), // stored as string
67 ColumnType::Vector(dim) => extract_vector(decoder, tuples, col_idx, n, *dim as usize),
68 // ColumnType is #[non_exhaustive]; unknown future types are extracted
69 // as binary blobs so Arrow consumers can at least receive raw bytes.
70 _ => extract_binary(decoder, tuples, col_idx, n),
71 }
72}
73
74/// Build a NullBuffer from the null bitmap of N tuples for a given column.
75fn build_null_buffer(

Callers 5

extract_int64_columnFunction · 0.85
extract_string_columnFunction · 0.85

Calls 10

extract_int64Function · 0.85
extract_float64Function · 0.85
extract_boolFunction · 0.85
extract_binaryFunction · 0.85
extract_uuidFunction · 0.85
extract_vectorFunction · 0.85
extract_timestampFunction · 0.70
extract_stringFunction · 0.70
lenMethod · 0.45

Tested by 5

extract_int64_columnFunction · 0.68
extract_string_columnFunction · 0.68