zeroshade commented on code in PR #1139:
URL: https://github.com/apache/arrow-go/pull/1139#discussion_r3769052406


##########
arrow/ipc/file_writer.go:
##########
@@ -303,6 +305,13 @@ func (f *FileWriter) Close() error {
        return nil
 }
 
+func (f *FileWriter) releaseDictionaries() {
+       for _, d := range f.lastWrittenDicts {
+               d.Release()
+       }
+       f.lastWrittenDicts = nil

Review Comment:
   `releaseDictionaries` leaves `lastWrittenDicts` nil. Because `Write` does 
not reject a closed writer, writing another dictionary record after `Close` 
reaches dictionary encoding and panics with `assignment to entry in nil map`.
   
   Please keep the writer in a state where subsequent calls return an error 
rather than panic—likely by tracking the closed state and checking it in 
`Write`.



##########
arrow/compute/internal/kernels/vector_cumulative.go:
##########
@@ -0,0 +1,411 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+//go:build go1.18
+
+package kernels
+
+import (
+       "fmt"
+
+       "github.com/apache/arrow-go/v18/arrow"
+       "github.com/apache/arrow-go/v18/arrow/bitutil"
+       "github.com/apache/arrow-go/v18/arrow/compute/exec"
+       "github.com/apache/arrow-go/v18/arrow/scalar"
+)
+
+// CumulativeOptions controls cumulative operations.
+type CumulativeOptions struct {
+       // Start is the initial value. A nil value uses the zero value for the
+       // input type. A non-nil null scalar is invalid.
+       Start scalar.Scalar `compute:"start"`
+       // SkipNulls controls whether a null input stops the cumulative 
operation.
+       // Null positions are still null in the output when this is true.
+       SkipNulls bool `compute:"skip_nulls"`
+}
+
+func (CumulativeOptions) TypeName() string { return "CumulativeOptions" }
+
+func (opts CumulativeOptions) Release() {
+       if opts.Start == nil {
+               return
+       }
+
+       if releasable, ok := opts.Start.(interface{ Release() }); ok {
+               releasable.Release()
+       }
+}
+
+type cumulativeSumState[T arrow.NumericType] struct {
+       current         T
+       skipNulls       bool
+       encounteredNull bool
+       checked         bool
+       add             func(T, T) (T, error)
+}
+
+type ScalarCastFn func(*exec.KernelCtx, scalar.Scalar, arrow.DataType) 
(scalar.Scalar, error)
+
+func safeNumericCastScalar(ctx *exec.KernelCtx, cast ScalarCastFn, start 
scalar.Scalar, typ arrow.DataType) (scalar.Scalar, error) {
+       targetID := typ.ID()
+       if !arrow.IsInteger(targetID) && !arrow.IsFloating(targetID) {
+               return nil, fmt.Errorf("%w: cumulative sum input type must be 
numeric, got %s", arrow.ErrType, typ)
+       }
+       if arrow.TypeEqual(start.DataType(), typ) {
+               return start, nil
+       }
+
+       if cast == nil {
+               return nil, fmt.Errorf("%w: cumulative sum start value caster 
is not configured", arrow.ErrInvalid)
+       }
+
+       casted, err := cast(ctx, start, typ)
+       if err != nil {
+               return nil, fmt.Errorf("%w: cannot cast cumulative sum start 
value to %s: %v", arrow.ErrInvalid, typ, err)
+       }
+       return casted, nil
+}
+
+func cumulativeStartValue[T arrow.NumericType](ctx *exec.KernelCtx, cast 
ScalarCastFn, start scalar.Scalar, typ arrow.DataType) (T, error) {
+       var zero T
+       if start == nil {
+               return zero, nil
+       }
+       if !start.IsValid() {

Review Comment:
   A typed-nil scalar bypasses `start == nil` because the interface itself is 
non-nil, then panics here:
   
   ```go
   var start *scalar.Int32
   CumulativeOptions{Start: start}
   ```
   
   Typed-nil releasable starts can similarly panic during expression 
construction at `Retain`. Please detect typed-nil starts and either treat them 
as absent or return `arrow.ErrInvalid`.



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