-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding arrow operators for stable interpolating functions
Also removing experimental copies of stable interpolation functions.
- Loading branch information
Brian Rowe
committed
Feb 24, 2023
1 parent
96678c5
commit a75e791
Showing
6 changed files
with
280 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
use pgx::*; | ||
|
||
use crate::{ | ||
counter_agg::{CounterSummary, CounterSummaryData, MetricSummary}, | ||
datum_utils::interval_to_ms, | ||
pg_type, ron_inout_funcs, | ||
}; | ||
|
||
use tspoint::TSPoint; | ||
|
||
pg_type! { | ||
struct CounterInterpolatedRateAccessor { | ||
timestamp : i64, | ||
interval : i64, | ||
prev : CounterSummaryData, | ||
next : CounterSummaryData, | ||
flags : u64, | ||
} | ||
} | ||
|
||
ron_inout_funcs!(CounterInterpolatedRateAccessor); | ||
|
||
#[pg_extern(immutable, parallel_safe, name = "interpolated_rate")] | ||
fn counter_iterpolated_rate_accessor<'a>( | ||
start: crate::raw::TimestampTz, | ||
duration: crate::raw::Interval, | ||
prev: Option<CounterSummary<'a>>, | ||
next: Option<CounterSummary<'a>>, | ||
) -> CounterInterpolatedRateAccessor<'static> { | ||
fn empty_summary<'b>() -> Option<CounterSummary<'b>> { | ||
let tmp = TSPoint { ts: 0, val: 0.0 }; | ||
let tmp = MetricSummary::new(&tmp, None); | ||
let tmp = CounterSummary::from_internal_counter_summary(tmp); | ||
Some(tmp) | ||
} | ||
|
||
let flags = u64::from(prev.is_some()) + if next.is_some() { 2 } else { 0 }; | ||
let prev = prev.or_else(empty_summary).unwrap().0; | ||
let next = next.or_else(empty_summary).unwrap().0; | ||
let interval = interval_to_ms(&start, &duration); | ||
crate::build! { | ||
CounterInterpolatedRateAccessor { | ||
timestamp : start.into(), | ||
interval, | ||
prev, | ||
next, | ||
flags, | ||
} | ||
} | ||
} | ||
|
||
pg_type! { | ||
struct CounterInterpolatedDeltaAccessor { | ||
timestamp : i64, | ||
interval : i64, | ||
prev : CounterSummaryData, | ||
next : CounterSummaryData, | ||
flags : u64, | ||
} | ||
} | ||
|
||
ron_inout_funcs!(CounterInterpolatedDeltaAccessor); | ||
|
||
#[pg_extern(immutable, parallel_safe, name = "interpolated_delta")] | ||
fn counter_iterpolated_delta_accessor<'a>( | ||
start: crate::raw::TimestampTz, | ||
duration: crate::raw::Interval, | ||
prev: Option<CounterSummary<'a>>, | ||
next: Option<CounterSummary<'a>>, | ||
) -> CounterInterpolatedDeltaAccessor<'static> { | ||
fn empty_summary<'b>() -> Option<CounterSummary<'b>> { | ||
let tmp = TSPoint { ts: 0, val: 0.0 }; | ||
let tmp = MetricSummary::new(&tmp, None); | ||
let tmp = CounterSummary::from_internal_counter_summary(tmp); | ||
Some(tmp) | ||
} | ||
|
||
let flags = u64::from(prev.is_some()) + if next.is_some() { 2 } else { 0 }; | ||
let prev = prev.or_else(empty_summary).unwrap().0; | ||
let next = next.or_else(empty_summary).unwrap().0; | ||
let interval = interval_to_ms(&start, &duration); | ||
crate::build! { | ||
CounterInterpolatedDeltaAccessor { | ||
timestamp : start.into(), | ||
interval, | ||
prev, | ||
next, | ||
flags, | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.