xgbtxy opened a new pull request, #1683:
URL: https://github.com/apache/arrow-go/pull/1683

   ### Rationale for this change
   
   `LargeList`, `Map`, and `FixedSizeList` scalars embed `*List` without 
overriding `CastTo`. When `CastTo` is called with the scalar's own `DataType`, 
the inherited `(*List).CastTo` retains and returns the embedded `*List` instead 
of the concrete `*LargeList`, `*Map`, or `*FixedSizeList` receiver (unlike 
`ListView` and `LargeListView`, which already override `CastTo`).
   
   Returning the embedded `*List` breaks concrete type expectations and 
downstream type switches:
   - Calling `MakeArrayFromScalar` on a same-type cast `*FixedSizeList` scalar 
enters `case *List, *LargeList:` and panics (`*arrow.FixedSizeListType` does 
not implement `arrow.OffsetsDataType`).
   - Calling `MakeArrayFromScalar` on a same-type cast `*Map` scalar enters 
`case *List, *LargeList:` instead of `case *Map:`, failing to construct the 
map's entry struct child array properly.
   - Calling `Validate()` on a same-type cast `*FixedSizeList` scalar bypasses 
`(*FixedSizeList).Validate()`'s element length check.
   
   ### What changes are included in this PR?
   
   - `arrow/scalar/nested.go`:
     - Add `CastTo` overrides on `*LargeList`, `*Map`, and `*FixedSizeList` 
that retain and return the concrete receiver when `Valid && 
arrow.TypeEqual(Type, to)`, delegating all other cases (nulls, string cast, 
unsupported targets) to embedded `(*List).CastTo` — matching `ListView.CastTo` 
and `LargeListView.CastTo`.
   - `arrow/scalar/scalar_test.go`:
     - Add `TestListLikeScalarSameTypeCastTo` verifying concrete receiver 
identity (`assert.Same`), reference ownership (`CheckedAllocator` stays 
non-zero after releasing original and returns to `0` after releasing cast 
result), `Validate()`, and `MakeArrayFromScalar` round-trip without panic for 
`LargeList`, `Map`, and `FixedSizeList` (plus null same-type casts).
   
   ### Are these changes tested?
   
   Yes. Verified with `go test -race -count=1 -tags "assert,test"` and `-tags 
"noasm,assert,test"` on `./arrow/scalar/...` and `./arrow/compute/...`.
   
   ### Are there any user-facing changes?
   
   Yes: calling `CastTo` with the same `DataType` on `*scalar.LargeList`, 
`*scalar.Map`, and `*scalar.FixedSizeList` now returns the concrete 
`*scalar.LargeList`, `*scalar.Map`, and `*scalar.FixedSizeList` receiver 
instead of the embedded `*scalar.List`.
   


-- 
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