Skip to content

Commit

Permalink
Merge #491
Browse files Browse the repository at this point in the history
491: Stabilize accessors. r=epgts a=epgts



Co-authored-by: Eric Gillespie <epg@timescale.com>
  • Loading branch information
bors[bot] and epgts authored Aug 16, 2022
2 parents 7691792 + 5b24113 commit ec8080c
Show file tree
Hide file tree
Showing 13 changed files with 534 additions and 285 deletions.
4 changes: 2 additions & 2 deletions docs/timeseries_pipeline_elements.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ CREATE VIEW daily_delta AS
SELECT device,
timevector(time, temperature)
-> (toolkit_experimental.sort()
-> toolkit_experimental.delta()) AS deltas
-> delta()) AS deltas
FROM test_data
GROUP BY device;
```
Expand Down Expand Up @@ -142,7 +142,7 @@ This element will return a new timevector where each point is the difference bet
SELECT time, value
FROM unnest(
(SELECT timevector('2020-01-01'::timestamptz + step * '1 day'::interval, step * step)
-> toolkit_experimental.delta()
-> delta()
FROM generate_series(1, 5) step)
);
```
Expand Down
151 changes: 73 additions & 78 deletions extension/src/accessors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,50 +48,46 @@ macro_rules! accessor_fn_impl {
};
}

#[pg_schema]
pub mod toolkit_experimental {
pub use super::*;

accessor! { approx_percentile(
percentile: f64,
) }

accessor! { approx_percentile_rank(
value: f64,
) }

accessor! { num_vals() }
accessor! { mean() }
accessor! { error() }
accessor! { min_val() }
accessor! { max_val() }
accessor! { average() }
accessor! { average_x() }
accessor! { average_y() }
accessor! { sum() }
accessor! { sum_x() }
accessor! { sum_y() }
accessor! { slope() }
accessor! { corr() }
accessor! { intercept() }
accessor! { x_intercept() }
accessor! { determination_coeff() }
accessor! { distinct_count() }
accessor! { stderror() }
accessor! { delta() }
accessor! { time_delta() }
accessor! { rate() }
accessor! { irate_left() }
accessor! { irate_right() }
accessor! { idelta_left() }
accessor! { idelta_right() }
accessor! { num_elements() }
accessor! { num_changes() }
accessor! { num_resets() }
accessor! { counter_zero_time() }


// The rest are more complex, with String or other challenges. Leaving alone for now.
accessor! { approx_percentile(
percentile: f64,
) }

accessor! { approx_percentile_rank(
value: f64,
) }

accessor! { num_vals() }
accessor! { mean() }
accessor! { error() }
accessor! { min_val() }
accessor! { max_val() }
accessor! { average() }
accessor! { average_x() }
accessor! { average_y() }
accessor! { sum() }
accessor! { sum_x() }
accessor! { sum_y() }
accessor! { slope() }
accessor! { corr() }
accessor! { intercept() }
accessor! { x_intercept() }
accessor! { determination_coeff() }
accessor! { distinct_count() }
accessor! { stderror() }
accessor! { delta() }
accessor! { time_delta() }
accessor! { rate() }
accessor! { irate_left() }
accessor! { irate_right() }
accessor! { idelta_left() }
accessor! { idelta_right() }
accessor! { num_elements() }
accessor! { num_changes() }
accessor! { num_resets() }
accessor! { counter_zero_time() }


// The rest are more complex, with String or other challenges. Leaving alone for now.

pg_type! {
#[derive(Debug)]
Expand All @@ -104,10 +100,10 @@ pub mod toolkit_experimental {
//FIXME string IO
ron_inout_funcs!(AccessorStdDev);

#[pg_extern(immutable, parallel_safe, schema="toolkit_experimental", name="stddev")]
#[pg_extern(immutable, parallel_safe, name="stddev")]
pub fn accessor_stddev(
method: default!(&str, "'sample'"),
) -> toolkit_experimental::AccessorStdDev<'static> {
) -> AccessorStdDev<'static> {
let _ = crate::stats_agg::method_kind(method);
unsafe {
flatten!{
Expand All @@ -131,10 +127,10 @@ pub mod toolkit_experimental {
//FIXME string IO
ron_inout_funcs!(AccessorStdDevX);

#[pg_extern(immutable, parallel_safe, schema="toolkit_experimental", name="stddev_x")]
#[pg_extern(immutable, parallel_safe, name="stddev_x")]
pub fn accessor_stddev_x(
method: default!(&str, "'sample'"),
) -> toolkit_experimental::AccessorStdDevX<'static> {
) -> AccessorStdDevX<'static> {
let _ = crate::stats_agg::method_kind(method);
unsafe {
flatten!{
Expand All @@ -158,10 +154,10 @@ pub mod toolkit_experimental {
//FIXME string IO
ron_inout_funcs!(AccessorStdDevY);

#[pg_extern(immutable, parallel_safe, schema="toolkit_experimental", name="stddev_y")]
#[pg_extern(immutable, parallel_safe, name="stddev_y")]
pub fn accessor_stddev_y(
method: default!(&str, "'sample'"),
) -> toolkit_experimental::AccessorStdDevY<'static> {
) -> AccessorStdDevY<'static> {
let _ = crate::stats_agg::method_kind(method);
unsafe {
flatten!{
Expand All @@ -185,10 +181,10 @@ pub mod toolkit_experimental {
//FIXME string IO
ron_inout_funcs!(AccessorVariance);

#[pg_extern(immutable, parallel_safe, schema="toolkit_experimental", name="variance")]
#[pg_extern(immutable, parallel_safe, name="variance")]
pub fn accessor_variance(
method: default!(&str, "'sample'"),
) -> toolkit_experimental::AccessorVariance<'static> {
) -> AccessorVariance<'static> {
let _ = crate::stats_agg::method_kind(method);
unsafe {
flatten!{
Expand All @@ -212,10 +208,10 @@ pub mod toolkit_experimental {
//FIXME string IO
ron_inout_funcs!(AccessorVarianceX);

#[pg_extern(immutable, parallel_safe, schema="toolkit_experimental", name="variance_x")]
#[pg_extern(immutable, parallel_safe, name="variance_x")]
pub fn accessor_variance_x(
method: default!(&str, "'sample'"),
) -> toolkit_experimental::AccessorVarianceX<'static> {
) -> AccessorVarianceX<'static> {
let _ = crate::stats_agg::method_kind(method);
unsafe {
flatten!{
Expand All @@ -238,10 +234,10 @@ pub mod toolkit_experimental {
//FIXME string IO
ron_inout_funcs!(AccessorVarianceY);

#[pg_extern(immutable, parallel_safe, schema="toolkit_experimental", name="variance_y")]
#[pg_extern(immutable, parallel_safe, name="variance_y")]
pub fn accessor_variance_y(
method: default!(&str, "'sample'"),
) -> toolkit_experimental::AccessorVarianceY<'static> {
) -> AccessorVarianceY<'static> {
let _ = crate::stats_agg::method_kind(method);
unsafe {
flatten!{
Expand All @@ -264,10 +260,10 @@ pub mod toolkit_experimental {

ron_inout_funcs!(AccessorSkewness);

#[pg_extern(immutable, parallel_safe, schema="toolkit_experimental", name="skewness")]
#[pg_extern(immutable, parallel_safe, name="skewness")]
pub fn accessor_skewness(
method: default!(&str, "'sample'"),
) -> toolkit_experimental::AccessorSkewness<'static> {
) -> AccessorSkewness<'static> {
let _ = crate::stats_agg::method_kind(method);
unsafe {
flatten!{
Expand All @@ -290,10 +286,10 @@ pub mod toolkit_experimental {

ron_inout_funcs!(AccessorSkewnessX);

#[pg_extern(immutable, parallel_safe, schema="toolkit_experimental", name="skewness_x")]
#[pg_extern(immutable, parallel_safe, name="skewness_x")]
pub fn accessor_skewness_x(
method: default!(&str, "'sample'"),
) -> toolkit_experimental::AccessorSkewnessX<'static> {
) -> AccessorSkewnessX<'static> {
let _ = crate::stats_agg::method_kind(method);
unsafe {
flatten!{
Expand All @@ -316,10 +312,10 @@ pub mod toolkit_experimental {

ron_inout_funcs!(AccessorSkewnessY);

#[pg_extern(immutable, parallel_safe, schema="toolkit_experimental", name="skewness_y")]
#[pg_extern(immutable, parallel_safe, name="skewness_y")]
pub fn accessor_skewness_y(
method: default!(&str, "'sample'"),
) -> toolkit_experimental::AccessorSkewnessY<'static> {
) -> AccessorSkewnessY<'static> {
let _ = crate::stats_agg::method_kind(method);
unsafe {
flatten!{
Expand All @@ -342,10 +338,10 @@ pub mod toolkit_experimental {

ron_inout_funcs!(AccessorKurtosis);

#[pg_extern(immutable, parallel_safe, schema="toolkit_experimental", name="kurtosis")]
#[pg_extern(immutable, parallel_safe, name="kurtosis")]
pub fn accessor_kurtosis(
method: default!(&str, "'sample'"),
) -> toolkit_experimental::AccessorKurtosis<'static> {
) -> AccessorKurtosis<'static> {
let _ = crate::stats_agg::method_kind(method);
unsafe {
flatten!{
Expand All @@ -368,10 +364,10 @@ pub mod toolkit_experimental {

ron_inout_funcs!(AccessorKurtosisX);

#[pg_extern(immutable, parallel_safe, schema="toolkit_experimental", name="kurtosis_x")]
#[pg_extern(immutable, parallel_safe, name="kurtosis_x")]
pub fn accessor_kurtosis_x(
method: default!(&str, "'sample'"),
) -> toolkit_experimental::AccessorKurtosisX<'static> {
) -> AccessorKurtosisX<'static> {
let _ = crate::stats_agg::method_kind(method);
unsafe {
flatten!{
Expand All @@ -394,10 +390,10 @@ pub mod toolkit_experimental {

ron_inout_funcs!(AccessorKurtosisY);

#[pg_extern(immutable, parallel_safe, schema="toolkit_experimental", name="kurtosis_y")]
#[pg_extern(immutable, parallel_safe, name="kurtosis_y")]
pub fn accessor_kurtosis_y(
method: default!(&str, "'sample'"),
) -> toolkit_experimental::AccessorKurtosisY<'static> {
) -> AccessorKurtosisY<'static> {
let _ = crate::stats_agg::method_kind(method);
unsafe {
flatten!{
Expand All @@ -421,10 +417,10 @@ pub mod toolkit_experimental {
// FIXME string IO
ron_inout_funcs!(AccessorCovar);

#[pg_extern(immutable, parallel_safe, schema="toolkit_experimental", name="covariance")]
#[pg_extern(immutable, parallel_safe, name="covariance")]
pub fn accessor_covar(
method: default!(&str, "'sample'"),
) -> toolkit_experimental::AccessorCovar<'static> {
) -> AccessorCovar<'static> {
let _ = crate::stats_agg::method_kind(method);
unsafe {
flatten!{
Expand All @@ -448,10 +444,10 @@ pub mod toolkit_experimental {
//FIXME string IO
ron_inout_funcs!(AccessorExtrapolatedDelta);

#[pg_extern(immutable, parallel_safe, schema="toolkit_experimental", name="extrapolated_delta")]
#[pg_extern(immutable, parallel_safe, name="extrapolated_delta")]
pub fn accessor_extrapolated_delta(
method: &str,
) -> toolkit_experimental::AccessorExtrapolatedDelta<'static> {
) -> AccessorExtrapolatedDelta<'static> {
let _ = crate::counter_agg::method_kind(method);
unsafe {
flatten!{
Expand All @@ -475,10 +471,10 @@ pub mod toolkit_experimental {
//FIXME string IO
ron_inout_funcs!(AccessorExtrapolatedRate);

#[pg_extern(immutable, parallel_safe, schema="toolkit_experimental", name="extrapolated_rate")]
#[pg_extern(immutable, parallel_safe, name="extrapolated_rate")]
pub fn accessor_extrapolated_rate(
method: &str,
) -> toolkit_experimental::AccessorExtrapolatedRate<'static> {
) -> AccessorExtrapolatedRate<'static> {
let _ = crate::counter_agg::method_kind(method);
unsafe {
flatten!{
Expand All @@ -504,10 +500,10 @@ pub mod toolkit_experimental {

ron_inout_funcs!(AccessorWithBounds);

#[pg_extern(immutable, parallel_safe, schema="toolkit_experimental", name="with_bounds")]
#[pg_extern(immutable, parallel_safe, name="with_bounds")]
pub fn accessor_with_bounds(
bounds: crate::raw::tstzrange,
) -> toolkit_experimental::AccessorWithBounds<'static> {
) -> AccessorWithBounds<'static> {
let range = unsafe { crate::range::get_range(bounds.0 as *mut pg_sys::varlena) };
let mut accessor = build!{
AccessorWithBounds {
Expand Down Expand Up @@ -546,7 +542,6 @@ pub mod toolkit_experimental {
}.into()
}
}
}

pg_type! {
#[derive(Debug)]
Expand All @@ -565,4 +560,4 @@ pub fn accessor_unnest(
AccessorUnnest {
}
}
}
}
Loading

0 comments on commit ec8080c

Please sign in to comment.