Responses
A response output returns its rows to whoever ran the job instead of writing them anywhere. Use it when a caller
needs an answer from the run itself: the campaigns for a dropdown, a count, or what happened to each row an apply
output sent. Over HTTP the rows are in the run's result; on the command line, --response FILE writes them.
connections:
ads: {provider: google_ads, ...}
caller: {provider: response} # built in, no keys: the run's caller
outputs:
- name: campaigns
connection: caller
step: matching_campaigns # or sql: SELECT ...
description: id, name and status of each matching campaign
max_rows: 500 # default 1000
A job's outputs are still required: a read job's outputs are response outputs.
What the caller gets
Each response output is one entry of the run's responses, by its name:
{"campaigns": {"rows": [{"id": "2233", "name": "Brand - Search", "status": "ENABLED"}],
"total": 1, "complete": true, "truncated": false}}
| Field | Meaning |
|---|---|
rows | The rows, in the SQL's order, at most max_rows |
total | How many rows the output had |
truncated | More rows than max_rows: the rest were counted, not returned |
complete | All the rows are there: false when truncated, or with a reason (below) |
reason | Why rows are missing, when complete is false for another reason than truncation |
expired | Over HTTP: the run is older than response.ttl, and its rows were cleared |
- Values are JSON. Dates, timestamps and decimals come as text; NaN and infinities (
clicks / impressionswith no impressions) come asnull; secret values are masked. - A response is never stored with the batch: its receipt has the count only, and a resumed batch computes it
again. Under
streamwright servethe rows stay with the run untilresponse.ttl(default one hour). - A run of several batches, or a fan-out over accounts, returns every batch's or account's rows, one after another. Add the account to the SELECT when the caller needs to tell them apart. Under serve a request gets only the rows of the batches it made: when its run first finishes another request's interrupted batch, that batch's rows stay out of its result.
- On the command line:
--response FILE(or-for stdout) writes one JSON line per row,{"output": "campaigns", "row": {...}}, and--summaryincludesresponses.
How many rows
A response is for what a caller reads at once: a list for a screen, a summary, an outcome per row. max_rows
caps it (default 1000); in a served job it is a fixed number, at most serve.yaml's response.inline_rows (default
10,000), which also caps what a fan-out run returns.
For larger results, write a file output, one file per request with {run_id} in its name, and let serve offer it as
a download. A job can do both: write the large file and return a one-row summary.
After an apply output
A response whose sql reads an apply output by name runs once that batch's rows were sent.
It reads the output's results: the rows sent, each with its outcome (status, error_code, error_message,
result JSON, row), the table an apply output's log: reads. The steps and the input table are still there, so
the response can cover every row the caller sent, including those the job decided not to send:
steps:
- name: skipped_campaigns # names the account already has
sql: SELECT i.name, e.id FROM input AS i JOIN existing_campaigns AS e USING (name)
- name: new_campaigns
sql: SELECT i.name AS "campaign.name", ... FROM input AS i ANTI JOIN existing_campaigns AS e USING (name)
outputs:
- name: create_campaigns # the apply output
connection: ads
step: new_campaigns
operation: {service: CampaignService, method: mutate_campaigns, arguments: {customer_id: "{{ config.customer_id }}"}}
- name: campaigns # one row per campaign of the request
connection: caller
sql: |
SELECT i.name,
CASE WHEN s.name IS NOT NULL THEN 'skipped'
ELSE coalesce(c.outcome.status, 'not_sent') END AS status,
coalesce(c.outcome.result->>'$.resource_name',
'customers/{{ config.customer_id }}/campaigns/' || s.id) AS resource_name,
c.outcome.error_code AS error_code,
c.outcome.error_message AS error_message
FROM input AS i
LEFT JOIN create_campaigns AS c ON c."campaign.name" = i.name
LEFT JOIN skipped_campaigns AS s ON s.name = i.name
ORDER BY i.name
{"campaigns": {"rows": [
{"name": "Brand - Search", "status": "applied", "resource_name": "customers/1234567890/campaigns/2233",
"error_code": null, "error_message": null},
{"name": "Generic - Search", "status": "failed", "resource_name": null,
"error_code": "DUPLICATE_CAMPAIGN_NAME", "error_message": "Duplicate name."},
{"name": "Old - Search", "status": "skipped", "resource_name": "customers/1234567890/campaigns/1980",
"error_code": null, "error_message": null}],
"total": 3, "complete": true, "truncated": false}}
- The results table is empty when the batch sent nothing, so every row can still be answered.
- Rejected rows that fail the run (
on_row_error: fail) still get their response. - When rows are missing,
completeis false andreasonsays why:
reason | When | The rows |
|---|---|---|
delivery-incomplete | A call was cut short (a timeout, a crash) | The outcomes so far |
not-delivered | The batch built rows of the apply output that this run did not send | The rows, without outcomes |
steps-not-built | A later run delivered the batch (held rows resent, or after a crash between commit and delivery): its steps are gone | None, unless the response reads only the results |
failed | The response's SQL could not run (logged) | None |
A request to streamwright serve builds and delivers its batch in one run, so its response covers every row.
See also
- Serving over HTTP: results, downloads and
response.inline_rows. - Reverse ETL: apply outputs and their results.
- Input payloads: the caller's rows, the
inputtable.