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
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:
dataAny - 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 aDltResourceobject.partitionTColumnNames, optional - The name of the column to partition the BigQuery table by. This should be a string representing a single column name.clusterTColumnNames, optional - A column name or list of column names to cluster the BigQuery table by.round_half_away_from_zeroTColumnNames, 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 fromround_half_even. See https://cloud.google.com/bigquery/docs/schemas#rounding_mode for more information.round_half_evenTColumnNames, 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 fromround_half_away_from_zero. See https://cloud.google.com/bigquery/docs/schemas#rounding_mode for more information.table_descriptionstr, optional - A description for the BigQuery table.table_expiration_datetimestr, optional - String representing the datetime when the BigQuery table expires. This is always interpreted as UTC, BigQuery's default.insert_apiOptional[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 forappendwrite_disposition.autodetect_schemabool, 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]
should_autodetect_schema
def should_autodetect_schema(table: PreparedTableSchema) -> bool
Tells if schema should be auto detected for a given prepared table