Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion datafusion/core/tests/sql/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ async fn csv_query_error() -> Result<()> {
register_aggregate_csv(&ctx).await?;
let sql = "SELECT sin(c1) FROM aggregate_test_100";
let plan = ctx.create_logical_plan(sql);
assert!(plan.is_err());
// NOTE(cubesql): this coercion is supported
// assert!(plan.is_err());
assert!(plan.is_ok());
Ok(())
}

Expand Down
21 changes: 16 additions & 5 deletions datafusion/expr/src/type_coercion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,18 @@ pub fn data_types(
}
let valid_types = get_valid_types(&signature.type_signature, current_types)?;

if valid_types
.iter()
.any(|data_type| data_type == current_types)
{
return Ok(current_types.to_vec());
if let Some(types) = valid_types.iter().find(|data_types| {
if data_types.len() != current_types.len() {
return false;
}
data_types
.iter()
.zip(current_types)
.all(|(data_type, current_type)| {
data_type == current_type || matches!(current_type, DataType::Null)
})
}) {
return Ok(types.clone());
}

for valid_types in valid_types {
Expand Down Expand Up @@ -145,6 +152,10 @@ fn maybe_data_types(
/// See the module level documentation for more detail on coercion.
pub fn can_coerce_from(type_into: &DataType, type_from: &DataType) -> bool {
use self::DataType::*;
// Strings can be converted to most types implicitly
if matches!(type_from, Utf8 | LargeUtf8) {
return true;
}
// Null can convert to most of types
match type_into {
Int8 => matches!(type_from, Null | Int8),
Expand Down
Loading