Add KDoc and tests for ColumnAccessor.nullable() - #2065
Conversation
This commit introduces tests and comprehensive KDoc examples for the nullable ColumnAccessor API, ensuring clarity in usage. Updated KDOC_GUIDELINES.md to exclude deprecated APIs from examples and highlight proper documentation approaches.
There was a problem hiding this comment.
🟡 Changes recommended
The central KDoc overstates when null access fails and uses a nonconforming example heading.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
Documents and tests the unchecked nullable type cast for ColumnAccessor.
Changes:
- Adds detailed KDoc and usage example.
- Adds focused behavioral tests.
- Clarifies KDoc example guidelines.
File summaries
| File | Description |
|---|---|
KDOC_GUIDELINES.md |
Adds deprecated-API guidance. |
core/src/main/.../ColumnAccessorApi.kt |
Documents nullable(). |
core/src/test/.../ColumnAccessorApi.kt |
Tests documented behavior. |
Review details
- Files reviewed: 3/3 changed files
- Comments generated: 3
- Review effort level: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
There was a problem hiding this comment.
Thanks for the careful write-up — one blocking point on the new tests to sort out before this goes in.
Produced by Air Automations. Name: AI Review / Run: https://air.jetbrains.cloud/org/05cf1a7f-6ab5-713b-abd3-29d0c8a05e2d/automations/8daf2412-0b6c-4433-90c0-b40ab5aebcdb?run=db5ba26f-ebda-4080-aa9b-8d5bf5d64c02
There was a problem hiding this comment.
Nice, careful work — approving, with one non-blocking note inline.
Produced by Air Automations. Name: AI Review / Run: https://air.jetbrains.cloud/org/05cf1a7f-6ab5-713b-abd3-29d0c8a05e2d/automations/8daf2412-0b6c-4433-90c0-b40ab5aebcdb?run=c51059ea-f847-48aa-a1e4-3ace0dbbfef5
There was a problem hiding this comment.
Nice, careful piece of work — approving; one non-blocking note inline.
Produced by Air Automations. Name: AI Review / Run: https://air.jetbrains.cloud/org/05cf1a7f-6ab5-713b-abd3-29d0c8a05e2d/automations/8daf2412-0b6c-4433-90c0-b40ab5aebcdb?run=5b630911-72b8-4675-82ec-2f69c4dc5544
Enhanced tests and KDoc examples for the nullable `ColumnAccessor` API to improve clarity on type handling. Streamlined KDOC_GUIDELINES.md by refining deprecated API exclusion instructions.
Add KDoc for
ColumnAccessor.nullable()Closes #1996
ColumnAccessor<T>.nullable()was the only public declaration inColumnAccessorApi.ktand had no documentation at all.
The function is easy to misread as a data operation. It is a plain unchecked cast: it
returns the very same accessor object with the value type widened to
T?, looks up nocolumn and reads no value. Two things are worth knowing and were not written down anywhere:
ColumnAccessoris covariant, so aColumnAccessor<Double>is already accepted where aColumnAccessor<Double?>is expected. What the call changes is the declared type of theaccessor itself.
nullfrom the column arrives as anullin the non-nullable typeTand only fails later, at the first use of the value. That is the reason the functionexists, so the KDoc now says it.
Files
core/.../api/ColumnAccessorApi.kt— the KDoc, following the structure offirst.kt.core/.../test/.../api/ColumnAccessorApi.kt— newColumnAccessorApiTests, one test perdocumented claim.
KDOC_GUIDELINES.md— a note in the "Examples section": keep deprecated API out of KDocexamples, and where to find the deprecation constants.
Example
The example shows a
concatwith a frame that has noscorecolumn, because that is howthe nulls appear in practice. The same scenario is asserted by the test named
KDoc example nullable, so the example cannot silently rot.Tests
nullable()had no test of its own before; its only usage was incidental, inside aconcattest.
Nine tests, one per claim: the KDoc example; a
nullread through a non-nullable accessor(it returns
nulland throwsNullPointerExceptiononly at the first use); the return typeand object identity; the name and the path for a plain, a nested and a column-group
accessor; a missing column and a column without nulls; an already nullable accessor; and the
return type of
castToNullableon an accessor, which the "See also" section refers to.Where the return type is the contract, it is pinned by an explicit type annotation, so the
compiler is the assertion. All expected values are written out literally.
Open questions
Should this function be deprecated instead? Almost everything that reads through an
accessor is already
@Deprecated(DEPRECATED_ACCESS_API):df[accessor],row[accessor],accessor(),df.getColumn(accessor). The only supported reading path left isaccessor.getValue(row), which is why the example uses it. If the Column Accessors API isgoing away,
nullable()should probably go with it, and this KDoc documents an API on itsway out. Please tell me which way you want it.
inline/reifiedlook unnecessary.cast()here resolves to the non-reifiedColumnAccessor<*>.cast(), and a plainfun <T> ColumnAccessor<T>.nullable()compilesfine, call sites included. I left the signature untouched, because it is public and out of
scope for a KDoc issue.
@param [T]. The guidelines ask to document type parameters, so I did, but this one isfully implied by the receiver type. If we do not want such
@params, the rule inKDOC_GUIDELINES.mdshould be changed as well — today, the rule and the practice disagree(16 uses across
api/).