Mantenha tudo organizado com as coleções
Salve e categorize o conteúdo com base nas suas preferências.
Este documento mostra como declarar origens de dados do BigQuery com o
Dataform core.
Pode declarar qualquer tipo de tabela do BigQuery
como uma origem de dados no Dataform. A declaração de origens de dados do BigQuery
externas ao Dataform permite-lhe tratar essas origens de dados como
objetos do Dataform.
A declaração de origens de dados é opcional, mas pode ser útil quando quer fazer o seguinte:
Referencie ou resolva origens declaradas da mesma forma que qualquer outra tabela no Dataform.
Veja as origens declaradas no gráfico do Dataform visualizado.
Use o Dataform para gerir as descrições ao nível da tabela e da coluna de tabelas criadas externamente.
Acionar invocações de fluxo de trabalho que incluem todos os dependentes de uma origem de dados externa.
Pode declarar origens de dados através de ficheiros JavaScript ou SQLX. Num ficheiro JavaScript, pode declarar várias origens de dados por ficheiro. Num ficheiro SQLX, pode declarar uma origem de dados por ficheiro.
Para receber as autorizações de que
precisa para declarar uma origem de dados,
peça ao seu administrador que lhe conceda a
função do IAM Editor do Dataform (roles/dataform.editor) nos espaços de trabalho.
Para mais informações sobre a atribuição de funções, consulte o artigo Faça a gestão do acesso a projetos, pastas e organizações.
Crie um ficheiro JavaScript para várias declarações de origens de dados
Armazene ficheiros JavaScript para declarações de origens de dados no diretório definitions/.
Para criar um novo ficheiro JavaScript no diretório definitions/, siga estes passos:
DATABASE_PROJECT_ID: o ID do projeto que contém a origem de dados.
BIGQUERY_SCHEMA: o conjunto de dados do BigQuery no qual a origem de dados existe.
RELATION_NAME: o nome da tabela ou da vista que quer usar como origem de dados. Posteriormente, pode usar esse nome para fazer referência à origem de dados no Dataform.
Crie um ficheiro SQLX para a declaração da origem de dados
Armazene ficheiros SQLX para declarações de origens de dados no diretório definitions/.
Para criar um novo ficheiro SQLX no diretório definitions/, siga estes passos:
Selecione um espaço de trabalho de desenvolvimento.
No painel Ficheiros, junto a definitions/, clique no menu Mais.
Clique em Criar ficheiro.
No painel Criar novo ficheiro, faça o seguinte:
No campo Adicionar um caminho de ficheiro, após definitions/, introduza o nome do ficheiro seguido de .sqlx. Por exemplo,
definitions/dataset-declaration.sqlx.
Os nomes de ficheiros só podem incluir números, letras, hífenes e sublinhados.
Clique em Criar ficheiro.
Declare uma origem de dados
Pode declarar uma origem de dados por ficheiro de declaração SQLX. Para declarar uma origem de dados no bloco de configuração de um ficheiro SQLX, siga estes passos:
No espaço de trabalho de desenvolvimento, no painel Ficheiros, clique no ficheiro SQLX
para a declaração da origem de dados.
No ficheiro, introduza o seguinte fragmento do código:
DATABASE: o ID do projeto que contém a origem de dados.
SCHEMA: o conjunto de dados do BigQuery no qual a origem de dados existe.
NAME: o nome da tabela ou da vista que quer usar como origem de dados. Posteriormente, pode usar esse nome para fazer referência à origem de dados no Dataform.
Opcional: clique em Formatar.
O seguinte exemplo de código mostra uma declaração de amostra da tabela shakespeare
no conjunto de dados samples do projeto como
uma origem de dados:bigquery-public-data
[[["Fácil de entender","easyToUnderstand","thumb-up"],["Meu problema foi resolvido","solvedMyProblem","thumb-up"],["Outro","otherUp","thumb-up"]],[["Difícil de entender","hardToUnderstand","thumb-down"],["Informações incorretas ou exemplo de código","incorrectInformationOrSampleCode","thumb-down"],["Não contém as informações/amostras de que eu preciso","missingTheInformationSamplesINeed","thumb-down"],["Problema na tradução","translationIssue","thumb-down"],["Outro","otherDown","thumb-down"]],["Última atualização 2025-08-21 UTC."],[[["\u003cp\u003eDataform allows the declaration of BigQuery data sources, treating them as Dataform objects even if they are external to Dataform.\u003c/p\u003e\n"],["\u003cp\u003eDeclaring data sources in Dataform is optional but enables referencing them like any other table, viewing them in the Dataform graph, and managing their descriptions.\u003c/p\u003e\n"],["\u003cp\u003eData sources can be declared using either JavaScript files, where multiple sources are allowed per file, or SQLX files, where only one source per file is allowed.\u003c/p\u003e\n"],["\u003cp\u003eTo declare a data source, you need the Dataform Editor role and can utilize JavaScript or SQLX files, each requiring specific code snippets and file creation processes within the \u003ccode\u003edefinitions/\u003c/code\u003e directory.\u003c/p\u003e\n"],["\u003cp\u003eOnce declared, data sources can be used in workflow invocations that include all dependents of that external data source.\u003c/p\u003e\n"]]],[],null,["# Declare a data source\n\nThis document shows you how to declare BigQuery data sources with\n[Dataform core](/dataform/docs/overview#dataform-core).\n\nYou can declare any [BigQuery table type](/bigquery/docs/tables-intro)\nas a data source in Dataform. Declaring BigQuery data sources\nthat are external to Dataform lets you treat those data sources as\nDataform objects.\n\nDeclaring data sources is **optional**, but can be useful when you want to do the following:\n\n- Reference or resolve declared sources in the same way as any other table in Dataform.\n- View declared sources in the visualized Dataform graph.\n- Use Dataform to manage the table-level and column-level descriptions of externally created tables.\n- Trigger workflow invocations that include all the dependents of an external data source.\n\nYou can declare data sources using JavaScript or SQLX files. In a JavaScript file, you can declare multiple data sources per file. In a SQLX file, you can declare one data source per file.\n\nBefore you begin\n----------------\n\nBefore you declare a data source,\n[create and initialize a development workspace in your repository](/dataform/docs/create-workspace).\n\n### Required roles\n\n\nTo get the permissions that\nyou need to declare a data source,\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 a JavaScript file for multiple data source declarations\n--------------------------------------------------------------\n\nStore JavaScript files for data source declarations in the `definitions/` directory.\nTo create a new JavaScript file in the `definitions/` directory, follow these steps:\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 a repository.\n\n3. Select a development workspace.\n\n4. In the **Files** pane, next to `definitions/`, click the **More** menu.\n\n5. Click **Create file**.\n\n6. In the **Create new file** pane, do the following:\n\n 1. In the **Add a file path** field, after `definitions/`, enter the name\n of the file followed by `.js`. For example,\n `definitions/declarations.js`.\n\n Filenames can only include numbers, letters, hyphens, and underscores.\n 2. Click **Create file**.\n\n### Add a declaration to a JavaScript file\n\nYou can declare multiple data sources per JavaScript file. To add a new declaration, follow these steps:\n\n1. In your development workspace, in the **Files** pane, click your JavaScript file for data source declarations.\n2. In the file, for each data source, add the following code snippet:\n\n declare({\n database: \"\u003cvar translate=\"no\"\u003eDATABASE_PROJECT_ID\u003c/var\u003e\",\n schema: \"\u003cvar translate=\"no\"\u003eBIGQUERY_SCHEMA\u003c/var\u003e\",\n name: \"\u003cvar translate=\"no\"\u003eRELATION_NAME\u003c/var\u003e\",\n });\n\n Replace the following:\n - \u003cvar translate=\"no\"\u003eDATABASE_PROJECT_ID\u003c/var\u003e: the project ID of the project which contains the data source.\n - \u003cvar translate=\"no\"\u003eBIGQUERY_SCHEMA\u003c/var\u003e: the BigQuery dataset in which the data source exists.\n - \u003cvar translate=\"no\"\u003eRELATION_NAME\u003c/var\u003e: the name of the table or view that you want to use as the data source. You can later use that name to reference the data source in Dataform.\n\nCreate a SQLX file for data source declaration\n----------------------------------------------\n\nStore SQLX files for data source declarations in the `definitions/` directory.\nTo create a new SQLX file in the `definitions/` directory, follow these steps:\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 a repository.\n\n3. Select a development workspace.\n\n4. In the **Files** pane, next to `definitions/`, click the **More** menu.\n\n5. Click **Create file**.\n\n6. In the **Create new file** pane, do the following:\n\n 1. In the **Add a file path** field, after `definitions/`, enter the name\n of the file followed by `.sqlx`. For example,\n `definitions/dataset-declaration.sqlx`.\n\n Filenames can only include numbers, letters, hyphens, and underscores.\n 2. Click **Create file**.\n\n### Declare a data source\n\nYou can declare one data source per a SQLX declaration file. To declare a data\nsource in the configuration block of an SQLX file, follow these steps:\n\n1. In your development workspace, in the **Files** pane, click your SQLX file for data source declaration.\n2. In the file, enter the following code snippet:\n\n config {\n type: \"declaration\",\n database: \"\u003cvar translate=\"no\"\u003eDATABASE\u003c/var\u003e\",\n schema: \"\u003cvar translate=\"no\"\u003eSCHEMA\u003c/var\u003e\",\n name: \"\u003cvar translate=\"no\"\u003eNAME\u003c/var\u003e\",\n }\n\n Replace the following:\n - \u003cvar translate=\"no\"\u003eDATABASE\u003c/var\u003e: the project ID of the project which contains the data source.\n - \u003cvar translate=\"no\"\u003eSCHEMA\u003c/var\u003e: the BigQuery dataset in which the data source exists.\n - \u003cvar translate=\"no\"\u003eNAME\u003c/var\u003e: the name of the table or view that you want to use as the data source. You can later use that name to reference the data source in Dataform.\n3. Optional: Click **Format**.\n\nThe following code sample shows a sample declaration of the `shakespeare`\ntable in the `samples` dataset of the `bigquery-public-data` project as\na data source: \n\n config {\n type: \"declaration\",\n database: \"bigquery-public-data\",\n schema: \"samples\",\n name: \"shakespeare\",\n }\n\nWhat's next\n-----------\n\n- To learn how to declare a data source with JavaScript, see [Create workflows exclusively with JavaScript](/dataform/docs/javascript-in-dataform#create-workflows-with-javascript).\n- To learn how to define a table, see [Create tables](/dataform/docs/create-tables#create-table).\n- To learn how to configure table partitions and clusters, see [Create table partitions and clusters](/dataform/docs/create-tables#create-table-partitions-clusters)."]]