hcrosse opened a new issue, #1563: URL: https://github.com/apache/arrow-go/issues/1563
### Describe the bug, including details regarding any error messages, version, and platform. `Scalar.CastTo` results have mixed ownership, but its doc comment describes only conversion semantics. It does not say whether the caller owns a reference or borrows the result: https://github.com/apache/arrow-go/blob/fc5d5ce5a99b8583448b2cb70d0e9357dd10a420/arrow/scalar/scalar.go#L60-L62 I reproduced this on v18.8.0 and main, with Go 1.26.10 on macOS arm64. These examples are from main. REE means run end encoded. | Cast | Result | Ownership | | --- | --- | --- | | `Binary` to `utf8` | Fresh scalar | Owns a reference | | `List` to the same type | Receiver | Borrowed | | `REE<int32,list>` to `list` | Inner value | Borrowed | | `REE<int16,list>` to `REE<int32,list>` | Fresh wrapper | Borrows the same inner value | For the last three rows, releasing the receiver frees its buffers. Releasing the result too panics with `too many releases` under `assert`. The return paths are: https://github.com/apache/arrow-go/blob/fc5d5ce5a99b8583448b2cb70d0e9357dd10a420/arrow/scalar/binary.go#L70-L95 https://github.com/apache/arrow-go/blob/fc5d5ce5a99b8583448b2cb70d0e9357dd10a420/arrow/scalar/nested.go#L87-L89 https://github.com/apache/arrow-go/blob/fc5d5ce5a99b8583448b2cb70d0e9357dd10a420/arrow/scalar/nested.go#L824-L838 **Visible effect in expression execution** With a checked allocator, I built a `struct<a: binary>` scalar containing `{"a": "eA=="}` and executed a literal against a schema expecting `a: utf8`. The literal does not return the cast value: ```go arr, _, _ := array.FromJSON(mem, in, strings.NewReader(`[{"a": "eA=="}]`)) sc, _ := scalar.GetScalar(arr, 0) arr.Release() res, _ := exprs.ExecuteScalarExpression(ctx, schema, expr.NewPrimitiveLiteral[int32](1, false), compute.NewDatumWithoutOwning(sc)) res.Release() sc.(interface{ Release() }).Release() mem.CurrentAlloc() ``` On both versions, I saw 64 B left after releasing the result and input. Each additional distinct input left another 64 B. `makeExecBatch` retains every valid cast result through `compute.NewDatum`, including results that already own a reference: https://github.com/apache/arrow-go/blob/fc5d5ce5a99b8583448b2cb70d0e9357dd10a420/arrow/compute/exprs/exec.go#L115-L129 C++ returns a `std::shared_ptr<Scalar>` from `Scalar::CastTo`: https://github.com/apache/arrow/blob/976779b2aac587f51b87c3bd2e6ae4c36f75ab6c/cpp/src/arrow/scalar.h#L120 Should `CastTo` always return a new reference that the caller must release, or should borrowed results be documented for the relevant casts? ### 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]
