diffplug / diffplug/spotless

BUG: Spotless SQL DBeaver formatter produces INVALID spark sql syntax with whitespaces added inside backticks and other places

オープン
#2,250 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

bug
主要言語
Java
スター
5.7k
フォーク
561
平均マージ
1日 14時間
マージ済み PR(30日)
43

説明

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("<my-folder-with-sqls>/**/*.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

  • summary of problem
  • Gradle or Maven version
  • spotless version
  • operating system and version
  • copy-paste your full Spotless configuration block(s), and a link to a public git repo that reproduces the problem if possible
  • 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.

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

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

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

まず、示されている Gradle spotless sql/dbeaver 設定と .dbeaver.properties ファイルを使い、バッククォート、数値識別子、配列、リテラルの例で formatter の出力を再現します。gradlew spotlessApply または spotlessCheck を実行し、結果を有効な Spark SQL と比較します。MyCol.1、3p_dummy、arr[0]、0L のような構文をフォーマットによって保持し、無効な空白を導入しなければ完了です。

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

評価

技術スタック
spark, sql
領域
databases, tooling
issue の種類
バグ
難易度
4/5
見積もり時間
3〜5日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
35/100

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

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