Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stabilize accessors. #491

Merged
merged 1 commit into from
Aug 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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