ReadStatMetadata

Struct ReadStatMetadata 

Source
pub struct ReadStatMetadata {
Show 13 fields pub row_count: i32, pub var_count: i32, pub table_name: String, pub file_label: String, pub file_encoding: String, pub version: i32, pub is64bit: i32, pub creation_time: String, pub modified_time: String, pub compression: ReadStatCompress, pub endianness: ReadStatEndian, pub vars: BTreeMap<i32, ReadStatVarMetadata>, pub schema: Schema,
}
Expand description

File-level metadata extracted from a .sas7bdat file.

Populated by the handle_metadata and handle_variable FFI callbacks during parsing. After parsing, call read_metadata to populate all fields and build the Arrow [Schema].

Fields§

§row_count: i32

Number of rows (observations) in the dataset.

§var_count: i32

Number of variables (columns) in the dataset.

§table_name: String

Internal table name from the SAS file header.

§file_label: String

User-assigned file label.

§file_encoding: String

Character encoding of the file (e.g. "UTF-8", "WINDOWS-1252").

§version: i32

SAS file format version number.

§is64bit: i32

Whether the file uses 64-bit format (0 = 32-bit, 1 = 64-bit).

§creation_time: String

File creation timestamp (formatted as YYYY-MM-DD HH:MM:SS).

§modified_time: String

File modification timestamp (formatted as YYYY-MM-DD HH:MM:SS).

§compression: ReadStatCompress

Compression method used in the file.

§endianness: ReadStatEndian

Byte order (endianness) of the file.

§vars: BTreeMap<i32, ReadStatVarMetadata>

Per-variable metadata, keyed by variable index.

§schema: Schema

Arrow schema derived from variable types. Not serialized.

Implementations§

Source§

impl ReadStatMetadata

Source

pub fn new() -> Self

Creates a new ReadStatMetadata with default (empty) values.

Source

fn initialize_schema(&self) -> Schema

Source

pub fn read_metadata( &mut self, rsp: &ReadStatPath, skip_row_count: bool, ) -> Result<(), ReadStatError>

Parses metadata from the .sas7bdat file referenced by rsp.

Sets up the ReadStat C parser with metadata and variable handlers, then invokes parsing. On success, builds the Arrow [Schema] from the discovered variable types. If skip_row_count is true, sets a row limit of 1 to skip counting all rows (faster for metadata-only queries).

§Errors

Returns ReadStatError if FFI parsing fails.

Source

pub fn read_metadata_from_bytes( &mut self, bytes: &[u8], skip_row_count: bool, ) -> Result<(), ReadStatError>

Parses metadata from an in-memory byte slice containing .sas7bdat data.

Equivalent to read_metadata but reads from a &[u8] buffer instead of a file path. Useful for WASM targets, cloud storage, HTTP uploads, and testing without filesystem access.

§Errors

Returns ReadStatError if FFI parsing fails.

§Panics

Panics if the dummy path CString allocation fails (should never happen).

Source

pub fn read_metadata_from_mmap( &mut self, path: &Path, skip_row_count: bool, ) -> Result<(), ReadStatError>

Parses metadata from a memory-mapped .sas7bdat file.

Opens the file at path and memory-maps it, avoiding explicit read syscalls. The OS loads pages on demand and manages caching automatically. This is especially beneficial for large files where it avoids copying file data through kernel buffers.

§Safety

Memory mapping is safe as long as the file is not modified or truncated by another process while the map is active. This is the standard expectation for .sas7bdat files, which are read-only artifacts.

§Errors

Returns ReadStatError if the file cannot be opened, mapped, or parsed.

Source

pub fn parse_columns_file(path: &Path) -> Result<Vec<String>, ReadStatError>

Parses a columns file, returning column names.

Lines starting with # are treated as comments and blank lines are skipped. Each remaining line is trimmed and used as a column name.

§Errors

Returns ReadStatError if the file cannot be read.

Source

pub fn resolve_selected_columns( &self, columns: Option<Vec<String>>, ) -> Result<Option<BTreeMap<i32, i32>>, ReadStatError>

Validates column names against the dataset’s variables and returns a mapping of original variable index to new contiguous index.

Returns Ok(None) if columns is None (no filtering requested). Returns Err(ColumnsNotFound) if any requested names are not in the dataset.

§Errors

Returns ReadStatError::ColumnsNotFound if any requested column names do not exist in the dataset.

Source

pub fn filter_to_selected_columns(&self, mapping: &BTreeMap<i32, i32>) -> Self

Returns a new ReadStatMetadata with only the selected variables, re-keyed with contiguous indices starting from 0.

Constructs the result directly instead of cloning the full struct, avoiding a deep clone of unselected variables and the original schema.

Trait Implementations§

Source§

impl Clone for ReadStatMetadata

Source§

fn clone(&self) -> ReadStatMetadata

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ReadStatMetadata

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for ReadStatMetadata

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Serialize for ReadStatMetadata

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> Allocation for T
where T: RefUnwindSafe + Send + Sync,