Mit Datastream Daten in partitionierte Tabellen in BigQuery einlesen
Mit Sammlungen den Überblick behalten
Sie können Inhalte basierend auf Ihren Einstellungen speichern und kategorisieren.
Möglicherweise müssen Sie Ihre BigQuery-Tabellen in kleinere Segmente partitionieren, um die Abfrageleistung zu verbessern und die Kosten zu kontrollieren. Da Datastream keine partitionierten Tabellen in BigQuery unterstützt, müssen Sie die Partitionen manuell hinzufügen, bevor Sie den Stream starten. Allgemeine Informationen zur Partitionierung in BigQuery finden Sie unter Einführung in partitionierte Tabellen.
Tabellen in BigQuery partitionieren
Je nach Anwendungsfall können Sie Ihre Tabellen in BigQuery mit einer der folgenden Optionen partitionieren.
Option 1: Die Tabelle ist bereits in BigQuery vorhanden und in einem Stream enthalten
Schließen Sie die Tabelle von der Quellkonfiguration Ihres Streams aus. Weitere Informationen zum Ein- und Ausschließen von Objekten aus der Quellkonfiguration finden Sie unter Quelldatenbanken konfigurieren.
Warten Sie einige Minuten, bis Datastream die Verarbeitung aller Ereignisse für die Tabelle abgeschlossen hat.
Erstellen Sie manuell eine Datastream-kompatible BigQuery-Tabelle. Wenn Sie beispielsweise eine Tabelle erstellen und die Daten anhand der Spalte TIMESTAMP partitionieren möchten, können Sie eine Abfrage wie die folgende verwenden:
Achten Sie nach dem Erstellen der partitionierten Tabelle darauf, dass der max_staleness-Wert Ihren Anforderungen entspricht. Wenn Sie den Wert nicht festlegen, wird der Standardwert 0 verwendet. Wenn Sie diesen Wert bei 0 belassen, erhalten Sie die aktuellsten Daten. Dies ist jedoch mit erheblichen Kosten verbunden. Informationen dazu, wie Sie den optimalen Wert für Ihre Tabelle ermitteln, finden Sie unter BigQuery-Tabellen mit der Option max_staleness verwenden.
[[["Leicht verständlich","easyToUnderstand","thumb-up"],["Mein Problem wurde gelöst","solvedMyProblem","thumb-up"],["Sonstiges","otherUp","thumb-up"]],[["Schwer verständlich","hardToUnderstand","thumb-down"],["Informationen oder Beispielcode falsch","incorrectInformationOrSampleCode","thumb-down"],["Benötigte Informationen/Beispiele nicht gefunden","missingTheInformationSamplesINeed","thumb-down"],["Problem mit der Übersetzung","translationIssue","thumb-down"],["Sonstiges","otherDown","thumb-down"]],["Zuletzt aktualisiert: 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."]]