Skip to content

Commit

Permalink
Fix rustc and clippy warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
syvb committed Nov 12, 2024
1 parent 31b7ccb commit 585401c
Show file tree
Hide file tree
Showing 19 changed files with 70 additions and 76 deletions.
3 changes: 3 additions & 0 deletions crates/aggregate_builder/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,6 @@ proc-macro = true
syn = {version="1.0", features=["extra-traits", "visit", "visit-mut", "full"]}
quote = "1.0"
proc-macro2 = "1.0"

[features]
print-generated = []
6 changes: 2 additions & 4 deletions crates/hyperloglogplusplus/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ extern crate quickcheck;
extern crate quickcheck_macros;

use std::{
hash::{BuildHasher, Hash, Hasher},
hash::{BuildHasher, Hash},
marker::PhantomData,
};

Expand Down Expand Up @@ -131,9 +131,7 @@ where
pub fn add(&mut self, value: &T) {
use HyperLogLogStorage::*;

let mut hasher = self.buildhasher.build_hasher();
value.hash(&mut hasher);
let hash = hasher.finish();
let hash = self.buildhasher.hash_one(value);
match &mut self.storage {
Sparse(s) => {
let overflowing = s.add_hash(hash);
Expand Down
4 changes: 2 additions & 2 deletions crates/stats-agg/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ pub struct XYPair<T: FloatLike> {
// but then the cost of recalculation is low, compared to when there are many values in a rolling calculation, so we
// test early in the function for whether we need to recalculate and pass NULL quickly so that we don't affect those
// cases too heavily.
#[cfg(not(any(test, feature = "pg_test")))]
#[cfg(not(test))]
const INV_FLOATING_ERROR_THRESHOLD: f64 = 0.99;
#[cfg(any(test, feature = "pg_test"))] // don't have a threshold for tests, to ensure the inverse function is better tested
#[cfg(test)] // don't have a threshold for tests, to ensure the inverse function is better tested
const INV_FLOATING_ERROR_THRESHOLD: f64 = f64::INFINITY;

pub mod stats1d;
Expand Down
17 changes: 8 additions & 9 deletions crates/t-digest/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,8 @@ impl TDigest {
max_size,
sum: OrderedFloat::from(0.0),
count: 0,
max: OrderedFloat::from(std::f64::NAN),
min: OrderedFloat::from(std::f64::NAN),
max: OrderedFloat::from(f64::NAN),
min: OrderedFloat::from(f64::NAN),
}
}

Expand Down Expand Up @@ -243,8 +243,8 @@ impl Default for TDigest {
max_size: 100,
sum: OrderedFloat::from(0.0),
count: 0,
max: OrderedFloat::from(std::f64::NAN),
min: OrderedFloat::from(std::f64::NAN),
max: OrderedFloat::from(f64::NAN),
min: OrderedFloat::from(f64::NAN),
}
}
}
Expand Down Expand Up @@ -429,8 +429,8 @@ impl TDigest {
let mut starts: Vec<usize> = Vec::with_capacity(digests.len());

let mut count: u64 = 0;
let mut min = OrderedFloat::from(std::f64::INFINITY);
let mut max = OrderedFloat::from(std::f64::NEG_INFINITY);
let mut min = OrderedFloat::from(f64::INFINITY);
let mut max = OrderedFloat::from(f64::NEG_INFINITY);

let mut start: usize = 0;
for digest in digests.into_iter() {
Expand Down Expand Up @@ -1037,9 +1037,8 @@ mod tests {

let digest = TDigest::merge_digests(vec![digest1, digest2]);

let quantile_tests = vec![0.01, 0.1, 0.25, 0.5, 0.6, 0.8, 0.95];
let tolerated_percentile_error =
vec![0.010001, 0.100001, 0.2, 0.30, 0.275, 0.1725, 0.050001]; // .000001 cases are to handle rounding errors on cases that might return infinities
let quantile_tests = [0.01, 0.1, 0.25, 0.5, 0.6, 0.8, 0.95];
let tolerated_percentile_error = [0.010001, 0.100001, 0.2, 0.30, 0.275, 0.1725, 0.050001]; // .000001 cases are to handle rounding errors on cases that might return infinities

let mut master: Vec<f64> = batch1
.iter()
Expand Down
6 changes: 3 additions & 3 deletions crates/time-weighted-average/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,10 @@ impl TimeWeightSummary {
/// The initial aggregate will only have points within the time bucket, but outside of it, you will either have a point that you select
/// or a TimeWeightSummary where the first or last point can be used depending on which bound you are extrapolating to.
/// 1. The start_prev parameter is optional, but if a start is provided a previous point must be
/// provided (for both linear and locf weighting methods).
/// provided (for both linear and locf weighting methods).
/// 2. The end_next parameter is also optional, if an end is provided and the locf weighting
/// method is specified, a next parameter isn't needed, with the linear method, the next
/// point is needed and we will error if it is not provided.
/// method is specified, a next parameter isn't needed, with the linear method, the next
/// point is needed and we will error if it is not provided.
pub fn with_bounds(
&self,
start_prev: Option<(i64, TSPoint)>,
Expand Down
2 changes: 1 addition & 1 deletion crates/udd-sketch/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -710,7 +710,7 @@ mod tests {
sketch.add_value(*value);
}

let quantile_tests = vec![0.01, 0.1, 0.25, 0.5, 0.6, 0.8, 0.95];
let quantile_tests = [0.01, 0.1, 0.25, 0.5, 0.6, 0.8, 0.95];

master.sort_by(|a, b| a.partial_cmp(b).unwrap());

Expand Down
2 changes: 1 addition & 1 deletion extension/src/countminsketch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ pub mod toolkit_experimental {

impl CountMinSketch<'_> {
fn new(width: u32, depth: u32, counters: Vec<i64>) -> Self {
let counters_arr = counters.try_into().unwrap();
let counters_arr = counters.into();
unsafe {
flatten!(CountMinSketch {
width,
Expand Down
3 changes: 1 addition & 2 deletions extension/src/datum_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -330,8 +330,7 @@ impl<'a, 'de> Deserialize<'de> for DatumStore<'a> {
where
A: SeqAccess<'de>,
{
let oid =
Oid::from(seq.next_element::<u32>().unwrap().unwrap()); // TODO: error handling
let oid = Oid::from(seq.next_element::<u32>().unwrap().unwrap()); // TODO: error handling

// TODO separate human-readable and binary forms
let mut reader = DatumFromSerializedTextReader::from_oid(oid);
Expand Down
9 changes: 3 additions & 6 deletions extension/src/frequency.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1276,12 +1276,9 @@ pub fn freq_iter<'a>(
TableIterator::new(agg.datums.clone().into_iter().zip(counts).map_while(
move |(value, (&count, &overcount))| {
let total = agg.values_seen as f64;
let value = AnyElement::from_polymorphic_datum(
value,
false,
Oid::from(agg.type_oid),
)
.unwrap();
let value =
AnyElement::from_polymorphic_datum(value, false, Oid::from(agg.type_oid))
.unwrap();
let min_freq = (count - overcount) as f64 / total;
let max_freq = count as f64 / total;
Some((value, min_freq, max_freq))
Expand Down
1 change: 1 addition & 0 deletions extension/src/lttb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ pub fn gp_lttb_trans(

let mut trans = lttb_trans_inner(state, time, val, resolution, fcinfo);
if needs_interval {
#[allow(clippy::manual_inspect)] // need to mutate s
trans.as_mut().map(|s| {
s.gap_interval = gap_val;
s
Expand Down
26 changes: 16 additions & 10 deletions extension/src/raw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,10 @@ macro_rules! raw_type {
unsafe impl<'fcx> callconv::ArgAbi<'fcx> for $name {
unsafe fn unbox_arg_unchecked(arg: callconv::Arg<'_, 'fcx>) -> Self {
let index = arg.index();
unsafe { arg.unbox_arg_using_from_datum().unwrap_or_else(|| panic!("argument {index} must not be null")) }
unsafe {
arg.unbox_arg_using_from_datum()
.unwrap_or_else(|| panic!("argument {index} must not be null"))
}
}

unsafe fn unbox_nullable_arg(arg: callconv::Arg<'_, 'fcx>) -> nullable::Nullable<Self> {
Expand All @@ -92,9 +95,10 @@ pub struct bytea(pub pg_sys::Datum);
raw_type!(bytea, pg_sys::BYTEAOID, pg_sys::BYTEAARRAYOID);

unsafe impl pgrx::callconv::BoxRet for bytea {
unsafe fn box_into<'fcx>(self, fcinfo: &mut pgrx::callconv::FcInfo<'fcx>)
-> pgrx::datum::Datum<'fcx>
{
unsafe fn box_into<'fcx>(
self,
fcinfo: &mut pgrx::callconv::FcInfo<'fcx>,
) -> pgrx::datum::Datum<'fcx> {
unsafe { fcinfo.return_raw_datum(self.0) }
}
}
Expand All @@ -113,9 +117,10 @@ raw_type!(
);

unsafe impl pgrx::callconv::BoxRet for TimestampTz {
unsafe fn box_into<'fcx>(self, fcinfo: &mut pgrx::callconv::FcInfo<'fcx>)
-> pgrx::datum::Datum<'fcx>
{
unsafe fn box_into<'fcx>(
self,
fcinfo: &mut pgrx::callconv::FcInfo<'fcx>,
) -> pgrx::datum::Datum<'fcx> {
unsafe { fcinfo.return_raw_datum(self.0) }
}
}
Expand Down Expand Up @@ -145,9 +150,10 @@ pub struct Interval(pub pg_sys::Datum);
raw_type!(Interval, pg_sys::INTERVALOID, pg_sys::INTERVALARRAYOID);

unsafe impl pgrx::callconv::BoxRet for Interval {
unsafe fn box_into<'fcx>(self, fcinfo: &mut pgrx::callconv::FcInfo<'fcx>)
-> pgrx::datum::Datum<'fcx>
{
unsafe fn box_into<'fcx>(
self,
fcinfo: &mut pgrx::callconv::FcInfo<'fcx>,
) -> pgrx::datum::Datum<'fcx> {
unsafe { fcinfo.return_raw_datum(self.0) }
}
}
Expand Down
26 changes: 4 additions & 22 deletions extension/src/serialization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ use std::{
os::raw::{c_char, c_int},
};

#[cfg(feature = "pg16")]
use pgrx::pg_sys::DateTimeErrorExtra;
use pgrx::pg_sys::{self};

use std::ffi::CStr;
Expand Down Expand Up @@ -78,12 +76,7 @@ pub extern "C" fn _ts_toolkit_decode_timestamptz(text: &str) -> i64 {
pg_sys::MAXDATEFIELDS as i32,
&mut nf,
);
#[cfg(any(
feature = "pg12",
feature = "pg13",
feature = "pg14",
feature = "pg15"
))]
#[cfg(any(feature = "pg12", feature = "pg13", feature = "pg14", feature = "pg15"))]
if dterr == 0 {
dterr = pg_sys::DecodeDateTime(
field.as_mut_ptr(),
Expand All @@ -95,10 +88,7 @@ pub extern "C" fn _ts_toolkit_decode_timestamptz(text: &str) -> i64 {
&mut tz,
)
}
#[cfg(any(
feature = "pg16",
feature = "pg17"
))]
#[cfg(any(feature = "pg16", feature = "pg17"))]
if dterr == 0 {
let mut extra = pgrx::pg_sys::DateTimeErrorExtra::default();
dterr = pg_sys::DecodeDateTime(
Expand All @@ -113,23 +103,15 @@ pub extern "C" fn _ts_toolkit_decode_timestamptz(text: &str) -> i64 {
)
}

#[cfg(any(
feature = "pg12",
feature = "pg13",
feature = "pg14",
feature = "pg15"
))]
#[cfg(any(feature = "pg12", feature = "pg13", feature = "pg14", feature = "pg15"))]
if dterr != 0 {
pg_sys::DateTimeParseError(
dterr,
str.as_ptr(),
b"timestamptz\0".as_ptr().cast::<c_char>(),
);
}
#[cfg(any(
feature = "pg16",
feature = "pg17"
))]
#[cfg(any(feature = "pg16", feature = "pg17"))]
if dterr != 0 {
pg_sys::DateTimeParseError(
dterr,
Expand Down
13 changes: 10 additions & 3 deletions extension/src/serialization/collations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ impl PgCollationId {
#[allow(non_upper_case_globals)]
const Anum_pg_collation_oid: u32 = 1;
// https://github.com/postgres/postgres/blob/e955bd4b6c2bcdbd253837f6cf4c7520b98e69d4/src/include/catalog/pg_collation.dat
#[allow(deprecated)] // From::from is non-const
pub(crate) const DEFAULT_COLLATION_OID: Oid = unsafe { Oid::from_u32_unchecked(100) };

#[allow(non_camel_case_types)]
Expand Down Expand Up @@ -121,7 +122,10 @@ impl Serialize for PgCollationId {

let namespace = pg_sys::get_namespace_name((*collation_tuple).collnamespace);
if namespace.is_null() {
pgrx::error!("invalid schema oid {}", (*collation_tuple).collnamespace.as_u32());
pgrx::error!(
"invalid schema oid {}",
(*collation_tuple).collnamespace.as_u32()
);
}

let namespace_len = CStr::from_ptr(namespace).to_bytes().len();
Expand Down Expand Up @@ -185,8 +189,11 @@ impl<'de> Deserialize<'de> for PgCollationId {
);
let namespace = CStr::from_ptr(namespace);

let name =
pg_sys::pg_any_to_server(name.as_ptr(), name_len as _, pg_sys::pg_enc::PG_UTF8 as _);
let name = pg_sys::pg_any_to_server(
name.as_ptr(),
name_len as _,
pg_sys::pg_enc::PG_UTF8 as _,
);
let name = CStr::from_ptr(name);

let namespace_id = pg_sys::LookupExplicitNamespace(namespace.as_ptr(), true);
Expand Down
7 changes: 5 additions & 2 deletions extension/src/serialization/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -276,8 +276,11 @@ impl<'de> Deserialize<'de> for PgTypId {
);
let namespace = CStr::from_ptr(namespace);

let name =
pg_sys::pg_any_to_server(name.as_ptr(), name_len as _, pg_sys::pg_enc::PG_UTF8 as _);
let name = pg_sys::pg_any_to_server(
name.as_ptr(),
name_len as _,
pg_sys::pg_enc::PG_UTF8 as _,
);
let name = CStr::from_ptr(name);

let namespace_id = pg_sys::LookupExplicitNamespace(namespace.as_ptr(), true);
Expand Down
2 changes: 1 addition & 1 deletion extension/src/tdigest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ fn tdigest_compound_final(
_fcinfo: pg_sys::FunctionCallInfo,
) -> Option<TDigest<'static>> {
let state: Option<&InternalTDigest> = unsafe { state.get() };
state.map(|state| TDigest::from_internal_tdigest(state.deref()))
state.map(TDigest::from_internal_tdigest)
}

#[pg_extern(immutable, parallel_safe)]
Expand Down
7 changes: 3 additions & 4 deletions extension/src/time_vector/pipeline/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,9 @@ pub fn map_series_pipeline_element(
}

pub fn map_series_element<'a>(function: crate::raw::regproc) -> Element<'a> {
let function: pg_sys::regproc =
pg_sys::Oid::from(function.0.value() as u32)
.try_into()
.unwrap();
let function: pg_sys::regproc = pg_sys::Oid::from(function.0.value() as u32)
.try_into()
.unwrap();
check_user_function_type(function);
Element::MapSeries {
function: PgProcId(function),
Expand Down
4 changes: 2 additions & 2 deletions extension/src/type_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ macro_rules! pg_type {
) => {
$crate::pg_type_impl!{
'input
$(#[$attrs])*
$(#[$attrs])*
struct $name $(<$inlife>)?
{
$($($vals)*)?
Expand Down Expand Up @@ -431,8 +431,8 @@ macro_rules! do_deserialize {
($bytes: expr, $t: ty) => {{
use $crate::type_builder::SerializationType;

let input: $crate::raw::bytea = $bytes;
let state: $t = unsafe {
let input: $crate::raw::bytea = $bytes;
let input: pgrx::pg_sys::Datum = input.into();
let detoasted = pg_sys::pg_detoast_datum_packed(input.cast_mut_ptr());
let len = pgrx::varsize_any_exhdr(detoasted);
Expand Down
4 changes: 2 additions & 2 deletions tools/sql-doctester/src/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -276,8 +276,8 @@ fn stringify_delta(left: &[Vec<String>], right: &[Vec<String>]) -> String {
let mut width = vec![
0;
max(
left.get(0).map(Vec::len).unwrap_or(0),
right.get(0).map(Vec::len).unwrap_or(0)
left.first().map(Vec::len).unwrap_or(0),
right.first().map(Vec::len).unwrap_or(0)
)
];
let num_rows = max(left.len(), right.len());
Expand Down
4 changes: 2 additions & 2 deletions tools/update-tester/src/testrunner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -583,8 +583,8 @@ fn stringify_delta(left: &[Vec<String>], right: &[Vec<String>]) -> String {
let mut width = vec![
0;
max(
left.get(0).map(Vec::len).unwrap_or(0),
right.get(0).map(Vec::len).unwrap_or(0)
left.first().map(Vec::len).unwrap_or(0),
right.first().map(Vec::len).unwrap_or(0)
)
];
let num_rows = max(left.len(), right.len());
Expand Down

0 comments on commit 585401c

Please sign in to comment.