Skip to content

Apache DataFusion SQL Query Engine

Minor: Add debug logging for schema mismatch errors (#6626)

Andrew Lambaebe71eace36
diff --git a/datafusion/core/src/datasource/memory.rs b/datafusion/core/src/datasource/memory.rs
index f66b44e9d1..3f6316d28a 100644
--- a/datafusion/core/src/datasource/memory.rs
+++ b/datafusion/core/src/datasource/memory.rs
@@ -18,6 +18,7 @@
//! [`MemTable`] for querying `Vec<RecordBatch>` by DataFusion.
use futures::StreamExt;
+use log::debug;
use std::any::Any;
use std::fmt::{self, Debug, Display};
use std::sync::Arc;
@@ -55,23 +56,26 @@ pub struct MemTable {
impl MemTable {
/// Create a new in-memory table from the provided schema and record batches
pub fn try_new(schema: SchemaRef, partitions: Vec<Vec<RecordBatch>>) -> Result<Self> {
- if partitions
- .iter()
- .flatten()
- .all(|batches| schema.contains(&batches.schema()))
- {
- Ok(Self {
- schema,
- batches: partitions
- .into_iter()
- .map(|e| Arc::new(RwLock::new(e)))
- .collect::<Vec<_>>(),
- })
- } else {
- Err(DataFusionError::Plan(
- "Mismatch between schema and batches".to_string(),
- ))
+ for batches in partitions.iter().flatten() {
+ let batches_schema = batches.schema();
+ if !schema.contains(&batches_schema) {
+ debug!(
+ "mem table schema does not contain batches schema. \
+ Target_schema: {schema:?}. Batches Schema: {batches_schema:?}"
+ );
+ return Err(DataFusionError::Plan(
+ "Mismatch between schema and batches".to_string(),
+ ));
+ }
}
+
+ Ok(Self {
+ schema,
+ batches: partitions
+ .into_iter()
+ .map(|e| Arc::new(RwLock::new(e)))
+ .collect::<Vec<_>>(),
+ })
}
/// Create a mem table by reading from another data source
diff --git a/datafusion/core/src/datasource/streaming.rs b/datafusion/core/src/datasource/streaming.rs
index 4a234fbe13..a5fc6f1929 100644
--- a/datafusion/core/src/datasource/streaming.rs
+++ b/datafusion/core/src/datasource/streaming.rs
@@ -25,6 +25,7 @@ use async_trait::async_trait;
use datafusion_common::{DataFusionError, Result};
use datafusion_expr::{Expr, TableType};
+use log::debug;
use crate::datasource::TableProvider;
use crate::execution::context::{SessionState, TaskContext};
@@ -53,10 +54,17 @@ impl StreamingTable {
schema: SchemaRef,
partitions: Vec<Arc<dyn PartitionStream>>,
) -> Result<Self> {
- if !partitions.iter().all(|x| schema.contains(x.schema())) {
- return Err(DataFusionError::Plan(
- "Mismatch between schema and batches".to_string(),
- ));
+ for x in partitions.iter() {
+ let partition_schema = x.schema();
+ if !schema.contains(partition_schema) {
+ debug!(
+ "target schema does not contain partition schema. \
+ Target_schema: {schema:?}. Partiton Schema: {partition_schema:?}"
+ );
+ return Err(DataFusionError::Plan(
+ "Mismatch between schema and batches".to_string(),
+ ));
+ }
}
Ok(Self {
diff --git a/datafusion/core/src/physical_plan/streaming.rs b/datafusion/core/src/physical_plan/streaming.rs
index 0555c1ce28..797e19c467 100644
--- a/datafusion/core/src/physical_plan/streaming.rs
+++ b/datafusion/core/src/physical_plan/streaming.rs
@@ -26,6 +26,7 @@ use futures::stream::StreamExt;
use datafusion_common::{DataFusionError, Result, Statistics};
use datafusion_physical_expr::PhysicalSortExpr;
+use log::debug;
use crate::datasource::streaming::PartitionStream;
use crate::physical_plan::stream::RecordBatchStreamAdapter;
@@ -48,10 +49,17 @@ impl StreamingTableExec {
projection: Option<&Vec<usize>>,
infinite: bool,
) -> Result<Self> {
- if !partitions.iter().all(|x| schema.contains(x.schema())) {
- return Err(DataFusionError::Plan(
- "Mismatch between schema and batches".to_string(),
- ));
+ for x in partitions.iter() {
+ let partition_schema = x.schema();
+ if !schema.contains(partition_schema) {
+ debug!(
+ "target schema does not contain partition schema. \
+ Target_schema: {schema:?}. Partiton Schema: {partition_schema:?}"
+ );
+ return Err(DataFusionError::Plan(
+ "Mismatch between schema and batches".to_string(),
+ ));
+ }
}
let projected_schema = match projection {