Allow any valid SQL query to be used as a table in a s-string
メンテナーはふだん 3 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 初心者へのやさしさ
- 38/100
調査の方向性
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.
索引モデルが issue の本文から書いたものです。
説明
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!
- 主要言語
- Rust
- スター
- 10.9k
- フォーク
- 261
- 平均マージ
- 3日 20時間
- マージ済み PR(30日)
- 85
環境構築
このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
PRQL/prql のほかの issue
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
メンテナーはふだん 3 日以内に返信
-
prqlc Debug Report HTML Does Not Escape Source File Name, Enabling Stored XSS via PRQLC_DEBUG_LOGオープンbug
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
メンテナーはふだん 3 日以内に返信
-
friendliness integrations
難易度 2/5 1〜3時間 初心者へのやさしさ 64/100
PRQL/prql#1636 · コメント 2 件 · リアクション 2 件 ·
メンテナーはふだん 3 日以内に返信
-
tend-rate-limit
難易度 5/5 1週間以上 初心者へのやさしさ 4/100
メンテナーはふだん 3 日以内に返信
-
難易度 4/5 1〜2日 初心者へのやさしさ 12/100
メンテナーはふだん 3 日以内に返信
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
libnativeapi/nativeapi#21 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
longbridge/nsh#804 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
メンテナーはふだん 1 日以内に返信