Skip to content

Commit

Permalink
chore: remove a few unwrap calls
Browse files Browse the repository at this point in the history
  • Loading branch information
imor committed Oct 3, 2023
1 parent fc1a538 commit b989b16
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 14 deletions.
28 changes: 15 additions & 13 deletions wrappers/src/fdw/bigquery_fdw/bigquery_fdw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,19 @@ fn field_to_cell(rs: &ResultSet, field: &TableFieldSchema) -> BigQueryFdwResult<
FieldType::Boolean => rs.get_bool_by_name(&field.name)?.map(Cell::Bool),
FieldType::Int64 | FieldType::Integer => rs.get_i64_by_name(&field.name)?.map(Cell::I64),
FieldType::Float64 | FieldType::Float => rs.get_f64_by_name(&field.name)?.map(Cell::F64),
FieldType::Numeric => rs
.get_f64_by_name(&field.name)?
.map(|v| Cell::Numeric(AnyNumeric::try_from(v).unwrap())),
FieldType::Numeric => match rs.get_f64_by_name(&field.name)? {
Some(v) => Some(Cell::Numeric(AnyNumeric::try_from(v)?)),
None => None,
},
FieldType::String => rs.get_string_by_name(&field.name)?.map(Cell::String),
FieldType::Date => rs.get_string_by_name(&field.name)?.map(|v| {
let dt = Date::from_str(&v).unwrap();
Cell::Date(dt)
}),
FieldType::Datetime => rs.get_string_by_name(&field.name)?.map(|v| {
let ts = Timestamp::from_str(&v).unwrap();
Cell::Timestamp(ts)
}),
FieldType::Date => match rs.get_string_by_name(&field.name)? {
Some(v) => Some(Cell::Date(Date::from_str(&v)?)),
None => None,
},
FieldType::Datetime => match rs.get_string_by_name(&field.name)? {
Some(v) => Some(Cell::Timestamp(Timestamp::from_str(&v)?)),
None => None,
},
FieldType::Timestamp => rs.get_f64_by_name(&field.name)?.map(|v| {
let ts = pgrx::to_timestamp(v);
Cell::Timestamp(ts.to_utc())
Expand Down Expand Up @@ -178,7 +179,8 @@ impl ForeignDataWrapper<BigQueryFdwError> for BigQueryFdw {
let auth_mock_uri = auth_mock.uri();
let dummy_auth_config = dummy_configuration(&auth_mock_uri);
ret.auth_mock = Some(auth_mock);
serde_json::to_string_pretty(&dummy_auth_config).unwrap()
serde_json::to_string_pretty(&dummy_auth_config)
.expect("dummy auth config should not fail to serialize")
}
false => match options.get("sa_key") {
Some(sa_key) => sa_key.to_owned(),
Expand Down Expand Up @@ -396,7 +398,7 @@ impl ForeignDataWrapper<BigQueryFdwError> for BigQueryFdw {
}
}

insert_request.add_row(None, row_json).unwrap();
insert_request.add_row(None, row_json)?;

// execute insert job on BigQuery
if let Err(err) = self.rt.block_on(client.tabledata().insert_all(
Expand Down
8 changes: 7 additions & 1 deletion wrappers/src/fdw/bigquery_fdw/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use gcp_bigquery_client::error::BQError;
use gcp_bigquery_client::model::field_type::FieldType;
use pgrx::pg_sys::panic::ErrorReport;
use pgrx::PgSqlErrorCode;
use pgrx::{DateTimeConversionError, PgSqlErrorCode};
use supabase_wrappers::prelude::{CreateRuntimeError, OptionsError};
use thiserror::Error;

Expand All @@ -23,6 +23,12 @@ enum BigQueryFdwError {

#[error("field type {0:?} not supported")]
UnsupportedFieldType(FieldType),

#[error("{0}")]
NumericConversionError(#[from] pgrx::numeric::Error),

#[error("{0}")]
DateTimeConversionError(#[from] DateTimeConversionError),
}

impl From<BigQueryFdwError> for ErrorReport {
Expand Down

0 comments on commit b989b16

Please sign in to comment.