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


##########
arrow/compute/datum.go:
##########
@@ -256,50 +276,77 @@ func NewDatum(value interface{}) Datum {
        switch v := value.(type) {
        case Datum:
                return NewDatum(v.data())
+       case arrow.ArrayData:
+               v.Retain()
+               return &ArrayDatum{Value: v}
        case arrow.Array:
                v.Data().Retain()
-               return &ArrayDatum{v.Data()}
+               return &ArrayDatum{Value: v.Data()}
+       case *arrow.Chunked:
+               v.Retain()
+               return &ChunkedDatum{Value: v}
+       case arrow.RecordBatch:
+               v.Retain()
+               return &RecordDatum{Value: v}
+       case arrow.Table:
+               v.Retain()
+               return &TableDatum{Value: v}
        case scalar.Releasable:
                v.Retain()
-               return NewDatumWithoutOwning(v)
+               if sc, ok := v.(scalar.Scalar); ok {
+                       return &ScalarDatum{Value: sc}
+               }
+               return &ScalarDatum{Value: scalar.MakeScalar(v)}
        case scalar.Scalar:
-               return &ScalarDatum{v}
+               return &ScalarDatum{Value: v}
        default:
-               return &ScalarDatum{scalar.MakeScalar(value)}
+               return &ScalarDatum{Value: scalar.MakeScalar(value)}
        }
 }
 
 // NewDatumWithoutOwning is like NewDatum but does not call Retain on the
-// value it is given. The Datum takes over whatever reference the caller
-// supplies, and Datum.Release consumes that reference: it is an ordinary
-// ArrayDatum, ChunkedDatum, RecordDatum, TableDatum or ScalarDatum whose
-// Release calls the wrapped value's Release.
+// value it is given. The returned Datum borrows the underlying value: it

Review Comment:
   Nit: this paragraph, the next one and the note at L319 all say `Release` is 
a no-op. The note at L319 on its own is enough.



##########
arrow/compute/datum_test.go:
##########
@@ -0,0 +1,185 @@
+// 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 compute
+
+import (
+       "testing"
+
+       "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"
+       "github.com/stretchr/testify/assert"
+)
+
+// TestNewDatumWithoutOwningDoesNotLeakOwner verifies that calling Release()
+// on a Datum constructed with NewDatumWithoutOwning is a no-op: it must not
+// free the caller's underlying allocation. A CheckedAllocator tracks bytes
+// before and after so any silent leak or over-release is caught.
+//
+// Each case follows the same pattern:
+//   1. Caller builds a fresh owning value (refcount == 1).

Review Comment:
   gofmt wants two spaces here (`//  1.` … `//  4.`); `gofmt -w 
arrow/compute/datum_test.go` fixes it. Otherwise Lint will fail.



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