Skip to content
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

Add Ints larger than UInt64 param handling #181

Merged
merged 1 commit into from
Jul 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions lib/ecto/adapters/clickhouse/connection.ex
Original file line number Diff line number Diff line change
Expand Up @@ -1094,6 +1094,12 @@ defmodule Ecto.Adapters.ClickHouse.Connection do
end

defp param_type(s) when is_binary(s), do: "String"
defp param_type(i) when is_integer(i) and i > 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF, do: "UInt256"
defp param_type(i) when is_integer(i) and i > 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF, do: "Int256"
defp param_type(i) when is_integer(i) and i > 0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF, do: "UInt128"
defp param_type(i) when is_integer(i) and i > 0xFFFFFFFFFFFFFFFF, do: "Int128"
defp param_type(i) when is_integer(i) and i > 0x7FFFFFFFFFFFFFFF, do: "UInt64"
defp param_type(i) when is_integer(i), do: "Int64"
defp param_type(i) when is_integer(i) and i > 0x7FFFFFFFFFFFFFFF, do: "UInt64"
defp param_type(i) when is_integer(i), do: "Int64"
defp param_type(f) when is_float(f), do: "Float64"
Expand Down
15 changes: 15 additions & 0 deletions test/ecto/adapters/clickhouse/connection_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -3151,4 +3151,19 @@ defmodule Ecto.Adapters.ClickHouse.ConnectionTest do
) ==
"1,'a',true,'2024-04-12'::date,'2024-04-12 09:55:54.329788'::DateTime64(6,'Etc/UTC'),'2024-04-12 09:55:54'::DateTime('Etc/UTC')"
end

test "integer boundaries" do
params =
[
9223372036854775807, #Int64 Boundary
18446744073709551615, #UInt64 Boundary
170141183460469231731687303715884105727, #Int128 Boundary
340282366920938463463374607431768211455, #UInt128 Boundary
57896044618658097711785492504343953926634992332820282019728792003956564819967, #Int256 Boundary
115792089237316195423570985008687907853269984665640564039457584007913129639935, #UInt256 Boundary
]

assert to_string(Connection.build_params(_ix = 0, _len = 6, params)) ==
"{$0:Int64},{$1:UInt64},{$2:Int128},{$3:UInt128},{$4:Int256},{$5:UInt256}"
end
end
Loading