ClickHouse / ClickHouse/ClickHouse

Allow parametized views to be dynamic with optional parameters

Open
#49,661 3 comments 1 reaction 0 assignees View on GitHub
comp-view feature
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

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.