|
18 | 18 | //! [`VarianceSample`]: variance sample aggregations.
|
19 | 19 | //! [`VariancePopulation`]: variance population aggregations.
|
20 | 20 |
|
21 |
| -use std::{fmt::Debug, sync::Arc}; |
22 |
| - |
23 | 21 | use arrow::{
|
24 | 22 | array::{Array, ArrayRef, BooleanArray, Float64Array, UInt64Array},
|
25 | 23 | buffer::NullBuffer,
|
26 | 24 | compute::kernels::cast,
|
27 | 25 | datatypes::{DataType, Field},
|
28 | 26 | };
|
| 27 | +use std::sync::OnceLock; |
| 28 | +use std::{fmt::Debug, sync::Arc}; |
29 | 29 |
|
30 | 30 | use datafusion_common::{
|
31 | 31 | downcast_value, not_impl_err, plan_err, DataFusionError, Result, ScalarValue,
|
32 | 32 | };
|
| 33 | +use datafusion_expr::aggregate_doc_sections::DOC_SECTION_GENERAL; |
33 | 34 | use datafusion_expr::{
|
34 | 35 | function::{AccumulatorArgs, StateFieldsArgs},
|
35 | 36 | utils::format_state_name,
|
36 |
| - Accumulator, AggregateUDFImpl, GroupsAccumulator, Signature, Volatility, |
| 37 | + Accumulator, AggregateUDFImpl, Documentation, GroupsAccumulator, Signature, |
| 38 | + Volatility, |
37 | 39 | };
|
38 | 40 | use datafusion_functions_aggregate_common::{
|
39 | 41 | aggregate::groups_accumulator::accumulate::accumulate, stats::StatsType,
|
@@ -135,6 +137,26 @@ impl AggregateUDFImpl for VarianceSample {
|
135 | 137 | ) -> Result<Box<dyn GroupsAccumulator>> {
|
136 | 138 | Ok(Box::new(VarianceGroupsAccumulator::new(StatsType::Sample)))
|
137 | 139 | }
|
| 140 | + |
| 141 | + fn documentation(&self) -> Option<&Documentation> { |
| 142 | + Some(get_variance_sample_doc()) |
| 143 | + } |
| 144 | +} |
| 145 | + |
| 146 | +static VARIANCE_SAMPLE_DOC: OnceLock<Documentation> = OnceLock::new(); |
| 147 | + |
| 148 | +fn get_variance_sample_doc() -> &'static Documentation { |
| 149 | + VARIANCE_SAMPLE_DOC.get_or_init(|| { |
| 150 | + Documentation::builder() |
| 151 | + .with_doc_section(DOC_SECTION_GENERAL) |
| 152 | + .with_description( |
| 153 | + "Returns the statistical sample variance of a set of numbers.", |
| 154 | + ) |
| 155 | + .with_syntax_example("var(expression)") |
| 156 | + .with_expression_argument() |
| 157 | + .build() |
| 158 | + .unwrap() |
| 159 | + }) |
138 | 160 | }
|
139 | 161 |
|
140 | 162 | pub struct VariancePopulation {
|
@@ -222,6 +244,25 @@ impl AggregateUDFImpl for VariancePopulation {
|
222 | 244 | StatsType::Population,
|
223 | 245 | )))
|
224 | 246 | }
|
| 247 | + fn documentation(&self) -> Option<&Documentation> { |
| 248 | + Some(get_variance_population_doc()) |
| 249 | + } |
| 250 | +} |
| 251 | + |
| 252 | +static VARIANCE_POPULATION_DOC: OnceLock<Documentation> = OnceLock::new(); |
| 253 | + |
| 254 | +fn get_variance_population_doc() -> &'static Documentation { |
| 255 | + VARIANCE_POPULATION_DOC.get_or_init(|| { |
| 256 | + Documentation::builder() |
| 257 | + .with_doc_section(DOC_SECTION_GENERAL) |
| 258 | + .with_description( |
| 259 | + "Returns the statistical population variance of a set of numbers.", |
| 260 | + ) |
| 261 | + .with_syntax_example("var_pop(expression)") |
| 262 | + .with_expression_argument() |
| 263 | + .build() |
| 264 | + .unwrap() |
| 265 | + }) |
225 | 266 | }
|
226 | 267 |
|
227 | 268 | /// An accumulator to compute variance
|
|
0 commit comments