Skip to content

Commit

Permalink
Minor: Add example with parameters to LogicalPlan (apache#8418)
Browse files Browse the repository at this point in the history
  • Loading branch information
alamb authored and appletreeisyellow committed Dec 15, 2023
1 parent b77b2bf commit d044deb
Showing 1 changed file with 25 additions and 6 deletions.
31 changes: 25 additions & 6 deletions datafusion/expr/src/logical_plan/plan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -976,20 +976,39 @@ impl LogicalPlan {
/// .filter(col("id").eq(placeholder("$1"))).unwrap()
/// .build().unwrap();
///
/// assert_eq!("Filter: t1.id = $1\
/// \n TableScan: t1",
/// plan.display_indent().to_string()
/// assert_eq!(
/// "Filter: t1.id = $1\
/// \n TableScan: t1",
/// plan.display_indent().to_string()
/// );
///
/// // Fill in the parameter $1 with a literal 3
/// let plan = plan.with_param_values(vec![
/// ScalarValue::from(3i32) // value at index 0 --> $1
/// ]).unwrap();
///
/// assert_eq!("Filter: t1.id = Int32(3)\
/// \n TableScan: t1",
/// plan.display_indent().to_string()
/// assert_eq!(
/// "Filter: t1.id = Int32(3)\
/// \n TableScan: t1",
/// plan.display_indent().to_string()
/// );
///
/// // Note you can also used named parameters
/// // Build SELECT * FROM t1 WHRERE id = $my_param
/// let plan = table_scan(Some("t1"), &schema, None).unwrap()
/// .filter(col("id").eq(placeholder("$my_param"))).unwrap()
/// .build().unwrap()
/// // Fill in the parameter $my_param with a literal 3
/// .with_param_values(vec![
/// ("my_param", ScalarValue::from(3i32)),
/// ]).unwrap();
///
/// assert_eq!(
/// "Filter: t1.id = Int32(3)\
/// \n TableScan: t1",
/// plan.display_indent().to_string()
/// );
///
/// ```
pub fn with_param_values(
self,
Expand Down

0 comments on commit d044deb

Please sign in to comment.