diff --git a/Changelog.md b/Changelog.md index 5168d039..cbcbf1be 100644 --- a/Changelog.md +++ b/Changelog.md @@ -15,6 +15,7 @@ This changelog should be updated as part of a PR if the work is worth noting (mo #### Stabilized features - [#741](https://github.com/timescale/timescaledb-toolkit/pull/741): Stabilize `approx_count_distinct` +- [#748](https://github.com/timescale/timescaledb-toolkit/pull/748): Stabilize `approx_percentile_array` #### Other notable changes - [#743](https://github.com/timescale/timescaledb-toolkit/pull/743): Remove support for direct upgrades from toolkit versions more than 1 year old. Toolkit versions 1.4.x and 1.5.x will have to upgrade to an intermediate version before upgrading to 1.16.0. diff --git a/extension/src/accessors.rs b/extension/src/accessors.rs index cfbf0417..473b677f 100644 --- a/extension/src/accessors.rs +++ b/extension/src/accessors.rs @@ -578,28 +578,24 @@ pub fn accessor_integral(unit: default!(&str, "'second'")) -> AccessorIntegral<' } } } -#[pg_schema] -pub mod toolkit_experimental { - use super::*; - - pg_type! { - #[derive(Debug)] - struct AccessorPercentileArray<'input> { - len: u64, - percentile: [f64; self.len], - } + +pg_type! { + #[derive(Debug)] + struct AccessorPercentileArray<'input> { + len: u64, + percentile: [f64; self.len], } +} - ron_inout_funcs!(AccessorPercentileArray); +ron_inout_funcs!(AccessorPercentileArray); - #[pg_extern(immutable, name = "approx_percentiles")] - pub fn accessor_percentiles(unit: Vec) -> AccessorPercentileArray<'static> { - unsafe { - flatten! { - AccessorPercentileArray{ - len: unit.len().try_into().unwrap(), - percentile: unit.into(), - } +#[pg_extern(immutable, name = "approx_percentiles")] +pub fn accessor_percentiles(unit: Vec) -> AccessorPercentileArray<'static> { + unsafe { + flatten! { + AccessorPercentileArray{ + len: unit.len().try_into().unwrap(), + percentile: unit.into(), } } } diff --git a/extension/src/stabilization_info.rs b/extension/src/stabilization_info.rs index 5e6d6cea..939fe2d4 100644 --- a/extension/src/stabilization_info.rs +++ b/extension/src/stabilization_info.rs @@ -29,6 +29,9 @@ crate::functions_stabilized_at! { num_live_ranges(heartbeatagg), trim_to(heartbeatagg,timestamp with time zone,interval), trim_to(timestamp with time zone,interval), + accessorpercentilearray_in(cstring), + accessorpercentilearray_out(accessorpercentilearray), + arrow_uddsketch_approx_percentile_array(uddsketch,accessorpercentilearray), } "1.15.0" => { arrow_counter_interpolated_delta(countersummary,counterinterpolateddeltaaccessor), @@ -692,6 +695,7 @@ crate::types_stabilized_at! { accessornumgaps, accessornumliveranges, heartbeattrimtoaccessor, + accessorpercentilearray } "1.15.0" => { counterinterpolateddeltaaccessor, @@ -821,6 +825,7 @@ crate::operators_stabilized_at! { "->"(heartbeatagg,accessornumgaps), "->"(heartbeatagg,accessornumliveranges), "->"(heartbeatagg,heartbeattrimtoaccessor), + "->"(uddsketch,accessorpercentilearray), } "1.15.0" => { "->"(countersummary,counterinterpolateddeltaaccessor), diff --git a/extension/src/stabilization_tests.rs b/extension/src/stabilization_tests.rs index c66a03ab..2b414280 100644 --- a/extension/src/stabilization_tests.rs +++ b/extension/src/stabilization_tests.rs @@ -91,6 +91,13 @@ mod tests { return None; } + // Hack to fix the function macro's inability to handle [] in the type double precision[]. + if function == "approx_percentile_array(double precision[],uddsketch)" + || function == "approx_percentiles(double precision[])" + { + return None; + } + return Some(val); } diff --git a/extension/src/uddsketch.rs b/extension/src/uddsketch.rs index f0372734..18ca590d 100644 --- a/extension/src/uddsketch.rs +++ b/extension/src/uddsketch.rs @@ -6,8 +6,8 @@ use uddsketch::{SketchHashKey, UDDSketch as UddSketchInternal}; use crate::{ accessors::{ - toolkit_experimental, AccessorApproxPercentile, AccessorApproxPercentileRank, - AccessorError, AccessorMean, AccessorNumVals, + AccessorApproxPercentile, AccessorApproxPercentileRank, AccessorError, AccessorMean, + AccessorNumVals, AccessorPercentileArray, }, aggregate_utils::in_aggregate_context, flatten, @@ -585,17 +585,13 @@ pub fn uddsketch_approx_percentile<'a>(percentile: f64, sketch: UddSketch<'a>) - #[opname(->)] pub fn arrow_uddsketch_approx_percentile_array<'a>( sketch: UddSketch<'a>, - percentiles: toolkit_experimental::AccessorPercentileArray<'a>, + percentiles: AccessorPercentileArray<'a>, ) -> Vec { approx_percentile_slice(percentiles.percentile.as_slice(), sketch) } // Approximate the value at the given approx_percentile (0.0-1.0) for each entry in an array -#[pg_extern( - immutable, - schema = "toolkit_experimental", - name = "approx_percentile_array" -)] +#[pg_extern(immutable, name = "approx_percentile_array")] pub fn uddsketch_approx_percentile_array<'a>( percentiles: Vec, sketch: UddSketch<'a>, @@ -1047,7 +1043,7 @@ mod tests { let (value, error) = client .update( "SELECT \ - toolkit_experimental.approx_percentile_array(array[0.9,0.5,0.2], approx), \ + approx_percentile_array(array[0.9,0.5,0.2], approx), \ error(approx) \ FROM uddsketch_test", None, @@ -1061,7 +1057,7 @@ mod tests { let (test_value, test_error) = client .update( "SELECT \ - toolkit_experimental.approx_percentile_array(array[0.9,0.5,0.2], approx), \ + approx_percentile_array(array[0.9,0.5,0.2], approx), \ error(approx) \ FROM percentile_agg", None, @@ -1134,7 +1130,7 @@ mod tests { let (value, error) = client .update( "SELECT \ - toolkit_experimental.approx_percentile_array(array[0.9,0.5,0.2], approx), \ + approx_percentile_array(array[0.9,0.5,0.2], approx), \ error(approx) \ FROM uddsketch_test", None, @@ -1147,7 +1143,7 @@ mod tests { let (test_value_arrow, test_error_arrow) = client .update( - "SELECT approx->toolkit_experimental.approx_percentiles(array[0.9,0.5,0.2]), \ + "SELECT approx->approx_percentiles(array[0.9,0.5,0.2]), \ error(approx) \ FROM uddsketch_test", None,