hcrosse opened a new issue, #1497:
URL: https://github.com/apache/arrow-go/issues/1497

   ### Describe the bug, including details regarding any error messages, 
version, and platform.
   
   `arrow/scalar` has no scalar types for `decimal32` or `decimal64`. 
`GetScalar` returns an error for valid values but panics on null slots. Null 
dictionary decoding and casting a null scalar with `Scalar.CastTo` also panic.
   
   I reproduced the following `decimal32` cases on main at `32947b25` and on 
v18.8.0, on macOS arm64 with Go 1.26.10.
   
   **Reproduction**
   
   Save this as `main.go` in a new subdirectory of an arrow-go checkout at 
`32947b259414a77ae6347d3d29bd69ec00b9d560`, then run `go run . valid`, `go run 
. getscalar`, `go run . encoded` and `go run . castto` from that directory:
   
   ```go
   package main
   
   import (
        "fmt"
        "os"
   
        "github.com/apache/arrow-go/v18/arrow"
        "github.com/apache/arrow-go/v18/arrow/array"
        "github.com/apache/arrow-go/v18/arrow/memory"
        "github.com/apache/arrow-go/v18/arrow/scalar"
   )
   
   func main() {
        d32 := &arrow.Decimal32Type{Precision: 5, Scale: 2}
        switch os.Args[1] {
        case "valid":
                b := array.NewDecimal32Builder(memory.DefaultAllocator, d32)
                b.Append(12345)
                fmt.Println(scalar.GetScalar(b.NewArray(), 0))
        case "getscalar":
                arr := array.MakeArrayOfNull(memory.DefaultAllocator, d32, 1)
                fmt.Println(scalar.GetScalar(arr, 0))
        case "encoded":
                dict := 
scalar.NewNullDictScalar(&arrow.DictionaryType{IndexType: 
arrow.PrimitiveTypes.Int8, ValueType: d32})
                fmt.Println(dict.GetEncodedValue())
        case "castto":
                
fmt.Println(scalar.MakeNullScalar(arrow.PrimitiveTypes.Int32).CastTo(d32))
        }
   }
   ```
   
   | Command | Main and v18.8.0 | Expected |
   | --- | --- | --- |
   | `valid` | `<nil> cannot create scalar from array of type decimal32(5, 2)` 
| `123.45 <nil>` |
   | `getscalar`, `encoded`, `castto` | nil pointer panic | `null <nil>` |
   
   **Cause**
   
   `GetScalar` has no cases for these decimal types, and their entries in the 
null constructor table are nil. `MakeNullScalar` calls those entries, including 
through the null branch of `Dictionary.GetEncodedValue`:
   
   
https://github.com/apache/arrow-go/blob/32947b259414a77ae6347d3d29bd69ec00b9d560/arrow/scalar/scalar.go#L489-L491
   
   
https://github.com/apache/arrow-go/blob/32947b259414a77ae6347d3d29bd69ec00b9d560/arrow/scalar/scalar.go#L586-L610
   
   
https://github.com/apache/arrow-go/blob/32947b259414a77ae6347d3d29bd69ec00b9d560/arrow/scalar/nested.go#L522-L528
   
   C++ has 
[`Decimal32Scalar`](https://github.com/apache/arrow/blob/1ebb9379b2f635755e773b79e88cb99852c70455/cpp/src/arrow/scalar.h#L592-L594)
 and 
[`Decimal64Scalar`](https://github.com/apache/arrow/blob/1ebb9379b2f635755e773b79e88cb99852c70455/cpp/src/arrow/scalar.h#L596-L598).
   
   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]

Reply via email to