use serde::{Deserialize, Serialize};
use std::{error, fmt};
use crate::common::*;
use crate::drivers::bigquery_shared::{BqColumn, TableName};
mod extract;
pub(crate) mod jobs;
mod load;
mod queries;
mod schema;
mod tables;
pub(crate) use extract::*;
pub(crate) use jobs::Labels;
pub(crate) use load::*;
pub(crate) use queries::*;
pub(crate) use schema::*;
pub(crate) use tables::*;
#[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub(crate) struct BigQueryError {
reason: String,
location: Option<String>,
debug_info: Option<String>,
message: String,
}
impl BigQueryError {
pub(crate) fn is_access_denied(&self) -> bool {
self.reason.starts_with("accessDenied")
}
}
impl fmt::Display for BigQueryError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}", self.reason)?;
if let Some(location) = &self.location {
write!(f, " at {}", location)?;
}
write!(f, ": {}", self.message)
}
}
impl error::Error for BigQueryError {}
pub(crate) fn original_bigquery_error(err: &Error) -> Option<&BigQueryError> {
for cause in err.chain() {
if let Some(bigquery_error) = cause.downcast_ref::<BigQueryError>() {
return Some(bigquery_error);
}
}
None
}
#[derive(Debug, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub(crate) struct TableSchema {
fields: Vec<BqColumn>,
}
#[instrument(level = "trace", skip(labels))]
pub(crate) async fn drop_table(table_name: &TableName, labels: &Labels) -> Result<()> {
debug!("deleting table: {}", table_name);
let sql = format!("DROP TABLE {};\n", table_name.dotted_and_quoted());
execute_sql(table_name.project(), &sql, labels).await
}