-
Notifications
You must be signed in to change notification settings - Fork 514
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Postgres: Add window function support (#4283)
* Postgresql: Support window function * Use snapshot repo * Postgresql: Support window function * Use long as migration version * Add integration test * Bump to sql-psi 0.4.5 * Fix int usage * Fix dialect test * Fix dialect tests * Fix schema version * Fix schema version * Fix tests * Update settings.gradle * Remove snapshot repo * Remove snapshot repo --------- Co-authored-by: hfhbd <hfhbd@users.noreply.github.com> Co-authored-by: Alec Kazakova <AlecStrong@users.noreply.github.com>
- Loading branch information
1 parent
d597342
commit 50c2ae2
Showing
9 changed files
with
90 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
...main/kotlin/app/cash/sqldelight/dialects/postgresql/grammar/mixins/WindowFunctionMixin.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package app.cash.sqldelight.dialects.postgresql.grammar.mixins | ||
|
||
import app.cash.sqldelight.dialects.postgresql.grammar.psi.PostgreSqlWindowFunctionExpr | ||
import com.alecstrong.sql.psi.core.psi.SqlCompositeElementImpl | ||
import com.alecstrong.sql.psi.core.psi.SqlFunctionExpr | ||
import com.intellij.lang.ASTNode | ||
|
||
internal abstract class WindowFunctionMixin( | ||
node: ASTNode, | ||
) : SqlCompositeElementImpl(node), | ||
PostgreSqlWindowFunctionExpr { | ||
val functionExpr get() = children.filterIsInstance<SqlFunctionExpr>().single() | ||
} |
6 changes: 6 additions & 0 deletions
6
dialects/postgresql/src/test/fixtures_postgresql/functions-aggregate/Test.s
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
CREATE TABLE myTable( | ||
myColumn REAL NOT NULL | ||
); | ||
|
||
SELECT percentile_disc(.5) WITHIN GROUP (ORDER BY myTable.myColumn) AS P5 | ||
FROM myTable; |
11 changes: 11 additions & 0 deletions
11
dialects/postgresql/src/test/fixtures_postgresql/functions-stats/Test.s
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
CREATE TABLE myTable( | ||
foo REAL NOT NULL, | ||
bar NUMERIC NOT NULL | ||
); | ||
|
||
SELECT | ||
corr(foo), | ||
stddev(bar), | ||
stddev(foo), | ||
regr_count(foo) | ||
FROM myTable GROUP BY foo, bar; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
...on-postgresql/src/main/sqldelight/app/cash/sqldelight/postgresql/integration/Functions.sq
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
CREATE TABLE myTable( | ||
foo REAL NOT NULL, | ||
bar NUMERIC NOT NULL | ||
); | ||
|
||
INSERT INTO myTable VALUES (1, 1), (2, 2), (3, 3); | ||
|
||
selectPercentile: | ||
SELECT percentile_disc(.5) WITHIN GROUP (ORDER BY foo) AS P5 | ||
FROM myTable; | ||
|
||
selectStats: | ||
SELECT | ||
corr(foo, bar), | ||
stddev(foo), | ||
regr_count(foo, bar) | ||
FROM myTable | ||
GROUP BY foo, bar; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters