This is an automated email from the ASF dual-hosted git repository.
zeroshade pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow-go.git
The following commit(s) were added to refs/heads/main by this push:
new e71ce3e0 fix(arrow/compute): fix NewDatumWithoutOwning ownership
semantics (#1377)
e71ce3e0 is described below
commit e71ce3e02380756dc7eac4d06229ce5fb777a1c6
Author: Stochastic <[email protected]>
AuthorDate: Fri Nov 6 05:10:20 2026 +0800
fix(arrow/compute): fix NewDatumWithoutOwning ownership semantics (#1377)
## Background
`NewDatumWithoutOwning` is documented as returning a non-owning Datum --
one that should not release the caller's underlying array when
`Release()`
is called. However, it returned an ordinary Datum struct, so `Release()`
did free the caller's memory, leading to silent double-frees and
use-after-free bugs.
## Problem
The non-owning contract was unenforced. Callers following the documented
non-owning semantics would corrupt memory when they (or a downstream
consumer) called `Release()`.
## Solution
Add a `borrowed bool` field to each Datum variant (`ScalarDatum`,
`ArrayDatum`, `ChunkedDatum`, `RecordDatum`, `TableDatum`). When
`borrowed == true`, `Release()` is a no-op and does not free the
underlying value. `NewDatumWithoutOwning` now constructs Datums with
`borrowed = true`, and `NewDatum` is made explicit for each owned type.
Internal call sites in `executor.go` (`Take()`) and `exprs/exec.go`
(`NewMapScalar`) that construct new owned values were updated to build
owned Datums directly instead of routing through
`NewDatumWithoutOwning`.
## Testing
- `go build ./arrow/compute/...` -- pass
- `go test ./arrow/compute/...` -- all PASS
- `go vet ./arrow/compute/...` -- pass
Fixes #1298
---------
Co-authored-by: Asthenia0412 <[email protected]>
Co-authored-by: PR Maintainer <[email protected]>
Co-authored-by: TRAE Agent <[email protected]>
---
arrow/compute/arithmetic_test.go | 276 ++++++++++++++++-----------------
arrow/compute/cast_test.go | 2 +-
arrow/compute/datum.go | 95 ++++++++----
arrow/compute/datum_test.go | 185 ++++++++++++++++++++++
arrow/compute/exec_internals_test.go | 14 +-
arrow/compute/exec_test.go | 14 +-
arrow/compute/executor.go | 16 +-
arrow/compute/exprs/exec.go | 2 +-
arrow/compute/scalar_compare_test.go | 102 ++++++------
arrow/compute/vector_selection_test.go | 6 +-
10 files changed, 472 insertions(+), 240 deletions(-)
diff --git a/arrow/compute/arithmetic_test.go b/arrow/compute/arithmetic_test.go
index d670db7b..bf319740 100644
--- a/arrow/compute/arithmetic_test.go
+++ b/arrow/compute/arithmetic_test.go
@@ -73,7 +73,7 @@ func assertNullToNull(t *testing.T, ctx context.Context, fn
string, mem memory.A
t.Run("null to null array", func(t *testing.T) {
args := make([]compute.Datum, n)
for i := 0; i < n; i++ {
- args[i] = &compute.ArrayDatum{nulls.Data()}
+ args[i] = &compute.ArrayDatum{Value: nulls.Data()}
}
result, err := compute.CallFunction(ctx, fn, nil, args...)
@@ -132,7 +132,7 @@ func assertBinop(t *testing.T, fn binaryFunc, left, right,
expected arrow.Array,
}
func assertBinopErr(t *testing.T, fn binaryFunc, left, right arrow.Array,
expectedMsg string) {
- _, err := fn(&compute.ArrayDatum{left.Data()},
&compute.ArrayDatum{Value: right.Data()})
+ _, err := fn(&compute.ArrayDatum{Value: left.Data()},
&compute.ArrayDatum{Value: right.Data()})
assert.ErrorIs(t, err, arrow.ErrInvalid)
assert.ErrorContains(t, err, expectedMsg)
}
@@ -169,7 +169,7 @@ func (b *Float16BinaryFuncTestSuite) assertBinopErr(fn
binaryFunc, lhs, rhs stri
right, _, _ := array.FromJSON(b.mem, arrow.FixedWidthTypes.Float16,
strings.NewReader(rhs))
defer right.Release()
- _, err := fn(&compute.ArrayDatum{left.Data()},
&compute.ArrayDatum{right.Data()})
+ _, err := fn(&compute.ArrayDatum{Value: left.Data()},
&compute.ArrayDatum{Value: right.Data()})
b.ErrorIs(err, arrow.ErrNotImplemented)
}
@@ -258,10 +258,10 @@ func (b *BinaryArithmeticSuite[T])
assertBinopArrScalarExpArr(fn binaryArithmeti
left, _, _ := array.FromJSON(b.mem, b.DataType(),
strings.NewReader(lhs))
defer left.Release()
- actual, err := fn(b.ctx, b.opts, &compute.ArrayDatum{left.Data()},
compute.NewDatum(rhs))
+ actual, err := fn(b.ctx, b.opts, &compute.ArrayDatum{Value:
left.Data()}, compute.NewDatum(rhs))
b.Require().NoError(err)
defer actual.Release()
- assertDatumsEqual(b.T(), &compute.ArrayDatum{exp.Data()}, actual,
b.equalOpts, b.scalarEqualOpts)
+ assertDatumsEqual(b.T(), &compute.ArrayDatum{Value: exp.Data()},
actual, b.equalOpts, b.scalarEqualOpts)
}
func (b *BinaryArithmeticSuite[T]) assertBinopArrScalarVal(fn
binaryArithmeticFunc, lhs string, rhs T, expected string) {
@@ -1070,12 +1070,12 @@ func (ds *DecimalBinaryArithmeticSuite)
TestAddSubScalars() {
strings.NewReader(`["-12344.366", "-11111.600",
"-22222.143", "-11678.712"]`))
defer rightSubLeft.Release()
- rightDatum := &compute.ArrayDatum{right.Data()}
- addedDatum := &compute.ArrayDatum{added.Data()}
+ rightDatum := &compute.ArrayDatum{Value: right.Data()}
+ addedDatum := &compute.ArrayDatum{Value: added.Data()}
checkScalarBinary(ds.T(), "add", compute.NewDatum(left),
rightDatum, addedDatum, nil)
checkScalarBinary(ds.T(), "add", rightDatum,
compute.NewDatum(left), addedDatum, nil)
- checkScalarBinary(ds.T(), "sub", compute.NewDatum(left),
rightDatum, &compute.ArrayDatum{leftSubRight.Data()}, nil)
- checkScalarBinary(ds.T(), "sub", rightDatum,
compute.NewDatum(left), &compute.ArrayDatum{rightSubLeft.Data()}, nil)
+ checkScalarBinary(ds.T(), "sub", compute.NewDatum(left),
rightDatum, &compute.ArrayDatum{Value: leftSubRight.Data()}, nil)
+ checkScalarBinary(ds.T(), "sub", rightDatum,
compute.NewDatum(left), &compute.ArrayDatum{Value: rightSubLeft.Data()}, nil)
})
ds.Run("scalar_scalar", func() {
@@ -1128,7 +1128,7 @@ func (ds *DecimalBinaryArithmeticSuite) TestMultiply() {
ds.Require().NoError(err)
defer expected.Release()
- checkScalarBinary(ds.T(), "multiply_unchecked",
&compute.ArrayDatum{left.Data()}, &compute.ArrayDatum{right.Data()},
&compute.ArrayDatum{expected.Data()}, nil)
+ checkScalarBinary(ds.T(), "multiply_unchecked",
&compute.ArrayDatum{Value: left.Data()}, &compute.ArrayDatum{Value:
right.Data()}, &compute.ArrayDatum{Value: expected.Data()}, nil)
})
ds.Run("array x array decimal256", func() {
@@ -1144,7 +1144,7 @@ func (ds *DecimalBinaryArithmeticSuite) TestMultiply() {
strings.NewReader(`["-1524157875323883675034293577501905199.875019052100",
"0.000000000000"]`))
ds.Require().NoError(err)
defer expected.Release()
- checkScalarBinary(ds.T(), "multiply_unchecked",
&compute.ArrayDatum{left.Data()}, &compute.ArrayDatum{right.Data()},
&compute.ArrayDatum{expected.Data()}, nil)
+ checkScalarBinary(ds.T(), "multiply_unchecked",
&compute.ArrayDatum{Value: left.Data()}, &compute.ArrayDatum{Value:
right.Data()}, &compute.ArrayDatum{Value: expected.Data()}, nil)
})
ds.Run("scalar x array", func() {
@@ -1159,8 +1159,8 @@ func (ds *DecimalBinaryArithmeticSuite) TestMultiply() {
ds.Require().NoError(err)
defer expected.Release()
- leftDatum, rightDatum := &compute.ScalarDatum{left},
&compute.ArrayDatum{right.Data()}
- expDatum := &compute.ArrayDatum{expected.Data()}
+ leftDatum, rightDatum := &compute.ScalarDatum{Value: left},
&compute.ArrayDatum{Value: right.Data()}
+ expDatum := &compute.ArrayDatum{Value: expected.Data()}
checkScalarBinary(ds.T(), "multiply_unchecked", leftDatum,
rightDatum, expDatum, nil)
checkScalarBinary(ds.T(), "multiply_unchecked", rightDatum,
leftDatum, expDatum, nil)
@@ -1215,7 +1215,7 @@ func (ds *DecimalBinaryArithmeticSuite) TestDivide() {
ds.Require().NoError(err)
defer expected.Release()
- checkScalarBinary(ds.T(), "divide_unchecked",
&compute.ArrayDatum{left.Data()}, &compute.ArrayDatum{right.Data()},
&compute.ArrayDatum{expected.Data()}, nil)
+ checkScalarBinary(ds.T(), "divide_unchecked",
&compute.ArrayDatum{Value: left.Data()}, &compute.ArrayDatum{Value:
right.Data()}, &compute.ArrayDatum{Value: expected.Data()}, nil)
})
ds.Run("array / array decimal256", func() {
@@ -1231,7 +1231,7 @@ func (ds *DecimalBinaryArithmeticSuite) TestDivide() {
strings.NewReader(`["1.000000000000369999093",
"9999999999999.999999900000000000000"]`))
ds.Require().NoError(err)
defer expected.Release()
- checkScalarBinary(ds.T(), "divide_unchecked",
&compute.ArrayDatum{left.Data()}, &compute.ArrayDatum{right.Data()},
&compute.ArrayDatum{expected.Data()}, nil)
+ checkScalarBinary(ds.T(), "divide_unchecked",
&compute.ArrayDatum{Value: left.Data()}, &compute.ArrayDatum{Value:
right.Data()}, &compute.ArrayDatum{Value: expected.Data()}, nil)
})
ds.Run("scalar / array", func() {
@@ -1250,10 +1250,10 @@ func (ds *DecimalBinaryArithmeticSuite) TestDivide() {
ds.Require().NoError(err)
defer rightDivLeft.Release()
- leftDatum, rightDatum := &compute.ScalarDatum{left},
&compute.ArrayDatum{right.Data()}
+ leftDatum, rightDatum := &compute.ScalarDatum{Value: left},
&compute.ArrayDatum{Value: right.Data()}
- checkScalarBinary(ds.T(), "divide_unchecked", leftDatum,
rightDatum, &compute.ArrayDatum{leftDivRight.Data()}, nil)
- checkScalarBinary(ds.T(), "divide_unchecked", rightDatum,
leftDatum, &compute.ArrayDatum{rightDivLeft.Data()}, nil)
+ checkScalarBinary(ds.T(), "divide_unchecked", leftDatum,
rightDatum, &compute.ArrayDatum{Value: leftDivRight.Data()}, nil)
+ checkScalarBinary(ds.T(), "divide_unchecked", rightDatum,
leftDatum, &compute.ArrayDatum{Value: rightDivLeft.Data()}, nil)
})
ds.Run("scalar / scalar", func() {
@@ -1304,22 +1304,22 @@ func (ds *DecimalBinaryArithmeticSuite) TestAtan2() {
for _, ty := range ds.positiveScales() {
empty := ds.getArr(ty, `[]`)
defer empty.Release()
- ds.checkDecimalToFloat(fn,
[]compute.Datum{&compute.ArrayDatum{empty.Data()},
&compute.ArrayDatum{empty.Data()}})
+ ds.checkDecimalToFloat(fn,
[]compute.Datum{&compute.ArrayDatum{Value: empty.Data()},
&compute.ArrayDatum{Value: empty.Data()}})
larr := ds.getArr(ty, `["1.00", "10.00", "1.00", "2.00", null]`)
defer larr.Release()
- ldatum := &compute.ArrayDatum{larr.Data()}
+ ldatum := &compute.ArrayDatum{Value: larr.Data()}
test := ds.getArr(ty, `["10.00", "10.00", "2.00", "2.00",
null]`)
defer test.Release()
ds.checkDecimalToFloat(fn, []compute.Datum{ldatum,
- &compute.ArrayDatum{test.Data()}})
+ &compute.ArrayDatum{Value: test.Data()}})
test = ds.getArr(&arrow.Decimal128Type{Precision: 4, Scale: 2},
`["10.00", "10.00", "2.00", "2.00", null]`)
defer test.Release()
ds.checkDecimalToFloat(fn, []compute.Datum{ldatum,
- &compute.ArrayDatum{test.Data()}})
+ &compute.ArrayDatum{Value: test.Data()}})
ds.checkDecimalToFloat(fn, []compute.Datum{ldatum,
compute.NewDatum(scalar.MakeScalar(int64(10)))})
@@ -1331,33 +1331,33 @@ func (ds *DecimalBinaryArithmeticSuite) TestAtan2() {
sc, _ := scalar.MakeScalarParam("10.00", ty)
ds.checkDecimalToFloat(fn, []compute.Datum{
- &compute.ArrayDatum{larr.Data()},
+ &compute.ArrayDatum{Value: larr.Data()},
compute.NewDatum(sc)})
larr = ds.getArr(arrow.PrimitiveTypes.Int64, `[1, 10, 1, 2,
null]`)
defer larr.Release()
ds.checkDecimalToFloat(fn, []compute.Datum{
- &compute.ArrayDatum{larr.Data()},
+ &compute.ArrayDatum{Value: larr.Data()},
compute.NewDatum(sc)})
}
for _, ty := range ds.negativeScales() {
empty := ds.getArr(ty, `[]`)
defer empty.Release()
- ds.checkDecimalToFloat(fn,
[]compute.Datum{&compute.ArrayDatum{empty.Data()},
&compute.ArrayDatum{empty.Data()}})
+ ds.checkDecimalToFloat(fn,
[]compute.Datum{&compute.ArrayDatum{Value: empty.Data()},
&compute.ArrayDatum{Value: empty.Data()}})
larr := ds.getArr(ty, `["12E2", "42E2", null]`)
defer larr.Release()
ds.checkDecimalToFloat(fn, []compute.Datum{
- &compute.ArrayDatum{larr.Data()},
&compute.ArrayDatum{larr.Data()}})
+ &compute.ArrayDatum{Value: larr.Data()},
&compute.ArrayDatum{Value: larr.Data()}})
rarr := ds.getArr(&arrow.Decimal128Type{Precision: 2, Scale:
-2}, `["12E2", "42E2", null]`)
defer rarr.Release()
ds.checkDecimalToFloat(fn, []compute.Datum{
- &compute.ArrayDatum{larr.Data()},
&compute.ArrayDatum{rarr.Data()}})
+ &compute.ArrayDatum{Value: larr.Data()},
&compute.ArrayDatum{Value: rarr.Data()}})
ds.checkDecimalToFloat(fn, []compute.Datum{
- &compute.ArrayDatum{larr.Data()},
compute.NewDatum(scalar.MakeScalar(int64(10)))})
+ &compute.ArrayDatum{Value: larr.Data()},
compute.NewDatum(scalar.MakeScalar(int64(10)))})
}
}
@@ -1368,22 +1368,22 @@ func (ds *DecimalBinaryArithmeticSuite) TestLogb() {
for _, ty := range ds.positiveScales() {
empty := ds.getArr(ty, `[]`)
defer empty.Release()
- ds.checkDecimalToFloat(fn,
[]compute.Datum{&compute.ArrayDatum{empty.Data()},
&compute.ArrayDatum{empty.Data()}})
+ ds.checkDecimalToFloat(fn,
[]compute.Datum{&compute.ArrayDatum{Value: empty.Data()},
&compute.ArrayDatum{Value: empty.Data()}})
larr := ds.getArr(ty, `["1.00", "10.00",
"1.00", "2.00", null]`)
defer larr.Release()
- ldatum := &compute.ArrayDatum{larr.Data()}
+ ldatum := &compute.ArrayDatum{Value:
larr.Data()}
test := ds.getArr(ty, `["10.00", "10.00",
"2.00", "2.00", null]`)
defer test.Release()
ds.checkDecimalToFloat(fn,
[]compute.Datum{ldatum,
- &compute.ArrayDatum{test.Data()}})
+ &compute.ArrayDatum{Value:
test.Data()}})
test =
ds.getArr(&arrow.Decimal128Type{Precision: 4, Scale: 2}, `["10.00", "10.00",
"2.00", "2.00", null]`)
defer test.Release()
ds.checkDecimalToFloat(fn,
[]compute.Datum{ldatum,
- &compute.ArrayDatum{test.Data()}})
+ &compute.ArrayDatum{Value:
test.Data()}})
ds.checkDecimalToFloat(fn,
[]compute.Datum{ldatum,
compute.NewDatum(scalar.MakeScalar(int64(10)))})
@@ -1395,33 +1395,33 @@ func (ds *DecimalBinaryArithmeticSuite) TestLogb() {
sc, _ := scalar.MakeScalarParam("10.00", ty)
ds.checkDecimalToFloat(fn, []compute.Datum{
- &compute.ArrayDatum{larr.Data()},
+ &compute.ArrayDatum{Value: larr.Data()},
compute.NewDatum(sc)})
larr = ds.getArr(arrow.PrimitiveTypes.Int64,
`[1, 10, 1, 2, null]`)
defer larr.Release()
ds.checkDecimalToFloat(fn, []compute.Datum{
- &compute.ArrayDatum{larr.Data()},
+ &compute.ArrayDatum{Value: larr.Data()},
compute.NewDatum(sc)})
}
for _, ty := range ds.negativeScales() {
empty := ds.getArr(ty, `[]`)
defer empty.Release()
- ds.checkDecimalToFloat(fn,
[]compute.Datum{&compute.ArrayDatum{empty.Data()},
&compute.ArrayDatum{empty.Data()}})
+ ds.checkDecimalToFloat(fn,
[]compute.Datum{&compute.ArrayDatum{Value: empty.Data()},
&compute.ArrayDatum{Value: empty.Data()}})
larr := ds.getArr(ty, `["12E2", "42E2", null]`)
defer larr.Release()
ds.checkDecimalToFloat(fn, []compute.Datum{
- &compute.ArrayDatum{larr.Data()},
&compute.ArrayDatum{larr.Data()}})
+ &compute.ArrayDatum{Value:
larr.Data()}, &compute.ArrayDatum{Value: larr.Data()}})
rarr :=
ds.getArr(&arrow.Decimal128Type{Precision: 2, Scale: -2}, `["12E2", "42E2",
null]`)
defer rarr.Release()
ds.checkDecimalToFloat(fn, []compute.Datum{
- &compute.ArrayDatum{larr.Data()},
&compute.ArrayDatum{rarr.Data()}})
+ &compute.ArrayDatum{Value:
larr.Data()}, &compute.ArrayDatum{Value: rarr.Data()}})
ds.checkDecimalToFloat(fn, []compute.Datum{
- &compute.ArrayDatum{larr.Data()},
compute.NewDatum(scalar.MakeScalar(int64(10)))})
+ &compute.ArrayDatum{Value:
larr.Data()}, compute.NewDatum(scalar.MakeScalar(int64(10)))})
}
})
}
@@ -1446,8 +1446,8 @@ func (ds *DecimalUnaryArithmeticSuite)
TestAbsoluteValue() {
exp, _, _ :=
array.FromJSON(ds.mem, ty, strings.NewReader(`["1.00", "42.15", null]`))
defer exp.Release()
- checkScalar(ds.T(), fn,
[]compute.Datum{&compute.ArrayDatum{empty.Data()}},
&compute.ArrayDatum{empty.Data()}, nil)
- checkScalar(ds.T(), fn,
[]compute.Datum{&compute.ArrayDatum{in.Data()}},
&compute.ArrayDatum{exp.Data()}, nil)
+ checkScalar(ds.T(), fn,
[]compute.Datum{&compute.ArrayDatum{Value: empty.Data()}},
&compute.ArrayDatum{Value: empty.Data()}, nil)
+ checkScalar(ds.T(), fn,
[]compute.Datum{&compute.ArrayDatum{Value: in.Data()}},
&compute.ArrayDatum{Value: exp.Data()}, nil)
})
}
@@ -1464,8 +1464,8 @@ func (ds *DecimalUnaryArithmeticSuite)
TestAbsoluteValue() {
exp, _, _ :=
array.FromJSON(ds.mem, ty, strings.NewReader(`["12E2", "42E2", null]`))
defer exp.Release()
- checkScalar(ds.T(), fn,
[]compute.Datum{&compute.ArrayDatum{empty.Data()}},
&compute.ArrayDatum{empty.Data()}, nil)
- checkScalar(ds.T(), fn,
[]compute.Datum{&compute.ArrayDatum{in.Data()}},
&compute.ArrayDatum{exp.Data()}, nil)
+ checkScalar(ds.T(), fn,
[]compute.Datum{&compute.ArrayDatum{Value: empty.Data()}},
&compute.ArrayDatum{Value: empty.Data()}, nil)
+ checkScalar(ds.T(), fn,
[]compute.Datum{&compute.ArrayDatum{Value: in.Data()}},
&compute.ArrayDatum{Value: exp.Data()}, nil)
})
}
})
@@ -1487,8 +1487,8 @@ func (ds *DecimalUnaryArithmeticSuite) TestNegate() {
exp, _, _ := array.FromJSON(ds.mem, ty,
strings.NewReader(`["0.00", "-1.00", "42.15", null]`))
defer exp.Release()
- checkScalar(ds.T(), fn,
[]compute.Datum{&compute.ArrayDatum{empty.Data()}},
&compute.ArrayDatum{empty.Data()}, nil)
- checkScalar(ds.T(), fn,
[]compute.Datum{&compute.ArrayDatum{in.Data()}},
&compute.ArrayDatum{exp.Data()}, nil)
+ checkScalar(ds.T(), fn,
[]compute.Datum{&compute.ArrayDatum{Value: empty.Data()}},
&compute.ArrayDatum{Value: empty.Data()}, nil)
+ checkScalar(ds.T(), fn,
[]compute.Datum{&compute.ArrayDatum{Value: in.Data()}},
&compute.ArrayDatum{Value: exp.Data()}, nil)
}
checkScalar(ds.T(), fn,
[]compute.Datum{compute.NewDatum(scalar.NewDecimal128Scalar(max128.Negate(),
&arrow.Decimal128Type{Precision: 38}))},
@@ -1508,8 +1508,8 @@ func (ds *DecimalUnaryArithmeticSuite) TestNegate() {
exp, _, _ := array.FromJSON(ds.mem, ty,
strings.NewReader(`["0", "-12E2", "42E2", null]`))
defer exp.Release()
- checkScalar(ds.T(), fn,
[]compute.Datum{&compute.ArrayDatum{empty.Data()}},
&compute.ArrayDatum{empty.Data()}, nil)
- checkScalar(ds.T(), fn,
[]compute.Datum{&compute.ArrayDatum{in.Data()}},
&compute.ArrayDatum{exp.Data()}, nil)
+ checkScalar(ds.T(), fn,
[]compute.Datum{&compute.ArrayDatum{Value: empty.Data()}},
&compute.ArrayDatum{Value: empty.Data()}, nil)
+ checkScalar(ds.T(), fn,
[]compute.Datum{&compute.ArrayDatum{Value: in.Data()}},
&compute.ArrayDatum{Value: exp.Data()}, nil)
})
}
})
@@ -1568,10 +1568,10 @@ func (ds *DecimalUnaryArithmeticSuite) TestSign() {
exp := ds.decimalArrayFromJSON(arrow.PrimitiveTypes.Int64, `[1,
0, -1, null]`)
defer exp.Release()
- checkScalar(ds.T(), "sign",
[]compute.Datum{&compute.ArrayDatum{empty.Data()}},
- &compute.ArrayDatum{emptyOut.Data()}, nil)
- checkScalar(ds.T(), "sign",
[]compute.Datum{&compute.ArrayDatum{in.Data()}},
- &compute.ArrayDatum{exp.Data()}, nil)
+ checkScalar(ds.T(), "sign",
[]compute.Datum{&compute.ArrayDatum{Value: empty.Data()}},
+ &compute.ArrayDatum{Value: emptyOut.Data()}, nil)
+ checkScalar(ds.T(), "sign",
[]compute.Datum{&compute.ArrayDatum{Value: in.Data()}},
+ &compute.ArrayDatum{Value: exp.Data()}, nil)
}
checkScalar(ds.T(), "sign", []compute.Datum{compute.NewDatum(
@@ -1597,10 +1597,10 @@ func (ds *DecimalUnaryArithmeticSuite) TestSign() {
exp := ds.decimalArrayFromJSON(arrow.PrimitiveTypes.Int64, `[1,
0, -1, null]`)
defer exp.Release()
- checkScalar(ds.T(), "sign",
[]compute.Datum{&compute.ArrayDatum{empty.Data()}},
- &compute.ArrayDatum{emptyOut.Data()}, nil)
- checkScalar(ds.T(), "sign",
[]compute.Datum{&compute.ArrayDatum{in.Data()}},
- &compute.ArrayDatum{exp.Data()}, nil)
+ checkScalar(ds.T(), "sign",
[]compute.Datum{&compute.ArrayDatum{Value: empty.Data()}},
+ &compute.ArrayDatum{Value: emptyOut.Data()}, nil)
+ checkScalar(ds.T(), "sign",
[]compute.Datum{&compute.ArrayDatum{Value: in.Data()}},
+ &compute.ArrayDatum{Value: exp.Data()}, nil)
}
}
@@ -1613,8 +1613,8 @@ func (ds *DecimalUnaryArithmeticSuite) TestTrigAcosAsin()
{
defer empty.Release()
vals := ds.decimalArrayFromJSON(ty,
`["0.00", "-1.00", "1.00", null]`)
defer vals.Release()
- ds.checkDecimalToFloat(fn,
[]compute.Datum{&compute.ArrayDatum{empty.Data()}})
- ds.checkDecimalToFloat(fn,
[]compute.Datum{&compute.ArrayDatum{vals.Data()}})
+ ds.checkDecimalToFloat(fn,
[]compute.Datum{&compute.ArrayDatum{Value: empty.Data()}})
+ ds.checkDecimalToFloat(fn,
[]compute.Datum{&compute.ArrayDatum{Value: vals.Data()}})
})
}
})
@@ -1626,8 +1626,8 @@ func (ds *DecimalUnaryArithmeticSuite) TestTrigAcosAsin()
{
ds.Run(ty.String(), func() {
arr := ds.decimalArrayFromJSON(ty,
`["12E2", "-42E2", null]`)
defer arr.Release()
- ds.checkDecimalToFloat(fn+"_unchecked",
[]compute.Datum{&compute.ArrayDatum{arr.Data()}})
- ds.checkFail(fn,
[]compute.Datum{&compute.ArrayDatum{arr.Data()}}, "domain error", nil)
+ ds.checkDecimalToFloat(fn+"_unchecked",
[]compute.Datum{&compute.ArrayDatum{Value: arr.Data()}})
+ ds.checkFail(fn,
[]compute.Datum{&compute.ArrayDatum{Value: arr.Data()}}, "domain error", nil)
})
}
})
@@ -1642,8 +1642,8 @@ func (ds *DecimalUnaryArithmeticSuite) TestAtan() {
defer empty.Release()
vals := ds.decimalArrayFromJSON(ty, `["0.00", "-1.00",
"1.00", null]`)
defer vals.Release()
- ds.checkDecimalToFloat(fn,
[]compute.Datum{&compute.ArrayDatum{empty.Data()}})
- ds.checkDecimalToFloat(fn,
[]compute.Datum{&compute.ArrayDatum{vals.Data()}})
+ ds.checkDecimalToFloat(fn,
[]compute.Datum{&compute.ArrayDatum{Value: empty.Data()}})
+ ds.checkDecimalToFloat(fn,
[]compute.Datum{&compute.ArrayDatum{Value: vals.Data()}})
})
}
for _, ty := range ds.negativeScales() {
@@ -1652,8 +1652,8 @@ func (ds *DecimalUnaryArithmeticSuite) TestAtan() {
defer empty.Release()
vals := ds.decimalArrayFromJSON(ty, `["12E2", "-42E2",
null]`)
defer vals.Release()
- ds.checkDecimalToFloat(fn,
[]compute.Datum{&compute.ArrayDatum{empty.Data()}})
- ds.checkDecimalToFloat(fn,
[]compute.Datum{&compute.ArrayDatum{vals.Data()}})
+ ds.checkDecimalToFloat(fn,
[]compute.Datum{&compute.ArrayDatum{Value: empty.Data()}})
+ ds.checkDecimalToFloat(fn,
[]compute.Datum{&compute.ArrayDatum{Value: vals.Data()}})
})
}
}
@@ -1669,8 +1669,8 @@ func (ds *DecimalUnaryArithmeticSuite) TestTrig() {
defer empty.Release()
vals :=
ds.decimalArrayFromJSON(ty, `["0.00", "-1.00", "1.00", null]`)
defer vals.Release()
- ds.checkDecimalToFloat(fn,
[]compute.Datum{&compute.ArrayDatum{empty.Data()}})
- ds.checkDecimalToFloat(fn,
[]compute.Datum{&compute.ArrayDatum{vals.Data()}})
+ ds.checkDecimalToFloat(fn,
[]compute.Datum{&compute.ArrayDatum{Value: empty.Data()}})
+ ds.checkDecimalToFloat(fn,
[]compute.Datum{&compute.ArrayDatum{Value: vals.Data()}})
})
}
for _, ty := range ds.negativeScales() {
@@ -1679,8 +1679,8 @@ func (ds *DecimalUnaryArithmeticSuite) TestTrig() {
defer empty.Release()
vals :=
ds.decimalArrayFromJSON(ty, `["12E2", "-42E2", null]`)
defer vals.Release()
- ds.checkDecimalToFloat(fn,
[]compute.Datum{&compute.ArrayDatum{empty.Data()}})
- ds.checkDecimalToFloat(fn,
[]compute.Datum{&compute.ArrayDatum{vals.Data()}})
+ ds.checkDecimalToFloat(fn,
[]compute.Datum{&compute.ArrayDatum{Value: empty.Data()}})
+ ds.checkDecimalToFloat(fn,
[]compute.Datum{&compute.ArrayDatum{Value: vals.Data()}})
})
}
})
@@ -1718,8 +1718,8 @@ func (ds *DecimalUnaryArithmeticSuite) TestRound() {
options.Mode = tt.mode
exp := ds.getArr(ty, tt.exp)
defer exp.Release()
- checkScalar(ds.T(), fn,
[]compute.Datum{&compute.ArrayDatum{values.Data()}},
-
&compute.ArrayDatum{exp.Data()}, options)
+ checkScalar(ds.T(), fn,
[]compute.Datum{&compute.ArrayDatum{Value: values.Data()}},
+ &compute.ArrayDatum{Value:
exp.Data()}, options)
})
}
})
@@ -1738,16 +1738,16 @@ func (ds *DecimalUnaryArithmeticSuite)
TestRoundHalfToOddTies() {
expected := ds.getArr(ty, `["3.00", "-3.00", "3.00",
"-3.00", null]`)
defer expected.Release()
- checkScalar(ds.T(), "round",
[]compute.Datum{&compute.ArrayDatum{values.Data()}},
- &compute.ArrayDatum{expected.Data()}, options)
+ checkScalar(ds.T(), "round",
[]compute.Datum{&compute.ArrayDatum{Value: values.Data()}},
+ &compute.ArrayDatum{Value: expected.Data()},
options)
options.NDigits = 1
values = ds.getArr(ty, `["12.25", "-12.25"]`)
defer values.Release()
expected = ds.getArr(ty, `["12.30", "-12.30"]`)
defer expected.Release()
- checkScalar(ds.T(), "round",
[]compute.Datum{&compute.ArrayDatum{values.Data()}},
- &compute.ArrayDatum{expected.Data()}, options)
+ checkScalar(ds.T(), "round",
[]compute.Datum{&compute.ArrayDatum{Value: values.Data()}},
+ &compute.ArrayDatum{Value: expected.Data()},
options)
})
}
}
@@ -1762,33 +1762,33 @@ func (ds *DecimalUnaryArithmeticSuite)
TestRoundTowardsInfinity() {
vals := ds.getArr(ty, `["1.00", "1.99", "1.01",
"-42.00", "-42.99", "-42.15", null]`)
defer vals.Release()
- checkScalar(ds.T(), fn,
[]compute.Datum{&compute.ArrayDatum{empty.Data()}},
&compute.ArrayDatum{empty.Data()}, options)
- input :=
[]compute.Datum{&compute.ArrayDatum{vals.Data()}}
+ checkScalar(ds.T(), fn,
[]compute.Datum{&compute.ArrayDatum{Value: empty.Data()}},
&compute.ArrayDatum{Value: empty.Data()}, options)
+ input := []compute.Datum{&compute.ArrayDatum{Value:
vals.Data()}}
options.NDigits = 0
exp0 := ds.getArr(ty, `["1.00", "2.00", "2.00",
"-42.00", "-43.00", "-43.00", null]`)
defer exp0.Release()
- checkScalar(ds.T(), fn, input,
&compute.ArrayDatum{exp0.Data()}, options)
+ checkScalar(ds.T(), fn, input,
&compute.ArrayDatum{Value: exp0.Data()}, options)
exp1 := ds.getArr(ty, `["1.00", "2.00", "1.10",
"-42.00", "-43.00", "-42.20", null]`)
defer exp1.Release()
options.NDigits = 1
- checkScalar(ds.T(), fn, input,
&compute.ArrayDatum{exp1.Data()}, options)
+ checkScalar(ds.T(), fn, input,
&compute.ArrayDatum{Value: exp1.Data()}, options)
options.NDigits = 2
- checkScalar(ds.T(), fn, input,
&compute.ArrayDatum{vals.Data()}, options)
+ checkScalar(ds.T(), fn, input,
&compute.ArrayDatum{Value: vals.Data()}, options)
options.NDigits = 4
- checkScalar(ds.T(), fn, input,
&compute.ArrayDatum{vals.Data()}, options)
+ checkScalar(ds.T(), fn, input,
&compute.ArrayDatum{Value: vals.Data()}, options)
options.NDigits = 100
- checkScalar(ds.T(), fn, input,
&compute.ArrayDatum{vals.Data()}, options)
+ checkScalar(ds.T(), fn, input,
&compute.ArrayDatum{Value: vals.Data()}, options)
options.NDigits = -1
neg := ds.getArr(ty, `["10.00", "10.00", "10.00",
"-50.00", "-50.00", "-50.00", null]`)
defer neg.Release()
- checkScalar(ds.T(), fn, input,
&compute.ArrayDatum{neg.Data()}, options)
+ checkScalar(ds.T(), fn, input,
&compute.ArrayDatum{Value: neg.Data()}, options)
options.NDigits = -2
ds.checkFail(fn, input, "rounding to -2 digits will not
fit in precision", options)
@@ -1796,7 +1796,7 @@ func (ds *DecimalUnaryArithmeticSuite)
TestRoundTowardsInfinity() {
noprec := ds.getArr(ty, `["99.99"]`)
defer noprec.Release()
- ds.checkFail(fn,
[]compute.Datum{&compute.ArrayDatum{noprec.Data()}}, "rounded value 100.00 does
not fit in precision", options)
+ ds.checkFail(fn,
[]compute.Datum{&compute.ArrayDatum{Value: noprec.Data()}}, "rounded value
100.00 does not fit in precision", options)
})
}
@@ -1805,7 +1805,7 @@ func (ds *DecimalUnaryArithmeticSuite)
TestRoundTowardsInfinity() {
values := ds.getArr(ty, `["10E2", "12E2", "18E2",
"-10E2", "-12E2", "-18E2", null]`)
defer values.Release()
- input := &compute.ArrayDatum{values.Data()}
+ input := &compute.ArrayDatum{Value: values.Data()}
options.NDigits = 0
checkScalar(ds.T(), fn, []compute.Datum{input}, input,
options)
@@ -1820,7 +1820,7 @@ func (ds *DecimalUnaryArithmeticSuite)
TestRoundTowardsInfinity() {
options.NDigits = -3
res := ds.getArr(ty, `["10E2", "20E2", "20E2", "-10E2",
"-20E2", "-20E2", null]`)
defer res.Release()
- checkScalar(ds.T(), fn, []compute.Datum{input},
&compute.ArrayDatum{res.Data()}, options)
+ checkScalar(ds.T(), fn, []compute.Datum{input},
&compute.ArrayDatum{Value: res.Data()}, options)
options.NDigits = -4
ds.checkFail(fn, []compute.Datum{input}, "rounding to
-4 digits will not fit in precision", options)
@@ -1836,11 +1836,11 @@ func (ds *DecimalUnaryArithmeticSuite)
TestRoundHalfToEven() {
empty := ds.getArr(ty, `[]`)
defer empty.Release()
- checkScalar(ds.T(), fn,
[]compute.Datum{&compute.ArrayDatum{empty.Data()}},
&compute.ArrayDatum{empty.Data()}, options)
+ checkScalar(ds.T(), fn,
[]compute.Datum{&compute.ArrayDatum{Value: empty.Data()}},
&compute.ArrayDatum{Value: empty.Data()}, options)
values := ds.getArr(ty, `["1.00", "5.99", "1.01",
"-42.00", "-42.99", "-42.15", "1.50", "2.50", "-5.50", "-2.55", null]`)
defer values.Release()
- input := &compute.ArrayDatum{values.Data()}
+ input := &compute.ArrayDatum{Value: values.Data()}
exp0 := ds.getArr(ty, `["1.00", "6.00", "1.00",
"-42.00", "-43.00", "-42.00", "2.00", "2.00", "-6.00", "-3.00", null]`)
defer exp0.Release()
@@ -1852,9 +1852,9 @@ func (ds *DecimalUnaryArithmeticSuite)
TestRoundHalfToEven() {
defer expNeg1.Release()
options.NDigits = 0
- checkScalar(ds.T(), fn, []compute.Datum{input},
&compute.ArrayDatum{exp0.Data()}, options)
+ checkScalar(ds.T(), fn, []compute.Datum{input},
&compute.ArrayDatum{Value: exp0.Data()}, options)
options.NDigits = 1
- checkScalar(ds.T(), fn, []compute.Datum{input},
&compute.ArrayDatum{exp1.Data()}, options)
+ checkScalar(ds.T(), fn, []compute.Datum{input},
&compute.ArrayDatum{Value: exp1.Data()}, options)
options.NDigits = 2
checkScalar(ds.T(), fn, []compute.Datum{input}, input,
options)
options.NDigits = 4
@@ -1862,13 +1862,13 @@ func (ds *DecimalUnaryArithmeticSuite)
TestRoundHalfToEven() {
options.NDigits = 100
checkScalar(ds.T(), fn, []compute.Datum{input}, input,
options)
options.NDigits = -1
- checkScalar(ds.T(), fn, []compute.Datum{input},
&compute.ArrayDatum{expNeg1.Data()}, options)
+ checkScalar(ds.T(), fn, []compute.Datum{input},
&compute.ArrayDatum{Value: expNeg1.Data()}, options)
options.NDigits = -2
ds.checkFail(fn, []compute.Datum{input}, "rounding to
-2 digits will not fit in precision", options)
options.NDigits = -1
noprec := ds.getArr(ty, `["99.99"]`)
defer noprec.Release()
- ds.checkFail(fn,
[]compute.Datum{&compute.ArrayDatum{noprec.Data()}}, "rounded value 100.00 does
not fit in precision", options)
+ ds.checkFail(fn,
[]compute.Datum{&compute.ArrayDatum{Value: noprec.Data()}}, "rounded value
100.00 does not fit in precision", options)
})
}
for _, ty := range []arrow.DataType{&arrow.Decimal128Type{Precision: 2,
Scale: -2}, &arrow.Decimal256Type{Precision: 2, Scale: -2}} {
@@ -1876,7 +1876,7 @@ func (ds *DecimalUnaryArithmeticSuite)
TestRoundHalfToEven() {
values := ds.getArr(ty, `["5E2", "10E2", "12E2",
"15E2", "18E2", "-10E2", "-12E2", "-15E2", "-18E2", null]`)
defer values.Release()
- input := &compute.ArrayDatum{values.Data()}
+ input := &compute.ArrayDatum{Value: values.Data()}
options.NDigits = 0
checkScalar(ds.T(), fn, []compute.Datum{input}, input,
options)
@@ -1891,7 +1891,7 @@ func (ds *DecimalUnaryArithmeticSuite)
TestRoundHalfToEven() {
options.NDigits = -3
res := ds.getArr(ty, `["0", "10E2", "10E2", "20E2",
"20E2", "-10E2", "-10E2", "-20E2", "-20E2", null]`)
defer res.Release()
- checkScalar(ds.T(), fn, []compute.Datum{input},
&compute.ArrayDatum{res.Data()}, options)
+ checkScalar(ds.T(), fn, []compute.Datum{input},
&compute.ArrayDatum{Value: res.Data()}, options)
options.NDigits = -4
ds.checkFail(fn, []compute.Datum{input}, "rounding to
-4 digits will not fit in precision", options)
@@ -1906,16 +1906,16 @@ func (ds *DecimalUnaryArithmeticSuite) TestRoundCeil() {
empty := ds.getArr(ty, `[]`)
defer empty.Release()
- checkScalar(ds.T(), fn,
[]compute.Datum{&compute.ArrayDatum{empty.Data()}},
- &compute.ArrayDatum{empty.Data()}, nil)
+ checkScalar(ds.T(), fn,
[]compute.Datum{&compute.ArrayDatum{Value: empty.Data()}},
+ &compute.ArrayDatum{Value: empty.Data()}, nil)
in := ds.getArr(ty, `["1.00", "1.99", "1.01", "-42.00",
"-42.99", "-42.15", null]`)
defer in.Release()
out := ds.getArr(ty, `["1.00", "2.00", "2.00",
"-42.00", "-42.00", "-42.00", null]`)
defer out.Release()
- checkScalar(ds.T(), fn,
[]compute.Datum{&compute.ArrayDatum{in.Data()}},
- &compute.ArrayDatum{out.Data()}, nil)
+ checkScalar(ds.T(), fn,
[]compute.Datum{&compute.ArrayDatum{Value: in.Data()}},
+ &compute.ArrayDatum{Value: out.Data()}, nil)
})
}
for _, ty := range []arrow.DataType{&arrow.Decimal128Type{Precision: 4,
Scale: 2}, &arrow.Decimal256Type{Precision: 4, Scale: 2}} {
@@ -1932,14 +1932,14 @@ func (ds *DecimalUnaryArithmeticSuite) TestRoundCeil() {
empty := ds.getArr(ty, `[]`)
defer empty.Release()
- checkScalar(ds.T(), fn,
[]compute.Datum{&compute.ArrayDatum{empty.Data()}},
- &compute.ArrayDatum{empty.Data()}, nil)
+ checkScalar(ds.T(), fn,
[]compute.Datum{&compute.ArrayDatum{Value: empty.Data()}},
+ &compute.ArrayDatum{Value: empty.Data()}, nil)
ex := ds.getArr(ty, `["12E2", "-42E2", null]`)
defer ex.Release()
- checkScalar(ds.T(), fn,
[]compute.Datum{&compute.ArrayDatum{ex.Data()}},
- &compute.ArrayDatum{ex.Data()}, nil)
+ checkScalar(ds.T(), fn,
[]compute.Datum{&compute.ArrayDatum{Value: ex.Data()}},
+ &compute.ArrayDatum{Value: ex.Data()}, nil)
})
}
}
@@ -1951,16 +1951,16 @@ func (ds *DecimalUnaryArithmeticSuite) TestRoundFloor()
{
empty := ds.getArr(ty, `[]`)
defer empty.Release()
- checkScalar(ds.T(), fn,
[]compute.Datum{&compute.ArrayDatum{empty.Data()}},
- &compute.ArrayDatum{empty.Data()}, nil)
+ checkScalar(ds.T(), fn,
[]compute.Datum{&compute.ArrayDatum{Value: empty.Data()}},
+ &compute.ArrayDatum{Value: empty.Data()}, nil)
in := ds.getArr(ty, `["1.00", "1.99", "1.01", "-42.00",
"-42.99", "-42.15", null]`)
defer in.Release()
out := ds.getArr(ty, `["1.00", "1.00", "1.00",
"-42.00", "-43.00", "-43.00", null]`)
defer out.Release()
- checkScalar(ds.T(), fn,
[]compute.Datum{&compute.ArrayDatum{in.Data()}},
- &compute.ArrayDatum{out.Data()}, nil)
+ checkScalar(ds.T(), fn,
[]compute.Datum{&compute.ArrayDatum{Value: in.Data()}},
+ &compute.ArrayDatum{Value: out.Data()}, nil)
})
}
for _, ty := range []arrow.DataType{&arrow.Decimal128Type{Precision: 4,
Scale: 2}, &arrow.Decimal256Type{Precision: 4, Scale: 2}} {
@@ -1977,14 +1977,14 @@ func (ds *DecimalUnaryArithmeticSuite) TestRoundFloor()
{
empty := ds.getArr(ty, `[]`)
defer empty.Release()
- checkScalar(ds.T(), fn,
[]compute.Datum{&compute.ArrayDatum{empty.Data()}},
- &compute.ArrayDatum{empty.Data()}, nil)
+ checkScalar(ds.T(), fn,
[]compute.Datum{&compute.ArrayDatum{Value: empty.Data()}},
+ &compute.ArrayDatum{Value: empty.Data()}, nil)
ex := ds.getArr(ty, `["12E2", "-42E2", null]`)
defer ex.Release()
- checkScalar(ds.T(), fn,
[]compute.Datum{&compute.ArrayDatum{ex.Data()}},
- &compute.ArrayDatum{ex.Data()}, nil)
+ checkScalar(ds.T(), fn,
[]compute.Datum{&compute.ArrayDatum{Value: ex.Data()}},
+ &compute.ArrayDatum{Value: ex.Data()}, nil)
})
}
}
@@ -1996,16 +1996,16 @@ func (ds *DecimalUnaryArithmeticSuite) TestRoundTrunc()
{
empty := ds.getArr(ty, `[]`)
defer empty.Release()
- checkScalar(ds.T(), fn,
[]compute.Datum{&compute.ArrayDatum{empty.Data()}},
- &compute.ArrayDatum{empty.Data()}, nil)
+ checkScalar(ds.T(), fn,
[]compute.Datum{&compute.ArrayDatum{Value: empty.Data()}},
+ &compute.ArrayDatum{Value: empty.Data()}, nil)
in := ds.getArr(ty, `["1.00", "1.99", "1.01", "-42.00",
"-42.99", "-42.15", null]`)
defer in.Release()
out := ds.getArr(ty, `["1.00", "1.00", "1.00",
"-42.00", "-42.00", "-42.00", null]`)
defer out.Release()
- checkScalar(ds.T(), fn,
[]compute.Datum{&compute.ArrayDatum{in.Data()}},
- &compute.ArrayDatum{out.Data()}, nil)
+ checkScalar(ds.T(), fn,
[]compute.Datum{&compute.ArrayDatum{Value: in.Data()}},
+ &compute.ArrayDatum{Value: out.Data()}, nil)
})
}
for _, ty := range []arrow.DataType{&arrow.Decimal128Type{Precision: 4,
Scale: 2}, &arrow.Decimal256Type{Precision: 4, Scale: 2}} {
@@ -2023,14 +2023,14 @@ func (ds *DecimalUnaryArithmeticSuite) TestRoundTrunc()
{
empty := ds.getArr(ty, `[]`)
defer empty.Release()
- checkScalar(ds.T(), fn,
[]compute.Datum{&compute.ArrayDatum{empty.Data()}},
- &compute.ArrayDatum{empty.Data()}, nil)
+ checkScalar(ds.T(), fn,
[]compute.Datum{&compute.ArrayDatum{Value: empty.Data()}},
+ &compute.ArrayDatum{Value: empty.Data()}, nil)
ex := ds.getArr(ty, `["12E2", "-42E2", null]`)
defer ex.Release()
- checkScalar(ds.T(), fn,
[]compute.Datum{&compute.ArrayDatum{ex.Data()}},
- &compute.ArrayDatum{ex.Data()}, nil)
+ checkScalar(ds.T(), fn,
[]compute.Datum{&compute.ArrayDatum{Value: ex.Data()}},
+ &compute.ArrayDatum{Value: ex.Data()}, nil)
})
}
}
@@ -2049,7 +2049,7 @@ func (ds *DecimalUnaryArithmeticSuite)
TestRoundToMultiple() {
values := ds.getArr(ty, `["-3.50", "-3.00", "-2.50",
"-2.00", "-1.50", "-1.00", "-0.50", "0.00", "0.50", "1.00", "1.50", "2.00",
"2.50", "3.00", "3.50", null]`)
defer values.Release()
- input :=
[]compute.Datum{&compute.ArrayDatum{values.Data()}}
+ input := []compute.Datum{&compute.ArrayDatum{Value:
values.Data()}}
tests := []struct {
mode compute.RoundMode
@@ -2074,7 +2074,7 @@ func (ds *DecimalUnaryArithmeticSuite)
TestRoundToMultiple() {
result := ds.getArr(ty, tt.exp)
defer result.Release()
- checkScalar(ds.T(), fn, input,
&compute.ArrayDatum{result.Data()}, options)
+ checkScalar(ds.T(), fn, input,
&compute.ArrayDatum{Value: result.Data()}, options)
})
}
})
@@ -2100,14 +2100,14 @@ func (ds *DecimalUnaryArithmeticSuite)
TestRoundToMultipleTowardsInfinity() {
values := ds.getArr(ty, `["1.00", "1.99", "1.01",
"-42.00", "-42.99", "-42.15", null]`)
defer values.Release()
- input := &compute.ArrayDatum{values.Data()}
+ input := &compute.ArrayDatum{Value: values.Data()}
setMultiple(ty, 25)
- checkScalar(ds.T(), fn,
[]compute.Datum{&compute.ArrayDatum{empty.Data()}},
&compute.ArrayDatum{empty.Data()}, options)
+ checkScalar(ds.T(), fn,
[]compute.Datum{&compute.ArrayDatum{Value: empty.Data()}},
&compute.ArrayDatum{Value: empty.Data()}, options)
exp25 := ds.getArr(ty, `["1.00", "2.00", "1.25",
"-42.00", "-43.00", "-42.25", null]`)
defer exp25.Release()
- checkScalar(ds.T(), fn, []compute.Datum{input},
&compute.ArrayDatum{exp25.Data()}, options)
+ checkScalar(ds.T(), fn, []compute.Datum{input},
&compute.ArrayDatum{Value: exp25.Data()}, options)
setMultiple(ty, 1)
checkScalar(ds.T(), fn, []compute.Datum{input}, input,
options)
@@ -2115,7 +2115,7 @@ func (ds *DecimalUnaryArithmeticSuite)
TestRoundToMultipleTowardsInfinity() {
setMultiple(&arrow.Decimal128Type{Precision: 2, Scale:
0}, 2)
exp20 := ds.getArr(ty, `["2.00", "2.00", "2.00",
"-42.00", "-44.00", "-44.00", null]`)
defer exp20.Release()
- checkScalar(ds.T(), fn, []compute.Datum{input},
&compute.ArrayDatum{exp20.Data()}, options)
+ checkScalar(ds.T(), fn, []compute.Datum{input},
&compute.ArrayDatum{Value: exp20.Data()}, options)
setMultiple(ty, 0)
ds.checkFail(fn, []compute.Datum{input}, "rounding
multiple must be positive", options)
@@ -2126,7 +2126,7 @@ func (ds *DecimalUnaryArithmeticSuite)
TestRoundToMultipleTowardsInfinity() {
tester := ds.getArr(ty, `["99.99"]`)
defer tester.Release()
- testDatum := &compute.ArrayDatum{tester.Data()}
+ testDatum := &compute.ArrayDatum{Value: tester.Data()}
setMultiple(ty, -10)
ds.checkFail(fn, []compute.Datum{testDatum}, "rounding
multiple must be positive", options)
@@ -2146,13 +2146,13 @@ func (ds *DecimalUnaryArithmeticSuite)
TestRoundToMultipleTowardsInfinity() {
values := ds.getArr(ty, `["10E2", "12E2", "18E2",
"-10E2", "-12E2", "-18E2", null]`)
defer values.Release()
- input := &compute.ArrayDatum{values.Data()}
+ input := &compute.ArrayDatum{Value: values.Data()}
setMultiple(ty, 4)
exp := ds.getArr(ty, `["12E2", "12E2", "20E2", "-12E2",
"-12E2", "-20E2", null]`)
defer exp.Release()
- checkScalar(ds.T(), fn, []compute.Datum{input},
&compute.ArrayDatum{exp.Data()}, options)
+ checkScalar(ds.T(), fn, []compute.Datum{input},
&compute.ArrayDatum{Value: exp.Data()}, options)
setMultiple(ty, 1)
checkScalar(ds.T(), fn, []compute.Datum{input}, input,
options)
@@ -2178,31 +2178,31 @@ func (ds *DecimalUnaryArithmeticSuite)
TestRoundToMultipleHalfToOdd() {
values := ds.getArr(ty, `["-0.38", "-0.37", "-0.25", "-0.13",
"-0.12", "0.00", "0.12", "0.13", "0.25", "0.37", "0.38", null]`)
defer values.Release()
- input := &compute.ArrayDatum{values.Data()}
+ input := &compute.ArrayDatum{Value: values.Data()}
// there is no exact halfway point, check what happens
setMultiple(ty, 25)
- checkScalar(ds.T(), fn,
[]compute.Datum{&compute.ArrayDatum{empty.Data()}},
&compute.ArrayDatum{empty.Data()}, options)
+ checkScalar(ds.T(), fn,
[]compute.Datum{&compute.ArrayDatum{Value: empty.Data()}},
&compute.ArrayDatum{Value: empty.Data()}, options)
exp25 := ds.getArr(ty, `["-0.50", "-0.25", "-0.25", "-0.25",
"-0.00", "0.00", "0.00", "0.25", "0.25", "0.25", "0.50", null]`)
defer exp25.Release()
- checkScalar(ds.T(), fn, []compute.Datum{input},
&compute.ArrayDatum{exp25.Data()}, options)
+ checkScalar(ds.T(), fn, []compute.Datum{input},
&compute.ArrayDatum{Value: exp25.Data()}, options)
setMultiple(ty, 1)
checkScalar(ds.T(), fn, []compute.Datum{input}, input, options)
setMultiple(ty, 24)
- checkScalar(ds.T(), fn,
[]compute.Datum{&compute.ArrayDatum{empty.Data()}},
&compute.ArrayDatum{empty.Data()}, options)
+ checkScalar(ds.T(), fn,
[]compute.Datum{&compute.ArrayDatum{Value: empty.Data()}},
&compute.ArrayDatum{Value: empty.Data()}, options)
exp24 := ds.getArr(ty, `["-0.48", "-0.48", "-0.24", "-0.24",
"-0.24", "0.00", "0.24", "0.24", "0.24", "0.48", "0.48", null]`)
defer exp24.Release()
- checkScalar(ds.T(), fn, []compute.Datum{input},
&compute.ArrayDatum{exp24.Data()}, options)
+ checkScalar(ds.T(), fn, []compute.Datum{input},
&compute.ArrayDatum{Value: exp24.Data()}, options)
setMultiple(&arrow.Decimal128Type{Precision: 3, Scale: 1}, 1)
exp1 := ds.getArr(ty, `["-0.40", "-0.40", "-0.30", "-0.10",
"-0.10", "0.00", "0.10", "0.10", "0.30", "0.40", "0.40", null]`)
defer exp1.Release()
- checkScalar(ds.T(), fn, []compute.Datum{input},
&compute.ArrayDatum{exp1.Data()}, options)
+ checkScalar(ds.T(), fn, []compute.Datum{input},
&compute.ArrayDatum{Value: exp1.Data()}, options)
}
for _, ty := range []arrow.DataType{&arrow.Decimal128Type{Precision: 2,
Scale: -2}, &arrow.Decimal256Type{Precision: 2, Scale: -2}} {
@@ -2215,12 +2215,12 @@ func (ds *DecimalUnaryArithmeticSuite)
TestRoundToMultipleHalfToOdd() {
exp5 := ds.getArr(ty, `["10E2", "10E2", "20E2", "-10E2",
"-10E2", "-20E2", null]`)
defer exp5.Release()
- input := &compute.ArrayDatum{values.Data()}
+ input := &compute.ArrayDatum{Value: values.Data()}
setMultiple(ty, 4)
- checkScalar(ds.T(), fn, []compute.Datum{input},
&compute.ArrayDatum{exp4.Data()}, options)
+ checkScalar(ds.T(), fn, []compute.Datum{input},
&compute.ArrayDatum{Value: exp4.Data()}, options)
setMultiple(ty, 5)
- checkScalar(ds.T(), fn, []compute.Datum{input},
&compute.ArrayDatum{exp5.Data()}, options)
+ checkScalar(ds.T(), fn, []compute.Datum{input},
&compute.ArrayDatum{Value: exp5.Data()}, options)
setMultiple(ty, 1)
checkScalar(ds.T(), fn, []compute.Datum{input}, input, options)
@@ -2510,11 +2510,11 @@ func (us *UnaryArithmeticSuite[T, O])
assertUnaryOpScalars(fn unaryArithmeticFun
}
func (us *UnaryArithmeticSuite[T, O]) assertUnaryOpArrs(fn
unaryArithmeticFunc[O], arg, exp arrow.Array) {
- datum := &compute.ArrayDatum{arg.Data()}
+ datum := &compute.ArrayDatum{Value: arg.Data()}
actual, err := fn(us.ctx, us.opts, datum)
us.Require().NoError(err)
defer actual.Release()
- assertDatumsEqual(us.T(), &compute.ArrayDatum{exp.Data()}, actual,
[]array.EqualOption{array.WithNaNsEqual(true)},
[]scalar.EqualOption{scalar.WithNaNsEqual(true)})
+ assertDatumsEqual(us.T(), &compute.ArrayDatum{Value: exp.Data()},
actual, []array.EqualOption{array.WithNaNsEqual(true)},
[]scalar.EqualOption{scalar.WithNaNsEqual(true)})
// also check scalar ops
for i := 0; i < arg.Len(); i++ {
@@ -2553,7 +2553,7 @@ func (us *UnaryArithmeticSuite[T, O]) assertUnaryOpErr(fn
unaryArithmeticFunc[O]
us.Require().NoError(err)
defer in.Release()
- _, err = fn(us.ctx, us.opts, &compute.ArrayDatum{in.Data()})
+ _, err = fn(us.ctx, us.opts, &compute.ArrayDatum{Value: in.Data()})
us.ErrorIs(err, arrow.ErrInvalid)
us.ErrorContains(err, msg)
}
@@ -3023,10 +3023,10 @@ func (bs *BitwiseArithmeticSuite[T]) assertBinaryOp(fn
string, arg0, arg1, expec
out.Release()
}()
- actual, err := compute.CallFunction(bs.ctx, fn, nil,
&compute.ArrayDatum{in0.Data()}, &compute.ArrayDatum{in1.Data()})
+ actual, err := compute.CallFunction(bs.ctx, fn, nil,
&compute.ArrayDatum{Value: in0.Data()}, &compute.ArrayDatum{Value: in1.Data()})
bs.Require().NoError(err)
defer actual.Release()
- assertDatumsEqual(bs.T(), &compute.ArrayDatum{out.Data()}, actual, nil,
nil)
+ assertDatumsEqual(bs.T(), &compute.ArrayDatum{Value: out.Data()},
actual, nil, nil)
for i := 0; i < out.Len(); i++ {
a0, err := scalar.GetScalar(in0, i)
diff --git a/arrow/compute/cast_test.go b/arrow/compute/cast_test.go
index 532c3d62..fdcff6f1 100644
--- a/arrow/compute/cast_test.go
+++ b/arrow/compute/cast_test.go
@@ -3955,7 +3955,7 @@ func (c *CastSuite) TestFromDictionary() {
for _, ty := range dictIndexTypes {
indices, _, _ := array.FromJSON(c.mem, ty,
strings.NewReader(`[4, 0, 1, 2, 0, 4, null, 2]`))
- expected, err := compute.Take(ctx,
compute.TakeOptions{}, &compute.ArrayDatum{d.Data()},
&compute.ArrayDatum{indices.Data()})
+ expected, err := compute.Take(ctx,
compute.TakeOptions{}, &compute.ArrayDatum{Value: d.Data()},
&compute.ArrayDatum{Value: indices.Data()})
c.Require().NoError(err)
exp := expected.(*compute.ArrayDatum).MakeArray()
diff --git a/arrow/compute/datum.go b/arrow/compute/datum.go
index 65dee0aa..822add20 100644
--- a/arrow/compute/datum.go
+++ b/arrow/compute/datum.go
@@ -100,7 +100,8 @@ func (EmptyDatum) data() any { return nil }
// ScalarDatum contains a scalar value
type ScalarDatum struct {
- Value scalar.Scalar
+ Value scalar.Scalar
+ borrowed bool
}
func (ScalarDatum) Kind() DatumKind { return KindScalar }
@@ -124,6 +125,9 @@ type releasable interface {
}
func (d *ScalarDatum) Release() {
+ if d.borrowed {
+ return
+ }
if v, ok := d.Value.(releasable); ok {
v.Release()
}
@@ -139,7 +143,8 @@ func (d *ScalarDatum) Equals(other Datum) bool {
// ArrayDatum references an array.Data object which can be used to create
// array instances from if needed.
type ArrayDatum struct {
- Value arrow.ArrayData
+ Value arrow.ArrayData
+ borrowed bool
}
func (ArrayDatum) Kind() DatumKind { return KindArray }
@@ -153,6 +158,9 @@ func (d *ArrayDatum) ToScalar() (scalar.Scalar, error) {
return scalar.NewListScalarData(d.Value), nil
}
func (d *ArrayDatum) Release() {
+ if d.borrowed {
+ return
+ }
d.Value.Release()
d.Value = nil
}
@@ -173,7 +181,8 @@ func (d *ArrayDatum) Equals(other Datum) bool {
// ChunkedDatum contains a chunked array for use with expressions and compute.
type ChunkedDatum struct {
- Value *arrow.Chunked
+ Value *arrow.Chunked
+ borrowed bool
}
func (ChunkedDatum) Kind() DatumKind { return KindChunked }
@@ -184,6 +193,9 @@ func (d *ChunkedDatum) String() string { return
fmt.Sprintf("Array:{%s}",
func (d *ChunkedDatum) Chunks() []arrow.Array { return d.Value.Chunks() }
func (d *ChunkedDatum) data() any { return d.Value }
func (d *ChunkedDatum) Release() {
+ if d.borrowed {
+ return
+ }
d.Value.Release()
d.Value = nil
}
@@ -198,7 +210,8 @@ func (d *ChunkedDatum) Equals(other Datum) bool {
// RecordDatum contains an array.Record for passing a full record to an
expression
// or to compute.
type RecordDatum struct {
- Value arrow.RecordBatch
+ Value arrow.RecordBatch
+ borrowed bool
}
func (RecordDatum) Kind() DatumKind { return KindRecord }
@@ -207,6 +220,9 @@ func (r *RecordDatum) Len() int64 { return
r.Value.NumRows() }
func (r *RecordDatum) Schema() *arrow.Schema { return r.Value.Schema() }
func (r *RecordDatum) data() any { return r.Value }
func (r *RecordDatum) Release() {
+ if r.borrowed {
+ return
+ }
r.Value.Release()
r.Value = nil
}
@@ -221,7 +237,8 @@ func (r *RecordDatum) Equals(other Datum) bool {
// TableDatum contains a table so that multiple record batches can be worked
with
// together as a single table for being passed to compute and expression
handling.
type TableDatum struct {
- Value arrow.Table
+ Value arrow.Table
+ borrowed bool
}
func (TableDatum) Kind() DatumKind { return KindTable }
@@ -230,6 +247,9 @@ func (d *TableDatum) Len() int64 { return
d.Value.NumRows() }
func (d *TableDatum) Schema() *arrow.Schema { return d.Value.Schema() }
func (d *TableDatum) data() any { return d.Value }
func (d *TableDatum) Release() {
+ if d.borrowed {
+ return
+ }
d.Value.Release()
d.Value = nil
}
@@ -256,50 +276,67 @@ 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 — the
+// caller is responsible for keeping it alive for as long as the Datum is
+// in use. Release on a Datum from NewDatumWithoutOwning is a no-op, so use
+// NewDatum when the Datum should own the value.
+//
+// Example:
//
-// Two call patterns follow from that. Wrapping a value the caller still owns
-// borrows it: the caller keeps the value alive for as long as the Datum is in
-// use and must not call Release on the Datum, because that would give up the
-// caller's own reference and, with a C-backed allocator or buffers imported
-// through the cdata package, free memory under a live value. Wrapping a
-// value created for the Datum transfers it: the Datum is then the only
-// handle, and it must eventually be released through the Datum or the
-// value's retained data leaks. NewDatum itself uses the second pattern,
-// retaining a Releasable and handing the new reference to this function.
+// builder := array.NewInt32Builder(memory.DefaultAllocator)
+// builder.AppendValues([]int32{1, 2, 3}, nil)
+// arr := builder.NewArray()
+// defer arr.Release()
+// datum := NewDatumWithoutOwning(arr) // datum borrows arr, arr is still
alive
func NewDatumWithoutOwning(value interface{}) Datum {
switch v := value.(type) {
case arrow.Array:
- return &ArrayDatum{v.Data()}
+ return &ArrayDatum{Value: v.Data(), borrowed: true}
case arrow.ArrayData:
- return &ArrayDatum{v}
+ return &ArrayDatum{Value: v, borrowed: true}
case *arrow.Chunked:
- return &ChunkedDatum{v}
+ return &ChunkedDatum{Value: v, borrowed: true}
case arrow.RecordBatch:
- return &RecordDatum{v}
+ return &RecordDatum{Value: v, borrowed: true}
case arrow.Table:
- return &TableDatum{v}
+ return &TableDatum{Value: v, borrowed: true}
case scalar.Scalar:
- return &ScalarDatum{v}
+ return &ScalarDatum{Value: v, borrowed: true}
default:
- return &ScalarDatum{scalar.MakeScalar(value)}
+ // When given a plain Go value (not an Arrow type), we construct
+ // a new Scalar via scalar.MakeScalar. Since this scalar is
created
+ // here with no prior owner, the Datum takes ownership of it
+ // (borrowed=false) — Datum.Release() will free it.
+ return &ScalarDatum{Value: scalar.MakeScalar(value)}
}
}
diff --git a/arrow/compute/datum_test.go b/arrow/compute/datum_test.go
new file mode 100644
index 00000000..ef7c97a8
--- /dev/null
+++ b/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).
+// 2. NewDatumWithoutOwning borrows it without Retain.
+// 3. Datum.Release() must be a no-op (refcount still 1).
+// 4. Caller's Release() finally frees everything.
+//
+// This is the regression test for issue #1298.
+func TestNewDatumWithoutOwningDoesNotLeakOwner(t *testing.T) {
+ mem := memory.NewCheckedAllocator(memory.NewGoAllocator())
+ defer mem.AssertSize(t, 0)
+
+ // -- Array --------------------------------------------------------
+ {
+ builder := array.NewInt32Builder(mem)
+ builder.AppendValues([]int32{1, 2, 3, 4, 5, 6, 7, 8}, nil)
+ arr := builder.NewArray()
+ builder.Release()
+
+ assert.Greater(t, mem.CurrentAlloc(), 0,
+ "array builder should have allocated backing buffers")
+
+ before := mem.CurrentAlloc()
+ d := NewDatumWithoutOwning(arr)
+ d.Release() // must be no-op
+
+ assert.Equal(t, before, mem.CurrentAlloc(),
+ "ArrayDatum.Release() must not free caller's
allocation")
+
+ arr.Release()
+ }
+
+ // -- Chunked ------------------------------------------------------
+ {
+ builder := array.NewInt32Builder(mem)
+ builder.AppendValues([]int32{9, 10, 11, 12, 13, 14, 15, 16},
nil)
+ arr := builder.NewArray()
+ builder.Release()
+
+ chunked := arrow.NewChunked(arr.DataType(), []arrow.Array{arr})
+ // chunked owns arr (Retain), caller can now release arr
+ arr.Release()
+
+ before := mem.CurrentAlloc()
+ d := NewDatumWithoutOwning(chunked)
+ d.Release()
+
+ assert.Equal(t, before, mem.CurrentAlloc(),
+ "ChunkedDatum.Release() must not free caller's
allocation")
+
+ chunked.Release()
+ }
+
+ // -- RecordBatch --------------------------------------------------
+ {
+ builder := array.NewInt32Builder(mem)
+ builder.AppendValues([]int32{1, 2, 3, 4, 5, 6, 7, 8}, nil)
+ arr := builder.NewArray()
+ builder.Release()
+
+ schema := arrow.NewSchema([]arrow.Field{{Name: "col", Type:
arr.DataType()}}, nil)
+ rec := array.NewRecordBatch(schema, []arrow.Array{arr}, 8)
+ // rec owns arr (Retain), caller can now release arr
+ arr.Release()
+
+ before := mem.CurrentAlloc()
+ d := NewDatumWithoutOwning(rec)
+ d.Release()
+
+ assert.Equal(t, before, mem.CurrentAlloc(),
+ "RecordDatum.Release() must not free caller's
allocation")
+
+ rec.Release()
+ }
+
+ // -- Table --------------------------------------------------------
+ {
+ builder := array.NewInt32Builder(mem)
+ builder.AppendValues([]int32{1, 2, 3, 4, 5, 6, 7, 8}, nil)
+ arr := builder.NewArray()
+ builder.Release()
+
+ schema := arrow.NewSchema([]arrow.Field{{Name: "col", Type:
arr.DataType()}}, nil)
+ chunked := arrow.NewChunked(arr.DataType(), []arrow.Array{arr})
+ // chunked owns arr
+ arr.Release()
+
+ col := arrow.NewColumn(schema.Field(0), chunked)
+ // column owns chunked
+ chunked.Release()
+
+ tbl := array.NewTable(schema, []arrow.Column{*col}, -1)
+ // table owns column
+ col.Release()
+
+ before := mem.CurrentAlloc()
+ d := NewDatumWithoutOwning(tbl)
+ d.Release()
+
+ assert.Equal(t, before, mem.CurrentAlloc(),
+ "TableDatum.Release() must not free caller's
allocation")
+
+ tbl.Release()
+ }
+
+ // -- Scalar (list scalar wraps an array, so it allocates) ---------
+ {
+ builder := array.NewInt32Builder(mem)
+ builder.AppendValues([]int32{100, 200, 300}, nil)
+ arr := builder.NewArray()
+ builder.Release()
+
+ sc := scalar.NewListScalar(arr)
+ // list scalar wraps arr's data via array.MakeFromData
+ arr.Release()
+
+ assert.Greater(t, mem.CurrentAlloc(), 0,
+ "list scalar should wrap an allocated array")
+
+ before := mem.CurrentAlloc()
+ d := NewDatumWithoutOwning(sc)
+ d.Release()
+
+ assert.Equal(t, before, mem.CurrentAlloc(),
+ "ScalarDatum.Release() must not free caller's
allocation")
+
+ sc.Release()
+ }
+}
+
+// TestNewDatumOwns verifies the owning NewDatum path releases its
+// Retain on Datum.Release(), leaving the caller a single Release to do.
+func TestNewDatumOwns(t *testing.T) {
+ mem := memory.NewCheckedAllocator(memory.NewGoAllocator())
+ defer mem.AssertSize(t, 0)
+
+ builder := array.NewInt32Builder(mem)
+ builder.AppendValues([]int32{1, 2, 3}, nil)
+ arr := builder.NewArray()
+ builder.Release()
+
+ // NewDatum Retains the array data; Datum.Release() must Relinquish.
+ before := mem.CurrentAlloc()
+ d := NewDatum(arr)
+ d.Release()
+ assert.Equal(t, before, mem.CurrentAlloc(),
+ "Datum.Release() must exactly match the Retain from NewDatum")
+
+ // caller still owns arr's last reference
+ arr.Release()
+}
diff --git a/arrow/compute/exec_internals_test.go
b/arrow/compute/exec_internals_test.go
index 9def1be9..b7380957 100644
--- a/arrow/compute/exec_internals_test.go
+++ b/arrow/compute/exec_internals_test.go
@@ -514,7 +514,7 @@ func (e *ExecSpanItrSuite) TestInputValidation() {
// length mismatch
batch := &ExecBatch{
- Values: []Datum{&ArrayDatum{arr1.Data()},
&ArrayDatum{arr2.Data()}},
+ Values: []Datum{&ArrayDatum{Value: arr1.Data()},
&ArrayDatum{Value: arr2.Data()}},
Len: 10,
}
@@ -522,12 +522,12 @@ func (e *ExecSpanItrSuite) TestInputValidation() {
e.ErrorIs(err, arrow.ErrInvalid)
// swap order of input
- batch.Values = []Datum{&ArrayDatum{arr2.Data()},
&ArrayDatum{arr1.Data()}}
+ batch.Values = []Datum{&ArrayDatum{Value: arr2.Data()},
&ArrayDatum{Value: arr1.Data()}}
_, _, err = iterateExecSpans(batch, DefaultMaxChunkSize, true)
e.ErrorIs(err, arrow.ErrInvalid)
- batch.Values = []Datum{&ArrayDatum{arr1.Data()}}
+ batch.Values = []Datum{&ArrayDatum{Value: arr1.Data()}}
_, _, err = iterateExecSpans(batch, DefaultMaxChunkSize, true)
e.NoError(err)
}
@@ -542,7 +542,7 @@ func (e *ExecSpanItrSuite) TestChunkedArrays() {
batch := &ExecBatch{
Values: []Datum{
- &ChunkedDatum{arr1}, &ChunkedDatum{arr2},
&ArrayDatum{arr3.Data()},
+ &ChunkedDatum{Value: arr1}, &ChunkedDatum{Value: arr2},
&ArrayDatum{Value: arr3.Data()},
NewDatum(int32(5)),
NewDatum(scalar.MakeNullScalar(arrow.FixedWidthTypes.Boolean))},
Len: 30,
}
@@ -566,18 +566,18 @@ func (e *ExecSpanItrSuite) TestZeroLengthInput() {
input := &ExecBatch{Len: 0}
// zero-length chunkedarray with zero chunks
- input.Values = []Datum{&ChunkedDatum{carr}}
+ input.Values = []Datum{&ChunkedDatum{Value: carr}}
checkArgs(input)
// zero-length array
arr := e.getInt32Arr(0, 0.1)
defer arr.Release()
- input.Values = []Datum{&ArrayDatum{arr.Data()}}
+ input.Values = []Datum{&ArrayDatum{Value: arr.Data()}}
checkArgs(input)
// chunkedarray with single empty chunk
carr = e.getInt32Chunked([]int64{0})
- input.Values = []Datum{&ChunkedDatum{carr}}
+ input.Values = []Datum{&ChunkedDatum{Value: carr}}
checkArgs(input)
}
diff --git a/arrow/compute/exec_test.go b/arrow/compute/exec_test.go
index 65007dd5..7cba69fb 100644
--- a/arrow/compute/exec_test.go
+++ b/arrow/compute/exec_test.go
@@ -501,7 +501,7 @@ func (c *CallScalarFuncSuite) TestPreallocationCases() {
c.resetCtx()
c.Run("single output default", func() {
- result, err := CallFunction(c.ctx.Ctx,
funcName, nil, &ArrayDatum{arr.Data()})
+ result, err := CallFunction(c.ctx.Ctx,
funcName, nil, &ArrayDatum{Value: arr.Data()})
c.NoError(err)
defer result.Release()
c.Equal(KindArray, result.Kind())
@@ -513,7 +513,7 @@ func (c *CallScalarFuncSuite) TestPreallocationCases() {
// several invocations of the kernel,
// but still only one output array
c.execCtx.ChunkSize = 80
- result, err :=
CallFunction(SetExecCtx(c.ctx.Ctx, c.execCtx), funcName, nil,
&ArrayDatum{arr.Data()})
+ result, err :=
CallFunction(SetExecCtx(c.ctx.Ctx, c.execCtx), funcName, nil,
&ArrayDatum{Value: arr.Data()})
c.NoError(err)
defer result.Release()
c.Equal(KindArray, result.Kind())
@@ -523,7 +523,7 @@ func (c *CallScalarFuncSuite) TestPreallocationCases() {
c.Run("not multiple 8 chunk", func() {
// chunksize is not a multiple of 8
c.execCtx.ChunkSize = 11
- result, err :=
CallFunction(SetExecCtx(c.ctx.Ctx, c.execCtx), funcName, nil,
&ArrayDatum{arr.Data()})
+ result, err :=
CallFunction(SetExecCtx(c.ctx.Ctx, c.execCtx), funcName, nil,
&ArrayDatum{Value: arr.Data()})
c.NoError(err)
defer result.Release()
c.Equal(KindArray, result.Kind())
@@ -538,7 +538,7 @@ func (c *CallScalarFuncSuite) TestPreallocationCases() {
carr := arrow.NewChunked(arr.DataType(),
[]arrow.Array{chk1, chk2})
defer carr.Release()
- result, err :=
CallFunction(SetExecCtx(c.ctx.Ctx, c.execCtx), funcName, nil,
&ChunkedDatum{carr})
+ result, err :=
CallFunction(SetExecCtx(c.ctx.Ctx, c.execCtx), funcName, nil,
&ChunkedDatum{Value: carr})
c.NoError(err)
defer result.Release()
c.Equal(KindChunked, result.Kind())
@@ -551,7 +551,7 @@ func (c *CallScalarFuncSuite) TestPreallocationCases() {
// preallocate independently for each batch
c.execCtx.PreallocContiguous = false
c.execCtx.ChunkSize = 40
- result, err :=
CallFunction(SetExecCtx(c.ctx.Ctx, c.execCtx), funcName, nil,
&ArrayDatum{arr.Data()})
+ result, err :=
CallFunction(SetExecCtx(c.ctx.Ctx, c.execCtx), funcName, nil,
&ArrayDatum{Value: arr.Data()})
c.NoError(err)
defer result.Release()
c.Equal(KindChunked, result.Kind())
@@ -582,7 +582,7 @@ func (c *CallScalarFuncSuite) TestBasicNonStandardCases() {
nullProb := float64(0.2)
arr := c.getUint8Arr(1000, nullProb)
defer arr.Release()
- args := []Datum{&ArrayDatum{arr.Data()}}
+ args := []Datum{&ArrayDatum{Value: arr.Data()}}
for _, funcName := range []string{"test_nopre_data",
"test_nopre_validity_or_data"} {
c.Run("funcName", func() {
@@ -628,7 +628,7 @@ func (c *CallScalarFuncSuite) TestStatefulKernel() {
defer expected.Release()
options := &ExampleOptions{multiplier}
- result, err := CallFunction(c.ctx.Ctx, "test_stateful", options,
&ArrayDatum{input.Data()})
+ result, err := CallFunction(c.ctx.Ctx, "test_stateful", options,
&ArrayDatum{Value: input.Data()})
c.NoError(err)
defer result.Release()
c.assertDatumEqual(expected, result)
diff --git a/arrow/compute/executor.go b/arrow/compute/executor.go
index cb1dfee4..7f6c410a 100644
--- a/arrow/compute/executor.go
+++ b/arrow/compute/executor.go
@@ -1283,9 +1283,19 @@ func (a *scalarAggExecutor) Execute(ctx context.Context,
batch *ExecBatch, data
return fmt.Errorf("%w: scalar aggregate kernel finalized
without a result", arrow.ErrInvalid)
}
- // the result owns its value; boxing it without owning hands that single
- // reference over to the Datum, which the caller releases
- out := NewDatumWithoutOwning(result.Take())
+ // the result owns its value; boxing it as an owned Datum hands that
+ // single reference over to the Datum, which the caller releases
+ var out Datum
+ switch taken := result.Take().(type) {
+ case nil:
+ out = &EmptyDatum{}
+ case scalar.Scalar:
+ out = &ScalarDatum{Value: taken}
+ case arrow.ArrayData:
+ out = &ArrayDatum{Value: taken}
+ default:
+ return fmt.Errorf("%w: unexpected aggregate result type %T from
Take()", arrow.ErrInvalid, taken)
+ }
select {
case <-ctx.Done():
out.Release()
diff --git a/arrow/compute/exprs/exec.go b/arrow/compute/exprs/exec.go
index 722147f6..d4f60294 100644
--- a/arrow/compute/exprs/exec.go
+++ b/arrow/compute/exprs/exec.go
@@ -326,7 +326,7 @@ func literalToDatum(mem memory.Allocator, lit expr.Literal,
ext ExtensionIDSet)
}
defer kvArr.Release()
- return
compute.NewDatumWithoutOwning(scalar.NewMapScalar(kvArr)), nil
+ return &compute.ScalarDatum{Value: scalar.NewMapScalar(kvArr)},
nil
case *expr.StructLiteral:
fields := make([]scalar.Scalar, len(v.Value))
names := make([]string, len(v.Value))
diff --git a/arrow/compute/scalar_compare_test.go
b/arrow/compute/scalar_compare_test.go
index ad93630a..5cca7f36 100644
--- a/arrow/compute/scalar_compare_test.go
+++ b/arrow/compute/scalar_compare_test.go
@@ -64,7 +64,7 @@ func (c *CompareSuite) validateCompare(op
kernels.CompareOperator, dt arrow.Data
rhs.Release()
exp.Release()
}()
- c.validateCompareDatum(op, &compute.ArrayDatum{lhs.Data()},
&compute.ArrayDatum{rhs.Data()}, &compute.ArrayDatum{exp.Data()})
+ c.validateCompareDatum(op, &compute.ArrayDatum{Value: lhs.Data()},
&compute.ArrayDatum{Value: rhs.Data()}, &compute.ArrayDatum{Value: exp.Data()})
}
func (c *CompareSuite) validateCompareArrScalar(op kernels.CompareOperator, dt
arrow.DataType, lhsStr string, rhs compute.Datum, expStr string) {
@@ -76,7 +76,7 @@ func (c *CompareSuite) validateCompareArrScalar(op
kernels.CompareOperator, dt a
lhs.Release()
exp.Release()
}()
- c.validateCompareDatum(op, &compute.ArrayDatum{lhs.Data()}, rhs,
&compute.ArrayDatum{exp.Data()})
+ c.validateCompareDatum(op, &compute.ArrayDatum{Value: lhs.Data()}, rhs,
&compute.ArrayDatum{Value: exp.Data()})
}
func (c *CompareSuite) validateCompareScalarArr(op kernels.CompareOperator, dt
arrow.DataType, lhs compute.Datum, rhsStr string, expStr string) {
@@ -88,7 +88,7 @@ func (c *CompareSuite) validateCompareScalarArr(op
kernels.CompareOperator, dt a
rhs.Release()
exp.Release()
}()
- c.validateCompareDatum(op, lhs, &compute.ArrayDatum{rhs.Data()},
&compute.ArrayDatum{exp.Data()})
+ c.validateCompareDatum(op, lhs, &compute.ArrayDatum{Value: rhs.Data()},
&compute.ArrayDatum{Value: exp.Data()})
}
func slowCompare[T arrow.NumericType | string](op kernels.CompareOperator,
lhs, rhs T) bool {
@@ -552,14 +552,14 @@ func (c *CompareTimestampSuite) TestDiffParams() {
exp := c.getArr(arrow.FixedWidthTypes.Boolean, op.exp)
defer exp.Release()
- expected := &compute.ArrayDatum{exp.Data()}
+ expected := &compute.ArrayDatum{Value: exp.Data()}
c.Run("diff units", func() {
lhs := c.getArr(&arrow.TimestampType{Unit:
arrow.Second}, lhsJSON)
defer lhs.Release()
rhs := c.getArr(&arrow.TimestampType{Unit:
arrow.Millisecond}, rhsJSON)
defer rhs.Release()
- checkScalarBinary(c.T(), op.fn,
&compute.ArrayDatum{lhs.Data()}, &compute.ArrayDatum{rhs.Data()}, expected, nil)
+ checkScalarBinary(c.T(), op.fn,
&compute.ArrayDatum{Value: lhs.Data()}, &compute.ArrayDatum{Value: rhs.Data()},
expected, nil)
})
c.Run("diff time zones", func() {
lhs := c.getArr(&arrow.TimestampType{Unit:
arrow.Second, TimeZone: "America/New_York"}, zonedLHSJSON)
@@ -567,7 +567,7 @@ func (c *CompareTimestampSuite) TestDiffParams() {
rhs := c.getArr(&arrow.TimestampType{Unit:
arrow.Second, TimeZone: "America/Phoenix"}, zonedRHSJSON)
defer rhs.Release()
- checkScalarBinary(c.T(), op.fn,
&compute.ArrayDatum{lhs.Data()}, &compute.ArrayDatum{rhs.Data()}, expected, nil)
+ checkScalarBinary(c.T(), op.fn,
&compute.ArrayDatum{Value: lhs.Data()}, &compute.ArrayDatum{Value: rhs.Data()},
expected, nil)
})
c.Run("diff time zones and units", func() {
cases := []struct {
@@ -581,7 +581,7 @@ func (c *CompareTimestampSuite) TestDiffParams() {
lhs :=
c.getArr(&arrow.TimestampType{Unit: arrow.Second, TimeZone: tc.lhsZone},
zonedLHSJSON)
rhs :=
c.getArr(&arrow.TimestampType{Unit: arrow.Millisecond, TimeZone: tc.rhsZone},
zonedRHSJSON)
- checkScalarBinary(c.T(), op.fn,
&compute.ArrayDatum{lhs.Data()}, &compute.ArrayDatum{rhs.Data()}, expected, nil)
+ checkScalarBinary(c.T(), op.fn,
&compute.ArrayDatum{Value: lhs.Data()}, &compute.ArrayDatum{Value: rhs.Data()},
expected, nil)
lhs.Release()
rhs.Release()
}
@@ -592,7 +592,7 @@ func (c *CompareTimestampSuite) TestDiffParams() {
rhs := c.getArr(&arrow.TimestampType{Unit:
arrow.Second, TimeZone: "America/Phoenix"}, zonedRHSJSON)
defer rhs.Release()
- _, err := compute.CallFunction(c.ctx, op.fn,
nil, &compute.ArrayDatum{lhs.Data()}, &compute.ArrayDatum{rhs.Data()})
+ _, err := compute.CallFunction(c.ctx, op.fn,
nil, &compute.ArrayDatum{Value: lhs.Data()}, &compute.ArrayDatum{Value:
rhs.Data()})
c.ErrorIs(err, arrow.ErrInvalid)
c.ErrorContains(err, "cannot compare timestamp
with timezone to timestamp without timezone")
@@ -601,7 +601,7 @@ func (c *CompareTimestampSuite) TestDiffParams() {
rhs = c.getArr(&arrow.TimestampType{Unit:
arrow.Second}, rhsJSON)
defer rhs.Release()
- _, err = compute.CallFunction(c.ctx, op.fn,
nil, &compute.ArrayDatum{lhs.Data()}, &compute.ArrayDatum{rhs.Data()})
+ _, err = compute.CallFunction(c.ctx, op.fn,
nil, &compute.ArrayDatum{Value: lhs.Data()}, &compute.ArrayDatum{Value:
rhs.Data()})
c.ErrorIs(err, arrow.ErrInvalid)
c.ErrorContains(err, "cannot compare timestamp
with timezone to timestamp without timezone")
})
@@ -628,7 +628,7 @@ func (c *CompareTimestampSuite) TestDiffParams() {
for _, tc := range cases {
lhs := c.getArr(tc.lhsType, tc.lhsValue)
rhs := c.getArr(tc.rhsType, tc.rhsValue)
- _, err := compute.CallFunction(c.ctx,
op.fn, nil, &compute.ArrayDatum{lhs.Data()}, &compute.ArrayDatum{rhs.Data()})
+ _, err := compute.CallFunction(c.ctx,
op.fn, nil, &compute.ArrayDatum{Value: lhs.Data()}, &compute.ArrayDatum{Value:
rhs.Data()})
lhs.Release()
rhs.Release()
@@ -668,8 +668,8 @@ func (c *CompareTimestampSuite) TestScalarArray() {
defer flipExpected.Release()
cases := []struct{ side1, side2, expected compute.Datum }{
- {compute.NewDatum(scalarSide),
&compute.ArrayDatum{arraySide.Data()}, &compute.ArrayDatum{expected.Data()}},
- {&compute.ArrayDatum{arraySide.Data()},
compute.NewDatum(scalarSide), &compute.ArrayDatum{flipExpected.Data()}},
+ {compute.NewDatum(scalarSide),
&compute.ArrayDatum{Value: arraySide.Data()}, &compute.ArrayDatum{Value:
expected.Data()}},
+ {&compute.ArrayDatum{Value: arraySide.Data()},
compute.NewDatum(scalarSide), &compute.ArrayDatum{Value: flipExpected.Data()}},
}
for _, arrCase := range cases {
@@ -731,9 +731,9 @@ func (c *CompareDecimalSuite) TestArrayScalar() {
lhsIntLikeArr.Release()
}()
- lhs := &compute.ArrayDatum{lhsArr.Data()}
- lhsFloat := &compute.ArrayDatum{lhsFloatArr.Data()}
- lhsIntLike := &compute.ArrayDatum{lhsIntLikeArr.Data()}
+ lhs := &compute.ArrayDatum{Value: lhsArr.Data()}
+ lhsFloat := &compute.ArrayDatum{Value:
lhsFloatArr.Data()}
+ lhsIntLike := &compute.ArrayDatum{Value:
lhsIntLikeArr.Data()}
rhs, _ := scalar.MakeScalarParam("1.23", ty)
rhsFloat := scalar.MakeScalar(float64(1.23))
@@ -742,7 +742,7 @@ func (c *CompareDecimalSuite) TestArrayScalar() {
c.Run(tc.fn, func() {
exp :=
c.getArr(arrow.FixedWidthTypes.Boolean, tc.exp)
defer exp.Release()
- expected :=
&compute.ArrayDatum{exp.Data()}
+ expected := &compute.ArrayDatum{Value:
exp.Data()}
checkScalarBinary(c.T(), tc.fn, lhs,
compute.NewDatum(rhs), expected, nil)
checkScalarBinary(c.T(), tc.fn,
lhsFloat, compute.NewDatum(rhs), expected, nil)
@@ -777,9 +777,9 @@ func (c *CompareDecimalSuite) TestScalarArray() {
rhsIntLikeArr.Release()
}()
- rhs := &compute.ArrayDatum{rhsArr.Data()}
- rhsFloat := &compute.ArrayDatum{rhsFloatArr.Data()}
- rhsIntLike := &compute.ArrayDatum{rhsIntLikeArr.Data()}
+ rhs := &compute.ArrayDatum{Value: rhsArr.Data()}
+ rhsFloat := &compute.ArrayDatum{Value:
rhsFloatArr.Data()}
+ rhsIntLike := &compute.ArrayDatum{Value:
rhsIntLikeArr.Data()}
lhs, _ := scalar.MakeScalarParam("1.23", ty)
lhsFloat := scalar.MakeScalar(float64(1.23))
@@ -788,7 +788,7 @@ func (c *CompareDecimalSuite) TestScalarArray() {
c.Run(tc.fn, func() {
exp :=
c.getArr(arrow.FixedWidthTypes.Boolean, tc.exp)
defer exp.Release()
- expected :=
&compute.ArrayDatum{exp.Data()}
+ expected := &compute.ArrayDatum{Value:
exp.Data()}
checkScalarBinary(c.T(), tc.fn,
compute.NewDatum(lhs), rhs, expected, nil)
checkScalarBinary(c.T(), tc.fn,
compute.NewDatum(lhs), rhsFloat, expected, nil)
@@ -823,9 +823,9 @@ func (c *CompareDecimalSuite) TestArrayArray() {
lhsIntLikeArr.Release()
}()
- lhs := &compute.ArrayDatum{lhsArr.Data()}
- lhsFloat := &compute.ArrayDatum{lhsFloatArr.Data()}
- lhsIntLike := &compute.ArrayDatum{lhsIntLikeArr.Data()}
+ lhs := &compute.ArrayDatum{Value: lhsArr.Data()}
+ lhsFloat := &compute.ArrayDatum{Value:
lhsFloatArr.Data()}
+ lhsIntLike := &compute.ArrayDatum{Value:
lhsIntLikeArr.Data()}
rhsArr := c.getArr(ty, `["1.23", "2.34", "1.23",
"-1.23", "1.23", "-1.23", null, "1.23"]`)
rhsFloatArr := c.getArr(arrow.PrimitiveTypes.Float64,
`[1.23, 2.34, 1.23, -1.23, 1.23, -1.23, null, 1.23]`)
@@ -836,9 +836,9 @@ func (c *CompareDecimalSuite) TestArrayArray() {
rhsIntArr.Release()
}()
- rhs := &compute.ArrayDatum{rhsArr.Data()}
- rhsFloat := &compute.ArrayDatum{rhsFloatArr.Data()}
- rhsInt := &compute.ArrayDatum{rhsIntArr.Data()}
+ rhs := &compute.ArrayDatum{Value: rhsArr.Data()}
+ rhsFloat := &compute.ArrayDatum{Value:
rhsFloatArr.Data()}
+ rhsInt := &compute.ArrayDatum{Value: rhsIntArr.Data()}
empty := c.getArr(ty, `[]`)
emptyExp := c.getArr(arrow.FixedWidthTypes.Boolean,
`[]`)
@@ -855,12 +855,12 @@ func (c *CompareDecimalSuite) TestArrayArray() {
c.Run(tc.fn, func() {
exp :=
c.getArr(arrow.FixedWidthTypes.Boolean, tc.exp)
defer exp.Release()
- expected :=
&compute.ArrayDatum{exp.Data()}
+ expected := &compute.ArrayDatum{Value:
exp.Data()}
- checkScalarBinary(c.T(), tc.fn,
&compute.ArrayDatum{empty.Data()},
-
&compute.ArrayDatum{empty.Data()}, &compute.ArrayDatum{emptyExp.Data()}, nil)
- checkScalarBinary(c.T(), tc.fn,
&compute.ArrayDatum{null.Data()},
-
&compute.ArrayDatum{null.Data()}, &compute.ArrayDatum{nullExp.Data()}, nil)
+ checkScalarBinary(c.T(), tc.fn,
&compute.ArrayDatum{Value: empty.Data()},
+ &compute.ArrayDatum{Value:
empty.Data()}, &compute.ArrayDatum{Value: emptyExp.Data()}, nil)
+ checkScalarBinary(c.T(), tc.fn,
&compute.ArrayDatum{Value: null.Data()},
+ &compute.ArrayDatum{Value:
null.Data()}, &compute.ArrayDatum{Value: nullExp.Data()}, nil)
checkScalarBinary(c.T(), tc.fn, lhs,
rhs, expected, nil)
checkScalarBinary(c.T(), tc.fn,
lhsFloat, rhs, expected, nil)
checkScalarBinary(c.T(), tc.fn, lhs,
rhsFloat, expected, nil)
@@ -893,14 +893,14 @@ func (c *CompareDecimalSuite) TestDiffParams() {
rhsArr.Release()
}()
- lhs := &compute.ArrayDatum{lhsArr.Data()}
- rhs := &compute.ArrayDatum{rhsArr.Data()}
+ lhs := &compute.ArrayDatum{Value: lhsArr.Data()}
+ rhs := &compute.ArrayDatum{Value: rhsArr.Data()}
for _, tc := range cases {
c.Run(tc.fn, func() {
exp :=
c.getArr(arrow.FixedWidthTypes.Boolean, tc.exp)
defer exp.Release()
- expected :=
&compute.ArrayDatum{exp.Data()}
+ expected := &compute.ArrayDatum{Value:
exp.Data()}
checkScalarBinary(c.T(), tc.fn, lhs,
rhs, expected, nil)
})
@@ -999,15 +999,15 @@ func (c *CompareFixedSizeBinary) TestArrayScalar() {
exp := c.getArr(arrow.FixedWidthTypes.Boolean,
op.exp[tc.resultIdx])
defer exp.Release()
- expected := &compute.ArrayDatum{exp.Data()}
+ expected := &compute.ArrayDatum{Value:
exp.Data()}
null := c.getArr(tc.lhsType, `[null]`)
defer null.Release()
scNull := scalar.MakeNullScalar(tc.rhsType)
- checkScalarBinary(c.T(), op.fn,
&compute.ArrayDatum{null.Data()}, compute.NewDatum(scNull),
- &compute.ArrayDatum{expNull.Data()},
nil)
- checkScalarBinary(c.T(), op.fn,
&compute.ArrayDatum{lhs.Data()},
+ checkScalarBinary(c.T(), op.fn,
&compute.ArrayDatum{Value: null.Data()}, compute.NewDatum(scNull),
+ &compute.ArrayDatum{Value:
expNull.Data()}, nil)
+ checkScalarBinary(c.T(), op.fn,
&compute.ArrayDatum{Value: lhs.Data()},
compute.NewDatum(rhs), expected, nil)
}
})
@@ -1094,16 +1094,16 @@ func (c *CompareFixedSizeBinary) TestScalarArray() {
exp := c.getArr(arrow.FixedWidthTypes.Boolean,
op.exp[tc.resultIdx])
defer exp.Release()
- expected := &compute.ArrayDatum{exp.Data()}
+ expected := &compute.ArrayDatum{Value:
exp.Data()}
null := c.getArr(tc.rhsType, `[null]`)
defer null.Release()
scNull := scalar.MakeNullScalar(tc.lhsType)
- checkScalarBinary(c.T(), op.fn,
compute.NewDatum(scNull), &compute.ArrayDatum{null.Data()},
- &compute.ArrayDatum{expNull.Data()},
nil)
+ checkScalarBinary(c.T(), op.fn,
compute.NewDatum(scNull), &compute.ArrayDatum{Value: null.Data()},
+ &compute.ArrayDatum{Value:
expNull.Data()}, nil)
checkScalarBinary(c.T(), op.fn,
compute.NewDatum(lhs),
- &compute.ArrayDatum{rhs.Data()},
expected, nil)
+ &compute.ArrayDatum{Value: rhs.Data()},
expected, nil)
}
})
}
@@ -1211,7 +1211,7 @@ func (c *CompareFixedSizeBinary) TestArrayArray() {
exp := c.getArr(arrow.FixedWidthTypes.Boolean,
op.exp[tc.resultIdx])
defer exp.Release()
- expected := &compute.ArrayDatum{exp.Data()}
+ expected := &compute.ArrayDatum{Value:
exp.Data()}
lhsEmpty := c.getArr(tc.lhsType, `[]`)
defer lhsEmpty.Release()
@@ -1222,12 +1222,12 @@ func (c *CompareFixedSizeBinary) TestArrayArray() {
rhsNull := c.getArr(tc.rhsType, `[null]`)
defer rhsNull.Release()
- checkScalarBinary(c.T(), op.fn,
&compute.ArrayDatum{lhsEmpty.Data()}, &compute.ArrayDatum{rhsEmpty.Data()},
- &compute.ArrayDatum{expEmpty.Data()},
nil)
- checkScalarBinary(c.T(), op.fn,
&compute.ArrayDatum{lhsNull.Data()}, &compute.ArrayDatum{rhsNull.Data()},
- &compute.ArrayDatum{expNull.Data()},
nil)
- checkScalarBinary(c.T(), op.fn,
&compute.ArrayDatum{lhs.Data()},
- &compute.ArrayDatum{rhs.Data()},
expected, nil)
+ checkScalarBinary(c.T(), op.fn,
&compute.ArrayDatum{Value: lhsEmpty.Data()}, &compute.ArrayDatum{Value:
rhsEmpty.Data()},
+ &compute.ArrayDatum{Value:
expEmpty.Data()}, nil)
+ checkScalarBinary(c.T(), op.fn,
&compute.ArrayDatum{Value: lhsNull.Data()}, &compute.ArrayDatum{Value:
rhsNull.Data()},
+ &compute.ArrayDatum{Value:
expNull.Data()}, nil)
+ checkScalarBinary(c.T(), op.fn,
&compute.ArrayDatum{Value: lhs.Data()},
+ &compute.ArrayDatum{Value: rhs.Data()},
expected, nil)
}
})
}
@@ -1298,8 +1298,8 @@ func (c *CompareStringSuite)
TestRandomCompareArrayArray() {
defer rhs.Release()
c.validateCompareComputed(op,
-
&compute.ArrayDatum{lhs.Data()},
-
&compute.ArrayDatum{rhs.Data()})
+
&compute.ArrayDatum{Value: lhs.Data()},
+
&compute.ArrayDatum{Value: rhs.Data()})
})
}
})
diff --git a/arrow/compute/vector_selection_test.go
b/arrow/compute/vector_selection_test.go
index 00fa4f91..91160f4c 100644
--- a/arrow/compute/vector_selection_test.go
+++ b/arrow/compute/vector_selection_test.go
@@ -1583,7 +1583,7 @@ func (tk *TakeKernelTestChunked) takeWithArray(dt
arrow.DataType, values []strin
tk.Require().NoError(err)
defer indicesArr.Release()
- result, err := compute.Take(context.TODO(),
*compute.DefaultTakeOptions(), &compute.ChunkedDatum{chunked},
&compute.ArrayDatum{indicesArr.Data()})
+ result, err := compute.Take(context.TODO(),
*compute.DefaultTakeOptions(), &compute.ChunkedDatum{Value: chunked},
&compute.ArrayDatum{Value: indicesArr.Data()})
if err != nil {
return nil, err
}
@@ -1600,7 +1600,7 @@ func (tk *TakeKernelTestChunked) takeWithChunked(dt
arrow.DataType, values, indi
tk.Require().NoError(err)
defer chunkedIndices.Release()
- result, err := compute.Take(context.TODO(),
*compute.DefaultTakeOptions(), &compute.ChunkedDatum{chunked},
&compute.ChunkedDatum{chunkedIndices})
+ result, err := compute.Take(context.TODO(),
*compute.DefaultTakeOptions(), &compute.ChunkedDatum{Value: chunked},
&compute.ChunkedDatum{Value: chunkedIndices})
if err != nil {
return nil, err
}
@@ -2375,7 +2375,7 @@ func BenchmarkTakeDictionary(b *testing.B) {
b.ReportMetric(float64(bm.numRows), "rows/sec")
b.ResetTimer()
for i := 0; i < b.N; i++ {
- result, err := compute.Take(ctx,
*compute.DefaultTakeOptions(), &compute.ArrayDatum{values.Data()},
&compute.ArrayDatum{takeIndices.Data()})
+ result, err := compute.Take(ctx,
*compute.DefaultTakeOptions(), &compute.ArrayDatum{Value: values.Data()},
&compute.ArrayDatum{Value: takeIndices.Data()})
if err != nil {
b.Fatal(err)
}