-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Doc gen: Migrate aggregate functions doc to attribute based. #13646
Changes from 3 commits
19938dc
00b9d5a
44bf00c
bbc03c9
eddf7b5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -63,6 +63,88 @@ impl Documentation { | |
) -> DocumentationBuilder { | ||
DocumentationBuilder::new(doc_section, description, syntax_example) | ||
} | ||
|
||
/// Output the `Documentation` struct in form of custom Rust documentation attributes | ||
pub fn to_doc_attribute(&self) -> String { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe it would also help helpful here to note this is to help migration to doc comment attributes |
||
let mut result = String::new(); | ||
|
||
result.push_str("#[user_doc("); | ||
// Doc Section | ||
result.push_str( | ||
format!( | ||
"\n doc_section({}label = \"{}\"{}),", | ||
if !self.doc_section.include { | ||
"include = \"false\", " | ||
} else { | ||
"" | ||
}, | ||
self.doc_section.label, | ||
self.doc_section | ||
.description | ||
.map(|s| format!(", description = \"{}\"", s)) | ||
.unwrap_or_default(), | ||
) | ||
.as_ref(), | ||
); | ||
|
||
// Description | ||
result.push_str(format!("\n description=\"{}\",", self.description).as_ref()); | ||
// Syntax Example | ||
result.push_str( | ||
format!("\n syntax_example=\"{}\",", self.syntax_example).as_ref(), | ||
); | ||
// SQL Example | ||
result.push_str( | ||
&self | ||
.sql_example | ||
.clone() | ||
.map(|s| format!("\n sql_example = r#\"{}\"#,", s)) | ||
.unwrap_or_default(), | ||
); | ||
|
||
let st_arg_token = " expression to operate on. Can be a constant, column, or function, and any combination of operators."; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Perhaps this could be extracted to a constant and that used instead of having text copies of the string in 2 places. |
||
// Standard Arguments | ||
if let Some(args) = self.arguments.clone() { | ||
args.iter().for_each(|(name, value)| { | ||
if value.contains(st_arg_token) { | ||
if name.starts_with("The ") { | ||
result.push_str(format!("\n standard_argument(\n name = \"{}\"),", name).as_ref()); | ||
} else { | ||
result.push_str(format!("\n standard_argument(\n name = \"{}\",\n prefix = \"{}\"\n ),", name, value.replace(st_arg_token, "")).as_ref()); | ||
} | ||
} | ||
}); | ||
} | ||
|
||
// Arguments | ||
if let Some(args) = self.arguments.clone() { | ||
args.iter().for_each(|(name, value)| { | ||
if !value.contains(st_arg_token) { | ||
result.push_str(format!("\n argument(\n name = \"{}\",\n description = \"{}\"\n ),", name, value).as_ref()); | ||
} | ||
}); | ||
} | ||
|
||
if let Some(alt_syntax) = self.alternative_syntax.clone() { | ||
alt_syntax.iter().for_each(|syntax| { | ||
result.push_str( | ||
format!("\n alternative_syntax = \"{}\",", syntax).as_ref(), | ||
); | ||
}); | ||
} | ||
|
||
// Related UDFs | ||
if let Some(related_udf) = self.related_udfs.clone() { | ||
related_udf.iter().for_each(|udf| { | ||
result | ||
.push_str(format!("\n related_udf(name = \"{}\"),", udf).as_ref()); | ||
}); | ||
} | ||
|
||
result.push_str("\n)]"); | ||
|
||
result | ||
} | ||
} | ||
|
||
#[derive(Debug, Clone, PartialEq)] | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm thinking of leaving it for now as this part generates text files with attribute text so its easier to do a migration for remaning parts(windows/builtin udfs), semi automatic way instead of manual
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would just add a small comment noting this is useful for migration purposes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree a comment explaining what this is used for would be most helpful