Combine tables
Every wire into a node is a named table, named by its handle. Nothing merges several wires on its own: the node’s formula says how, with three tools.
| Tool | What it does |
|---|---|
inputs().prop(handle) |
The table a wire carries, read-only |
table.find(column, value), table.findAll(column, value), table.rows() |
A lookup: the first matching row, every matching row, or all rows |
appendRows(table) |
Adds every row of a table, with its styles, to the node’s rows |
The first wire into a node has the handle input; each further wire takes a handle from its source node’s title, which you can rename on the wire’s Overview panel. inputs("prices") is a short form of inputs().prop("prices"). See Wires and named tables for how wires and handles work on the canvas.
What the first statement receives
Section titled “What the first statement receives”| Wires into the node | The first statement’s rows | Named tables |
|---|---|---|
| None | Empty | None |
| One | That wire’s rows | That wire, on its handle |
| Several | Empty | Every wire, on its own handle |
A node with several wires and no statement that reads them fails with a message naming the missing merge formula, so a missing merge is visible rather than silent.
Look a value up
Section titled “Look a value up”setProp("price", inputs().prop("prices").find("ISIN", prop("ISIN")).prop("price"))find(column, value)returns the first row, in table order, whose column equals the value, oremptywhen none matches.findAll(column, value)returns every matching row as a list, androws()every row.row.prop(name)reads a field of a table row. The value keeps the data styles of the cell it came from.- A miss writes an empty cell. To write something else on a miss, test the match first:
setProp("price", let( hit, inputs().prop("prices").find("ISIN", prop("ISIN")), if(empty(hit), -1, hit.prop("price"))))A let binding lives inside its statement, so each column you take from a lookup reads the table in its own setProp.
Lists of matching rows work with the list functions:
setProp("open_orders", inputs().prop("orders").findAll("account", prop("account")).count())setProp("open_amount", inputs().prop("orders").findAll("account", prop("account")).map(current.prop("amount")).sum())Merge shapes
Section titled “Merge shapes”Append two wires
Section titled “Append two wires”appendRows(inputs().prop("trades_eu"))appendRows(inputs().prop("trades_us"))The columns afterwards are the union of both tables; a column only one side has reads empty on the other side’s rows.
Enrich one wire from another by key
Section titled “Enrich one wire from another by key”appendRows(inputs().prop("trades"))setProp("price", inputs().prop("prices").find("ISIN", prop("ISIN")).prop("price"))setProp("priceDate", inputs().prop("prices").find("ISIN", prop("ISIN")).prop("asOf"))Enrich without overwriting a value the row has
Section titled “Enrich without overwriting a value the row has”appendRows(inputs().prop("trades"))if( empty(prop("currency")), setProp("currency", inputs().prop("reference").find("ISIN", prop("ISIN")).prop("currency")))Keep one-sided rows as well as matches
Section titled “Keep one-sided rows as well as matches”appendRows(inputs().prop("left"))appendRows(inputs().prop("right"))groupBy(prop("id"))setProp("id", prop("id").first())setProp("amount", prop("amount").filter(not(empty(current))).first())Both sides stack, then the key collapses them into one row per id. A key only one side has still gets its row, and where both sides carry a value the left one wins because it was appended first.
Match by position
Section titled “Match by position”appendRows(inputs().prop("a"))setProp("amount", inputs().prop("b").rows().at(rowIndex()).prop("amount"))at() past the end is empty, so a shorter b leaves amount empty on the trailing rows.
Aggregate several wires
Section titled “Aggregate several wires”appendRows(inputs().prop("a"))appendRows(inputs().prop("b"))groupBy(prop("ISIN"))setProp("ISIN", prop("ISIN").first())setProp("qty", prop("qty").sum())- A named table is read-only: statements write to the node’s rows, so
sortByandgroupByapply to the rows, not to a table. appendRowstakes a table, never a filtered list of rows, and stands on its own line, never insideif,do, oreach.- An appended row has no input row behind it, so an exception raised on it is filed against the output row, and its lineage points to the table row on the wire it came from.
- A table whose columns are unknown, because no schema describes the wire and no rows have loaded yet, accepts any column name; a column it turns out not to have matches nothing.
Joins in SQL
Section titled “Joins in SQL”When a join is easier to say in SQL, fromQuery reads named tables by their handles with .tables(…):
fromQuery(`SELECT t.*, p.priceFROM "trades" t LEFT JOIN "prices" p ON p.isin = t.isin`, "sql") .tables("trades", "prices")A query keeps no per-cell lineage or data styles. See Templates, queries, and scripts.