Skip to content
This repository has been archived by the owner on Jan 11, 2021. It is now read-only.

Add accessors for List and Map type #101

Merged
merged 2 commits into from
Apr 25, 2018
Merged

Add accessors for List and Map type #101

merged 2 commits into from
Apr 25, 2018

Conversation

sunchao
Copy link
Owner

@sunchao sunchao commented Apr 24, 2018

Similar to Row, this adds accessors to List and Map type. For the
former, type-safe accessors are added to get the ith element in the
list. For the latter, getKeys and getValues are added to get the map
keys and values, respectively.

Similar to `Row`, this adds accessors to `List` and `Map` type. For the
former, type-safe accessors are added to get the `i`th element in the
list. For the latter, `getKeys` and `getValues` are added to get the map
keys and values, respectively.
@coveralls
Copy link

coveralls commented Apr 24, 2018

Coverage Status

Coverage increased (+0.05%) to 94.964% when pulling f8cd7d3 on list-map-access into 4d624ea on master.

Copy link
Collaborator

@sadikovi sadikovi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, just left a couple of questions.

// TODO: implement `getKeys`, `getValues`, etc., for `Map`.
/// Trait for type-safe access of an index for a `Map`
pub trait MapAccessor {
fn get_keys<'a>(&'a self) -> Box<ListAccessor + 'a>;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you consider returning Vec<Field> or &[Field] for keys and values? It might result in less code.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now the question is whether or not it is possible to get struct from map value if we return &[Field]. In this case we would have to map to Group(Row), and then use one of the accessors. So yes, it may be functionally correct to return ListAccessor.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, we are only exposing Row, List and Map at the moment, and each of them offers accessors. So, here we need to return ListAccessor instead of list of Field which is not exposed.

I'm also hesitant on whether the RowIter should return Box<RowAccessor> instead of Row. In future if we implement a batch-oriented record reader, we may want to return a Row from the current RowBatch, whose implementation may be different from what we have right now.

Also, it might better to rename the RowAccessor to Row, and the current Row to RowImpl or something.

Just some random thought 😀 .

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good, I would suggest we keep the current implementation for now.

fn get_values<'a>(&'a self) -> Box<ListAccessor + 'a>;
}

struct MapList<'a> {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will API work if this struct is private?

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good spot! Will change.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we don't need to export MapList, but only the accessors.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, makes sense.

Copy link
Collaborator

@sadikovi sadikovi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good.

@sunchao sunchao merged commit f0bcc82 into master Apr 25, 2018
@sunchao
Copy link
Owner Author

sunchao commented Apr 25, 2018

Merged. Thanks @sadikovi for the review!

@sunchao sunchao deleted the list-map-access branch April 25, 2018 04:50
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants