Clinker user guide · ← Route Nodes · Merge Nodes →

Split
and rejoin with Route and Merge

A Route sends each record down one or more named branches. A Merge joins branches, or Sources, back into one stream. Reorder the conditions, switch the mode, and watch where each order goes, including the ones whose condition can't be worked out.

01

RouteOrder matters, and a condition can be true, not true, or fail

- type: route
  name: classify
  input: orders
  config:
    mode: 
    conditions:
    default: standard
  • exclusive (default): conditions are checked top to bottom, and the first true one wins. The conditions after it are never checked, so an error further down never happens.
  • inclusive: the conditions are checked in order, all of them unless one fails, and the record goes down every branch whose condition is true, as a separate copy.
  • A condition that comes out null is "not true": the record moves on to the next one. If nothing is true, it takes the default branch.
  • A condition that fails (here, dividing by a quantity of 0) is neither true nor false. Under strategy: continue the record is dead-lettered and takes no branch at all, not even one already matched and not the default. Under fail_fast the run stops.
Watch order O5: its country is empty, and country != "US" is true for an empty country, because != never gives null. See where does a null go?
mode
strategy
conditions, in order (use the arrows to reorder)
default: standard

Each order

02

MergeJoining the branches back into one stream

A Merge brings the branches back together, here straight from the Route's ports (in a real pipeline there is usually a Transform on each branch first). It doesn't match records up: it passes along everything from every input. How the inputs are mixed depends on mode:

  • concat (default): all of the first input, then all of the second, in the order of inputs:. The same every run.
  • interleave: records pass on as they arrive from any input. Each input keeps its own order, but how the inputs mix can change from run to run.
  • interleave with interleave_seed: a mix that is the same every run, at the cost of reading every input into memory first. Meant for tests.
Inclusive routes make copies. A record that went down two branches comes out of the Merge twice. That is often what you want (a review queue and a flag list), but if the branches are rejoined for one output, use exclusive, or remove the copies afterwards.

All inputs must have the same columns; the Merge's columns come from its first input. A Merge never sorts: two sorted inputs concatenated are not one sorted stream. Put a sort_order on the Sink for that.

- type: merge
  name: rejoin
  inputs: 
  config:
    mode: 
mode
inputs, in order (the branches from section 01)
03

WiringHow the next node picks a branch

Port syntax

A node reads one branch with input: classify.big, and the default branch the same way: input: classify.standard. A Merge lists branches in inputs:.

The name shortcut

A node whose own name matches a branch can write input: classify, and it receives that branch. A Sink named big reading classify gets the big branch.

One branch, two readers

Several nodes can read the same branch; each gets every record on it.

Branch names

Use names that differ from each other and from default. Today a default with the same name as a condition is folded into that condition's branch without an error, so its records can't be told apart.