From bb6475beba86612663ec2c5951dd175cdb072f9e Mon Sep 17 00:00:00 2001 From: ruslandoga Date: Thu, 24 Jul 2025 14:25:08 +0300 Subject: [PATCH 1/2] named tuples insert --- test/ecto/integration/schema_test.exs | 53 +++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 test/ecto/integration/schema_test.exs diff --git a/test/ecto/integration/schema_test.exs b/test/ecto/integration/schema_test.exs new file mode 100644 index 0000000..294b14c --- /dev/null +++ b/test/ecto/integration/schema_test.exs @@ -0,0 +1,53 @@ +defmodule Ecto.Integration.SchemaTest do + use Ecto.Integration.Case + import Ecto.Query, only: [from: 2] + alias Ecto.Integration.TestRepo + + setup do + TestRepo.query!(""" + create table schema_test ( + id UInt64, + array_tuple_dynamic Array(Tuple(a LowCardinality(String), b LowCardinality(String), c LowCardinality(String), d Dynamic)) + ) ENGINE = MergeTree ORDER BY tuple() + """) + + on_exit(fn -> TestRepo.query!("drop table schema_test") end) + end + + defmodule Schema do + use Ecto.Schema + + @primary_key false + schema "schema_test" do + field :id, Ch, type: "UInt64" + + # TODO preserve names in named tuples + field :array_tuple_dynamic, {:array, Ch}, + type: + "Tuple(LowCardinality(String), LowCardinality(String), LowCardinality(String), Dynamic)" + end + end + + describe "insert_all/3" do + test "with array of tuples containing dynamic type" do + TestRepo.insert_all( + Schema, + [ + %{id: 1, array_tuple_dynamic: [{"a1", "b1", "c1", "d1"}]}, + %{id: 2, array_tuple_dynamic: []} + ], + # TODO remove this workaround when Ch preserves names in named tuples + settings: [input_format_with_types_use_header: 0] + ) + + assert TestRepo.all( + from s in Schema, + select: map(s, [:id, :array_tuple_dynamic]), + order_by: s.id + ) == [ + %{id: 1, array_tuple_dynamic: [{"a1", "b1", "c1", "d1"}]}, + %{id: 2, array_tuple_dynamic: []} + ] + end + end +end From 1abf711fa682bac7732ef201b42e6bfa3321fcfe Mon Sep 17 00:00:00 2001 From: ruslandoga Date: Thu, 24 Jul 2025 14:26:01 +0300 Subject: [PATCH 2/2] exclude dynamic tests in older ch --- test/ecto/integration/schema_test.exs | 1 + test/test_helper.exs | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/test/ecto/integration/schema_test.exs b/test/ecto/integration/schema_test.exs index 294b14c..e714f40 100644 --- a/test/ecto/integration/schema_test.exs +++ b/test/ecto/integration/schema_test.exs @@ -29,6 +29,7 @@ defmodule Ecto.Integration.SchemaTest do end describe "insert_all/3" do + @tag :dynamic test "with array of tuples containing dynamic type" do TestRepo.insert_all( Schema, diff --git a/test/test_helper.exs b/test/test_helper.exs index fbe7916..031ecf6 100644 --- a/test/test_helper.exs +++ b/test/test_helper.exs @@ -46,8 +46,8 @@ exclude = if ch_version >= "25" do [] else - # Time type is not supported in older ClickHouse versions we have in the CI - [:time] + # Time and Dynamic types are not supported in older ClickHouse versions we have in the CI + [:time, :dynamic] end ExUnit.start(exclude: exclude)