pub fn lag_str<T: Integer>(
arr: StringAVT<'_, T>,
n: usize,
) -> Result<StringArray<T>, KernelError>Expand description
Accesses string values from previous positions with UTF-8 string handling.
Implements SQL LAG() function for string data, retrieving textual values from earlier positions in the array sequence. Essential for textual analysis, sequential string processing, and comparative text analytics.
§Parameters
arr- String array view containing sequential textual datan- Lag offset specifying backward position distance
§Returns
Returns Result<StringArray<T>, KernelError> containing:
- Success: String values from n positions earlier
- Error: KernelError if string processing fails
- Empty strings for positions with insufficient history
- Null mask indicating lag validity and source availability
§String Lag Semantics
- UTF-8 preservation: Maintains proper UTF-8 encoding throughout operation
- Null propagation: Null strings in source positions result in null outputs
- Memory management: Efficient string copying and allocation strategies
- Boundary handling: Positions without history receive empty string defaults
§Applications
- Text analysis: Comparing current text with previous entries
- Sequential processing: Analysing patterns in ordered textual data
- Log analysis: Accessing previous log entries for context
- Natural language processing: Context-aware text processing with history
§Examples
ⓘ
use minarrow::StringArray;
use simd_kernels::kernels::window::lag_str;
let arr = StringArray::<u32>::from_slice(&["first", "second", "third"]);
let result = lag_str((&arr, 0, arr.len()), 1).unwrap();
// Output: ["", "first", "second"] - strings lagged by 1 position