ClickHouse / ClickHouse/pg_clickhouse

Decide how to handle Aggregate function combinators

Open
#88 0 comments 0 reactions 0 assignees View on GitHub
aggregates functions interfaces pushdown sql
Dominant language
C
Stars
283
Forks
21
Avg merge
2d 6h
Merged PRs (30d)
11

Description

ClickHouse [Aggregate function combinators](https://clickhouse.com/docs/sql-reference/aggregate-functions/combinators) allow users to append suffixes to aggregate functions to change behaviors. pg_clickhouse does this some automatically already:

* To convert filtered aggregates to `addNameIf()`
* To append `Merge` to aggregates on `AggregateFunction` columns

ClickHouse also provides similar combinators for regular functions, as in [type conversion functions](https://clickhouse.com/docs/sql-reference/functions/type-conversion-functions) each having `OrNull`, `OrDefault`, and `OrZero` variants.

It would be nice not to have to implement all of these variants in pg_clickhouse. Would it be possible to somehow annotate them in some other way, in SQL, such that they could be recognized and applied (if they're not automatically applied for some other reason)? Some random ideas:

* Provide functions just for the combinators, e.g., `orZero()`, so they could be called as `orZero(toUInt8())`. Downsides: Need variants that return every data type, and the rewriter must set a flag so the nested function can be rewritten with the combinator.
* Provide functions for each combinator that could be passed as the first argument to another function, e.g., toUInt8(orZero())`. Downside: changes the possible parameter list for every function
* Make up some syntax or use the existing syntax but then hook into the Postgres Parser to find them and to rewrite the plan nodes as appropriate. Postgres won't recognize `toUInt8OrNull()` if only `toUInt8()` is defined, but perhaps we can hook into the parser to recognize the syntax and accept it?

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.