diff --git a/datafusion/core/src/datasource/file_format/mod.rs b/datafusion/core/src/datasource/file_format/mod.rs index 19c74b109493..7cd1d71ecfe9 100644 --- a/datafusion/core/src/datasource/file_format/mod.rs +++ b/datafusion/core/src/datasource/file_format/mod.rs @@ -234,12 +234,21 @@ pub(crate) fn merge_file_schema_on_view_type( table_schema: &Schema, file_schema: &Schema, ) -> Option { - let mut transformed = false; + let mut transform = false; let table_fields: HashMap<_, _> = table_schema .fields .iter() - .map(|f| (f.name(), f.data_type())) + .map(|f| { + let dt = f.data_type(); + if dt.equals_datatype(&DataType::Utf8View) { + transform = true; + } + (f.name(), dt) + }) .collect(); + if !transform { + return None; + } let transformed_fields: Vec> = file_schema .fields @@ -247,31 +256,18 @@ pub(crate) fn merge_file_schema_on_view_type( .map( |field| match (table_fields.get(field.name()), field.data_type()) { (Some(DataType::Utf8View), DataType::Utf8) - | (Some(DataType::Utf8View), DataType::LargeUtf8) => { - transformed = true; - Arc::new(Field::new( - field.name(), - DataType::Utf8View, - field.is_nullable(), - )) - } + | (Some(DataType::Utf8View), DataType::LargeUtf8) => Arc::new( + Field::new(field.name(), DataType::Utf8View, field.is_nullable()), + ), (Some(DataType::BinaryView), DataType::Binary) - | (Some(DataType::BinaryView), DataType::LargeBinary) => { - transformed = true; - Arc::new(Field::new( - field.name(), - DataType::BinaryView, - field.is_nullable(), - )) - } + | (Some(DataType::BinaryView), DataType::LargeBinary) => Arc::new( + Field::new(field.name(), DataType::BinaryView, field.is_nullable()), + ), _ => field.clone(), }, ) .collect(); - if !transformed { - return None; - } Some(Schema::new_with_metadata( transformed_fields, file_schema.metadata.clone(),