From 6249591f8c5f5f16095d159940822d53edd325f1 Mon Sep 17 00:00:00 2001 From: Ian Joiner Date: Fri, 2 Sep 2022 14:35:27 -0400 Subject: [PATCH 1/3] Add to_raw_logical_plan --- datafusion/core/src/dataframe.rs | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/datafusion/core/src/dataframe.rs b/datafusion/core/src/dataframe.rs index bb572b7d5cec..0f990de0a9e9 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 raw (i.e. unoptimized) logical plan represented by this DataFrame. + pub fn to_raw_logical_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 { // 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_raw_logical_plan()) + ); + assert_eq!("\ Projection: #t1.c1 AS AAA, #t1.c2, #t1.c3, #t2.c1, #t2.c2, #t2.c3\ \n Limit: skip=None, fetch=1\ From 094e66ddf03a4dc7ceae812616f9e8bd7f12a908 Mon Sep 17 00:00:00 2001 From: Ian Joiner Date: Fri, 2 Sep 2022 16:19:05 -0400 Subject: [PATCH 2/3] rename the new func --- datafusion/core/src/dataframe.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/datafusion/core/src/dataframe.rs b/datafusion/core/src/dataframe.rs index 0f990de0a9e9..4ef74ba61c79 100644 --- a/datafusion/core/src/dataframe.rs +++ b/datafusion/core/src/dataframe.rs @@ -520,8 +520,8 @@ impl DataFrame { self.plan.schema() } - /// Return the raw (i.e. unoptimized) logical plan represented by this DataFrame. - pub fn to_raw_logical_plan(&self) -> LogicalPlan { + /// Return the unoptimized logical plan represented by this DataFrame. + pub fn to_unoptimized_logical_plan(&self) -> LogicalPlan { // Optimize the plan first for better UX self.plan.clone() } @@ -1272,7 +1272,7 @@ mod tests { \n Inner Join: #t1.c1 = #t2.c1\ \n TableScan: t1\ \n TableScan: t2", - format!("{:?}", df_renamed.to_raw_logical_plan()) + format!("{:?}", df_renamed.to_unoptimized_logical_plan()) ); assert_eq!("\ From dc03f409906c3e478857d67d0fbb2324a6156991 Mon Sep 17 00:00:00 2001 From: Ian Joiner Date: Fri, 2 Sep 2022 16:22:03 -0400 Subject: [PATCH 3/3] change func name to to_unoptimized_plan --- datafusion/core/src/dataframe.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/datafusion/core/src/dataframe.rs b/datafusion/core/src/dataframe.rs index 4ef74ba61c79..cf7803494a0c 100644 --- a/datafusion/core/src/dataframe.rs +++ b/datafusion/core/src/dataframe.rs @@ -521,7 +521,7 @@ impl DataFrame { } /// Return the unoptimized logical plan represented by this DataFrame. - pub fn to_unoptimized_logical_plan(&self) -> LogicalPlan { + pub fn to_unoptimized_plan(&self) -> LogicalPlan { // Optimize the plan first for better UX self.plan.clone() } @@ -1272,7 +1272,7 @@ mod tests { \n Inner Join: #t1.c1 = #t2.c1\ \n TableScan: t1\ \n TableScan: t2", - format!("{:?}", df_renamed.to_unoptimized_logical_plan()) + format!("{:?}", df_renamed.to_unoptimized_plan()) ); assert_eq!("\