fix(promql): preserve ordinary NaN samples (#8494)

* fix(promql): distinguish stale markers from NaN

Signed-off-by: discord9 <discord9@163.com>

* fix(promql): preserve ordinary NaN samples

Signed-off-by: discord9 <discord9@163.com>

---------

Signed-off-by: discord9 <discord9@163.com>
This commit is contained in:
discord9
2026-07-15 01:54:49 +00:00
committed by GitHub
parent 1a476f76e2
commit 2123108db0
14 changed files with 507 additions and 60 deletions
+1
View File
@@ -17,6 +17,7 @@ pub mod error;
pub mod logical_plan;
pub mod native_histogram;
pub mod prelude;
pub mod prometheus;
pub mod request;
pub mod stream;
#[cfg(any(test, feature = "testing"))]
+37
View File
@@ -0,0 +1,37 @@
// Copyright 2023 Greptime Team
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
/// Canonical Prometheus stale-marker NaN bit pattern.
pub const PROMETHEUS_STALE_NAN_BITS: u64 = 0x7ff0_0000_0000_0002;
/// Returns whether `value` is the canonical Prometheus stale-marker NaN.
#[inline]
pub fn is_prometheus_stale_nan(value: f64) -> bool {
value.to_bits() == PROMETHEUS_STALE_NAN_BITS
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn recognizes_only_the_canonical_stale_marker() {
assert!(is_prometheus_stale_nan(f64::from_bits(
0x7ff0_0000_0000_0002
)));
assert!(!is_prometheus_stale_nan(f64::from_bits(
0x7ff8_0000_0000_0000
)));
}
}