Skip to content

Commit 18ba6cd

Browse files
committed
Add tests and improve formatting for ORDER BY with condition directives
1 parent 70067e9 commit 18ba6cd

File tree

4 files changed

+14
-8
lines changed

4 files changed

+14
-8
lines changed

src/test/kotlin/org/domaframework/doma/intellij/formatter/SqlFormatterTest.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,10 @@ class SqlFormatterTest : BasePlatformTestCase() {
274274
formatSqlFile("OrderByGroup.sql", "OrderByGroup$formatDataPrefix.sql")
275275
}
276276

277+
fun testOrderByGroupWithConditionDirectiveFormatter() {
278+
formatSqlFile("OrderByGroupWithConditionDirective.sql", "OrderByGroupWithConditionDirective$formatDataPrefix.sql")
279+
}
280+
277281
private fun formatSqlFile(
278282
beforeFile: String,
279283
afterFile: String,

src/test/testData/sql/formatter/OrderByGroupWithConditionDirective.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
SELECT e.id
22
-- with condition
3-
, ROW_NUMBER() OVER(/*%if order */ORDER BY e.manager_id DESC/*%end*/) AS row_num
3+
, ROW_NUMBER() /*%if order */OVER(ORDER BY e.manager_id DESC)/*%end*/ AS row_num
44
, RANK() OVER(PARTITION BY department_id
55
/*%if order */ORDER BY e.manager_id DESC/*%end */
66
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS rank_num

src/test/testData/sql/formatter/OrderByGroupWithConditionDirective_format.sql

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
SELECT e.id
22
-- with condition
3-
, ROW_NUMBER() OVER(/*%if order */
4-
ORDER BY e.manager_id DESC
5-
/*%end*/) AS row_num
3+
, ROW_NUMBER()
4+
/*%if order */
5+
OVER(ORDER BY e.manager_id DESC)
6+
/*%end*/
7+
AS row_num
68
, RANK() OVER(PARTITION BY department_id
79
/*%if order */
810
ORDER BY e.manager_id DESC
@@ -24,14 +26,14 @@ SELECT e.id
2426
ROWS BETWEEN 1 PRECEDING AND 1 FOLLOWING
2527
/*%end*/)
2628
, FIRST_VALUE(salary) IGNORE NULLS OVER(PARTITION BY department_id
27-
ORDER BY e.id ASC, e.manager_id ASC, created_at DESC)
29+
ORDER BY e.id ASC, e.manager_id ASC, created_at DESC)
2830
, LAST_VALUE() OVER(ORDER BY e.manager_id ASC
2931
/*%if rows */
3032
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
3133
/*%end*/) AS bottom_salary
3234
, LISTAGG(e.name
33-
, ', ')
34-
/*%if filter */
35+
, ', ')
36+
/*%if filter */
3537
WITHIN GROUP (ORDER BY name DESC)
3638
/*%end*/
3739
FROM employees e

src/test/testData/sql/formatter/OrderByGroup_format.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ SELECT e.id
1616
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS bottom_salary
1717
, COUNT(*) FILTER(WHERE gender = 'F') AS female_count
1818
, LISTAGG(e.name
19-
, ', ') WITHIN GROUP(ORDER BY name DESC)
19+
, ', ') WITHIN GROUP (ORDER BY name DESC)
2020
FROM employees e
2121
WHERE e.status = 1
2222
ORDER BY e.id

0 commit comments

Comments
 (0)