Skip to content

docs(compute): attach the NewDatumWithoutOwning doc comment and say what Release does to it - #1320

Merged
zeroshade merged 2 commits into
apache:mainfrom
singhpratech:docs-compute-datum-without-owning
Sep 21, 2026
Merged

zeroshade merged 2 commits into
apache:mainfrom
singhpratech:docs-compute-datum-without-owning

Conversation

@singhpratech

Copy link
Copy Markdown
Contributor

Rationale for this change

The comment above NewDatumWithoutOwning is separated from the declaration by a blank line, so
go doc and pkg.go.dev show the function with no documentation at all. The text itself has a
sentence with no main clause and ends in stray characters (convenience function.+-). The
function's one hazard, a Release call that releases the caller's reference (#1298), is the thing
a reader most needs to see and currently cannot.

What changes are included in this PR?

The comment now sits on the declaration and states the contract: the returned Datum owns nothing,
the caller keeps the value alive for as long as the Datum is in use and must not call Release on
it, and since the Datum is an ordinary ArrayDatum/ChunkedDatum/RecordDatum/TableDatum/
ScalarDatum, a Release call compiles and releases the caller's reference, which with a C-backed
allocator or cdata-imported buffers frees memory under a live value. It ends by pointing at
NewDatum for the owning case.

Are these changes tested?

Documentation only. go doc ./arrow/compute NewDatumWithoutOwning renders the two paragraphs;
gofmt and go vet ./arrow/compute/ are clean.

Are there any user-facing changes?

Documentation only. Whether a non-owning Datum should refuse Release (a no-op, a distinct
type, or a panic) is a separate decision and stays with #1298; this change does not close it.

…hat Release does to it

The comment above NewDatumWithoutOwning was separated from the declaration
by a blank line, so go doc and pkg.go.dev show the function with no
documentation at all. The text itself had a broken sentence and ended in
stray characters ("convenience function.+-").

The comment now sits on the declaration and states the contract: the
Datum owns nothing, the caller keeps the value alive and must not call
Release on the Datum, and a Release call releases the caller's reference,
which with a C-backed allocator or cdata-imported buffers frees memory
under a live value.

Documentation only. Whether a non-owning Datum should refuse Release is
left to apache#1298.
singhpratech added a commit to singhpratech/ArrowMetal that referenced this pull request Sep 17, 2026

@zeroshade zeroshade left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The proposed ownership rule is not correct for every accepted call pattern. NewDatumWithoutOwning does not add a reference, but that does not imply callers must never release the returned Datum.

arrow/compute/exprs/exec.go currently returns compute.NewDatumWithoutOwning(scalar.NewMapScalar(kvArr)). That releasable scalar is created inline, so the Datum is its only surviving handle; not releasing it leaks the scalar's retained Arrow data. ScalarDatum.Release delegates to the wrapped scalar's Release, and downstream expression evaluation currently releases these returned Datums.

Please describe the actual contract: no reference is added, and Datum.Release consumes the supplied reference. Borrowed inputs must remain owned and alive elsewhere; ownership-transferred temporaries must eventually be released through the Datum. Alternatively, forbid temporaries and update the existing caller.

singhpratech added a commit to singhpratech/ArrowMetal that referenced this pull request Sep 21, 2026
…ract is a consumed reference, not a forbidden release
…e; Release consumes it

Review feedback: the first version said a caller must never release the
returned Datum, which is wrong for a value created for the Datum. The
expressions package wraps a scalar it builds inline, so that Datum is the
only surviving handle and must be released through it, and NewDatum itself
retains a Releasable and hands the new reference to this function.

The comment now states the contract: no reference is added, Release
consumes the supplied reference, a borrowed value stays owned and alive
elsewhere and is never released through the Datum, a transferred temporary
is released through the Datum.
@singhpratech

Copy link
Copy Markdown
Contributor Author

Yes, you're right, thanks. I'd looked at the datum types and their Release methods but not at who calls this, and the inline NewMapScalar in exec.go is exactly what the comment said you couldn't do. I've rewritten it along the lines you describe: no reference is added and Release consumes the one you passed in, so a borrowed value has to stay alive elsewhere and shouldn't be released through the Datum, while a temporary created for the Datum has to be. I also mention that NewDatum itself does the second thing.

I had a look at the other callers too. The sort and cumulative entry points borrow, as does the set-lookup value set; NewDatum and the map literal transfer. Both are in use, so describing the contract seemed better than forbidding temporaries.

singhpratech added a commit to singhpratech/ArrowMetal that referenced this pull request Sep 21, 2026

@zeroshade zeroshade left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the rewrite — this addresses my earlier comment.

The contract is now stated correctly: no retain, and Datum.Release consumes the reference the caller supplied. Describing the two call patterns rather than forbidding temporaries is the right call, since both are in use. I checked the callers and it matches: the sort entry points, safeCastScalar, the set-lookup value set in exprs/types.go, and the tests all borrow; exprs/exec.go's inline NewMapScalar and NewDatum's scalar.Releasable branch transfer. The pointer back at NewDatum is accurate — it retains and hands the new reference to this function.

Also confirms clean: comment is attached to the declaration so go doc renders it, the stray convenience function.+- is gone, and gofmt/go vet ./arrow/compute/ pass on the PR head.

One nit, not worth another round: ScalarDatum.Release type-asserts releasable and is a no-op otherwise, so "whose Release calls the wrapped value's Release" is a touch stronger than the code for a non-releasable scalar. The guidance it supports is still correct.

Agreed that whether a non-owning Datum should refuse Release stays with #1298.

singhpratech added a commit to singhpratech/ArrowMetal that referenced this pull request Sep 21, 2026
@zeroshade
zeroshade merged commit 6f2e895 into apache:main Sep 21, 2026
23 checks passed
singhpratech added a commit to singhpratech/ArrowMetal that referenced this pull request Sep 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants