Skip to content

Commit

Permalink
change usage of literal
Browse files Browse the repository at this point in the history
  • Loading branch information
liukun4515 committed Jul 3, 2022
1 parent 767f899 commit de66710
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions datafusion/physical-expr/src/expressions/case.rs
Original file line number Diff line number Diff line change
Expand Up @@ -309,14 +309,15 @@ pub fn case(
let left = when_thens
.into_iter()
.map(|(when, then)| {
let then = try_cast(then, input_schema, data_type.clone()).unwrap();
(when, then)
let then = try_cast(then, input_schema, data_type.clone())?;
Ok((when, then))
})
.collect::<Vec<WhenThen>>();
.collect::<Result<Vec<_>>>()?;
let right = match else_expr {
None => None,
Some(expr) => Some(try_cast(expr, input_schema, data_type.clone())?),
};

Ok((left, right))
}
}?;
Expand Down Expand Up @@ -711,17 +712,17 @@ mod tests {
let when1 = binary(
col("a", &schema)?,
Operator::Eq,
lit(ScalarValue::Utf8(Some("foo".to_string()))),
lit("foo"),
&batch.schema(),
)?;
let then1 = lit(ScalarValue::Int32(Some(123)));
let then1 = lit(123i32);
let when2 = binary(
col("a", &schema)?,
Operator::Eq,
lit(ScalarValue::Utf8(Some("bar".to_string()))),
lit("bar"),
&batch.schema(),
)?;
let then2 = lit(ScalarValue::Boolean(Some(true)));
let then2 = lit(true);

let expr = case(
None,
Expand All @@ -738,18 +739,18 @@ mod tests {
let when1 = binary(
col("a", &schema)?,
Operator::Eq,
lit(ScalarValue::Utf8(Some("foo".to_string()))),
lit("foo"),
&batch.schema(),
)?;
let then1 = lit(ScalarValue::Int32(Some(123)));
let then1 = lit(123i32);
let when2 = binary(
col("a", &schema)?,
Operator::Eq,
lit(ScalarValue::Utf8(Some("bar".to_string()))),
lit("bar"),
&batch.schema(),
)?;
let then2 = lit(ScalarValue::Int64(Some(456)));
let else_expr = lit(ScalarValue::Float64(Some(1.23)));
let then2 = lit(456i64);
let else_expr = lit(1.23f64);

let expr = case(
None,
Expand Down

0 comments on commit de66710

Please sign in to comment.