Skip to content

Fix #80429 Logical error: SQL user defined function ... must represent lambda expression - #80431

Merged
alexey-milovidov merged 4 commits into
masterfrom
fix-udf
May 19, 2025
Merged

alexey-milovidov merged 4 commits into
masterfrom
fix-udf

Conversation

@alexey-milovidov

Copy link
Copy Markdown
Member

Changelog category (leave one):

  • Not for changelog (changelog entry is not required)

This closes #80429.

@clickhouse-gh

clickhouse-gh Bot commented May 19, 2025 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [c8beef5]

@clickhouse-gh clickhouse-gh Bot added the pr-not-for-changelog This PR should not be mentioned in the changelog label May 19, 2025
@pufit pufit self-assigned this May 19, 2025
@pufit pufit changed the title Fix #80429 Fix #80429 Logical error: SQL user defined function ... must represent lambda expression May 19, 2025
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue May 19, 2025
Merged via the queue into master with commit c81bec3 May 19, 2025
@alexey-milovidov
alexey-milovidov deleted the fix-udf branch May 19, 2025 06:19
@robot-ch-test-poll2 robot-ch-test-poll2 added the pr-synced-to-cloud The PR is synced to the cloud repo label May 19, 2025
clickgapai pushed a commit to clickgapai/ClickHouse that referenced this pull request Oct 1, 2026
`RESTORE TABLE system.functions` registers every restored definition through
`registerFunction`, whose `checkCanBeRegistered` runs `validateSQLFunction`,
the check for a new `CREATE FUNCTION`. Each time that check was tightened,
definitions stored under the older rules became unrestorable, and the first of
them aborted the whole restore:

- ClickHouse#80431 (25.6) requires the argument list to be a `tuple`, so a backup taken
  on 25.5 or earlier that holds `CREATE FUNCTION f AS lambda(identity(x), x)`
  fails on 25.6 and later with `Lambda must have valid arguments`.
- ClickHouse#120483 (master) requires the core to be a `lambda` and the tuple to have no
  parameters, so a Cloud upgrade from 26.4 failed with
  `Expected lambda expression, got: JSONExtractString((x, y), x): While
  restoring data of table system.functions`:
  ClickHouse#120483 (comment)

Loading the same definitions from disk or Keeper at startup never validates
them, so an in-place upgrade keeps them and `BACKUP` writes them out unchanged.

`restore` now passes `is_restore`, and `validateSQLFunction` then skips exactly
those two rules. The structural rules stay (the core is a function with two
arguments, the argument list holds unique identifiers, the body exists, no
self-recursion): no version accepted a definition that fails them, and the DDL
expansion in `UserDefinedSQLFunctionVisitor::tryToReplaceFunction` relies on
them without checks. `CREATE FUNCTION` is unchanged. Tables are re-created by
`RESTORE` under `LoadingStrictnessLevel::SECONDARY_CREATE`, which skips some
sanity checks for the same reason.

The new backward-compatibility test creates three such definitions and a
control on 25.3, backs them up, upgrades, and restores; it fails on master and
on 26.9.1.1629 at the first restore.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-not-for-changelog This PR should not be mentioned in the changelog pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Logical error: SQL user defined function ... must represent lambda expression

3 participants