Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: backticks in count_distinct #1611

Merged
merged 1 commit into from
Jan 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion prql-compiler/src/sql/std_impl.prql
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ func average <scalar|column> column -> s"AVG({column})"
func count <scalar|column> non_null:s"*" -> s"COUNT({non_null})"
# TODO: Possibly make this into `count distinct:true` (or like `distinct:` as an
# abbreviation of that?)
func count_distinct <scalar|column> column -> s"COUNT(DISTINCT `{column}`)"
func count_distinct <scalar|column> column -> s"COUNT(DISTINCT {column})"

# Window functions
func lag<column> offset column -> s"LAG({column}, {offset})"
Expand Down
25 changes: 21 additions & 4 deletions prql-compiler/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1711,22 +1711,39 @@ fn test_sql_of_ast_2() {

#[test]
fn test_prql_to_sql_1() {
let query = r#"
assert_display_snapshot!(compile(r#"
from employees
aggregate [
count non_null:salary,
sum salary,
]
"#;
let sql = compile(query).unwrap();
assert_display_snapshot!(sql,
"#).unwrap(),
@r###"
SELECT
COUNT(salary),
SUM(salary)
FROM
employees
"###
);
assert_display_snapshot!(compile(r#"
prql target:sql.postgres
from developers
group team (
aggregate [
skill_width = count_distinct specialty,
]
)
"#).unwrap(),
@r###"
SELECT
team,
COUNT(DISTINCT specialty) AS skill_width
FROM
developers
GROUP BY
team
"###
)
}

Expand Down