Skip to content

Commit ea25cc5

Browse files
authored
fix: Support formatting queries with % operator (#1427)
Fixes HDX-2954 # Summary This PR fixes a limitation of the sql formatter which caused errors in queries that include the `%` (mod) operator <img width="212" height="145" alt="Screenshot 2025-12-02 at 1 34 11 PM" src="https://github.com/user-attachments/assets/505211a5-fa05-4d76-84f0-d76a92e852cf" />
1 parent d9baa43 commit ea25cc5

3 files changed

Lines changed: 15 additions & 1 deletion

File tree

‎.changeset/eight-cooks-do.md‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@hyperdx/common-utils": patch
3+
---
4+
5+
fix: Support formatting queries with % operator

‎packages/common-utils/src/__tests__/sqlFormatter.test.ts‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,4 +79,13 @@ ORDER BY
7979
toStartOfInterval (toDateTime (TimestampTime), INTERVAL 6 hour) AS \`__hdx_time_bucket\``;
8080
expect(format(input)).toBe(expected);
8181
});
82+
83+
test('should work with mod operator', () => {
84+
const input = 'SELECT 10 % 2 FROM table';
85+
const expected = `SELECT
86+
10 % 2
87+
FROM
88+
table`;
89+
expect(format(input)).toBe(expected);
90+
});
8291
});

‎packages/common-utils/src/sqlFormatter.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,7 @@ const clickhouse: DialectOptions = {
449449
identTypes: [`""-qq`, '``'],
450450
extraParens: ['[]'],
451451
paramTypes: { positional: true },
452-
operators: ['||'],
452+
operators: ['||', '%'],
453453
},
454454
formatOptions: {
455455
onelineClauses: [...standardOnelineClauses, ...tabularOnelineClauses],

0 commit comments

Comments
 (0)