Skip to content

Apache DataFusion SQL Query Engine

Add to_unoptimized_plan (#3344)

Ian Alexander Joiner5bdd55b53243
diff --git a/datafusion/core/src/dataframe.rs b/datafusion/core/src/dataframe.rs
index bb572b7d5c..cf7803494a 100644
--- a/datafusion/core/src/dataframe.rs
+++ b/datafusion/core/src/dataframe.rs
@@ -520,7 +520,13 @@ impl DataFrame {
self.plan.schema()
}
- /// Return the logical plan represented by this DataFrame.
+ /// Return the unoptimized logical plan represented by this DataFrame.
+ pub fn to_unoptimized_plan(&self) -> LogicalPlan {
+ // Optimize the plan first for better UX
+ self.plan.clone()
+ }
+
+ /// Return the optimized logical plan represented by this DataFrame.
pub fn to_logical_plan(&self) -> Result<LogicalPlan> {
// Optimize the plan first for better UX
let state = self.session_state.read().clone();
@@ -1258,6 +1264,17 @@ mod tests {
);
let df_renamed = df.with_column_renamed("t1.c1", "AAA")?;
+
+ assert_eq!("\
+ Projection: #t1.c1 AS AAA, #t1.c2, #t1.c3, #t2.c1, #t2.c2, #t2.c3\
+ \n Limit: skip=None, fetch=1\
+ \n Sort: #t1.c1 ASC NULLS FIRST, #t1.c2 ASC NULLS FIRST, #t1.c3 ASC NULLS FIRST, #t2.c1 ASC NULLS FIRST, #t2.c2 ASC NULLS FIRST, #t2.c3 ASC NULLS FIRST\
+ \n Inner Join: #t1.c1 = #t2.c1\
+ \n TableScan: t1\
+ \n TableScan: t2",
+ format!("{:?}", df_renamed.to_unoptimized_plan())
+ );
+
assert_eq!("\
Projection: #t1.c1 AS AAA, #t1.c2, #t1.c3, #t2.c1, #t2.c2, #t2.c3\
\n Limit: skip=None, fetch=1\