diff --git a/crates/polars-core/src/datatypes/any_value.rs b/crates/polars-core/src/datatypes/any_value.rs index 5f92bf33a55b..7778475049d1 100644 --- a/crates/polars-core/src/datatypes/any_value.rs +++ b/crates/polars-core/src/datatypes/any_value.rs @@ -464,7 +464,6 @@ impl<'a> AnyValue<'a> { DataType::Duration(tu) => AnyValue::Duration($av as i64, *tu), #[cfg(feature="dtype-time")] DataType::Time => AnyValue::Time($av as i64), - DataType::Utf8 => AnyValue::Utf8Owned(format_smartstring!("{}", $av)), _ => polars_bail!( ComputeError: "cannot cast any-value {:?} to dtype '{}'", self, dtype, ), @@ -474,6 +473,7 @@ impl<'a> AnyValue<'a> { ); let new_av = match self { + AnyValue::Utf8(v) => AnyValue::Utf8Owned(format_smartstring!("{}", v)), AnyValue::Boolean(v) => cast_to!(*v as u8), AnyValue::Float32(_) | AnyValue::Float64(_) => cast_to!(self.extract::().unwrap()), av if av.is_signed() => cast_to!(av.extract::().unwrap()), diff --git a/crates/polars-sql/tests/simple_exprs.rs b/crates/polars-sql/tests/simple_exprs.rs index 5ea4937f6995..cd0db4232903 100644 --- a/crates/polars-sql/tests/simple_exprs.rs +++ b/crates/polars-sql/tests/simple_exprs.rs @@ -504,6 +504,23 @@ fn test_group_by_2() -> PolarsResult<()> { Ok(()) } +#[test] +fn test_cast_and_str_concat_expr(){ + let a = Series::new("a", vec!["hello"]); + let df = DataFrame::new(vec![a]).unwrap(); + let mut context = SQLContext::new(); + context.register("df", df.clone().lazy()); + let sql = r#" + SELECT + a || ' world' as a_v2, + 'hello' || ' world' as a_v3 + FROM df"#; + let df_sql = context.execute(sql).unwrap().collect().unwrap(); + + assert_eq!(Series::new("a_v2", vec!["hello world"]),*df_sql.column("a_v2").unwrap()); + assert_eq!(Series::new("a_v3", vec!["hello world"]),*df_sql.column("a_v3").unwrap()); +} + #[test] fn test_case_expr() { let df = create_sample_df().unwrap().head(Some(10));