Skip to content

Commit

Permalink
Print undocumented functions to console while generating docs (#12874)
Browse files Browse the repository at this point in the history
  • Loading branch information
alamb authored Oct 14, 2024
1 parent b932cdb commit 21cb357
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion datafusion/core/src/bin/print_functions_docs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,16 @@ use datafusion_expr::{
aggregate_doc_sections, scalar_doc_sections, window_doc_sections, AggregateUDF,
DocSection, Documentation, ScalarUDF, WindowUDF,
};
use hashbrown::HashSet;
use itertools::Itertools;
use std::env::args;
use std::fmt::Write as _;

/// Print documentation for all functions of a given type to stdout
///
/// Usage: `cargo run --bin print_functions_docs -- <type>`
///
/// Called from `dev/update_function_docs.sh`
fn main() {
let args: Vec<String> = args().collect();

Expand Down Expand Up @@ -83,9 +89,12 @@ fn print_docs(
) -> String {
let mut docs = "".to_string();

// Ensure that all providers have documentation
let mut providers_with_no_docs = HashSet::new();

// doc sections only includes sections that have 'include' == true
for doc_section in doc_sections {
// make sure there is a function that is in this doc section
// make sure there is at least one function that is in this doc section
if !&providers.iter().any(|f| {
if let Some(documentation) = f.get_documentation() {
documentation.doc_section == doc_section
Expand All @@ -96,12 +105,14 @@ fn print_docs(
continue;
}

// filter out functions that are not in this doc section
let providers: Vec<&Box<dyn DocProvider>> = providers
.iter()
.filter(|&f| {
if let Some(documentation) = f.get_documentation() {
documentation.doc_section == doc_section
} else {
providers_with_no_docs.insert(f.get_name());
false
}
})
Expand Down Expand Up @@ -202,9 +213,19 @@ fn print_docs(
}
}

// If there are any functions that do not have documentation, print them out
// eventually make this an error: https://github.com/apache/datafusion/issues/12872
if !providers_with_no_docs.is_empty() {
eprintln!("INFO: The following functions do not have documentation:");
for f in providers_with_no_docs {
eprintln!(" - {f}");
}
}

docs
}

/// Trait for accessing name / aliases / documentation for differnet functions
trait DocProvider {
fn get_name(&self) -> String;
fn get_aliases(&self) -> Vec<String>;
Expand Down

0 comments on commit 21cb357

Please sign in to comment.