Skip to content

Update the user_doc() macro to support multiple alternative syntaxes #13944

@alamb

Description

@alamb

Originally posted by @Chen-Yuan-Lai in #13924 (comment)

The idea is to migrate the trim function to use the doc macros

However, when @Chen-Yuan-Lai tried to do so in #13924 we found that the second alternative_syntax was ignored

Here is the rust change:

#[user_doc(
    doc_section(label = "String Functions"),
    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.",
    syntax_example = "btrim(str[, trim_str])",
    alternative_syntax = "trim(BOTH trim_str FROM str)",
    alternative_syntax = "trim(trim_str FROM str)",
    sql_example = r#"```sql
> select btrim('__datafusion____', '_');
+-------------------------------------------+
| btrim(Utf8("__datafusion____"),Utf8("_")) |
+-------------------------------------------+
| datafusion                                |
+-------------------------------------------+
```"#,
    standard_argument(name = "str", prefix = "String"),
    argument(
        name = "trim_str",
        description = "String expression to operate on. Can be a constant, column, or function, and any combination of operators. _Default is whitespace characters._"
    ),
    related_udf(name = "ltrim"),
    related_udf(name = "rtrim")
)]
#[derive(Debug)]
pub struct BTrimFunc {
    signature: Signature,

Then regenerate the documentation:

./dev/update_function_docs.sh

And you'll see that the second syntax is gone

#### Alternative Syntax

-```sql
-trim(BOTH trim_str FROM str)
-```

```sql
trim(trim_str FROM str)

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions