apache / apache/datafusion-sqlparser-rs

How to interprete 'B = T1.A' and 'T1.A AS B' as equivalent? (convert "UnnamedExpr" with "op": "Eq" into "ExprWithAlias")

オープン
#272 コメント 2 件 リアクション 0 件 担当者 0 名 GitHub で見る
question
主要言語
Rust
スター
3.5k
フォーク
772
平均マージ
4日 9時間
マージ済み PR(30日)
17

説明

in views mssqlserver allows 2 ways to define a columns alias. I would like to "normalize" the representation in json. I would like to have the same style in JSON for the same logic. There could be a property to indicate how this was in the original expression to not lost this information.

The best would be, if I could convert the presentation of `B = T1.A` into the presentation of `T1.A AS B`
but it would also be OK to convert `T1.C AS D` into `D = T1.C`

```sql
CREATE VIEW aaa.test01 AS SELECT B = T1.A, T1.C AS D FROM aaa.bbb AS T1
```

Serialized as JSON:
```json
[
{
"CreateView": {
"or_replace": false,
"materialized": false,
"name": [
{
"value": "aaa",
"quote_style": null
},
{
"value": "test01",
"quote_style": null
}
],
"columns": [],
"query": {
"ctes": [],
"body": {
"Select": {
"distinct": false,
"top": null,
"projection": [
{
"UnnamedExpr": {
"BinaryOp": {
"left": {
"Identifier": {
"value": "B",
"quote_style": null
}
},
"op": "Eq",
"right": {
"CompoundIdentifier": [
{
"value": "T1",
"quote_style": null
},
{
"value": "A",
"quote_style": null
}
]
}
}
}
},
{
"ExprWithAlias": {
"expr": {
"CompoundIdentifier": [
{
"value": "T1",
"quote_style": null
},
{
"value": "C",
"quote_style": null
}
]
},
"alias": {
"value": "D",
"quote_style": null
}
}
}
],
"from": [
{
"relation": {
"Table": {
"name": [
{
"value": "aaa",
"quote_style": null
},
{
"value": "bbb",
"quote_style": null
}
],
"alias": {
"name": {
"value": "T1",
"quote_style": null
},
"columns": []
},
"args": [],
"with_hints": []
}
},
"joins": []
}
],
"selection": null,
"group_by": [],
"having": null
}
},
"order_by": [],
"limit": null,
"offset": null,
"fetch": null
},
"with_options": []
}
}
]
```

コントリビューションガイド

このリポジトリのコントリビューションガイドは索引されていません

調査の方向性

まず、issue の JSON に示されている `UnnamedExpr`/`BinaryOp` 形式と `ExprWithAlias` 形式を SQL parser がどのように表現しているかを追跡します。等価な SQL Server エイリアスをどのように正規化すべきか、また元の表現をどのように保持するかを定義し、その後、両方の CREATE VIEW の例が一貫してシリアライズされることを検証します。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
rust, sql
領域
compilers
issue の種類
機能追加
難易度
5/5
見積もり時間
1週間以上
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
30/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。