-
Notifications
You must be signed in to change notification settings - Fork 19
Add type-safe accessors to Row #85
Comments
PR: #86 |
It seems a little bit strange that we need to cast an entire row to a |
I agree. I can make this change but then each accessor will now need to perform two matches - one to check that the Row is a Group and then another match for the contained Row. This is in addition to creating a Vec for each row being read. This is quite expensive. I think a better approach would be for the row reader to return a trait for reading each row that has accessor methods that can get the value from each column without having to build the intermediate vec. I don't know how big a change that would be though. |
I pushed changes to the PR to add this: trait RowAccessor {
fn get_bool(&self, i: usize) -> Result<bool>;
fn get_byte(&self, i: usize) -> Result<i8>;
fn get_short(&self, i: usize) -> Result<i16>;
fn get_int(&self, i: usize) -> Result<i32>;
fn get_long(&self, i: usize) -> Result<i64>;
fn get_float(&self, i: usize) -> Result<f32>;
fn get_double(&self, i: usize) -> Result<f64>;
fn get_string(&self, i: usize) -> Result<&String>;
fn get_bytes(&self, i: usize) -> Result<&ByteArray>;
fn get_timestamp(&self, i: usize) -> Result<u64>;
fn get_group(&self, i: usize) -> Result<&Vec<(String,Row)>>;
fn get_list(&self, i: usize) -> Result<&Vec<(Row)>>;
fn get_map(&self, i: usize) -> Result<&Vec<(Row,Row)>>;
} I then implemented this for Row. Let me know if you like this and I'll finish adding the tests. |
I figure with this approach, it will be possible later to have get_row_reader() return an iterator over this perhaps. |
I wonder if it makes sense to break the current @sadikovi : would like to know your thought on this. |
It is a good idea, plus, I think it should have been named RowField in the first place:). I like the idea of accessing by field name and by position. The implementation might take some time though, so I would suggest we go with what @andygrove has done, since it is already really good, and would unblock him. |
Closing this since #86 is merged. |
When processing parquet files I would like the ability to get values like this:
Currently I have to write pattern matching each time I want to extract a value.
The text was updated successfully, but these errors were encountered: