You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit aff8a45
Browse filesBrowse the repository at this point in the historyBrowse files
sqb format regenerated SQL from the parse tree, so any spelling the SQL
library canonicalised was written back into the user's file. In Snowflake
that renamed STARTSWITH to STARTS_WITH, which Snowflake rejects, and also
rewrote SUBSTR, TIMESTAMPDIFF and TRY_TO_DECIMAL to synonyms. The formatter's
syntax-tree check could not see this because both spellings parse to the same
node.
After generating the layout, walk the authored and generated token streams
together and write the authored text of every aligned token into the new
layout. Only whitespace, the case of unquoted words, an added AS, and dropped
optional terminators may differ; any other structural difference refuses the
format and leaves the file unchanged. The same check runs on the idempotence
pass.
On a 1,337-file Snowflake project this removes all 82 function renames, with
no new refusals.
description:"Snowflake STARTSWITH keeps its authored name",
13
+
sql:"select startswith(order_code, 'EU') as is_eu_order from orders",
14
+
expected_sql:"SELECT\n startswith(order_code, 'EU') AS is_eu_order\nFROM orders",
15
+
expected_changed:true,
16
+
},
17
+
test_types::FormatTestCase{
18
+
description:"function synonyms keep their authored names",
19
+
sql:"select SUBSTR(order_code, 1, 2) as region, TIMESTAMPDIFF(day, ordered_at, shipped_at) as days_to_ship, TRY_TO_DECIMAL(amount_text, 10, 2) as amount from orders",
20
+
expected_sql:"SELECT\n SUBSTR(order_code, 1, 2) AS region,\n TIMESTAMPDIFF(DAY, ordered_at, shipped_at) AS days_to_ship,\n TRY_TO_DECIMAL(amount_text, 10, 2) AS amount\nFROM orders",
21
+
expected_changed:true,
22
+
},
23
+
test_types::FormatTestCase{
24
+
description:"operator and function spellings stay authored",
25
+
sql:"select IFNULL(status, 'open') as status from orders where quantity != 0",
26
+
expected_sql:"SELECT\n IFNULL(status, 'open') AS status\nFROM orders\nWHERE\n quantity != 0",
0 commit comments