Skip to content

Commit 7788c73

Browse files
authored
Minor: verify plan output and unique field names (#20220)
## Which issue does this PR close? - Follow on to #20146 from @nuno-faria ## Rationale for this change While reviewing the change with Codex, I noticed that the actual output names and their uniqueness were not verified, which I think would help the coverage ## What changes are included in this PR? Extend the test ## Are these changes tested? Yes it is only tests ## Are there any user-facing changes? No
1 parent 8fc9681 commit 7788c73

1 file changed

Lines changed: 24 additions & 1 deletion

File tree

datafusion/substrait/tests/cases/logical_plans.rs

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020
#[cfg(test)]
2121
mod tests {
2222
use crate::utils::test::{add_plan_schemas_to_ctx, read_json};
23+
use datafusion::common::test_util::format_batches;
24+
use std::collections::HashSet;
25+
2326
use datafusion::common::Result;
2427
use datafusion::dataframe::DataFrame;
2528
use datafusion::prelude::SessionContext;
@@ -250,7 +253,27 @@ mod tests {
250253
);
251254

252255
// Trigger execution to ensure plan validity
253-
DataFrame::new(ctx.state(), plan).show().await?;
256+
let results = DataFrame::new(ctx.state(), plan).collect().await?;
257+
258+
assert_snapshot!(
259+
format_batches(&results)?,
260+
@r"
261+
+------+------+
262+
| col1 | col2 |
263+
+------+------+
264+
| 100 | 200 |
265+
| 300 | 400 |
266+
+------+------+
267+
",
268+
);
269+
270+
// also verify that the output schema has unique field names
271+
let schema = results[0].schema();
272+
for batch in &results {
273+
assert_eq!(schema, batch.schema());
274+
}
275+
let field_names: HashSet<_> = schema.fields().iter().map(|f| f.name()).collect();
276+
assert_eq!(field_names.len(), schema.fields().len());
254277

255278
Ok(())
256279
}

0 commit comments

Comments
 (0)