Skip to content

Apache DataFusion SQL Query Engine

Add a LogicalPlanBuilder::schema() function (#1075)

Andrew Lamb396cb79c736f
diff --git a/datafusion/src/logical_plan/builder.rs b/datafusion/src/logical_plan/builder.rs
index 20908d7df8..c23102cfef 100644
--- a/datafusion/src/logical_plan/builder.rs
+++ b/datafusion/src/logical_plan/builder.rs
@@ -94,6 +94,11 @@ impl LogicalPlanBuilder {
Self { plan }
}
+ /// Return the output schema of the plan build so far
+ pub fn schema(&self) -> &DFSchemaRef {
+ self.plan.schema()
+ }
+
/// Create an empty relation.
///
/// `produce_one_row` set to true means this empty node needs to produce a placeholder row.
@@ -680,6 +685,18 @@ mod tests {
Ok(())
}
+ #[test]
+ fn plan_builder_schema() {
+ let schema = employee_schema();
+ let plan =
+ LogicalPlanBuilder::scan_empty(Some("employee_csv"), &schema, None).unwrap();
+
+ let expected =
+ DFSchema::try_from_qualified_schema("employee_csv", &schema).unwrap();
+
+ assert_eq!(&expected, plan.schema().as_ref())
+ }
+
#[test]
fn plan_builder_aggregate() -> Result<()> {
let plan = LogicalPlanBuilder::scan_empty(