Skip to content

Commit 9b90d5a

Browse files
committed
warn about NaNs
1 parent baf27a5 commit 9b90d5a

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

pgdog/src/net/messages/data_types/numeric.rs

+10-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use std::{
55
};
66

77
use bytes::Buf;
8+
use tracing::warn;
89

910
use crate::net::messages::data_row::Data;
1011

@@ -18,6 +19,9 @@ pub struct Numeric {
1819

1920
impl Hash for Numeric {
2021
fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
22+
if self.data.is_nan() {
23+
warn!("using NaNs in hashing, this breaks aggregates");
24+
}
2125
// We don't expect NaNs from Postgres.
2226
self.data.to_bits().hash(state);
2327
}
@@ -57,7 +61,12 @@ impl Ord for Numeric {
5761
fn cmp(&self, other: &Self) -> std::cmp::Ordering {
5862
match self.partial_cmp(other) {
5963
Some(ordering) => ordering,
60-
None => Ordering::Equal, // We don't expect Postgres to send us NaNs.
64+
None => {
65+
if self.data.is_nan() || other.data.is_nan() {
66+
warn!("using NaNs in sorting, this doesn't work")
67+
}
68+
Ordering::Equal // We don't expect Postgres to send us NaNs.
69+
}
6170
}
6271
}
6372
}

0 commit comments

Comments
 (0)