Area: Observability
Sub-Area: Data Quality
Applies to: Cloud
Issue
A Custom SQL assertion in DataHub Cloud fails to run, shows an unexpected pass or fail result, or can't be created. Common signs:
- The assertion reports
Unable to retrieve valid connection for Data Platform with urn <urn>. - The assertion reports
Missing connection URN for SQL assertion evaluation. - The assertion fails when you expect a pass, or passes when you expect a failure.
- The Create button on the Quality tab is missing or disabled.
- Creating a monitor fails with
Monitor limit exceeded. Current monitors: <N>, attempting to create: <N>, maximum allowed: <N>. Cannot create new monitor entity.
You Might Be Asking
- How do I write a Custom SQL assertion?
- Does the query have to return 0 to pass?
- Which platforms and SQL dialects are supported?
- Why can't I see or click Create on the Quality tab?
- Why is my assertion erroring?
Cause
Common causes:
- Unsupported platform. Custom SQL assertions run only on Snowflake, Redshift, BigQuery and Databricks. They don't run on Postgres or other platforms.
-
No usable ingestion source. The assertion runs its query through the ingestion source that ingested the table, using that source's connection and configured user or role. There is no separate assertion connection or assertion role.
Unable to retrieve valid connection for Data Platform with urn <urn>means the executor found no usable ingestion source for the dataset. Either no ingestion source was found, or the source that ingested the table is an ingestion source run from the CLI rather than set up in the DataHub UI. The<urn>in this message is normally the data platform URN, for exampleurn:li:dataPlatform:snowflake, not the dataset URN. -
Assertion has no connection URN.
Missing connection URN for SQL assertion evaluationis a separate error. It means the assertion reached the executor with no connection URN at all. It does not mean the dataset has no ingestion source. - Missing read access. The user or role configured in that ingestion source can't read the table, or the query doesn't use the fully qualified table name.
- Wrong condition. The query's result is a number. The condition you choose under Pass if resulting value decides pass or fail. A result of 0 has no built-in meaning.
- Missing privileges. Creating a Custom SQL assertion needs more privileges than other assertion types.
- Monitor limit. The default maximum is 1000 monitors.
Solution
-
Check the platform. Use a table from Snowflake, Redshift, BigQuery or Databricks.
-
Check the ingestion source. The table must have been ingested by a source for that platform. If several sources ingested the same table, the executor uses the one that ingested the table's dataset properties. Your DataHub representative can change this. Make sure the user or role configured in that source has read access to the table. See source system selection.
- If you see
Unable to retrieve valid connection for Data Platform with urn <urn>, make sure the table is ingested by an ingestion source set up in the DataHub UI, not one run from the CLI. Then check the assertion again. - If you see
Missing connection URN for SQL assertion evaluation, changing the ingestion source won't address it, because the assertion arrived with no connection URN. Contact DataHub Support.
- If you see
-
Write the query. The query must return one row with one numeric column (integer or float). Use the fully qualified table name. For example:
SELECT COUNT(*) FROM analytics.public.sales WHERE amount < 0 OR amount IS NULL;Then pick the condition under Pass if resulting value. The options are Is equal to, Is not equal to, Is greater than, Is less than, Is within a range, Grows at least, Grows at most, and Grows within a range. For the query above, choose Is equal to with the value 0 to pass when no bad rows exist. DataHub records success if the condition holds and failure if it doesn't.
-
Create the assertion in the UI.
- Open the table and click the Quality tab.
- Click Create and choose Custom.
- Set the evaluation schedule.
- Enter the SQL query.
- Choose the condition.
- Configure actions (raise or resolve an incident).
- Optional: click Try it out. It isn't available for sources that run on a Remote Executor. The UI says "Trying assertions is not supported for sources with remote executors."
- Click Next, add a description, and click Save.
There is no step to pick a connection. The dataset's ingestion source connection is used. See Custom SQL Assertions.
-
If Create is missing or disabled.
- If the button doesn't appear, assertion monitors are not enabled for your instance. Contact DataHub Support.
- If it is disabled, you may lack privileges, or the platform may not support assertion monitoring. You need both the Edit Assertions and Edit Monitors privileges on the dataset. Custom SQL assertions also need the Edit SQL Assertion Monitors privilege, or the platform Manage Monitors privilege. A general "all privileges on the entity" grant does not count. Ask a DataHub admin to grant them through a policy. Don't assume default policies give them to you, because your admins may have changed them.
-
If you hit the monitor limit, contact DataHub Support to review it. The limit is set on the server.
-
Create the assertion with the API (optional). You can use the GraphQL mutation
upsertDatasetSqlAssertionMonitor(assertionUrn: String, input: UpsertDatasetSqlAssertionMonitorInput!). PassassertionUrnonly when you update an assertion. The input requiresentityUrn,type(METRICorMETRIC_CHANGE),statement,operatorandparameters. Cloud evaluates an assertion through a monitor as well as the assertion, and this mutation is the documented way to create both for Custom SQL. The GraphQL endpoint ishttps://<your-account>.acryl.io/api/graphql. Call it with a personal access token as a Bearer token.You can also use the Python SDK from
acryl-datahub-cloud:from datahub.sdk import DataHubClient client = DataHubClient(server="<your_server>", token="<your_token>") client.assertions.sync_sql_assertion( dataset_urn="<dataset_urn>", display_name="No negative or null amounts", statement="SELECT COUNT(*) FROM analytics.public.sales WHERE amount < 0 OR amount IS NULL", criteria_condition="IS_EQUAL_TO", criteria_parameters=0, schedule="0 0 * * *", )criteria_parameterstakes a number, or a(min, max)tuple for range conditions. If you leave outscheduleon create, the assertion runs daily at0 0 * * *. See Assertions API and Python SDK.Don't use the
datahub assertionsCLI or assertion YAML files. They are deprecated. -
Check results.
- Open the Data Health Dashboard under Observe in the sidebar. On the Assertions tab, use the By Assertion view, set a time range such as Last 7 Days, and set Results to At least one failure. This shows which assertions fail and how often they fail compared with how often they run. See Data Health Dashboard.
- Or query GraphQL. Select
assertions { ... }insideassertions(...), and selectrunEvents { ... }insiderunEvents(...):
query { dataset(urn: "YOUR_DATASET_URN") { assertions(start: 0, count: 20) { assertions { urn runEvents(limit: 5) { total succeeded failed errored runEvents { result { type actualAggValue } } } } } } }result.typeisINIT,SUCCESS,FAILUREorERROR. The runstatusis alwaysCOMPLETE, so useresult.typefor pass or fail.runEventshas nostartorcountarguments. Without a time range it returns the most recent events, up tolimit.
Related Documentation
- Assertions Guide
- Assertions: source system selection
- Custom SQL Assertions
- Assertions API and Python SDK
- Data Health Dashboard
Tags: assertions, data-quality, custom-sql, validation, data-contracts, sql-queries, observability, testing