Skip to content

Conversation

@waitingkuo
Copy link
Contributor

Which issue does this PR close?

Closes #2897

Rationale for this change

What changes are included in this PR?

atan2(y, x) expression

Are there any user-facing changes?

@github-actions github-actions bot added core Core DataFusion crate logical-expr Logical plan and expressions physical-expr Changes to the physical-expr crates labels Jul 18, 2022
@waitingkuo
Copy link
Contributor Author

atan2(y, x) is implemented. Do we have any test cases for validating basic math function like sin, cos? I'd like to know what's the recommended way to deal with float number (might be something like assert_f64_near!?)

@waitingkuo waitingkuo changed the title Atan2 add Atan2 Jul 18, 2022
@codecov-commenter
Copy link

Codecov Report

Merging #2942 (86fe7c9) into master (b772c6d) will increase coverage by 0.24%.
The diff coverage is 91.17%.

@@            Coverage Diff             @@
##           master    #2942      +/-   ##
==========================================
+ Coverage   85.41%   85.66%   +0.24%     
==========================================
  Files         273      280       +7     
  Lines       49495    51144    +1649     
==========================================
+ Hits        42278    43814    +1536     
- Misses       7217     7330     +113     
Impacted Files Coverage Δ
datafusion/core/tests/sql/mod.rs 98.26% <ø> (-0.56%) ⬇️
datafusion/proto/src/from_proto.rs 35.58% <0.00%> (-0.18%) ⬇️
datafusion/proto/src/to_proto.rs 53.21% <0.00%> (-0.10%) ⬇️
datafusion/physical-expr/src/math_expressions.rs 90.00% <96.96%> (+6.21%) ⬆️
datafusion/core/tests/sql/expr.rs 99.83% <100.00%> (+<0.01%) ⬆️
datafusion/core/tests/sql/math.rs 100.00% <100.00%> (ø)
datafusion/expr/src/built_in_function.rs 100.00% <100.00%> (ø)
datafusion/expr/src/expr_fn.rs 90.69% <100.00%> (+1.22%) ⬆️
datafusion/expr/src/function.rs 97.64% <100.00%> (+0.06%) ⬆️
datafusion/physical-expr/src/functions.rs 92.72% <100.00%> (+<0.01%) ⬆️
... and 30 more

Help us with your feedback. Take ten seconds to tell us how you rate us.

@waitingkuo waitingkuo marked this pull request as ready for review July 26, 2022 15:53
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 so much for the contribution @waitingkuo -- this looks great

let sql = "SELECT atan2(y, x) FROM t1";
let actual = execute_to_batches(&ctx, sql).await;

let expected = vec![
Copy link
Contributor

Choose a reason for hiding this comment

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

alamb=# select atan2(2.0, 1.0);
       atan2        
--------------------
 1.1071487177940904
(1 row)

alamb=# select atan2(-2.0, 1.0);
        atan2        
---------------------
 -1.1071487177940904
(1 row)

alamb=# select atan2(2.0, -1.0);
       atan2        
--------------------
 2.0344439357957027
(1 row)

alamb=# select atan2(-2.0, -1.0);
        atan2        
---------------------
 -2.0344439357957027
(1 row)

👍

}

pub fn atan2(args: &[ArrayRef]) -> Result<ArrayRef> {
// FIXME other data_type?
Copy link
Contributor

Choose a reason for hiding this comment

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

What does this comment mean? What other data types do you have in mind?

Copy link
Contributor

Choose a reason for hiding this comment

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

(the type coercion already applies here)

For example, I can run this on integers for example in cargo datafusion-cli

select atan2(2, 1);
+--------------------------+
| atan2(Int64(2),Int64(1)) |
+--------------------------+
| 1.1071488                |
+--------------------------+select atan2(cast(2 as int), cast(1 as int));
+--------------------------------------------------------+
| atan2(CAST(Int64(2) AS Int32),CAST(Int64(1) AS Int32)) |
+--------------------------------------------------------+
| 1.1071488                                              |
+--------------------------------------------------------+

Copy link
Contributor Author

Choose a reason for hiding this comment

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

i implemented f64 first and left this to remind me to implement f32. it turns out that i need another reminder to delete this comment...
fixed!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

if both args are f32, it will return f32 using https://doc.rust-lang.org/std/primitive.f32.html#method.atan2

@alamb
Copy link
Contributor

alamb commented Jul 27, 2022

Thanks @waitingkuo -!

@alamb alamb merged commit 176f432 into apache:master Jul 27, 2022
@ursabot
Copy link

ursabot commented Jul 27, 2022

Benchmark runs are scheduled for baseline = cd31649 and contender = 176f432. 176f432 is a master commit associated with this PR. Results will be available as each benchmark for each run completes.
Conbench compare runs links:
[Skipped ⚠️ Benchmarking of arrow-datafusion-commits is not supported on ec2-t3-xlarge-us-east-2] ec2-t3-xlarge-us-east-2
[Skipped ⚠️ Benchmarking of arrow-datafusion-commits is not supported on test-mac-arm] test-mac-arm
[Skipped ⚠️ Benchmarking of arrow-datafusion-commits is not supported on ursa-i9-9960x] ursa-i9-9960x
[Skipped ⚠️ Benchmarking of arrow-datafusion-commits is not supported on ursa-thinkcentre-m75q] ursa-thinkcentre-m75q
Buildkite builds:
Supported benchmarks:
ec2-t3-xlarge-us-east-2: Supported benchmark langs: Python, R. Runs only benchmarks with cloud = True
test-mac-arm: Supported benchmark langs: C++, Python, R
ursa-i9-9960x: Supported benchmark langs: Python, R, JavaScript
ursa-thinkcentre-m75q: Supported benchmark langs: C++, Java

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

core Core DataFusion crate logical-expr Logical plan and expressions physical-expr Changes to the physical-expr crates

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Atan2 added to built-in functions

4 participants