Skip to content
Open
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
1 change: 1 addition & 0 deletions lib/ecto/adapters/clickhouse.ex
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ defmodule Ecto.Adapters.ClickHouse do
def dumpers(:uuid, Ecto.UUID), do: [&__MODULE__.hex_uuid/1]
def dumpers(:uuid, type), do: [type, &__MODULE__.hex_uuid/1]
def dumpers(:binary_id, type), do: [type, &__MODULE__.hex_uuid/1]
def dumpers({:in, sub}, {:in, sub}), do: [{:array, sub}]
def dumpers(_primitive, {:parameterized, {Ch, params}}), do: [dumper(params)]
def dumpers({:parameterized, {Ch, params}}, type), do: [type, dumper(params)]
def dumpers(_primitive, type), do: [type]
Expand Down
7 changes: 7 additions & 0 deletions lib/ecto/adapters/clickhouse/connection.ex
Original file line number Diff line number Diff line change
Expand Up @@ -678,6 +678,13 @@ defmodule Ecto.Adapters.ClickHouse.Connection do

defp expr({:in, _, [_, {:^, _, [_ix, 0]}]}, _sources, _params, _query), do: "0"

defp expr({:in, _, [left, {:^, _, [ix, len]}]}, sources, params, query) when len > 0 do
array_values = Enum.at(params, ix)
param = build_param(ix, array_values)

[expr(left, sources, params, query), " IN ", param]
end

defp expr({:in, _, [left, right]}, sources, params, query) do
[expr(left, sources, params, query), " IN ", expr(right, sources, params, query)]
end
Expand Down
4 changes: 2 additions & 2 deletions test/ecto/adapters/clickhouse/connection_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -933,8 +933,8 @@

query =
"schema"
|> where(fragment("? = ?", literal(^name), "Main"))

Check warning on line 936 in test/ecto/adapters/clickhouse/connection_test.exs

View workflow job for this annotation

GitHub Actions / test (1.14, 26, latest, UTC)

`literal/1` is deprecated. Please use `identifier/1` instead.

Check warning on line 936 in test/ecto/adapters/clickhouse/connection_test.exs

View workflow job for this annotation

GitHub Actions / test (1.15, 25, latest, UTC)

`literal/1` is deprecated. Please use `identifier/1` instead.

Check warning on line 936 in test/ecto/adapters/clickhouse/connection_test.exs

View workflow job for this annotation

GitHub Actions / test (1.14, 25, latest, UTC)

`literal/1` is deprecated. Please use `identifier/1` instead.

Check warning on line 936 in test/ecto/adapters/clickhouse/connection_test.exs

View workflow job for this annotation

GitHub Actions / test (1.16, 26, latest, UTC)

`literal/1` is deprecated. Please use `identifier/1` instead.

Check warning on line 936 in test/ecto/adapters/clickhouse/connection_test.exs

View workflow job for this annotation

GitHub Actions / test (1.16, 25, latest, UTC)

`literal/1` is deprecated. Please use `identifier/1` instead.

Check warning on line 936 in test/ecto/adapters/clickhouse/connection_test.exs

View workflow job for this annotation

GitHub Actions / test (1.15, 26, latest, UTC)

`literal/1` is deprecated. Please use `identifier/1` instead.
|> select([], true)

Check warning on line 937 in test/ecto/adapters/clickhouse/connection_test.exs

View workflow job for this annotation

GitHub Actions / test (1.17, 27, latest, UTC)

`literal/1` is deprecated. Please use `identifier/1` instead.

Check warning on line 937 in test/ecto/adapters/clickhouse/connection_test.exs

View workflow job for this annotation

GitHub Actions / test (1.18, 28, 24.5.4.49, UTC)

`literal/1` is deprecated. Please use `identifier/1` instead.

Check warning on line 937 in test/ecto/adapters/clickhouse/connection_test.exs

View workflow job for this annotation

GitHub Actions / test (1.18, 28, latest, Europe/Berlin)

`literal/1` is deprecated. Please use `identifier/1` instead.

Check warning on line 937 in test/ecto/adapters/clickhouse/connection_test.exs

View workflow job for this annotation

GitHub Actions / test (1.18, 28, latest, UTC)

`literal/1` is deprecated. Please use `identifier/1` instead.

Check warning on line 937 in test/ecto/adapters/clickhouse/connection_test.exs

View workflow job for this annotation

GitHub Actions / test (1.18, 27, latest, UTC)

`literal/1` is deprecated. Please use `identifier/1` instead.

Check warning on line 937 in test/ecto/adapters/clickhouse/connection_test.exs

View workflow job for this annotation

GitHub Actions / test (1.18.3, 27.3.1, 24.12.2.29, UTC)

`literal/1` is deprecated. Please use `identifier/1` instead.

Check warning on line 937 in test/ecto/adapters/clickhouse/connection_test.exs

View workflow job for this annotation

GitHub Actions / test (1.17, 26, latest, UTC)

`literal/1` is deprecated. Please use `identifier/1` instead.

Check warning on line 937 in test/ecto/adapters/clickhouse/connection_test.exs

View workflow job for this annotation

GitHub Actions / test (1.17, 25, latest, UTC)

`literal/1` is deprecated. Please use `identifier/1` instead.

assert all(query) == ~s|SELECT true FROM "schema" AS s0 WHERE ("y" = 'Main')|
end
Expand Down Expand Up @@ -1019,15 +1019,15 @@
assert all(query) == ~s[SELECT 0 FROM "schema" AS s0]

query = Schema |> select([e], 1 in ^[1, 2, 3])
assert all(query) == ~s[SELECT 1 IN ({$0:Int64},{$1:Int64},{$2:Int64}) FROM "schema" AS s0]
assert all(query) == ~s[SELECT 1 IN {$0:Array(Int64)} FROM "schema" AS s0]

query = Schema |> select([e], 1 in [1, ^2, 3])
assert all(query) == ~s[SELECT 1 IN (1,{$0:Int64},3) FROM "schema" AS s0]

query = Schema |> select([e], e.x == ^0 or e.x in ^[1, 2, 3] or e.x == ^4)

assert all(query) ==
~s[SELECT (s0."x" = {$0:Int64}) OR (s0."x" IN ({$1:Int64},{$2:Int64},{$3:Int64})) OR (s0."x" = {$4:Int64}) FROM "schema" AS s0]
~s[SELECT (s0."x" = {$0:Int64}) OR (s0."x" IN {$1:Array(Int64)}) OR (s0."x" = {$2:Int64}) FROM "schema" AS s0]

query = Schema |> select([e], e in [1, 2, 3])

Expand Down
11 changes: 5 additions & 6 deletions test/ecto_ch_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,14 @@ defmodule EctoCh.Test do
countIf(e0."type" != 'pageview') \
FROM "events" AS e0 \
WHERE (\
e0."domain" IN ({$0:String},{$1:String})) AND \
(e0."tags" = {$2:Array(String)}) AND \
(toDate(e0."inserted_at") >= {$3:Date}) AND \
(toDate(e0."inserted_at") <= {$4:Date}\
e0."domain" IN {$0:Array(String)}) AND \
(e0."tags" = {$1:Array(String)}) AND \
(toDate(e0."inserted_at") >= {$2:Date}) AND \
(toDate(e0."inserted_at") <= {$3:Date}\
)\
""",
[
"dummy.site",
"dummy2.site",
["dummy.site", "dummy2.site"],
["1", "2", "3"],
~D[2020-10-10],
~D[2021-01-01]
Expand Down
Loading