Berserk Docs
Tabular OperatorsOther Operators

fork

Executes multiple independent pipelines from a single source, producing multiple result tables.

Executes multiple independent pipelines from a single source, producing multiple result tables.

Each branch receives the same input and operates independently — filters, projections, and aggregations in one branch do not affect other branches. When all branches read the same table, Berserk uses a shared-scan optimization: segments are read and decompressed once, and each row is fanned out to all branch pipelines.

Use the Name=(...) syntax to label result tables. Semicolons (;) can also separate independent top-level queries, each producing its own result table.

Most tabular operators are supported inside fork branches, including where, summarize, project, extend, take, sort, top, distinct, parse, mv-expand, mv-apply, make-series, annotate, getschema, and render. The operators join and nested fork are not allowed inside branches. Semicolon-separated statements have no restrictions.

Syntax

fork (branch) (branch) ...

Execute parallel branches

Parameters

NameDescription
branchA query branch to execute on the input

Syntax

fork Name=(branch) Name=(branch) ...

Execute named parallel branches

Parameters

NameDescription
NameOptional name for the result table
branchA query branch to execute on the input

Examples

Example 1

datatable(warrior:string, weapon:string, voyages:long)[
  "Ragnar", "axe", 42,
  "Bjorn", "sword", 31,
  "Lagertha", "spear", 28,
  "Ivar", "bow", 35
]
| fork (where voyages > 30) (summarize avg(voyages) by weapon)

Result table 1:

warrior (string)weapon (string)voyages (long)
Bjornsword31
Ivarbow35
Ragnaraxe42

Result table 2:

weapon (string)avg_voyages (real)
axe42.0
bow35.0
spear28.0
sword31.0

Example 2

datatable(x:long)[
  1,
  2,
  3
]
| fork Totals = (count) Top = (take 2)

Result table 1:

Count (long)
3

Result table 2:

x (long)
1
2

On this page