Apache DataFusion SQL Query Engine
Add alternative syntax for extract, trim and substring. (#13143)
Bruce Ritchiefeeb32ab090f
diff --git a/datafusion/functions/src/datetime/date_part.rs b/datafusion/functions/src/datetime/date_part.rsindex 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.rsindex 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.rsindex 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.rsindex 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.rsindex 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.mdindex 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