diff --git a/docs/timeseries_pipeline_elements.md b/docs/timeseries_pipeline_elements.md index 185ffe54..42e354e3 100644 --- a/docs/timeseries_pipeline_elements.md +++ b/docs/timeseries_pipeline_elements.md @@ -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; ``` @@ -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) ); ``` diff --git a/extension/src/accessors.rs b/extension/src/accessors.rs index 18968d13..82764f53 100644 --- a/extension/src/accessors.rs +++ b/extension/src/accessors.rs @@ -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)] @@ -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!{ @@ -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!{ @@ -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!{ @@ -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!{ @@ -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!{ @@ -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!{ @@ -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!{ @@ -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!{ @@ -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!{ @@ -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!{ @@ -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!{ @@ -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!{ @@ -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!{ @@ -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!{ @@ -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!{ @@ -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 { @@ -546,7 +542,6 @@ pub mod toolkit_experimental { }.into() } } -} pg_type! { #[derive(Debug)] @@ -565,4 +560,4 @@ pub fn accessor_unnest( AccessorUnnest { } } -} \ No newline at end of file +} diff --git a/extension/src/counter_agg.rs b/extension/src/counter_agg.rs index eb65056b..6c3fcbe2 100644 --- a/extension/src/counter_agg.rs +++ b/extension/src/counter_agg.rs @@ -3,12 +3,18 @@ use serde::{Serialize, Deserialize}; use pgx::*; use crate::{ + accessors::{ + AccessorCorr, AccessorCounterZeroTime, AccessorDelta, AccessorExtrapolatedDelta, + AccessorExtrapolatedRate, AccessorIdeltaLeft, AccessorIdeltaRight, AccessorIntercept, + AccessorIrateLeft, AccessorIrateRight, AccessorNumChanges, AccessorNumElements, + AccessorNumResets, AccessorRate, AccessorSlope, AccessorTimeDelta, AccessorWithBounds, + }, aggregate_utils::in_aggregate_context, - ron_inout_funcs, flatten, - palloc::{Internal, InternalAsValue, Inner, ToInternal}, + palloc::{Inner, Internal, InternalAsValue, ToInternal}, pg_type, range::*, + ron_inout_funcs, }; use tspoint::TSPoint; @@ -46,12 +52,6 @@ pg_type! { ron_inout_funcs!(CounterSummary); -// hack to allow us to qualify names with "toolkit_experimental" -// so that pgx generates the correct SQL -mod toolkit_experimental { - pub(crate) use crate::accessors::toolkit_experimental::*; -} - impl<'input> CounterSummary<'input> { pub fn to_internal_counter_summary(&self) -> MetricSummary { MetricSummary{ @@ -432,9 +432,8 @@ requires = [counter_agg_summary_trans, counter_agg_final, counter_agg_combine, c #[opname(->)] pub fn arrow_counter_agg_delta( sketch: CounterSummary, - accessor: toolkit_experimental::AccessorDelta, + _accessor: AccessorDelta, ) -> f64 { - let _ = accessor; counter_agg_delta(sketch) } @@ -450,9 +449,8 @@ fn counter_agg_delta( #[opname(->)] pub fn arrow_counter_agg_rate( sketch: CounterSummary, - accessor: toolkit_experimental::AccessorRate, + _accessor: AccessorRate, ) -> Option { - let _ = accessor; counter_agg_rate(sketch) } @@ -468,9 +466,8 @@ fn counter_agg_rate( #[opname(->)] pub fn arrow_counter_agg_time_delta( sketch: CounterSummary, - accessor: toolkit_experimental::AccessorTimeDelta, + _accessor: AccessorTimeDelta, ) -> f64 { - let _ = accessor; counter_agg_time_delta(sketch) } @@ -486,9 +483,8 @@ fn counter_agg_time_delta( #[opname(->)] pub fn arrow_counter_agg_irate_left( sketch: CounterSummary, - accessor: toolkit_experimental::AccessorIrateLeft, + _accessor: AccessorIrateLeft, ) -> Option { - let _ = accessor; counter_agg_irate_left(sketch) } @@ -504,9 +500,8 @@ fn counter_agg_irate_left( #[opname(->)] pub fn arrow_counter_agg_irate_right( sketch: CounterSummary, - accessor: toolkit_experimental::AccessorIrateRight, + _accessor: AccessorIrateRight, ) -> Option { - let _ = accessor; counter_agg_irate_right(sketch) } @@ -522,9 +517,8 @@ fn counter_agg_irate_right( #[opname(->)] pub fn arrow_counter_agg_idelta_left( sketch: CounterSummary, - accessor: toolkit_experimental::AccessorIdeltaLeft, + _accessor: AccessorIdeltaLeft, ) -> f64 { - let _ = accessor; counter_agg_idelta_left(sketch) } @@ -540,9 +534,8 @@ fn counter_agg_idelta_left( #[opname(->)] pub fn arrow_counter_agg_idelta_right( sketch: CounterSummary, - accessor: toolkit_experimental::AccessorIdeltaRight, + _accessor: AccessorIdeltaRight, ) -> f64 { - let _ = accessor; counter_agg_idelta_right(sketch) } @@ -558,9 +551,8 @@ fn counter_agg_idelta_right( #[opname(->)] pub fn arrow_counter_agg_with_bounds( sketch: CounterSummary, - accessor: toolkit_experimental::AccessorWithBounds, + accessor: AccessorWithBounds, ) -> CounterSummary<'static> { - let _ = accessor; let mut builder = CounterSummaryBuilder::from(sketch.to_internal_counter_summary()); builder.set_bounds(accessor.bounds()); CounterSummary::from_internal_counter_summary(builder.build()) @@ -595,9 +587,8 @@ fn counter_agg_with_bounds( #[opname(->)] pub fn arrow_counter_agg_extrapolated_delta( sketch: CounterSummary, - accessor: toolkit_experimental::AccessorExtrapolatedDelta, + accessor: AccessorExtrapolatedDelta, ) -> Option { - let _ = accessor; let method = String::from_utf8_lossy(accessor.bytes.as_slice()); counter_agg_extrapolated_delta(sketch, &*method) } @@ -633,9 +624,8 @@ fn counter_agg_interpolated_delta( #[opname(->)] pub fn arrow_counter_agg_extrapolated_rate( sketch: CounterSummary, - accessor: toolkit_experimental::AccessorExtrapolatedRate, + accessor: AccessorExtrapolatedRate, ) -> Option { - let _ = accessor; let method = String::from_utf8_lossy(accessor.bytes.as_slice()); counter_agg_extrapolated_rate(sketch, &*method) } @@ -670,9 +660,8 @@ fn counter_agg_interpolated_rate( #[opname(->)] pub fn arrow_counter_agg_num_elements( sketch: CounterSummary, - accessor: toolkit_experimental::AccessorNumElements, + _accessor: AccessorNumElements, ) -> i64 { - let _ = accessor; counter_agg_num_elements(sketch) } @@ -688,9 +677,8 @@ fn counter_agg_num_elements( #[opname(->)] pub fn arrow_counter_agg_num_changes( sketch: CounterSummary, - accessor: toolkit_experimental::AccessorNumChanges, + _accessor: AccessorNumChanges, ) -> i64 { - let _ = accessor; counter_agg_num_changes(sketch) } @@ -706,9 +694,8 @@ fn counter_agg_num_changes( #[opname(->)] pub fn arrow_counter_agg_num_resets( sketch: CounterSummary, - accessor: toolkit_experimental::AccessorNumResets, + _accessor: AccessorNumResets, ) -> i64 { - let _ = accessor; counter_agg_num_resets(sketch) } @@ -724,9 +711,8 @@ fn counter_agg_num_resets( #[opname(->)] pub fn arrow_counter_agg_slope( sketch: CounterSummary, - accessor: toolkit_experimental::AccessorSlope, + _accessor: AccessorSlope, ) -> Option { - let _ = accessor; counter_agg_slope(sketch) } @@ -742,9 +728,8 @@ fn counter_agg_slope( #[opname(->)] pub fn arrow_counter_agg_intercept( sketch: CounterSummary, - accessor: toolkit_experimental::AccessorIntercept, + _accessor: AccessorIntercept, ) -> Option { - let _ = accessor; counter_agg_intercept(sketch) } @@ -760,9 +745,8 @@ fn counter_agg_intercept( #[opname(->)] pub fn arrow_counter_agg_corr( sketch: CounterSummary, - accessor: toolkit_experimental::AccessorCorr, + _accessor: AccessorCorr, ) -> Option { - let _ = accessor; counter_agg_corr(sketch) } @@ -778,9 +762,8 @@ fn counter_agg_corr( #[opname(->)] pub fn arrow_counter_agg_zero_time( sketch: CounterSummary, - accessor: toolkit_experimental::AccessorCounterZeroTime, + _accessor: AccessorCounterZeroTime, ) -> Option { - let _ = accessor; counter_agg_counter_zero_time(sketch) } @@ -1285,7 +1268,7 @@ mod tests { client, "SELECT \ irate_left(counter_agg(ts, val)), \ - counter_agg(ts, val) -> toolkit_experimental.irate_left() \ + counter_agg(ts, val) -> irate_left() \ FROM test", f64 ), @@ -1304,7 +1287,7 @@ mod tests { client, "SELECT \ irate_right(counter_agg(ts, val)), \ - counter_agg(ts, val) -> toolkit_experimental.irate_right() \ + counter_agg(ts, val) -> irate_right() \ FROM test", f64 ), @@ -1323,7 +1306,7 @@ mod tests { client, "SELECT \ idelta_left(counter_agg(ts, val)), \ - counter_agg(ts, val) -> toolkit_experimental.idelta_left() \ + counter_agg(ts, val) -> idelta_left() \ FROM test", f64 ), @@ -1342,7 +1325,7 @@ mod tests { client, "SELECT \ idelta_right(counter_agg(ts, val)), \ - counter_agg(ts, val) -> toolkit_experimental.idelta_right() \ + counter_agg(ts, val) -> idelta_right() \ FROM test", f64 ), @@ -1361,7 +1344,7 @@ mod tests { client, "SELECT \ num_resets(counter_agg(ts, val)), \ - counter_agg(ts, val) -> toolkit_experimental.num_resets() \ + counter_agg(ts, val) -> num_resets() \ FROM test", f64 ), diff --git a/extension/src/gauge_agg.rs b/extension/src/gauge_agg.rs index 93720324..a18b480e 100644 --- a/extension/src/gauge_agg.rs +++ b/extension/src/gauge_agg.rs @@ -7,6 +7,12 @@ use stats_agg::stats2d::StatsSummary2D; use tspoint::TSPoint; use crate::{ + accessors::{ + AccessorCorr, AccessorCounterZeroTime, AccessorDelta, AccessorExtrapolatedDelta, + AccessorExtrapolatedRate, AccessorIdeltaLeft, AccessorIdeltaRight, AccessorIntercept, + AccessorIrateLeft, AccessorIrateRight, AccessorNumChanges, AccessorNumElements, + AccessorRate, AccessorSlope, AccessorTimeDelta, AccessorWithBounds, + }, aggregate_utils::in_aggregate_context, flatten, palloc::{Inner, Internal, InternalAsValue, ToInternal}, @@ -91,10 +97,6 @@ mod toolkit_experimental { } ron_inout_funcs!(GaugeSummary); - - // hack to allow us to qualify names with "toolkit_experimental" - // so that pgx generates the correct SQL - pub(crate) use crate::accessors::toolkit_experimental::*; } use toolkit_experimental::*; @@ -416,7 +418,7 @@ extension_sql!( #[pg_operator(immutable, parallel_safe)] #[opname(->)] -fn arrow_delta(sketch: GaugeSummary, _accessor: toolkit_experimental::AccessorDelta) -> f64 { +fn arrow_delta(sketch: GaugeSummary, _accessor: AccessorDelta) -> f64 { delta(sketch) } @@ -429,7 +431,7 @@ fn delta(summary: GaugeSummary) -> f64 { #[opname(->)] fn arrow_gauge_agg_rate( sketch: GaugeSummary, - _accessor: toolkit_experimental::AccessorRate, + _accessor: AccessorRate, ) -> Option { rate(sketch) } @@ -443,7 +445,7 @@ fn rate(summary: GaugeSummary) -> Option { #[opname(->)] fn arrow_time_delta( sketch: GaugeSummary, - _accessor: toolkit_experimental::AccessorTimeDelta, + _accessor: AccessorTimeDelta, ) -> f64 { time_delta(sketch) } @@ -457,7 +459,7 @@ fn time_delta(summary: GaugeSummary) -> f64 { #[opname(->)] fn arrow_irate_left( sketch: GaugeSummary, - _accessor: toolkit_experimental::AccessorIrateLeft, + _accessor: AccessorIrateLeft, ) -> Option { irate_left(sketch) } @@ -471,7 +473,7 @@ fn irate_left(summary: GaugeSummary) -> Option { #[opname(->)] fn arrow_irate_right( sketch: GaugeSummary, - _accessor: toolkit_experimental::AccessorIrateRight, + _accessor: AccessorIrateRight, ) -> Option { irate_right(sketch) } @@ -485,7 +487,7 @@ fn irate_right(summary: GaugeSummary) -> Option { #[opname(->)] fn arrow_idelta_left( sketch: GaugeSummary, - _accessor: toolkit_experimental::AccessorIdeltaLeft, + _accessor: AccessorIdeltaLeft, ) -> f64 { idelta_left(sketch) } @@ -499,7 +501,7 @@ fn idelta_left(summary: GaugeSummary) -> f64 { #[opname(->)] fn arrow_idelta_right( sketch: GaugeSummary, - _accessor: toolkit_experimental::AccessorIdeltaRight, + _accessor: AccessorIdeltaRight, ) -> f64 { idelta_right(sketch) } @@ -513,7 +515,7 @@ fn idelta_right(summary: GaugeSummary) -> f64 { #[opname(->)] fn arrow_with_bounds( sketch: GaugeSummary, - accessor: toolkit_experimental::AccessorWithBounds, + accessor: AccessorWithBounds, ) -> GaugeSummary<'static> { let mut builder = GaugeSummaryBuilder::from(MetricSummary::from(sketch)); builder.set_bounds(accessor.bounds()); @@ -535,7 +537,7 @@ fn with_bounds(summary: GaugeSummary, bounds: tstzrange) -> GaugeSummary { #[opname(->)] fn arrow_extrapolated_delta( sketch: GaugeSummary, - _accessor: toolkit_experimental::AccessorExtrapolatedDelta, + _accessor: AccessorExtrapolatedDelta, ) -> Option { extrapolated_delta(sketch) } @@ -564,7 +566,7 @@ fn interpolated_delta( #[opname(->)] fn arrow_extrapolated_rate( sketch: GaugeSummary, - _accessor: toolkit_experimental::AccessorExtrapolatedRate, + _accessor: AccessorExtrapolatedRate, ) -> Option { extrapolated_rate(sketch) } @@ -593,7 +595,7 @@ fn interpolated_rate( #[opname(->)] fn arrow_num_elements( sketch: GaugeSummary, - _accessor: toolkit_experimental::AccessorNumElements, + _accessor: AccessorNumElements, ) -> i64 { num_elements(sketch) } @@ -607,7 +609,7 @@ fn num_elements(summary: GaugeSummary) -> i64 { #[opname(->)] fn arrow_num_changes( sketch: GaugeSummary, - _accessor: toolkit_experimental::AccessorNumChanges, + _accessor: AccessorNumChanges, ) -> i64 { num_changes(sketch) } @@ -621,7 +623,7 @@ fn num_changes(summary: GaugeSummary) -> i64 { #[opname(->)] fn arrow_slope( sketch: GaugeSummary, - _accessor: toolkit_experimental::AccessorSlope, + _accessor: AccessorSlope, ) -> Option { slope(sketch) } @@ -635,7 +637,7 @@ fn slope(summary: GaugeSummary) -> Option { #[opname(->)] fn arrow_intercept( sketch: GaugeSummary, - _accessor: toolkit_experimental::AccessorIntercept, + _accessor: AccessorIntercept, ) -> Option { intercept(sketch) } @@ -647,7 +649,7 @@ fn intercept(summary: GaugeSummary) -> Option { #[pg_operator(immutable, parallel_safe)] #[opname(->)] -fn arrow_corr(sketch: GaugeSummary, _accessor: toolkit_experimental::AccessorCorr) -> Option { +fn arrow_corr(sketch: GaugeSummary, _accessor: AccessorCorr) -> Option { corr(sketch) } @@ -660,7 +662,7 @@ fn corr(summary: GaugeSummary) -> Option { #[opname(->)] fn arrow_zero_time( sketch: GaugeSummary, - __accessor: toolkit_experimental::AccessorCounterZeroTime, + __accessor: AccessorCounterZeroTime, ) -> Option { gauge_zero_time(sketch) } diff --git a/extension/src/hyperloglog.rs b/extension/src/hyperloglog.rs index cc2f0b2a..8992e539 100644 --- a/extension/src/hyperloglog.rs +++ b/extension/src/hyperloglog.rs @@ -10,6 +10,7 @@ use pg_sys::{Datum, Oid}; use pgx::*; use crate::{ + accessors::{AccessorDistinctCount, AccessorStderror}, aggregate_utils::{get_collation, in_aggregate_context}, datum_utils::DatumHashBuilder, flatten, ron_inout_funcs, @@ -197,12 +198,6 @@ flat_serialize_macro::flat_serialize! { } } -// hack to allow us to qualify names with "toolkit_experimental" -// so that pgx generates the correct SQL -mod toolkit_experimental { - pub(crate) use crate::accessors::toolkit_experimental::*; -} - ron_inout_funcs!(HyperLogLog); #[pg_extern(immutable, parallel_safe)] @@ -317,9 +312,8 @@ requires = [hyperloglog_union, hyperloglog_final, hyperloglog_combine, hyperlogl #[opname(->)] pub fn arrow_hyperloglog_count( sketch: HyperLogLog, - accessor: toolkit_experimental::AccessorDistinctCount, + _accessor: AccessorDistinctCount, ) -> i64 { - let _ = accessor; hyperloglog_count(sketch) } @@ -342,9 +336,8 @@ pub fn hyperloglog_count( #[opname(->)] pub fn arrow_hyperloglog_error( sketch: HyperLogLog, - accessor: toolkit_experimental::AccessorStderror, + _accessor: AccessorStderror, ) -> f64 { - let _ = accessor; hyperloglog_error(sketch) } @@ -478,7 +471,7 @@ mod tests { distinct_count(\ hyperloglog(32, v::float)\ ), \ - hyperloglog(32, v::float)->toolkit_experimental.distinct_count() \ + hyperloglog(32, v::float) -> distinct_count() \ FROM generate_series(1, 100) v", None, None) .first() .get_two::(); @@ -552,7 +545,7 @@ mod tests { distinct_count(\ toolkit_experimental.approx_count_distinct(v::float)\ ), \ - toolkit_experimental.approx_count_distinct(v::float)->toolkit_experimental.distinct_count() \ + toolkit_experimental.approx_count_distinct(v::float) -> distinct_count() \ FROM generate_series(1, 100) v", None, None) .first() .get_two::(); @@ -853,7 +846,7 @@ mod tests { stderror(\ hyperloglog(32, v::float)\ ), \ - hyperloglog(32, v::float)->toolkit_experimental.stderror() \ + hyperloglog(32, v::float) -> stderror() \ FROM generate_series(1, 100) v", None, None) .first() .get_two::(); diff --git a/extension/src/stabilization_info.rs b/extension/src/stabilization_info.rs index fadedddf..bfc82add 100644 --- a/extension/src/stabilization_info.rs +++ b/extension/src/stabilization_info.rs @@ -12,25 +12,223 @@ crate::functions_stabilized_at! { STABLE_FUNCTIONS "1.9.0" => { + accessorapproxpercentile_in(cstring), + accessorapproxpercentile_out(accessorapproxpercentile), + accessorapproxpercentilerank_in(cstring), + accessorapproxpercentilerank_out(accessorapproxpercentilerank), + accessoraverage_in(cstring), + accessoraverage_out(accessoraverage), + accessoraveragex_in(cstring), + accessoraveragex_out(accessoraveragex), + accessoraveragey_in(cstring), + accessoraveragey_out(accessoraveragey), + accessorcorr_in(cstring), + accessorcorr_out(accessorcorr), + accessorcounterzerotime_in(cstring), + accessorcounterzerotime_out(accessorcounterzerotime), + accessorcovar_in(cstring), + accessorcovar_out(accessorcovar), + accessordelta_in(cstring), + accessordelta_out(accessordelta), + accessordeterminationcoeff_in(cstring), + accessordeterminationcoeff_out(accessordeterminationcoeff), + accessordistinctcount_in(cstring), + accessordistinctcount_out(accessordistinctcount), + accessorerror_in(cstring), + accessorerror_out(accessorerror), + accessorextrapolateddelta_in(cstring), + accessorextrapolateddelta_out(accessorextrapolateddelta), + accessorextrapolatedrate_in(cstring), + accessorextrapolatedrate_out(accessorextrapolatedrate), + accessorideltaleft_in(cstring), + accessorideltaleft_out(accessorideltaleft), + accessorideltaright_in(cstring), + accessorideltaright_out(accessorideltaright), + accessorintercept_in(cstring), + accessorintercept_out(accessorintercept), + accessorirateleft_in(cstring), + accessorirateleft_out(accessorirateleft), + accessorirateright_in(cstring), + accessorirateright_out(accessorirateright), + accessorkurtosis_in(cstring), + accessorkurtosis_out(accessorkurtosis), + accessorkurtosisx_in(cstring), + accessorkurtosisx_out(accessorkurtosisx), + accessorkurtosisy_in(cstring), + accessorkurtosisy_out(accessorkurtosisy), + accessormaxval_in(cstring), + accessormaxval_out(accessormaxval), + accessormean_in(cstring), + accessormean_out(accessormean), + accessorminval_in(cstring), + accessorminval_out(accessorminval), + accessornumchanges_in(cstring), + accessornumchanges_out(accessornumchanges), + accessornumelements_in(cstring), + accessornumelements_out(accessornumelements), + accessornumresets_in(cstring), + accessornumresets_out(accessornumresets), + accessornumvals_in(cstring), + accessornumvals_out(accessornumvals), + accessorrate_in(cstring), + accessorrate_out(accessorrate), + accessorskewness_in(cstring), + accessorskewness_out(accessorskewness), + accessorskewnessx_in(cstring), + accessorskewnessx_out(accessorskewnessx), + accessorskewnessy_in(cstring), + accessorskewnessy_out(accessorskewnessy), + accessorslope_in(cstring), + accessorslope_out(accessorslope), + accessorstddev_in(cstring), + accessorstddev_out(accessorstddev), + accessorstddevx_in(cstring), + accessorstddevx_out(accessorstddevx), + accessorstddevy_in(cstring), + accessorstddevy_out(accessorstddevy), + accessorstderror_in(cstring), + accessorstderror_out(accessorstderror), + accessorsum_in(cstring), + accessorsum_out(accessorsum), + accessorsumx_in(cstring), + accessorsumx_out(accessorsumx), + accessorsumy_in(cstring), + accessorsumy_out(accessorsumy), + accessortimedelta_in(cstring), + accessortimedelta_out(accessortimedelta), accessorunnest_in(cstring), accessorunnest_out(accessorunnest), + accessorvariance_in(cstring), + accessorvariance_out(accessorvariance), + accessorvariancex_in(cstring), + accessorvariancex_out(accessorvariancex), + accessorvariancey_in(cstring), + accessorvariancey_out(accessorvariancey), + accessorwithbounds_in(cstring), + accessorwithbounds_out(accessorwithbounds), + accessorxintercept_in(cstring), + accessorxintercept_out(accessorxintercept), + approx_percentile(double precision), + approx_percentile_rank(double precision), + arrow_counter_agg_corr(countersummary,accessorcorr), + arrow_counter_agg_delta(countersummary,accessordelta), + arrow_counter_agg_extrapolated_delta(countersummary,accessorextrapolateddelta), + arrow_counter_agg_extrapolated_rate(countersummary,accessorextrapolatedrate), + arrow_counter_agg_idelta_left(countersummary,accessorideltaleft), + arrow_counter_agg_idelta_right(countersummary,accessorideltaright), + arrow_counter_agg_intercept(countersummary,accessorintercept), + arrow_counter_agg_irate_left(countersummary,accessorirateleft), + arrow_counter_agg_irate_right(countersummary,accessorirateright), + arrow_counter_agg_num_changes(countersummary,accessornumchanges), + arrow_counter_agg_num_elements(countersummary,accessornumelements), + arrow_counter_agg_num_resets(countersummary,accessornumresets), + arrow_counter_agg_rate(countersummary,accessorrate), + arrow_counter_agg_slope(countersummary,accessorslope), + arrow_counter_agg_time_delta(countersummary,accessortimedelta), + arrow_counter_agg_with_bounds(countersummary,accessorwithbounds), + arrow_counter_agg_zero_time(countersummary,accessorcounterzerotime), + arrow_hyperloglog_count(hyperloglog,accessordistinctcount), + arrow_hyperloglog_error(hyperloglog,accessorstderror), + arrow_stats1d_average(statssummary1d,accessoraverage), + arrow_stats1d_kurtosis(statssummary1d,accessorkurtosis), + arrow_stats1d_num_vals(statssummary1d,accessornumvals), + arrow_stats1d_skewness(statssummary1d,accessorskewness), + arrow_stats1d_stddev(statssummary1d,accessorstddev), + arrow_stats1d_sum(statssummary1d,accessorsum), + arrow_stats1d_variance(statssummary1d,accessorvariance), + arrow_stats2d_average_x(statssummary2d,accessoraveragex), + arrow_stats2d_average_y(statssummary2d,accessoraveragey), + arrow_stats2d_corr(statssummary2d,accessorcorr), + arrow_stats2d_covar(statssummary2d,accessorcovar), + arrow_stats2d_determination_coeff(statssummary2d,accessordeterminationcoeff), + arrow_stats2d_intercept(statssummary2d,accessorintercept), + arrow_stats2d_kurtosis_x(statssummary2d,accessorkurtosisx), + arrow_stats2d_kurtosis_y(statssummary2d,accessorkurtosisy), + arrow_stats2d_num_vals(statssummary2d,accessornumvals), + arrow_stats2d_skewness_x(statssummary2d,accessorskewnessx), + arrow_stats2d_skewness_y(statssummary2d,accessorskewnessy), + arrow_stats2d_slope(statssummary2d,accessorslope), + arrow_stats2d_stdddev_x(statssummary2d,accessorstddevx), + arrow_stats2d_stdddev_y(statssummary2d,accessorstddevy), + arrow_stats2d_sum_x(statssummary2d,accessorsumx), + arrow_stats2d_sum_y(statssummary2d,accessorsumy), + arrow_stats2d_variance_x(statssummary2d,accessorvariancex), + arrow_stats2d_variance_y(statssummary2d,accessorvariancey), + arrow_stats2d_x_intercept(statssummary2d,accessorxintercept), + arrow_tdigest_approx_percentile(tdigest,accessorapproxpercentile), + arrow_tdigest_approx_rank(tdigest,accessorapproxpercentilerank), + arrow_tdigest_max(tdigest,accessormaxval), + arrow_tdigest_mean(tdigest,accessormean), + arrow_tdigest_min(tdigest,accessorminval), + arrow_tdigest_num_vals(tdigest,accessornumvals), + arrow_time_weighted_average_average(timeweightsummary,accessoraverage), arrow_timevector_unnest(timevector_tstz_f64,accessorunnest), + arrow_uddsketch_approx_percentile(uddsketch,accessorapproxpercentile), + arrow_uddsketch_approx_rank(uddsketch,accessorapproxpercentilerank), + arrow_uddsketch_error(uddsketch,accessorerror), + arrow_uddsketch_mean(uddsketch,accessormean), + arrow_uddsketch_num_vals(uddsketch,accessornumvals), + average(), + average_x(), + average_y(), + corr(), + counter_zero_time(), + covariance(text), + delta(), + determination_coeff(), + distinct_count(), + error(), + extrapolated_delta(text), + extrapolated_rate(text), + idelta_left(), + idelta_right(), + intercept(), + irate_left(), + irate_right(), + kurtosis(text), + kurtosis_x(text), + kurtosis_y(text), + lttb(timestamp with time zone,double precision,integer), + lttb(timevector_tstz_f64,integer), + lttb_final(internal), + lttb_trans(internal,timestamp with time zone,double precision,integer), + max_val(), + mean(), + min_val(), + num_changes(), + num_elements(), + num_resets(), + num_vals(), + rate(), rollup(timevector_tstz_f64), + skewness(text), + skewness_x(text), + skewness_y(text), + slope(), + stddev(text), + stddev_x(text), + stddev_y(text), + stderror(), + sum(), + sum_x(), + sum_y(), + time_delta(), timevector(timestamp with time zone,double precision), timevector_combine(internal,internal), - timevector_tstz_f64_compound_trans(internal,timevector_tstz_f64), timevector_deserialize(bytea,internal), timevector_final(internal), + timevector_serialize(internal), + timevector_tstz_f64_compound_trans(internal,timevector_tstz_f64), timevector_tstz_f64_in(cstring), timevector_tstz_f64_out(timevector_tstz_f64), - timevector_serialize(internal), timevector_tstz_f64_trans(internal,timestamp with time zone,double precision), - unnest(timevector_tstz_f64), unnest(), - lttb(timestamp with time zone,double precision,integer), - lttb(timevector_tstz_f64,integer), - lttb_final(internal), - lttb_trans(internal,timestamp with time zone,double precision,integer), + unnest(timevector_tstz_f64), + variance(text), + variance_x(text), + variance_y(text), + with_bounds(tstzrange), + x_intercept(), } "1.8.0" => { } @@ -190,8 +388,55 @@ crate::functions_stabilized_at! { crate::types_stabilized_at! { STABLE_TYPES "1.9.0" => { + accessorapproxpercentile, + accessorapproxpercentilerank, + accessoraverage, + accessoraveragex, + accessoraveragey, + accessorcorr, + accessorcounterzerotime, + accessorcovar, + accessordelta, + accessordeterminationcoeff, + accessordistinctcount, + accessorerror, + accessorextrapolateddelta, + accessorextrapolatedrate, + accessorideltaleft, + accessorideltaright, + accessorintercept, + accessorirateleft, + accessorirateright, + accessorkurtosis, + accessorkurtosisx, + accessorkurtosisy, + accessormaxval, + accessormean, + accessorminval, + accessornumchanges, + accessornumelements, + accessornumresets, + accessornumvals, + accessorrate, + accessorskewness, + accessorskewnessx, + accessorskewnessy, + accessorslope, + accessorstddev, + accessorstddevx, + accessorstddevy, + accessorstderror, + accessorsum, + accessorsumx, + accessorsumy, + accessortimedelta, + accessorunnest, + accessorvariance, + accessorvariancex, + accessorvariancey, + accessorwithbounds, + accessorxintercept, timevector_tstz_f64, - accessorunnest } "1.8.0" => { } @@ -215,7 +460,64 @@ crate::types_stabilized_at! { crate::operators_stabilized_at! { STABLE_OPERATORS "1.9.0" => { + "->"(countersummary,accessorcorr), + "->"(countersummary,accessorcounterzerotime), + "->"(countersummary,accessordelta), + "->"(countersummary,accessorextrapolateddelta), + "->"(countersummary,accessorextrapolatedrate), + "->"(countersummary,accessorideltaleft), + "->"(countersummary,accessorideltaright), + "->"(countersummary,accessorintercept), + "->"(countersummary,accessorirateleft), + "->"(countersummary,accessorirateright), + "->"(countersummary,accessornumchanges), + "->"(countersummary,accessornumelements), + "->"(countersummary,accessornumresets), + "->"(countersummary,accessorrate), + "->"(countersummary,accessorslope), + "->"(countersummary,accessortimedelta), + "->"(countersummary,accessorwithbounds), + "->"(hyperloglog,accessordistinctcount), + "->"(hyperloglog,accessorstderror), + "->"(statssummary1d,accessoraverage), + "->"(statssummary1d,accessorkurtosis), + "->"(statssummary1d,accessornumvals), + "->"(statssummary1d,accessorskewness), + "->"(statssummary1d,accessorstddev), + "->"(statssummary1d,accessorsum), + "->"(statssummary1d,accessorvariance), + "->"(statssummary2d,accessoraveragex), + "->"(statssummary2d,accessoraveragey), + "->"(statssummary2d,accessorcorr), + "->"(statssummary2d,accessorcovar), + "->"(statssummary2d,accessordeterminationcoeff), + "->"(statssummary2d,accessorintercept), + "->"(statssummary2d,accessorkurtosisx), + "->"(statssummary2d,accessorkurtosisy), + "->"(statssummary2d,accessornumvals), + "->"(statssummary2d,accessorskewnessx), + "->"(statssummary2d,accessorskewnessy), + "->"(statssummary2d,accessorslope), + "->"(statssummary2d,accessorstddevx), + "->"(statssummary2d,accessorstddevy), + "->"(statssummary2d,accessorsumx), + "->"(statssummary2d,accessorsumy), + "->"(statssummary2d,accessorvariancex), + "->"(statssummary2d,accessorvariancey), + "->"(statssummary2d,accessorxintercept), + "->"(tdigest,accessorapproxpercentile), + "->"(tdigest,accessorapproxpercentilerank), + "->"(tdigest,accessormaxval), + "->"(tdigest,accessormean), + "->"(tdigest,accessorminval), + "->"(tdigest,accessornumvals), "->"(timevector_tstz_f64,accessorunnest), + "->"(timeweightsummary,accessoraverage), + "->"(uddsketch,accessorapproxpercentile), + "->"(uddsketch,accessorapproxpercentilerank), + "->"(uddsketch,accessorerror), + "->"(uddsketch,accessormean), + "->"(uddsketch,accessornumvals), } "1.8.0" => { } @@ -227,4 +529,4 @@ crate::operators_stabilized_at! { } "prehistory" => { } -} \ No newline at end of file +} diff --git a/extension/src/stats_agg.rs b/extension/src/stats_agg.rs index 13e2072b..122b0ad9 100644 --- a/extension/src/stats_agg.rs +++ b/extension/src/stats_agg.rs @@ -1,12 +1,17 @@ - use pgx::*; use crate::{ + accessors::{ + AccessorAverage, AccessorAverageX, AccessorAverageY, AccessorCorr, AccessorCovar, + AccessorDeterminationCoeff, AccessorIntercept, AccessorKurtosis, AccessorKurtosisX, + AccessorKurtosisY, AccessorNumVals, AccessorSkewness, AccessorSkewnessX, AccessorSkewnessY, + AccessorSlope, AccessorStdDev, AccessorStdDevX, AccessorStdDevY, AccessorSum, AccessorSumX, + AccessorSumY, AccessorVariance, AccessorVarianceX, AccessorVarianceY, AccessorXIntercept, + }, aggregate_utils::in_aggregate_context, - ron_inout_funcs, build, - palloc::{Internal, InternalAsValue, Inner, ToInternal}, - pg_type, + palloc::{Inner, Internal, InternalAsValue, ToInternal}, + pg_type, ron_inout_funcs, }; use stats_agg::XYPair; @@ -47,13 +52,6 @@ pg_type! { ron_inout_funcs!(StatsSummary1D); ron_inout_funcs!(StatsSummary2D); - -// hack to allow us to qualify names with "toolkit_experimental" -// so that pgx generates the correct SQL -mod toolkit_experimental { - pub(crate) use crate::accessors::toolkit_experimental::*; -} - impl<'input> StatsSummary1D<'input> { fn to_internal(&self) -> InternalStatsSummary1D { InternalStatsSummary1D{ @@ -691,9 +689,8 @@ requires = [stats2d_summary_trans, stats2d_final, stats2d_combine, stats2d_trans #[opname(->)] pub fn arrow_stats1d_average( sketch: StatsSummary1D, - accessor: toolkit_experimental::AccessorAverage, + _accessor: AccessorAverage, ) -> Option { - let _ = accessor; stats1d_average(sketch) } @@ -709,9 +706,8 @@ pub(crate) fn stats1d_average( #[opname(->)] pub fn arrow_stats1d_sum( sketch: StatsSummary1D, - accessor: toolkit_experimental::AccessorSum, + _accessor: AccessorSum, ) -> Option { - let _ = accessor; stats1d_sum(sketch) } @@ -727,9 +723,8 @@ pub (crate) fn stats1d_sum( #[opname(->)] pub fn arrow_stats1d_stddev( sketch: Option, - accessor: toolkit_experimental::AccessorStdDev, + accessor: AccessorStdDev, ) -> Option { - let _ = accessor; let method = String::from_utf8_lossy(accessor.bytes.as_slice()); stats1d_stddev(sketch, &*method) } @@ -750,9 +745,8 @@ fn stats1d_stddev( #[opname(->)] pub fn arrow_stats1d_variance( sketch: Option, - accessor: toolkit_experimental::AccessorVariance, + accessor: AccessorVariance, ) -> Option { - let _ = accessor; let method = String::from_utf8_lossy(accessor.bytes.as_slice()); stats1d_variance(sketch, &*method) } @@ -773,9 +767,8 @@ fn stats1d_variance( #[opname(->)] pub fn arrow_stats1d_skewness( sketch: StatsSummary1D, - accessor: toolkit_experimental::AccessorSkewness, + accessor: AccessorSkewness, ) -> Option { - let _ = accessor; let method = String::from_utf8_lossy(accessor.bytes.as_slice()); stats1d_skewness(sketch, &*method) } @@ -796,9 +789,8 @@ fn stats1d_skewness( #[opname(->)] pub fn arrow_stats1d_kurtosis( sketch: StatsSummary1D, - accessor: toolkit_experimental::AccessorKurtosis, + accessor: AccessorKurtosis, ) -> Option { - let _ = accessor; let method = String::from_utf8_lossy(accessor.bytes.as_slice()); stats1d_kurtosis(sketch, &*method) } @@ -820,9 +812,8 @@ fn stats1d_kurtosis( #[opname(->)] pub fn arrow_stats1d_num_vals( sketch: StatsSummary1D, - accessor: toolkit_experimental::AccessorNumVals, + _accessor: AccessorNumVals, ) -> i64 { - let _ = accessor; stats1d_num_vals(sketch) } @@ -838,9 +829,8 @@ fn stats1d_num_vals( #[opname(->)] pub fn arrow_stats2d_average_x( sketch: StatsSummary2D, - accessor: toolkit_experimental::AccessorAverageX, + _accessor: AccessorAverageX, ) -> Option { - let _ = accessor; stats2d_average_x(sketch) } @@ -856,9 +846,8 @@ fn stats2d_average_x( #[opname(->)] pub fn arrow_stats2d_average_y( sketch: StatsSummary2D, - accessor: toolkit_experimental::AccessorAverageY, + _accessor: AccessorAverageY, ) -> Option { - let _ = accessor; stats2d_average_y(sketch) } @@ -874,9 +863,8 @@ fn stats2d_average_y( #[opname(->)] pub fn arrow_stats2d_sum_x( sketch: StatsSummary2D, - accessor: toolkit_experimental::AccessorSumX, + _accessor: AccessorSumX, ) -> Option { - let _ = accessor; stats2d_sum_x(sketch) } @@ -892,9 +880,8 @@ fn stats2d_sum_x( #[opname(->)] pub fn arrow_stats2d_sum_y( sketch: StatsSummary2D, - accessor: toolkit_experimental::AccessorSumY, + _accessor: AccessorSumY, ) -> Option { - let _ = accessor; stats2d_sum_y(sketch) } @@ -910,9 +897,8 @@ fn stats2d_sum_y( #[opname(->)] pub fn arrow_stats2d_stdddev_x( sketch: Option, - accessor: toolkit_experimental::AccessorStdDevX, + accessor: AccessorStdDevX, ) -> Option { - let _ = accessor; let method = String::from_utf8_lossy(accessor.bytes.as_slice()); stats2d_stddev_x(sketch, &*method) } @@ -933,9 +919,8 @@ fn stats2d_stddev_x( #[opname(->)] pub fn arrow_stats2d_stdddev_y( sketch: Option, - accessor: toolkit_experimental::AccessorStdDevY, + accessor: AccessorStdDevY, ) -> Option { - let _ = accessor; let method = String::from_utf8_lossy(accessor.bytes.as_slice()); stats2d_stddev_y(sketch, &*method) } @@ -956,9 +941,8 @@ fn stats2d_stddev_y( #[opname(->)] pub fn arrow_stats2d_variance_x( sketch: Option, - accessor: toolkit_experimental::AccessorVarianceX, + accessor: AccessorVarianceX, ) -> Option { - let _ = accessor; let method = String::from_utf8_lossy(accessor.bytes.as_slice()); stats2d_variance_x(sketch, &*method) } @@ -979,9 +963,8 @@ fn stats2d_variance_x( #[opname(->)] pub fn arrow_stats2d_variance_y( sketch: Option, - accessor: toolkit_experimental::AccessorVarianceY, + accessor: AccessorVarianceY, ) -> Option { - let _ = accessor; let method = String::from_utf8_lossy(accessor.bytes.as_slice()); stats2d_variance_y(sketch, &*method) } @@ -1002,9 +985,8 @@ fn stats2d_variance_y( #[opname(->)] pub fn arrow_stats2d_skewness_x( sketch: StatsSummary2D, - accessor: toolkit_experimental::AccessorSkewnessX, + accessor: AccessorSkewnessX, ) -> Option { - let _ = accessor; let method = String::from_utf8_lossy(accessor.bytes.as_slice()); stats2d_skewness_x(sketch, &*method) } @@ -1025,9 +1007,8 @@ fn stats2d_skewness_x( #[opname(->)] pub fn arrow_stats2d_skewness_y( sketch: StatsSummary2D, - accessor: toolkit_experimental::AccessorSkewnessY, + accessor: AccessorSkewnessY, ) -> Option { - let _ = accessor; let method = String::from_utf8_lossy(accessor.bytes.as_slice()); stats2d_skewness_y(sketch, &*method) } @@ -1048,9 +1029,8 @@ fn stats2d_skewness_y( #[opname(->)] pub fn arrow_stats2d_kurtosis_x( sketch: StatsSummary2D, - accessor: toolkit_experimental::AccessorKurtosisX, + accessor: AccessorKurtosisX, ) -> Option { - let _ = accessor; let method = String::from_utf8_lossy(accessor.bytes.as_slice()); stats2d_kurtosis_x(sketch, &*method) } @@ -1071,9 +1051,8 @@ fn stats2d_kurtosis_x( #[opname(->)] pub fn arrow_stats2d_kurtosis_y( sketch: StatsSummary2D, - accessor: toolkit_experimental::AccessorKurtosisY, + accessor: AccessorKurtosisY, ) -> Option { - let _ = accessor; let method = String::from_utf8_lossy(accessor.bytes.as_slice()); stats2d_kurtosis_y(sketch, &*method) } @@ -1094,9 +1073,8 @@ fn stats2d_kurtosis_y( #[opname(->)] pub fn arrow_stats2d_num_vals( sketch: StatsSummary2D, - accessor: toolkit_experimental::AccessorNumVals, + _accessor: AccessorNumVals, ) -> i64 { - let _ = accessor; stats2d_num_vals(sketch) } @@ -1112,9 +1090,8 @@ fn stats2d_num_vals( #[opname(->)] pub fn arrow_stats2d_slope( sketch: StatsSummary2D, - accessor: toolkit_experimental::AccessorSlope, + _accessor: AccessorSlope, ) -> Option { - let _ = accessor; stats2d_slope(sketch) } @@ -1130,9 +1107,8 @@ fn stats2d_slope( #[opname(->)] pub fn arrow_stats2d_corr( sketch: StatsSummary2D, - accessor: toolkit_experimental::AccessorCorr, + _accessor: AccessorCorr, ) -> Option { - let _ = accessor; stats2d_corr(sketch) } @@ -1148,9 +1124,8 @@ fn stats2d_corr( #[opname(->)] pub fn arrow_stats2d_intercept( sketch: StatsSummary2D, - accessor: toolkit_experimental::AccessorIntercept, + _accessor: AccessorIntercept, ) -> Option { - let _ = accessor; stats2d_intercept(sketch) } @@ -1166,9 +1141,8 @@ fn stats2d_intercept( #[opname(->)] pub fn arrow_stats2d_x_intercept( sketch: StatsSummary2D, - accessor: toolkit_experimental::AccessorXIntercept, + _accessor: AccessorXIntercept, ) -> Option { - let _ = accessor; stats2d_x_intercept(sketch) } @@ -1184,9 +1158,8 @@ fn stats2d_x_intercept( #[opname(->)] pub fn arrow_stats2d_determination_coeff( sketch: StatsSummary2D, - accessor: toolkit_experimental::AccessorDeterminationCoeff, + _accessor: AccessorDeterminationCoeff, ) -> Option { - let _ = accessor; stats2d_determination_coeff(sketch) } @@ -1202,9 +1175,8 @@ fn stats2d_determination_coeff( #[opname(->)] pub fn arrow_stats2d_covar( sketch: Option, - accessor: toolkit_experimental::AccessorCovar, + accessor: AccessorCovar, ) -> Option { - let _ = accessor; let method = String::from_utf8_lossy(accessor.bytes.as_slice()); stats2d_covar(sketch, &*method) } @@ -1539,28 +1511,28 @@ mod tests { fn tk1d_agg(agg: &str) -> String { format!("SELECT \ {agg}(stats_agg(test_x)), \ - stats_agg(test_x)->toolkit_experimental.{agg}() \ + stats_agg(test_x)->{agg}() \ FROM test_table", agg=agg) } fn tk1d_agg_arg(agg: &str, arg: &str) -> String { format!("SELECT \ {agg}(stats_agg(test_x), '{arg}'), \ - stats_agg(test_x)->toolkit_experimental.{agg}('{arg}') \ + stats_agg(test_x)->{agg}('{arg}') \ FROM test_table", agg=agg, arg=arg) } fn tk2d_agg(agg: &str) -> String { format!("SELECT \ {agg}(stats_agg(test_y, test_x)), \ - stats_agg(test_y, test_x)->toolkit_experimental.{agg}() \ + stats_agg(test_y, test_x)->{agg}() \ FROM test_table", agg=agg) } fn tk2d_agg_arg(agg: &str, arg: &str) -> String { format!("SELECT \ {agg}(stats_agg(test_y, test_x), '{arg}'), \ - stats_agg(test_y, test_x)->toolkit_experimental.{agg}('{arg}') \ + stats_agg(test_y, test_x)->{agg}('{arg}') \ FROM test_table", agg=agg, arg=arg) } diff --git a/extension/src/tdigest.rs b/extension/src/tdigest.rs index 6c64e1d9..cb663fa0 100644 --- a/extension/src/tdigest.rs +++ b/extension/src/tdigest.rs @@ -6,11 +6,14 @@ use serde::{Serialize, Deserialize}; use pgx::*; use crate::{ + accessors::{ + AccessorApproxPercentile, AccessorApproxPercentileRank, AccessorMaxVal, AccessorMean, + AccessorMinVal, AccessorNumVals, + }, aggregate_utils::in_aggregate_context, - ron_inout_funcs, flatten, - palloc::{Internal, InternalAsValue, Inner, ToInternal}, pg_type, - accessors::toolkit_experimental, + palloc::{Inner, Internal, InternalAsValue, ToInternal}, + pg_type, ron_inout_funcs, }; use tdigest::{ @@ -352,7 +355,7 @@ requires = [tdigest_compound_trans, tdigest_compound_final, tdigest_compound_com #[opname(->)] pub fn arrow_tdigest_approx_percentile( sketch: TDigest, - accessor: toolkit_experimental::AccessorApproxPercentile, + accessor: AccessorApproxPercentile, ) -> f64 { tdigest_quantile(accessor.percentile, sketch) } @@ -370,7 +373,7 @@ pub fn tdigest_quantile( #[opname(->)] pub fn arrow_tdigest_approx_rank( sketch: TDigest, - accessor: toolkit_experimental::AccessorApproxPercentileRank, + accessor: AccessorApproxPercentileRank, ) -> f64 { tdigest_quantile_at_value(accessor.value, sketch) } @@ -388,9 +391,8 @@ pub fn tdigest_quantile_at_value( #[opname(->)] pub fn arrow_tdigest_num_vals( sketch: TDigest, - accessor: toolkit_experimental::AccessorNumVals, + _accessor: AccessorNumVals, ) -> f64 { - let _ = accessor; tdigest_count(sketch) } @@ -406,9 +408,8 @@ pub fn tdigest_count( #[opname(->)] pub fn arrow_tdigest_min( sketch: TDigest, - accessor: toolkit_experimental::AccessorMinVal, + _accessor: AccessorMinVal, ) -> f64 { - let _ = accessor; tdigest_min(sketch) } @@ -425,9 +426,8 @@ pub fn tdigest_min( #[opname(->)] pub fn arrow_tdigest_max( sketch: TDigest, - accessor: toolkit_experimental::AccessorMaxVal, + _accessor: AccessorMaxVal, ) -> f64 { - let _ = accessor; tdigest_max(sketch) } @@ -443,9 +443,8 @@ pub fn tdigest_max( #[opname(->)] pub fn arrow_tdigest_mean( sketch: TDigest, - accessor: toolkit_experimental::AccessorMean, + _accessor: AccessorMean, ) -> f64 { - let _ = accessor; tdigest_mean(sketch) } @@ -515,9 +514,9 @@ mod tests { let (min2, max2, count2) = client .select("SELECT \ - tdigest->toolkit_experimental.min_val(), \ - tdigest->toolkit_experimental.max_val(), \ - tdigest->toolkit_experimental.num_vals() \ + tdigest->min_val(), \ + tdigest->max_val(), \ + tdigest->num_vals() \ FROM digest", None, None @@ -532,7 +531,7 @@ mod tests { let (mean, mean2) = client .select("SELECT \ mean(tdigest), \ - tdigest -> toolkit_experimental.mean() + tdigest -> mean() FROM digest", None, None @@ -571,8 +570,8 @@ mod tests { let (est_val2, est_quant2) = client .select( &format!("SELECT - tdigest->toolkit_experimental.approx_percentile({}), \ - tdigest->toolkit_experimental.approx_percentile_rank({}) \ + tdigest->approx_percentile({}), \ + tdigest->approx_percentile_rank({}) \ FROM digest", quantile, value), diff --git a/extension/src/time_vector/pipeline.rs b/extension/src/time_vector/pipeline.rs index cc2a9932..a4c0d6db 100644 --- a/extension/src/time_vector/pipeline.rs +++ b/extension/src/time_vector/pipeline.rs @@ -27,7 +27,7 @@ use crate::serialization::PgProcId; #[pg_schema] pub mod toolkit_experimental { use super::*; - pub(crate) use crate::accessors::toolkit_experimental::AccessorDelta; + pub(crate) use crate::accessors::AccessorDelta; pub use crate::time_vector::Timevector_TSTZ_F64; pub(crate) use lambda::toolkit_experimental::{Lambda, LambdaData}; // TODO once we start stabilizing elements, create a type TimevectorPipeline diff --git a/extension/src/time_vector/pipeline/aggregation.rs b/extension/src/time_vector/pipeline/aggregation.rs index 4b7dfb1a..42036d5d 100644 --- a/extension/src/time_vector/pipeline/aggregation.rs +++ b/extension/src/time_vector/pipeline/aggregation.rs @@ -7,6 +7,7 @@ use counter_agg::CounterSummaryBuilder; use super::*; use crate::{ + accessors::{AccessorAverage, AccessorNumVals, AccessorSum}, build, counter_agg::CounterSummary, hyperloglog::HyperLogLog, @@ -26,7 +27,6 @@ use self::toolkit_experimental::{ #[pg_schema] pub mod toolkit_experimental { use super::*; - pub(crate) use crate::accessors::toolkit_experimental::*; pub(crate) use crate::time_vector::pipeline::UnstableTimevectorPipeline; pg_type! { @@ -188,7 +188,7 @@ ALTER FUNCTION "arrow_run_pipeline_then_stats_agg" SUPPORT toolkit_experimental. schema = "toolkit_experimental" )] pub fn sum_pipeline_element( - accessor: toolkit_experimental::AccessorSum, + accessor: AccessorSum, ) -> toolkit_experimental::PipelineThenSum { let _ = accessor; build! { @@ -201,7 +201,7 @@ pub fn sum_pipeline_element( extension_sql!( r#" - CREATE CAST (toolkit_experimental.AccessorSum AS toolkit_experimental.PipelineThenSum) + CREATE CAST (AccessorSum AS toolkit_experimental.PipelineThenSum) WITH FUNCTION toolkit_experimental.sum_cast AS IMPLICIT; "#, @@ -274,7 +274,7 @@ ALTER FUNCTION "arrow_pipeline_then_sum" SUPPORT toolkit_experimental.pipeline_s #[pg_extern(immutable, parallel_safe, schema = "toolkit_experimental")] pub fn average_pipeline_element( - accessor: toolkit_experimental::AccessorAverage, + accessor: AccessorAverage, ) -> toolkit_experimental::PipelineThenAverage { let _ = accessor; build! { @@ -287,7 +287,7 @@ pub fn average_pipeline_element( extension_sql!( r#" - CREATE CAST (toolkit_experimental.AccessorAverage AS toolkit_experimental.PipelineThenAverage) + CREATE CAST (AccessorAverage AS toolkit_experimental.PipelineThenAverage) WITH FUNCTION toolkit_experimental.average_pipeline_element AS IMPLICIT; "#, @@ -369,7 +369,7 @@ ALTER FUNCTION "arrow_pipeline_then_average" SUPPORT toolkit_experimental.pipeli schema = "toolkit_experimental" )] pub fn num_vals_pipeline_element( - accessor: toolkit_experimental::AccessorNumVals, + accessor: AccessorNumVals, ) -> toolkit_experimental::PipelineThenNumVals { let _ = accessor; build! { @@ -382,7 +382,7 @@ pub fn num_vals_pipeline_element( extension_sql!( r#" - CREATE CAST (toolkit_experimental.AccessorNumVals AS toolkit_experimental.PipelineThenNumVals) + CREATE CAST (AccessorNumVals AS toolkit_experimental.PipelineThenNumVals) WITH FUNCTION toolkit_experimental.num_vals_cast AS IMPLICIT; "#, diff --git a/extension/src/time_vector/pipeline/delta.rs b/extension/src/time_vector/pipeline/delta.rs index efb5d988..5846a499 100644 --- a/extension/src/time_vector/pipeline/delta.rs +++ b/extension/src/time_vector/pipeline/delta.rs @@ -18,7 +18,7 @@ pub fn delta_pipeline_element<'p, 'e>( extension_sql!( r#" - CREATE CAST (toolkit_experimental.AccessorDelta AS toolkit_experimental.UnstableTimevectorPipeline) + CREATE CAST (AccessorDelta AS toolkit_experimental.UnstableTimevectorPipeline) WITH FUNCTION toolkit_experimental.delta_cast AS IMPLICIT; "#, diff --git a/extension/src/time_weighted_average.rs b/extension/src/time_weighted_average.rs index c2a642f9..12139d06 100644 --- a/extension/src/time_weighted_average.rs +++ b/extension/src/time_weighted_average.rs @@ -1,12 +1,15 @@ #![allow(non_camel_case_types)] +use pgx::*; use serde::{Deserialize, Serialize}; use crate::{ - aggregate_utils::in_aggregate_context, flatten, ron_inout_funcs, palloc::{Internal, InternalAsValue, Inner, ToInternal}, pg_type, - accessors::toolkit_experimental, + accessors::AccessorAverage, + aggregate_utils::in_aggregate_context, + flatten, + palloc::{Inner, Internal, InternalAsValue, ToInternal}, + pg_type, ron_inout_funcs, }; -use pgx::*; use tspoint::TSPoint; @@ -343,9 +346,8 @@ requires = [time_weight_trans, time_weight_final, time_weight_combine, time_weig #[opname(->)] pub fn arrow_time_weighted_average_average( sketch: Option, - accessor: toolkit_experimental::AccessorAverage, + _accessor: AccessorAverage, ) -> Option { - let _ = accessor; time_weighted_average_average(sketch) } @@ -437,7 +439,7 @@ mod tests { // expected =(15 +15 +15 +15 + 20*4 + 20*2 +15*.5 + 25*9.5) / 20 = 21.25 just taking the midpoints between each point and multiplying by minutes and dividing by total assert!((select_one!(client, stmt, f64) - 21.25).abs() < f64::EPSILON); let stmt = "SELECT time_weight('Linear', ts, val) \ - ->toolkit_experimental.average() \ + ->average() \ FROM test"; // arrow syntax should be the same assert!((select_one!(client, stmt, f64) - 21.25).abs() < f64::EPSILON); diff --git a/extension/src/uddsketch.rs b/extension/src/uddsketch.rs index cff6aef6..c92dfa3f 100644 --- a/extension/src/uddsketch.rs +++ b/extension/src/uddsketch.rs @@ -6,10 +6,14 @@ use encodings::{delta, prefix_varint}; use uddsketch::{SketchHashKey, UDDSketch as UddSketchInternal}; use crate::{ + accessors::{ + AccessorApproxPercentile, AccessorApproxPercentileRank, AccessorError, AccessorMean, + AccessorNumVals, + }, aggregate_utils::in_aggregate_context, flatten, - palloc::{Internal, InternalAsValue, Inner, ToInternal}, pg_type, - accessors::toolkit_experimental, + palloc::{Inner, Internal, InternalAsValue, ToInternal}, + pg_type, }; // PG function for adding values to a sketch. @@ -528,7 +532,7 @@ requires = [uddsketch_compound_trans, uddsketch_final, uddsketch_combine, uddske #[opname(->)] pub fn arrow_uddsketch_approx_percentile( sketch: UddSketch, - accessor: toolkit_experimental::AccessorApproxPercentile, + accessor: AccessorApproxPercentile, ) -> f64 { uddsketch_approx_percentile(accessor.percentile, sketch) } @@ -552,7 +556,7 @@ pub fn uddsketch_approx_percentile( #[opname(->)] pub fn arrow_uddsketch_approx_rank( sketch: UddSketch, - accessor: toolkit_experimental::AccessorApproxPercentileRank, + accessor: AccessorApproxPercentileRank, ) -> f64 { uddsketch_approx_percentile_rank(accessor.value, sketch) } @@ -575,9 +579,8 @@ pub fn uddsketch_approx_percentile_rank( #[opname(->)] pub fn arrow_uddsketch_num_vals( sketch: UddSketch, - accessor: toolkit_experimental::AccessorNumVals, + _accessor: AccessorNumVals, ) -> f64 { - let _ = accessor; uddsketch_num_vals(sketch) } @@ -594,9 +597,8 @@ pub fn uddsketch_num_vals( #[opname(->)] pub fn arrow_uddsketch_mean( sketch: UddSketch, - accessor: toolkit_experimental::AccessorMean, + _accessor: AccessorMean, ) -> f64 { - let _ = accessor; uddsketch_mean(sketch) } @@ -618,9 +620,8 @@ pub fn uddsketch_mean( #[opname(->)] pub fn arrow_uddsketch_error( sketch: UddSketch, - accessor: toolkit_experimental::AccessorError, + _accessor: AccessorError, ) -> f64 { - let _ = accessor; uddsketch_error(sketch) } @@ -684,8 +685,8 @@ mod tests { let (mean2, count2) = client .select("SELECT \ - uddsketch -> toolkit_experimental.mean(), \ - uddsketch -> toolkit_experimental.num_vals() \ + uddsketch -> mean(), \ + uddsketch -> num_vals() \ FROM sketch", None, None) .first() .get_two::(); @@ -695,7 +696,7 @@ mod tests { let (error, error2) = client .select("SELECT \ error(uddsketch), \ - uddsketch -> toolkit_experimental.error() \ + uddsketch -> error() \ FROM sketch", None, None) .first() .get_two::(); @@ -727,8 +728,8 @@ mod tests { let (est_val2, est_quant2) = client .select( &format!("SELECT \ - uddsketch->toolkit_experimental.approx_percentile({}), \ - uddsketch->toolkit_experimental.approx_percentile_rank({}) \ + uddsketch->approx_percentile({}), \ + uddsketch->approx_percentile_rank({}) \ FROM sketch", approx_percentile, value), None, None) .first() .get_two::();