Skip to content

Commit 235e7ce

Browse files
Add tracing debug/trace logging on schema cast failures
Add tracing statements to try_cast_to() that log schema information and record batch contents when errors occur: - debug! logs actual and expected schemas on any error - trace! logs full record batch contents for detailed debugging This helps diagnose schema mismatch issues during record batch casting.
1 parent 007c82d commit 235e7ce

2 files changed

Lines changed: 26 additions & 4 deletions

File tree

datafusion-federation/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ async-trait.workspace = true
2626
datafusion.workspace = true
2727
async-stream.workspace = true
2828
arrow-json.workspace = true
29+
tracing = "0.1"
2930

3031
[dev-dependencies]
3132
tokio.workspace = true
3233
tracing-subscriber = { version = "0.3.18", features = ["env-filter"] }
33-
tracing = "0.1.40"
3434
insta = { version = "1.42.0", features = ["filters"] }
3535

3636
[[example]]

datafusion-federation/src/schema_cast/record_convert.rs

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,12 @@ pub fn try_cast_to(record_batch: RecordBatch, expected_schema: SchemaRef) -> Res
5252
let actual_schema = record_batch.schema();
5353

5454
if actual_schema.fields().len() != expected_schema.fields().len() {
55+
tracing::debug!(
56+
actual_schema = ?actual_schema,
57+
expected_schema = ?expected_schema,
58+
"Schema mismatch in try_cast_to"
59+
);
60+
tracing::trace!(record_batch = ?record_batch, "Record batch contents");
5561
return Err(Error::UnexpectedNumberOfColumns {
5662
expected: expected_schema.fields().len(),
5763
found: actual_schema.fields().len(),
@@ -122,10 +128,26 @@ pub fn try_cast_to(record_batch: RecordBatch, expected_schema: SchemaRef) -> Res
122128
.map_err(|e| Error::UnableToConvertRecordBatch { source: e }),
123129
}
124130
})
125-
.collect::<Result<Vec<Arc<dyn Array>>>>()?;
131+
.collect::<Result<Vec<Arc<dyn Array>>>>()
132+
.map_err(|e| {
133+
tracing::debug!(
134+
actual_schema = ?actual_schema,
135+
expected_schema = ?expected_schema,
136+
"Cast error in try_cast_to"
137+
);
138+
tracing::trace!(record_batch = ?record_batch, "Record batch contents");
139+
e
140+
})?;
126141

127-
RecordBatch::try_new(expected_schema, cols)
128-
.map_err(|e| Error::UnableToConvertRecordBatch { source: e })
142+
RecordBatch::try_new(expected_schema.clone(), cols).map_err(|e| {
143+
tracing::debug!(
144+
actual_schema = ?actual_schema,
145+
expected_schema = ?expected_schema,
146+
"RecordBatch creation error in try_cast_to"
147+
);
148+
tracing::trace!(record_batch = ?record_batch, "Record batch contents");
149+
Error::UnableToConvertRecordBatch { source: e }
150+
})
129151
}
130152

131153
#[cfg(test)]

0 commit comments

Comments
 (0)