From 90ef3894e60f64e52301a8936260a10079cdea76 Mon Sep 17 00:00:00 2001 From: MunMun Miao <18216142+MunMunMiao@users.noreply.github.com> Date: Wed, 14 Oct 2026 11:58:25 +0800 Subject: [PATCH] Support the strictness before the join type in ClickHouse The ClickHouse dialect only recognised the strictness after the join type (`LEFT ASOF JOIN`). ClickHouse also accepts it before the type, and its documentation uses that form (`ASOF LEFT JOIN`, `ANY LEFT JOIN`, `ALL INNER JOIN`). Without it, `ASOF` and `ANY` stayed at the end of the previous line and the join was split in two. --- .../clickhouse/clickhouse.formatter.ts | 4 ++++ test/clickhouse.test.ts | 18 ++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/src/languages/clickhouse/clickhouse.formatter.ts b/src/languages/clickhouse/clickhouse.formatter.ts index 71aa28b32d..8b306e971f 100644 --- a/src/languages/clickhouse/clickhouse.formatter.ts +++ b/src/languages/clickhouse/clickhouse.formatter.ts @@ -226,6 +226,10 @@ const reservedSetOperations = expandPhrases([ const reservedJoins = expandPhrases([ // https://clickhouse.com/docs/sql-reference/statements/select/join '[GLOBAL] [INNER|LEFT|RIGHT|FULL|CROSS] [OUTER|SEMI|ANTI|ANY|ALL|ASOF] JOIN', + // The strictness can also come before the join type, e.g. `ANY LEFT JOIN`, `ALL INNER JOIN` + // and `ASOF LEFT JOIN`, which the documentation uses as well: + // https://clickhouse.com/docs/sql-reference/statements/select/join#asof-join-usage + '[GLOBAL] {ANY|ALL|ASOF} [INNER|LEFT|RIGHT|FULL] [OUTER] JOIN', // https://clickhouse.com/docs/sql-reference/statements/select/array-join '[LEFT] ARRAY JOIN', ]); diff --git a/test/clickhouse.test.ts b/test/clickhouse.test.ts index 225b0480f0..14dd163fd8 100644 --- a/test/clickhouse.test.ts +++ b/test/clickhouse.test.ts @@ -149,6 +149,24 @@ describe('ClickhouseFormatter', () => { 'GLOBAL ALL JOIN', 'GLOBAL ASOF JOIN', + // Strictness before the join type + 'ANY INNER JOIN', + 'ANY LEFT JOIN', + 'ANY RIGHT JOIN', + 'ANY FULL JOIN', + 'ALL INNER JOIN', + 'ALL LEFT JOIN', + 'ALL RIGHT JOIN', + 'ALL FULL JOIN', + 'ASOF INNER JOIN', + 'ASOF LEFT JOIN', + 'ASOF RIGHT JOIN', + 'ASOF FULL JOIN', + 'ANY LEFT OUTER JOIN', + 'ASOF LEFT OUTER JOIN', + 'GLOBAL ANY LEFT JOIN', + 'GLOBAL ASOF LEFT JOIN', + 'GLOBAL JOIN', 'OUTER JOIN',