Skip to content

Commit fa8d350

Browse files
authored
Add exposing fields from parquet row (#5842)
* Add exposing fields from parquet row * revert formatting * fmt
1 parent bca2f3a commit fa8d350

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

parquet/src/record/api.rs

+20
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,26 @@ impl Row {
5757
self.fields.len()
5858
}
5959

60+
/// Move columns data out of the row. Useful to avoid internal data cloning.
61+
///
62+
/// # Example
63+
///
64+
/// ```no_run
65+
/// use std::fs::File;
66+
/// use parquet::record::Row;
67+
/// use parquet::file::reader::{FileReader, SerializedFileReader};
68+
///
69+
/// let file = File::open("/path/to/file").unwrap();
70+
/// let reader = SerializedFileReader::new(file).unwrap();
71+
/// let row: Row = reader.get_row_iter(None).unwrap().next().unwrap().unwrap();
72+
/// let columns = row.into_columns();
73+
/// println!("row columns: {:?}", columns);
74+
///
75+
/// ```
76+
pub fn into_columns(self) -> Vec<(String, Field)> {
77+
self.fields
78+
}
79+
6080
/// Get an iterator to go through all columns in the row.
6181
///
6282
/// # Example

parquet/src/record/reader.rs

+15
Original file line numberDiff line numberDiff line change
@@ -1280,6 +1280,21 @@ mod tests {
12801280
);
12811281
}
12821282

1283+
#[test]
1284+
fn test_into_columns_in_row() {
1285+
let r = row![
1286+
("a".to_string(), Field::Str("My string".to_owned())),
1287+
("b".to_string(), Field::Int(1))
1288+
];
1289+
assert_eq!(
1290+
r.into_columns(),
1291+
vec![
1292+
("a".to_string(), Field::Str("My string".to_owned())),
1293+
("b".to_string(), Field::Int(1)),
1294+
]
1295+
);
1296+
}
1297+
12831298
#[test]
12841299
fn test_file_reader_rows_projection_map() {
12851300
let schema = "

0 commit comments

Comments
 (0)