|
16 | 16 | // under the License. |
17 | 17 |
|
18 | 18 | use std::any::Any; |
19 | | -use std::sync::{Arc, OnceLock}; |
| 19 | +use std::sync::Arc; |
20 | 20 |
|
21 | 21 | use crate::utils::make_scalar_function; |
22 | 22 |
|
23 | 23 | use arrow::array::{ArrayRef, AsArray, Float32Array, Float64Array}; |
24 | 24 | use arrow::datatypes::DataType::{Float32, Float64}; |
25 | 25 | use arrow::datatypes::{DataType, Float32Type, Float64Type}; |
26 | 26 | use datafusion_common::{exec_err, DataFusionError, Result}; |
27 | | -use datafusion_expr::scalar_doc_sections::DOC_SECTION_MATH; |
28 | 27 | use datafusion_expr::TypeSignature::Exact; |
29 | 28 | use datafusion_expr::{ |
30 | 29 | ColumnarValue, Documentation, ScalarUDFImpl, Signature, Volatility, |
31 | 30 | }; |
| 31 | +use datafusion_macros::user_doc; |
32 | 32 |
|
| 33 | +#[user_doc( |
| 34 | + doc_section(label = "Math Functions"), |
| 35 | + description = r#"Returns the first argument if it's not _NaN_. |
| 36 | +Returns the second argument otherwise."#, |
| 37 | + syntax_example = "nanvl(expression_x, expression_y)", |
| 38 | + argument( |
| 39 | + name = "expression_x", |
| 40 | + description = "Numeric expression to return if it's not _NaN_. Can be a constant, column, or function, and any combination of arithmetic operators." |
| 41 | + ), |
| 42 | + argument( |
| 43 | + name = "expression_y", |
| 44 | + description = "Numeric expression to return if the first expression is _NaN_. Can be a constant, column, or function, and any combination of arithmetic operators." |
| 45 | + ) |
| 46 | +)] |
33 | 47 | #[derive(Debug)] |
34 | 48 | pub struct NanvlFunc { |
35 | 49 | signature: Signature, |
@@ -82,26 +96,10 @@ impl ScalarUDFImpl for NanvlFunc { |
82 | 96 | } |
83 | 97 |
|
84 | 98 | fn documentation(&self) -> Option<&Documentation> { |
85 | | - Some(get_nanvl_doc()) |
| 99 | + self.doc() |
86 | 100 | } |
87 | 101 | } |
88 | 102 |
|
89 | | -static DOCUMENTATION: OnceLock<Documentation> = OnceLock::new(); |
90 | | - |
91 | | -fn get_nanvl_doc() -> &'static Documentation { |
92 | | - DOCUMENTATION.get_or_init(|| { |
93 | | - Documentation::builder( |
94 | | - DOC_SECTION_MATH, |
95 | | - r#"Returns the first argument if it's not _NaN_. |
96 | | -Returns the second argument otherwise."#, |
97 | | - |
98 | | - "nanvl(expression_x, expression_y)") |
99 | | - .with_argument("expression_x", "Numeric expression to return if it's not _NaN_. Can be a constant, column, or function, and any combination of arithmetic operators.") |
100 | | - .with_argument("expression_y", "Numeric expression to return if the first expression is _NaN_. Can be a constant, column, or function, and any combination of arithmetic operators.") |
101 | | - .build() |
102 | | - }) |
103 | | -} |
104 | | - |
105 | 103 | /// Nanvl SQL function |
106 | 104 | fn nanvl(args: &[ArrayRef]) -> Result<ArrayRef> { |
107 | 105 | match args[0].data_type() { |
|
0 commit comments