Apache DataFusion SQL Query Engine
fix: schema metadata retrieval when listing parquet table (#9134)
Brayan Jules9669520bbd7b
diff --git a/datafusion/core/src/datasource/listing/table.rs b/datafusion/core/src/datasource/listing/table.rsindex 8ec16956b6..094b26bfbd 100644--- a/datafusion/core/src/datasource/listing/table.rs+++ b/datafusion/core/src/datasource/listing/table.rs@@ -548,7 +548,7 @@ impl ListingTable {})?;// Add the partition columns to the file schema- let mut builder = SchemaBuilder::from(file_schema.fields());+ let mut builder = SchemaBuilder::from(file_schema.as_ref().to_owned());for (part_col_name, part_col_type) in &options.table_partition_cols {builder.push(Field::new(part_col_name, part_col_type.clone(), false));}diff --git a/datafusion/core/tests/parquet/schema.rs b/datafusion/core/tests/parquet/schema.rsindex 30d4e11930..0dd15cb00e 100644--- a/datafusion/core/tests/parquet/schema.rs+++ b/datafusion/core/tests/parquet/schema.rs@@ -148,6 +148,10 @@ async fn schema_merge_can_preserve_metadata() {.read_parquet(&table_path, options.clone()).await.unwrap();++ let actual = df.schema().metadata();+ assert_eq!(actual.clone(), expected_metadata,);+let actual = df.collect().await.unwrap();assert_batches_sorted_eq!(expected, &actual);@@ -158,13 +162,12 @@ async fn schema_merge_can_preserve_metadata() {.await.unwrap();- let actual = ctx- .sql("SELECT * from t")- .await- .unwrap()- .collect()- .await- .unwrap();+ let df = ctx.sql("SELECT * from t").await.unwrap();++ let actual = df.schema().metadata();+ assert_eq!(actual.clone(), expected_metadata);++ let actual = df.collect().await.unwrap();assert_batches_sorted_eq!(expected, &actual);assert_metadata(&actual, &expected_metadata);}