plausible/ch

Can't cast `SimpleAggregateFunction(groupArrayArray, Array(DateTime('UTC')))`

hkrutzer opened this issue · 4 comments

This works:

type = Ecto.ParameterizedType.init(Ch, type: "SimpleAggregateFunction(groupArrayArray, Array(String))")
Ecto.Type.cast(type, ["asdf"])

This does not:

type = Ecto.ParameterizedType.init(Ch, type: "SimpleAggregateFunction(groupArrayArray, Array(DateTime('UTC')))")
Ecto.Type.cast(type, [~U[2022-11-24 11:57:23Z]])
** (FunctionClauseError) no function clause matching in Ecto.Type.cast_fun/1

    The following arguments were given to Ecto.Type.cast_fun/1:

        # 1
        {:datetime, "UTC"}

    Attempted function clauses (showing 10 out of 25):

        defp cast_fun(:integer)
        defp cast_fun(:float)
        defp cast_fun(:boolean)
        defp cast_fun(:map)
        defp cast_fun(:string)
        defp cast_fun(:binary)
        defp cast_fun(:id)
        defp cast_fun(:binary_id)
        defp cast_fun(:any)
        defp cast_fun(:decimal)
        ...
        (15 clauses not shown)

    (ecto 3.10.3) lib/ecto/type.ex:761: Ecto.Type.cast_fun/1
    (ecto 3.10.3) lib/ecto/type.ex:788: Ecto.Type.cast_fun/1
    (ecto 3.10.3) lib/ecto/type.ex:758: Ecto.Type.cast/2

This also does not:

type = Ecto.ParameterizedType.init(Ch, type: "SimpleAggregateFunction(groupArrayArray, Array(UInt8))")
Ecto.Type.cast(type, [1,11,1,1,1])
** (UndefinedFunctionError) function :u8.cast/1 is undefined (module :u8 is not available)
    :u8.cast(1)
    (ecto 3.10.3) lib/ecto/type.ex:1257: Ecto.Type.array/4

👋 @hkrutzer

Thank you! I've added a failing test in #118 and will try to fix it in the same PR.

The problem was with casting arrays of Ch types, fixed in #118

I've published v0.2.1 with that fix.

That was very quick, thank you!