Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: add cargo fmt and cargo clippy checks to CI #218

Merged
merged 6 commits into from
Jan 5, 2024
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
9 changes: 9 additions & 0 deletions .github/workflows/test_supabase_wrappers.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,13 @@ jobs:

- run: cargo install cargo-pgrx --version 0.11.2
- run: cargo pgrx init --pg15 /usr/lib/postgresql/15/bin/pg_config

- name: Format code
run: |
cd supabase-wrappers && cargo fmt --check

- name: Run clippy
run: |
cd supabase-wrappers && RUSTFLAGS="-D warnings" cargo clippy --all --tests --no-deps

- run: cd supabase-wrappers && cargo test
9 changes: 9 additions & 0 deletions .github/workflows/test_wrappers.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,13 @@ jobs:

- run: cargo install cargo-pgrx --version 0.11.2
- run: cargo pgrx init --pg15 /usr/lib/postgresql/15/bin/pg_config

- name: Format code
run: |
cd wrappers && cargo fmt --check

- name: Run clippy
run: |
cd wrappers && RUSTFLAGS="-D warnings" cargo clippy --all --tests --no-deps --features all_fdws,helloworld_fdw

- run: cd wrappers && cargo pgrx test --features all_fdws,pg15
2 changes: 1 addition & 1 deletion supabase-wrappers/src/qual.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ pub(crate) unsafe fn form_array_from_datum(
pub(crate) unsafe fn get_operator(opno: pg_sys::Oid) -> pg_sys::Form_pg_operator {
let htup = pg_sys::SearchSysCache1(
pg_sys::SysCacheIdentifier_OPEROID.try_into().unwrap(),
opno.try_into().unwrap(),
opno.into(),
);
if htup.is_null() {
pg_sys::ReleaseSysCache(htup);
Expand Down
8 changes: 3 additions & 5 deletions wrappers/src/fdw/auth0_fdw/auth0_client/rows_iterator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,10 @@ impl Iterator for RowsIterator {
fn next(&mut self) -> Option<Self::Item> {
if let Some(row) = self.get_next_row() {
Some(Ok(row))
} else if self.have_more_rows {
self.fetch_rows_batch().transpose()
} else {
if self.have_more_rows {
self.fetch_rows_batch().transpose()
} else {
None
}
None
}
}
}
12 changes: 6 additions & 6 deletions wrappers/src/fdw/clickhouse_fdw/clickhouse_fdw.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::stats;
use chrono::{Date, DateTime, NaiveDate, NaiveDateTime, Utc};
#[allow(deprecated)]
use chrono::{Date, DateTime, Datelike, NaiveDate, NaiveDateTime, Utc};
use chrono_tz::Tz;
use clickhouse_rs::{types, types::Block, types::SqlType, ClientHandle, Pool};
use pgrx::to_timestamp;
Expand Down Expand Up @@ -55,11 +56,10 @@ fn field_to_cell(row: &types::Row<types::Complex>, i: usize) -> ClickHouseFdwRes
Ok(Some(Cell::String(value)))
}
SqlType::Date => {
#[allow(deprecated)]
let value = row.get::<Date<_>, usize>(i)?;
let epoch = NaiveDate::from_ymd_opt(1970, 1, 1).unwrap();
let seconds_from_epoch = value.naive_utc().signed_duration_since(epoch).num_seconds();
let ts = to_timestamp(seconds_from_epoch as f64);
Ok(Some(Cell::Date(pgrx::Date::from(ts))))
let dt = pgrx::Date::new(value.year(), value.month() as u8, value.day() as u8)?;
Ok(Some(Cell::Date(dt)))
}
SqlType::DateTime(_) => {
let value = row.get::<DateTime<_>, usize>(i)?;
Expand Down Expand Up @@ -330,7 +330,7 @@ impl ForeignDataWrapper<ClickHouseFdwError> for ClickHouseFdw {
Cell::Timestamp(_) => {
let s = cell.to_string().replace('\'', "");
let tm = NaiveDateTime::parse_from_str(&s, "%Y-%m-%d %H:%M:%S")?;
let tm: DateTime<Utc> = DateTime::from_utc(tm, Utc);
let tm: DateTime<Utc> = DateTime::from_naive_utc_and_offset(tm, Utc);
row.push((col_name, types::Value::from(tm)));
}
_ => {
Expand Down
4 changes: 4 additions & 0 deletions wrappers/src/fdw/clickhouse_fdw/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
mod clickhouse_fdw;
mod tests;

use pgrx::datum::datetime_support::DateTimeConversionError;
use pgrx::pg_sys::panic::ErrorReport;
use pgrx::prelude::PgSqlErrorCode;
use thiserror::Error;
Expand All @@ -19,6 +20,9 @@ enum ClickHouseFdwError {
#[error("column data type '{0}' is not supported")]
UnsupportedColumnType(String),

#[error("datetime conversion error: {0}")]
DatetimeConversionError(#[from] DateTimeConversionError),

#[error("datetime parse error: {0}")]
DatetimeParseError(#[from] chrono::format::ParseError),

Expand Down
16 changes: 5 additions & 11 deletions wrappers/src/fdw/stripe_fdw/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -527,10 +527,7 @@ mod tests {
.zip(r.get_by_name::<&str, _>("type").unwrap())
})
.collect::<Vec<_>>();
assert_eq!(
results,
vec![(((((100, "usd"), 0), "available"), "charge"))]
);
assert_eq!(results, vec![((((100, "usd"), 0), "available"), "charge")]);

let results = c
.select("SELECT * FROM stripe_charges", None, None)
Expand All @@ -542,7 +539,7 @@ mod tests {
.zip(r.get_by_name::<&str, _>("status").unwrap())
})
.collect::<Vec<_>>();
assert_eq!(results, vec![(((100, "usd"), "succeeded"))]);
assert_eq!(results, vec![((100, "usd"), "succeeded")]);

let results = c
.select("SELECT * FROM stripe_customers", None, None)
Expand All @@ -555,10 +552,7 @@ mod tests {
.collect::<Vec<_>>();
assert_eq!(
results,
vec![(
"cus_MJiBgSUgeWFN0z",
Timestamp::try_from(287883090000000i64).unwrap()
)]
vec![("cus_MJiBgSUgeWFN0z", Timestamp::from(287883090000000i64))]
);

let results = c
Expand Down Expand Up @@ -825,9 +819,9 @@ mod tests {
vec![(
(
("cus_MJiBtCqOF1Bb3F", "usd"),
Timestamp::try_from(287883090000000i64).unwrap()
Timestamp::from(287883090000000i64)
),
Timestamp::try_from(287883090000000i64).unwrap()
Timestamp::from(287883090000000i64)
)]
);

Expand Down
Loading