Skip to main content
Version: Next

destinations.impl.bigquery.bigquery_adapter

bigquery_adapter

def bigquery_adapter(data: Any,
partition: TColumnNames = None,
cluster: TColumnNames = None,
round_half_away_from_zero: TColumnNames = None,
round_half_even: TColumnNames = None,
table_description: Optional[str] = None,
table_expiration_datetime: Optional[str] = None,
insert_api: Optional[Literal["streaming",
"default"]] = None,
autodetect_schema: Optional[bool] = None) -> DltResource

[view_source]

Prepares data for loading into BigQuery.

This function takes data, which can be raw or already wrapped in a DltResource object, and prepares it for BigQuery by optionally specifying partitioning, clustering, table description and table expiration settings.

Arguments:

  • data Any - The data to be transformed. This can be raw data or an instance of DltResource. If raw data is provided, the function will wrap it into a DltResource object.
  • partition TColumnNames, optional - The name of the column to partition the BigQuery table by. This should be a string representing a single column name.
  • cluster TColumnNames, optional - A column name or list of column names to cluster the BigQuery table by.
  • round_half_away_from_zero TColumnNames, optional - Determines how values in the column are rounded when written to the table. This mode rounds halfway cases away from zero. The columns specified must be mutually exclusive from round_half_even. See https://cloud.google.com/bigquery/docs/schemas#rounding_mode for more information.
  • round_half_even TColumnNames, optional - Determines how values in the column are rounded when written to the table. This mode rounds halfway cases towards the nearest even digit. The columns specified must be mutually exclusive from round_half_away_from_zero. See https://cloud.google.com/bigquery/docs/schemas#rounding_mode for more information.
  • table_description str, optional - A description for the BigQuery table.
  • table_expiration_datetime str, optional - String representing the datetime when the BigQuery table expires. This is always interpreted as UTC, BigQuery's default.
  • insert_api Optional[Literal["streaming", "default"]] - The API to use for inserting data into BigQuery. If "default" is chosen, the original SQL query mechanism is used. If "streaming" is chosen, the streaming API (https://cloud.google.com/bigquery/docs/streaming-data-into-bigquery) is used.
  • NOTE - due to BigQuery features, streaming insert is only available for append write_disposition.
  • autodetect_schema bool, optional - If set to True, BigQuery schema autodetection will be used to create data tables. This allows to create structured types from nested data.

Returns:

A DltResource object that is ready to be loaded into BigQuery.

Raises:

  • ValueError - If any hint is invalid or none are specified.

Examples:

    data = [{"name": "Marcel", "description": "Raccoon Engineer", "date_hired": 1700784000}]
bigquery_adapter(data, partition="date_hired", table_expiration_datetime="2024-01-30", table_description="Employee Data")

[DltResource with hints applied]

This demo works on codespaces. Codespaces is a development environment available for free to anyone with a Github account. You'll be asked to fork the demo repository and from there the README guides you with further steps.
The demo uses the Continue VSCode extension.

Off to codespaces!

DHelp

Ask a question

Welcome to "Codex Central", your next-gen help center, driven by OpenAI's GPT-4 model. It's more than just a forum or a FAQ hub – it's a dynamic knowledge base where coders can find AI-assisted solutions to their pressing problems. With GPT-4's powerful comprehension and predictive abilities, Codex Central provides instantaneous issue resolution, insightful debugging, and personalized guidance. Get your code running smoothly with the unparalleled support at Codex Central - coding help reimagined with AI prowess.