Skip to content

Interval Arithmetic NegativeExpr Support#7804

Merged
alamb merged 2 commits intoapache:mainfrom
synnada-ai:feature/negative-expr-interval-arithmetic
Oct 12, 2023
Merged

Interval Arithmetic NegativeExpr Support#7804
alamb merged 2 commits intoapache:mainfrom
synnada-ai:feature/negative-expr-interval-arithmetic

Conversation

@berkaysynnada
Copy link
Copy Markdown
Contributor

@berkaysynnada berkaysynnada commented Oct 12, 2023

Which issue does this PR close?

Closes #.

Rationale for this change

If there is a NegativeExpr in a PhysicalExpr, during the pruning operations of joins, we encounter a "not implemented" error. This PR enables us to use NegativeExpr's in join predicates if there is a pruning operation.

What changes are included in this PR?

NegativeExpr's evaluate_bounds() and propagate_constraints() functions are implemented.

Are these changes tested?

Yes, unit tests of propagation over NegativeExpr's are added.

Are there any user-facing changes?

Copy link
Copy Markdown
Contributor

@alamb alamb left a comment

Choose a reason for hiding this comment

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

Thank you @berkaysynnada -- this PR looks really nice to me. I had a few comment suggestions, but otherwise this looks ready to merge to me.

I also had a question about improving the interface for analysis, but that can be done separately I think

Comment thread datafusion/physical-expr/src/expressions/negative.rs Outdated
Comment thread datafusion/physical-expr/src/expressions/negative.rs Outdated
Comment thread datafusion/physical-expr/src/intervals/interval_aritmetic.rs
/// will relax as more types of `PhysicalExpr`s and `Operator`s are supported.
/// Currently, [`CastExpr`], [`BinaryExpr`], [`Column`] and [`Literal`] are supported.
pub fn check_support(expr: &Arc<dyn PhysicalExpr>) -> bool {
/// Currently, [`CastExpr`], [`NegativeExpr`], [`BinaryExpr`], [`Column`] and [`Literal`] are supported.
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.

While reviewing this PR I noticed that to add support for interval analysis to a PhysicalExpr there are at least two places that need to be changed. The impl PhysicalExpr and check_support. Besides making it somewhat harder to add interval analysis to new expression types, I also think it means that custom impls of PhysicalExpr can't be used in interval analysis.

What do you think about making it possible for custom PhysicalExprs to use interval analysis (likely by moving some part of this check into the impl PhysicalExpr)? I can file a follow on ticket if you like

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

fn supports_interval_analysis(&self) -> bool {
        false
}

Adding such method in impl PhysicalExpr is what you're thinking? If it is so, I can quickly convert it to that form.

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.

Adding such method in impl PhysicalExpr is what you're thinking? If it is so, I can quickly convert it to that form.

Yes that would be one way. Another potential might be to change the signature of evaluate_bounds to an Option so that multiple functions didn't need to kept in sync

 fn evaluate_bounds(&self, _children: &[&Interval]) -> Result<Option<Interval>> {
        Ok(None)
    }

To be clear, I think we should merge this PR as is -- maybe with documentation updates -- and then make this change as a follow on PR. That way we will unblock #7793 faster

Copy link
Copy Markdown
Contributor

@alamb alamb left a comment

Choose a reason for hiding this comment

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

Since this is an incremental feature improvement and has no API change or anything I think will cause controversy I plan to merge it in after the CI checks pass

@alamb alamb merged commit 1f4442e into apache:main Oct 12, 2023
@alamb
Copy link
Copy Markdown
Contributor

alamb commented Oct 12, 2023

Thanks again @berkaysynnada

@andygrove andygrove added the enhancement New feature or request label Nov 5, 2023
@berkaysynnada berkaysynnada deleted the feature/negative-expr-interval-arithmetic branch November 10, 2023 11:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core Core DataFusion crate enhancement New feature or request physical-expr Changes to the physical-expr crates

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants