feature request / tracking issue: parameterized views

Ouverte
#6,181 0 commentaires 0 réactions 0 personnes assignées Voir sur GitHub

Les mainteneurs répondent en général sous 4 jours

Personne n'a encore pris cette issue.

Évaluation

Difficulté
5/5
Temps estimé
Plus d'une semaine
Accessibilité débutants
18/100
Type d'issue
Fonctionnalité
Clarté
Plutôt claire
Activité
Active
Stack technique
python, sql
Domaine
data, databases

Piste de recherche

This is a design proposal, not a ready task: the author asks for feedback before implementing. Start with the ViewKind class, which the payload says already has a parameterized attribute, and the place where views are rendered for DuckDB and ClickHouse. Done would mean agreed design decisions on parameter typing, defaults and name resolution, followed by an accepted implementation plan. Wait for maintainer direction before writing code.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Description

Hey guys,

A few issues/PRs have been raised around parameterized views / duckdb macros / table-value-functions:
#5786 #4002 .

I am going to have a shot at implementing this, just touching base first.

Proposal:

Models of kind VIEW can take a parameters argument:

model (
  name = my_parameterized_view,
  kind = VIEW (
    parameters ( discount_rate Float64 )
  )
)

select
  sum(total * (1 / (1 + discount_rate)**t )) as discounted_total
from cashflows
group by all;

ViewKind in sqlmesh has a parameterized attribute that tracks this. (Materialized views work and represented internally in exactly the same way).

This then renders as an engine-specific parameterized view / etc, e.g. duckdb

create macro my_parameterized_view(discount_rate Float64)
as
select
  sum(total * (1 / (1 + discount_rate)**t )) as discounted_total
from cashflows
group by all;

or clickhouse

create view my_parameterized_view
as
select
  sum(total * (1 / (1 + {discount_rate:Float64})**t )) as discounted_total
from cashflows
group by all;

I intend to implement both Clickhouse and DuckDB - these are quite different so I'm hopeful this will prevent any engine-specific assumptions from creeping in to the general stuff.

Known gnarliness:

  • parameter typing (required, optional, not represented at all) differs widely between different DBs
  • default value support differs widely between different DBs
  • parameter name resolution / reference style differs widely between different DBs (e.g. see above, DuckDB refers to it as an identifier, Clickhouse refers to it as a parameter placeholder)
  • initial spiking shows there will be some small sqlglot work required at least

Unknown but suspected gnarliness

  • I'm not sure if sqlglot has the ability to translate between the different representations of this feature at the engine level, and personally I think it would be folly to try - this might imply some more engine-specific logic in sqlmesh as a result.
  • I suspect there are engines around that don't even put these things in a database/schema scope - i don't intend to try and fix this problem, but if such things exist they will probably block this from working in those engines

any feedback on the above before I start?

Langage dominant
Python
Étoiles
3.3k
Forks
471
Merge moyen
6 j 7 h
PR mergées (30 j)
35

Préparer son environnement

Ouvrir dans Codespaces

Lance le conteneur de développement du projet dans votre navigateur, avec votre propre compte GitHub.

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Autres issues de SQLMesh/sqlmesh

Toutes les issues de SQLMesh/sqlmesh

Issues similaires

Plus d'issues Python

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.