Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions etl-destinations/src/bigquery/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,33 @@ impl BigQueryClient {
Ok(BigQueryClient { project_id, client })
}

/// Creates a new [`BigQueryClient`] using Application Default Credentials.
///
/// Authenticates with BigQuery using the environment's default credentials.
/// Returns an error if credentials are missing or invalid.
pub async fn new_with_adc(project_id: BigQueryProjectId) -> EtlResult<BigQueryClient> {
let client = Client::from_application_default_credentials()
.await
.map_err(bq_error_to_etl_error)?;

Ok(BigQueryClient { project_id, client })
}

/// Creates a new [`BigQueryClient`] using OAuth2 installed flow authentication.
///
/// Authenticates with BigQuery using the OAuth2 installed flow.
pub async fn new_with_flow_authenticator<S: AsRef<[u8]>, P: Into<std::path::PathBuf>>(
project_id: BigQueryProjectId,
secret: S,
persistant_file_path: P,
) -> EtlResult<BigQueryClient> {
let client = Client::from_installed_flow_authenticator(secret, persistant_file_path)
.await
.map_err(bq_error_to_etl_error)?;

Ok(BigQueryClient { project_id, client })
}

/// Returns the fully qualified BigQuery table name.
///
/// Formats the table name as `project_id.dataset_id.table_id` with proper quoting.
Expand Down
65 changes: 65 additions & 0 deletions etl-destinations/src/bigquery/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,71 @@ where
inner: Arc::new(Mutex::new(inner)),
})
}
/// Creates a new [`BigQueryDestination`] using Application Default Credentials (ADC).
///
/// Initializes the BigQuery client with the default credentials and project settings.
/// The `max_staleness_mins` parameter controls table metadata cache freshness.
/// The `max_concurrent_streams` parameter controls parallelism for streaming operations
/// and determines how table rows are split into batches for concurrent processing.
pub async fn new_with_adc(
project_id: String,
dataset_id: BigQueryDatasetId,
max_staleness_mins: Option<u16>,
max_concurrent_streams: usize,
store: S,
) -> EtlResult<Self> {
let client = BigQueryClient::new_with_adc(project_id).await?;
let inner = Inner {
created_tables: HashSet::new(),
created_views: HashMap::new(),
};

Ok(Self {
client,
dataset_id,
max_staleness_mins,
max_concurrent_streams,
store,
inner: Arc::new(Mutex::new(inner)),
})
}

/// Creates a new [`BigQueryDestination`] using an installed flow authenticator.
///
/// Initializes the BigQuery client with a flow authenticator using the provided secret and persistent file path.
/// The `max_staleness_mins` parameter controls table metadata cache freshness.
/// The `max_concurrent_streams` parameter controls parallelism for streaming operations
/// and determines how table rows are split into batches for concurrent processing.
pub async fn new_with_flow_authenticator<Secret, Path>(
project_id: String,
dataset_id: BigQueryDatasetId,
secret: Secret,
persistent_file_path: Path,
max_staleness_mins: Option<u16>,
max_concurrent_streams: usize,
store: S,
) -> EtlResult<Self>
where
Secret: AsRef<[u8]>,
Path: Into<std::path::PathBuf>,
{
let client =
BigQueryClient::new_with_flow_authenticator(project_id, secret, persistent_file_path)
.await?;
let inner = Inner {
created_tables: HashSet::new(),
created_views: HashMap::new(),
};

Ok(Self {
client,
dataset_id,
max_staleness_mins,
max_concurrent_streams,
store,
inner: Arc::new(Mutex::new(inner)),
})
}

/// Prepares a table for CDC streaming operations with schema-aware table creation.
///
Expand Down
Loading