alberttwong opened a new issue, #1598:
URL: https://github.com/apache/arrow-go/issues/1598
### Describe the bug, including details regarding any error messages,
version, and platform.
## Reproduction
Arrow Go v18.8.0, Go 1.27.3, macOS arm64. This standalone test uses only
Arrow Go C Data APIs; no Redis server, SQL driver or callback wrapper is
involved.
Expected: a sliced STRUCT round trip retains both rows `[202, 303]`.
Actual:
```text
=== RUN TestSlicedStructCDataRoundTrip
struct_offset_test.go:20: expected {[202 303]}; got {[303]}
--- FAIL: TestSlicedStructCDataRoundTrip (0.00s)
```
Run `go test -count=1 -v .` with this test and a module requiring
`github.com/apache/arrow-go/v18 v18.8.0`:
```go
package cdatarepro
import (
"testing"
"github.com/apache/arrow-go/v18/arrow"
"github.com/apache/arrow-go/v18/arrow/array"
"github.com/apache/arrow-go/v18/arrow/cdata"
"github.com/apache/arrow-go/v18/arrow/memory"
)
func TestSlicedStructCDataRoundTrip(t *testing.T) {
b := array.NewInt64Builder(memory.DefaultAllocator)
b.AppendValues([]int64{101, 202, 303, 404}, nil)
child := b.NewArray()
b.Release()
defer child.Release()
parent, err := array.NewStructArray([]arrow.Array{child}, []string{"x"})
if err != nil { t.Fatal(err) }
defer parent.Release()
source := array.NewSlice(parent, 1, 3)
defer source.Release()
var exported cdata.CArrowArray
cdata.ExportArrowArray(source, &exported, nil)
actual, err := cdata.ImportCArrayWithType(&exported, source.DataType())
if err != nil { t.Fatal(err) }
defer actual.Release()
if !array.Equal(source, actual) {
t.Fatalf("expected %s; got %s", source, actual)
}
}
```
## Suspected cause / proposed direction
`exportArray` retains the STRUCT parent's nonzero offset and exports
`arr.Field(i)`, which already applies that parent slice. The receiving
implementation applies the parent offset again.
https://github.com/apache/arrow-go/blob/v18.8.0/arrow/cdata/cdata_exports.go
The same STRUCT exporter shape is still present in the inspected
current-main file (blob `a760ec53942d1cb70463b688bcaabd9fc4fabea2`). The
complete test above was executed against v18.8.0; I am not claiming a
main-branch execution result.
Consider exporting the original unsliced child data
(`arr.Data().Children()[i]`) via a temporary array, with the matching Release,
so the parent offset is applied once. Preserve each child's original
offset/length/validity and all ownership callbacks. This needs full
interoperability and sanitizer validation, especially nested STRUCTs, NULLs,
and children with their own offsets.
## Additional observation and limits
A downstream C/PyArrow stub echo path also changes the first nested STRUCT
value of a sliced record batch from 1 to 0, through both Bind and BindStream;
the standalone reproduction above isolates the issue from that driver. Seed 0
alone masks the wrong-value case, while seed 1 exposes it. Production SQL
impact has not yet been qualified.
Downstream tracker: https://github.com/redis/redis-adbc-driver/issues/460
Related lifetime investigation: redis/redis-adbc-driver#446. No GC-policy or
performance claim is made here.
### 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]