hcrosse opened a new issue, #1489:
URL: https://github.com/apache/arrow-go/issues/1489
### Describe the bug, including details regarding any error messages,
version, and platform.
`arrow/scalar` has no scalar types for `string_view` or `binary_view`.
`GetScalar` returns an error for a valid value but panics on a null slot.
`Dictionary.GetEncodedValue` on a null dictionary scalar with view values also
panics. Casting a null string scalar to `string_view` through
`compute.CastDatum` panics in an executor goroutine and crashes the process.
I reproduced these on main at `66722e30`, on macOS arm64 with Go 1.26.10.
The three null cases also reproduce on v18.8.0.
**Reproduction**
Save this as `main.go` in a new subdirectory of an arrow-go checkout at
`66722e30df98ddd6f7bb46023fa13287b84308f6`, then run `go run . valid`, `go run
. getscalar`, `go run . encoded` and `go run . cast` from that directory:
```go
package main
import (
"context"
"fmt"
"os"
"github.com/apache/arrow-go/v18/arrow"
"github.com/apache/arrow-go/v18/arrow/array"
"github.com/apache/arrow-go/v18/arrow/compute"
"github.com/apache/arrow-go/v18/arrow/memory"
"github.com/apache/arrow-go/v18/arrow/scalar"
)
func main() {
sv := arrow.BinaryTypes.StringView
switch os.Args[1] {
case "valid":
b := array.NewStringViewBuilder(memory.DefaultAllocator)
b.Append("hello")
fmt.Println(scalar.GetScalar(b.NewArray(), 0))
case "getscalar":
arr := array.MakeArrayOfNull(memory.DefaultAllocator, sv, 1)
fmt.Println(scalar.GetScalar(arr, 0))
case "encoded":
dict :=
scalar.NewNullDictScalar(&arrow.DictionaryType{IndexType:
arrow.PrimitiveTypes.Int8, ValueType: sv})
fmt.Println(dict.GetEncodedValue())
case "cast":
fmt.Println(compute.CastDatum(context.Background(),
compute.NewDatum(scalar.MakeNullScalar(arrow.BinaryTypes.String)),
compute.SafeCastOptions(sv)))
}
}
```
| Command | Main | Expected |
| --- | --- | --- |
| `valid` | `<nil> cannot create scalar from array of type string_view` |
`hello <nil>` |
| `getscalar`, `encoded`, `cast` | nil pointer panic | `null <nil>` |
**Cause**
`GetScalar` has no view cases, and the null constructor table has nil
entries for both types. `MakeNullScalar` calls those entries:
https://github.com/apache/arrow-go/blob/66722e30df98ddd6f7bb46023fa13287b84308f6/arrow/scalar/scalar.go#L489-L491
https://github.com/apache/arrow-go/blob/66722e30df98ddd6f7bb46023fa13287b84308f6/arrow/scalar/scalar.go#L586-L588
https://github.com/apache/arrow-go/blob/66722e30df98ddd6f7bb46023fa13287b84308f6/arrow/scalar/nested.go#L519-L521
C++ has
[`StringViewScalar`](https://github.com/apache/arrow/blob/1ebb9379b2f635755e773b79e88cb99852c70455/cpp/src/arrow/scalar.h#L392-L403)
and
[`BinaryViewScalar`](https://github.com/apache/arrow/blob/1ebb9379b2f635755e773b79e88cb99852c70455/cpp/src/arrow/scalar.h#L355-L390).
The Go gap is noted in https://github.com/apache/arrow-go/pull/802 and
https://github.com/apache/arrow-go/pull/1448.
I have a patch with tests and can open a PR.
### 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]