Open nathanielc opened 5 years ago
JavaScript uses the spread operator to do something similar:
rows.map(r => {...r, _value: r._value + 2})
What if you want to update multiple columns at the same time or insert a new one and update one? Possible to do?
|> map(fn:(r) => {r with {_value: r._value+2, foo:"bar"}}
You can comma separate as many as you need.
|> map(fn:(r) => {r with _value: r._value+2, foo:"bar"}
this is now supported for row functions #1303 , but type checking is not working generally within the language.
For the type bits see #1378
Seems like this can be closed in favor of https://github.com/influxdata/flux/issues/1378 ?
This issue has had no recent activity and will be closed soon.
Currently the map function can either merge the result with the group key or it can explicitly define all new columns. There is no way to generically say given an object update just these columns.
Other langauges for example OCaml have a
with
keyword like this:That function updates
r
with the_value
value column, all other columns ofr
are preserved whether they are part of the group key or not. Adding a similar syntax to Flux would remove the need to have themergeKey
boolean on map.Here is OCaml's description of the
with
record expression:http://caml.inria.fr/pub/docs/manual-ocaml/expr.html#htoc69