alberttwong opened a new issue, #1557:
URL: https://github.com/apache/arrow-go/issues/1557
### Describe the bug, including details regarding any error messages,
version, and platform.
### Request / observed behavior
Could C Data import validate invalid Map key nullability and return an
ordinary error before entering array constructors that panic? This would let
downstream ADBC drivers retire Map-specific defensive C preflight code rather
than maintain parallel Arrow validation at the FFI boundary.
A small server-free reproducer prints:
```
PANIC: arrow/array: map array keys array should have no nulls
```
Reproduced locally with Go 1.27.3 / darwin arm64 on both Arrow Go v18.8.0
and current main `fc5d5ce5a99b8583448b2cb70d0e9357dd10a420`
(`v18.9.0-rc0.0.20261113184511-fc5d5ce5a99b`). No Redis server or end-to-end
performance benchmark was run for this report.
The fixture exports a valid one-entry Map, keeps its allocated
buffers/release callbacks readable and intact, and changes only the exported
key child null_count to 1. It then calls the public error-returning
`ImportCArrayWithType`. The metadata is deliberately semantically invalid; this
does not ask Arrow to make arbitrary invalid pointers safe.
### Minimal standalone reproducer
Save as main.go in a fresh Go module requiring
github.com/apache/arrow-go/v18, then `go run -mod=mod .`:
```go
package main
/*
#include <stdint.h>
#include <stdlib.h>
struct ArrowArray {
int64_t length, null_count, offset, n_buffers, n_children;
const void** buffers;
struct ArrowArray** children;
struct ArrowArray* dictionary;
void (*release)(struct ArrowArray*);
void* private_data;
};
static void null_map_key(struct ArrowArray* a) {
a->children[0]->children[0]->null_count = 1; }
*/
import "C"
import (
"fmt"
"unsafe"
"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 main() {
b := array.NewMapBuilder(memory.DefaultAllocator, arrow.BinaryTypes.String,
arrow.PrimitiveTypes.Int64, false)
b.Append(true)
b.KeyBuilder().(*array.StringBuilder).Append("key")
b.ItemBuilder().(*array.Int64Builder).Append(1)
a := b.NewMapArray()
b.Release()
defer a.Release()
ca :=
(*cdata.CArrowArray)(C.calloc(1,C.size_t(unsafe.Sizeof(C.struct_ArrowArray{}))))
defer C.free(unsafe.Pointer(ca))
cdata.ExportArrowArray(a,ca,nil)
defer cdata.ReleaseCArrowArray(ca)
C.null_map_key((*C.struct_ArrowArray)(unsafe.Pointer(ca)))
defer func() { if p:=recover(); p!=nil { fmt.Printf("PANIC: %v\n",p) } }()
imported, err := cdata.ImportCArrayWithType(ca,a.DataType())
if imported!=nil { imported.Release() }
fmt.Printf("RETURNED ERROR: %v\n",err)
}
```
The recover is only to report the observed panic; it is not a proposed
production fix or an assertion that panic recovery balances all intermediate
ownership.
### Requested contract and downstream code reduction
- Reject this shape with an ordinary error from the public import API,
including equivalent nested-record and streamed imports before unsafe
constructor assumptions are reached.
- Keep C Array/Schema ownership documented and balanced on every failure.
Add release-count/checked-allocator tests, successful subsequent imports,
nonzero-offset and NULL-count-unknown variants where supported.
- Keep valid buffer sharing zero-copy. Producer obligations to supply
readable memory remain unchanged.
Our generated ADBC boundary treats unexpected Go panics as a
driver-poisoning event. We therefore carry a 120-line generic C preflight plus
a checking stream adapter; Map validation is one part of it:
https://github.com/redis/redis-adbc-driver/blob/24f654b7/go/pkg/input_preflight.c
Existing downstream regression (direct and streamed input, followed by a
valid query):
https://github.com/redis/redis-adbc-driver/blob/24f654b7/go/validation/tests/test_arrow_interop.py#L314-L365
Fixing this case could remove that portion of the shim. Removing the entire
shim would require equivalent coverage for its other structural/Union checks;
we are not claiming 120 lines can all be deleted from this fix alone. No
throughput improvement is quantified.
Current import and dispatch implementation:
https://github.com/apache/arrow-go/blob/fc5d5ce5a99b8583448b2cb70d0e9357dd10a420/arrow/cdata/interface.go#L82-L88
https://github.com/apache/arrow-go/blob/fc5d5ce5a99b8583448b2cb70d0e9357dd10a420/arrow/cdata/cdata.go#L747-L748
This differs from #1548, which requests C Data/Stream handoff allocation
benchmarking and ownership guidance.
### Component(s)
Integration
--
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]