Allow any valid SQL query to be used as a table in a s-string
Maintainer thường phản hồi trong vòng 3 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 38/100
Hướng nghiên cứu
The issue points to the s-string handling in prqlc/prqlc/src/sql/gen_query.rs, around line 508. Read that code and its related tests to see how table s-strings are validated and emitted, especially the current requirement that they start with SELECT . Done means a valid SQL query, including one beginning with a CTE, can be used as a table in an s-string while existing cases remain covered.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
I was wondering if there would be an easy way to allow any valid SQL query to be used as table.
Our use case it the following: We receive a source SQL query, and its content is out of our control. We then generate a PRQL pipeline applying to this query, compile it to SQL, and execute it on a target database. We have no control over the source query, and some of them can be pretty complex, and can include CTEs. An example would be
WITH Base AS (SELECT c.company_id, cc.name AS company_name, [...] a.value::JSONB AS json_data FROM sometable AS c LEFT JOIN other_table AS cc ON cc.foo = c.baz LEFT JOIN fizz AS s ON s.wee = c.woo LEFT JOIN CROSS JOIN LATERAL (SELECT EXTRACT(YEAR FROM d.d)::INTEGER AS blah FROM generate_series(date_trunc('year', a.start_date), date_trunc('year', a.end_date), INTERVAL '1 year'), other_cte AS ([...]) SELECT * FROM other_cte
Right now, this results in an error with s-strings representing a table must start with SELECT `, which seems to originate in https://github.com/PRQL/prql/blob/main/prqlc/prqlc/src/sql/gen_query.rs#L508 .
Would there be an easy way to allow such a query to be used in an s-string in a from statement ?
from (s""" <complex_sql_query_here> """) | select {this.a, this.b, this.c}
For now, I see an escape hatch, but it seems quite hacky:
- Instead of the real SQL query, use a magic value accepted by prql, so you get a prql query like
from (s""" SELECT __MY_MAGIC_VALUE__ """) | select {this.a, this.b, this.c} - Compile to SQL
- Replace
SELECT __MY_MAGIC_VALUE__with the actual sql query in the compiled SQL - Validate and format the final string with
sqlparser
Thank you for your help and your work on prql!
- Ngôn ngữ chính
- Rust
- Star
- 10.9k
- Fork
- 261
- Merge trung bình
- 3 ngày 20 giờ
- Pull request đã merge (30 ngày)
- 85
Chuẩn bị môi trường
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.
- Không có Dockerfile hay tệp Docker Compose
- Không có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- 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.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của PRQL/prql
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
PRQL/prql#6518 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 3 ngày
-
prqlc Debug Report HTML Does Not Escape Source File Name, Enabling Stored XSS via PRQLC_DEBUG_LOGĐang mởbug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
PRQL/prql#6502 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 3 ngày
-
Add `.prql` to linguistĐang mởfriendliness integrations
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 64/100
PRQL/prql#1636 · 2 bình luận · 2 reaction ·
Maintainer thường phản hồi trong vòng 3 ngày
-
Creation allowance reachedĐang mởtend-rate-limit
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 4/100
Maintainer thường phản hồi trong vòng 3 ngày
-
Độ khó 4/5 1-2 ngày Mức phù hợp với người mới 12/100
PRQL/prql#6517 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 3 ngày
Issue tương tự
-
example
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
rust-lang-nursery/rust-cookbook#954 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 70/100
OpenZeppelin/openzeppelin-relayer#967 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
Maintainer thường phản hồi trong vòng 1 ngày
-
DecisionOutcome::label() / n_dosed(): engine-side mapping so downstream needs no wildcard armĐang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
Maintainer thường phản hồi trong vòng 1 ngày
-
src/runs.rs:1987: a missing --source-run-id now answers 400 "Source run ... does not exist", not 404Đang mởnightly-audit
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
antithesishq/snouty#602 ·
Maintainer thường phản hồi trong vòng 1 ngày