Skip to content

Commit

Permalink
chore: Minor cleanup simplify_demo() example (#11576)
Browse files Browse the repository at this point in the history
* chore: fix examples and comments

Signed-off-by: Kaviraj <[email protected]>

* remove unused `b` field

Signed-off-by: Kaviraj <[email protected]>

* fix the number of days

Signed-off-by: Kaviraj <[email protected]>

---------

Signed-off-by: Kaviraj <[email protected]>
  • Loading branch information
kavirajk authored Jul 22, 2024
1 parent ecf5323 commit 12c0a1e
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions datafusion-examples/examples/expr_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,16 +177,12 @@ fn simplify_demo() -> Result<()> {
);

// here are some other examples of what DataFusion is capable of
let schema = Schema::new(vec![
make_field("i", DataType::Int64),
make_field("b", DataType::Boolean),
])
.to_dfschema_ref()?;
let schema = Schema::new(vec![make_field("i", DataType::Int64)]).to_dfschema_ref()?;
let context = SimplifyContext::new(&props).with_schema(schema.clone());
let simplifier = ExprSimplifier::new(context);

// basic arithmetic simplification
// i + 1 + 2 => a + 3
// i + 1 + 2 => i + 3
// (note this is not done if the expr is (col("i") + (lit(1) + lit(2))))
assert_eq!(
simplifier.simplify(col("i") + (lit(1) + lit(2)))?,
Expand All @@ -209,7 +205,7 @@ fn simplify_demo() -> Result<()> {
);

// String --> Date simplification
// `cast('2020-09-01' as date)` --> 18500
// `cast('2020-09-01' as date)` --> 18506 # number of days since epoch 1970-01-01
assert_eq!(
simplifier.simplify(lit("2020-09-01").cast_to(&DataType::Date32, &schema)?)?,
lit(ScalarValue::Date32(Some(18506)))
Expand Down

0 comments on commit 12c0a1e

Please sign in to comment.