Mantieni tutto organizzato con le raccolte
Salva e classifica i contenuti in base alle tue preferenze.
Questa pagina descrive come configurare Datastream in modo da poter scrivere
i dati nei set di dati BigQuery.
Autorizzazioni obbligatorie
Datastream utilizza il supporto integrato di BigQuery per gli aggiornamenti di Change Data Capture (CDC). Datastream aggiorna le tabelle BigQuery
elaborando e applicando le modifiche trasmesse in streaming utilizzando l'API BigQuery Storage Write.
Le autorizzazioni necessarie per utilizzare l'API e importare i dati in BigQuery vengono concesse al ruolo agente di servizio Datastream.
Configurare BigQuery come destinazione
Per configurare Datastream per lo streaming in BigQuery, segui
questi passaggi:
Assicurati che l'API BigQuery sia abilitata nel tuo progetto Google Cloud.
I set di dati sono contenitori di primo livello utilizzati per organizzare e controllare l'accesso
alle tabelle BigQuery.
Quando configuri i set di dati per la destinazione BigQuery utilizzando
Datastream, puoi selezionare una delle seguenti opzioni:
Set di dati per ogni schema: il set di dati viene selezionato o creato automaticamente da Datastream nella posizione BigQuery specificata, in base al nome dello schema dell'origine. Di conseguenza, ogni schema nell'origine ha un set di dati corrispondente in BigQuery.
Ad esempio, se hai un'origine MySQL e questa origine ha un database mydb e una tabella employees all'interno del database, Datastream crea il set di dati mydb e la tabella employees in BigQuery.
Se selezioni questa opzione, Datastream crea set di dati nel progetto che contiene lo stream. Anche se non è necessario creare i set di dati nella stessa regione del flusso, ti consigliamo di mantenere tutte le risorse del flusso, nonché i set di dati, nella stessa regione per ottimizzare costi e prestazioni.
Un unico set di dati per tutti gli schemi: seleziona un set di dati BigQuery per lo stream. Datastream trasmette in streaming tutti i dati in questo set di dati. Per il set di dati selezionato, Datastream crea tutte le tabelle come <schema>_<table>.
Ad esempio, se hai un'origine MySQL e questa origine ha un database mydb e una tabella employees all'interno del database, Datastream crea la tabella mydb_employees nel set di dati che selezioni.
Configura la modalità di scrittura
Esistono due modalità che puoi utilizzare per definire come vuoi che i dati vengano scritti in BigQuery:
Unione: questa è la modalità di scrittura predefinita. Se selezionata, BigQuery riflette il modo in cui i dati vengono archiviati nel database di origine. Ciò significa che Datastream scrive tutte le modifiche ai tuoi dati in BigQuery, che poi le consolida con i dati esistenti, creando così tabelle finali che sono repliche delle tabelle di origine. Con la modalità di unione, non viene conservato alcun record storico degli eventi di modifica. Ad esempio, se inserisci e poi aggiorni una riga, BigQuery conserva solo i dati aggiornati. Se poi elimini la riga dalla tabella di origine, BigQuery non conserva più alcun record di quella riga.
Solo accodamento: la modalità di scrittura solo accodamento ti consente di aggiungere dati a BigQuery come flusso di modifiche (eventi INSERT, UPDATE-INSERT, UPDATE-DELETE e DELETE). Utilizza questa modalità quando devi conservare lo stato storico dei dati.
Per comprendere meglio la modalità di scrittura di sola aggiunta, considera i seguenti scenari:
Backfill iniziale: dopo il backfill iniziale, tutti gli eventi vengono scritti in BigQuery come eventi di tipo INSERT, con lo stesso timestamp, lo stesso identificatore univoco universale (UUID) e lo stesso numero di sequenza di modifica.
Aggiornamento della chiave primaria: quando una chiave primaria cambia, in BigQuery vengono scritte due righe:
Una riga UPDATE-DELETE con la chiave primaria originale
Una riga UPDATE-INSERT con la nuova chiave primaria
Aggiornamento riga: quando aggiorni una riga, in BigQuery viene scritta una singola riga UPDATE-INSERT
Eliminazione di righe: quando elimini una riga, in BigQuery viene scritta una singola riga DELETE
Specifica il limite di inattività dei dati
BigQuery applica le modifiche all'origine in background su base continuativa o al momento dell'esecuzione delle query, secondo il limite di obsolescenza dei dati configurato. Quando Datastream crea una nuova tabella in BigQuery, l'opzione max_staleness della tabella viene impostata in base al valore attuale del limite di inattività dei dati per lo stream.
Per ulteriori informazioni sull'utilizzo delle tabelle BigQuery con l'opzione max_staleness, consulta Stalezza della tabella.
[[["Facile da capire","easyToUnderstand","thumb-up"],["Il problema è stato risolto","solvedMyProblem","thumb-up"],["Altra","otherUp","thumb-up"]],[["Difficile da capire","hardToUnderstand","thumb-down"],["Informazioni o codice di esempio errati","incorrectInformationOrSampleCode","thumb-down"],["Mancano le informazioni o gli esempi di cui ho bisogno","missingTheInformationSamplesINeed","thumb-down"],["Problema di traduzione","translationIssue","thumb-down"],["Altra","otherDown","thumb-down"]],["Ultimo aggiornamento 2025-09-04 UTC."],[],[],null,["# Configure a BigQuery destination\n\nThis page describes how to configure Datastream so that you can write\ndata to BigQuery datasets.\n\nRequired permissions\n--------------------\n\nDatastream uses the BigQuery built-in support for change data\ncapture (CDC) updates. Datastream updates the BigQuery tables\nby processing and applying streamed changes using the BigQuery Storage Write API.\n\nThe permissions required for using the API and ingesting data to\nBigQuery are granted to the\n[Datastream Service Agent](/iam/docs/roles-permissions/datastream#datastream.serviceAgent)\nrole.\n\nConfigure BigQuery as a destination\n-----------------------------------\n\nTo configure Datastream for streaming to BigQuery, perform the\nfollowing steps:\n\n1. Make sure that the BigQuery API is enabled in your Google Cloud project.\n2. If you want to use the **Single dataset for all schemas** option, [create a dataset in BigQuery](/bigquery/docs/datasets#create-dataset).\n3. [Configure the destination dataset for your stream](#configure-datasets).\n4. [Configure write mode](#configure-write-mode).\n5. [Specify the maximum data staleness limit](#specify-staleness) for your stream.\n\n### Configure the destination datasets\n\nDatasets are top-level containers that are used to organize and control access\nto your BigQuery tables.\n\nWhen you configure datasets for the BigQuery destination using\nDatastream, you can select one of the following options:\n\n- **Dataset for each schema** : The dataset is selected or automatically created by Datastream in the [BigQuery location](/bigquery/docs/locations) specified, based on the schema name of the source. As a result, each schema in the source has a corresponding dataset in BigQuery.\n For example, if you have a MySQL source, and this source has a `mydb`\n database and an `employees` table within the database, then\n Datastream creates the `mydb` dataset and `employees` table in\n BigQuery.\n\n If you select this option, then Datastream creates datasets in the project that contains the stream. Although you don't need to create the datasets in the same region as your stream, we recommend to keep all resources for the stream, as well as datasets, in the same region for cost and performance optimization.\n | **Note:** The **Dataset for each schema** option isn't supported for Salesforce sources ([Preview](/products#product-launch-stages)).\n- **Single dataset for all schemas** : You select a BigQuery\n dataset for the stream. Datastream streams all data into this\n dataset. For the dataset that you select, Datastream creates all\n tables as `\u003cschema\u003e_\u003ctable\u003e`.\n\n For example, if you have a MySQL source, and this source has a `mydb`\n database and an `employees` table within the database, then\n Datastream creates the `mydb_employees` table in the dataset that\n you select.\n | **Note:** If your source is Salesforce ([Preview](/products#product-launch-stages)), Datastream uses the customer domain as the dataset name.\n\n### Configure write mode\n\nThere are two modes you can use to define how you want your data written to\nBigQuery:\n\n- **Merge**: This is the default write mode. When selected, BigQuery reflects the way your data is stored in the source database. This means that Datastream writes all changes to your data to BigQuery, and BigQuery then consolidates the changes with existing data, thus creating final tables that are replicas of the source tables. With merge mode, no historical record of the change events is kept. For example, if you insert and then update a row, BigQuery only keeps the updated data. If you then delete the row from the source table, BigQuery no longer keeps any record of that row.\n\n | **Note:** Merge mode is only applicable for tables with primary keys. Tables without primary keys are append-only.\n- **Append-only** : The append-only write mode lets you add data to BigQuery as a stream of changes (`INSERT`, `UPDATE-INSERT`, `UPDATE-DELETE` and `DELETE` events). Use this mode when you need to retain the historical state of your data.\n To get a better understanding of the append-only write mode, consider the following scenarios:\n\n - *Initial backfill* : after the initial backfill, all events are written to BigQuery as `INSERT` type events, with the same timestamp, universally unique identifier (UUID), and change sequence number.\n - *Primary key update* : when a primary key changes, two rows are written to BigQuery:\n - An `UPDATE-DELETE` row with the original primary key\n - An `UPDATE-INSERT` row with the new primary key\n - *Row update* : when you update a row, a single `UPDATE-INSERT` row is written to BigQuery\n - *Row deletion* : when you delete a row, a single `DELETE` row is written to BigQuery\n\n### Specify data staleness limit\n\nBigQuery applies source modifications in the background on an ongoing basis, or at query run time, according to the configured data staleness limit. When Datastream creates a new table in BigQuery, the table's `max_staleness` option is set according to the current data staleness limit value for the stream.\n\nFor more information about using BigQuery tables with the `max_staleness` option, see [Table staleness](/bigquery/docs/change-data-capture#manage_table_staleness)."]]