-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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 operator section to user guide, Add std::ops
operations to prelude
, and add not()
expr_fn
#7732
Conversation
Several functions added in this PR:
Few more questions:
Edit: change r#mod to mod_ for better code completion |
Methods added to
I found that there are multiple implementations to do the same thing, e.g., bitwise operations on https://github.com/apache/arrow-datafusion/blob/a64f36d8fbce35cb7146271fb5d9ab98a9f094e6/datafusion/expr/src/expr_fn.rs#L172-L215 and https://github.com/apache/arrow-datafusion/blob/a64f36d8fbce35cb7146271fb5d9ab98a9f094e6/datafusion/expr/src/operator.rs#L313-L355, that should/is identical to each other. Do we have to merge these implementations and place tests in the same place? |
datafusion/expr/src/expr.rs
Outdated
// | ||
|
||
/// Return `self + other` | ||
#[allow(clippy::should_implement_trait)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Clippy fires warnings because these methods have same name on trait methods in std::ops
. Without these methods, user may require to include specific traits from std::ops::*
in their source. Or, should we re-export these traits in prelude?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
user may require to include specific traits from std::ops::* in their source.
I think using the std::ops
in their traits is the less surprising API and is the "idiomatic" rust way to do this. I think we should remove these methods and just use std::ops
Or, should we re-export these traits in prelude?
This would be ok with me. Alternately we could add an example to https://docs.rs/datafusion/latest/datafusion/logical_expr/enum.Expr.html saying that it is possible to use the std::ops
and show an example of a + b
or the equivalent
@@ -118,4 +118,4 @@ | |||
myst_heading_anchors = 3 | |||
|
|||
# enable nice rendering of checkboxes for the task lists | |||
myst_enable_extensions = [ "tasklist"] | |||
myst_enable_extensions = ["colon_fence", "deflist", "tasklist"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not sure if its related to this PR description 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I add some admonitions and definition list to the page that require colon_fence
and deflist
extensions.
Thanks @ongchi for the PR, I left some minor comments |
Doc is definitely looks more solid and consistent now, thanks @ongchi Another thing comes to my mind if we support both syntaxes, we should prob have some notification when new operator is introduced. |
I think we should reorganize test cases in datafusion-expr and make some improvements by creating a test module. Currently, these tests do not cover all use cases. The tests may follow the order/structure from expression API documentation, which would make it easier to identify which parts needs to be improve. |
datafusion/expr/src/expr.rs
Outdated
} | ||
|
||
/// Return `self % other` | ||
pub fn mod_(self, other: Expr) -> Expr { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
underscore in naming might be confusing
} | ||
|
||
#[test] | ||
fn test_logical_ops() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
awesome. In addition to planner test would be great to have same tests on Dataframe level to prove operators returns correct values.
Update examples and factor out the common interface (to make sure new added operator will be covered by all kind of syntaxes) can be done is follow up PR
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
datafusion/expr/src/expr.rs
Outdated
// | ||
|
||
/// Return `self + other` | ||
#[allow(clippy::should_implement_trait)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
user may require to include specific traits from std::ops::* in their source.
I think using the std::ops
in their traits is the less surprising API and is the "idiomatic" rust way to do this. I think we should remove these methods and just use std::ops
Or, should we re-export these traits in prelude?
This would be ok with me. Alternately we could add an example to https://docs.rs/datafusion/latest/datafusion/logical_expr/enum.Expr.html saying that it is possible to use the std::ops
and show an example of a + b
or the equivalent
@@ -265,7 +265,6 @@ mod test { | |||
use arrow::datatypes::DataType; | |||
use datafusion_common::tree_node::{RewriteRecursion, TreeNode, TreeNodeRewriter}; | |||
use datafusion_common::{DFField, DFSchema, ScalarValue}; | |||
use std::ops::Add; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Implementing std::ops::Add
means you can write something like expr1 + expr2
.
Converting to draft as this PR is not waiting on feedback anymore. Please mark it ready to review when ready. I do realize when writing documentation, often deficiencies in the existing APIs become clearer One suggestion I had was to split out the changes to the documentation from the changes to how the traits work.
I agree -- @ongchi could you please file a follow on ticket describing this work? Perhaps it would be a good first step in updating how the traits worked: consolidate all the existing tests we do have, so the scope of the "to do" work becomes clear. |
Sure, I'm happy to do that. I'll focus on correctness of the documentation in this PR with minimal code changes. Any further changes can depend on other users' input. |
…wise, comparison, and arithmetic expressions
std::ops
operations to prelude
, and add not()
expr_fn
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Which issue does this PR close?
Closes #7681
Rationale for this change
What changes are included in this PR?
Are these changes tested?
Are there any user-facing changes?