Usar o Datastream para ingerir dados em tabelas particionadas no BigQuery
Mantenha tudo organizado com as coleções
Salve e categorize o conteúdo com base nas suas preferências.
Talvez seja necessário particionar as tabelas do BigQuery em segmentos menores para melhorar a performance da consulta e controlar os custos. Como o Datastream não oferece suporte a tabelas de particionamento no BigQuery, é necessário adicionar as partições manualmente antes de iniciar o fluxo. Para informações gerais sobre particionamento
no BigQuery, consulte Introdução às tabelas particionadas.
Particionar tabelas no BigQuery
Para particionar as tabelas no BigQuery, use uma das opções descritas
nas seções a seguir, dependendo do seu caso de uso.
Opção 1: a tabela já existe no BigQuery e está incluída em um fluxo
Exclua a tabela da configuração de origem do fluxo. Para mais informações sobre como incluir e excluir objetos da configuração de origem, consulte Configurar bancos de dados de origem.
Aguarde alguns minutos para garantir que o Datastream tenha concluído o processamento
de todos os eventos da tabela.
Crie a tabela particionada no BigQuery.
Se você quiser manter os dados que já estavam na tabela original do BigQuery, dê um nome temporário diferente a ela.
Copie os dados da tabela original para a nova tabela particionada.
Exclua ou renomeie a tabela original.
Mude o nome temporário da nova tabela para o nome da tabela original.
Adicione a tabela de origem à configuração do fluxo.
Opção 2: a tabela não existe no BigQuery
Crie a tabela no BigQuery usando uma das seguintes abordagens:
Crie manualmente uma tabela do BigQuery compatível com o Datastream. Por
exemplo, se você quiser criar uma tabela e particionar os dados com base na
coluna TIMESTAMP, use uma consulta semelhante a esta:
Depois de criar a tabela particionada, verifique se o valor max_staleness
está definido de acordo com seus requisitos. Se você não definir o valor, o valor padrão
de 0 será definido. Deixar esse valor em 0 garante os dados mais recentes, mas
incorre em um custo significativo. Para informações sobre como encontrar o valor ideal para sua tabela, consulte Usar tabelas do BigQuery com a opção max_staleness.
[[["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-09-04 UTC."],[[["\u003cp\u003eBigQuery table partitioning is necessary for improved query performance and cost control, but Datastream does not automatically support it.\u003c/p\u003e\n"],["\u003cp\u003eFor tables already in BigQuery and included in a stream, you must exclude the table from the stream, create a partitioned table, copy data, and then re-add the table to the stream's configuration.\u003c/p\u003e\n"],["\u003cp\u003eIf the table is not yet in BigQuery, you can create a partitioned table manually or using the BigQuery Migration Toolkit, ensuring to set the \u003ccode\u003emax_staleness\u003c/code\u003e value, and then add it to your stream configuration.\u003c/p\u003e\n"],["\u003cp\u003eWhen creating partitioned tables manually, ensure that you define the correct data types and specify the \u003ccode\u003ePARTITION BY\u003c/code\u003e clause in your query, and create your primary key.\u003c/p\u003e\n"]]],[],null,["# Use Datastream to ingest data into partitioned tables in BigQuery\n\nYou might need to partition your BigQuery tables into smaller segments to\nimprove query performance and control costs. Because Datastream doesn't\nsupport partitioning tables in BigQuery, you need to manually add the\npartitions before starting your stream. For general information about partitioning\nin BigQuery, see [Introduction to partitioned tables](/bigquery/docs/partitioned-tables).\n\nPartition tables in BigQuery\n----------------------------\n\nTo partition your tables in BigQuery, use one of the options described\nin the sections that follow, depending on your use case.\n\n### Option 1: The table already exists in BigQuery and is included in a stream\n\n1. Exclude the table from the source configuration of your stream. For more information about including and excluding objects from your source configuration, see [Configure source databases](/datastream/docs/create-a-stream#configuresourcedb).\n2. Wait a few minutes to ensure that Datastream has completed processing all events for the table.\n3. [Create your partitioned table in BigQuery](/bigquery/docs/creating-partitioned-tables). If you want to keep the data that was already in the original BigQuery table, give the table a different, temporary name.\n4. Copy the data from the original table to the new partitioned table.\n5. Drop or rename the original table.\n6. Change the temporary name of the new table to the name of the original table.\n7. Add the source table to the configuration of your stream.\n\n### Option 2: The table doesn't exist in BigQuery\n\n1. Create the table in BigQuery using one of the following approaches:\n\n - Use the [BigQuery Migration Toolkit](/datastream/docs/best-practices-migration-toolkit).\n - Manually create a Datastream-compatible BigQuery table. For\n example, if you want to create a table and partition the data based on the\n `TIMESTAMP` column, you can use a query similar to the following:\n\n CREATE TABLE dataset.partitioned_table (\n 'id' INT64,\n 'name' STRING\n 'update_date' DATETIME,\n 'datastream_metadata' STRUCT\u003c'uuid' STRING, 'source_timestamp' INT64\u003e,\n PRIMARY KEY ('id') NOT ENFORCED\n )\n PARTITION BY TIMESTAMP(update_date)\n\n2. After you create the partitioned table, make sure that its `max_staleness` value\n is set according to your requirements. If you don't set the value, the default\n value of `0` is set. Leaving this value at `0` ensures the freshest data, but\n incurs a significant cost. For information about how to find the optimal value\n for your table, see [Use BigQuery tables with the `max_staleness` option](/datastream/docs/destination-bigquery#use-max-staleness).\n\n3. [Add the source table to the configuration of your stream](/datastream/docs/create-a-stream#configuresourcedb).\n\n4. Optionally, if you've set manual backfill for the stream, initiate backfill\n for the table."]]