Skip to content
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
32 changes: 26 additions & 6 deletions test/ch/decimal_param_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,25 @@ defmodule Ch.DecimalParamTest do

assert_decimal_param(
ctx,
Decimal.new(max_integer),
Decimal.new(max_integer, max_digits: :infinity, max_exponent: :infinity),
"Decimal(76, 0)",
Decimal.new(max_integer)
Decimal.new(max_integer, max_digits: :infinity, max_exponent: :infinity)
)

assert_decimal_param(ctx, Decimal.new(1, 1, -76), "Decimal(76, 76)", Decimal.new(max_scale))
assert_decimal_param(
ctx,
Decimal.new(1, 1, -76),
"Decimal(76, 76)",
Decimal.new(max_scale, max_digits: :infinity, max_exponent: :infinity)
)
end

test "compact exponent Decimal params are not expanded before request", ctx do
encoded = encoded_decimal_param(ctx.query_options, Decimal.new("1e1000000"))
encoded =
encoded_decimal_param(
ctx.query_options,
Decimal.new("1e1000000", max_digits: :infinity, max_exponent: :infinity)
)

assert encoded =~ "1E+1000000"
assert byte_size(encoded) < 300
Expand All @@ -40,10 +49,21 @@ defmodule Ch.DecimalParamTest do
assert decimal_error(ctx, Decimal.new(1, 1, 76), "Decimal(76, 0)") =~
"value 1E+76 cannot be parsed as Decimal(76, 0)"

assert decimal_error(ctx, Decimal.new(String.duplicate("9", 77)), "Decimal(76, 0)") =~
assert decimal_error(
ctx,
Decimal.new(String.duplicate("9", 77),
max_digits: :infinity,
max_exponent: :infinity
),
"Decimal(76, 0)"
) =~
"value 99999999999999999999999999999999999999999999999999999999999999999999999999999 cannot be parsed as Decimal(76, 0)"

assert decimal_error(ctx, Decimal.new("1e1000000"), "Decimal(76, 0)") =~
assert decimal_error(
ctx,
Decimal.new("1e1000000", max_digits: :infinity, max_exponent: :infinity),
"Decimal(76, 0)"
) =~
"value 1E+1000000 cannot be parsed as Decimal(76, 0)"

assert_raise ArgumentError, "ClickHouse Decimal values must be finite", fn ->
Expand Down
2 changes: 1 addition & 1 deletion test/ch/query_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ defmodule Ch.QueryTest do
]

Enum.each(nums, fn {num, type} ->
dec = Decimal.new(num)
dec = Decimal.new(num, max_digits: :infinity, max_exponent: :infinity)
assert [[dec]] == Ch.query!(conn, "SELECT {$0:#{type}}", [dec], query_options).rows
end)
end
Expand Down
Loading