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

docs: Add alternative syntax for extract, trim and substring. #13143

Merged
merged 1 commit into from
Oct 29, 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
1 change: 1 addition & 0 deletions datafusion/functions/src/datetime/date_part.rs
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@ fn get_date_part_doc() -> &'static Documentation {
"expression",
"Time expression to operate on. Can be a constant, column, or function.",
)
.with_alternative_syntax("extract(field FROM source)")
.build()
.unwrap()
})
Expand Down
2 changes: 2 additions & 0 deletions datafusion/functions/src/string/btrim.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@ fn get_btrim_doc() -> &'static Documentation {
```"#)
.with_standard_argument("str", Some("String"))
.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._")
.with_alternative_syntax("trim(BOTH trim_str FROM str)")
.with_alternative_syntax("trim(trim_str FROM str)")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this deserve new SLT test cases?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I grabbed the syntax from an slt test :)

.with_related_udf("ltrim")
.with_related_udf("rtrim")
.build()
Expand Down
1 change: 1 addition & 0 deletions datafusion/functions/src/string/ltrim.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ fn get_ltrim_doc() -> &'static Documentation {
```"#)
.with_standard_argument("str", Some("String"))
.with_argument("trim_str", "String expression to trim from the beginning of the input string. Can be a constant, column, or function, and any combination of arithmetic operators. _Default is whitespace characters._")
.with_alternative_syntax("trim(LEADING trim_str FROM str)")
.with_related_udf("btrim")
.with_related_udf("rtrim")
.build()
Expand Down
1 change: 1 addition & 0 deletions datafusion/functions/src/string/rtrim.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ fn get_rtrim_doc() -> &'static Documentation {
```"#)
.with_standard_argument("str", Some("String"))
.with_argument("trim_str", "String expression to trim from the end of the input string. Can be a constant, column, or function, and any combination of arithmetic operators. _Default is whitespace characters._")
.with_alternative_syntax("trim(TRAILING trim_str FROM str)")
.with_related_udf("btrim")
.with_related_udf("ltrim")
.build()
Expand Down
1 change: 1 addition & 0 deletions datafusion/functions/src/unicode/substr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ fn get_substr_doc() -> &'static Documentation {
.with_standard_argument("str", Some("String"))
.with_argument("start_pos", "Character position to start the substring at. The first character in the string has a position of 1.")
.with_argument("length", "Number of characters to extract. If not specified, returns the rest of the string after the start position.")
.with_alternative_syntax("substring(str from start_pos for length)")
.build()
.unwrap()
})
Expand Down
34 changes: 34 additions & 0 deletions docs/source/user-guide/sql/scalar_functions_new.md
Original file line number Diff line number Diff line change
Expand Up @@ -808,6 +808,16 @@ btrim(str[, trim_str])
+-------------------------------------------+
```

#### Alternative Syntax

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

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

#### Aliases

- trim
Expand Down Expand Up @@ -1191,6 +1201,12 @@ ltrim(str[, trim_str])
+-------------------------------------------+
```

#### Alternative Syntax

```sql
trim(LEADING trim_str FROM str)
```

**Related functions**:

- [btrim](#btrim)
Expand Down Expand Up @@ -1387,6 +1403,12 @@ rtrim(str[, trim_str])
+-------------------------------------------+
```

#### Alternative Syntax

```sql
trim(TRAILING trim_str FROM str)
```

**Related functions**:

- [btrim](#btrim)
Expand Down Expand Up @@ -1501,6 +1523,12 @@ substr(str, start_pos[, length])
+----------------------------------------------+
```

#### Alternative Syntax

```sql
substring(str from start_pos for length)
```

#### Aliases

- substring
Expand Down Expand Up @@ -1965,6 +1993,12 @@ date_part(part, expression)

- **expression**: Time expression to operate on. Can be a constant, column, or function.

#### Alternative Syntax

```sql
extract(field FROM source)
```

#### Aliases

- datepart
Expand Down