Skip to content

Move numeric and boolean cast helpers into a private submodule - #11076

Merged
alamb merged 1 commit into
apache:mainfrom
anandghegde:extract-numeric-bool-cast-helpers
Oct 16, 2026
Merged

alamb merged 1 commit into
apache:mainfrom
anandghegde:extract-numeric-bool-cast-helpers

Conversation

@anandghegde

@anandghegde anandghegde commented Sep 13, 2026 •

Copy link
Copy Markdown
Contributor

Which issue does this PR close?

Rationale for this change

Continues splitting up cast/mod.rs.

What changes are included in this PR?

Moves the numeric and boolean cast helpers into a new cast/numeric.rs. Code is unchanged apart from pub(crate) visibility.

Are these changes tested?

Covered by existing tests.

Are there any significant user-facing changes?

No. The public helpers are re-exported, so their paths are unchanged.

@Jefffrey

Jefffrey commented Oct 2, 2026

Copy link
Copy Markdown
Contributor

could we merge up to resolve the conflict

@anandghegde

Copy link
Copy Markdown
Contributor Author

Merged main up and resolved the conflicts — upstream's infallible-cast optimization of cast_numeric_arrays (plus NumericKind/is_infallible_numeric_cast) and the from_unary rewrite of cast_numeric_to_bool now live in the numeric submodule. cargo test -p arrow-cast (417 tests), clippy and fmt are clean.

@Jefffrey

Jefffrey commented Oct 3, 2026

Copy link
Copy Markdown
Contributor

please doublecheck this PR, it seems to regress changes introduced by #11242

@anandghegde

Copy link
Copy Markdown
Contributor Author

Good catch — you're right. When relocating the bool casts into the numeric submodule during the merge-up, I took upstream's post-#11242 cast_numeric_to_bool (from_unary) but left the pre-#11242 iterator-based bool_to_numeric_cast and its NumCast bounds in place, silently reverting the word-at-a-time bit_chunks optimization.

9164cfce fixes it: bool_to_numeric_cast now matches upstream main exactly (64-bit word unpacking via BooleanArray::bit_chunks, T::Native::ONE/ZERO), and the TO::Native: NumCast bound is dropped from cast_bool_to_numeric as in #11242. single_bool_to_numeric stays — it's public API. The #11242 tests (test_cast_bool_numeric_sliced, test_cast_float_to_bool_special_values) were already present in mod.rs's test module via the merge and now exercise the optimized path. cargo test -p arrow-cast (417 tests), clippy and fmt clean.

Also double-checked the reverse direction and the other cast families in the module against upstream/main — no other stale copies.

DKER2 pushed a commit to DKER2/arrow-rs that referenced this pull request Oct 3, 2026
…he#11077)

# Which issue does this PR close?

Part of apache#11032 — the **binary, fixed-size binary and byte-view helpers**
group
only, so it does not close the issue.

Sibling PRs against the same issue: apache#11075 (temporal) and apache#11076
(numeric and
boolean). All three are independent and move disjoint functions, but
each adds a
`mod` line and an import to `mod.rs`, so whichever lands later will want
a
trivial rebase.

# Rationale for this change

`arrow-cast/src/cast/mod.rs` is ~14k lines. apache#5125 moved list, decimal,
dictionary, string, map, run-array and union support into private
submodules,
and apache#11032 lists the groups still inline. The byte-oriented conversions
are one
of them.

# What changes are included in this PR?

A new private `arrow-cast/src/cast/binary.rs` holding:

- `cast_numeric_to_binary`
- `cast_binary_to_fixed_size_binary`
- `cast_fixed_size_binary_to_binary`
- `cast_fixed_size_binary_to_binary_view`
- `cast_byte_container`
- `cast_view_to_byte`

`cast_with_options` stays the top-level dispatcher in `mod.rs`.

Worth flagging for review:

- **No public API surface is involved here.** Unlike the numeric group
in
  apache#11076, none of these six were `pub`, so `mod.rs` uses a plain
`use crate::cast::binary::*` rather than a `pub use`. All six are called
from
the dispatcher, so all six became `pub(crate)` and nothing stayed
private.
- **`cast_numeric_to_binary` is not adjacent to the rest.** It sits up
with the
numeric helpers in `mod.rs` rather than with the other byte conversions,
but
  it belongs to this group, so it is moved from there.
- Three imports left orphaned in `mod.rs` by the move are dropped:
`arrow_data::ByteView`, and `Buffer` from the `arrow_buffer` import
list.

# Are these changes tested?

Covered by the existing `arrow-cast` tests — this is a code move, so no
new
tests are warranted and no existing test was modified.

```
cargo test -p arrow-cast     379 passed + 12 passed, 0 failed (same as base)
cargo clippy -p arrow-cast --all-targets -- -D warnings   clean
cargo fmt -p arrow-cast -- --check                        clean
cargo build -p arrow                                      builds
```

As with the sibling PRs, the faithfulness of the move is checked
mechanically
rather than by eye: extracting the two original line ranges from `HEAD`
and
normalising away the added `pub(crate)` gives a **byte-identical** match
against
the new file.

Run on macOS 26.6.2, aarch64-apple-darwin, toolchain 1.98.1 from
`rust-toolchain.toml`.

# Are there any user-facing changes?

No. No public API change and no behavioural change.

# AI usage disclosure

Written with AI assistance (Claude). The AI performed the mechanical
extraction
and ran the verification above; I reviewed the result and own the
change.

The moved bodies are unedited, and the byte-identity check is the
evidence for
that rather than a reading. The judgement calls — pulling
`cast_numeric_to_binary`
out of the numeric neighbourhood, the uniform `pub(crate)`, and the
three dropped
imports — are listed above because they are the parts a "pure move" diff
would
not otherwise draw attention to.
Comment thread arrow-cast/src/cast/mod.rs Outdated
use crate::cast::dictionary::*;
use crate::cast::list::*;
use crate::cast::map::*;
pub use crate::cast::numeric::*;

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.

id prefer not making it public by default, it makes it too easy to accidentally introduce a new public api

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.

Done in f93fa86: the glob pub use is gone. The numeric submodule is imported privately, and only the three helpers that were already public before the move (cast_num_to_bool, num_cast, single_bool_to_numeric) keep explicit pub use re-exports, so nothing new becomes public by default.

@Jefffrey

Jefffrey commented Oct 6, 2026

Copy link
Copy Markdown
Contributor

can i ask is there any human on the end of this? the comments seem extremely LLM, and it seems theres very little effort being put into this PR. for example, an update was made per comments, but the merge conflict was ignored and not also updated.

@anandghegde

Copy link
Copy Markdown
Contributor Author

Yes, there is a human here 🙋‍♂️ , sorry.

I opened four PRs on 13 September for issue #11032. All four move code out of
the same file, cast/mod.rs. Each merge-up then made fresh conflicts in the
other three. The result was a queue of repetitive merge work.

I handed that merge work, and some of these replies, to an AI tool. I did not
review the output before I pushed the same. That one decision caused every
problem that you found:

You spent your time on slop that i should have reviewed before pushing.

Now coming to the state of the PRs -

I did not resolve the conflicts by hand. Upstream had changed several of the
functions that move. This includes the integer-to-decimal cast optimisation and
the decimal-to-float rounding correction. A manual resolution can revert those
changes silently. So I rebuilt both extractions on the current main instead.

Both branches now only move the existing code into the new module, without changing its logic or behavior.

  • The moved text is identical to the text that came out of cast/mod.rs.
  • The only other changes are the mod lines, the use lines, and the
    visibility that the child module needs.

Going forward, i will -

  • One PR at a time when the PRs touch the same file. I will not open a
    parallel queue again.
  • I shall read every diff and every comment myself before I push or post the
    same.

Hope this clarifies. Thanks for your patience, and sorry once again for the
wasted review cycles. In case this PR has already taken more of your review time than
the change is worth, I am okay if you close it. I shall not feel bad about the same.

@alamb

alamb commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

I shall read every diff and every comment myself before I push or post the

This will be most appreciated 🙏

You spent your time on slop that i should have reviewed before pushing.

I think the point here is that the most value you can add, as an author, is to make it easy to understand your propsoed changes to others (aka us as reviewers) so we can get the changes in efficiently

The more concise / easier to understand what you are doing here the better.

For example, the details of what you had to do to resolve the merge conflict in English prose is not very helpful (how does it help us determine if we should merge this PR?)

Upstream had changed several of the
functions that move. This includes the integer-to-decimal cast optimisation and
the decimal-to-float rounding correction. A manual resolution can revert those
changes silently. So I rebuilt both extractions on the current main instead.

@github-actions github-actions Bot added the arrow-kernels Crates that transform arrow data (e.g. compute, cast) label Oct 11, 2026
@alamb

alamb commented Oct 11, 2026

Copy link
Copy Markdown
Contributor

CI appears to be failing due to a clippy problem

@anandghegde

Copy link
Copy Markdown
Contributor Author

Fixed the clippy failure. Two imports were only used by tests, so I moved them into the test module.

@alamb

alamb commented Oct 15, 2026

Copy link
Copy Markdown
Contributor
Screenshot 2026-10-15 at 3 20 26 PM Something seems wrong with this PR -- it now adds a net of 200 lines of code 🤔

@anandghegde

anandghegde commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor Author

Sorry the last merge went wrong 😟

I've reset the branch onto current main and redone the move as a single commit. It's now +206/−180

@anandghegde
anandghegde force-pushed the extract-numeric-bool-cast-helpers branch from e79270b to b96bb58 Compare October 16, 2026 12:44

@alamb alamb 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.

Thank you

@alamb
alamb added this pull request to the merge queue Oct 16, 2026
Merged via the queue into apache:main with commit 8f4bb0c Oct 16, 2026
35 of 37 checks passed
@Jefffrey Jefffrey added the development-process Internal changes; PRs with this label are excluded from changelog label Oct 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

arrow Changes to the arrow crate arrow-cast arrow-kernels Crates that transform arrow data (e.g. compute, cast) development-process Internal changes; PRs with this label are excluded from changelog

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants