zeekayandYakov Olkhovskiy 26cd4c5eba Fix THERE_IS_NO_COLUMN for optimize_rewrite_aggregate_function_with_if with distributed queries
When `RewriteAggregateFunctionWithIfPass` rewrites `sum(if(cond, val, null))`
to `sumIf(_CAST(val, 'Nullable(T)'), cond)`, the `_CAST` stays as a
FunctionNode on the initiator (no resolve pass runs after optimization).
On the remote (secondary) server, the same `_CAST` gets constant-folded
during re-resolution, producing a ConstantNode with result type
`Nullable(T)`.

The column naming function `calculateActionNodeNameWithCastIfNeeded` used
`getResultType()` for the inner type annotation, which gives `T` on the
initiator (from the pre-cast constant) but `Nullable(T)` on the remote
(from the folded result). This caused a column name mismatch:
- Initiator: `_CAST(0_UInt8, 'Nullable(UInt8)'_String)`
- Remote:    `_CAST(0_Nullable(UInt8), 'Nullable(UInt8)'_String)`

Fix: when the constant was folded from `_CAST` (`receivedFromInitiatorServer`
is true), use the source `_CAST` function's first argument type as the
inner type annotation. This mirrors how the initiator names it.

Closes: https://github.com/ClickHouse/ClickHouse/issues/82941

Co-authored-by: Yakov Olkhovskiy <[email protected]>
2026-06-10 02:59:15 +00:00
…
…
…
…
…
…
…
…
2026-06-08 23:22:00 -06:00

Website Apache 2.0 License

The ClickHouse company logo.

ClickHouse® is an open-source column-oriented database management system that allows generating analytical data reports in real-time.

How To Install (Linux, macOS, FreeBSD)

curl https://clickhouse.com/ | sh
  • Official website has a quick high-level overview of ClickHouse on the main page.
  • ClickHouse Cloud ClickHouse as a service, built by the creators and maintainers.
  • Tutorial shows how to set up and query a small ClickHouse cluster.
  • Documentation provides more in-depth information.
  • YouTube channel has a lot of content about ClickHouse in video format.
  • ClickHouse Theater contains presentations and videos about ClickHouse.
  • Slack and Telegram allow chatting with ClickHouse users in real-time.
  • Blog contains various ClickHouse-related articles, as well as announcements and reports about events.
  • Bluesky and X for short news.
  • Code Browser (github.dev) with syntax highlighting, powered by github.dev.
  • Contacts can help to get your questions answered if there are any.

Monthly Release & Community Call

Join us for the ClickHouse 26.5 Release Call on May 21, 2026.

Watch all release presentations and videos at ClickHouse Theater and YouTube Playlist.

Upcoming Events

Keep an eye out for upcoming meetups and events around the world. Want to speak? Apply here You can also peruse ClickHouse Events for a list of all upcoming trainings, meetups, speaking engagements, etc.

Upcoming meetups

Recent meetups

Recent Recordings

  • Recent Meetup Videos: Meetup Playlist Whenever possible recordings of the ClickHouse Community Meetups are edited and presented as individual talks.

Interested in joining ClickHouse and making it your full-time job?

ClickHouse is a nice DBMS, and it's a good place to work.

Check out our current openings here: https://clickhouse.com/company/careers

Email: [email protected]!

S
Description
No description provided
Readme Apache-2.0 Cite this repository
8.3 GiB
Languages
C++ 70.9%
Python 12.2%
Shell 5.5%
Assembly 4.2%
C 1.8%
Other 5.2%