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 evaluate_demo and range_analysis_demo to Expr examples #8377

Merged
merged 6 commits into from
Dec 8, 2023

Conversation

alamb
Copy link
Contributor

@alamb alamb commented Nov 30, 2023

Which issue does this PR close?

Part of #7013

Rationale for this change

As part of updating DataFusion internally in IOx https://github.com/influxdata/influxdb_iox/pull/9428 , I found that we had code that used the range analysis code directly and thus had to be changed due to #8276

I found that DataFusion has a much nicer interface to do this analyze but I didn't think it was particularly obvious how to do so

It also came up on #8306 (comment) that it was non trivial to figure out how to evaluate expressions, so I added an example of how to do that as well

What changes are included in this PR?

  1. Add example of using analysis APIs
  2. Add example of evaluating an Expr, which is not as obvious either

Are these changes tested?

Are there any user-facing changes?

@github-actions github-actions bot added physical-expr Physical Expressions core Core DataFusion crate labels Nov 30, 2023
/// DataFusion also has APIs for analyzing predicates (boolean expressions) to
/// determine any ranges restrictions on the inputs required for the predicate
/// evaluate to true.
fn range_analysis_demo() -> Result<()> {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is a really powerful feature of DataFusion and I don't think it is widely understood yet

@alamb alamb marked this pull request as ready for review November 30, 2023 19:39
@@ -111,6 +115,22 @@ impl ExprBoundaries {
distinct_count: col_stats.distinct_count.clone(),
})
}

/// Create `ExprBoundaries` that represent no known bounds for all the columns `schema`
pub fn try_new_unknown(schema: &Schema) -> Result<Vec<Self>> {
Copy link
Contributor Author

@alamb alamb Nov 30, 2023

Choose a reason for hiding this comment

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

This was added to make the demo easier to write (I ported it from IOx downstream)

Copy link
Contributor

Choose a reason for hiding this comment

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

Might unbounded be more obvious a name than unknown?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Might unbounded be more obvious a name than unknown?

I agree -- will change.

@alamb alamb added documentation Improvements or additions to documentation devrel labels Nov 30, 2023
@alamb alamb requested a review from andygrove December 5, 2023 20:45
@alamb
Copy link
Contributor Author

alamb commented Dec 5, 2023

cc @ozankabak / @berkaysynnada / @metesynnada as this PR adds examples to some of the great features you have added

@berkaysynnada
Copy link
Contributor

These are really good demos. The utility functions you've added also make sense to me. Thanks, @alamb.

datafusion-examples/examples/expr_api.rs Outdated Show resolved Hide resolved
@@ -111,6 +115,22 @@ impl ExprBoundaries {
distinct_count: col_stats.distinct_count.clone(),
})
}

/// Create `ExprBoundaries` that represent no known bounds for all the columns `schema`
pub fn try_new_unknown(schema: &Schema) -> Result<Vec<Self>> {
Copy link
Contributor

Choose a reason for hiding this comment

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

Might unbounded be more obvious a name than unknown?

@github-actions github-actions bot removed the documentation Improvements or additions to documentation label Dec 8, 2023
@alamb alamb merged commit 91cc573 into apache:main Dec 8, 2023
23 checks passed
@alamb alamb deleted the alamb/document_analysis branch December 8, 2023 21:44
appletreeisyellow pushed a commit to appletreeisyellow/datafusion that referenced this pull request Dec 15, 2023
…e#8377)

* Add `evaluate_demo` and `range_analysis_demo` to Expr examples

* Prettier

* Update datafusion-examples/examples/expr_api.rs

Co-authored-by: Raphael Taylor-Davies <[email protected]>

* rename ExprBoundaries::try_new_unknown --> ExprBoundaries::try_new_unbounded

---------

Co-authored-by: Raphael Taylor-Davies <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core Core DataFusion crate physical-expr Physical Expressions
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants