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
11 changes: 11 additions & 0 deletions compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
services:
clickhouse:
image: clickhouse/clickhouse-server:latest-alpine
ports:
- 8123:8123
environment:
- CLICKHOUSE_SKIP_USER_SETUP=1
ulimits:
nofile:
soft: 262144
hard: 262144
7 changes: 4 additions & 3 deletions mix.exs
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,7 @@ defmodule EctoCh.MixProject do

# Run "mix help compile.app" to learn about applications.
def application do
[
extra_applications: [:logger]
]
[extra_applications: extra_applications(Mix.env())]
end

# Specifies which paths to compile per environment.
Expand All @@ -35,6 +33,9 @@ defmodule EctoCh.MixProject do
defp test_paths(nil), do: ["test"]
defp test_paths(_any), do: ["integration_test"]

defp extra_applications(:test), do: [:logger, :inets]
defp extra_applications(_), do: [:logger]

# Run "mix help deps" to learn about dependencies.
defp deps do
[
Expand Down
13 changes: 11 additions & 2 deletions test/ecto/integration/clickhouse_joins_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ defmodule Ecto.Integration.ClickHouseJoinsTest do
]
end

# https://github.com/ClickHouse/ClickHouse/blob/master/tests/queries/0_stateless/00976_asof_join_on.sql
# https://github.com/ClickHouse/ClickHouse/blob/master/tests/queries/0_stateless/00976_asof_join_on.sql.j2
# https://github.com/ClickHouse/ClickHouse/blob/master/tests/queries/0_stateless/00976_asof_join_on.reference
test "00976_asof_join_on" do
TestRepo.query!("CREATE TABLE 00976_A(a UInt32, t UInt32) ENGINE = Memory")
Expand Down Expand Up @@ -411,8 +411,17 @@ defmodule Ecto.Integration.ClickHouseJoinsTest do
)
end

[[ch_version]] = TestRepo.query!("select version()").rows

expected_error =
if ch_version >= "25.2" do
~r/INVALID_JOIN_ON_EXPRESSION/
else
~r/NOT_IMPLEMENTED/
end

# SELECT A.a, A.t, B.b, B.t FROM A ASOF JOIN B ON A.a == B.b AND A.t < B.t OR A.a == B.b + 1 ORDER BY (A.a, A.t); -- { serverError 48 }
assert_raise Ch.Error, ~r/NOT_IMPLEMENTED/, fn ->
assert_raise Ch.Error, expected_error, fn ->
TestRepo.all(
from a in "00976_A",
join: b in "00976_B",
Expand Down
17 changes: 17 additions & 0 deletions test/test_helper.exs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,23 @@ Application.put_env(:ecto_ch, TestRepo,
show_sensitive_data_on_connection_error: true
)

clickhouse_available? =
case :httpc.request(:get, {~c"http://localhost:8123/ping", []}, [], []) do
{:ok, {{_version, _status = 200, _reason}, _headers, ~c"Ok.\n"}} ->
true

{:error, {:failed_connect, [{:to_address, _to_address}, {:inet, [:inet], :econnrefused}]}} ->
false
end

unless clickhouse_available? do
Mix.shell().error("""
ClickHouse is not detected! Please start the local container with the following command:

docker compose up -d clickhouse
""")
end

{:ok, _} = Ecto.Adapters.ClickHouse.ensure_all_started(TestRepo.config(), :temporary)

_ = Ecto.Adapters.ClickHouse.storage_down(TestRepo.config())
Expand Down
Loading