Skip to content

Match struct scalar casts by field name and add Hegel suites - #12340

Open
lwwmanning wants to merge 9 commits into
developfrom
wm/hegel-scalar-and-all-non-distinct
Open

lwwmanning wants to merge 9 commits into
developfrom
wm/hegel-scalar-and-all-non-distinct

Conversation

@lwwmanning

@lwwmanning lwwmanning commented Nov 29, 2026 •

Copy link
Copy Markdown
Contributor

Updates StructScalar::cast to match fields by name whenever source and target struct field names differ—reordering fields, dropping removed fields, filling added nullable fields with null, and rejecting added non-nullable fields (including recursively on null structs)—so Scalar::cast and ConstantArray::cast agree with StructArray::cast instead of silently mapping values positionally. Replaces redundant manual per-type boilerplate across vortex-array's scalar and all_non_distinct test suites with fast Hegel property tests covering nested proto roundtrips, scalar-vs-array casting, DecimalValue cross-width coherence, nullability laws, and all_non_distinct differential parity against the scalar baseline.

Behaviour change: when field-name lists differ, StructArray::cast, StructScalar::cast, and struct extension-cast validation now match repeated field names by occurrence rather than reusing the first matching source field; extra target occurrences beyond the source count are treated as added fields.

Assisted by Antigravity.

Signed-off-by: Will Manning <will@willmanning.io>
@lwwmanning lwwmanning added the changelog/fix A bug fix label Nov 29, 2026
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 29, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-29T19:24:04.092803Z 55d31c7 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@vortex-roborev-bot

vortex-roborev-bot Bot commented Nov 29, 2026 •

Copy link
Copy Markdown

roborev: Combined Review (f9e8241)

Verdict: No issues found.


Reviewers: claude-code | Synthesis: claude-code, 0s | Total: 1m33s, cost partial ~$0.72

chatgpt-codex-connector[bot]

This comment was marked as resolved.

@codspeed

codspeed Bot commented Nov 29, 2026 •

Copy link
Copy Markdown

Merging this PR will improve performance by 15.18%

Warning

vortex-data has exceeded the Hobby plan limit of 5 active contributors. Upgrade your plan or apply to the open source program by December 8, 2026 to keep using CodSpeed.

2 warnings

⚠️ Walltime results may be unreliable

Some benchmarks used the Walltime instrument outside CodSpeed Macro Runners, which can make the results inconsistent.

Learn more about Macro Runners

See affected benchmarks

⚠️ 1 benchmark is dominated by system calls

System calls cannot be simulated consistently and are left out of the measure. The reported value understates the real cost. Switch to the Walltime instrument to measure them.

Learn more about system calls

See affected benchmarks

⚡ 7 improved benchmarks
✅ 2170 untouched benchmarks
⏩ 164 skipped benchmarks1

Performance Changes

Mode Benchmark BASE HEAD Efficiency
⚡ CPU Simulation encode_primitives[u8, (2000, 2)] 119.1 µs 92.3 µs +29.09%
⚡ CPU Simulation varbinview_large 153.6 µs 131.5 µs +16.82%
⚡ CPU Simulation fsl_i32[2, 0.5] 114.9 µs 99.9 µs +15.1%
⚡ Walltime filter_avx2[80] 1.9 µs 1.7 µs +12.63%
⚡ CPU Simulation density_sweep_dense_runs[0.9] 80.9 µs 72.4 µs +11.74%
⚡ CPU Simulation filter_powerlaw_by_mostly_true[100000] 86.8 µs 78 µs +11.32%
⚡ CPU Simulation fsl_i32[16, 0.01] 23.1 µs 20.9 µs +10.59%

Tip

Curious why performance improved? Comment @codspeedbot explain why performance improved on this PR, or directly use the CodSpeed MCP with your agent.


Comparing wm/hegel-scalar-and-all-non-distinct (9604f63) with develop (fbf3f32)

Open in CodSpeed

Footnotes

  1. 164 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. ↩

@lwwmanning lwwmanning left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Posted by Claude Opus 5.5 on Will's behalf.

The cast fix matches struct_cast_fields and is the right size. Cutting about 5,300 test lines in favor of Hegel suites is welcome, but a few gaps came with it.

  • vortex-array/src/scalar/typed_view/struct_.rs line 220: the null-struct early return skips the schema check. A null {a: i32?} scalar cast to nullable {a: i32?, b: i32} returns a null, but StructArray::cast of a one-row all-null struct fails with "CAST for struct only supports added nullable fields". That is the scalar-versus-array mismatch this PR removes elsewhere. Please run the field check before the null return. Please also add a rename case with the same field count ({a, b} to {x, y}). Its result changes most, and Hegel never draws it because names are always f0 to fN.
  • vortex-array/src/scalar/tests/hegel.rs lines 491 to 550: Constant's CastReduce returns scalar.cast whenever it succeeds, so the ConstantArray comparison checks Scalar::cast against itself. The Canonical oracle skips null scalars (line 526) and accepts a scalar Ok with an array Err (line 548). The case above falls through both gaps. Please run the oracle for nulls and fail on (Ok, Err), or list the known exceptions.
  • The equality laws check reflexivity, symmetry and coherence, but not direction. An Eq that called every pair of non-null values equal would pass. The ordering-direction tests for list, FixedSizeList, extension, struct, decimal and float are gone. So are the hash tests for the ListScalar and ExtScalar impls and for nested nullability. One rstest per view with a known smaller and larger value would restore them.
  • vortex-array/src/scalar/tests/casting.rs line 229: union_nullability_casts compares with Scalar ==, which ignores nullability. So the old checks that the cast child becomes nullable Utf8 and the other child stays non-nullable I32 no longer test anything. Asserting on dtype() would fix it. test_scalar_into_nullable has the same problem.
  • Decimal and primitive exact values: the exact f64 cast became a relative tolerance of one part in 10^15 (decimal/tests.rs line 197). The I16 carry width check is gone, because DecimalValue == ignores width. From checks only the type (lines 229 to 241). Three error messages are now just is_err(). The f32 and f64 coerce-from-unsigned arms in pvalue.rs lines 610 to 640 and PValue::zero == 0 lost their tests.
  • all_non_distinct: hegel_nullable_garbage_under_nulls_ignored (tests.rs line 182) has no List case, and nothing draws equal flattened elements with different list offsets on the non-zero-copy ListView path. Those were list_nullable_ignores_garbage and list_different_lengths.
  • Proto: draw_variant_inner never nests a Variant inside a Variant, and draw_decimal_value always uses the canonical width. So the old nested-variant and non-canonical-width decimal roundtrips are lost.

Signed-off-by: Will Manning <will@spiraldb.com>
Co-Authored-By: Will Manning <will@spiraldb.com>
@devin-ai-integration

Copy link
Copy Markdown
Contributor

Addressed all findings from the Claude Opus 5.5 review and roborev in 069c99c:

  1. Null struct cast validation & renames: Scalar::cast and StructScalar::cast now run check_struct_cast_added_fields before the null-struct early return, rejecting added non-nullable target fields even for null source structs. Added regression tests for null struct casts and same-field-count renames ({a, b} -> {x, y}).
  2. Canonical cast differential oracle: hegel_scalar_cast_matches_constant_array_cast no longer skips null scalars or wildcard-ignores (Ok, Err) mismatches; only explicit known canonical-cast gaps are allowed, and (Err, Ok) panics.
  3. Nested-nullability Eq/Hash & ordering direction: Restored focused tests for nested-nullability hash invariance (Struct, List, Extension, Scalar) and directional ordering (List, FixedSizeList, Extension, Struct, Decimal, f16/f32/f64), plus nested-nullability coverage in hegel_eq_ord_hash_and_nullability_laws.
  4. DType nullability assertions: Updated union cast tests in casting.rs and the nullability law in hegel.rs to assert .dtype() directly rather than relying on Scalar::eq.
  5. Decimal & PValue coverage: Restored exact f64 assertions for scale.abs() <= 22, checked DecimalType::I16 on the carry-width test, checked both width and value for unsigned DecimalValue::from, restored out-of-range/unsupported error-message assertions, and restored PValue::zero value checks and f32/f64 unsigned-width coercion tests.
  6. all_non_distinct List & proto coverage: Added a ListViewArray arm to hegel_nullable_garbage_under_nulls_ignored, added list_different_lengths_same_flattened_elements covering non-zero-copy out-of-order offsets, enabled nested Variant generation in hegel.rs, and added widen_decimal_value for non-canonical decimal widths in hegel_proto_roundtrip.

devin-ai-integration[bot]

This comment was marked as resolved.

…ty checks

Signed-off-by: Will Manning <will@spiraldb.com>
Co-Authored-By: Will Manning <will@spiraldb.com>
devin-ai-integration[bot]

This comment was marked as resolved.

@lwwmanning lwwmanning left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Posted by Claude Opus 5.5 on Will's behalf.

Commits 069c99c and 05d00d3 resolve the earlier review. Null struct casts now check added fields. The rename, ordering, hash, union, decimal, list and proto gaps have tests. The Canonical oracle now fails when the scalar cast succeeds and the array cast fails.

One small gap remains. The check in check_struct_cast_added_fields in scalar/typed_view/struct_.rs line 330 checks only the top level. Take a null scalar of nullable struct {a: {b: i32}}, cast to nullable {a: {b: i32, c: i32}}. It passes the check and returns a null. But StructArray::cast fails on the child a, because c is a new non-nullable field.

The Hegel oracle comment at hegel.rs line 585 says it never ignores this error. The generator in draw_cast_target can draw this shape, so it is also a rare latent Hegel failure. Recursing into matched struct fields would fix it in a few lines.

05d00d3 also changes StructArray::cast to match repeated field names by occurrence. Please mention that behavior change in the description.

Signed-off-by: Will Manning <will@spiraldb.com>
Co-Authored-By: Will Manning <will@spiraldb.com>
@devin-ai-integration

Copy link
Copy Markdown
Contributor

Addressed both items in 3bbd3b5: check_struct_cast_added_fields now recurses into matched child structs (with a regression test matching Scalar::cast, ConstantArray::cast, and StructArray::cast), and the PR description now calls out the repeated-field-name occurrence matching behaviour change.

devin-ai-integration[bot]

This comment was marked as resolved.

…stant::cast

Signed-off-by: Will Manning <will@spiraldb.com>
Co-Authored-By: Will Manning <will@spiraldb.com>

@lwwmanning lwwmanning left a comment •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Posted by Claude Opus 5.5 on Will's behalf.

Commits 3bbd3b5 and 978fbea resolve my last review. check_struct_cast_added_fields now recurses into nested structs, lists and maps. Constant::cast now reports the error instead of falling back. The new test checks that the scalar cast, the constant cast and the canonical cast all fail with the same error. The description now names the change to repeated field names.

devin-ai-integration[bot]

This comment was marked as resolved.

Signed-off-by: Will Manning <will@spiraldb.com>
Co-Authored-By: Will Manning <will@spiraldb.com>
Signed-off-by: Will Manning <will@spiraldb.com>
Co-Authored-By: Will Manning <will@spiraldb.com>
vortex-roborev-bot[bot]

This comment was marked as resolved.

…tions

Signed-off-by: Will Manning <will@spiraldb.com>
Co-Authored-By: Will Manning <will@spiraldb.com>
devin-ai-integration[bot]

This comment was marked as resolved.

@robert3005 robert3005 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The duplicate-name handling preserves occurrence order. I found a performance regression in the shared mapping used by the array cast.

— Codex (OpenAI)

Signed-off-by: Will Manning <will@spiraldb.com>
Co-Authored-By: Will Manning <will@spiraldb.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

changelog/fix A bug fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants