Skip to content

Commit

Permalink
change it to sql_agg
Browse files Browse the repository at this point in the history
  • Loading branch information
drizk1 committed Apr 28, 2024
1 parent f7b6978 commit a67fa06
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 13 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ From TidierDates.jl:
Supported aggregate functions (as supported by the backend) with more to come
- `mean`, `minimium`, `maximum`, `std`, `sum`, `cumsum`, `cor`, `cov`, `var`
- `@summarize` supports any SQL aggregate function in addition to the list above. Simply write the function as written in SQL syntax and it will work.
- `agg_str` allows any SQL aggregate function not listed above to be used in `@mutate`. Simply write the function expression as written in SQL syntax as a string wrapped in `agg_str`, and subsequent windowing is handled by `@mutate`.
- `sql_agg` allows any SQL aggregate function not listed above to be used in `@mutate`. Simply write the function expression as written in SQL syntax as a string wrapped in `sql_agg`, and subsequent windowing is handled by `@mutate`.
- `copy_to` (for DuckDB, MySQL, SQLite)

DuckDB specifically enables copy_to to directly reading in `.parquet`, `.json`, `.csv`, and `.arrow` file, including https file paths.
Expand Down
1 change: 1 addition & 0 deletions src/TidierDB.jl
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,7 @@ function connect(backend::Symbol; kwargs...)
return SQLite.DB(db_path)
elseif backend == :DuckDB || backend == :duckdb
mem = DuckDB.open(":memory:")
set_sql_mode(:duckdb)
return DuckDB.connect(mem)
else
throw(ArgumentError("Unsupported backend: $backend"))
Expand Down
4 changes: 2 additions & 2 deletions src/parsing_clickhouse.jl
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,9 @@ function expr_to_sql_clickhouse(expr, sq; from_summarize::Bool)
window_clause = construct_window_clause(sq)
return "VAR_SAMP($(string(a))) $(window_clause)"
end
elseif @capture(x, agg_str(str_))
elseif @capture(x, sql_agg(str_))
if from_summarize
return error("agg_str is only needed with aggregate functions in @mutate")
return error("sql_agg is only needed with aggregate functions in @mutate")
else
window_clause = construct_window_clause(sq)
return "$(str) $(window_clause)"
Expand Down
4 changes: 2 additions & 2 deletions src/parsing_duckdb.jl
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,9 @@ function expr_to_sql_duckdb(expr, sq; from_summarize::Bool)
window_clause = construct_window_clause(sq)
return "VAR_SAMP($(string(a))) $(window_clause)"
end
elseif @capture(x, agg_str(str_))
elseif @capture(x, sql_agg(str_))
if from_summarize
return error("agg_str is only needed with aggregate functions in @mutate")
return error("sql_agg is only needed with aggregate functions in @mutate")
else
window_clause = construct_window_clause(sq)
return "$(str) $(window_clause)"
Expand Down
4 changes: 2 additions & 2 deletions src/parsing_mssql.jl
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,9 @@ function expr_to_sql_mssql(expr, sq; from_summarize::Bool)
window_clause = construct_window_clause(sq)
return "VAR_SAMP($(string(a))) $(window_clause)"
end
elseif @capture(x, agg_str(str_))
elseif @capture(x, sql_agg(str_))
if from_summarize
return error("agg_str is only needed with aggregate functions in @mutate")
return error("sql_agg is only needed with aggregate functions in @mutate")
else
window_clause = construct_window_clause(sq)
return "$(str) $(window_clause)"
Expand Down
4 changes: 2 additions & 2 deletions src/parsing_mysql.jl
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,9 @@ function expr_to_sql_mysql(expr, sq; from_summarize::Bool)
window_clause = construct_window_clause(sq)
return "VAR_SAMP($(string(a))) $(window_clause)"
end
elseif @capture(x, agg_str(str_))
elseif @capture(x, sql_agg(str_))
if from_summarize
return error("agg_str is only needed with aggregate functions in @mutate")
return error("sql_agg is only needed with aggregate functions in @mutate")
else
window_clause = construct_window_clause(sq)
return "$(str) $(window_clause)"
Expand Down
4 changes: 2 additions & 2 deletions src/parsing_postgres.jl
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,9 @@ function expr_to_sql_postgres(expr, sq; from_summarize::Bool)
window_clause = construct_window_clause(sq)
return "VAR_SAMP($(string(a))) $(window_clause)"
end
elseif @capture(x, agg_str(str_))
elseif @capture(x, sql_agg(str_))
if from_summarize
return error("agg_str is only needed with aggregate functions in @mutate")
return error("sql_agg is only needed with aggregate functions in @mutate")
else
window_clause = construct_window_clause(sq)
return "$(str) $(window_clause)"
Expand Down
4 changes: 2 additions & 2 deletions src/parsing_sqlite.jl
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ function expr_to_sql_lite(expr, sq; from_summarize::Bool)
window_clause = construct_window_clause(sq, from_cumsum = true)
return "SUM($(string(a))) $(window_clause)"
end
elseif @capture(x, agg_str(str_))
elseif @capture(x, sql_agg(str_))
if from_summarize
return error("agg_str is only needed with aggregate functions in @mutate")
return error("sql_agg is only needed with aggregate functions in @mutate")
else
window_clause = construct_window_clause(sq)
return "$(str) $(window_clause)"
Expand Down

0 comments on commit a67fa06

Please sign in to comment.