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

Interval Arithmetic NegativeExpr Support #7804

Merged
merged 2 commits into from
Oct 12, 2023
Merged

Interval Arithmetic NegativeExpr Support #7804

merged 2 commits into from
Oct 12, 2023

Conversation

berkaysynnada
Copy link
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
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

datafusion/physical-expr/src/expressions/negative.rs Outdated Show resolved Hide resolved
datafusion/physical-expr/src/expressions/negative.rs Outdated Show resolved Hide resolved
@@ -37,16 +36,32 @@ const DT_MS_MASK: i64 = 0xFFFF_FFFF;
/// Currently, we do not support all [`PhysicalExpr`]s for interval calculations.
/// We do not support every type of [`Operator`]s either. Over time, this check
/// 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
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
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
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
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
22 checks passed
@alamb
Copy link
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 Physical Expressions
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants