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 个 reaction 已指派 0 人 在 GitHub 查看
question
主要语言
Rust
星标
3.5k
派生
772
平均合并
4 天 9 小时
30 天内合并 PR
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": []
}
}
]
```

贡献指南

这个仓库没有索引到贡献指南

调研方向

首先追踪 SQL 解析器如何表示 issue 的 JSON 中所示的 `UnnamedExpr`/`BinaryOp` 形式和 `ExprWithAlias` 形式。定义等价的 SQL Server 别名应如何规范化,以及如何保留原始呈现形式,然后验证两个 CREATE VIEW 示例序列化结果是否一致。

由索引模型根据 Issue 内容生成。

评估

技术栈
rust, sql
领域
compilers
Issue 类型
功能
难度
5/5
预计耗时
一周以上
活跃度
停滞
描述清晰度
基本清楚
新手友好度
30/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。