Transform Calculate

A calculate transformation generates a new column by computing some operations.

Calculate properties

Property Type Description
calculate ExprString A filter expression.
as String (Required) A new field name.
groupby Array[String] (Optional) Nominal fields to group elements by.

Caculate expression

Use datum to refer to each row item. To access a field (say, cost), you can use datum.cost. Filter expressions allow basic JavaScript expressions.

Usage pattern

JSON

{
  ...
  "transform" : [
    {
      "calculate": "datum.cost + datum.expense",
      "as": "net_cost",
    },
  ]
  ...
}

JavaScript

let stream = new Erie.Stream();
...
let calc = new Erie.Calculate("datum.cost + datum.expense", "net_cost"); // filter expression and new field name
// alt) let calc = new Erie.Calculate();
//      calc.calculate("datum.cost + datum.expense");
//      calc.as("net_cost");
stream.transform.add(calc);
...
© Hyeok Kim