-
Notifications
You must be signed in to change notification settings - Fork 188
Description
Would you like to update sql-formatter?
Currently, dataform CLI depends on version ^2.3.3
, which is about 4 years old.
The latest version is 12.2.1
.
By updating, we can resolve the following issues related to formatting:
- Formatter breaks BQ named arguments #1070
- A fix has been merged in sql-formatter-org/sql-formatter#603. (I did it)
- Make QUALIFY behave like HAVING or WHERE when formatter is run on the code #1077
- The current version of sql-formatter can handle this.
dataform format
breaks triple-quoted strings in BigQuery #1444- This requires to fix the lexer of this repo as well. (so updating doesn't resolve this)
Handling dialects in sql-formatter
The current version of sql-formatter have a feature for "dialects" specific to different database products.
Now sql-formatter covers all SQL dialects supported warehouse by Dataform.
https://github.com/sql-formatter-org/sql-formatter/blob/master/docs/language.md
By passing a language value corresponding to the warehouse setting in Dataform to the formatter, we can expect more appropriate formatting.
But if we use the neutral default sql
that means StandardSQL, formatting for UNNEST and QUALIFY will not work well, and I think it need to refer to the warehouse value in dataform.json
.
I have also confirmed that the formatting result changes in some cases. The files under examples/formatter/
seems to assume BigQuery, so if we format as BigQuery,
- The space after
IF
,IFNULL
disappears - A space is added after
UNNEST
- A line break is added after
ALTER TABLE {name}
While sql-formatter updating brings differences in the formatting results, QUALIFY is a frequently used clause, and named arguments are broken by current formatter. The update makes the format command practical.
Could you take a look at the pull request I'm going to send here? You may use only some of the commits.