Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor: Add documentation for cot #13069

Merged
merged 3 commits into from
Oct 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 22 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,10 @@ 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