Skip to content

Commit 6f8bc81

Browse files
chore: Format examples in doc strings - macros and optmizer (#18354)
## Which issue does this PR close? Part of #16915 ## Rationale for this change Format code examples in documentation comments to improve readability and maintain consistent code style across the codebase. This is part of a multi-PR effort to format all doc comment examples and eventually enable CI checks to enforce this formatting. ## What changes are included in this PR? Run `cargo fmt -p <crate> -- --config format_code_in_doc_comments=true` for the following datasource-related crates: - `datafusion-macros` - `datafusion-optimizer` ## Are these changes tested? No testing needed - this is purely a formatting change with no functional modifications. ## Are there any user-facing changes? No - this only affects documentation formatting.
1 parent dfba228 commit 6f8bc81

File tree

5 files changed

+54
-63
lines changed

5 files changed

+54
-63
lines changed

datafusion/macros/src/user_doc.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ use syn::{parse_macro_input, DeriveInput, LitStr};
6161
/// }
6262
/// ```
6363
/// will generate the following code
64-
///
6564
/// ```ignore
6665
/// pub struct ToDateFunc {
6766
/// signature: Signature,

datafusion/optimizer/src/push_down_filter.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -562,7 +562,6 @@ fn push_down_join(
562562
///
563563
/// * `on_filters` filters from the join ON clause that have not already been
564564
/// identified as join predicates
565-
///
566565
fn infer_join_predicates(
567566
join: &Join,
568567
predicates: &[Expr],
@@ -649,7 +648,6 @@ impl InferredPredicates {
649648
/// * `predicates` the pushed down predicates
650649
///
651650
/// * `inferred_predicates` the inferred results
652-
///
653651
fn infer_join_predicates_from_predicates(
654652
join_col_keys: &[(&Column, &Column)],
655653
predicates: &[Expr],
@@ -673,7 +671,6 @@ fn infer_join_predicates_from_predicates(
673671
/// identified as join predicates
674672
///
675673
/// * `inferred_predicates` the inferred results
676-
///
677674
fn infer_join_predicates_from_on_filters(
678675
join_col_keys: &[(&Column, &Column)],
679676
join_type: JoinType,
@@ -719,7 +716,6 @@ fn infer_join_predicates_from_on_filters(
719716
///
720717
/// * `ENABLE_RIGHT_TO_LEFT` indicates that the left table related predicate can
721718
/// be inferred from the right table related predicate
722-
///
723719
fn infer_join_predicates_impl<
724720
const ENABLE_LEFT_TO_RIGHT: bool,
725721
const ENABLE_RIGHT_TO_LEFT: bool,

datafusion/optimizer/src/push_down_limit.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ use datafusion_expr::logical_plan::{Join, JoinType, Limit, LogicalPlan};
3030
use datafusion_expr::{lit, FetchType, SkipType};
3131

3232
/// Optimization rule that tries to push down `LIMIT`.
33-
///
3433
//. It will push down through projection, limits (taking the smaller limit)
3534
#[derive(Default, Debug)]
3635
pub struct PushDownLimit {}

datafusion/optimizer/src/simplify_expressions/expr_simplifier.rs

Lines changed: 54 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -69,23 +69,21 @@ use regex::Regex;
6969
///
7070
/// For example:
7171
/// ```
72-
/// use arrow::datatypes::{Schema, Field, DataType};
73-
/// use datafusion_expr::{col, lit};
72+
/// use arrow::datatypes::{DataType, Field, Schema};
7473
/// use datafusion_common::{DataFusionError, ToDFSchema};
7574
/// use datafusion_expr::execution_props::ExecutionProps;
7675
/// use datafusion_expr::simplify::SimplifyContext;
76+
/// use datafusion_expr::{col, lit};
7777
/// use datafusion_optimizer::simplify_expressions::ExprSimplifier;
7878
///
7979
/// // Create the schema
80-
/// let schema = Schema::new(vec![
81-
/// Field::new("i", DataType::Int64, false),
82-
/// ])
83-
/// .to_dfschema_ref().unwrap();
80+
/// let schema = Schema::new(vec![Field::new("i", DataType::Int64, false)])
81+
/// .to_dfschema_ref()
82+
/// .unwrap();
8483
///
8584
/// // Create the simplifier
8685
/// let props = ExecutionProps::new();
87-
/// let context = SimplifyContext::new(&props)
88-
/// .with_schema(schema);
86+
/// let context = SimplifyContext::new(&props).with_schema(schema);
8987
/// let simplifier = ExprSimplifier::new(context);
9088
///
9189
/// // Use the simplifier
@@ -144,35 +142,35 @@ impl<S: SimplifyInfo> ExprSimplifier<S> {
144142
///
145143
/// ```
146144
/// use arrow::datatypes::DataType;
147-
/// use datafusion_expr::{col, lit, Expr};
145+
/// use datafusion_common::DFSchema;
148146
/// use datafusion_common::Result;
149147
/// use datafusion_expr::execution_props::ExecutionProps;
150148
/// use datafusion_expr::simplify::SimplifyContext;
151149
/// use datafusion_expr::simplify::SimplifyInfo;
150+
/// use datafusion_expr::{col, lit, Expr};
152151
/// use datafusion_optimizer::simplify_expressions::ExprSimplifier;
153-
/// use datafusion_common::DFSchema;
154152
/// use std::sync::Arc;
155153
///
156154
/// /// Simple implementation that provides `Simplifier` the information it needs
157155
/// /// See SimplifyContext for a structure that does this.
158156
/// #[derive(Default)]
159157
/// struct Info {
160-
/// execution_props: ExecutionProps,
158+
/// execution_props: ExecutionProps,
161159
/// };
162160
///
163161
/// impl SimplifyInfo for Info {
164-
/// fn is_boolean_type(&self, expr: &Expr) -> Result<bool> {
165-
/// Ok(false)
166-
/// }
167-
/// fn nullable(&self, expr: &Expr) -> Result<bool> {
168-
/// Ok(true)
169-
/// }
170-
/// fn execution_props(&self) -> &ExecutionProps {
171-
/// &self.execution_props
172-
/// }
173-
/// fn get_data_type(&self, expr: &Expr) -> Result<DataType> {
174-
/// Ok(DataType::Int32)
175-
/// }
162+
/// fn is_boolean_type(&self, expr: &Expr) -> Result<bool> {
163+
/// Ok(false)
164+
/// }
165+
/// fn nullable(&self, expr: &Expr) -> Result<bool> {
166+
/// Ok(true)
167+
/// }
168+
/// fn execution_props(&self) -> &ExecutionProps {
169+
/// &self.execution_props
170+
/// }
171+
/// fn get_data_type(&self, expr: &Expr) -> Result<DataType> {
172+
/// Ok(DataType::Int32)
173+
/// }
176174
/// }
177175
///
178176
/// // Create the simplifier
@@ -198,7 +196,6 @@ impl<S: SimplifyInfo> ExprSimplifier<S> {
198196
/// optimizations.
199197
///
200198
/// See [Self::simplify] for details and usage examples.
201-
///
202199
#[deprecated(
203200
since = "48.0.0",
204201
note = "Use `simplify_with_cycle_count_transformed` instead"
@@ -222,7 +219,6 @@ impl<S: SimplifyInfo> ExprSimplifier<S> {
222219
/// - The number of simplification cycles that were performed
223220
///
224221
/// See [Self::simplify] for details and usage examples.
225-
///
226222
pub fn simplify_with_cycle_count_transformed(
227223
&self,
228224
mut expr: Expr,
@@ -286,24 +282,24 @@ impl<S: SimplifyInfo> ExprSimplifier<S> {
286282
///
287283
/// ```rust
288284
/// use arrow::datatypes::{DataType, Field, Schema};
289-
/// use datafusion_expr::{col, lit, Expr};
290-
/// use datafusion_expr::interval_arithmetic::{Interval, NullableInterval};
291285
/// use datafusion_common::{Result, ScalarValue, ToDFSchema};
292286
/// use datafusion_expr::execution_props::ExecutionProps;
287+
/// use datafusion_expr::interval_arithmetic::{Interval, NullableInterval};
293288
/// use datafusion_expr::simplify::SimplifyContext;
289+
/// use datafusion_expr::{col, lit, Expr};
294290
/// use datafusion_optimizer::simplify_expressions::ExprSimplifier;
295291
///
296292
/// let schema = Schema::new(vec![
297-
/// Field::new("x", DataType::Int64, false),
298-
/// Field::new("y", DataType::UInt32, false),
299-
/// Field::new("z", DataType::Int64, false),
300-
/// ])
301-
/// .to_dfschema_ref().unwrap();
293+
/// Field::new("x", DataType::Int64, false),
294+
/// Field::new("y", DataType::UInt32, false),
295+
/// Field::new("z", DataType::Int64, false),
296+
/// ])
297+
/// .to_dfschema_ref()
298+
/// .unwrap();
302299
///
303300
/// // Create the simplifier
304301
/// let props = ExecutionProps::new();
305-
/// let context = SimplifyContext::new(&props)
306-
/// .with_schema(schema);
302+
/// let context = SimplifyContext::new(&props).with_schema(schema);
307303
///
308304
/// // Expression: (x >= 3) AND (y + 2 < 10) AND (z > 5)
309305
/// let expr_x = col("x").gt_eq(lit(3_i64));
@@ -312,15 +308,18 @@ impl<S: SimplifyInfo> ExprSimplifier<S> {
312308
/// let expr = expr_x.and(expr_y).and(expr_z.clone());
313309
///
314310
/// let guarantees = vec![
315-
/// // x ∈ [3, 5]
316-
/// (
317-
/// col("x"),
318-
/// NullableInterval::NotNull {
319-
/// values: Interval::make(Some(3_i64), Some(5_i64)).unwrap()
320-
/// }
321-
/// ),
322-
/// // y = 3
323-
/// (col("y"), NullableInterval::from(ScalarValue::UInt32(Some(3)))),
311+
/// // x ∈ [3, 5]
312+
/// (
313+
/// col("x"),
314+
/// NullableInterval::NotNull {
315+
/// values: Interval::make(Some(3_i64), Some(5_i64)).unwrap(),
316+
/// },
317+
/// ),
318+
/// // y = 3
319+
/// (
320+
/// col("y"),
321+
/// NullableInterval::from(ScalarValue::UInt32(Some(3))),
322+
/// ),
324323
/// ];
325324
/// let simplifier = ExprSimplifier::new(context).with_guarantees(guarantees);
326325
/// let output = simplifier.simplify(expr).unwrap();
@@ -345,24 +344,24 @@ impl<S: SimplifyInfo> ExprSimplifier<S> {
345344
///
346345
/// ```rust
347346
/// use arrow::datatypes::{DataType, Field, Schema};
348-
/// use datafusion_expr::{col, lit, Expr};
349-
/// use datafusion_expr::interval_arithmetic::{Interval, NullableInterval};
350347
/// use datafusion_common::{Result, ScalarValue, ToDFSchema};
351348
/// use datafusion_expr::execution_props::ExecutionProps;
349+
/// use datafusion_expr::interval_arithmetic::{Interval, NullableInterval};
352350
/// use datafusion_expr::simplify::SimplifyContext;
351+
/// use datafusion_expr::{col, lit, Expr};
353352
/// use datafusion_optimizer::simplify_expressions::ExprSimplifier;
354353
///
355354
/// let schema = Schema::new(vec![
356-
/// Field::new("a", DataType::Int64, false),
357-
/// Field::new("b", DataType::Int64, false),
358-
/// Field::new("c", DataType::Int64, false),
359-
/// ])
360-
/// .to_dfschema_ref().unwrap();
355+
/// Field::new("a", DataType::Int64, false),
356+
/// Field::new("b", DataType::Int64, false),
357+
/// Field::new("c", DataType::Int64, false),
358+
/// ])
359+
/// .to_dfschema_ref()
360+
/// .unwrap();
361361
///
362362
/// // Create the simplifier
363363
/// let props = ExecutionProps::new();
364-
/// let context = SimplifyContext::new(&props)
365-
/// .with_schema(schema);
364+
/// let context = SimplifyContext::new(&props).with_schema(schema);
366365
/// let simplifier = ExprSimplifier::new(context);
367366
///
368367
/// // Expression: a = c AND 1 = b
@@ -376,9 +375,9 @@ impl<S: SimplifyInfo> ExprSimplifier<S> {
376375
///
377376
/// // If canonicalization is disabled, the expression is not changed
378377
/// let non_canonicalized = simplifier
379-
/// .with_canonicalize(false)
380-
/// .simplify(expr.clone())
381-
/// .unwrap();
378+
/// .with_canonicalize(false)
379+
/// .simplify(expr.clone())
380+
/// .unwrap();
382381
///
383382
/// assert_eq!(non_canonicalized, expr);
384383
/// ```
@@ -437,7 +436,6 @@ impl<S: SimplifyInfo> ExprSimplifier<S> {
437436
/// assert_eq!(simplified_expr.data, lit(true));
438437
/// // Only 1 cycle was executed
439438
/// assert_eq!(count, 1);
440-
///
441439
/// ```
442440
pub fn with_max_cycles(mut self, max_simplifier_cycles: u32) -> Self {
443441
self.max_simplifier_cycles = max_simplifier_cycles;

datafusion/optimizer/src/simplify_expressions/unwrap_cast.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@
5353
//! ```text
5454
//! c1 > INT32(10)
5555
//! ```
56-
//!
5756
5857
use arrow::datatypes::DataType;
5958
use datafusion_common::{internal_err, tree_node::Transformed};

0 commit comments

Comments
 (0)