Skip to content

Commit

Permalink
Update test as now Cast from UTF8 -> Boolean is supported
Browse files Browse the repository at this point in the history
  • Loading branch information
alamb committed Jun 10, 2022
1 parent f5ee84d commit b19f5ca
Showing 1 changed file with 17 additions and 19 deletions.
36 changes: 17 additions & 19 deletions datafusion/core/src/physical_plan/planner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1288,6 +1288,7 @@ fn tuple_err<T, R>(value: (Result<T>, Result<R>)) -> Result<(T, R)> {
#[cfg(test)]
mod tests {
use super::*;
use crate::assert_contains;
use crate::execution::context::TaskContext;
use crate::execution::options::CsvReadOptions;
use crate::execution::runtime_env::{RuntimeConfig, RuntimeEnv};
Expand Down Expand Up @@ -1516,10 +1517,7 @@ mod tests {
#[tokio::test]
async fn in_list_types() -> Result<()> {
// expression: "a in ('a', 1)"
let list = vec![
Expr::Literal(ScalarValue::Utf8(Some("a".to_string()))),
Expr::Literal(ScalarValue::Int64(Some(1))),
];
let list = vec![lit("a"), lit(1i64)];
let logical_plan = test_csv_scan()
.await?
// filter clause needs the type coercion rule applied
Expand All @@ -1531,11 +1529,9 @@ mod tests {
let expected = "InListExpr { expr: Column { name: \"c1\", index: 0 }, list: [Literal { value: Utf8(\"a\") }, CastExpr { expr: Literal { value: Int64(1) }, cast_type: Utf8, cast_options: CastOptions { safe: false } }], negated: false, set: None }";
assert!(format!("{:?}", execution_plan).contains(expected));

// expression: "a in (true, 'a')"
let list = vec![
Expr::Literal(ScalarValue::Boolean(Some(true))),
Expr::Literal(ScalarValue::Utf8(Some("a".to_string()))),
];
// expression: "a in (struct::null, 'a')"
let list = vec![struct_literal(), lit("a")];

let logical_plan = test_csv_scan()
.await?
// filter clause needs the type coercion rule applied
Expand All @@ -1544,20 +1540,22 @@ mod tests {
.build()?;
let execution_plan = plan(&logical_plan).await;

let expected_error = "Unsupported CAST from Utf8 to Boolean";
match execution_plan {
Ok(_) => panic!("Expected planning failure"),
Err(e) => assert!(
e.to_string().contains(expected_error),
"Error '{}' did not contain expected error '{}'",
e,
expected_error
),
}
let e = execution_plan.unwrap_err().to_string();
assert_contains!(&e, "Unsupported CAST from Struct");
assert_contains!(&e, "to Boolean");

Ok(())
}

/// Return a `null` literal representing a struct type like: `{ a: bool }`
fn struct_literal() -> Expr {
let struct_literal = ScalarValue::Struct(
None,
Box::new(vec![Field::new("foo", DataType::Boolean, false)]),
);
lit(struct_literal)
}

#[tokio::test]
async fn in_set_test() -> Result<()> {
// OPTIMIZER_INSET_THRESHOLD = 10
Expand Down

0 comments on commit b19f5ca

Please sign in to comment.