Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add to_unoptimized_plan #3344

Merged
merged 3 commits into from
Sep 2, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion datafusion/core/src/dataframe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if a better name would be to_unoptimized_plan?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure. Do we need to specify that it is a logical as opposed to physical plan in the name?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think so, because the return type is LogicalPlan

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@andygrove Done!

// 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();
Expand Down Expand Up @@ -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\
Expand Down