Macaw.Data.Ops (macaw_data v0.12.0)
View SourceWhat a derived source's stored function calls to reach the registered operations (spec/04 §6): an aggregate of values, or a transform over rows, by name, with the options a design's node would carry.
fn %{hosts: rows} ->
p95 = rows |> Enum.map(& &1.cpu) |> Macaw.Data.Ops.aggregate!("quantile", %{p: 0.95})
rows
|> Macaw.Data.Ops.transform!("filter", %{field: "cpu", test: :gte, value: p95})
|> Macaw.Data.Ops.transform!("sort", %{field: "cpu", order: :descending})
endIn a stored function the name is a literal string the checker holds to the engine's
registry, and the call is compiled against that registry (__run__/5), so it runs
exactly what was checked. Called from a host's own code, the functions use
macaw_data's own package.
Errors are values (spec/00 §5). aggregate/2,3 answers {:ok, value} and
transform/2,3 {:ok, rows}, or {:error, faults}: Macaw.Data.Operations' faults
(spec/04 §3.1), worded by format_error/1.
Where a fault is placed (spec/04 §6, macaw_data#139): a transform call runs a
one-step pipeline, so its faults are at that step, [0, key] for an option and
[0, "op"] for its name or an op option. An aggregate call is no step, so its faults
name none: [] for an unknown name, [key] for an option, ["values"] for a reading.
Options that are no map are at ["options"] either way.
In a stored function a fault's atoms are spelled as its literals are (spec/02 §6.3), so it matches a
reason with its own words. aggregate!/2,3 and transform!/2,3 answer the value alone,
or raise Macaw.Data.Error with the faults' words, which the runner reports as :raised.
iex> Macaw.Data.Ops.aggregate([3, nil, 1, 2], "median")
{:ok, 2}
iex> Macaw.Data.Ops.transform!([%{v: 2}, %{v: 1}], "sort", %{field: :v})
[%{v: 1}, %{v: 2}]
iex> Macaw.Data.Ops.aggregate(["a"], "sum")
{:error, [{["values"], {:reads, :number}}]}
iex> Macaw.Data.Ops.aggregate([1, 2], "mode")
{:error, [{[], {:unknown, :aggregate, "mode"}}]}
iex> Macaw.Data.Ops.transform([%{v: 1}], "mode")
{:error, [{[0, "op"], {:unknown, :transform, "mode"}}]}
Summary
Functions
As aggregate/3 with no options.
The named aggregate of values, nils dropped, with its options: {:ok, value} or
Macaw.Data.Operations.aggregate/4's {:error, faults}, which name no step: [] for
an unknown name, [key] for an option, ["values"] for a reading.
As aggregate/2, the value alone, raising Macaw.Data.Error naming every fault.
As aggregate/3, the value alone, raising Macaw.Data.Error naming every fault.
A fault in words, Macaw.Data.Operations.format_error/1's, its reason read back from
the spellings a stored function holds it in.
As transform/3 with no options.
The named transform run over rows with options, {:ok, rows} its answer as rows, or
Macaw.Data.Operations.apply/4's {:error, faults} of its one step: [0, key] for an
option, [0, "op"] for an unknown name. Options that name an op are
{[0, "op"], {:invalid_for, name}}: the name is the op.
As transform/2, the rows alone, raising Macaw.Data.Error naming every fault.
As transform/3, the rows alone, raising Macaw.Data.Error naming every fault.
Functions
@spec aggregate(Enumerable.t(), String.t()) :: {:ok, term()} | {:error, [Macaw.Data.Operations.fault()]}
As aggregate/3 with no options.
@spec aggregate(Enumerable.t(), String.t(), map()) :: {:ok, term()} | {:error, [Macaw.Data.Operations.fault()]}
The named aggregate of values, nils dropped, with its options: {:ok, value} or
Macaw.Data.Operations.aggregate/4's {:error, faults}, which name no step: [] for
an unknown name, [key] for an option, ["values"] for a reading.
@spec aggregate!(Enumerable.t(), String.t()) :: term()
As aggregate/2, the value alone, raising Macaw.Data.Error naming every fault.
@spec aggregate!(Enumerable.t(), String.t(), map()) :: term()
As aggregate/3, the value alone, raising Macaw.Data.Error naming every fault.
@spec format_error(Macaw.Data.Operations.fault()) :: String.t()
A fault in words, Macaw.Data.Operations.format_error/1's, its reason read back from
the spellings a stored function holds it in.
iex> Macaw.Data.Ops.format_error({[0, "n"], "required"})
"step 1, n: is required"
@spec transform(Macaw.Data.Table.source() | Macaw.Data.Table.t(), String.t()) :: {:ok, [map()]} | {:error, [Macaw.Data.Operations.fault()]}
As transform/3 with no options.
@spec transform(Macaw.Data.Table.source() | Macaw.Data.Table.t(), String.t(), map()) :: {:ok, [map()]} | {:error, [Macaw.Data.Operations.fault()]}
The named transform run over rows with options, {:ok, rows} its answer as rows, or
Macaw.Data.Operations.apply/4's {:error, faults} of its one step: [0, key] for an
option, [0, "op"] for an unknown name. Options that name an op are
{[0, "op"], {:invalid_for, name}}: the name is the op.
@spec transform!(Macaw.Data.Table.source() | Macaw.Data.Table.t(), String.t()) :: [ map() ]
As transform/2, the rows alone, raising Macaw.Data.Error naming every fault.
@spec transform!(Macaw.Data.Table.source() | Macaw.Data.Table.t(), String.t(), map()) :: [map()]
As transform/3, the rows alone, raising Macaw.Data.Error naming every fault.