Skip to content

Commit

Permalink
Add documentation for cot
Browse files Browse the repository at this point in the history
  • Loading branch information
alamb committed Oct 22, 2024
1 parent cf60da9 commit d7dbf5f
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 4 deletions.
27 changes: 23 additions & 4 deletions datafusion/functions/src/math/cot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,18 @@
// under the License.

use std::any::Any;
use std::sync::Arc;
use std::sync::{Arc, OnceLock};

use arrow::array::{ArrayRef, AsArray};
use arrow::datatypes::DataType::{Float32, Float64};
use arrow::datatypes::{DataType, Float32Type, Float64Type};

use crate::utils::make_scalar_function;
use datafusion_common::{exec_err, Result};
use datafusion_expr::ColumnarValue;
use datafusion_expr::scalar_doc_sections::DOC_SECTION_MATH;
use datafusion_expr::{ColumnarValue, Documentation};
use datafusion_expr::{ScalarUDFImpl, Signature, Volatility};

use crate::utils::make_scalar_function;

#[derive(Debug)]
pub struct CotFunc {
signature: Signature,
Expand All @@ -39,6 +39,20 @@ impl Default for CotFunc {
}
}

static DOCUMENTATION: OnceLock<Documentation> = OnceLock::new();

fn get_cot_doc() -> &'static Documentation {
DOCUMENTATION.get_or_init(|| {
Documentation::builder()
.with_doc_section(DOC_SECTION_MATH)
.with_description("Returns the cotangent of a number.")
.with_syntax_example(r#"cot(numeric_expression)"#)
.with_standard_argument("numeric_expression", Some("Numeric"))
.build()
.unwrap()
})
}

impl CotFunc {
pub fn new() -> Self {
use DataType::*;
Expand Down Expand Up @@ -77,6 +91,11 @@ impl ScalarUDFImpl for CotFunc {
}
}

fn documentation(&self) -> Option<&Documentation> {
Some(get_cot_doc())
}


fn invoke(&self, args: &[ColumnarValue]) -> Result<ColumnarValue> {
make_scalar_function(cot, vec![])(args)
}
Expand Down
13 changes: 13 additions & 0 deletions docs/source/user-guide/sql/scalar_functions_new.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ the rest of the documentation.
- [ceil](#ceil)
- [cos](#cos)
- [cosh](#cosh)
- [cot](#cot)
- [degrees](#degrees)
- [exp](#exp)
- [factorial](#factorial)
Expand Down Expand Up @@ -221,6 +222,18 @@ cosh(numeric_expression)

- **numeric_expression**: Numeric expression to operate on. Can be a constant, column, or function, and any combination of operators.

### `cot`

Returns the cotangent of a number.

```
cot(numeric_expression)
```

#### Arguments

- **numeric_expression**: Numeric expression to operate on. Can be a constant, column, or function, and any combination of operators.

### `degrees`

Converts radians to degrees.
Expand Down

0 comments on commit d7dbf5f

Please sign in to comment.