hcrosse opened a new issue, #1564:
URL: https://github.com/apache/arrow-go/issues/1564
### Describe the bug, including details regarding any error messages,
version, and platform.
On array input, `ListElementRef{Offset: k}` selects row `k`'s whole list. On
a struct scalar input it selects element `k` within the list. Arrow C++ and
Substrait use element selection within each row, so I am unsure which semantics
are intended for array input.
I reproduced this on v18.8.0 and main, with Go 1.26.10 on macOS arm64.
For a `list<utf8>` column with rows `["a", "b"]`, `["c", "d"]` and `["e",
"f"]`:
```go
out, _ := exprs.GetReferencedValue(mem, &expr.ListElementRef{Offset: 1},
compute.NewDatumWithoutOwning(col), ext)
```
On main this returns the scalar list `["c" "d"]`, not the elements `["b" "d"
"f"]`. `compute.ListElement` on the same array returns those three elements.
`NewFieldRefFromDotPath(".l[1]", schema)` builds the reference
`.field(0).[1]`, and an expression using it has result type `utf8`. Executing
it on the record input fails on both versions:
```go
_, err := exprs.ExecuteScalarExpression(ctx, schema, e,
compute.NewDatumWithoutOwning(rec))
```
```text
invalid: referenced field .[1] was list<item: utf8, nullable>, but should
have been utf8
```
The same expression on a struct scalar containing `l: ["a", "b"]` returns
`b` on both versions.
**Current behavior and references**
The array path checks the offset against the row count and calls
`scalar.GetScalar` on the whole array:
https://github.com/apache/arrow-go/blob/fc5d5ce5a99b8583448b2cb70d0e9357dd10a420/arrow/compute/exprs/field_refs.go#L278-L294
The scalar path indexes into the list's values instead:
https://github.com/apache/arrow-go/blob/fc5d5ce5a99b8583448b2cb70d0e9357dd10a420/arrow/compute/exprs/field_refs.go#L139-L153
The `array list element` subtest of `TestNestedFieldRefResultOwnership`
explicitly expects row 1's whole list:
https://github.com/apache/arrow-go/blob/fc5d5ce5a99b8583448b2cb70d0e9357dd10a420/arrow/compute/exprs/exec_test.go#L1032-L1052
Substrait's array reference is an offset within a list:
https://github.com/substrait-io/substrait/blob/2a16cf8882d11601f89f12056a57cdb978c165e8/site/docs/expressions/field_references.md?plain=1#L15
Arrow C++ lowers the reference to `list_element`, which selects the element
from each row:
https://github.com/apache/arrow/blob/976779b2aac587f51b87c3bd2e6ae4c36f75ab6c/cpp/src/arrow/engine/substrait/expression_internal.cc#L173-L191
Which semantics are intended for `ListElementRef` on array input: row
selection or element selection within each row?
If element selection is intended, I can open a PR that uses
`compute.ListElement` for array input.
### Component(s)
Other
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]