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")

Abierto
#272 2 comentarios 0 reacciones 0 asignados Ver en GitHub
question
Lenguaje dominante
Rust
Estrellas
3.5k
Forks
772
Merge medio
4 d 9 h
PR fusionados (30 d)
17

Descripción

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": []
}
}
]
```

Guía de contribución

No hay ninguna guía de contribución indexada para este repositorio

Línea de trabajo

Empieza rastreando cómo el analizador SQL representa la forma `UnnamedExpr`/`BinaryOp` y la forma `ExprWithAlias` mostradas en el JSON del issue. Define cómo deben normalizarse los alias equivalentes de SQL Server y cómo se conservaría la presentación original, y después verifica que ambos ejemplos de CREATE VIEW se serialicen de forma coherente.

Escrito por el modelo de indexación a partir del texto del issue.

Evaluación

Stack tecnológico
rust, sql
Área
compilers
Tipo de issue
Nueva funcionalidad
Dificultad
5/5
Tiempo estimado
Más de una semana
Estado de actividad
Estancado
Claridad
Bastante claro
Aptitud para principiantes
30/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.