Skip to content

Commit c268106

Browse files
chore: Format examples in doc strings - proto, pruning, and session (#18358)
## 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-proto` - `datafusion-proto-common` - `datafusion-pruning` - `datafusion-session` ## 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 6f8bc81 commit c268106

File tree

4 files changed

+38
-31
lines changed

4 files changed

+38
-31
lines changed

datafusion/proto-common/src/lib.rs

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -62,28 +62,33 @@
6262
//! # use datafusion_proto_common::protobuf_common;
6363
//! # use prost::Message;
6464
//! # fn main() -> Result<()>{
65-
//! // Create a new ScalarValue
66-
//! let val = ScalarValue::UInt64(Some(3));
67-
//! let mut buffer = BytesMut::new();
68-
//! let protobuf: protobuf_common::ScalarValue = match val {
69-
//! ScalarValue::UInt64(Some(val)) => {
70-
//! protobuf_common::ScalarValue{value: Some(protobuf_common::scalar_value::Value::Uint64Value(val))}
71-
//! }
72-
//! _ => unreachable!(),
73-
//! };
65+
//! // Create a new ScalarValue
66+
//! let val = ScalarValue::UInt64(Some(3));
67+
//! let mut buffer = BytesMut::new();
68+
//! let protobuf: protobuf_common::ScalarValue = match val {
69+
//! ScalarValue::UInt64(Some(val)) => protobuf_common::ScalarValue {
70+
//! value: Some(protobuf_common::scalar_value::Value::Uint64Value(val)),
71+
//! },
72+
//! _ => unreachable!(),
73+
//! };
7474
//!
75-
//! protobuf.encode(&mut buffer)
75+
//! protobuf
76+
//! .encode(&mut buffer)
7677
//! .map_err(|e| plan_datafusion_err!("Error encoding protobuf as bytes: {e}"))?;
77-
//! // Convert it to bytes (for sending over the network, etc.)
78-
//! let bytes: Bytes = buffer.into();
78+
//! // Convert it to bytes (for sending over the network, etc.)
79+
//! let bytes: Bytes = buffer.into();
7980
//!
80-
//! let protobuf = protobuf_common::ScalarValue::decode(bytes).map_err(|e| plan_datafusion_err!("Error decoding ScalarValue as protobuf: {e}"))?;
81-
//! // Decode bytes from somewhere (over network, etc.) back to ScalarValue
82-
//! let decoded_val: ScalarValue = match protobuf.value {
83-
//! Some(protobuf_common::scalar_value::Value::Uint64Value(val)) => ScalarValue::UInt64(Some(val)),
84-
//! _ => unreachable!(),
85-
//! };
86-
//! assert_eq!(val, decoded_val);
81+
//! let protobuf = protobuf_common::ScalarValue::decode(bytes).map_err(|e| {
82+
//! plan_datafusion_err!("Error decoding ScalarValue as protobuf: {e}")
83+
//! })?;
84+
//! // Decode bytes from somewhere (over network, etc.) back to ScalarValue
85+
//! let decoded_val: ScalarValue = match protobuf.value {
86+
//! Some(protobuf_common::scalar_value::Value::Uint64Value(val)) => {
87+
//! ScalarValue::UInt64(Some(val))
88+
//! }
89+
//! _ => unreachable!(),
90+
//! };
91+
//! assert_eq!(val, decoded_val);
8792
//! # Ok(())
8893
//! # }
8994
//! ```

datafusion/proto/src/lib.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -64,15 +64,15 @@
6464
//! # use datafusion_expr::{col, lit, Expr};
6565
//! # use datafusion_proto::bytes::Serializeable;
6666
//! # fn main() -> Result<()>{
67-
//! // Create a new `Expr` a < 32
68-
//! let expr = col("a").lt(lit(5i32));
67+
//! // Create a new `Expr` a < 32
68+
//! let expr = col("a").lt(lit(5i32));
6969
//!
70-
//! // Convert it to bytes (for sending over the network, etc.)
71-
//! let bytes = expr.to_bytes()?;
70+
//! // Convert it to bytes (for sending over the network, etc.)
71+
//! let bytes = expr.to_bytes()?;
7272
//!
73-
//! // Decode bytes from somewhere (over network, etc.) back to Expr
74-
//! let decoded_expr = Expr::from_bytes(&bytes)?;
75-
//! assert_eq!(expr, decoded_expr);
73+
//! // Decode bytes from somewhere (over network, etc.) back to Expr
74+
//! let decoded_expr = Expr::from_bytes(&bytes)?;
75+
//! assert_eq!(expr, decoded_expr);
7676
//! # Ok(())
7777
//! # }
7878
//! ```

datafusion/pruning/src/pruning_predicate.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -882,7 +882,7 @@ impl From<Vec<(phys_expr::Column, StatisticsType, Field)>> for RequiredColumns {
882882
/// ```text
883883
/// ("s1", Min, Field:s1_min)
884884
/// ("s2", Max, field:s2_max)
885-
///```
885+
/// ```
886886
///
887887
/// And the input statistics had
888888
/// ```text
@@ -5108,7 +5108,6 @@ mod tests {
51085108
///
51095109
/// `expected` is a vector of bools, where true means the row group should
51105110
/// be kept, and false means it should be pruned.
5111-
///
51125111
// TODO refactor other tests to use this to reduce boiler plate
51135112
fn prune_with_expr(
51145113
expr: Expr,

datafusion/session/src/session.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,12 @@ use std::sync::{Arc, Weak};
5757
/// // Given a `Session` reference, get the concrete `SessionState` reference
5858
/// // Note: this may stop working in future versions,
5959
/// fn session_state_from_session(session: &dyn Session) -> Result<&SessionState> {
60-
/// session.as_any()
61-
/// .downcast_ref::<SessionState>()
62-
/// .ok_or_else(|| exec_datafusion_err!("Failed to downcast Session to SessionState"))
60+
/// session
61+
/// .as_any()
62+
/// .downcast_ref::<SessionState>()
63+
/// .ok_or_else(|| {
64+
/// exec_datafusion_err!("Failed to downcast Session to SessionState")
65+
/// })
6366
/// }
6467
/// ```
6568
///

0 commit comments

Comments
 (0)