Skip to content

Commit a0588cc

Browse files
authored
[docs]: added alternative_syntax function for docs (#13140)
* Add alternative syntax function. * fmt check
1 parent e22d231 commit a0588cc

File tree

4 files changed

+27
-0
lines changed

4 files changed

+27
-0
lines changed

datafusion/core/src/bin/print_functions_docs.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,13 @@ fn print_docs(
195195
);
196196
}
197197

198+
if let Some(alt_syntax) = &documentation.alternative_syntax {
199+
let _ = writeln!(docs, "#### Alternative Syntax\n");
200+
for syntax in alt_syntax {
201+
let _ = writeln!(docs, "```sql\n{}\n```", syntax);
202+
}
203+
}
204+
198205
// next, aliases
199206
if !f.get_aliases().is_empty() {
200207
let _ = writeln!(docs, "#### Aliases");

datafusion/expr/src/udf_docs.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ pub struct Documentation {
4747
/// Left member of a pair is the argument name, right is a
4848
/// description for the argument
4949
pub arguments: Option<Vec<(String, String)>>,
50+
/// A list of alternative syntax examples for a function
51+
pub alternative_syntax: Option<Vec<String>>,
5052
/// Related functions if any. Values should match the related
5153
/// udf's name exactly. Related udf's must be of the same
5254
/// UDF type (scalar, aggregate or window) for proper linking to
@@ -96,6 +98,7 @@ pub struct DocumentationBuilder {
9698
pub syntax_example: Option<String>,
9799
pub sql_example: Option<String>,
98100
pub arguments: Option<Vec<(String, String)>>,
101+
pub alternative_syntax: Option<Vec<String>>,
99102
pub related_udfs: Option<Vec<String>>,
100103
}
101104

@@ -107,6 +110,7 @@ impl DocumentationBuilder {
107110
syntax_example: None,
108111
sql_example: None,
109112
arguments: None,
113+
alternative_syntax: None,
110114
related_udfs: None,
111115
}
112116
}
@@ -172,6 +176,13 @@ impl DocumentationBuilder {
172176
self.with_argument(arg_name, description)
173177
}
174178

179+
pub fn with_alternative_syntax(mut self, syntax_name: impl Into<String>) -> Self {
180+
let mut alternative_syntax_array = self.alternative_syntax.unwrap_or_default();
181+
alternative_syntax_array.push(syntax_name.into());
182+
self.alternative_syntax = Some(alternative_syntax_array);
183+
self
184+
}
185+
175186
pub fn with_related_udf(mut self, related_udf: impl Into<String>) -> Self {
176187
let mut related = self.related_udfs.unwrap_or_default();
177188
related.push(related_udf.into());
@@ -186,6 +197,7 @@ impl DocumentationBuilder {
186197
syntax_example,
187198
sql_example,
188199
arguments,
200+
alternative_syntax,
189201
related_udfs,
190202
} = self;
191203

@@ -205,6 +217,7 @@ impl DocumentationBuilder {
205217
syntax_example: syntax_example.unwrap(),
206218
sql_example,
207219
arguments,
220+
alternative_syntax,
208221
related_udfs,
209222
})
210223
}

datafusion/functions/src/unicode/strpos.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ fn get_strpos_doc() -> &'static Documentation {
9797
```"#)
9898
.with_standard_argument("str", Some("String"))
9999
.with_argument("substr", "Substring expression to search for.")
100+
.with_alternative_syntax("position(substr in origstr)")
100101
.build()
101102
.unwrap()
102103
})

docs/source/user-guide/sql/scalar_functions_new.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1465,6 +1465,12 @@ strpos(str, substr)
14651465
+----------------------------------------+
14661466
```
14671467

1468+
#### Alternative Syntax
1469+
1470+
```sql
1471+
position(substr in origstr)
1472+
```
1473+
14681474
#### Aliases
14691475

14701476
- instr

0 commit comments

Comments
 (0)