-
Notifications
You must be signed in to change notification settings - Fork 9
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
Handle missing written_rows in insert #236
Conversation
lib/ch/query.ex
Outdated
%{"written_rows" => written_rows} = Jason.decode!(summary) | ||
with summary <- get_header(headers, "x-clickhouse-summary"), | ||
{:ok, summary} <- Jason.decode(summary), | ||
written_rows when not is_nil(written_rows) <- Map.get(summary, "written_rows") do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
with
falls through with the unmatched value (e.g. {:error, Jason.DecodeError.t()}
). I think we might need to change the logic a bit to preserve num_rows :: integer | nil
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about
num_rows =
if summary = get_header(headers, "x-clickhouse-summary") do
summary = Jason.decode!(summary)
if written_rows = Map.get(summary, "written_rows") do
String.to_integer(written_rows)
end
end
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great catch. What do you think of:
num_rows =
with summary <- get_header(headers, "x-clickhouse-summary"),
summary <- Jason.decode!(summary),
written_rows when not is_nil(written_rows) <- Map.get(summary, "written_rows") do
String.to_integer(written_rows)
end
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it would "crash" on missing x-clickhouse-summary
(get_header returns nil, with
continues, Jason fails on nil
) which might be OK. The initial goal was to allow missing x-clickhouse-summary
but ensure it's JSON (raise otherwise). Not sure about how important it is now, though. Right now I think we probably shouldn't fail inserts at all on missing num_rows info and document it in ecto_ch that insert_all num_rows is unreliable.
Thank you for the fix!
I have verified that the fix works, but I still think we need to be careful with |
7560ede
to
c600a85
Compare
Thank you! I'm going to cut a release right away! Published as And I have also published |
Thanks, I did end up needing |
Right, UPDATE: I've released ecto_ch v0.6.0 which depends on ch v0.3.0. |
This happens in the latest Clickhouse version (25.1)
It should resolve https://github.com/plausible/ecto_ch/actions/runs/13110662749/job/36573653799