Skip to content

Simplify ProjectionPushdown and make it more general - #8109

Merged
alamb merged 5 commits into
apache:mainfrom
alamb:alamb/more_general
Nov 10, 2023
Merged

Simplify ProjectionPushdown and make it more general#8109
alamb merged 5 commits into
apache:mainfrom
alamb:alamb/more_general

Conversation

@alamb

@alambalamb commented Nov 9, 2023

Copy link
Copy Markdown
Contributor

Which issue does this PR close?

Follow on to #8073

Rationale for this change

I noticed some ways the code could be simplified and made more general while reviewing the PR,

What changes are included in this PR?

  1. Use TreeNode::transform_down instead of a manual tree walk to rewrite expressions
  2. pull a common check out of each branch

Are these changes tested?

Yes, by existing tests

Are there any user-facing changes?

@github-actionsgithub-actionsBot added the core Core DataFusion crate label Nov 9, 2023

// If the projection does not narrow the the schema, we should not try
// to push it down
if projection.expr().len() >= projection.input().schema().fields().len() {

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

I pulled this out of the individual try_swapping_* calls

{
return Ok(None);
}
let new_expr = expr

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

I rewrote this logic to use TreeNode recursion / rewriting rather than a manual recursion, which I think is both less code and is more general (handles all PhysicalExprs, not just the ones explicitly checked for here)

@alamb
alamb marked this pull request as ready for review November 9, 2023 14:27
@alamb
alamb marked this pull request as draft November 9, 2023 14:27
@alamb

alamb commented Nov 9, 2023

Copy link
Copy Markdown
ContributorAuthor

Some test is failing -- I will debug it later

@alamb
alambforce-pushed the alamb/more_general branch from ed89a21 to b29b097CompareNovember 9, 2023 16:39
/// Convenience utils for writing optimizers rule: recursively apply the given 'op' first to all of its
/// children and then itself(Postorder Traversal) using a mutable function, `F`.
/// When the `op` does not apply to a given node, it is left unchanged.
fn transform_up_mut<F>(self, op: &mut F) -> Result<Self>

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

mut variant is needed to support changing a variable in the closure (updating state)

@alamb
alamb marked this pull request as ready for review November 9, 2023 17:11
@alamb

alamb commented Nov 9, 2023

Copy link
Copy Markdown
ContributorAuthor

cc @berkaysynnada

@ozankabakozankabak left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM apart from one idiom suggestion. I'll let @berkaysynnada take a look and make sure all is right, then this will be good to go from our perspective. Thanks Andrew

Comment threaddatafusion/core/src/physical_optimizer/projection_pushdown.rs Outdated
Comment threaddatafusion/core/src/physical_optimizer/projection_pushdown.rs Outdated
@berkaysynnada

Copy link
Copy Markdown
Contributor

Thanks @alamb, that function will possibly be used for future iterations as well. It's better now.

Co-authored-by: Berkay Şahin <124376117+berkaysynnada@users.noreply.github.com>
Co-authored-by: Mehmet Ozan Kabak <ozankabak@gmail.com>

@ozankabakozankabak left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM, thank you

@alamb
alamb merged commit e305bcf into apache:mainNov 10, 2023
@alamb
alamb deleted the alamb/more_general branch November 10, 2023 21:04
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

coreCore DataFusion crate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

@alamb@berkaysynnada@ozankabak