Skip to content

Commit

Permalink
Add exposing fields from parquet row (#5842)
Browse files Browse the repository at this point in the history
* Add exposing fields from parquet row

* revert formatting

* fmt
  • Loading branch information
SHaaD94 authored Jun 5, 2024
1 parent bca2f3a commit fa8d350
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
20 changes: 20 additions & 0 deletions parquet/src/record/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,26 @@ impl Row {
self.fields.len()
}

/// Move columns data out of the row. Useful to avoid internal data cloning.
///
/// # Example
///
/// ```no_run
/// use std::fs::File;
/// use parquet::record::Row;
/// use parquet::file::reader::{FileReader, SerializedFileReader};
///
/// let file = File::open("/path/to/file").unwrap();
/// let reader = SerializedFileReader::new(file).unwrap();
/// let row: Row = reader.get_row_iter(None).unwrap().next().unwrap().unwrap();
/// let columns = row.into_columns();
/// println!("row columns: {:?}", columns);
///
/// ```
pub fn into_columns(self) -> Vec<(String, Field)> {
self.fields
}

/// Get an iterator to go through all columns in the row.
///
/// # Example
Expand Down
15 changes: 15 additions & 0 deletions parquet/src/record/reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1280,6 +1280,21 @@ mod tests {
);
}

#[test]
fn test_into_columns_in_row() {
let r = row![
("a".to_string(), Field::Str("My string".to_owned())),
("b".to_string(), Field::Int(1))
];
assert_eq!(
r.into_columns(),
vec![
("a".to_string(), Field::Str("My string".to_owned())),
("b".to_string(), Field::Int(1)),
]
);
}

#[test]
fn test_file_reader_rows_projection_map() {
let schema = "
Expand Down

0 comments on commit fa8d350

Please sign in to comment.