[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["很难理解","hardToUnderstand","thumb-down"],["信息或示例代码不正确","incorrectInformationOrSampleCode","thumb-down"],["没有我需要的信息/示例","missingTheInformationSamplesINeed","thumb-down"],["翻译问题","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2025-08-19。"],[],[],null,["# Configure additional actions\n\nThis document shows you how to do the following:\n\n- [Define a SQL statement to be run before table creation](#execute-sql-before-table).\n- [Define a SQL statement to be run after table creation](#execute-sql-after-table).\n- [Disable table creation](#disable-table-creation).\n- [Add execution tags](#add-execution-tags).\n\nBefore you begin\n----------------\n\n1. In the Google Cloud console, go to the **Dataform** page.\n\n [Go to Dataform](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\n5. Define a SQLX file of any of the following types:\n\n - [`type: table`](/dataform/docs/create-tables#create-table)\n - [`type: view`](/dataform/docs/create-tables#create-table)\n - [`type: incremental`](/dataform/docs/create-tables#create-table)\n - [`type: assertion`](/dataform/docs/assertions)\n - [`type: operations`](/dataform/docs/custom-sql)\n\n### Required roles\n\n\nTo get the permissions that\nyou need to complete the tasks in this document,\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\nDefine a SQL statement to be run before table creation\n------------------------------------------------------\n\nYou can configure Dataform to run one or more SQL statements\nbefore creating a selected table in BigQuery. To run a SQL\nstatement before Dataform creates a selected table, add your\nstatement to the `pre_operations` block in the table definition SQLX file.\n\nTo create a custom SQL statement that's run before Dataform creates\na specific table, follow these steps:\n\n1. Go to your development workspace.\n2. In the **Files** pane, expand `definitions/`.\n3. Open a SQLX table definition file.\n4. Outside the `config` block, enter `pre_operations { ... }`.\n5. Inside `pre_operations { ... }`, add your SQL statement.\n6. Optional: To add multiple statements, separate them with `---`.\n7. Optional: Click **Format**.\n\nThe following code sample shows a `pre_operations` statement that creates a\ntemporary function that can be used in the select statement: \n\n pre_operations {\n CREATE TEMP FUNCTION AddFourAndDivide(x INT64, y INT64)\n RETURNS FLOAT64\n AS ((x + 4) / y);\n }\n\nDefine a SQL statement to be run after table creation\n-----------------------------------------------------\n\nYou can configure Dataform to run one or more SQL statements\nafter creating a selected table in BigQuery. To run a SQL statement\nafter Dataform creates a selected table, add your statement to\nthe `post_operations` block in the table definition SQLX file. You can add\nmultiple SQL statements to the `post_operations` block.\n\nTo create a custom SQL statement that's run after Dataform creates\na specific table, follow these steps:\n\n1. Go to your development workspace.\n2. In the **Files** pane, expand `definitions/`.\n3. Open a SQLX table definition file.\n4. Outside the `config` block, enter `post_operations { ... }`.\n5. Inside `post_operations { ... }`, add your SQL statement.\n6. Optional: Click **Format**.\n\nThe following code sample shows `post_operations` statements that grant groups\naccess to the created table: \n\n post_operations {\n GRANT `roles/bigquery.dataViewer`\n ON\n TABLE ${self()}\n TO \"group:allusers@example.com\", \"user:otheruser@example.com\"\n }\n\nDisable table creation\n----------------------\n\nTo stop Dataform from creating a selected table in\nBigQuery, you can disable the table in its SQLX table definition file.\nDataform keeps a disabled table in the dependency graph, but it does\nnot compile and create it. This can be useful, for example, if a table fails and\nyou don't want your whole workflow to fail while you fix the issue.\n\nTo disable a table, follow these steps:\n\n1. Go to your development workspace.\n2. In the **Files** pane, expand `definitions/`.\n3. Select a SQLX table definition file.\n4. In the `config` block of the file, enter `disabled: true`.\n5. Optional: Click **Format**.\n\nThe following code sample shows a disabled table: \n\n config {\n type: \"table\",\n disabled: true\n }\n\n select * from ${ref(\"source_data\")}\n\nAdd execution tags\n------------------\n\nThis section shows you how to add tags to\n[Dataform core](/dataform/docs/overview#dataform-core) SQLX files to\ncategorize your workflow.\n\nTo organize the components of your workflow into collections, you can add\ncustom tags to SQLX files of the following types:\n\n- `table`\n- `view`\n- `incremental`\n- `assertion`\n- `operations`\n\nDuring a workflow run, you can\n[run only files with a selected tag](/dataform/docs/trigger-execution).\n\nWith [Cloud Composer](/dataform/docs/schedule-runs#composer) or\n[Workflows together with Cloud Scheduler](/dataform/docs/schedule-runs#workflows-cloud-scheduler),\nyou can create a schedule that runs a Dataform workflow with\na selected tag at a specific interval.\n\n### Add a tag\n\nYou can add multiple tags to a SQLX file.\n\nTo add a tag to a SQLX file, follow these steps:\n\n1. Go to your development workspace.\n2. In the **Files** pane, expand `definitions/`.\n3. Select a SQLX file.\n4. In the `config` block, add a tag in the following format:\n\n tags: [\"\u003cvar translate=\"no\"\u003eCUSTOM_TAG\u003c/var\u003e\"]\n\n Replace \u003cvar translate=\"no\"\u003eCUSTOM_TAG\u003c/var\u003e with your tag.\n5. Optional: To add multiple tags, separate them with a comma (`,`).\n\n6. Optional: Click **Format**.\n\nThe following code sample shows the `user_counts` view with the `daily` and\n`hourly` tags: \n\n config {\n type: \"view\",\n name: \"user_counts\",\n tags: [\"daily\", \"hourly\"]\n }\n\nWhat's next\n-----------\n\n- To learn how to configure Dataform settings in `workflow_settings.yaml`, see [Configure Dataform workflow settings](/dataform/docs/manage-repository#configure-workflow-settings).\n- To learn how to test table data with assertions, see [Test data quality](/dataform/docs/assertions).\n- To learn how to reuse code with includes, see [Reuse code across a single repository with includes](/dataform/docs/javascript-in-dataform#reuse_code_across_a_single_repository_with_includes).\n- To learn to manually trigger executions, see [Manually trigger runs](/dataform/docs/trigger-execution).\n- To learn how to add BigQuery policy tags in Dataform, see [Control column access](/dataform/docs/policy-tags)."]]