Skip to content

Commit 1a6e9f5

Browse files
compheadOmega359
andauthored
User documentation: Generate docs from macros, makeDocumentationBuilder::build infallable (#12822)
User documentation: Generate docs from macros, makeDocumentationBuilder::build infallable * Update datafusion/macros/src/lib.rs Co-authored-by: Bruce Ritchie <bruce.ritchie@veeva.com> * Update datafusion/macros/src/lib.rs Co-authored-by: Bruce Ritchie <bruce.ritchie@veeva.com> * Minor: clean up error entries --------- Co-authored-by: Bruce Ritchie <bruce.ritchie@veeva.com>
1 parent 5c78912 commit 1a6e9f5

File tree

148 files changed

+385
-279
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

148 files changed

+385
-279
lines changed

Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ members = [
5252
"datafusion-examples/examples/ffi/ffi_module_loader",
5353
"test-utils",
5454
"benchmarks",
55+
"datafusion/macros",
56+
"datafusion/doc",
5557
]
5658
resolver = "2"
5759

@@ -100,6 +102,7 @@ datafusion = { path = "datafusion/core", version = "43.0.0", default-features =
100102
datafusion-catalog = { path = "datafusion/catalog", version = "43.0.0" }
101103
datafusion-common = { path = "datafusion/common", version = "43.0.0", default-features = false }
102104
datafusion-common-runtime = { path = "datafusion/common-runtime", version = "43.0.0" }
105+
datafusion-doc = { path = "datafusion/doc", version = "43.0.0" }
103106
datafusion-execution = { path = "datafusion/execution", version = "43.0.0" }
104107
datafusion-expr = { path = "datafusion/expr", version = "43.0.0" }
105108
datafusion-expr-common = { path = "datafusion/expr-common", version = "43.0.0" }
@@ -110,6 +113,7 @@ datafusion-functions-aggregate-common = { path = "datafusion/functions-aggregate
110113
datafusion-functions-nested = { path = "datafusion/functions-nested", version = "43.0.0" }
111114
datafusion-functions-window = { path = "datafusion/functions-window", version = "43.0.0" }
112115
datafusion-functions-window-common = { path = "datafusion/functions-window-common", version = "43.0.0" }
116+
datafusion-macros = { path = "datafusion/macros", version = "43.0.0" }
113117
datafusion-optimizer = { path = "datafusion/optimizer", version = "43.0.0", default-features = false }
114118
datafusion-physical-expr = { path = "datafusion/physical-expr", version = "43.0.0", default-features = false }
115119
datafusion-physical-expr-common = { path = "datafusion/physical-expr-common", version = "43.0.0", default-features = false }

datafusion-cli/Cargo.lock

Lines changed: 17 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

datafusion/doc/Cargo.toml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
[package]
19+
name = "datafusion-doc"
20+
description = "Documentation module for DataFusion query engine"
21+
keywords = ["datafusion", "query", "sql"]
22+
version = { workspace = true }
23+
edition = { workspace = true }
24+
homepage = { workspace = true }
25+
repository = { workspace = true }
26+
license = { workspace = true }
27+
authors = { workspace = true }
28+
rust-version = { workspace = true }
29+
30+
[lints]
31+
workspace = true
32+
33+
[lib]
34+
name = "datafusion_doc"
35+
path = "src/lib.rs"

datafusion/expr/src/udf_docs.rs renamed to datafusion/doc/src/lib.rs

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,13 @@
1515
// specific language governing permissions and limitations
1616
// under the License.
1717

18-
use datafusion_common::exec_err;
19-
use datafusion_common::Result;
20-
21-
/// Documentation for use by [`ScalarUDFImpl`](crate::ScalarUDFImpl),
22-
/// [`AggregateUDFImpl`](crate::AggregateUDFImpl) and [`WindowUDFImpl`](crate::WindowUDFImpl) functions
18+
#[allow(rustdoc::broken_intra_doc_links)]
19+
/// Documentation for use by [`ScalarUDFImpl`](ScalarUDFImpl),
20+
/// [`AggregateUDFImpl`](AggregateUDFImpl) and [`WindowUDFImpl`](WindowUDFImpl) functions
2321
/// that will be used to generate public documentation.
2422
///
25-
/// The name of the udf will be pulled from the [`ScalarUDFImpl::name`](crate::ScalarUDFImpl::name),
26-
/// [`AggregateUDFImpl::name`](crate::AggregateUDFImpl::name) or [`WindowUDFImpl::name`](crate::WindowUDFImpl::name)
23+
/// The name of the udf will be pulled from the [`ScalarUDFImpl::name`](ScalarUDFImpl::name),
24+
/// [`AggregateUDFImpl::name`](AggregateUDFImpl::name) or [`WindowUDFImpl::name`](WindowUDFImpl::name)
2725
/// function as appropriate.
2826
///
2927
/// All strings in the documentation are required to be
@@ -79,18 +77,21 @@ pub struct DocSection {
7977
/// Example:
8078
///
8179
/// ```rust
82-
/// # use datafusion_expr::Documentation;
83-
/// # use datafusion_expr::scalar_doc_sections::DOC_SECTION_MATH;
84-
/// # use datafusion_common::Result;
85-
/// #
86-
/// # fn main() -> Result<()> {
87-
/// let documentation = Documentation::builder()
88-
/// .with_doc_section(DOC_SECTION_MATH)
80+
///
81+
/// # fn main() {
82+
/// use datafusion_doc::{DocSection, Documentation};
83+
/// let doc_section = DocSection {
84+
/// include: true,
85+
/// label: "Display Label",
86+
/// description: None,
87+
/// };
88+
///
89+
/// let documentation = Documentation::builder()
90+
/// .with_doc_section(doc_section)
8991
/// .with_description("Add one to an int32")
9092
/// .with_syntax_example("add_one(2)")
9193
/// .with_argument("arg_1", "The int32 number to add one to")
92-
/// .build()?;
93-
/// Ok(())
94+
/// .build();
9495
/// # }
9596
pub struct DocumentationBuilder {
9697
pub doc_section: Option<DocSection>,
@@ -190,7 +191,10 @@ impl DocumentationBuilder {
190191
self
191192
}
192193

193-
pub fn build(self) -> Result<Documentation> {
194+
/// Build the documentation from provided components
195+
///
196+
/// Panics if `doc_section`, `description` or `syntax_example` is not set
197+
pub fn build(self) -> Documentation {
194198
let Self {
195199
doc_section,
196200
description,
@@ -202,24 +206,24 @@ impl DocumentationBuilder {
202206
} = self;
203207

204208
if doc_section.is_none() {
205-
return exec_err!("Documentation must have a doc section");
209+
panic!("Documentation must have a doc section");
206210
}
207211
if description.is_none() {
208-
return exec_err!("Documentation must have a description");
212+
panic!("Documentation must have a description");
209213
}
210214
if syntax_example.is_none() {
211-
return exec_err!("Documentation must have a syntax_example");
215+
panic!("Documentation must have a syntax_example");
212216
}
213217

214-
Ok(Documentation {
218+
Documentation {
215219
doc_section: doc_section.unwrap(),
216220
description: description.unwrap(),
217221
syntax_example: syntax_example.unwrap(),
218222
sql_example,
219223
arguments,
220224
alternative_syntax,
221225
related_udfs,
222-
})
226+
}
223227
}
224228
}
225229

datafusion/expr/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ arrow-array = { workspace = true }
4444
arrow-buffer = { workspace = true }
4545
chrono = { workspace = true }
4646
datafusion-common = { workspace = true }
47+
datafusion-doc = { workspace = true }
4748
datafusion-expr-common = { workspace = true }
4849
datafusion-functions-aggregate-common = { workspace = true }
4950
datafusion-functions-window-common = { workspace = true }

datafusion/expr/src/lib.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ mod partition_evaluator;
3434
mod table_source;
3535
mod udaf;
3636
mod udf;
37-
mod udf_docs;
3837
mod udwf;
3938

4039
pub mod conditional_expressions;
@@ -66,6 +65,7 @@ pub mod var_provider;
6665
pub mod window_frame;
6766
pub mod window_state;
6867

68+
pub use datafusion_doc::{DocSection, Documentation, DocumentationBuilder};
6969
pub use datafusion_expr_common::accumulator::Accumulator;
7070
pub use datafusion_expr_common::columnar_value::ColumnarValue;
7171
pub use datafusion_expr_common::groups_accumulator::{EmitTo, GroupsAccumulator};
@@ -93,7 +93,6 @@ pub use udaf::{
9393
aggregate_doc_sections, AggregateUDF, AggregateUDFImpl, ReversedUDAF, StatisticsArgs,
9494
};
9595
pub use udf::{scalar_doc_sections, ScalarFunctionArgs, ScalarUDF, ScalarUDFImpl};
96-
pub use udf_docs::{DocSection, Documentation, DocumentationBuilder};
9796
pub use udwf::{window_doc_sections, ReversedUDWF, WindowUDF, WindowUDFImpl};
9897
pub use window_frame::{WindowFrame, WindowFrameBound, WindowFrameUnits};
9998

datafusion/expr/src/udaf.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,6 @@ where
339339
/// .with_syntax_example("geo_mean(2.0)")
340340
/// .with_argument("arg1", "The Float64 number for the geometric mean")
341341
/// .build()
342-
/// .unwrap()
343342
/// })
344343
/// }
345344
///

datafusion/expr/src/udf.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,6 @@ pub struct ScalarFunctionArgs<'a> {
382382
/// .with_syntax_example("add_one(2)")
383383
/// .with_argument("arg1", "The int32 number to add one to")
384384
/// .build()
385-
/// .unwrap()
386385
/// })
387386
/// }
388387
///

datafusion/expr/src/udwf.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ use arrow::datatypes::{DataType, Field};
3030

3131
use crate::expr::WindowFunction;
3232
use crate::{
33-
function::WindowFunctionSimplification, Documentation, Expr, PartitionEvaluator,
34-
Signature,
33+
function::WindowFunctionSimplification, Expr, PartitionEvaluator, Signature,
3534
};
3635
use datafusion_common::{not_impl_err, Result};
36+
use datafusion_doc::Documentation;
3737
use datafusion_functions_window_common::expr::ExpressionArgs;
3838
use datafusion_functions_window_common::field::WindowUDFFieldArgs;
3939
use datafusion_functions_window_common::partition::PartitionEvaluatorArgs;
@@ -264,7 +264,6 @@ where
264264
/// .with_syntax_example("smooth_it(2)")
265265
/// .with_argument("arg1", "The int32 number to smooth by")
266266
/// .build()
267-
/// .unwrap()
268267
/// })
269268
/// }
270269
///
@@ -557,7 +556,7 @@ impl WindowUDFImpl for AliasedWindowUDFImpl {
557556

558557
// Window UDF doc sections for use in public documentation
559558
pub mod window_doc_sections {
560-
use crate::DocSection;
559+
use datafusion_doc::DocSection;
561560

562561
pub fn doc_sections() -> Vec<DocSection> {
563562
vec![

datafusion/functions-aggregate/src/approx_distinct.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,5 @@ fn get_approx_distinct_doc() -> &'static Documentation {
334334
)
335335
.with_standard_argument("expression", None)
336336
.build()
337-
.unwrap()
338337
})
339338
}

0 commit comments

Comments
 (0)