This is an automated email from the ASF dual-hosted git repository.

tustvold pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/arrow-rs.git


The following commit(s) were added to refs/heads/master by this push:
     new fa8d3502388 Add exposing fields from parquet row (#5842)
fa8d3502388 is described below

commit fa8d3502388d7cfac724f7b9fae92abc3a716b6f
Author: Evgeniy Zuikin <[email protected]>
AuthorDate: Wed Jun 5 23:53:52 2024 +0700

    Add exposing fields from parquet row (#5842)
    
    * Add exposing fields from parquet row
    
    * revert formatting
    
    * fmt
---
 parquet/src/record/api.rs    | 20 ++++++++++++++++++++
 parquet/src/record/reader.rs | 15 +++++++++++++++
 2 files changed, 35 insertions(+)

diff --git a/parquet/src/record/api.rs b/parquet/src/record/api.rs
index e4f473562e0..85d96fd6527 100644
--- a/parquet/src/record/api.rs
+++ b/parquet/src/record/api.rs
@@ -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
diff --git a/parquet/src/record/reader.rs b/parquet/src/record/reader.rs
index d74dcd276e8..cc29658d918 100644
--- a/parquet/src/record/reader.rs
+++ b/parquet/src/record/reader.rs
@@ -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 = "

Reply via email to