ash_sqlite: Error when querying on an inline code calculation

Hey there! I'm trying out ash_sqlite on a toy project, and I'm encountering an issue which seems to boil down to querying a calculation defined as inline elixir code. Here is the error (full stacktrace in the next post), followed by some relevant code. Happy to add more context if required.
* ** (UndefinedFunctionError) function Ash.Resource.Calculation.Function.expression/2 is undefined or private
(ash 3.5.21) Ash.Resource.Calculation.Function.expression([fun: &BlueBox.Events.Event.calculation_0_generated_9B4035288DB6056F8A43EB5D284DE007/2], %Ash.Resource.Calculation.Context{actor: nil, tenant: nil, authorize?: true, tracer: nil, domain: nil, resource: nil, type: Ash.Type.String, constraints: [trim?: true, allow_empty?: false], arguments: %{}, source_context: %{private: %{authorize?: true, actor: nil}}})
(ash_sql 0.2.80) lib/expr.ex:1457: AshSql.Expr.default_dynamic_expr/6
...
* ** (UndefinedFunctionError) function Ash.Resource.Calculation.Function.expression/2 is undefined or private
(ash 3.5.21) Ash.Resource.Calculation.Function.expression([fun: &BlueBox.Events.Event.calculation_0_generated_9B4035288DB6056F8A43EB5D284DE007/2], %Ash.Resource.Calculation.Context{actor: nil, tenant: nil, authorize?: true, tracer: nil, domain: nil, resource: nil, type: Ash.Type.String, constraints: [trim?: true, allow_empty?: false], arguments: %{}, source_context: %{private: %{authorize?: true, actor: nil}}})
(ash_sql 0.2.80) lib/expr.ex:1457: AshSql.Expr.default_dynamic_expr/6
...
This is invoked as Event |> Ash.Query.filter(text_data == "asd") |> Ash.read, where text_data is defined as follow:
calculate :text_data, :string, fn records, _context ->
Enum.map(records, fn event ->
inspect(event.data)
end)
end
calculate :text_data, :string, fn records, _context ->
Enum.map(records, fn event ->
inspect(event.data)
end)
end
(the point is to have quick-and-dirty full text search on the content of a json data payload). Any guess on what could be happening here?
Solution:
You can't filter on calculations that don't define an expression
Jump to solution
5 Replies
Georges
GeorgesOP•4mo ago
Full stack trace:
* ** (UndefinedFunctionError) function Ash.Resource.Calculation.Function.expression/2 is undefined or private
(ash 3.5.21) Ash.Resource.Calculation.Function.expression([fun: &BlueBox.Events.Event.calculation_0_generated_9B4035288DB6056F8A43EB5D284DE007/2], %Ash.Resource.Calculation.Context{actor: nil, tenant: nil, authorize?: true, tracer: nil, domain: nil, resource: nil, type: Ash.Type.String, constraints: [trim?: true, allow_empty?: false], arguments: %{}, source_context: %{private: %{authorize?: true, actor: nil}}})
(ash_sql 0.2.80) lib/expr.ex:1457: AshSql.Expr.default_dynamic_expr/6
(ash_sql 0.2.80) lib/expr.ex:1782: AshSql.Expr.default_dynamic_expr/6
(ash_sql 0.2.80) lib/expr.ex:1183: AshSql.Expr.default_dynamic_expr/6
(ash_sql 0.2.80) lib/filter.ex:38: anonymous fn/2 in AshSql.Filter.add_filter_expression/2
(elixir 1.18.4) lib/enum.ex:2546: Enum."-reduce/3-lists^foldl/2-0-"/3
(ash_sqlite 0.2.11) lib/data_layer.ex:1902: AshSqlite.DataLayer.filter/4
(ash 3.5.21) lib/ash/query/query.ex:4431: Ash.Query.maybe_filter/3
(ash 3.5.21) lib/ash/query/query.ex:4184: Ash.Query.data_layer_query/2
(ash 3.5.21) lib/ash/actions/read/read.ex:633: anonymous fn/8 in Ash.Actions.Read.do_read/5
(ash 3.5.21) lib/ash/actions/read/read.ex:1366: Ash.Actions.Read.maybe_in_transaction/3
(ash 3.5.21) lib/ash/actions/read/read.ex:330: Ash.Actions.Read.do_run/3
(ash 3.5.21) lib/ash/actions/read/read.ex:89: anonymous fn/3 in Ash.Actions.Read.run/3
(ash 3.5.21) lib/ash/actions/read/read.ex:88: Ash.Actions.Read.run/3
(ash 3.5.21) lib/ash.ex:2760: Ash.read/2
* ** (UndefinedFunctionError) function Ash.Resource.Calculation.Function.expression/2 is undefined or private
(ash 3.5.21) Ash.Resource.Calculation.Function.expression([fun: &BlueBox.Events.Event.calculation_0_generated_9B4035288DB6056F8A43EB5D284DE007/2], %Ash.Resource.Calculation.Context{actor: nil, tenant: nil, authorize?: true, tracer: nil, domain: nil, resource: nil, type: Ash.Type.String, constraints: [trim?: true, allow_empty?: false], arguments: %{}, source_context: %{private: %{authorize?: true, actor: nil}}})
(ash_sql 0.2.80) lib/expr.ex:1457: AshSql.Expr.default_dynamic_expr/6
(ash_sql 0.2.80) lib/expr.ex:1782: AshSql.Expr.default_dynamic_expr/6
(ash_sql 0.2.80) lib/expr.ex:1183: AshSql.Expr.default_dynamic_expr/6
(ash_sql 0.2.80) lib/filter.ex:38: anonymous fn/2 in AshSql.Filter.add_filter_expression/2
(elixir 1.18.4) lib/enum.ex:2546: Enum."-reduce/3-lists^foldl/2-0-"/3
(ash_sqlite 0.2.11) lib/data_layer.ex:1902: AshSqlite.DataLayer.filter/4
(ash 3.5.21) lib/ash/query/query.ex:4431: Ash.Query.maybe_filter/3
(ash 3.5.21) lib/ash/query/query.ex:4184: Ash.Query.data_layer_query/2
(ash 3.5.21) lib/ash/actions/read/read.ex:633: anonymous fn/8 in Ash.Actions.Read.do_read/5
(ash 3.5.21) lib/ash/actions/read/read.ex:1366: Ash.Actions.Read.maybe_in_transaction/3
(ash 3.5.21) lib/ash/actions/read/read.ex:330: Ash.Actions.Read.do_run/3
(ash 3.5.21) lib/ash/actions/read/read.ex:89: anonymous fn/3 in Ash.Actions.Read.run/3
(ash 3.5.21) lib/ash/actions/read/read.ex:88: Ash.Actions.Read.run/3
(ash 3.5.21) lib/ash.ex:2760: Ash.read/2
Solution
ZachDaniel
ZachDaniel•4mo ago
You can't filter on calculations that don't define an expression
ZachDaniel
ZachDaniel•4mo ago
Inline function calculations don't
Georges
GeorgesOP•4mo ago
Ah. Yes, now that I think for 3 seconds, how would that work
Georges
GeorgesOP•4mo ago
thanks 🙂

Did you find this page helpful?