feature request / tracking issue: parameterized views

Đang mở
#6,181 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 4 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
5/5
Thời gian dự kiến
Hơn một tuần
Mức phù hợp với người mới
18/100
Loại issue
Tính năng
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
python, sql
Lĩnh vực
data, databases

Hướng nghiên cứu

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.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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?

Ngôn ngữ chính
Python
Star
3.3k
Fork
471
Merge trung bình
6 ngày 7 giờ
Pull request đã merge (30 ngày)
35

Chuẩn bị môi trường

Mở trong Codespaces

Khởi chạy dev container của dự án ngay trên trình duyệt, bằng tài khoản GitHub của bạn.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của SQLMesh/sqlmesh

Tất cả issue của SQLMesh/sqlmesh

Issue tương tự

Thêm issue về Python

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.