diff --git a/docs/cloud/features/data-tests/cloud-or-dbt-tests.mdx b/docs/cloud/features/data-tests/cloud-or-dbt-tests.mdx new file mode 100644 index 000000000..4ba1c495b --- /dev/null +++ b/docs/cloud/features/data-tests/cloud-or-dbt-tests.mdx @@ -0,0 +1,67 @@ +--- +title: "Cloud tests or dbt tests" +sidebarTitle: "Cloud or dbt tests" +description: "When your environment supports both, choose whether a data test should run in Elementary Cloud or in your dbt project." +--- + +Elementary monitors two kinds of data tests: + +- **dbt tests** are defined in your dbt project and run in your dbt pipeline. Elementary collects their results. You can add them in code or from the Elementary UI, which opens a pull request through your [code repository](/cloud/integrations/code-repo/connect-code-repo) integration. +- **Cloud tests** are defined in the Elementary UI and run by Elementary Cloud on their own schedule. [SQL data tests](/cloud/features/data-tests/sql-data-tests) and [custom SQL tests](/cloud/features/data-tests/custom-sql-tests) query your warehouse directly, through Elementary Cloud or an [Elementary Runtime](/cloud/features/elementary-runtime). + +If your environment has a dbt project **and** [data access](/cloud/features/data-tests/sql-data-tests#where-the-queries-run) to its warehouse, you can add most data quality checks either way. Both kinds appear in the same test results, incidents, alerts, Catalog, and coverage views. + +## Equivalent tests + +| Check | Cloud test | dbt test | +| --- | --- | --- | +| No duplicate values | [Uniqueness](/cloud/features/data-tests/sql-data-tests/uniqueness) | `unique`, `dbt_utils.unique_combination_of_columns` | +| No missing values | [Completeness](/cloud/features/data-tests/sql-data-tests/completeness) | `not_null` | +| Values follow a rule | [Validity](/cloud/features/data-tests/sql-data-tests/validity) | `accepted_values`, `dbt_expectations` tests for ranges, regex, and length | +| References exist in another table | [Relationship](/cloud/features/data-tests/sql-data-tests/relationship) | `relationships` | +| Custom business rule in SQL | [Custom SQL test](/cloud/features/data-tests/custom-sql-tests) | [Singular test](/data-tests/dbt/singular-tests) | +| Schema matches a baseline | [Data contract](/cloud/features/data-tests/data-contract-test) | [`schema_changes_from_baseline`](/data-tests/schema-tests/schema-changes-from-baseline) | + +## How they compare + +| | Cloud test | dbt test | +| --- | --- | --- | +| Where it's defined | Elementary UI | Your dbt project's code | +| Pull request required | No | Yes | +| When it runs | Its own schedule in Elementary | With your dbt jobs, for example `dbt build` or `dbt test` | +| Can stop a pipeline | No. Results are reported after the data is loaded | Yes. With `dbt build`, a failing test can stop downstream models | +| Preview before saving | Runs against your warehouse and shows failing rows | Runs when the dbt job runs | +| Assets it can test | Any supported table in the environment, including tables outside dbt | dbt models, sources, seeds, and snapshots | +| Version control and review | Changes are recorded in the audit logs | Changes go through your code review | +| Warehouse credentials | The environment's connection, or a runtime in your network | Your dbt profile | +| Supported warehouses | Snowflake, Databricks, Redshift, and Postgres for SQL data tests | Any warehouse dbt supports | + +## When to use cloud tests + +Use a cloud test when: + +- **You want coverage without a code change.** Analysts, data stewards, and business users can add and tune tests in the UI with no pull request or dbt knowledge. +- **The table isn't in dbt.** Cloud tests work on tables loaded by ingestion tools, other pipelines, or anything else in the warehouse. +- **The test needs its own schedule.** For example, check a source table hourly while your dbt jobs run daily, or check a table after an external load. +- **You want to see results before you commit.** The preview runs the test against your data and shows the failing rows before you save. +- **Warehouse credentials must stay in your network.** Run the tests through [Elementary Runtime](/cloud/features/elementary-runtime). + +## When to use dbt tests + +Use a dbt test when: + +- **A failure should stop the pipeline.** Tests that run with `dbt build` can prevent bad data from reaching downstream models and dashboards. +- **Test configuration must be version-controlled.** The test lives next to the model, goes through code review, and is deployed with it. +- **The test must run with every model change**, including in CI on pull requests. +- **The check needs a test type or warehouse that cloud tests don't support**, such as ephemeral models, BigQuery, or tests from dbt packages. + +## Defaults in the Elementary UI + +When the environment has data access, Elementary suggests cloud tests first: + +- In the add-test flow, the test picker starts filtered on **Elementary cloud**. Switch the filter to **dbt** to add a dbt test instead. +- For custom query tests, the selector next to the page title defaults to **Elementary Cloud (recommended)**. Choose **dbt** to open a pull request with a singular test. The dbt option requires a connected code repository. + +## Avoid duplicates + +If the same check exists as both a cloud test and a dbt test, **both run**. You get two results, possibly two alerts, and pay for both queries in your warehouse. When you move a check from dbt to the cloud, or the other way, remove the old test. diff --git a/docs/cloud/features/data-tests/cloud-tests-overview.mdx b/docs/cloud/features/data-tests/cloud-tests-overview.mdx index 9542b377e..f541f4672 100644 --- a/docs/cloud/features/data-tests/cloud-tests-overview.mdx +++ b/docs/cloud/features/data-tests/cloud-tests-overview.mdx @@ -1,7 +1,7 @@ --- title: "Cloud Tests" sidebarTitle: "Cloud tests" -description: "Tests that run in Elementary Cloud, outside your dbt pipeline - freshness, volume, data contracts, and custom SQL, configured in the UI with no dbt project required." +description: "Tests that run in Elementary Cloud, outside your dbt pipeline - freshness, volume, data contracts, SQL data tests, and custom SQL, configured in the UI with no dbt project required." badge: "Elementary Cloud" --- @@ -20,9 +20,17 @@ Cloud test types include: | [Cloud freshness test](/cloud/features/anomaly-detection/automated-freshness) | Tables that haven't been updated within their expected window | | [Cloud volume test](/cloud/features/anomaly-detection/automated-volume) | Unexpected drops or spikes in row count | | [Data contract test](/cloud/features/data-tests/data-contract-test) | Schema mismatches against a defined contract — column names, types, nullability | +| [Uniqueness test](/cloud/features/data-tests/sql-data-tests/uniqueness) | Duplicate values in a column or expression | +| [Completeness test](/cloud/features/data-tests/sql-data-tests/completeness) | Null, empty, or zero values where a value is required | +| [Validity test](/cloud/features/data-tests/sql-data-tests/validity) | Values that break an allow list, deny list, range, regex, or length rule | +| [Relationship test](/cloud/features/data-tests/sql-data-tests/relationship) | Values with no match in another table | | [Custom SQL test](/cloud/features/data-tests/custom-sql-tests) | Rows that violate a business rule defined in a SQL query | -Freshness, volume, and data contract tests use warehouse metadata collected by Elementary. Custom SQL tests execute against table data and consume compute in your data warehouse. +Freshness, volume, and data contract tests use warehouse metadata collected by Elementary. [SQL data tests](/cloud/features/data-tests/sql-data-tests) (uniqueness, completeness, validity, and relationship) and custom SQL tests execute against table data and consume compute in your data warehouse. They need data access to the warehouse, through Elementary Cloud or an [Elementary Runtime](/cloud/features/elementary-runtime) in your network. + + +If your environment also has a dbt project, many checks can be added either as a cloud test or as a dbt test. See [Cloud tests or dbt tests](/cloud/features/data-tests/cloud-or-dbt-tests). + ## Adding cloud tests @@ -30,8 +38,8 @@ Cloud freshness and volume tests are activated automatically on all your sources 1. Navigate to the **Test Configuration** page and click **Add Test**. For asset-based tests, you can also start by selecting assets in the Catalog. 2. Filter on **Elementary Cloud** and choose a test. -3. Select the assets to test. For a custom SQL test, enter the query instead; Elementary derives its referenced assets from the SQL. -4. Configure the test parameters, schedule, and metadata. +3. Select the assets to test. SQL data tests are added to one table at a time. For a custom SQL test, enter the query instead; Elementary derives its referenced assets from the SQL. +4. Configure the test parameters, schedule, and metadata. For SQL data tests and custom SQL tests, run the test to preview its result before saving. 5. Submit — no pull request is required. ## Editing cloud tests diff --git a/docs/cloud/features/data-tests/custom-sql-tests.mdx b/docs/cloud/features/data-tests/custom-sql-tests.mdx index 0f9fed056..ce7e90dce 100644 --- a/docs/cloud/features/data-tests/custom-sql-tests.mdx +++ b/docs/cloud/features/data-tests/custom-sql-tests.mdx @@ -4,17 +4,19 @@ sidebarTitle: Custom SQL badge: "Elementary Cloud" --- +import SqlTestsRequirements from '/snippets/cloud/features/data-tests/sql-tests-requirements.mdx'; +import SqlTestsThresholds from '/snippets/cloud/features/data-tests/sql-tests-thresholds.mdx'; +import WhereSqlTestsRun from '/snippets/cloud/features/data-tests/where-sql-tests-run.mdx'; + Custom SQL tests validate business rules that are specific to your data. They run as [cloud tests](/cloud/features/data-tests/cloud-tests-overview) directly against your data warehouse, without requiring a pull request or dbt job. - -Custom SQL cloud tests are available on request. Contact the Elementary team to enable them for your account. - + -Use them for checks that are difficult to express with an existing generic test, such as validating calculations or relationships across multiple tables. +Use them for checks that are difficult to express with a built-in test, such as validating calculations or relationships across multiple tables. For common checks, such as unique, not null, accepted values, ranges, and foreign keys, the built-in [SQL data tests](/cloud/features/data-tests/sql-data-tests) don't require writing SQL. ## How it works -Write a query that returns the rows that violate your expectation. For example: +Write a query that returns the rows that violate your expectation. The test passes when the query returns zero rows. For example: ```sql select @@ -25,16 +27,11 @@ from analytics.finance.orders where total_amount < 0 ``` -On each run, Elementary executes the query using the environment's existing warehouse connection and evaluates the number of rows returned: +On each run, Elementary executes the query and evaluates the number of rows returned. -| Result | Behavior | -| --- | --- | -| Pass | The returned row count does not exceed a configured threshold | -| Warning | The row count exceeds the optional warning threshold | -| Failure | The row count exceeds the failure threshold, which defaults to `0` | -| Error | The query is invalid, times out, or cannot be executed | + -By default, Elementary stores a limited sample of the returned rows with the test result. You can turn off row samples or change the sample limit. +By default, Elementary stores a sample of up to 100 returned rows with the test result. You can turn off row samples or change the sample limit. Disable row samples if the query could return sensitive values that should not be stored with test results. @@ -49,11 +46,14 @@ Custom SQL tests query table data and consume compute in your data warehouse. Ch Like other cloud tests, custom SQL tests: - Are created and configured in the Elementary UI -- Run independently of your dbt pipeline -- Can run on a recurring schedule or on demand +- Run independently of your dbt pipeline, on their own schedule - Appear alongside dbt tests and other monitors in test results, incidents, and coverage views -Elementary uses the warehouse credentials already configured for the environment. The connection must be able to read every table referenced by the query. +The warehouse role that runs the query must be able to read every table referenced by the query. + +## Where the queries run + + ## SQL requirements @@ -61,10 +61,11 @@ A custom SQL test must: - Contain exactly one read-only query - Use a `SELECT` statement, including queries built with CTEs or `UNION` -- Reference tables by their fully qualified names +- Reference tables by their fully qualified names, `database.schema.table` - Reference only tables that exist as assets in the Elementary Catalog +- Reference only tables on the same warehouse connection -Elementary validates the SQL before saving the test and again before every execution. A validation run can also check the query against your warehouse and preview its result columns without reading result rows. +Elementary validates the SQL before saving the test and again before every execution. If any referenced table has not been synced to the Elementary Catalog, the test cannot be created. The validation result lists unresolved tables so you can sync them or update the query. @@ -75,43 +76,66 @@ If any referenced table has not been synced to the Elementary Catalog, the test Elementary derives asset linkage from the tables referenced in the SQL: - If the query references one asset, Elementary links it automatically. -- If it references multiple assets, choose a primary asset during configuration. +- If it references multiple assets, choose the **Tested table** during configuration. -The primary asset determines where the test appears in the Catalog and how Elementary groups its incidents. It does not limit which tables the query can read. +The tested table determines where the test appears in the Catalog and how Elementary groups its incidents. It does not limit which tables the query can read. -To create or edit the test, you need permission to edit tests in the environment, view every referenced asset, and create tests on the primary asset. +To create or edit the test, you need permission to edit tests in the environment, view every referenced asset, and create tests on the tested table. ## Create a custom SQL test + + Custom query test page with Elementary Cloud (recommended) selected next to the page title, a SQL query, its failing-row results, and the severity and cadence settings + + - - Go to **Test Configuration**, click **Add Test**, and choose **Custom SQL** under Elementary Cloud tests. + + Go to **Test Configuration**, click **Add test**, and choose **Custom query test**. If your environment also has a dbt project, keep the selector next to the page title on **Elementary Cloud (recommended)**. Choosing **dbt** opens a pull request with a [singular test](/data-tests/dbt/singular-tests) instead. - - Enter a name, an optional description, and a query that returns failing rows. Validate the query to check its SQL, warehouse compatibility, and referenced assets. + + Enter a query that returns failing rows, and click **Run query**. Elementary checks the SQL and the referenced assets, runs the query against your warehouse, and shows a sample of the returned rows with the result the test would have. You must run the query successfully before you can create the test. You can also click **Generate** to write the query with AI from a description of the rule. - - If the query references multiple assets, select the asset that the test primarily represents. + + If the query references multiple assets, select the table that the test primarily represents. - Set failure and optional warning thresholds. Choose whether to store a sample of failing rows, then configure the row-sample limit and query timeout. + Enter a test name and set the severity, with optional error and warning thresholds. Choose whether to store a sample of failing rows, and set the sample row limit and the query timeout. Optionally choose a [quality dimension](/cloud/features/collaboration-and-communication/data-quality-dimensions) for the test. - - Choose a schedule, severity, owners, and tags, then submit the test. No pull request is required. + + Choose the test cadence, owners, and tags, then click **Create**. No pull request is required. Elementary runs the test right away and then on its schedule. +## Configuration + +| Setting | Description | Default | +| --- | --- | --- | +| **Test name** | Name shown in test results and alerts | — | +| **Severity** | **Use simple severity** (**Error** or **Warning**), or **Use conditional severity** with thresholds on the number of failures. See [How it works](#how-it-works) | — | +| **Test cadence** | How often the test runs. See [Scheduling](#scheduling) | Daily at 09:00 | +| **Store row sample** | Whether to store failing rows with each result | On | +| **Sample row limit** | Maximum number of failing rows to store, from 1 to 1000 | 100 | +| **Query timeout** | Maximum time, in seconds, the query can run, from 1 to 1200. A query that runs longer returns an **Error** result | 300 | +| **Quality dimension** | The [data quality dimension](/cloud/features/collaboration-and-communication/data-quality-dimensions) the test counts toward | None | +| **Tested table** | The asset the test is linked to, when the query references several | The only referenced asset | +| **Owners, tags, description** | Metadata used for alert routing, filtering, and context | — | + ## Scheduling -Set the test to run hourly, every few hours, daily, or weekly. +Set the **Test cadence** to one of: + +- **Every** N hours, from 1 to 23 +- **Daily** at a time of day +- **Weekly** on a day and time +- **Custom**, with a cron expression -You can also run the test immediately with **Test now**. +Times are in your account's timezone. Tests can't run more often than every 15 minutes. ## Edit configuration Open the test from test results or an incident and go to the **Configuration** tab. You can update the SQL, thresholds, row-sample settings, timeout, schedule, severity, owners, and tags. -When you save an updated query, Elementary validates it again and re-derives its referenced assets. If the query now references multiple assets or no longer references the current primary asset, you must choose a new primary asset. +When you save an updated query, Elementary validates it again and re-derives its referenced assets. If the query now references multiple assets or no longer references the current tested table, you must choose a new tested table. Saving changes re-runs the test with the updated configuration. @@ -119,7 +143,7 @@ Saving changes re-runs the test with the updated configuration. Each execution shows its status and the number of failing rows returned. When row samples are enabled, the execution details also show the sampled rows and whether the sample was truncated. -Execution errors, such as invalid SQL or a query timeout, are shown separately from failures caused by returned rows. +Execution errors, such as invalid SQL, missing permissions, or a query timeout, are shown separately from failures caused by returned rows. ## Alerts @@ -133,11 +157,11 @@ dbt singular tests also use SQL queries that return failing rows, but they are m | | Custom SQL cloud test | dbt singular test | | --- | --- | --- | -| Where it runs | Elementary Cloud, against your warehouse | dbt pipeline | +| Where it runs | Elementary Cloud or Elementary Runtime, against your warehouse | dbt pipeline | | Configuration | Elementary UI | SQL file in your dbt project | | Scheduling | Per-test schedule in Elementary | dbt job schedule and selectors | | Pull request required | No | Yes | | Asset linkage | Derived from referenced Catalog assets | Derived from dbt metadata | | Failing-row sample | Configurable in Elementary | Depends on dbt test configuration | -Choose a custom SQL cloud test when you want Elementary to manage the configuration and schedule. Choose a [dbt singular test](/data-tests/dbt/singular-tests) when the validation should live in version-controlled project code and run with your dbt jobs. +Choose a custom SQL cloud test when you want Elementary to manage the configuration and schedule. Choose a [dbt singular test](/data-tests/dbt/singular-tests) when the validation should live in version-controlled project code and run with your dbt jobs. See [Cloud tests or dbt tests](/cloud/features/data-tests/cloud-or-dbt-tests) for more guidance. diff --git a/docs/cloud/features/data-tests/sql-data-tests.mdx b/docs/cloud/features/data-tests/sql-data-tests.mdx new file mode 100644 index 000000000..7fc3abd5c --- /dev/null +++ b/docs/cloud/features/data-tests/sql-data-tests.mdx @@ -0,0 +1,140 @@ +--- +title: "SQL Data Tests" +sidebarTitle: "Overview" +description: "Built-in uniqueness, completeness, validity, and relationship tests that Elementary Cloud runs against your warehouse, configured in the UI without writing SQL or opening a pull request." +badge: "Elementary Cloud" +--- + +import SqlTestsRequirements from '/snippets/cloud/features/data-tests/sql-tests-requirements.mdx'; +import SqlTestsThresholds from '/snippets/cloud/features/data-tests/sql-tests-thresholds.mdx'; +import WhereSqlTestsRun from '/snippets/cloud/features/data-tests/where-sql-tests-run.mdx'; + +SQL data tests are built-in checks for the most common data quality rules. You choose a table, a column or expression, and the rule to enforce. Elementary generates the SQL for your warehouse, runs it on a schedule, and reports the rows that break the rule. + +They are [cloud tests](/cloud/features/data-tests/cloud-tests-overview): you create and manage them in the Elementary UI, they run outside your dbt pipeline, and they don't need a pull request or a dbt project. They work on any supported table in the environment, including tables that aren't part of a dbt project. + + + +## Test types + +| Test | What it checks | Fails on | Quality dimension | +| --- | --- | --- | --- | +| [Uniqueness](/cloud/features/data-tests/sql-data-tests/uniqueness) | Values that should not repeat | Each value that appears more than once | Uniqueness | +| [Completeness](/cloud/features/data-tests/sql-data-tests/completeness) | Required values are present | Each row whose value is null, empty, or zero | Completeness | +| [Validity](/cloud/features/data-tests/sql-data-tests/validity) | Values match an allow list, deny list, range, regex, or length rule | Each row whose value breaks the rule | Validity | +| [Relationship](/cloud/features/data-tests/sql-data-tests/relationship) | Values exist in another table | Each row whose value has no match in the target table | Consistency | + +Results count toward the [data quality dimension](/cloud/features/collaboration-and-communication/data-quality-dimensions) shown for each test type. + + +For a rule that none of these types can express, such as a calculation or a check across several tables, use a [custom SQL test](/cloud/features/data-tests/custom-sql-tests). + + +## How it works + +The saved configuration is the test. On every run, Elementary generates the query for your warehouse from that configuration, runs it, and counts the failing rows. Improvements to the generated SQL apply to existing tests without editing them. + +Each run: + +1. Scans the **entire table**, filtered by the optional `where` clause. +2. Counts the failing rows and stores a sample of them with the result. +3. Sets the result to **Pass**, **Warning**, **Failure**, or **Error** based on the test's severity and thresholds. +4. Stores the exact query that ran with the result, so any past result can be reproduced. + +Results appear with your other tests in test results, incidents, alerts, the Catalog, and [test coverage](/cloud/features/data-tests/test-coverage-screen). + + +SQL data tests read table data and use compute in your data warehouse. Every run scans the full table. On large tables, add a `where` clause to limit the scanned data and pick a schedule that matches how often the data changes. The preview shows the table size each run will scan. + + +## Where the queries run + + + +## Create a SQL data test + + + + Go to **Test Configuration**, click **Add test**, and choose **Table test** or **Column test**. You can also start from an asset in the Catalog. + + + Select one table. SQL data tests are added to one table at a time. In the test picker, filter on **Elementary cloud** and choose **Uniqueness**, **Completeness**, **Validity**, or **Relationship**. + + + Add test page with the Elementary cloud source filter selected, showing the Uniqueness, Completeness, Validity, and Relationship test cards + + + + Choose the **Tested field**, either a column or a SQL expression, and fill in the fields of the test type. Optionally add a `where` clause. + + + Choose the severity and optional thresholds, how many failing rows to store with each result, and the test cadence. Add owners, tags, and a description. + + + Click **Run test** in the **Preview** section to run the test against your warehouse. The preview shows the result status, the number of failed rows, a sample of them, and the size of the table each run will scan. You must run the preview after your last change before you can save the test. + + + Submit the test. No pull request is required. Elementary runs the test right away and then on its schedule. + + + +You can also ask the [Elementary AI agent](/cloud/ai-agents/ai-test-coverage) to recommend and create SQL data tests. The agent previews each test before it proposes the plan, and you review the plan before anything is created. The [MCP server](/cloud/mcp/intro) provides the same create and preview tools. + +## Configuration + +These settings are shared by all SQL data test types. Each test type page lists its own fields. + +| Setting | Description | Default | +| --- | --- | --- | +| **Tested field** | A **Column** of the table, or an **Expression**: a single SQL expression over the table's columns, such as `lower(email)` or `amount * quantity` | — | +| **Where clause** | Optional SQL condition, without the `WHERE` keyword, to limit the scanned data or exclude rows, for example `status = 'completed'` | None | +| **Severity** | **Use simple severity** (**Error** or **Warning**), or **Use conditional severity** with thresholds on the number of failures. See [Results](#results) | — | +| **Sampled rows** | Number of failing rows stored with each result, from 1 to 1000 | 5 | +| **Test cadence** | How often the test runs. See [Scheduling](#scheduling) | Daily at 09:00 | +| **Owners, tags, description** | Metadata used for alert routing, filtering, and context | — | + +Expressions and `where` clauses must be a single expression. They can't contain subqueries, aggregate or window functions, `*`, or table-qualified column names such as `t.amount`. + +Scheduled runs time out after 5 minutes and return an **Error** result. Previews time out after 30 seconds. + +## Scheduling + +Set the **Test cadence** to one of: + +- **Every** N hours, from 1 to 23 +- **Daily** at a time of day +- **Weekly** on a day and time +- **Custom**, with a cron expression + +Times are in your account's timezone. Tests can't run more often than every 15 minutes. + +## Results + + + +Each result shows the failing-row count and, when available, a sample of the failing rows. + +## Edit or delete a test + +Open the test from test results or an incident and go to the **Configuration** tab to change its settings. The test type can't be changed. Saving re-runs the test with the new configuration. + +To delete tests, select them on the **Test Configuration** page and use the delete option, or open a test result and click `...` → **Delete test**. Every create, edit, and delete is recorded in the [audit logs](/cloud/features/collaboration-and-communication/audit_logs/overview). + +## Alerts + +SQL data test failures map to the **Cloud data tests** category in [alert rules](/cloud/features/alerts-and-incidents/alert-rules). In environments with data access, the category is selected by default on new rules and included in the default rule. Check existing rules if you want them to include SQL data test failures. + +## Supported warehouses + +SQL data tests run on tables and other materialized assets in: + +- Snowflake +- Databricks +- Redshift +- Postgres + +Ephemeral models and assets without a table in the warehouse can't be tested. + +## SQL data tests or dbt tests + +Each SQL data test has a dbt equivalent. If your environment has both data access and a dbt project, see [Cloud tests or dbt tests](/cloud/features/data-tests/cloud-or-dbt-tests) to choose where each check should live. diff --git a/docs/cloud/features/data-tests/sql-data-tests/completeness.mdx b/docs/cloud/features/data-tests/sql-data-tests/completeness.mdx new file mode 100644 index 000000000..11f1fc7f8 --- /dev/null +++ b/docs/cloud/features/data-tests/sql-data-tests/completeness.mdx @@ -0,0 +1,55 @@ +--- +title: "Completeness test" +sidebarTitle: "Completeness" +description: "Detect rows where a required value is null, empty, or zero." +badge: "Elementary Cloud" +--- + +import SqlTestsRequirements from '/snippets/cloud/features/data-tests/sql-tests-requirements.mdx'; + +Validates that a column or expression has a value in every row. Use it for required fields such as IDs, foreign keys, amounts, and status columns. + +This is a [SQL data test](/cloud/features/data-tests/sql-data-tests): Elementary runs it against your warehouse on a schedule, with no SQL to write and no pull request. + + + +## How it works + +On each run, Elementary returns every row where the tested value counts as missing. You choose what counts as missing: + +| Missing value check | A row fails when | +| --- | --- | +| **Null** (default) | The value is `null` | +| **Empty** | The value is an empty string, `''`. Strings that contain only spaces are not empty | +| **Zero** | The value is `0`. Use it on numeric columns only | + +When you select more than one check, a row fails if it matches any of them. Each failing row is one table row, and the row sample contains the full rows. + +Results count toward the **Completeness** [data quality dimension](/cloud/features/collaboration-and-communication/data-quality-dimensions). + +## Configuration + +| Setting | Description | +| --- | --- | +| **Tested field** | The column, or an expression, that must have a value | +| **Missing values** | One or more of **Null**, **Empty**, and **Zero**. At least one is required | +| **Where clause** | Optional condition that limits the rows checked | + +Severity, thresholds, sampled rows, and cadence work the same for all SQL data tests. See [Configuration](/cloud/features/data-tests/sql-data-tests#configuration). + +## Examples + +| Goal | Tested field | Missing values | Where clause | +| --- | --- | --- | --- | +| Every order has a customer | Column `customer_id` | Null | — | +| Every user has an email | Column `email` | Null, Empty | — | +| Every paid invoice has an amount | Column `amount` | Null, Zero | `status = 'paid'` | +| Trimmed names aren't empty | Expression `trim(name)` | Null, Empty | — | + + +Allow a small number of missing values with a threshold instead of a filter, for example **Error if > 100**. See [Results](/cloud/features/data-tests/sql-data-tests#results). + + +## dbt equivalent + +The dbt [`not_null`](https://docs.getdbt.com/reference/resource-properties/data-tests#not_null) test checks for nulls from your dbt project. Checks for empty strings or zeros need a package test or a custom test in dbt. See [Cloud tests or dbt tests](/cloud/features/data-tests/cloud-or-dbt-tests) to decide which to use. diff --git a/docs/cloud/features/data-tests/sql-data-tests/relationship.mdx b/docs/cloud/features/data-tests/sql-data-tests/relationship.mdx new file mode 100644 index 000000000..85419d508 --- /dev/null +++ b/docs/cloud/features/data-tests/sql-data-tests/relationship.mdx @@ -0,0 +1,57 @@ +--- +title: "Relationship test" +sidebarTitle: "Relationship" +description: "Detect values that have no matching value in another table." +badge: "Elementary Cloud" +--- + +import SqlTestsRequirements from '/snippets/cloud/features/data-tests/sql-tests-requirements.mdx'; + +Validates referential integrity between two tables: every value in the tested table must exist in a target table. Use it for foreign keys, such as orders that reference customers, or events that reference users. + +This is a [SQL data test](/cloud/features/data-tests/sql-data-tests): Elementary runs it against your warehouse on a schedule, with no SQL to write and no pull request. + + + +## How it works + +On each run, Elementary returns every row of the tested table whose value has no equal value in the target table's target field. Each failing row is one row of the tested table, and the row sample contains the full rows. + +- **Null source values are ignored.** A row with a null value in the tested field never fails. To require a value, add a [completeness test](/cloud/features/data-tests/sql-data-tests/completeness). +- **The `where` clause applies to the tested table only.** All rows of the target table are used as valid values. +- **Both tables must use the same warehouse connection**, and the target table must be an asset in the Elementary Catalog. + +Results count toward the **Consistency** [data quality dimension](/cloud/features/collaboration-and-communication/data-quality-dimensions). + +## Configuration + +| Setting | Description | +| --- | --- | +| **Tested field** | The column, or an expression, in the tested table that references the target, for example `customer_id` | +| **Target table** | The table that holds the valid values, for example `analytics.core.customers` | +| **Target field** | The column, or an expression, in the target table to match against, for example `id` | +| **Where clause** | Optional condition that limits the rows of the tested table | + + + Relationship test configuration with the tested field, target table, and target field set to columns + + +Severity, thresholds, sampled rows, and cadence work the same for all SQL data tests. See [Configuration](/cloud/features/data-tests/sql-data-tests#configuration). + +The test is linked to the tested table: it appears on that table in the Catalog, and its incidents are grouped there. + +## Examples + +| Goal | Tested table and field | Target table and field | Where clause | +| --- | --- | --- | --- | +| Every order references a customer | `orders.customer_id` | `customers.id` | — | +| Every event references a user | `events.user_id` | `users.user_id` | `event_type != 'anonymous'` | +| Product codes match the catalog, regardless of case | `order_items`, expression `upper(sku)` | `products`, expression `upper(sku)` | — | + + +If the target table is updated later than the tested table, new rows can fail until the target catches up. Schedule the test after both tables load, or use a `where` clause to skip the most recent rows, for example `created_at < current_date`. + + +## dbt equivalent + +The dbt [`relationships`](https://docs.getdbt.com/reference/resource-properties/data-tests#relationships) test checks the same rule from your dbt project. See [Cloud tests or dbt tests](/cloud/features/data-tests/cloud-or-dbt-tests) to decide which to use. diff --git a/docs/cloud/features/data-tests/sql-data-tests/uniqueness.mdx b/docs/cloud/features/data-tests/sql-data-tests/uniqueness.mdx new file mode 100644 index 000000000..6b56e23c4 --- /dev/null +++ b/docs/cloud/features/data-tests/sql-data-tests/uniqueness.mdx @@ -0,0 +1,57 @@ +--- +title: "Uniqueness test" +sidebarTitle: "Uniqueness" +description: "Detect values that appear more than once in a column or expression." +badge: "Elementary Cloud" +--- + +import SqlTestsRequirements from '/snippets/cloud/features/data-tests/sql-tests-requirements.mdx'; + +Validates that a column or expression has no duplicate values. Use it for primary keys, natural keys, and any value that should identify a single row. + +This is a [SQL data test](/cloud/features/data-tests/sql-data-tests): Elementary runs it against your warehouse on a schedule, with no SQL to write and no pull request. + + + +## How it works + +On each run, Elementary groups the table by the tested value and returns every value that appears more than once, together with the number of times it appears. + +- **Failing rows are duplicated values.** If the value `1042` appears in three rows, it counts as one failing row with a duplicate count of 3. +- **Nulls are ignored.** Rows where the value is null are never counted as duplicates. To require a value in every row, add a [completeness test](/cloud/features/data-tests/sql-data-tests/completeness). +- **The `where` clause applies before grouping.** Only rows that match the condition are compared with each other. + +Results count toward the **Uniqueness** [data quality dimension](/cloud/features/collaboration-and-communication/data-quality-dimensions). + +## Configuration + +| Setting | Description | +| --- | --- | +| **Tested field** | The column, or an expression, whose values should be unique | +| **Where clause** | Optional condition that limits the rows checked | + +Severity, thresholds, sampled rows, and cadence work the same for all SQL data tests. See [Configuration](/cloud/features/data-tests/sql-data-tests#configuration). + +## Examples + +| Goal | Tested field | Where clause | +| --- | --- | --- | +| Order IDs are unique | Column `order_id` | — | +| One row per customer per day | Expression `customer_id \|\| '-' \|\| cast(order_date as varchar)` | — | +| Emails are unique regardless of case | Expression `lower(email)` | — | +| Active subscriptions are unique per account | Column `account_id` | `status = 'active'` | + +## Example result + +The sample lists each duplicated value and its count: + +| value | duplicate_count | +| --- | --- | +| 1042 | 3 | +| 2210 | 2 | + +The failing-row count for this result is 2: two values are duplicated. + +## dbt equivalent + +The dbt [`unique`](https://docs.getdbt.com/reference/resource-properties/data-tests#unique) test checks the same rule from your dbt project. For a combination of columns, use an expression here, or `dbt_utils.unique_combination_of_columns` in dbt. See [Cloud tests or dbt tests](/cloud/features/data-tests/cloud-or-dbt-tests) to decide which to use. diff --git a/docs/cloud/features/data-tests/sql-data-tests/validity.mdx b/docs/cloud/features/data-tests/sql-data-tests/validity.mdx new file mode 100644 index 000000000..7d483c945 --- /dev/null +++ b/docs/cloud/features/data-tests/sql-data-tests/validity.mdx @@ -0,0 +1,77 @@ +--- +title: "Validity test" +sidebarTitle: "Validity" +description: "Detect values that break an allow list, deny list, range, regex, or length rule." +badge: "Elementary Cloud" +--- + +import SqlTestsRequirements from '/snippets/cloud/features/data-tests/sql-tests-requirements.mdx'; + +Validates that the values of a column or expression follow a rule. Use it for status codes and categories, numeric ranges, formats such as email addresses or IDs, and string lengths. + +This is a [SQL data test](/cloud/features/data-tests/sql-data-tests): Elementary runs it against your warehouse on a schedule, with no SQL to write and no pull request. + + + +## How it works + +On each run, Elementary returns every row whose value breaks the test's rule. Each failing row is one table row, and the row sample contains the full rows. + +- **One rule per test.** To check several rules on the same field, for example a range and a regex, add a test for each rule. For combined logic, use a [custom SQL test](/cloud/features/data-tests/custom-sql-tests). +- **Nulls are ignored.** A null value never breaks a validity rule. To require a value, add a [completeness test](/cloud/features/data-tests/sql-data-tests/completeness). + +Results count toward the **Validity** [data quality dimension](/cloud/features/collaboration-and-communication/data-quality-dimensions). + +## Rules + +| Rule | A row fails when | Settings | +| --- | --- | --- | +| **Allow list** | The value isn't one of the allowed values | **Allowed values**: 1 to 1000 strings or numbers | +| **Deny list** | The value is one of the denied values | **Denied values**: 1 to 1000 strings or numbers | +| **Range** | The value is lower than the minimum or higher than the maximum | **Range**: a minimum, a maximum, or both. Bounds are inclusive | +| **Regex** | The value doesn't match the pattern | **Pattern**: a regular expression of up to 1000 characters | +| **Length** | The value's length is shorter than the minimum or longer than the maximum | **Length**: a minimum, a maximum, or both, as whole numbers of 0 or more. Bounds are inclusive | + + + Validity test configuration with the Rule dropdown open, listing Allow list, Deny list, Range, Regex, and Length + + +### Regex patterns + +A value matches when the pattern is found anywhere in it. To validate the whole value, anchor the pattern with `^` and `$`: + +| Pattern | `abc-123` | `id: abc-123` | +| --- | --- | --- | +| `[a-z]+-[0-9]+` | Matches | Matches | +| `^[a-z]+-[0-9]+$` | Matches | Doesn't match | + +Regex and length rules compare the value as text, so they also work on numeric columns. + + +Regular expression support differs between warehouses. Use standard syntax, such as character classes, anchors, and quantifiers, and run the preview to confirm the pattern behaves as expected on your warehouse. + + +## Configuration + +| Setting | Description | +| --- | --- | +| **Tested field** | The column, or an expression, whose values should follow the rule | +| **Rule** | **Allow list**, **Deny list**, **Range**, **Regex**, or **Length**, with the rule's settings | +| **Where clause** | Optional condition that limits the rows checked | + +Severity, thresholds, sampled rows, and cadence work the same for all SQL data tests. See [Configuration](/cloud/features/data-tests/sql-data-tests#configuration). + +## Examples + +| Goal | Tested field | Rule | +| --- | --- | --- | +| Order status is a known value | Column `status` | Allow list: `pending`, `shipped`, `delivered`, `cancelled` | +| No test accounts in production data | Column `account_type` | Deny list: `test`, `internal` | +| Discounts are between 0% and 100% | Column `discount_pct` | Range: min `0`, max `100` | +| Emails have a valid format | Column `email` | Regex: `^[^@\s]+@[^@\s]+\.[^@\s]+$` | +| Country codes have two characters | Column `country_code` | Length: min `2`, max `2` | +| Order totals are not negative | Expression `amount - discount` | Range: min `0` | + +## dbt equivalent + +In dbt, these rules map to the [`accepted_values`](https://docs.getdbt.com/reference/resource-properties/data-tests#accepted_values) test and to package tests such as `dbt_expectations.expect_column_values_to_be_between`, `expect_column_values_to_match_regex`, and `expect_column_value_lengths_to_be_between`. See [Cloud tests or dbt tests](/cloud/features/data-tests/cloud-or-dbt-tests) to decide which to use. diff --git a/docs/cloud/features/elementary-runtime.mdx b/docs/cloud/features/elementary-runtime.mdx index 912d35efa..a12fc8923 100644 --- a/docs/cloud/features/elementary-runtime.mdx +++ b/docs/cloud/features/elementary-runtime.mdx @@ -21,6 +21,16 @@ Elementary Runtime is a small service that runs in your network. It uses an outb Elementary Cloud remains the control plane. It decides what should run, prepares the SQL, schedules tests, interprets results, and manages incidents. Elementary Runtime is the data plane for supported operations. It checks and executes the SQL, then returns only the result needed by the Cloud workflow. +## What runs on the runtime + +When a runtime reports a warehouse connection as healthy, Elementary sends the queries that read table data on that connection through the runtime, instead of connecting to the warehouse directly: + +- [SQL data tests](/cloud/features/data-tests/sql-data-tests): uniqueness, completeness, validity, and relationship tests, including their previews +- [Custom SQL tests](/cloud/features/data-tests/custom-sql-tests), including query validation runs +- Warehouse queries that the [Elementary AI agent](/cloud/ai-agents/ai-test-coverage) runs after you approve them + +Metadata-based monitors, such as [cloud freshness](/cloud/features/anomaly-detection/automated-freshness) and [cloud volume](/cloud/features/anomaly-detection/automated-volume) tests, are not affected. + ## Why use Elementary Runtime diff --git a/docs/docs.json b/docs/docs.json index 7b004fbbf..6ffb139f4 100644 --- a/docs/docs.json +++ b/docs/docs.json @@ -68,6 +68,7 @@ { "group": "Data Tests", "pages": [ + "cloud/features/data-tests/cloud-or-dbt-tests", { "group": "Cloud Tests", "pages": [ @@ -76,6 +77,16 @@ "cloud/features/anomaly-detection/automated-volume", "cloud/features/anomaly-detection/cloud-pipeline-task-performance", "cloud/features/data-tests/data-contract-test", + { + "group": "SQL data tests", + "pages": [ + "cloud/features/data-tests/sql-data-tests", + "cloud/features/data-tests/sql-data-tests/uniqueness", + "cloud/features/data-tests/sql-data-tests/completeness", + "cloud/features/data-tests/sql-data-tests/validity", + "cloud/features/data-tests/sql-data-tests/relationship" + ] + }, "cloud/features/data-tests/custom-sql-tests", "cloud/features/anomaly-detection/metrics" ] diff --git a/docs/pics/cloud/data-tests/custom-sql-test-run-query.webp b/docs/pics/cloud/data-tests/custom-sql-test-run-query.webp new file mode 100644 index 000000000..765210b76 Binary files /dev/null and b/docs/pics/cloud/data-tests/custom-sql-test-run-query.webp differ diff --git a/docs/pics/cloud/data-tests/sql-data-tests-relationship.webp b/docs/pics/cloud/data-tests/sql-data-tests-relationship.webp new file mode 100644 index 000000000..a41b639e5 Binary files /dev/null and b/docs/pics/cloud/data-tests/sql-data-tests-relationship.webp differ diff --git a/docs/pics/cloud/data-tests/sql-data-tests-test-picker.webp b/docs/pics/cloud/data-tests/sql-data-tests-test-picker.webp new file mode 100644 index 000000000..e29bbaaf9 Binary files /dev/null and b/docs/pics/cloud/data-tests/sql-data-tests-test-picker.webp differ diff --git a/docs/pics/cloud/data-tests/sql-data-tests-validity-rule.webp b/docs/pics/cloud/data-tests/sql-data-tests-validity-rule.webp new file mode 100644 index 000000000..d15c364b3 Binary files /dev/null and b/docs/pics/cloud/data-tests/sql-data-tests-validity-rule.webp differ diff --git a/docs/snippets/cloud/features/data-tests/data-tests-cards.mdx b/docs/snippets/cloud/features/data-tests/data-tests-cards.mdx index b647b1153..9d9a436bb 100644 --- a/docs/snippets/cloud/features/data-tests/data-tests-cards.mdx +++ b/docs/snippets/cloud/features/data-tests/data-tests-cards.mdx @@ -5,6 +5,9 @@ Tests of packages such as `dbt-expectations`, `dbt-utils`, etc. + + Cloud tests for uniqueness, completeness, validity, and relationships, with no SQL to write. + Cloud tests that run SQL queries against your warehouse to validate business rules. diff --git a/docs/snippets/cloud/features/data-tests/sql-tests-requirements.mdx b/docs/snippets/cloud/features/data-tests/sql-tests-requirements.mdx new file mode 100644 index 000000000..fb6dd5a08 --- /dev/null +++ b/docs/snippets/cloud/features/data-tests/sql-tests-requirements.mdx @@ -0,0 +1,8 @@ + +SQL-based cloud tests read table data, so they need **data access** for the environment's warehouse connection. Data access is enabled in one of two ways: + +- Elementary enables data access on the warehouse connection. Contact the Elementary team to turn it on. +- You connect an [Elementary Runtime](/cloud/features/elementary-runtime) to the warehouse connection. + +Until data access is available, these tests are hidden from the test catalog. + diff --git a/docs/snippets/cloud/features/data-tests/sql-tests-thresholds.mdx b/docs/snippets/cloud/features/data-tests/sql-tests-thresholds.mdx new file mode 100644 index 000000000..ac284bbfa --- /dev/null +++ b/docs/snippets/cloud/features/data-tests/sql-tests-thresholds.mdx @@ -0,0 +1,10 @@ +Every row the test returns is a failing row. Elementary compares the number of failing rows to the test's **Severity** setting: + +| Severity setting | Result | +| --- | --- | +| **Use simple severity** (default) | Any failing row produces the selected severity: **Error** or **Warning** | +| **Use conditional severity**, with **Return error if the number of failures >** `X` | **Failure** when the failing-row count is greater than `X` | +| **Use conditional severity**, with **Return warn if the number of failures >** `Y` | **Warning** when the failing-row count is greater than `Y` | +| **Use conditional severity**, with both | **Failure** above `X`, otherwise **Warning** above `Y`, otherwise **Pass**. The warning threshold must be lower than the error threshold | + +A run that can't complete, for example because the query timed out, a column no longer exists, or the warehouse role lacks permissions, gets the **Error** status with the reason. The test stays enabled and runs again on its next schedule. diff --git a/docs/snippets/cloud/features/data-tests/where-sql-tests-run.mdx b/docs/snippets/cloud/features/data-tests/where-sql-tests-run.mdx new file mode 100644 index 000000000..b12aad5d0 --- /dev/null +++ b/docs/snippets/cloud/features/data-tests/where-sql-tests-run.mdx @@ -0,0 +1,16 @@ +Elementary runs these queries in one of two ways, depending on how the environment's warehouse connection is set up: + +| | Elementary Cloud connection | Elementary Runtime | +| --- | --- | --- | +| Where the query runs | Elementary Cloud connects to your warehouse | A service you host in your network connects to your warehouse | +| Warehouse credentials | The connection configured for the environment in Elementary | Stay in your environment, in the runtime configuration | +| What Elementary Cloud receives | Test status, failing-row count, and a row sample | Test status, failing-row count, and a row sample, within the limits you set locally | +| Setup | None beyond enabling data access for the connection | [Deploy](/cloud/features/elementary-runtime/deployment) and [configure](/cloud/features/elementary-runtime/configuration) the runtime | + +With [Elementary Runtime](/cloud/features/elementary-runtime), Elementary Cloud still prepares the SQL, schedules the test, and manages results and incidents, but the runtime validates and executes the query inside your network. When a runtime reports a warehouse connection as healthy, Elementary sends all test runs and previews for that connection through the runtime instead of connecting directly. + +The runtime also enforces its own local limits for query time, concurrency, and result size, and can limit or disable row samples entirely. See [Local limits](/cloud/features/elementary-runtime/configuration#local-limits) and [What leaves your network](/cloud/features/elementary-runtime/configuration#what-leaves-your-network). + + +Use a dedicated, read-only warehouse role for these tests, whichever way they run. It only needs to read the tables your tests query. See [Database roles](/cloud/features/elementary-runtime/configuration#database-roles) for examples per warehouse. +