You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "Joseph-Rance (via GitHub)" <gi...@apache.org> on 2023/10/02 10:58:42 UTC

Re: [PR] Add `RecordReader` trait and proc macro to implement it for a struct [arrow-rs]

Joseph-Rance commented on code in PR #4773:
URL: https://github.com/apache/arrow-rs/pull/4773#discussion_r1342545617


##########
parquet_derive/README.md:
##########
@@ -77,16 +77,55 @@ writer.close_row_group(row_group).unwrap();
 writer.close().unwrap();
 ```
 
+Example usage of deriving a `RecordReader` for your struct:
+
+```rust
+use parquet::file::{serialized_reader::SerializedFileReader, reader::FileReader};
+use parquet_derive::ParquetRecordReader;
+
+#[derive(ParquetRecordReader)]
+struct ACompleteRecord {
+    pub a_bool: bool,
+    pub a_string: String,
+    pub i16: i16,
+    pub i32: i32,
+    pub u64: u64,
+    pub isize: isize,
+    pub float: f32,
+    pub double: f64,
+    pub now: chrono::NaiveDateTime,
+    pub byte_vec: Vec<u8>,
+}
+
+// Initialize your parquet file
+let reader = SerializedFileReader::new(file).unwrap();
+let mut row_group = reader.get_row_group(0).unwrap();
+
+// create your records to read into
+let mut chunks = vec![ACompleteRecord{ ... }];

Review Comment:
   Where do you want to initialise the structs? If we want to do it at the start of the macro we would need the struct to derive default, which I think might be problematic for some structs. I don't think we can very easily initialise the struct with all the data we have already read because we read them column by column. I can save the columns and then build the structs after the entire file is read but this seems possibly overcomplicated compared to just letting the user initialise the structs.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org