Skip to content
Open
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
11 changes: 11 additions & 0 deletions parquet/src/record/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@ impl<'a> Iterator for RowColumnIter<'a> {

/// Trait for type-safe convenient access to fields within a Row.
pub trait RowAccessor {
/// Check if the field at the index is null.
fn is_null(&self, i: usize) -> bool;
/// Try to get a boolean value at the given index.
fn get_bool(&self, i: usize) -> Result<bool>;
/// Try to get a byte value at the given index.
Expand Down Expand Up @@ -247,6 +249,13 @@ impl RowFormatter for Row {
}

impl RowAccessor for Row {
fn is_null(&self, i: usize) -> bool {
match self.fields[i].1 {
Field::Null => true,
_ => false,
}
}

row_primitive_accessor!(get_bool, Bool, bool);

row_primitive_accessor!(get_byte, Byte, i8);
Expand Down Expand Up @@ -1651,6 +1660,8 @@ mod tests {
("p".to_string(), Field::Float16(f16::from_f32(9.1))),
]);

assert!(row.is_null(0));
assert!(!row.is_null(1));
assert!(!row.get_bool(1).unwrap());
assert_eq!(3, row.get_byte(2).unwrap());
assert_eq!(4, row.get_short(3).unwrap());
Expand Down