Skip to content

Commit

Permalink
Review suggestion, fmtsql.jl: determine fill_value cleanly
Browse files Browse the repository at this point in the history
  • Loading branch information
suvayu committed May 13, 2024
1 parent dd56a73 commit 11e9c7c
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/fmtsql.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ sprintf(fmt::String, args...) = format(Format(fmt), args...)
# quote literals appropriately for SQL
fmt_quote(item) = "$(item)"
fmt_quote(item::Union{AbstractString,AbstractChar}) = "'$(item)'"
fmt_quote(::Missing) = missing

function fmt_opts(source::String; opts...)
_src = '?' in source ? "$source" : "'$(source)'"
Expand Down Expand Up @@ -57,11 +58,14 @@ function fmt_join(
include = join(map(c -> "IFNULL(t2.$c, t1.$c) AS $c", cols), ", ")
else
include = join(
map(c -> begin
default = get(fill_values, c, missing)
fill_value = ismissing(default) ? "t1.$c" : fmt_quote(default)
map(
c -> begin
fill_value =
get(fill_values, c, missing) |> fmt_quote |> v -> coalesce(v, "t1.$c")
"IFNULL(t2.$c, $fill_value) AS $c"
end, cols),
end,
cols,
),
", ",
)
end
Expand Down

0 comments on commit 11e9c7c

Please sign in to comment.