bigquery Adapter¶
from sqlspec.adapters.bigquery import (
BigQueryConfig,
BigQueryConnectionParams,
BigQueryDriver,
BigQueryDriverFeatures,
BigQueryExceptionHandler,
)
Google Cloud BigQuery analytical adapter built on google-cloud-bigquery and google-cloud-bigquery-storage for high-throughput Arrow result streaming. Inherited execution methods are documented on SyncDriverAdapterBase. See the BigQuery Setup Guide for authentication and Storage Read API configuration.
Configuration & Parameters¶
BigQueryConfig
¶
Bases: NoPoolSyncConfig[BigQueryConnection, BigQueryDriver]
BigQuery configuration.
Configuration for Google Cloud BigQuery connections.
BigQueryConnectionParams
¶
Bases: TypedDict
Google Cloud BigQuery client and default QueryJobConfig parameters.
Attributes:
| Name | Type | Description |
|---|---|---|
project |
NotRequired[str]
|
Billing and default job execution Google Cloud project ID. |
project_id |
NotRequired[str]
|
Alias normalized to |
location |
NotRequired[str]
|
Default geographic region or multi-region (such as |
credentials |
NotRequired[BigQueryCredentials]
|
Explicit |
client_options |
NotRequired[BigQueryClientOptions]
|
GAPIC |
client_info |
NotRequired[BigQueryClientInfo]
|
Custom |
default_query_job_config |
NotRequired[BigQueryQueryJobConfig]
|
Base |
default_load_job_config |
NotRequired[BigQueryLoadJobConfig]
|
Base |
default_job_creation_mode |
NotRequired[str]
|
Client job creation mode (such as |
dataset_id |
NotRequired[str]
|
Default dataset ( |
dataset |
NotRequired[str]
|
Alias normalized to |
database |
NotRequired[str]
|
Alias normalized to |
db |
NotRequired[str]
|
Short alias normalized to |
use_query_cache |
NotRequired[bool]
|
Read from BigQuery cached query results when unmodified (defaults to |
maximum_bytes_billed |
NotRequired[int]
|
Per-query cost guard failing queries estimated to scan above this byte limit. |
query_timeout_ms |
NotRequired[int]
|
Server-side query execution timeout in milliseconds applied to |
job_timeout_ms |
NotRequired[int]
|
Server-side BigQuery job execution timeout in milliseconds. |
labels |
NotRequired[dict[str, str]]
|
Billing and governance key-value labels attached to executed query jobs. |
priority |
NotRequired[Literal['INTERACTIVE', 'BATCH']]
|
BigQuery query scheduling priority ( |
reservation |
NotRequired[str]
|
BigQuery Editions slot reservation resource path assigned to query jobs. |
max_slots |
NotRequired[int]
|
Maximum slot concurrency cap applied to individual query jobs. |
extra |
NotRequired[dict[str, Any]]
|
Additional keyword metadata retained in normalized connection configuration. |
BigQueryDriverFeatures
¶
Bases: TypedDict
BigQuery driver feature flags controlling query execution, Storage Write API, and EXPORT DATA.
Attributes:
| Name | Type | Description |
|---|---|---|
connection_instance |
NotRequired[BigQueryConnection]
|
Pre-created |
on_connection_create |
NotRequired[Callable[[Any], None]]
|
Callback invoked with the |
json_serializer |
NotRequired[Callable[[Any], str]]
|
Serializer converting dict/list parameters to JSON strings (defaults to |
enable_uuid_conversion |
NotRequired[bool]
|
Automatically coerce |
enable_events |
NotRequired[bool]
|
Enable SQLSpec table-backed event channel support. |
events_backend |
NotRequired[Literal['poll_queue']]
|
Event queue backend name ( |
job_retry_deadline |
NotRequired[float]
|
Total seconds to retry transient query failures (defaults to |
job_result_timeout |
NotRequired[float]
|
Maximum seconds to poll |
use_query_and_wait |
NotRequired[bool]
|
Execute single-statement queries via low-latency |
request_timeout |
NotRequired[float]
|
Per-request HTTP transport timeout in seconds for job submission calls (defaults to |
query_page_size |
NotRequired[int]
|
Page size forwarded to |
query_max_results |
NotRequired[int]
|
Maximum total rows fetched from |
enable_storage_write_api |
NotRequired[bool]
|
Route append |
storage_write_stream_type |
NotRequired[Literal['COMMITTED', 'PENDING']]
|
Storage Write API stream mode ( |
enable_native_storage |
NotRequired[bool]
|
Route eligible remote object-store exports through server-side |
native_export_connection |
NotRequired[str]
|
BigQuery Cloud Resource connection ID ( |
Driver & Pool¶
BigQueryDriver
¶
Bases: SyncDriverAdapterBase
BigQuery driver implementation.
Provides Google Cloud BigQuery connectivity with parameter style conversion, type coercion, error handling, and query job management.
BigQueryExceptionHandler
¶
Bases: BaseSyncExceptionHandler
Context manager for handling BigQuery API exceptions.
Maps HTTP status codes and API error reasons to SQLSpec exceptions stored on
pending_exception.
Extension Stores¶
BigQueryStore
¶
Bases: BaseSQLSpecStore['BigQueryConfig']
BigQuery session store using synchronous BigQuery driver.
Implements server-side session storage for Litestar using Google BigQuery. Uses Litestar's sync_to_thread utility to provide an async interface compatible with the Store protocol.
Provides efficient session management with
- Sync operations wrapped for async compatibility
- MERGE for UPSERT functionality
- Native TIMESTAMP type support
- Automatic expiration handling
- Efficient cleanup of expired sessions
- Table clustering on session_id for optimized lookups
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
BigQueryConfig
|
BigQueryConfig instance. |
required |
BigQueryADKStore
¶
Bases: BaseSyncADKStore[BigQueryConfig]
BigQuery ADK session/event/scoped-state store.
The store exposes the synchronous ADK store contract because BigQuery is a
synchronous SQLSpec adapter. SQLSpecSessionService provides async
bridging when Google ADK calls it from async service methods.
BigQueryEventQueueStore
¶
Bases: BaseEventQueueStore[BigQueryConfig]
BigQuery-specific event queue store with clustering optimization.
Generates DDL optimized for BigQuery. BigQuery does not support traditional indexes, so the table uses CLUSTER BY for query optimization instead.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
BigQueryConfig
|
BigQueryConfig with extension_config["events"] settings. |
required |