Skip to content

Commit

Permalink
{pipeline,fmtsql}.jl: fix String <-> Symbol confusion in API
Browse files Browse the repository at this point in the history
  • Loading branch information
suvayu committed Apr 20, 2024
1 parent 9878af1 commit bced2f5
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 31 deletions.
4 changes: 2 additions & 2 deletions src/fmtsql.jl
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ end
function fmt_join(
from_subquery::String,
join_subquery::String;
on::Vector{String},
cols::Vector{String},
on::Vector{Symbol},
cols::Vector{Symbol},
fill::Union{Bool,Vector::Any},
)
exclude = join(cols, ", ")
Expand Down
26 changes: 6 additions & 20 deletions src/pipeline.jl
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,8 @@ end
con::DB,
base_source::String,
alt_source::String;
on::Vector{String},
cols::Vector{String},
on::Vector{Symbol},
cols::Vector{Symbol},
variant::String = "",
fill::Union{Bool,Vector::Any} = true,
tmp::Bool = false,
Expand Down Expand Up @@ -155,8 +155,8 @@ function create_tbl(
con::DB,
base_source::String,
alt_source::String;
on::Vector{String},
cols::Vector{String},
on::Vector{Symbol},
cols::Vector{Symbol},
variant::String = "",
fill::Union{Bool,Vector::Any} = true,
tmp::Bool = false,
Expand Down Expand Up @@ -193,15 +193,7 @@ function _set_tbl_col_impl(
tmp_tbl = "t_col_$(col)"
register_data_frame(con, df, tmp_tbl)
# FIXME: should be fill=error (currently not implemented)
res = create_tbl(
con,
source,
tmp_tbl;
on = [String(on)],
cols = [String(col)],
fill = false,
opts...,
)
res = create_tbl(con, source, tmp_tbl; on = [on], cols = [col], fill = false, opts...)
unregister_data_frame(con, tmp_tbl)
return res
end
Expand Down Expand Up @@ -313,13 +305,7 @@ function set_tbl_col(
end

# FIXME: resolve String|Symbol schizophrenic API
query = fmt_join(
source,
"($subquery)";
on = ["$on"],
cols = map(string, [keys(cols)...]),
fill = true,
)
query = fmt_join(source, "($subquery)"; on = [on], cols = [keys(cols)...], fill = true)

if (length(variant) == 0) && !show
tmp = true
Expand Down
18 changes: 9 additions & 9 deletions test/test-pipeline.jl
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ end
con,
csv_path,
csv_copy;
on = ["name"],
cols = ["investable"],
on = [:name],
cols = [:investable],
fill = false,
show = true,
)
Expand All @@ -93,8 +93,8 @@ end
con,
csv_path,
csv_fill;
on = ["name"],
cols = ["investable"],
on = [:name],
cols = [:investable],
fill = true,
show = true,
)
Expand Down Expand Up @@ -142,8 +142,8 @@ end
"no_assets",
csv_copy;
variant = "alt_assets",
on = ["name"],
cols = ["investable"],
on = [:name],
cols = [:investable],
fill = false,
)
df_res = DF.DataFrame(DBInterface.execute(con, "SELECT * FROM $tbl_name"))
Expand All @@ -153,7 +153,7 @@ end

@testset "temporary tables" begin
tbl_name =
TIO.create_tbl(con, "no_assets", csv_copy; on = ["name"], cols = ["investable"])
TIO.create_tbl(con, "no_assets", csv_copy; on = [:name], cols = [:investable])
@test tbl_name in tmp_tbls(con)[!, :name]
@test tbl_name == "t_assets_data_copy" # t_<cleaned up filename>
end
Expand All @@ -164,8 +164,8 @@ end
"no_assets",
csv_fill;
variant = "alt_assets_filled",
on = ["name"],
cols = ["investable"],
on = [:name],
cols = [:investable],
fill = true,
)
df_res = DF.DataFrame(DBInterface.execute(con, "SELECT * FROM $tbl_name"))
Expand Down

0 comments on commit bced2f5

Please sign in to comment.