Skip to content
Draft
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
2 changes: 1 addition & 1 deletion lib/ecto/adapters/clickhouse/connection.ex
Original file line number Diff line number Diff line change
Expand Up @@ -1101,7 +1101,7 @@ defmodule Ecto.Adapters.ClickHouse.Connection do
defp ecto_to_db({:parameterized, {Ch, type}}, _query), do: Ch.Types.encode(type)
defp ecto_to_db({:array, type}, query), do: ["Array(", ecto_to_db(type, query), ?)]

defp ecto_to_db(type, _query) when type in [:uuid, :string, :date, :boolean] do
defp ecto_to_db(type, _query) when type in [:uuid, :string, :date, :time, :boolean] do
Ch.Types.encode(type)
end

Expand Down
4 changes: 0 additions & 4 deletions lib/ecto/adapters/clickhouse/migration.ex
Original file line number Diff line number Diff line change
Expand Up @@ -434,10 +434,6 @@ defmodule Ecto.Adapters.ClickHouse.Migration do
raise ArgumentError, "type :numeric is not supported"
end

defp column_type(:time) do
raise ArgumentError, "type :time is not supported"
end

defp column_type(:map) do
raise ArgumentError,
~s[type :map is ambiguous, use a literal (e.g. :JSON or :"Map(String, UInt8)") instead]
Expand Down
9 changes: 3 additions & 6 deletions lib/ecto/adapters/clickhouse/schema.ex
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ defmodule Ecto.Adapters.ClickHouse.Schema do
defp remap_type({:parameterized, {Ch, t}}, _original, _schema, _field), do: t

defp remap_type(t, _original, _schema, _field)
when t in [:string, :date, :uuid, :boolean],
when t in [:string, :date, :time, :uuid, :boolean],
do: t

defp remap_type(dt, _original, _schema, _field)
Expand All @@ -275,6 +275,8 @@ defmodule Ecto.Adapters.ClickHouse.Schema do
when usec in [:naive_datetime_usec, :utc_datetime_usec],
do: {:datetime64, _precision = 6}

defp remap_type(:time_usec, _original, _schema, _field), do: {:time64, _precision = 6}

# TODO remove
defp remap_type(t, _original, _schema, _field)
when t in [:binary, :binary_id],
Expand All @@ -291,11 +293,6 @@ defmodule Ecto.Adapters.ClickHouse.Schema do

defp remap_type(:integer, _original, Ecto.Migration.SchemaMigration, :version), do: :i64

defp remap_type(time, _original, _schema, _field) when time in [:time, :time_usec] do
raise ArgumentError,
"`#{inspect(time)}` type is not supported as there is no `Time` type in ClickHouse."
end

defp remap_type(other, original, schema, field) do
ch_type = ch_type_hint(original)

Expand Down
16 changes: 8 additions & 8 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, 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, 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.14, 25, 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, 25, 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, 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, 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.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.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, 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, 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.

assert all(query) == ~s|SELECT true FROM "schema" AS s0 WHERE ("y" = 'Main')|
end
Expand Down Expand Up @@ -962,13 +962,13 @@
assert all(query) == ~s[SELECT CAST(s0."x" + 1 AS UInt16) FROM "schema" AS s0]
end

test "tagged unknown type" do
@tag :time
test "tagged as time" do
query = from e in "events", select: type(e.count + 1, :time)
assert all(query) == ~s[SELECT CAST(e0."count" + CAST(1 AS Time) AS Time) FROM "events" AS e0]
end

assert_raise Ecto.QueryError,
~r/unknown or ambiguous \(for ClickHouse\) Ecto type :time in query/,
fn -> all(query) end

test "tagged unknown type" do
query = from e in "events", select: type(e.count + 1, :decimal)

assert_raise Ecto.QueryError,
Expand Down Expand Up @@ -2626,9 +2626,9 @@
{:create, table(:posts),
[{:add, :published_at, :time, []}, {:add, :submitted_at, :time, []}]}

assert_raise ArgumentError, "type :time is not supported", fn ->
execute_ddl(create)
end
assert execute_ddl(create) == [
~s[CREATE TABLE "posts" ("published_at" time,"submitted_at" time) ENGINE=TinyLog]
]
end

test "create table with utc_datetime columns" do
Expand Down
Loading