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

[PERF] Evaluate only true/false side of if_else if predicate is boolean #2222

Merged
merged 3 commits into from
May 2, 2024

Conversation

colin-ho
Copy link
Contributor

@colin-ho colin-ho commented May 2, 2024

Closes #2190

If the predicate for an if_else statement is a boolean, i.e true/false, we only need to evaluate one side of the expression.

@colin-ho colin-ho marked this pull request as ready for review May 2, 2024 20:20
Copy link

codecov bot commented May 2, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

❗ No coverage uploaded for pull request base (main@99a0ac0). Click here to learn what that means.
Report is 1 commits behind head on main.

❗ Current head fda4a2e differs from pull request most recent head 0313410. Consider uploading reports for the commit 0313410 to get more accurate results

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##             main    #2222   +/-   ##
=======================================
  Coverage        ?   85.59%           
=======================================
  Files           ?       71           
  Lines           ?     7586           
  Branches        ?        0           
=======================================
  Hits            ?     6493           
  Misses          ?     1093           
  Partials        ?        0           

Err(_) => Err(DaftError::TypeError(format!("Expected if_true and if_false arguments for if_else to be castable to the same supertype, but received {if_true_field} and {if_false_field}")))
match predicate.as_ref() {
Expr::Literal(lit::LiteralValue::Boolean(true)) => if_true.to_field(schema),
Expr::Literal(lit::LiteralValue::Boolean(false)) => if_false.to_field(schema),
Copy link
Contributor

Choose a reason for hiding this comment

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

The tricky bit for me in this PR is the conditional selection of the resultant column's name... Which feels a little ick.

Though I'm not sure what the best behavior is here. It feels a little icky to me though that depending on the inputs, the output expression name can change.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agreed, I'll keep it consistent with the current behavior to use the if_true expression name.

Though I think this may not be the best user experience either, in fact I'm not sure if there is a way to aptly name an if_else expression. We can consider writing in the if_else docs that it's best practice to use if_else in a with_column, or with an alias

@colin-ho colin-ho merged commit da991c5 into main May 2, 2024
27 checks passed
@colin-ho colin-ho deleted the colin/if_else_literal_predicate branch May 2, 2024 23:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants