Blend
POST /projects/{uid}/branches/{branch}/blend answers a question the model alone cannot: revenue from the warehouse beside a budget someone uploaded, store names from a list ops maintains, only the regions on a target list.
curl -s http://127.0.0.1:3699/projects/shop/branches/main/blend \
-H "Content-Type: application/json" \
-d '{
"spec": {"projections": [{"field": "Region"}, {"field": "Revenue"}, {"field": "budget.budget", "alias": "Budget"}]},
"datasets": [{"id": "ds_99a09f6e1d595492", "as": "budget"}],
"blend": [{"join": "budget", "to": "model", "on": [{"left": "Region", "right": "budget.region"}], "kind": "enrich"}]
}'
{
"columns": [{"name": "Region", "type": "string", "arrow_type": "Utf8"},
{"name": "Revenue", "type": "decimal", "arrow_type": "Decimal128(38, 2)"},
{"name": "Budget", "type": "integer", "arrow_type": "Int64"}],
"rows": [["MW", "10.86", 12], ["NE", "24.85", 30], ["SO", null, 5]],
"total": 3,
"offset": 0,
"complete": true,
"cache": "miss",
"model": {"result": "r-20261128-9f27613695a3b7c721c4",
"sql": "SELECT\n\tT0.\"region\" AS \"__m0\",\n\tsum(T0.\"revenue\") AS \"__m1\"\nFROM\n\torders T0\nGROUP BY\n\tT0.\"region\""},
"datasets": [{"id": "ds_99a09f6e1d595492", "version": 1}]
}
SO has a budget and no sales, and still shows: budget against actual keeps rows from both sides.
How it runs
- The spec is split. A projection whose field is
alias.columnof an attached dataset is the dataset’s; every other projection, and every model key a join names, is the model’s. - The model’s part is one query. The server plans it against the branch and runs it on the warehouse exactly as
/rundoes: under the request’scontext, so row-level security applies; with the deployed credential and the request’sconnectionover it; from the result cache when it answers.model.sqlis the statement, andmodel.resultthe run’s id, whichGET /results/{id}reads. - The joins run in the server, in its embedded DuckDB, over the model’s rows and each attached dataset’s live version, exactly as
blendsays.
It is not federation. The warehouse runs one planned statement on one datasource; the datasets are rows the server keeps; nothing is sent from one to the other. The model, its catalog and its plans do not know a dataset exists: a model plans byte for byte the same SQL whether datasets exist or not, and a dataset column is reachable only under the alias a blend request gives it. The model’s part is planned with each projection aliased __m0, __m1, … so its columns can be found; the answer carries the names the spec asked for.
The request
| Field | Is |
|---|---|
spec | a query spec whose projections may name alias.column. Projections, filters and the other spec keys apply to the model’s part; calculations are refused for now |
datasets | [{"id", "as"}]: each dataset attached, under an alias |
blend | [{"join", "to", "on", "kind"}]: how each attached dataset joins |
context | the security context the model’s part is planned under |
connection | connection settings and a credential for the model’s part, as /run takes them |
wait | seconds to wait for the model’s part, as /run takes it |
fresh | run the model’s part even though a stored result would answer |
cache_ttl | how long the model’s part’s result answers, as /run takes it: seconds, 10s, 30m, 1h, 10d; 0 keeps nothing, -1 never expires. See the cache and the API reference |
offset, limit | page the answer: limit 1 to 100,000, default 10,000. The spec’s own limit bounds the model’s statement |
An alias is lower-case letters, digits and _, starting with a letter or _, at most 64 characters, and not model. An alias that is also a table, a field or a uid prefix in the model is refused, so a bare name never means a dataset:
{"error": {"class": "Invalid", "message": "'sales' is a name in the model, so it cannot be a dataset's alias: a bare name never means a dataset"}}
A dataset is found in the route’s project, and its live version is what is joined. One with no output yet is 404, as is one that is not there: no dataset ds_0000000000000000 in project shop.
A join
{"join": "budget", "to": "model", "on": [{"left": "Region", "right": "budget.region"}], "kind": "enrich"}
joinis an attached alias;toismodelor another alias. Every attached dataset is joined exactly once, and the joins connect each one to the model with no loop; anything else is refused, naming it. Nothing is joined for you: there is no join found from names, relationships or roles.onpairs a key on thetoside (a model field as the spec names it, oralias.column) with one of the dataset’s (alias.column). Two keys whose types do not widen to one are refused.kindisfilterorenrich.
Every model key a join names must be projected. The dataset is at that grain, and the answer is too; a key planned only to join on would make the warehouse send rows finer than the answer, to be added up again:
{"error": {"class": "Invalid", "message": "'Region' joins 'budget' to the model, so ask for it too: add {\"field\": \"Region\"} to the projections. The dataset is at that grain, and the answer is joined on it"}}
filter
Keeps the rows of the side it joins whose keys the dataset has, and brings no column:
{"spec": {"projections": [{"field": "Region"}, {"field": "Revenue"}]},
"datasets": [{"id": "ds_99a09f6e1d595492", "as": "budget"}],
"blend": [{"join": "budget", "to": "model", "on": [{"left": "Region", "right": "budget.region"}], "kind": "filter"}]}
"rows": [["MW", "10.86"], ["NE", "24.85"]]
A filter needs keys, and projecting one of its columns is refused: 'budget' is a filter, which brings no column; 'budget.budget' needs an enrich.
enrich
Brings the dataset’s columns the spec asks for. What it does depends on their roles:
Only dimensions: a look-up. Each row gets the dataset’s values for its key, and a row with no match keeps nulls. The dataset must be unique on its keys:
{"spec": {"projections": [{"field": "Store ID"}, {"field": "stores.store_name", "alias": "Store"}, {"field": "Revenue"}]},
"datasets": [{"id": "ds_aad92d187e281d13", "as": "stores"}],
"blend": [{"join": "stores", "to": "model", "on": [{"left": "Store ID", "right": "stores.store_id"}], "kind": "enrich"}]}
"rows": [[101, "Maple Street Market", "24.26"], [102, "Harbor Fresh", "0.59"], [201, "Prairie Grocers", "8.97"], [202, "Lakeside Foods", "1.89"]]
{"error": {"class": "Unprocessable", "message": "'m' is not unique on its keys (1 repeat), so joining it would multiply rows; aggregate it in its recipe, or ask for a measure of it"}}
With measures: budget against actual. The dataset is summed to its keys and joined to the model’s rows keeping rows from both sides, as the first example shows. It joins to model only, its measures must be numbers, and every dimension the request asks for must be one of its keys (or come from a look-up on those keys), or its values would repeat:
{"error": {"class": "Invalid", "message": "'Category' is asked for, and 'budget' is not set beside the model by it: every dimension of a request with budget's measures must be one of its keys (Region), or its values would repeat"}}
A look-up joined to such a dataset on its keys is applied after, on the keys both sides now share.
With no keys: a cross join. "on": [] sets each row of the dataset beside every row, as it is: a rate, a target, a few scenarios. At most 1,000,000 rows result.
{"spec": {"projections": [{"field": "Region"}, {"field": "Revenue"}, {"field": "fx.currency"}, {"field": "fx.rate"}]},
"datasets": [{"id": "ds_d068f8a49130d344", "as": "fx"}],
"blend": [{"join": "fx", "to": "model", "on": [], "kind": "enrich"}]}
"rows": [["MW", "10.86", "EUR", "0.92"], ["NE", "24.85", "EUR", "0.92"]]
A dataset column with no alias in the projection is named as written, fx.rate.
The answer
| Field | Is |
|---|---|
columns, rows | the answer, in the order of the spec’s projections; rows is this page |
total, offset, complete | rows in all, where this page starts, and whether it reaches the end |
cache | hit when the same blend was answered before, miss otherwise |
model | the model part’s result id and sql |
datasets | each dataset read and the version it was |
A blend is kept by the model’s run, each dataset’s id and version, and the joins, so a hit is the same question over the same data. A new run of the model’s part (fresh, an expired cache_ttl, a cache invalidation) is a new question, and a new version of a dataset forgets the blends that read it. A project keeps its 64 most recent blends.
While the model’s part is still running past wait, 202:
{"status": "running", "model": {"result": "r-…"},
"message": "the model's part is still running in the warehouse; send the same request again, and it is joined to the run"}
A model part that failed on the warehouse is 422 Unprocessable, the model's part did not succeed: ….
Access
A blend reads the datasets it attaches; which datasets a caller may attach is your application’s to decide, as which projects it may query is. The model’s part is planned under the context you send, so row-level security holds for it; a dataset has no policies of its own. See securing access.