Skip to content

Commit

Permalink
chore: cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
wiedld committed Aug 29, 2024
1 parent 2024799 commit 8cef364
Showing 1 changed file with 17 additions and 21 deletions.
38 changes: 17 additions & 21 deletions datafusion/core/src/datasource/file_format/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,44 +234,40 @@ pub(crate) fn merge_file_schema_on_view_type(
table_schema: &Schema,
file_schema: &Schema,
) -> Option<Schema> {
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<Arc<Field>> = file_schema
.fields
.iter()
.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(),
Expand Down

0 comments on commit 8cef364

Please sign in to comment.