[[["容易理解","easyToUnderstand","thumb-up"],["確實解決了我的問題","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["難以理解","hardToUnderstand","thumb-down"],["資訊或程式碼範例有誤","incorrectInformationOrSampleCode","thumb-down"],["缺少我需要的資訊/範例","missingTheInformationSamplesINeed","thumb-down"],["翻譯問題","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["上次更新時間:2025-09-04 (世界標準時間)。"],[[["\u003cp\u003eDataform enables you to create assertions, which are data quality test queries that identify rows violating specified conditions, failing if any rows are returned.\u003c/p\u003e\n"],["\u003cp\u003eDataform automatically generates views in BigQuery to store the results of compiled assertion queries, which can be found in a designated assertions schema.\u003c/p\u003e\n"],["\u003cp\u003eAssertions can be created either within a table's configuration block using built-in assertion types or as separate SQLX files for custom, manual assertions.\u003c/p\u003e\n"],["\u003cp\u003eWorkflow actions that depend on other actions with assertions can be configured to only execute if the assertions of the dependencies pass, using \u003ccode\u003edependencies\u003c/code\u003e in the config block.\u003c/p\u003e\n"],["\u003cp\u003eYou can use \u003ccode\u003edependOnDependencyAssertions\u003c/code\u003e and \u003ccode\u003eincludeDependentAssertions\u003c/code\u003e parameters in the workflow actions config block to control the dependency of your workflow action on the assertions.\u003c/p\u003e\n"]]],[],null,["# Test data quality\n\nThis document shows you how to use [Dataform core](/dataform/docs/overview#dataform-core) to create Dataform table assertions and test your workflow code.\n\n\u003cbr /\u003e\n\nAbout assertions\n----------------\n\nAn assertion is a data quality test query that finds rows that violate one or\nmore conditions specified in the query. If the query returns any rows,\nthe assertion\nfails. Dataform runs assertions every time it updates your workflow\nand it alerts you if any assertions fail.\n\nDataform automatically creates views in BigQuery that contain\nthe results of compiled assertion queries. As\n[configured in your workflow settings file](/dataform/docs/manage-repository#configure-workflow-settings),\nDataform creates these views in an assertions schema where you can\ninspect assertion results.\n\nFor example, for the default `dataform_assertions` schema, Dataform\ncreates a view in BigQuery in the following format:\n`dataform_assertions.assertion_name`.\n\nYou can create assertions for all Dataform table types: tables,\nincremental tables, views, and materialized views.\n\nYou can create assertions in the following ways:\n\n- [Add built-in assertions to the config block of a table](#built-in).\n\n You can add built-in assertions to the `config` block of a table and\n specify their conditions.\n- [Add manual assertions in a separate SQLX file](#manual).\n\n You manually write custom assertions in a separate SQLX file for advanced\n use cases or for datasets not created by Dataform.\n\nBefore you begin\n----------------\n\n1. In the Google Cloud console, go to the **Dataform** page.\n\n [Go to the Dataform page](https://console.cloud.google.com/bigquery/dataform)\n2. Select or [create a repository](/dataform/docs/create-repository).\n\n3. Select or [create a development workspace](/dataform/docs/create-workspace).\n\n4. [Create a table](/dataform/docs/create-tables#create-table).\n\n### Required roles\n\n\nTo get the permissions that\nyou need to create assertions,\n\nask your administrator to grant you the\n\n\n[Dataform Editor](/iam/docs/roles-permissions/dataform#dataform.editor) (`roles/dataform.editor`)\nIAM role on workspaces.\n\n\nFor more information about granting roles, see [Manage access to projects, folders, and organizations](/iam/docs/granting-changing-revoking-access).\n\n\nYou might also be able to get\nthe required permissions through [custom\nroles](/iam/docs/creating-custom-roles) or other [predefined\nroles](/iam/docs/roles-overview#predefined).\n\nCreate built-in assertions\n--------------------------\n\nYou can add built-in Dataform assertions to the `config` block of a\ntable. Dataform runs these assertions after table creation. After\nDataform creates the table, you can see if the assertion passed in the\n**Workflow execution logs** tab of your workspace.\n\nYou can create the following assertions in the `config` block of a table:\n\n- `nonNull`\n\n This condition asserts that the specified columns are not null across all\n table rows. This condition is used for columns that can never be null.\n\n The following code sample shows a `nonNull` assertion in the `config` block\n of a table:\n\n config {\n type: \"table\",\n assertions: {\n nonNull: [\"user_id\", \"customer_id\", \"email\"]\n }\n }\n SELECT ...\n\n- `rowConditions`\n\n This condition asserts that all table rows follow the custom logic you\n define. Each row condition is a custom SQL expression, and each table row is\n evaluated against each row condition. The assertion fails if any table row\n results in `false`.\n\n The following code sample shows a custom `rowConditions` assertion in the\n `config` block of an incremental table:\n\n config {\n type: \"incremental\",\n assertions: {\n rowConditions: [\n 'signup_date is null or signup_date \u003e \"2022-08-01\"',\n 'email like \"%@%.%\"'\n ]\n }\n }\n SELECT ...\n\n- `uniqueKey`\n\n This condition asserts that, in a specified column, no table rows have the\n same value.\n\n The following code sample shows a `uniqueKey` assertion in the `config`\n block of a view:\n\n config {\n type: \"view\",\n assertions: {\n uniqueKey: [\"user_id\"]\n }\n }\n SELECT ...\n\n- `uniqueKeys`\n\n This condition asserts that, in the specified columns, no table rows have\n the same value. The assertion fails if there is more than one row in the\n table with the same values for all the specified columns.\n\n The following code sample shows a `uniqueKeys` assertion in the `config`\n block of a table:\n\n config {\n type: \"table\",\n assertions: {\n uniqueKeys: [[\"user_id\"], [\"signup_date\", \"customer_id\"]]\n }\n }\n SELECT ...\n\n### Add assertions to the `config` block\n\nTo add assertions to the config block of a table, follow these steps:\n\n1. In your development workspace, in the **Files** pane, select a table definition SQLX file.\n2. In the `config` block of the table file, enter `assertions: {}`.\n3. Inside `assertions: {}`, add your assertions.\n4. Optional: Click **Format**.\n\nThe following code sample shows the conditions added in the `config` block: \n\n config {\n type: \"table\",\n assertions: {\n uniqueKey: [\"user_id\"],\n nonNull: [\"user_id\", \"customer_id\"],\n rowConditions: [\n 'signup_date is null or signup_date \u003e \"2019-01-01\"',\n 'email like \"%@%.%\"'\n ]\n }\n }\n SELECT ...\n\nCreate manual assertions with SQLX\n----------------------------------\n\nManual assertions are SQL queries that you write in a dedicated SQLX file. A\nmanual assertion SQL query must return zero rows. If the query returns rows\nwhen it's run, the assertion fails.\n\nTo add manual assertions in a new SQLX file, follow these steps:\n\n1. In the **Files** pane, next to `definitions/`, click the **More** menu.\n2. Click **Create file**.\n3. In the **Add a file path** field, enter the name of the file followed by\n `.sqlx`. For example, `definitions/custom_assertion.sqlx`.\n\n Filenames can only include numbers, letters, hyphens, and underscores.\n4. Click **Create file**.\n\n5. In the **Files** pane, click the new file.\n\n6. In the file, enter:\n\n config {\n type: \"assertion\"\n }\n\n7. Below the `config` block, write your SQL query or multiple queries.\n\n8. Optional: Click **Format**.\n\nThe following code sample shows a manual assertion in a SQLX file that asserts\nthat fields **A** , **B** , and `c` are never `NULL` in `sometable`: \n\n config { type: \"assertion\" }\n\n SELECT\n *\n FROM\n ${ref(\"sometable\")}\n WHERE\n a IS NULL\n OR b IS NULL\n OR c IS NULL\n\nWhat's next\n-----------\n\n- To learn more about assertion types, see [Dataform API](/dataform/reference/rest).\n- To learn how to define assertions with JavaScript, see [Create workflows exclusively with JavaScript](/dataform/docs/javascript-in-dataform#create-workflows-with-javascript).\n- To learn how to manually run workflows, see [Manually trigger runs](/dataform/docs/trigger-execution)."]]