Skip to content

Add UnionVariants type and embed it in DType::Union#8703

Merged
connortsui20 merged 1 commit into
developfrom
ct/union-variants-v2
Jul 10, 2026
Merged

Add UnionVariants type and embed it in DType::Union#8703
connortsui20 merged 1 commit into
developfrom
ct/union-variants-v2

Conversation

@connortsui20

Copy link
Copy Markdown
Member

Rationale for this change

Tracking Issue: #7882

We want to make DType::Union usable. This PR has been resurrected from #7902.

What changes are included in this PR?

Replaces DType::Union(Nullability) with DType::Union(UnionVariants, Nullability). UnionVariants carries a FieldNames list, per-variant FieldDTypes, and an i8 type-id vector (supporting non-consecutive tags like [0, 5, 7] so children can be removed without renumbering).

The flatbuffer and protobuf Union schemas are extended with the names/dtypes/type_ids fields, and serde, flatbuffers, and protobuf paths are filled in with round-trip tests and nullability-constraint checks. The flatbuffer Union table uses explicit field ids so that nullable keeps the id it had before this change, keeping the schema conformant with develop.

Existing DType::Union(..) match arms that reject or skip unions are left in place, and concrete implementations will come later.

What APIs are changed? Are there any user-facing changes?

DType::Union will now have a type parameter UnionVariants.

@connortsui20 connortsui20 added the changelog/feature A new feature label Jul 9, 2026
@codspeed-hq

codspeed-hq Bot commented Jul 9, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

⚠️ Different runtime environments detected

Some benchmarks with significant performance changes were compared across different runtime environments,
which may affect the accuracy of the results.

Open the report in CodSpeed to investigate

⚡ 1 improved benchmark
❌ 4 regressed benchmarks
✅ 1625 untouched benchmarks
⏩ 42 skipped benchmarks1

Warning

Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Mode Benchmark BASE HEAD Efficiency
Simulation slice_empty_vortex 310.3 ns 368.6 ns -15.83%
Simulation rebuild_naive 91.4 µs 102.1 µs -10.46%
Simulation chunked_varbinview_opt_canonical_into[(100, 100)] 305.4 µs 340.5 µs -10.31%
Simulation encode_varbin[(1000, 512)] 190.4 µs 212 µs -10.19%
Simulation chunked_varbinview_canonical_into[(1000, 10)] 191 µs 154.6 µs +23.56%

Tip

Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.


Comparing ct/union-variants-v2 (1de4f39) with develop (a649d75)

Open in CodSpeed

Footnotes

  1. 42 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

/// assert_eq!(variants.len(), 2);
/// assert_eq!(variants.type_ids(), &[0, 1]);
/// ```
#[allow(

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

for some reason expect doesn't work here

@connortsui20 connortsui20 marked this pull request as ready for review July 9, 2026 17:32
Comment on lines +464 to +465
impl<'de> DeserializeSeed<'de> for DTypeSerde<'_, UnionVariants> {
type Value = UnionVariants;

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

this is all llm generated, I have no idea if it is correct

Replaces `DType::Union(Nullability)` with `DType::Union(UnionVariants,
Nullability)`. `UnionVariants` carries a `FieldNames` list, per-variant
`FieldDType`s, and an `i8` type-id vector (supporting non-consecutive tags
like `[0, 5, 7]` so children can be removed without renumbering).

The flatbuffer and protobuf `Union` schemas are extended with the
`names`/`dtypes`/`type_ids` fields, and serde, flatbuffers, and protobuf paths
are filled in with round-trip tests and nullability-constraint checks. The
flatbuffer `Union` table uses explicit field ids so that `nullable` keeps the
id it had before this change, keeping the schema conformant with develop.

Existing `DType::Union(..)` match arms that reject or skip unions are left in
place; concrete implementations land alongside the array work.

Signed-off-by: Connor Tsui <connor.tsui20@gmail.com>
@connortsui20 connortsui20 force-pushed the ct/union-variants-v2 branch from 93cfc14 to 1de4f39 Compare July 10, 2026 09:56
@connortsui20 connortsui20 merged commit a530b3b into develop Jul 10, 2026
72 of 74 checks passed
@connortsui20 connortsui20 deleted the ct/union-variants-v2 branch July 10, 2026 12:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

changelog/feature A new feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants