Closed hkrutzer closed 10 months ago
👋 @hkrutzer
The error comes from this part where we try to extract the types (for RowBinary encoding) from the Ecto schema https://github.com/plausible/ecto_ch/blob/36348a1a838f74efadd8346d0982c39e3079955a/lib/ecto/adapters/clickhouse/schema.ex#L229
Seems like we'd need to check for schema.__schema__(:type, __schema__(:field_source, field))
as well. Or would it be the other way around? Eh...
iex> Mix.install [:ecto, :ch]
iex> defmodule Stuff do
use Ecto.Schema
@primary_key false
schema "field_source" do
field :id, Ch, type: "String"
field :name, Ch, type: "String", source: :field_name
end
end
iex> Stuff.__schema__(:type, :name)
{:parameterized, Ch, :string}
iex> Stuff.__schema__(:type, :field_name) # this is what happens
nil
iex> Stuff.__schema__(:field_source, :name)
:field_name
iex> Stuff.__schema__(:field_source, :field_name)
nil
# seems like we'd need to do something like this unless we add our own reflection
iex> field = :field_name
iex> if reverse_source = Enum.find(Stuff.__schema__(:fields), fn other_field -> Stuff.__schema__(:field_source, other_field) == field end) do
Stuff.__schema__(:type, reverse_source)
end
{:parameterized, Ch, :string}
Not sure, I don't know how other adapters do this, but I couldn't easily find it. I guess they don't have to look up the type like ecto_ch has to?
Yes, other adapters don't need to do this kind of reflection.
https://github.com/plausible/ecto_ch/pull/137 should fix it. It's included in v0.3.1
release.
It's fixed, thanks very much!
I'm using the
source
field option to map a field to a differently named table column. This works when selecting data, but not when inserting data:Test:
Output