View Source Electric.Replication.Eval.Lookups (electric v0.6.1)

Summary

Functions

Given multiple possible function overloads (same name and arity), try to find a concrete implementation that matches the argument types.

Given multiple possible operator overloads (same name and arity), try to find a concrete implementation that matches the argument types.

Functions

Link to this function

pick_concrete_function_overload(choices, args, env)

View Source
@spec pick_concrete_function_overload(
  list(),
  [struct()],
  Electric.Replication.Eval.Env.t()
) ::
  {:ok, term()} | :error

Given multiple possible function overloads (same name and arity), try to find a concrete implementation that matches the argument types.

Rules for picking a function overload closely mimic those outlined in postgres documentation:

  1. Check if there is an overload where all variable types match exactly
  2. Check if only one overload remains based on implicit conversion rules (unknowns are considered always matching), discard those that cannot be applied even after implicit conversion
  3. Check if only one overload remains based on most exact type matches
  4. Keep overloads that accept most preferred types in each conversion spot
  5. If there are any unknowns, for each position first look for any overloads that accept string category, and if none found, check if all overloads accept the same type category. If that fails, keep all overloads, or pick any that don't accept picked category
  6. If there are both unknown and known arguments, and all known arguments have the same type category, assume unknowns have the same type category and look for overloads that fit.

If exactly one overload matched after those steps, pick it, otherwise fail.

Link to this function

pick_concrete_operator_overload(choices, args, env)

View Source
@spec pick_concrete_operator_overload(
  list(),
  [struct()],
  Electric.Replication.Eval.Env.t()
) ::
  {:ok, term()} | :error

Given multiple possible operator overloads (same name and arity), try to find a concrete implementation that matches the argument types.

Operators can only be 1 or 2-arity.

Rules for picking a operation overload closely mimic those outlined in postgres documentation, and mostly match pick_concrete_function_overload/3.