BUG: Spotless SQL DBeaver formatter produces INVALID spark sql syntax with whitespaces added inside backticks and other places
Nadie ha tomado este issue todavía.
- Lenguaje dominante
- Java
- Estrellas
- 5.7k
- Forks
- 561
- Merge medio
- 1 d 14 h
- PR fusionados (30 d)
- 43
Descripción
If you are submitting a **bug**, please include the following:
Hi Team,
We have a big side-effect of using DBeaver SQL formatter within spotless "as is".
When I run this formatter on valid Spark SQL code where column name is wrapped with backtick symbol, it puts whitespaces around column name making .sql valid INVALID for spark to run within
`spark.sql("sql-query-from-file")`
It's easy to reproduce. Just create a simple SQL file within columns given below with backticks (see: Expected example) and you'll see it's formatter to "Current behavior" that is not valid syntax.
Versions:
```
Gradle v8+. No matter what version, it doesn't work!
Spotless v.6.25.0. No matter what version, it doesn't work!
```
```
spotless {
sql {
dbeaver().configFile(rootProject.file(".dbeaver.properties"))
target("/**/*.sql")
}
}
```
**.dbeaver.properties**
```
sql.formatter.keyword.case=UPPER
sql.formatter.statement.delimiter=;
sql.formatter.indent.type=space
sql.formatter.indent.size=2
```
Current behavior (formatter gives not valid spark sql):
```
` MyCol.1 ` AS MY_COLUMN_1, -- whitespace inside backticks
` MyCol.2 ` AS MY_COLUMN_2 -- whitespace inside backticks
```
Expected (valid spark sql):
```
`MyCol.1` AS MY_COLUMN_1, -- no whitespace inside backticks
`MyCol.2` AS MY_COLUMN_2 -- no whitespace inside backticks
```
UPD:
Other problems with whitespace were discovered that makes it IMPOSSIBLE to use Spotless anymore :(
- Adding spaces when we have columns wrapped with backtick `` (known and shown above)
- Adding spaces when we have columns which start with number. e.g `3p_dummy` -> `3 p_dummy`
- Adding spaces when accessing arrays in SQL. e.g `arr[0]` -> `arr [ 0 ]`
- Adding spaces to some literal columns: e.g `0L as dummy` -> `0 L as dummy`
It seem like so popular Spark SQL syntax isn't supported here. Would appreciate it addressing asap or propose a possible workaround
- [x] summary of problem
- [x] Gradle or Maven version
- [x] spotless version
- [x] operating system and version
- [x] copy-paste your full Spotless configuration block(s), and a link to a public git repo that reproduces the problem if possible
- [x] copy-paste the full content of any console errors emitted by `gradlew spotless[Apply/Check] --stacktrace`
If you're just submitting a feature request or question, no need for the above.
Guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Línea de trabajo
Comienza reproduciendo la salida del formateador con la configuración mostrada de Gradle spotless sql/dbeaver y el archivo .dbeaver.properties, utilizando los ejemplos de backtick, identificador numérico, array y literal. Ejecuta gradlew spotlessApply o spotlessCheck y compara el resultado con Spark SQL válido. Se considera terminado cuando el formateo conserva sintaxis como `MyCol.1`, 3p_dummy, arr[0] y 0L sin introducir espacios en blanco no válidos.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- spark, sql
- Área
- databases, tooling
- Tipo de issue
- Error
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Estado de actividad
- Estancado
- Claridad
- Bastante claro
- Aptitud para principiantes
- 35/100