ClickHouse / ClickHouse/ClickHouse
Allow parametized views to be dynamic with optional parameters
- Dominant language
- C++
- Stars
- 49.9k
- Forks
- 9k
- Avg merge
- 21h 32m
- Merged PRs (30d)
- 515
Description
Currently we have to construct views with static parameters if we want to reuse them across many filters e.g.
```
CREATE VIEW sold_by_duration AS
SELECT
duration,
count() AS value
FROM default.uk_price_paid
WHERE ((postcode1 = {_postcode:String}) OR (district = {_district:String}) OR (town = {_town:String}))
GROUP BY duration
SELECT *
FROM sold_by_duration(_postcode = 'SL4', _district = 'X', _town = 'X')
```
Proposal is to allow a column name to be passed e.g.
```
CREATE VIEW sold_by_duration AS
SELECT
duration,
count() AS value
FROM default.uk_price_paid
WHERE _column:Column = {_value:String}
GROUP BY duration
SELECT *
FROM sold_by_duration(_column = 'postcode1', _value = 'SL4')
```
Alternative and maybe complementary is to allow parameters to be optional - they will in turn be optimized away. This is more challenging obviously i.e.
```
SELECT *
FROM sold_by_duration(_postcode = 'SL4')
becomes
SELECT
duration,
count() AS value
FROM default.uk_price_paid
WHERE postcode1 = 'SL4'
GROUP BY duration
```
Contributor guide
Assessment
This issue has not been assessed yet.