[ 
https://issues.apache.org/jira/browse/ARROW-18265?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17637679#comment-17637679
 ] 

Joris Van den Bossche edited comment on ARROW-18265 at 11/23/22 10:02 AM:
--------------------------------------------------------------------------

Yes, but the square-bracket form is basically the same as a single field path 
index, that is how it gets parsed (the top post could have been more explicit 
about this, instead of only mentioning FromDotPath, but also the resulting 
FieldPath). 

Using a small workaround through StructFieldOptions to show this in python:

{code}
>>> pc.StructFieldOptions(".x[0]")
StructFieldOptions(field_ref=FieldRef.Nested(FieldRef.Name(x) 
FieldRef.FieldPath(0)))
>>> pc.StructFieldOptions(["x", 0])
StructFieldOptions(field_ref=FieldRef.Nested(FieldRef.Name(x) 
FieldRef.FieldPath(0)))
{code}

So those two give currently the same result. Essentially, at the moment a "[0]" 
element in a path gets interpreted as {{pc.field(0)}}.

Given the above, AFAIU, we either agree that {{field_ref(0)}} for a list type 
means selecting the first element of each list (and thus not for selecting the 
flat values), or we either have to introduce a new concept in 
FieldRef/FieldPath to represent a list element selection (and thus also change 
how a "[0]" in a string path gets parsed to use this new object).


was (Author: jorisvandenbossche):
Yes, but the square-bracket form is basically the same as a single number, that 
is how it gets parsed (the top post could have been more explicit about this, 
instead of only mentioning FromDotPath, but also the resulting FieldPath). 

Using a small workaround through StructFieldOptions to show this in python:

{code}
>>> pc.StructFieldOptions(".x[0]")
StructFieldOptions(field_ref=FieldRef.Nested(FieldRef.Name(x) 
FieldRef.FieldPath(0)))
>>> pc.StructFieldOptions(["x", 0])
StructFieldOptions(field_ref=FieldRef.Nested(FieldRef.Name(x) 
FieldRef.FieldPath(0)))
{code}

So those two give currently the same result. Essentially, at the moment a "[0]" 
element in a path gets interpreted as {{pc.field(0)}}.

Given the above, AFAIU, we either agree that {{field_ref(0)}} for a list type 
means selecting the first element of each list (and thus not for selecting the 
flat values), or we either have to introduce a new concept in 
FieldRef/FieldPath to represent a list element selection (and thus also change 
how a "[0]" in a string path gets parsed to use this new object).

> [C++] Allow FieldPath to work with ListElement
> ----------------------------------------------
>
>                 Key: ARROW-18265
>                 URL: https://issues.apache.org/jira/browse/ARROW-18265
>             Project: Apache Arrow
>          Issue Type: Improvement
>          Components: C++
>            Reporter: Miles Granger
>            Assignee: Miles Granger
>            Priority: Major
>              Labels: pull-request-available
>             Fix For: 11.0.0
>
>          Time Spent: 1h 40m
>  Remaining Estimate: 0h
>
> {{FieldRef::FromDotPath}} can parse a single list element field. ie. 
> {{{}'path.to.list[0]`{}}}but does not work in practice. Failing with:
> _struct_field: cannot subscript field of type list<....>_
> Being able to add a slice or multiple list elements is not within the scope 
> of this issue. 



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to