This is an automated email from the ASF dual-hosted git repository.

alamb pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/datafusion.git


The following commit(s) were added to refs/heads/main by this push:
     new feeb32ab09 Add alternative syntax for extract, trim and substring. 
(#13143)
feeb32ab09 is described below

commit feeb32ab090fda25b9c0aca8b86cf10a5b91acaa
Author: Bruce Ritchie <[email protected]>
AuthorDate: Tue Oct 29 07:22:57 2024 -0400

    Add alternative syntax for extract, trim and substring. (#13143)
---
 datafusion/functions/src/datetime/date_part.rs     |  1 +
 datafusion/functions/src/string/btrim.rs           |  2 ++
 datafusion/functions/src/string/ltrim.rs           |  1 +
 datafusion/functions/src/string/rtrim.rs           |  1 +
 datafusion/functions/src/unicode/substr.rs         |  1 +
 docs/source/user-guide/sql/scalar_functions_new.md | 34 ++++++++++++++++++++++
 6 files changed, 40 insertions(+)

diff --git a/datafusion/functions/src/datetime/date_part.rs 
b/datafusion/functions/src/datetime/date_part.rs
index 3fefa50513..01e094bc4e 100644
--- a/datafusion/functions/src/datetime/date_part.rs
+++ b/datafusion/functions/src/datetime/date_part.rs
@@ -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()
     })
diff --git a/datafusion/functions/src/string/btrim.rs 
b/datafusion/functions/src/string/btrim.rs
index f689f27d9d..e215b18d9c 100644
--- a/datafusion/functions/src/string/btrim.rs
+++ b/datafusion/functions/src/string/btrim.rs
@@ -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)")
             .with_related_udf("ltrim")
             .with_related_udf("rtrim")
             .build()
diff --git a/datafusion/functions/src/string/ltrim.rs 
b/datafusion/functions/src/string/ltrim.rs
index 91809d6916..0b4c197646 100644
--- a/datafusion/functions/src/string/ltrim.rs
+++ b/datafusion/functions/src/string/ltrim.rs
@@ -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()
diff --git a/datafusion/functions/src/string/rtrim.rs 
b/datafusion/functions/src/string/rtrim.rs
index 06c8a85c38..e934147efb 100644
--- a/datafusion/functions/src/string/rtrim.rs
+++ b/datafusion/functions/src/string/rtrim.rs
@@ -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()
diff --git a/datafusion/functions/src/unicode/substr.rs 
b/datafusion/functions/src/unicode/substr.rs
index 5a8c250090..edfe57210b 100644
--- a/datafusion/functions/src/unicode/substr.rs
+++ b/datafusion/functions/src/unicode/substr.rs
@@ -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()
     })
diff --git a/docs/source/user-guide/sql/scalar_functions_new.md 
b/docs/source/user-guide/sql/scalar_functions_new.md
index 6031a68d40..56173b97b4 100644
--- a/docs/source/user-guide/sql/scalar_functions_new.md
+++ b/docs/source/user-guide/sql/scalar_functions_new.md
@@ -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
@@ -1191,6 +1201,12 @@ ltrim(str[, trim_str])
 +-------------------------------------------+
 ```
 
+#### Alternative Syntax
+
+```sql
+trim(LEADING trim_str FROM str)
+```
+
 **Related functions**:
 
 - [btrim](#btrim)
@@ -1387,6 +1403,12 @@ rtrim(str[, trim_str])
 +-------------------------------------------+
 ```
 
+#### Alternative Syntax
+
+```sql
+trim(TRAILING trim_str FROM str)
+```
+
 **Related functions**:
 
 - [btrim](#btrim)
@@ -1501,6 +1523,12 @@ substr(str, start_pos[, length])
 +----------------------------------------------+
 ```
 
+#### Alternative Syntax
+
+```sql
+substring(str from start_pos for length)
+```
+
 #### Aliases
 
 - substring
@@ -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


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to