# Combine sources with extracts and pivot on the server

> Query the historian and the alarms together in the Analytics workspace - read each source into an extract of your own session (with your read rights), join them with the source "Extracts (this session)", export the result, and group a result too large for the browser with "Pivot on the server" - with the session limits, the server-wide cap of sessions and its memory, who may use it, the audit records and the HTTP routes.

Product: eaxScada · Type: How-to guide · Editions: Pro, Enterprise
Source: https://eaxware.com/docs/eaxscada/how-to/combine-sources-with-extracts/
Verified against commit 4e830ea.

## Goal

Answer a question that needs two sources at once, for example "for each temperature alarm, how many samples of its tag were above the alarm's setpoint over three days", which joins the historian's samples to the alarm definitions. And, when a result is larger than the browser shows, group the whole of it on the server.

A query in the **Analytics** tab reads one source. An **extract** copies one relation of a source, over a time window, into **your own session** on the server; a query with the source **Extracts (this session)** can then join several extracts. Pro and Enterprise.

You need the right `analytics`, and a tablet or a computer ([Analyse data in the Analytics workspace](/docs/eaxscada/how-to/analyse-data-in-the-analytics-workspace/)).

**An extract reads as you, into a session only you see.** Each extract is read through the same secured path as a query: your tag read rights decide which rows exist, the time window is required, and the tag scope can only narrow. A user allowed only `Plant/A/>` gets area A's rows in the extract and nothing of area B. Another user never sees your extracts, your list or your results: for them they do not exist. The session is held in the server's memory, with no file, network or extension access; it ends when you drop it or leave it unused. Nothing here writes a tag or sends a command.

**Diagram: The analytics read path and its entries** (system architecture)

An analytics query, an export job and an extract all read through the same read path of the eaxScada server: the SQL guard, the read rights below the relations, the bound time window and a transaction that is always rolled back. An export writes its file on the server; an extract fills the user's own in-memory session, which a query over extracts then reads with its own guard. Every entry is for a signed-in person with the analytics right.

**Parts**

- **eaxScada server** (trust boundary)
- **Analyst** (person or role): signed in, with the analytics right
- **Route checks** (check or decision, inside eaxScada server): a person: no API token, no AI account
- **Query** (service or process, inside eaxScada server): 1 per user, 2 per server
- **Export job** (service or process, inside eaxScada server): one per user
- **Extract** (service or process, inside eaxScada server): one relation, a time window
- **The read path** (check or decision, inside eaxScada server): SQL guard, read rights below the relations, bound time window, always rolled back
- **Export file** (file or document, inside eaxScada server): written by the server, owner only
- **Historian** (data store, inside eaxScada server): and the alarms
- **Your session** (data store, inside eaxScada server): in memory; no file, network, extension

**Connections**

- **Analyst → Route checks** (data or telemetry). The analyst calls the analytics routes of the server.
- **Route checks → Analyst** (refusal). Refused when not signed in, with user security off, in an edition without analytics, for an API token, for the AI co-pilot account, without the analytics right, or with the engine off. A second query of the same user, a third on the server, a second export of the same user and a new extract session past the server-wide cap are refused too.
- **Route checks → Query** (data or telemetry)
- **Route checks → Export job** (data or telemetry). An export reads the whole result again on the server and writes a CSV, Excel or Parquet file.
- **Route checks → Extract** (data or telemetry)
- **Route checks → Your session** (data or telemetry). A query over Extracts (this session) does not take the read path: it runs in the user's session with its own guard, which names the user's extracts only, as one SELECT in a transaction that is always rolled back.
- **Query → The read path** (data or telemetry)
- **Export job → The read path** (data or telemetry)
- **Extract → The read path** (data or telemetry)
- **Historian → The read path** (data or telemetry). The read path reads the historian and the alarms for the user's readable tags only.
- **The read path → Export file** (data or telemetry). The server writes the export file from the secured rows; the SQL never writes a file. It is kept for analytics.export.keep and then deleted.
- **The read path → Your session** (data or telemetry). An extract's rows are read as the user into the user's own in-memory session.

The pivot is written in the browser as a GROUP BY query and runs as a normal query.

Three entries, one read path: what you may not read never reaches a result, a file or an extract.

## 1. Add the extracts

1. Open **Analytics and Reports > Analytics**. The **Extracts (this session)** panel is beside the editor; at 1024 pixels wide and below, open it with the toolbar's **Extracts** button.
2. Click **Add extract** and fill in:
   - **Source** and **Relation**: **Historian** `samples`, or **Alarms** `alarm_events` or `alarm_definitions`;
   - **Time window** (required): a preset or **Custom** with **From** and **To**;
   - **Tag scope** (optional): tag paths or patterns separated by commas (`>` matches everything below a folder); empty means every tag. Your read rights apply on top;
   - **Name in queries**: lower-case letters, digits and `_`, starting with a letter (at most 41 characters, not a reserved word such as `samples` or `select`, not taken in this session). Your queries read the extract under this name.
3. Click **Add extract**. The server reads the relation, as you, and says how many rows it holds ("Extract reactor_temps: N rows.").
4. Add the other extracts the same way, for example `alarm_defs` from **Alarms** `alarm_definitions`.
[Image: The dialog "Add an extract": "The server reads the relation in the window as you, into this session only. Other users never see it; it is dropped when unused for a while." Source Historian, Relation samples, Time window Custom from 11/02/2026 12:00 AM to 11/05/2026 12:00 AM, Tag scope Plant/Reactor1/Temperature, Plant/Reactor2/Temperature with its hint, Name in queries reactor_temps with its hint, and the buttons Cancel and Add extract.]
[Image: The same dialog in the dark theme.]

An extract: one relation of one source, over a window, read with your rights.
The panel lists your extracts in the data grid (name, source, relation, window, rows, size) with **Use** (puts a query of it in the editor) and **Drop** (asks first: "Its rows leave this session. The source data stays where it is."). **Drop all** empties the session. One line sums up the session against its limits: "2 of 8 extracts · 4,249 of 2,000,000 rows · 310.6 KiB of 512 MiB · idle expiry in 30 min". An extract that left out tags your rights hide carries a marker in the grid, and the chip "1 extract with hidden tags" filters to it; hidden tags are counted, never named.

## 2. Query across the extracts

1. Set **Source** to **Extracts (this session)**. There is no time window: "Over extracts: each extract has its own time window."
2. Write one `SELECT` that names your extracts as tables. The editor completes the extract names and their columns, and the quality helpers work as usual:

   ```sql
   SELECT d.name AS alarm, d.tag_path, d.setpoint,
          count(*) AS samples,
          sum(CASE WHEN t.value > d.setpoint THEN 1 ELSE 0 END) AS above_setpoint,
          round(avg(t.value), 2) AS avg_value,
          agg_quality(t.quality_class) AS quality_class
   FROM reactor_temps t
   JOIN alarm_defs d ON d.tag_path = t.tag_path
   GROUP BY d.name, d.tag_path, d.setpoint
   ORDER BY d.name
   ```

3. **Run** (**Ctrl+Enter**). The result has the same grid, quality markers, chart and limits as any query.
[Image: The Analytics tab with the source Extracts (this session) and the note "Over extracts: each extract has its own time window." The editor holds the query above, joining reactor_temps and alarm_defs; the chips under it say "2 rows in 16 ms" and "1 uncertain". The Extracts (this session) panel on the right shows "2 of 8 extracts · 4,249 of 200,000 rows · 310.6 KiB of 512 MiB · idle expiry in 30 min" and a grid with reactor_temps (Historian, samples) and alarm_defs (Alarms, alarm_definitions), each with Use and Drop.]
[Image: The same join over extracts in the dark theme.]

The historian and the alarm definitions joined in one query. The quality travels through the join: one row is uncertain. (This test server had a lower row limit than the default.)
A query over extracts reads only your extracts: their names are the only tables, and qualified names, table functions, files and the stored tables are refused (`422`). You can save it as a saved query; **Save as dataset** is not offered for it, because a dataset reads a source, not a session.

## 3. Pivot a large result on the server

When a result is cut at the browser's limit, **Pivot on the server** appears next to the notice. It groups the **whole** result on the server, for any source (historian, alarms or extracts):

1. Click **Pivot on the server**.
2. Choose the **Pivot column** (each of its values becomes a column; at most 50 different values), the **Row groups** (one row per group) and the **Values**: a column and an aggregation (**Sum**, **Average**, **Minimum**, **Maximum**, **Count**). **Add a value** adds another.
3. Click **Pivot**.
[Image: The dialog "Pivot on the server" over a result cut at the browser's limit: "The result is larger than the browser shows. The server groups the whole result for you: one row per group, one column per value of the pivot column (at most 50)." Pivot column quality_class, Row groups tag_path ticked (ts, value and quality_class not), Values value Average and value Count, Add a value, the note "The query it writes goes into the editor and runs as yours (Ctrl+Z in the editor brings your query back).", and the buttons Cancel and Pivot.]
[Image: The same dialog in the dark theme.]

Pivot on the server: row groups, a pivot column and aggregations over the whole result.
The page first asks the server for the pivot column's values, then writes a `GROUP BY` query over your query into the editor and runs it as yours: the same checks and read rights apply, and when the result has a quality column the worst quality of each group comes back as `quality_class`, so a group with an uncertain sample is marked uncertain. **Ctrl+Z** in the editor brings your own query back. A pivot column with more than 50 values is refused with a message: choose another column, or narrow the query.

## 4. Export a query over extracts

**Export** works over extracts as over a single source: it writes the whole result of your query over the extracts as CSV, Excel or Parquet, with the same limits, status line and audit record ([Export analytics results](/docs/eaxscada/how-to/export-analytics-results/)).

## When an extract is refused

| Message | Why (answer) | What to do |
|---|---|---|
| "This extract would take the session over its row or size limit..." | The session would pass `analytics.extract_rows` or `analytics.extract_bytes` (`413 EXTRACT_LIMIT`). The extract is refused whole; nothing is kept. | Drop an extract, or narrow the window or the scope. |
| "The session holds its maximum of extracts: drop one first." | `analytics.extract_per_user` extracts already (`409 EXTRACT_TOO_MANY`). | Drop one. |
| "Choose another name..." | The name is malformed, reserved or taken (`400 EXTRACT_NAME`). | Choose another. |
| "Check the source, the relation and the time window: ..." | A family, relation or window that is not valid (`400 EXTRACT_SPEC`). | Correct it. |
| "the server holds its maximum of N extract sessions (analytics.extract_sessions): try again when another user's extracts are dropped or expire" | `analytics.extract_sessions` other users already hold extracts (`429 EXTRACT_SERVER_FULL`). Refused, never queued; users who hold a session keep working. | Try again later, or ask the administrator. |
| "The extracts of this session are gone (dropped, or unused for too long): add them again." | The session ended (`410 EXTRACT_EXPIRED`). | Add them again. |
| "too many queries running" | The server runs `analytics.workers` queries already (`429 ANALYTICS_BUSY`): a query over extracts takes a place like any query. | Run it again in a moment. |

## Limits

| Limit | Value |
|---|---|
| Rows in a session (all your extracts together) | `analytics.extract_rows` (default 2,000,000) |
| Size of a session | `analytics.extract_bytes` (default 512 MiB; more than 4 GiB is refused at start-up) |
| Extracts per user | `analytics.extract_per_user` (default 8; 1 to 32) |
| Session unused | dropped after `analytics.extract_idle` (default 30 min; 5 min to 24 h) |
| Users holding extracts at once, server-wide | `analytics.extract_sessions` (default 4; 1 to 64) |
| Server memory, worst case | `extract_sessions × (2 × extract_bytes + 256 MiB)`: 5 GiB with the defaults; a configuration above 16 GiB is refused at start-up |
| A query over extracts | the query's limits: `analytics.max_rows`, `analytics.query_timeout`, one per user, a place among `analytics.workers` |
| Pivot column | at most 50 different values |

The extracts live in the same server process that serves the operators' screens: keep `extract_sessions` and `extract_bytes` within the memory the machine has to spare.

## Who may use it

- A person with `analytics` only: an **API token** (`403 REPORTS_TOKEN`) and the **AI co-pilot** (`403 REPORTS_AI`) are refused on every extract route.
- Through eaxCloud remote access, extracts are an *engineer* action.
- On Free and Starter, and after a downgrade or a licence expiry, the routes answer `403 EDITION`.
- The audit trail (category `analytics`) records `analytics.extract.create` for every extract, made or refused (name, source, relation, window, scope, rows, bytes, tags allowed and hidden, the SHA-256 of the generated SQL, the duration), `analytics.query` for each query over extracts (the extract names it read), and `analytics.extract.drop` for each extract dropped, with the reason: `user`, `idle` or `shutdown`. An extract whose record cannot be written is dropped before any query sees it (`503 AUDIT_NOT_WRITTEN`).

## Over the HTTP API

As a signed-in person with `analytics` (a browser session):

```http
POST /api/analytics/extracts
Content-Type: application/json

{"name": "reactor_temps", "family": "historian", "relation": "samples",
 "from": "2026-11-02T00:00:00Z", "to": "2026-11-05T00:00:00Z",
 "tag_scope": ["Plant/Reactor1/Temperature", "Plant/Reactor2/Temperature"]}
```

- The answer is `201` with the extract: `name`, `family`, `relation`, `from`, `to`, `scope`, `columns`, `rows`, `bytes`, `tags_allowed`, `tags_hidden`, `warnings` and `sql_sha256` (the generated SQL's hash, never its text).
- `GET /api/analytics/extracts` lists your extracts, your `session` (rows, bytes, memory, `expires_at`) and the `limits`; `DELETE /api/analytics/extracts/<name>` drops one, `DELETE /api/analytics/extracts` all.
- `POST /api/analytics/query` with `"family": "extracts"` runs a query over your extracts (no `tag_scope`: `400`); its result id starts with `ax_`, and its pages and close are the usual routes.
- `POST /api/analytics/export` with `"family": "extracts"` exports such a query (no `window`, no `tag_scope`).

The answers are listed in the [reference](/docs/eaxscada/reference/analytics-and-reports/#extract-routes-and-answers).

## Related

- [Analyse data in the Analytics workspace](/docs/eaxscada/how-to/analyse-data-in-the-analytics-workspace/)
- [Export analytics results (CSV, Excel, Parquet)](/docs/eaxscada/how-to/export-analytics-results/)
- [Export, extracts and the server pivot](/docs/eaxscada/explanation/analytics-and-reports/#export-extracts-and-the-server-pivot)
- [Analytics and Reports reference: extracts](/docs/eaxscada/reference/analytics-and-reports/#extract-routes-and-answers)
