You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by GitBox <gi...@apache.org> on 2022/07/27 18:01:33 UTC

[GitHub] [arrow-datafusion] alamb commented on a diff in pull request #2942: add Atan2

alamb commented on code in PR #2942:
URL: https://github.com/apache/arrow-datafusion/pull/2942#discussion_r931346601


##########
datafusion/core/tests/sql/math.rs:
##########
@@ -0,0 +1,57 @@
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+
+use super::*;
+use arrow::array::Float64Array;
+
+#[tokio::test]
+async fn test_atan2() -> Result<()> {
+    let ctx = SessionContext::new();
+
+    let t1_schema = Arc::new(Schema::new(vec![
+        Field::new("x", DataType::Float64, true),
+        Field::new("y", DataType::Float64, true),
+    ]));
+
+    let t1_data = RecordBatch::try_new(
+        t1_schema.clone(),
+        vec![
+            Arc::new(Float64Array::from(vec![1.0, 1.0, -1.0, -1.0])),
+            Arc::new(Float64Array::from(vec![2.0, -2.0, 2.0, -2.0])),
+        ],
+    )?;
+    let t1_table = MemTable::try_new(t1_schema, vec![vec![t1_data]])?;
+    ctx.register_table("t1", Arc::new(t1_table))?;
+
+    let sql = "SELECT atan2(y, x) FROM t1";
+    let actual = execute_to_batches(&ctx, sql).await;
+
+    let expected = vec![

Review Comment:
   ```
   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)
   ``` 
   
   👍 



##########
datafusion/physical-expr/src/math_expressions.rs:
##########
@@ -176,11 +176,39 @@ pub fn power(args: &[ArrayRef]) -> Result<ArrayRef> {
     }
 }
 
+pub fn atan2(args: &[ArrayRef]) -> Result<ArrayRef> {
+    // FIXME other data_type?

Review Comment:
   (the type coercion already applies here)
   
   For example, I can run this on integers for example in `cargo datafusion-cli`
   
   ```sql
   ❯ 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                                              |
   +--------------------------------------------------------+
   ```
   



##########
datafusion/physical-expr/src/math_expressions.rs:
##########
@@ -176,11 +176,39 @@ pub fn power(args: &[ArrayRef]) -> Result<ArrayRef> {
     }
 }
 
+pub fn atan2(args: &[ArrayRef]) -> Result<ArrayRef> {
+    // FIXME other data_type?

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



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org