How Computed Files Work¶
A Computed File is a piece of metadata inside Qualytics: one Spark SQL query over one file of a DFS datastore. The query lives with the datastore configuration, and nothing is written back to storage. This page walks through how Qualytics turns that query into data every time it needs to look at the container.
For what a Computed File can reference and how it composes with a Computed Join, see Referencing. For what happens on create, edit, and delete and how tracking works, see Lifecycle. For who can do what, see Permissions.
The Execution Model¶
A Computed File is never materialized as a physical file on storage. When Qualytics needs to look at the container (during a scan, a profile, a quality check run, or a preview), it reads the files that match the source file pattern and runs the stored query on top of them. The rows it returns are the container's live data.
This has three practical consequences to keep in mind while designing a Computed File:
- Every scan is fresh. There is no cached copy of the previous run. If the underlying files changed on storage, the next scan sees the new data.
- Query cost is real. The query runs every time the container is scanned, profiled, or previewed. Aggregations over very large file patterns can slow the run down. Narrow the rows with a
WHEREclause, use partition-aware file patterns, or move heavy preparation into a separate file pattern that Qualytics syncs on its own. - Validation is not execution. Validate (see below) confirms the query is valid against the file's schema. It does not run the query over the whole file pattern. Preview runs it, but only until the first 25 rows arrive.
The Form¶
The Add Computed File and Edit Computed File dialogs hold the same fields:
| Field | Required | Description |
|---|---|---|
| Name | Shown only when adding. Spaces are replaced with underscores, and the name must be unique inside the datastore. To change it later, use Rename on the container. | |
| Query | One Spark SQL query over one file of the datastore. A badge next to it reads Qualytics • Spark SQL. See Query Rules. |
|
| Description | A Markdown description of up to 8,000 characters. The editor can be pinned beside the form. When AgentQ is set up for your deployment, Suggest drafts one from the query. See Description Suggestions. | |
| Owner | The user who owns the Computed File: you by default. Only users with the Editor team permission can pick another owner. | |
| Additional Metadata | Key-value pairs. A key also gives the default value of a runtime variable with the same name, in the query and in this container's checks. |
When the query uses a {{ variable }} that has no value yet, the form shows A variable needs a value (or Variables need a value) and names the keys to add to Additional Metadata. A scan can still set its own value for the variable.
Query Rules¶
The query is a complete Spark SQL statement, so it can hold anything Spark SQL allows in a read-only query: WHERE, GROUP BY, HAVING, DISTINCT, window functions, LATERAL VIEW, subqueries, and common table expressions. Three rules apply on top of Spark SQL:
- It reads exactly one file of its datastore. Name the file as it appears in the datastore, in backticks, for example
FROM `orders.csv`. A query that reads two files is refused withA computed file reads one file, and its query reads 2:followed by their names. To combine files, use a Computed Join. - That file must be a profiled file pattern. Another Computed File cannot be the source, and the file must have been profiled at least once, so that its fields are known.
- Every computed column needs a name. A column read as it is (
customer_id) and*keep their own names, but an expression needs an alias: writeSELECT COUNT(*) AS order_count FROM `orders.csv`, notSELECT COUNT(*) FROM `orders.csv`. Validate and Save refuse an expression without an alias withThe query contains an unnamed output expression; add an explicit alias to every expression in the SELECT list.
Every Computed File is written in Spark SQL, whichever DFS connector holds the files (Amazon S3, Google Cloud Storage, or Azure Data Lake Storage). The storage only holds the files, so there is no connector-specific dialect to learn. See SQL Dialects per Connector for how this compares with Computed Tables.
File names are matched in any letter case, and Qualytics writes each one as the datastore spells it. Column names are matched by case, so copy them from autocomplete rather than typing them in another case.
Files Built from Separate Clauses¶
Computed Files created before queries were introduced were defined by separate clauses: a select expression, a filter, a grouping, and lateral views, over a source file picked in the form. They keep running from those clauses. The Edit dialog shows them as the one query they stand for, and the query replaces the clauses the first time you change it and save. See Edit a Computed File.
Validation¶
Validate sends the current form to Qualytics for checking without saving anything:
- The query must parse as Spark SQL and read exactly one profiled file pattern of the datastore.
- Every field the query reads must exist in that file's schema.
- Every expression in the outer
SELECTmust have an alias. - The file must be reachable on storage.
- No output column may nest arrays of structs deeper than Qualytics can profile (see Nesting Depth below).
When a check fails, the dialog shows the error so you can fix the query in place. Validation Successful appears when every check passes. Running Validate is optional: Save runs the same checks and shows any error the same way.
When you click Validate, the request runs with a default timeout of 150 seconds (configurable per request between 30 and 300 seconds). A request that does not finish in time returns 408 Request Timeout. If you skip Validate and click Save, the same validation runs as part of the save under a longer timeout (500 seconds by default). Very complex queries over very large file patterns can push either one toward its limit.
Nesting Depth¶
A column that holds an array of arrays of structs (array<array<struct>>) can give its structs scalar or array fields, but not struct fields. A struct inside those structs is past the depth Qualytics can profile, so Validate refuses the query and names the field. Saving it, when you add or edit the Computed File, fails with the same message:
Nested arrays of structs go deeper than supported at order_items.price. In an array of arrays of structs (array<array<struct>>), the struct's fields can be scalars or arrays but not structs. Select the nested struct's fields as separate fields instead, for example with transform() in a computed file's select expression.
This shape usually comes from the query's own columns. Say the file has a line_items array where each item holds a sku and a price struct with amount and currency. Grouping by customer_id with collect_list(line_items) AS order_items builds an array of arrays of those items, and price is the struct the message names.
To fix it, rebuild each item so the nested struct's fields become fields of their own. transform() rewrites every element of an array, and named_struct() builds the new struct:
SELECT
customer_id,
collect_list(
transform(line_items, i -> named_struct(
'sku', i.sku,
'price_amount', i.price.amount,
'price_currency', i.price.currency
))
) AS order_items
FROM `orders.json`
GROUP BY customer_id
Every field of the items in order_items is now a scalar, so the query passes Validate. Array fields such as a list of tags can stay as they are.
Preview¶
When you add a Computed File, Preview next to the query runs it as a sample. Press Ctrl+Enter in the editor (Cmd+Enter on a Mac) for the same thing.
- With a Name filled in, Preview validates the query first, so a query that would be refused never runs. Without a name, the sample runs alone.
- The Sample panel under the editor shows the first 25 rows, the row count, and how long the query took. When the query returns more rows, it reads
First 25 rows of the query. A query that returns nothing readsThe query ran, but no rows matched. - After you change the query, the sample says
The query changed. Preview again to update the sample. - Open in Explore opens the query in a new Explore workspace, in a new browser tab, where you can read the whole result.
- Minimize sample folds the panel and keeps its rows for when you open it again.
The Edit dialog has no Preview, because a saved Computed File also applies its own excluded and computed fields after the query, which a sample would leave out.
Query Editor¶
The query editor has a few features that speed up writing Spark SQL:
- Syntax highlighting. SQL keywords, names, strings, comments, and
{{ variables }}are colored. - Autocomplete. Press Ctrl+Space in the editor for the datastore's file patterns, their fields, and Spark SQL keywords and functions.
- Hint. The line under the editor reads
Any valid Spark SQL query over one file of this datastore. - Larger editor. Click Expand editor to edit in a larger dialog. When you are adding a Computed File, that dialog has its own Preview and shows the sample too.