-
Notifications
You must be signed in to change notification settings - Fork 4k
ARROW-18265: [C++][Python] Support FieldRef to work with ListElement #14697
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ARROW-18265: [C++][Python] Support FieldRef to work with ListElement #14697
Conversation
jorisvandenbossche
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(just a quick look at the tests)
parent was not passed in FieldPath first iteration
| static bool IsBaseListType(const DataType& type) { | ||
| return dynamic_cast<const BaseListType*>(&type) != nullptr; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have is_list_like helper defined (although that also includes Map type, not sure if the list_element kernel supports that)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, if we keep this, using a combination of a few type.id() == .. checks (like ValidParentType just below) might be more readable to know which types are included)
| if (!ValidParentType(type)) { | ||
| return Status::TypeError("struct_field: cannot subscript field of type ", type); | ||
| } else if (index < 0 || index >= type.num_fields()) { | ||
| } else if (!IsBaseListType(type) && (index < 0 || index >= type.num_fields())) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In theory, we could check the index for fixed sized list arrays as well (not for variable size list arrays, though, so not sure that is worth it)
| // Children then are fields from list type, and out will be the children from | ||
| // that field, thus index 0. | ||
| if (out != nullptr && IsBaseListType(*(*out)->type())) { | ||
| children = get_children(*out); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't fully understand why we need the get_children here (because then we call get_children twice in a single iteration? since there is another call a bit below)
Can you add a clarifying comment about that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(or to put it differently: why isn't this initial get_children needed when parent is a struct type? What's the difference between both?)
| // FindAll, only used by kernels for which list element to take. When FindAll | ||
| // encounters a list, it assumes the list value type. Not b/c they are numeric, but | ||
| // they are the position referencing a specific list element. | ||
| EXPECT_THAT(FieldRef("c", 0, "d").FindAll(*type), ElementsAre(FieldPath{0, 0, 0})); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you also add variants of those tests that pass a schema instead of type to FindAll?
|
I find it a bit uneasy how this PR is conflating a purely metadata-based field lookup (the current semantics of |
Not sure if |
I am not sure that this is still entirely correct nowadays, since we already do use
If you want to work with list types, this is a pretty basic operation. Now, the actual operation is already supported ( Another example of database that supports this in queries: https://cloud.google.com/bigquery/docs/reference/standard-sql/arrays#accessing_array_elements |
|
And to be clear, that's also basically the question that I asked on the JIRA: "do we want to use FieldRef/FieldPath for this?" (because it does deviate from how it is currently implemented) It could also be a different (new to add) data structure (that would be used throughout the compute code instead of the current FieldRef/FieldPath) |
|
Hmm... The convenience argument is convincing, I admit. Still, I wonder if we shouldn't make it optional in FieldRef, perhaps by adding a |
|
Closing because it has been untouched for a while, in case it's still relevant feel free to reopen and move it forward 👍 |
Will fix ARROW-18265
Type::LISTExample