|
15 | 15 | // specific language governing permissions and limitations
|
16 | 16 | // under the License.
|
17 | 17 |
|
| 18 | +use crate::string::common::*; |
| 19 | +use crate::utils::{make_scalar_function, utf8_to_str_type}; |
18 | 20 | use arrow::array::{ArrayRef, OffsetSizeTrait};
|
19 | 21 | use arrow::datatypes::DataType;
|
20 |
| -use std::any::Any; |
21 |
| - |
22 | 22 | use datafusion_common::{exec_err, Result};
|
23 | 23 | use datafusion_expr::function::Hint;
|
| 24 | +use datafusion_expr::scalar_doc_sections::DOC_SECTION_STRING; |
24 | 25 | use datafusion_expr::TypeSignature::*;
|
25 |
| -use datafusion_expr::{ColumnarValue, Volatility}; |
| 26 | +use datafusion_expr::{ColumnarValue, Documentation, Volatility}; |
26 | 27 | use datafusion_expr::{ScalarUDFImpl, Signature};
|
27 |
| - |
28 |
| -use crate::string::common::*; |
29 |
| -use crate::utils::{make_scalar_function, utf8_to_str_type}; |
| 28 | +use std::any::Any; |
| 29 | +use std::sync::OnceLock; |
30 | 30 |
|
31 | 31 | /// Returns the longest string with leading and trailing characters removed. If the characters are not specified, whitespace is removed.
|
32 | 32 | /// btrim('xyxtrimyyx', 'xyz') = 'trim'
|
@@ -109,6 +109,35 @@ impl ScalarUDFImpl for BTrimFunc {
|
109 | 109 | fn aliases(&self) -> &[String] {
|
110 | 110 | &self.aliases
|
111 | 111 | }
|
| 112 | + |
| 113 | + fn documentation(&self) -> Option<&Documentation> { |
| 114 | + Some(get_btrim_doc()) |
| 115 | + } |
| 116 | +} |
| 117 | + |
| 118 | +static DOCUMENTATION: OnceLock<Documentation> = OnceLock::new(); |
| 119 | + |
| 120 | +fn get_btrim_doc() -> &'static Documentation { |
| 121 | + DOCUMENTATION.get_or_init(|| { |
| 122 | + Documentation::builder() |
| 123 | + .with_doc_section(DOC_SECTION_STRING) |
| 124 | + .with_description("Trims the specified trim string from the start and end of a string. If no trim string is provided, all whitespace is removed from the start and end of the input string.") |
| 125 | + .with_syntax_example("btrim(str[, trim_str])") |
| 126 | + .with_sql_example(r#"```sql |
| 127 | +> select btrim('__datafusion____', '_'); |
| 128 | ++-------------------------------------------+ |
| 129 | +| btrim(Utf8("__datafusion____"),Utf8("_")) | |
| 130 | ++-------------------------------------------+ |
| 131 | +| datafusion | |
| 132 | ++-------------------------------------------+ |
| 133 | +```"#) |
| 134 | + .with_standard_argument("str", "String") |
| 135 | + .with_argument("trim_str", "String expression to operate on. Can be a constant, column, or function, and any combination of operators. _Default is whitespace characters._") |
| 136 | + .with_related_udf("ltrim") |
| 137 | + .with_related_udf("rtrim") |
| 138 | + .build() |
| 139 | + .unwrap() |
| 140 | + }) |
112 | 141 | }
|
113 | 142 |
|
114 | 143 | #[cfg(test)]
|
|
0 commit comments