Skip to content

Commit

Permalink
Merge pull request #79 from TidierOrg/adjust-names-when-reading-filepath
Browse files Browse the repository at this point in the history
small improvment in filepath reading
  • Loading branch information
drizk1 authored Oct 19, 2024
2 parents c8bcfe0 + d7e1157 commit b468b36
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 29 deletions.
2 changes: 1 addition & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Breaking Changes:
- All join syntax now matches TidierData's `(table1, table2, t1_col = t2_col)`
Additions:
- `@compute`for DuckDB, MySQL, PostGres, GBQ to write a table to the db and the end of a query.
- `@compute`for DuckDB, MySQL, PostGres, GBQ to write a table to the db at the end of a query.
- expands `@create_view` to MySQL, PostGres, GBQ
- Support for performing multiple joins of TidierDB queries in a single chain with further tests
- `dmy`, `mdy`, `ymd` support DuckDB, Postgres, GBQ, Clickhouse, MySQL, MsSQL, Athena, MsSQL
Expand Down
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ ClickHouse = "0.2"
DataFrames = "1.5"
Dates = "1.9"
Documenter = "0.27, 1"
DuckDB = "1.0"
DuckDB = "1.0, 1.1"
GZip = "0.6"
GoogleCloud = "0.11"
HTTP = "1.1"
Expand Down
28 changes: 4 additions & 24 deletions docs/examples/UserGuide/from_queryex.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# While using TidierDB, you may need to generate part of a query and reuse it multiple times. There are two ways to do this
# 1. `from_query(query)` or `t(query)`
# 1. `from_query(query)` or its alias `t(query)`
# 2. `@create_view(name)`

# ## Setup
Expand All @@ -12,7 +12,7 @@

# Start a query to analyze fuel efficiency by number of cylinders. However, to further build on this query later, end the chain without using `@show_query` or `@collect`
# ```julia
# query = DB.@chain DB.t(query) begin
# query = DB.@chain DB.t(mtcars) begin
# DB.@group_by cyl
# DB.@summarize begin
# across(mpg, (mean, minimum, maximum))
Expand All @@ -31,7 +31,7 @@
# Now, `from_query`, or `t()` a convienece wrapper, will allow you to reuse the query to calculate the average horsepower for each efficiency category
# ```julia
# DB.@chain DB.t(query) begin
# DB.@left_join("mtcars2", cyl, cyl)
# DB.@left_join(DB.t(mtcars), cyl = cyl)
# DB.@group_by(efficiency)
# DB.@summarize(avg_hp = mean(hp))
# DB.@collect
Expand All @@ -46,26 +46,6 @@
# 2 │ High 82.6364
# ```

# Reuse the query again to find the car with the highest MPG for each cylinder category
# ```julia
# DB.@chain DB.t(mtcars) begin
# DB.@left_join("mtcars2", cyl, cyl)
# DB.@group_by cyl
# DB.@slice_max(mpg)
# DB.@select model cyl mpg
# DB.@collect
# end
# ```
# ```
# 3×3 DataFrame
# Row │ model cyl mpg
# │ String? Int64? Float64?
# ─────┼────────────────────────────────────
# 1 │ Pontiac Firebird 8 19.2
# 2 │ Toyota Corolla 4 33.9
# 3 │ Hornet 4 Drive 6 21.4
# ```

# ## @create_view
# This can also be done with `@create_view`.
# ```julia
Expand All @@ -87,7 +67,7 @@
#
#
# DB.@chain DB.db_table(db, "viewer") begin
# DB.@left_join(DB.t(query2), cyl, cyl)
# DB.@left_join(DB.t(query2), cyl = cyl)
# DB.@group_by(efficiency)
# DB.@summarize(avg_mean = mean(mpg))
# DB.@mutate(mean = avg_mean / 4 )
Expand Down
2 changes: 1 addition & 1 deletion src/TidierDB.jl
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ function db_table(db, table, athena_params::Any=nothing; iceberg::Bool=false, de
elseif delta
"delta_scan('$table_name')"
elseif occursin(r"[:/]", table_name) && !(iceberg || delta) && !startswith(table_name, "read")
"'$table_name'"
"'$table_name' AS $(split(basename(table_name), '.')[1]) "
elseif startswith(table_name, "read")
"$table_name"
else
Expand Down
9 changes: 7 additions & 2 deletions src/joins_sq.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ function gbq_join_parse(input)
if current_sql_mode[] == gbq() && length(parts) >=2
return parts[end]
elseif occursin(".", input)
return split(input, '.')[end]
if occursin(r"[:/]", input)
return split(basename(input), '.')[1]
else
return split(input, '.')[end]
end
else
return input
end
Expand Down Expand Up @@ -78,7 +82,7 @@ $docstring_left_join
"""
macro left_join(sqlquery, join_table, expr)
lhs_col_str, rhs_col_str = parse_join_expression(expr)

return quote
sq = $(esc(sqlquery))
jq = $(esc(join_table)) # Evaluate join_table
Expand Down Expand Up @@ -160,6 +164,7 @@ macro left_join(sqlquery, join_table, expr)
join_table_name = jq.from
else
# When join_table is a table name

join_table_name = string(jq)
if current_sql_mode[] != :athena
new_metadata = get_table_metadata(sq.db, join_table_name)
Expand Down

2 comments on commit b468b36

@drizk1
Copy link
Member Author

@drizk1 drizk1 commented on b468b36 Oct 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator register

Release Notes:

Breaking Changes:

  • All join syntax now matches TidierData's (table1, table2, t1_col = t2_col)

Additions:

  • @computefor DuckDB, MySQL, PostGres, GBQ to write a table to the db at the end of a query.
  • expands @create_view to MySQL, PostGres, GBQ
  • Support for performing multiple joins of TidierDB queries in a single chain with further tests
  • dmy, mdy, ymd support DuckDB, Postgres, GBQ, Clickhouse, MySQL, MsSQL, Athena, MsSQL
  • support for working with intervals ie + interval4days - interval5months etc
  • Date related tests
  • copy_to for MysQL to write a dataframe to MySQL database
  • 65 total tests matching TidierData to TidierDB results

Improvements:

  • improve Google Big Query type mapping when collecting to dataframe
  • change gbq()'s connect() to accept location as second argument
  • str_detect now supports regex for all backends except MsSQL + some tests
  • @select(!table.name) now works to deselect a column

Docs:

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/117635

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.5.0 -m "<description of version>" b468b366e9401cd4a94071b3fe8299b61a868f30
git push origin v0.5.0

Please sign in to comment.