Skip to content

Declarative function signatures - #3775

Closed
alexey-milovidov wants to merge 47 commits into
masterfrom
function-signatures
Closed

alexey-milovidov wants to merge 47 commits into
masterfrom
function-signatures

Conversation

@alexey-milovidov

Copy link
Copy Markdown
Member

No description provided.

@alex-krash

Copy link
Copy Markdown
Contributor

@alexey-milovidov , sorry for interrupting, just wondering. Why you prefer string representation of signature instead of having a separate method/visitor pattern/whatever with explicit programmatic specification?
(I have a doubt about "primitive obsession", but just want to have Guru opinion on this stuff).

@alexey-milovidov

Copy link
Copy Markdown
Member Author

@alexey-milovidov , sorry for interrupting, just wondering. Why you prefer string representation of signature instead of having a separate method/visitor pattern/whatever with explicit programmatic specification?
(I have a doubt about "primitive obsession", but just want to have Guru opinion on this stuff).

We need declarative specification of function signatures for documentation, introspection, analysis.
The function signature must have string representation for docs.
And this representation need to be self-explanatory, even for complex functions, like this:
transform(T, const Array(T), const Array(U), U) -> U

How this signature can be specified in code?
There are several possible ways:

  • in string literal, that is parsed at runtime (1);
  • in expression consist of explicit construction of an object (2);
  • as expression template with overloaded operators (3).

1st variant is easy to write and use but not statically checked.
2nd variant is too difficult to write in code and too ugly.
3rd variant can be Ok, but is difficult to implement.

@alexey-milovidov

Copy link
Copy Markdown
Member Author

I will open another PR when the time will come.

zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
Port the experimental declarative function signature DSL from
ClickHouse#3775 onto current master.

A `FunctionSignature` is constructed from a string like:

  transform(T, const Array(T), const Array(U), U) -> U
  array(T1, ...) -> Array(leastSupertype(T1, ...))
  toFixedString(String, const N UnsignedInteger) -> FixedString(N)
  reverse(T : StringOrFixedString) -> T OR reverse(T : Array) -> T

It supports:
- type variables (T, U, ...) captured from arguments and reused;
- type matchers (UnsignedInteger, Number, StringOrFixedString,
  Array(...), Tuple(...), MaybeNullable(...), ...);
- type functions (leastSupertype, Array, FixedString, DateTime,
  difference, typeFromString, Nullable, LowCardinality,
  tuplesHaveSameSize);
- `const` arguments, captured by name so their value can drive the
  return type;
- ellipsis (...) for variadic / repeated argument groups;
- optional [...] groups;
- alternative signatures joined with OR;
- WHERE constraints over the captured variables.

The result is a single `check` call that takes
`ColumnsWithTypeAndName` and returns either the resolved return
type or an explanatory error message.

This commit only adds the DSL and unit tests under
`src/DataTypes/tests/gtest_FunctionSignature.cpp`. It does not yet
migrate any existing `getReturnTypeImpl` implementations.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
groeneai pushed a commit to groeneai/ClickHouse that referenced this pull request Oct 16, 2026
…res-2026

Declarative function signatures, continuation of ClickHouse#3775
nihalzp pushed a commit to nihalzp/ClickHouse that referenced this pull request Oct 16, 2026
Port the experimental declarative function signature DSL from
ClickHouse#3775 onto current master.

A `FunctionSignature` is constructed from a string like:

  transform(T, const Array(T), const Array(U), U) -> U
  array(T1, ...) -> Array(leastSupertype(T1, ...))
  toFixedString(String, const N UnsignedInteger) -> FixedString(N)
  reverse(T : StringOrFixedString) -> T OR reverse(T : Array) -> T

It supports:
- type variables (T, U, ...) captured from arguments and reused;
- type matchers (UnsignedInteger, Number, StringOrFixedString,
  Array(...), Tuple(...), MaybeNullable(...), ...);
- type functions (leastSupertype, Array, FixedString, DateTime,
  difference, typeFromString, Nullable, LowCardinality,
  tuplesHaveSameSize);
- `const` arguments, captured by name so their value can drive the
  return type;
- ellipsis (...) for variadic / repeated argument groups;
- optional [...] groups;
- alternative signatures joined with OR;
- WHERE constraints over the captured variables.

The result is a single `check` call that takes
`ColumnsWithTypeAndName` and returns either the resolved return
type or an explanatory error message.

This commit only adds the DSL and unit tests under
`src/DataTypes/tests/gtest_FunctionSignature.cpp`. It does not yet
migrate any existing `getReturnTypeImpl` implementations.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants