You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "melgenek (via GitHub)" <gi...@apache.org> on 2023/01/27 09:27:59 UTC

[GitHub] [arrow-datafusion] melgenek opened a new pull request, #5086: [sqllogictest] Move `decimal.rs` tests

melgenek opened a new pull request, #5086:
URL: https://github.com/apache/arrow-datafusion/pull/5086

   # Which issue does this PR close?
   
   <!--
   We generally require a GitHub issue to be filed for all bug fixes and enhancements and this helps us generate change logs for our releases. You can link an issue to this PR using the GitHub syntax. For example `Closes #123` indicates that this PR will close issue #123.
   -->
   
   Part of #4495
   
   # Rationale for this change
   
   Data-driven tests could be described in sqllogictest.
   
   <!--
    Why are you proposing this change? If this is already explained clearly in the issue then this section is not needed.
    Explaining clearly why changes are proposed helps reviewers understand your changes and offer better suggestions for fixes.  
   -->
   
   # What changes are included in this PR?
   
   Moves the tests that expect results from `decimal.rs` to sqllogictest.
   
   <!--
   There is no need to duplicate the description in the issue here but it is sometimes worth providing a summary of the individual changes in this PR.
   -->
   
   # Are these changes tested?
   
   Github actions sqllogictest job.
   
   <!--
   We typically require tests for all PRs in order to:
   1. Prevent the code from being accidentally broken by subsequent changes
   2. Serve as another way to document the expected behavior of the code
   
   If tests are not included in your PR, please explain why (for example, are they covered by existing tests)?
   -->
   
   # Are there any user-facing changes?
   
   No.
   
   <!--
   If there are user-facing changes then we may require documentation to be updated before approving the PR.
   -->
   
   <!--
   If there are any breaking changes to public APIs, please add the `api change` label.
   -->


-- 
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


[GitHub] [arrow-datafusion] alamb commented on a diff in pull request #5086: [sqllogictest] Move `decimal.rs` tests

Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb commented on code in PR #5086:
URL: https://github.com/apache/arrow-datafusion/pull/5086#discussion_r1089417112


##########
datafusion/core/tests/sql/decimal.rs:
##########
@@ -18,839 +18,256 @@
 use super::*;
 
 #[tokio::test]
-async fn decimal_cast() -> Result<()> {
+async fn decimal_cast_precision() -> Result<()> {
     let ctx = SessionContext::new();
     let sql = "select cast(1.23 as decimal(10,4))";
     let actual = execute_to_batches(&ctx, sql).await;
     assert_eq!(

Review Comment:
   Like below, I think you can write these tests using `arrow_typeof` -- like 
   
   ```sql
   ❯ select arrow_typeof(cast(1.23 as decimal(10,4)));
   +----------------------------+
   | arrowtypeof(Float64(1.23)) |
   +----------------------------+
   | Decimal128(10, 4)          |
   +----------------------------+
   ```



##########
datafusion/core/tests/sql/decimal.rs:
##########
@@ -879,37 +296,3 @@ async fn decimal_null_array_scalar_comparison() -> Result<()> {
     assert_eq!(&DataType::Boolean, actual[0].column(0).data_type());

Review Comment:
   I wonder if you could use `arrow_typeof` to do the check
   
   ```sql
   ❯ select null <= a from (values (1.1::decimal)) as t(a);
   +-----------+
   | NULL <= a |
   +-----------+
   |           |
   +-----------+
   1 row in set. Query took 0.029 seconds.
   ❯ select arrow_typeof(null <= a) from (values (1.1::decimal)) as t(a);
   +------------------------+
   | arrowtypeof(NULL <= a) |
   +------------------------+
   | Boolean                |
   +------------------------+
   1 row in set. Query took 0.006 seconds.
   ```



-- 
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


[GitHub] [arrow-datafusion] alamb merged pull request #5086: [sqllogictest] Move `decimal.rs` tests

Posted by "alamb (via GitHub)" <gi...@apache.org>.
alamb merged PR #5086:
URL: https://github.com/apache/arrow-datafusion/pull/5086


-- 
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


[GitHub] [arrow-datafusion] melgenek commented on a diff in pull request #5086: [sqllogictest] Move `decimal.rs` tests

Posted by "melgenek (via GitHub)" <gi...@apache.org>.
melgenek commented on code in PR #5086:
URL: https://github.com/apache/arrow-datafusion/pull/5086#discussion_r1089553803


##########
datafusion/core/tests/sqllogictests/test_files/decimal.slt:
##########
@@ -0,0 +1,594 @@
+# 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.
+
+query ?R
+select arrow_typeof(cast(1.23 as decimal(10,4))),
+       cast(1.23 as decimal(10,4));
+----
+Decimal128(10, 4) 1.23
+
+
+query ?R
+select arrow_typeof(cast(cast(1.23 as decimal(10,3)) as decimal(10,4))),
+       cast(cast(1.23 as decimal(10,3)) as decimal(10,4));
+----
+Decimal128(10, 4) 1.23
+
+
+query ?R
+select arrow_typeof(cast(1.2345 as decimal(24,2))), cast(1.2345 as decimal(24,2));
+----
+Decimal128(24, 2) 1.23
+
+
+query ok
+CREATE EXTERNAL TABLE decimal_simple (
+c1 DECIMAL(10,6) NOT NULL,
+c2 DOUBLE NOT NULL,
+c3 BIGINT NOT NULL,
+c4 BOOLEAN NOT NULL,
+c5 DECIMAL(12,7) NOT NULL
+)
+STORED AS CSV
+WITH HEADER ROW
+LOCATION 'tests/data/decimal_data.csv';
+
+
+query ??
+select arrow_typeof(c1), arrow_typeof(c5) from decimal_simple where c1 > c5 limit 1;
+----
+Decimal128(10, 6) Decimal128(12, 7)
+
+
+query R
+SELECT c1 from decimal_simple;
+----
+0.00001
+0.00002
+0.00002
+0.00003
+0.00003
+0.00003
+0.00004
+0.00004
+0.00004
+0.00004
+0.00005
+0.00005
+0.00005
+0.00005
+0.00005
+
+
+query R
+select c1 from decimal_simple where c1 > 0.000030;
+----
+0.00004
+0.00004
+0.00004
+0.00004
+0.00005
+0.00005
+0.00005
+0.00005
+0.00005
+
+
+query RRI?R
+select * from decimal_simple where c1 > c5;
+----
+0.00002 0.000000000002 3 false 0.000019
+0.00003 0.000000000003 5 true 0.000011
+0.00005 0.000000000005 8 false 0.000033
+
+
+query ?R
+select arrow_typeof(min(c1)), min(c1) from decimal_simple where c4=false;
+----
+Decimal128(10, 6) 0.00002
+
+
+query ?R
+select arrow_typeof(max(c1)), max(c1) from decimal_simple where c4=false;
+----
+Decimal128(10, 6) 0.00005
+
+
+# inferred precision is 10+10
+# inferred scale is the original scale
+query R
+select arrow_typeof(sum(c1)), sum(c1) from decimal_simple;
+----
+Decimal128(20, 6) 0.00055
+
+
+# inferred precision is original precision + 4
+# inferred scale is the original scale + 4
+query ?R
+select arrow_typeof(avg(c1)), avg(c1) from decimal_simple;
+----
+Decimal128(14, 10) 0.0000366666
+
+
+query RRI?R
+select * from decimal_simple where c1=CAST(0.00002 as Decimal(10,8));
+----
+0.00002 0.000000000002 2 true 0.000025
+0.00002 0.000000000002 3 false 0.000019
+
+
+query RI
+select c2,c3 from decimal_simple where c1!=0.00002;
+----
+0.000000000001 1
+0.000000000003 4
+0.000000000003 5
+0.000000000003 5
+0.000000000004 5
+0.000000000004 12
+0.000000000004 14
+0.000000000004 8
+0.000000000005 9
+0.000000000005 4
+0.000000000005 8
+0.000000000005 100
+0.000000000005 1
+
+
+query RRI?R
+select * from decimal_simple where 0.00002 > c1;
+----
+0.00001 0.000000000001 1 true 0.000014
+
+
+query RRI?R
+select * from decimal_simple where c1 <= 0.00002;
+----
+0.00001 0.000000000001 1 true 0.000014
+0.00002 0.000000000002 2 true 0.000025
+0.00002 0.000000000002 3 false 0.000019
+
+
+query RRI?R
+select * from decimal_simple where c1 > 0.00002;
+----
+0.00003 0.000000000003 4 true 0.000032
+0.00003 0.000000000003 5 false 0.000035
+0.00003 0.000000000003 5 true 0.000011
+0.00004 0.000000000004 5 true 0.000044
+0.00004 0.000000000004 12 false 0.00004
+0.00004 0.000000000004 14 true 0.00004
+0.00004 0.000000000004 8 false 0.000044
+0.00005 0.000000000005 9 true 0.000052
+0.00005 0.000000000005 4 true 0.000078
+0.00005 0.000000000005 8 false 0.000033
+0.00005 0.000000000005 100 true 0.000068
+0.00005 0.000000000005 1 false 0.0001
+
+
+query RRI?R
+select * from decimal_simple where c1 >= 0.00002;
+----
+0.00002 0.000000000002 2 true 0.000025
+0.00002 0.000000000002 3 false 0.000019
+0.00003 0.000000000003 4 true 0.000032
+0.00003 0.000000000003 5 false 0.000035
+0.00003 0.000000000003 5 true 0.000011
+0.00004 0.000000000004 5 true 0.000044
+0.00004 0.000000000004 12 false 0.00004
+0.00004 0.000000000004 14 true 0.00004
+0.00004 0.000000000004 8 false 0.000044
+0.00005 0.000000000005 9 true 0.000052
+0.00005 0.000000000005 4 true 0.000078
+0.00005 0.000000000005 8 false 0.000033
+0.00005 0.000000000005 100 true 0.000068
+0.00005 0.000000000005 1 false 0.0001
+
+
+query ?
+select arrow_typeof(c1+1) from decimal_simple limit 1;
+----
+Decimal128(27, 6)
+
+
+query R
+select c1+1 from decimal_simple;
+----
+1.00001
+1.00002
+1.00002
+1.00003
+1.00003
+1.00003
+1.00004
+1.00004
+1.00004
+1.00004
+1.00005
+1.00005
+1.00005
+1.00005
+1.00005
+
+
+# array decimal(10,6) + array decimal(12,7) => decimal(13,7)
+query ?
+select arrow_typeof(c1+c5) from decimal_simple limit 1;
+----
+Decimal128(13, 7)
+
+
+query R
+select c1+c5 from decimal_simple;
+----
+0.000024
+0.000045
+0.000039
+0.000062
+0.000065
+0.000041
+0.000084
+0.00008
+0.00008
+0.000084
+0.000102
+0.000128
+0.000083
+0.000118
+0.00015
+
+
+query ?
+select arrow_typeof(c1-1) from decimal_simple limit 1;
+----
+Decimal128(27, 6)
+
+
+query R
+select c1-1 from decimal_simple;
+----
+-0.99999
+-0.99998
+-0.99998
+-0.99997
+-0.99997
+-0.99997
+-0.99996
+-0.99996
+-0.99996
+-0.99996
+-0.99995
+-0.99995
+-0.99995
+-0.99995
+-0.99995
+
+
+query ?
+select arrow_typeof(c1-c5) from decimal_simple limit 1;
+----
+Decimal128(13, 7)
+
+
+query R
+select c1-c5 from decimal_simple;
+----
+-0.000004
+-0.000005
+0.000001
+-0.000002
+-0.000005
+0.000019
+-0.000004
+0
+0
+-0.000004
+-0.000002
+-0.000028
+0.000017
+-0.000018
+-0.00005
+
+
+query ?
+select arrow_typeof(c1*20) from decimal_simple limit 1;
+----
+Decimal128(31, 6)
+
+
+query R
+select c1*20 from decimal_simple;
+----
+0.0002
+0.0004
+0.0004
+0.0006
+0.0006
+0.0006
+0.0008
+0.0008
+0.0008
+0.0008
+0.001
+0.001
+0.001
+0.001
+0.001
+
+
+query ?
+select arrow_typeof(c1*c5) from decimal_simple limit 1;
+----
+Decimal128(23, 13)
+
+
+query R
+select c1*c5 from decimal_simple;
+----
+0.00000000014
+0.0000000005
+0.00000000038
+0.00000000096
+0.00000000105
+0.00000000033
+0.00000000176
+0.0000000016
+0.0000000016
+0.00000000176
+0.0000000026
+0.0000000039
+0.00000000165
+0.0000000034
+0.000000005
+
+
+query ?
+select arrow_typeof(c1/cast(0.00001 as decimal(5,5))) from decimal_simple limit 1;
+----
+Decimal128(21, 12)
+
+
+query R
+select c1/cast(0.00001 as decimal(5,5)) from decimal_simple;
+----
+1
+2
+2
+3
+3
+3
+4
+4
+4
+4
+5
+5
+5
+5
+5
+
+
+query ?
+select arrow_typeof(c1/c5) from decimal_simple limit 1;
+----
+Decimal128(30, 19)
+
+
+query R
+select c1/c5 from decimal_simple;
+----
+0.714285714286
+0.8
+1.052631578947
+0.9375
+0.857142857143
+2.727272727273
+0.909090909091
+1
+1
+0.909090909091
+0.961538461538
+0.641025641026
+1.515151515152
+0.735294117647
+0.5
+
+
+query ?
+select arrow_typeof(c5%cast(0.00001 as decimal(5,5))) from decimal_simple limit 1;
+----
+Decimal128(7, 7)
+
+
+query R
+select c5%cast(0.00001 as decimal(5,5)) from decimal_simple;
+----
+0.000004
+0.000005
+0.000009
+0.000002
+0.000005
+0.000001
+0.000004
+0
+0
+0.000004
+0.000002
+0.000008
+0.000003
+0.000008
+0
+
+
+query ?
+select arrow_typeof(c1%c5) from decimal_simple limit 1;
+----
+Decimal128(11, 7)
+
+
+query R
+select c1%c5 from decimal_simple;
+----
+0.00001
+0.00002
+0.000001
+0.00003
+0.00003
+0.000008
+0.00004
+0
+0
+0.00004
+0.00005
+0.00005
+0.000017
+0.00005
+0.00005
+
+
+query ?
+select arrow_typeof(abs(c1)) from decimal_simple limit 1;
+----
+Float64

Review Comment:
   The original test didn't check the type of `abs`, but I added a test entry for it. It seems like a bug to me. `Decimal(10,6)` was converted to a `Float64` as a result of `abs` call. It is probably related to https://github.com/apache/arrow-datafusion/issues/1335.



##########
datafusion/core/tests/sql/decimal.rs:
##########
@@ -1,915 +0,0 @@
-// 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::*;
-
-#[tokio::test]
-async fn decimal_cast() -> Result<()> {
-    let ctx = SessionContext::new();
-    let sql = "select cast(1.23 as decimal(10,4))";
-    let actual = execute_to_batches(&ctx, sql).await;
-    assert_eq!(
-        &DataType::Decimal128(10, 4),
-        actual[0].schema().field(0).data_type()
-    );
-    let expected = vec![
-        "+---------------+",
-        "| Float64(1.23) |",
-        "+---------------+",
-        "| 1.2300        |",
-        "+---------------+",
-    ];
-    assert_batches_eq!(expected, &actual);
-
-    let sql = "select cast(cast(1.23 as decimal(10,3)) as decimal(10,4))";
-    let actual = execute_to_batches(&ctx, sql).await;
-    assert_eq!(
-        &DataType::Decimal128(10, 4),
-        actual[0].schema().field(0).data_type()
-    );
-    let expected = vec![
-        "+---------------+",
-        "| Float64(1.23) |",
-        "+---------------+",
-        "| 1.2300        |",
-        "+---------------+",
-    ];
-    assert_batches_eq!(expected, &actual);
-
-    let sql = "select cast(1.2345 as decimal(24,2))";
-    let actual = execute_to_batches(&ctx, sql).await;
-    assert_eq!(
-        &DataType::Decimal128(24, 2),
-        actual[0].schema().field(0).data_type()
-    );
-    let expected = vec![
-        "+-----------------+",
-        "| Float64(1.2345) |",
-        "+-----------------+",
-        "| 1.23            |",
-        "+-----------------+",
-    ];
-    assert_batches_eq!(expected, &actual);
-
-    Ok(())
-}
-
-#[tokio::test]
-async fn decimal_by_sql() -> Result<()> {
-    let ctx = SessionContext::new();
-    register_decimal_csv_table_by_sql(&ctx).await;
-    let sql = "SELECT c1 from decimal_simple";
-    let actual = execute_to_batches(&ctx, sql).await;
-    assert_eq!(
-        &DataType::Decimal128(10, 6),
-        actual[0].schema().field(0).data_type()
-    );
-    let expected = vec![
-        "+----------+",
-        "| c1       |",
-        "+----------+",
-        "| 0.000010 |",
-        "| 0.000020 |",
-        "| 0.000020 |",
-        "| 0.000030 |",
-        "| 0.000030 |",
-        "| 0.000030 |",
-        "| 0.000040 |",
-        "| 0.000040 |",
-        "| 0.000040 |",
-        "| 0.000040 |",
-        "| 0.000050 |",
-        "| 0.000050 |",
-        "| 0.000050 |",
-        "| 0.000050 |",
-        "| 0.000050 |",
-        "+----------+",
-    ];
-    assert_batches_eq!(expected, &actual);
-    Ok(())
-}
-
-#[tokio::test]
-async fn decimal_by_filter() -> Result<()> {
-    let ctx = SessionContext::new();
-    register_decimal_csv_table_by_sql(&ctx).await;
-    let sql = "select c1 from decimal_simple where c1 > 0.000030";
-    let actual = execute_to_batches(&ctx, sql).await;
-    assert_eq!(
-        &DataType::Decimal128(10, 6),
-        actual[0].schema().field(0).data_type()
-    );
-    let expected = vec![
-        "+----------+",
-        "| c1       |",
-        "+----------+",
-        "| 0.000040 |",
-        "| 0.000040 |",
-        "| 0.000040 |",
-        "| 0.000040 |",
-        "| 0.000050 |",
-        "| 0.000050 |",
-        "| 0.000050 |",
-        "| 0.000050 |",
-        "| 0.000050 |",
-        "+----------+",
-    ];
-    assert_batches_eq!(expected, &actual);
-
-    let sql = "select * from decimal_simple where c1 > c5";
-    let actual = execute_to_batches(&ctx, sql).await;
-    assert_eq!(
-        &DataType::Decimal128(10, 6),
-        actual[0].schema().field(0).data_type()
-    );
-    assert_eq!(
-        &DataType::Decimal128(12, 7),
-        actual[0].schema().field(4).data_type()
-    );
-    let expected = vec![
-        "+----------+----------------+----+-------+-----------+",
-        "| c1       | c2             | c3 | c4    | c5        |",
-        "+----------+----------------+----+-------+-----------+",
-        "| 0.000020 | 0.000000000002 | 3  | false | 0.0000190 |",
-        "| 0.000030 | 0.000000000003 | 5  | true  | 0.0000110 |",
-        "| 0.000050 | 0.000000000005 | 8  | false | 0.0000330 |",
-        "+----------+----------------+----+-------+-----------+",
-    ];
-    assert_batches_eq!(expected, &actual);
-    Ok(())
-}
-
-#[tokio::test]
-async fn decimal_agg_function() -> Result<()> {
-    let ctx = SessionContext::new();
-    register_decimal_csv_table_by_sql(&ctx).await;
-    // min
-    let sql = "select min(c1) from decimal_simple where c4=false";
-    let actual = execute_to_batches(&ctx, sql).await;
-    assert_eq!(
-        &DataType::Decimal128(10, 6),
-        actual[0].schema().field(0).data_type()
-    );
-    let expected = vec![
-        "+------------------------+",
-        "| MIN(decimal_simple.c1) |",
-        "+------------------------+",
-        "| 0.000020               |",
-        "+------------------------+",
-    ];
-    assert_batches_eq!(expected, &actual);
-    // max
-    let sql = "select max(c1) from decimal_simple where c4=false";
-    let actual = execute_to_batches(&ctx, sql).await;
-    assert_eq!(
-        &DataType::Decimal128(10, 6),
-        actual[0].schema().field(0).data_type()
-    );
-    let expected = vec![
-        "+------------------------+",
-        "| MAX(decimal_simple.c1) |",
-        "+------------------------+",
-        "| 0.000050               |",
-        "+------------------------+",
-    ];
-    assert_batches_eq!(expected, &actual);
-
-    // sum
-    let sql = "select sum(c1) from decimal_simple";
-    let actual = execute_to_batches(&ctx, sql).await;
-    // inferred precision is 10+10
-    assert_eq!(
-        &DataType::Decimal128(20, 6),
-        actual[0].schema().field(0).data_type()
-    );
-    let expected = vec![
-        "+------------------------+",
-        "| SUM(decimal_simple.c1) |",
-        "+------------------------+",
-        "| 0.000550               |",
-        "+------------------------+",
-    ];
-    assert_batches_eq!(expected, &actual);
-
-    // avg
-    // inferred precision is original precision + 4
-    // inferred scale is original scale + 4
-    let sql = "select avg(c1) from decimal_simple";
-    let actual = execute_to_batches(&ctx, sql).await;
-    assert_eq!(
-        &DataType::Decimal128(14, 10),
-        actual[0].schema().field(0).data_type()
-    );
-    let expected = vec![
-        "+------------------------+",
-        "| AVG(decimal_simple.c1) |",
-        "+------------------------+",
-        "| 0.0000366666           |",
-        "+------------------------+",
-    ];
-    assert_batches_eq!(expected, &actual);
-
-    Ok(())
-}
-
-#[tokio::test]
-async fn decimal_logic_op() -> Result<()> {
-    let ctx = SessionContext::new();
-    register_decimal_csv_table_by_sql(&ctx).await;
-    // logic operation: eq
-    let sql = "select * from decimal_simple where c1=CAST(0.00002 as Decimal(10,8))";
-    let actual = execute_to_batches(&ctx, sql).await;
-    assert_eq!(
-        &DataType::Decimal128(10, 6),
-        actual[0].schema().field(0).data_type()
-    );
-    let expected = vec![
-        "+----------+----------------+----+-------+-----------+",
-        "| c1       | c2             | c3 | c4    | c5        |",
-        "+----------+----------------+----+-------+-----------+",
-        "| 0.000020 | 0.000000000002 | 2  | true  | 0.0000250 |",
-        "| 0.000020 | 0.000000000002 | 3  | false | 0.0000190 |",
-        "+----------+----------------+----+-------+-----------+",
-    ];
-    assert_batches_eq!(expected, &actual);
-
-    // logic operation: not eq
-    let sql = "select c2,c3 from decimal_simple where c1!=0.00002";
-    let actual = execute_to_batches(&ctx, sql).await;
-    let expected = vec![
-        "+----------------+-----+",
-        "| c2             | c3  |",
-        "+----------------+-----+",
-        "| 0.000000000001 | 1   |",
-        "| 0.000000000003 | 4   |",
-        "| 0.000000000003 | 5   |",
-        "| 0.000000000003 | 5   |",
-        "| 0.000000000004 | 5   |",
-        "| 0.000000000004 | 12  |",
-        "| 0.000000000004 | 14  |",
-        "| 0.000000000004 | 8   |",
-        "| 0.000000000005 | 9   |",
-        "| 0.000000000005 | 4   |",
-        "| 0.000000000005 | 8   |",
-        "| 0.000000000005 | 100 |",
-        "| 0.000000000005 | 1   |",
-        "+----------------+-----+",
-    ];
-    assert_batches_eq!(expected, &actual);
-    // logic operation: lt
-    let sql = "select * from decimal_simple where 0.00002 > c1";
-    let actual = execute_to_batches(&ctx, sql).await;
-    assert_eq!(
-        &DataType::Decimal128(10, 6),
-        actual[0].schema().field(0).data_type()
-    );
-    let expected = vec![
-        "+----------+----------------+----+------+-----------+",
-        "| c1       | c2             | c3 | c4   | c5        |",
-        "+----------+----------------+----+------+-----------+",
-        "| 0.000010 | 0.000000000001 | 1  | true | 0.0000140 |",
-        "+----------+----------------+----+------+-----------+",
-    ];
-    assert_batches_eq!(expected, &actual);
-
-    // logic operation: lteq
-    let sql = "select * from decimal_simple where c1 <= 0.00002";
-    let actual = execute_to_batches(&ctx, sql).await;
-    assert_eq!(
-        &DataType::Decimal128(10, 6),
-        actual[0].schema().field(0).data_type()
-    );
-    let expected = vec![
-        "+----------+----------------+----+-------+-----------+",
-        "| c1       | c2             | c3 | c4    | c5        |",
-        "+----------+----------------+----+-------+-----------+",
-        "| 0.000010 | 0.000000000001 | 1  | true  | 0.0000140 |",
-        "| 0.000020 | 0.000000000002 | 2  | true  | 0.0000250 |",
-        "| 0.000020 | 0.000000000002 | 3  | false | 0.0000190 |",
-        "+----------+----------------+----+-------+-----------+",
-    ];
-    assert_batches_eq!(expected, &actual);
-
-    // logic operation: gt
-    let sql = "select * from decimal_simple where c1 > 0.00002";
-    let actual = execute_to_batches(&ctx, sql).await;
-    assert_eq!(
-        &DataType::Decimal128(10, 6),
-        actual[0].schema().field(0).data_type()
-    );
-    let expected = vec![
-        "+----------+----------------+-----+-------+-----------+",
-        "| c1       | c2             | c3  | c4    | c5        |",
-        "+----------+----------------+-----+-------+-----------+",
-        "| 0.000030 | 0.000000000003 | 4   | true  | 0.0000320 |",
-        "| 0.000030 | 0.000000000003 | 5   | false | 0.0000350 |",
-        "| 0.000030 | 0.000000000003 | 5   | true  | 0.0000110 |",
-        "| 0.000040 | 0.000000000004 | 5   | true  | 0.0000440 |",
-        "| 0.000040 | 0.000000000004 | 12  | false | 0.0000400 |",
-        "| 0.000040 | 0.000000000004 | 14  | true  | 0.0000400 |",
-        "| 0.000040 | 0.000000000004 | 8   | false | 0.0000440 |",
-        "| 0.000050 | 0.000000000005 | 9   | true  | 0.0000520 |",
-        "| 0.000050 | 0.000000000005 | 4   | true  | 0.0000780 |",
-        "| 0.000050 | 0.000000000005 | 8   | false | 0.0000330 |",
-        "| 0.000050 | 0.000000000005 | 100 | true  | 0.0000680 |",
-        "| 0.000050 | 0.000000000005 | 1   | false | 0.0001000 |",
-        "+----------+----------------+-----+-------+-----------+",
-    ];
-    assert_batches_eq!(expected, &actual);
-
-    // logic operation: gteq
-    let sql = "select * from decimal_simple where c1 >= 0.00002";
-    let actual = execute_to_batches(&ctx, sql).await;
-    assert_eq!(
-        &DataType::Decimal128(10, 6),
-        actual[0].schema().field(0).data_type()
-    );
-    let expected = vec![
-        "+----------+----------------+-----+-------+-----------+",
-        "| c1       | c2             | c3  | c4    | c5        |",
-        "+----------+----------------+-----+-------+-----------+",
-        "| 0.000020 | 0.000000000002 | 2   | true  | 0.0000250 |",
-        "| 0.000020 | 0.000000000002 | 3   | false | 0.0000190 |",
-        "| 0.000030 | 0.000000000003 | 4   | true  | 0.0000320 |",
-        "| 0.000030 | 0.000000000003 | 5   | false | 0.0000350 |",
-        "| 0.000030 | 0.000000000003 | 5   | true  | 0.0000110 |",
-        "| 0.000040 | 0.000000000004 | 5   | true  | 0.0000440 |",
-        "| 0.000040 | 0.000000000004 | 12  | false | 0.0000400 |",
-        "| 0.000040 | 0.000000000004 | 14  | true  | 0.0000400 |",
-        "| 0.000040 | 0.000000000004 | 8   | false | 0.0000440 |",
-        "| 0.000050 | 0.000000000005 | 9   | true  | 0.0000520 |",
-        "| 0.000050 | 0.000000000005 | 4   | true  | 0.0000780 |",
-        "| 0.000050 | 0.000000000005 | 8   | false | 0.0000330 |",
-        "| 0.000050 | 0.000000000005 | 100 | true  | 0.0000680 |",
-        "| 0.000050 | 0.000000000005 | 1   | false | 0.0001000 |",
-        "+----------+----------------+-----+-------+-----------+",
-    ];
-    assert_batches_eq!(expected, &actual);
-
-    Ok(())
-}
-
-#[tokio::test]
-async fn decimal_arithmetic_op() -> Result<()> {
-    let ctx = SessionContext::new();
-    register_decimal_csv_table_by_sql(&ctx).await;
-    // add
-    let sql = "select c1+1 from decimal_simple"; // add scalar
-    let actual = execute_to_batches(&ctx, sql).await;
-    // array decimal(10,6) +  scalar decimal(20,0) => decimal(21,6)
-    assert_eq!(
-        &DataType::Decimal128(27, 6),

Review Comment:
   I noticed that the comment expects a precision `21`, but the assertion is `27`. I am not sure if it's a typo in the comment, or if something is wrong with the type. I moved this test to `decimal.slt` as is.



-- 
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


[GitHub] [arrow-datafusion] melgenek commented on a diff in pull request #5086: [sqllogictest] Move `decimal.rs` tests

Posted by "melgenek (via GitHub)" <gi...@apache.org>.
melgenek commented on code in PR #5086:
URL: https://github.com/apache/arrow-datafusion/pull/5086#discussion_r1089552307


##########
datafusion/core/tests/sql/decimal.rs:
##########
@@ -18,839 +18,256 @@
 use super::*;
 
 #[tokio::test]
-async fn decimal_cast() -> Result<()> {
+async fn decimal_cast_precision() -> Result<()> {
     let ctx = SessionContext::new();
     let sql = "select cast(1.23 as decimal(10,4))";
     let actual = execute_to_batches(&ctx, sql).await;
     assert_eq!(

Review Comment:
   I moved the tests to .slt file https://github.com/apache/arrow-datafusion/pull/5086/commits/8295aa5f7a138d1d44d3c05c436b88ef0b82140c



-- 
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


[GitHub] [arrow-datafusion] melgenek commented on pull request #5086: [sqllogictest] Move `decimal.rs` tests

Posted by "melgenek (via GitHub)" <gi...@apache.org>.
melgenek commented on PR #5086:
URL: https://github.com/apache/arrow-datafusion/pull/5086#issuecomment-1407201635

   @alamb I updated this pr to include the type checks in sqllogictests using `arrow_typeof`. Please, take a look once more.


-- 
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


[GitHub] [arrow-datafusion] melgenek commented on a diff in pull request #5086: [sqllogictest] Move `decimal.rs` tests

Posted by "melgenek (via GitHub)" <gi...@apache.org>.
melgenek commented on code in PR #5086:
URL: https://github.com/apache/arrow-datafusion/pull/5086#discussion_r1088747917


##########
datafusion/core/tests/sql/decimal.rs:
##########
@@ -879,37 +296,3 @@ async fn decimal_null_array_scalar_comparison() -> Result<()> {
     assert_eq!(&DataType::Boolean, actual[0].column(0).data_type());

Review Comment:
   `decimal_null_scalar_array_comparison` and `decimal_null_array_scalar_comparison` would also be good candidates to be moved to sqllogictest. It would properly check that the results are `NULL`. But there is currently no way to differentiate if its a decimal null or a boolean null. 



##########
datafusion/core/tests/sql/decimal.rs:
##########
@@ -18,839 +18,256 @@
 use super::*;
 
 #[tokio::test]
-async fn decimal_cast() -> Result<()> {
+async fn decimal_cast_precision() -> Result<()> {
     let ctx = SessionContext::new();
     let sql = "select cast(1.23 as decimal(10,4))";
     let actual = execute_to_batches(&ctx, sql).await;
     assert_eq!(
         &DataType::Decimal128(10, 4),
         actual[0].schema().field(0).data_type()
     );
-    let expected = vec![
-        "+---------------+",
-        "| Float64(1.23) |",
-        "+---------------+",
-        "| 1.2300        |",
-        "+---------------+",
-    ];
-    assert_batches_eq!(expected, &actual);
 
     let sql = "select cast(cast(1.23 as decimal(10,3)) as decimal(10,4))";
     let actual = execute_to_batches(&ctx, sql).await;
     assert_eq!(
         &DataType::Decimal128(10, 4),
         actual[0].schema().field(0).data_type()
     );
-    let expected = vec![
-        "+---------------+",
-        "| Float64(1.23) |",
-        "+---------------+",
-        "| 1.2300        |",
-        "+---------------+",
-    ];
-    assert_batches_eq!(expected, &actual);
-
-    let sql = "select cast(1.2345 as decimal(24,2))";
-    let actual = execute_to_batches(&ctx, sql).await;
-    assert_eq!(
-        &DataType::Decimal128(24, 2),
-        actual[0].schema().field(0).data_type()
-    );
-    let expected = vec![
-        "+-----------------+",
-        "| Float64(1.2345) |",
-        "+-----------------+",
-        "| 1.23            |",
-        "+-----------------+",
-    ];
-    assert_batches_eq!(expected, &actual);
 
     Ok(())
 }
 
 #[tokio::test]
-async fn decimal_by_sql() -> Result<()> {
+async fn decimal_filter_precision() -> Result<()> {
     let ctx = SessionContext::new();
     register_decimal_csv_table_by_sql(&ctx).await;
-    let sql = "SELECT c1 from decimal_simple";
+    let sql = "select c1, c5 from decimal_simple where c1 > c5";
+
     let actual = execute_to_batches(&ctx, sql).await;
+
     assert_eq!(
         &DataType::Decimal128(10, 6),
         actual[0].schema().field(0).data_type()
     );
-    let expected = vec![
-        "+----------+",
-        "| c1       |",
-        "+----------+",
-        "| 0.000010 |",
-        "| 0.000020 |",
-        "| 0.000020 |",
-        "| 0.000030 |",
-        "| 0.000030 |",
-        "| 0.000030 |",
-        "| 0.000040 |",
-        "| 0.000040 |",
-        "| 0.000040 |",
-        "| 0.000040 |",
-        "| 0.000050 |",
-        "| 0.000050 |",
-        "| 0.000050 |",
-        "| 0.000050 |",
-        "| 0.000050 |",
-        "+----------+",
-    ];
-    assert_batches_eq!(expected, &actual);
+    assert_eq!(
+        &DataType::Decimal128(12, 7),
+        actual[0].schema().field(1).data_type()
+    );
     Ok(())
 }
 
 #[tokio::test]
-async fn decimal_by_filter() -> Result<()> {
+async fn min_function_precision() -> Result<()> {
     let ctx = SessionContext::new();
     register_decimal_csv_table_by_sql(&ctx).await;
-    let sql = "select c1 from decimal_simple where c1 > 0.000030";
-    let actual = execute_to_batches(&ctx, sql).await;
-    assert_eq!(
-        &DataType::Decimal128(10, 6),
-        actual[0].schema().field(0).data_type()
-    );
-    let expected = vec![
-        "+----------+",
-        "| c1       |",
-        "+----------+",
-        "| 0.000040 |",
-        "| 0.000040 |",
-        "| 0.000040 |",
-        "| 0.000040 |",
-        "| 0.000050 |",
-        "| 0.000050 |",
-        "| 0.000050 |",
-        "| 0.000050 |",
-        "| 0.000050 |",
-        "+----------+",
-    ];
-    assert_batches_eq!(expected, &actual);
-
-    let sql = "select * from decimal_simple where c1 > c5";
+    let sql = "select min(c1) from decimal_simple where c4=false";
+
     let actual = execute_to_batches(&ctx, sql).await;
+
     assert_eq!(
         &DataType::Decimal128(10, 6),
         actual[0].schema().field(0).data_type()
     );
-    assert_eq!(
-        &DataType::Decimal128(12, 7),
-        actual[0].schema().field(4).data_type()
-    );
-    let expected = vec![
-        "+----------+----------------+----+-------+-----------+",
-        "| c1       | c2             | c3 | c4    | c5        |",
-        "+----------+----------------+----+-------+-----------+",
-        "| 0.000020 | 0.000000000002 | 3  | false | 0.0000190 |",
-        "| 0.000030 | 0.000000000003 | 5  | true  | 0.0000110 |",
-        "| 0.000050 | 0.000000000005 | 8  | false | 0.0000330 |",
-        "+----------+----------------+----+-------+-----------+",
-    ];
-    assert_batches_eq!(expected, &actual);
     Ok(())
 }
 
 #[tokio::test]
-async fn decimal_agg_function() -> Result<()> {
+async fn max_function_precision() -> Result<()> {
     let ctx = SessionContext::new();
     register_decimal_csv_table_by_sql(&ctx).await;
-    // min
-    let sql = "select min(c1) from decimal_simple where c4=false";
-    let actual = execute_to_batches(&ctx, sql).await;
-    assert_eq!(
-        &DataType::Decimal128(10, 6),
-        actual[0].schema().field(0).data_type()
-    );
-    let expected = vec![
-        "+------------------------+",
-        "| MIN(decimal_simple.c1) |",
-        "+------------------------+",
-        "| 0.000020               |",
-        "+------------------------+",
-    ];
-    assert_batches_eq!(expected, &actual);
-    // max
     let sql = "select max(c1) from decimal_simple where c4=false";
+
     let actual = execute_to_batches(&ctx, sql).await;
+
     assert_eq!(
         &DataType::Decimal128(10, 6),
         actual[0].schema().field(0).data_type()
     );
-    let expected = vec![
-        "+------------------------+",
-        "| MAX(decimal_simple.c1) |",
-        "+------------------------+",
-        "| 0.000050               |",
-        "+------------------------+",
-    ];
-    assert_batches_eq!(expected, &actual);
-
-    // sum
+    Ok(())
+}
+
+#[tokio::test]
+async fn sum_function_precision() -> Result<()> {
+    let ctx = SessionContext::new();
+    register_decimal_csv_table_by_sql(&ctx).await;
     let sql = "select sum(c1) from decimal_simple";
+
     let actual = execute_to_batches(&ctx, sql).await;
+
     // inferred precision is 10+10
     assert_eq!(
         &DataType::Decimal128(20, 6),
         actual[0].schema().field(0).data_type()
     );
-    let expected = vec![
-        "+------------------------+",
-        "| SUM(decimal_simple.c1) |",
-        "+------------------------+",
-        "| 0.000550               |",
-        "+------------------------+",
-    ];
-    assert_batches_eq!(expected, &actual);
-
-    // avg
-    // inferred precision is original precision + 4
-    // inferred scale is original scale + 4
-    let sql = "select avg(c1) from decimal_simple";
-    let actual = execute_to_batches(&ctx, sql).await;
-    assert_eq!(
-        &DataType::Decimal128(14, 10),
-        actual[0].schema().field(0).data_type()
-    );
-    let expected = vec![
-        "+------------------------+",
-        "| AVG(decimal_simple.c1) |",
-        "+------------------------+",
-        "| 0.0000366666           |",
-        "+------------------------+",
-    ];
-    assert_batches_eq!(expected, &actual);
-
     Ok(())
 }
 
 #[tokio::test]
-async fn decimal_logic_op() -> Result<()> {
+async fn avg_function_precision() -> Result<()> {
     let ctx = SessionContext::new();
     register_decimal_csv_table_by_sql(&ctx).await;
-    // logic operation: eq
-    let sql = "select * from decimal_simple where c1=CAST(0.00002 as Decimal(10,8))";
-    let actual = execute_to_batches(&ctx, sql).await;
-    assert_eq!(
-        &DataType::Decimal128(10, 6),
-        actual[0].schema().field(0).data_type()
-    );
-    let expected = vec![
-        "+----------+----------------+----+-------+-----------+",
-        "| c1       | c2             | c3 | c4    | c5        |",
-        "+----------+----------------+----+-------+-----------+",
-        "| 0.000020 | 0.000000000002 | 2  | true  | 0.0000250 |",
-        "| 0.000020 | 0.000000000002 | 3  | false | 0.0000190 |",
-        "+----------+----------------+----+-------+-----------+",
-    ];
-    assert_batches_eq!(expected, &actual);
-
-    // logic operation: not eq
-    let sql = "select c2,c3 from decimal_simple where c1!=0.00002";
-    let actual = execute_to_batches(&ctx, sql).await;
-    let expected = vec![
-        "+----------------+-----+",
-        "| c2             | c3  |",
-        "+----------------+-----+",
-        "| 0.000000000001 | 1   |",
-        "| 0.000000000003 | 4   |",
-        "| 0.000000000003 | 5   |",
-        "| 0.000000000003 | 5   |",
-        "| 0.000000000004 | 5   |",
-        "| 0.000000000004 | 12  |",
-        "| 0.000000000004 | 14  |",
-        "| 0.000000000004 | 8   |",
-        "| 0.000000000005 | 9   |",
-        "| 0.000000000005 | 4   |",
-        "| 0.000000000005 | 8   |",
-        "| 0.000000000005 | 100 |",
-        "| 0.000000000005 | 1   |",
-        "+----------------+-----+",
-    ];
-    assert_batches_eq!(expected, &actual);
-    // logic operation: lt
-    let sql = "select * from decimal_simple where 0.00002 > c1";
-    let actual = execute_to_batches(&ctx, sql).await;
-    assert_eq!(
-        &DataType::Decimal128(10, 6),
-        actual[0].schema().field(0).data_type()
-    );
-    let expected = vec![
-        "+----------+----------------+----+------+-----------+",
-        "| c1       | c2             | c3 | c4   | c5        |",
-        "+----------+----------------+----+------+-----------+",
-        "| 0.000010 | 0.000000000001 | 1  | true | 0.0000140 |",
-        "+----------+----------------+----+------+-----------+",
-    ];
-    assert_batches_eq!(expected, &actual);
-
-    // logic operation: lteq
-    let sql = "select * from decimal_simple where c1 <= 0.00002";
-    let actual = execute_to_batches(&ctx, sql).await;
-    assert_eq!(
-        &DataType::Decimal128(10, 6),
-        actual[0].schema().field(0).data_type()
-    );
-    let expected = vec![
-        "+----------+----------------+----+-------+-----------+",
-        "| c1       | c2             | c3 | c4    | c5        |",
-        "+----------+----------------+----+-------+-----------+",
-        "| 0.000010 | 0.000000000001 | 1  | true  | 0.0000140 |",
-        "| 0.000020 | 0.000000000002 | 2  | true  | 0.0000250 |",
-        "| 0.000020 | 0.000000000002 | 3  | false | 0.0000190 |",
-        "+----------+----------------+----+-------+-----------+",
-    ];
-    assert_batches_eq!(expected, &actual);
-
-    // logic operation: gt
-    let sql = "select * from decimal_simple where c1 > 0.00002";
-    let actual = execute_to_batches(&ctx, sql).await;
-    assert_eq!(
-        &DataType::Decimal128(10, 6),
-        actual[0].schema().field(0).data_type()
-    );
-    let expected = vec![
-        "+----------+----------------+-----+-------+-----------+",
-        "| c1       | c2             | c3  | c4    | c5        |",
-        "+----------+----------------+-----+-------+-----------+",
-        "| 0.000030 | 0.000000000003 | 4   | true  | 0.0000320 |",
-        "| 0.000030 | 0.000000000003 | 5   | false | 0.0000350 |",
-        "| 0.000030 | 0.000000000003 | 5   | true  | 0.0000110 |",
-        "| 0.000040 | 0.000000000004 | 5   | true  | 0.0000440 |",
-        "| 0.000040 | 0.000000000004 | 12  | false | 0.0000400 |",
-        "| 0.000040 | 0.000000000004 | 14  | true  | 0.0000400 |",
-        "| 0.000040 | 0.000000000004 | 8   | false | 0.0000440 |",
-        "| 0.000050 | 0.000000000005 | 9   | true  | 0.0000520 |",
-        "| 0.000050 | 0.000000000005 | 4   | true  | 0.0000780 |",
-        "| 0.000050 | 0.000000000005 | 8   | false | 0.0000330 |",
-        "| 0.000050 | 0.000000000005 | 100 | true  | 0.0000680 |",
-        "| 0.000050 | 0.000000000005 | 1   | false | 0.0001000 |",
-        "+----------+----------------+-----+-------+-----------+",
-    ];
-    assert_batches_eq!(expected, &actual);
-
-    // logic operation: gteq
-    let sql = "select * from decimal_simple where c1 >= 0.00002";
+    let sql = "select avg(c1) from decimal_simple";
+
     let actual = execute_to_batches(&ctx, sql).await;
+
+    // inferred precision is original precision + 4
+    // inferred scale is original scale + 4
     assert_eq!(
-        &DataType::Decimal128(10, 6),
+        &DataType::Decimal128(14, 10),
         actual[0].schema().field(0).data_type()
     );
-    let expected = vec![
-        "+----------+----------------+-----+-------+-----------+",
-        "| c1       | c2             | c3  | c4    | c5        |",
-        "+----------+----------------+-----+-------+-----------+",
-        "| 0.000020 | 0.000000000002 | 2   | true  | 0.0000250 |",
-        "| 0.000020 | 0.000000000002 | 3   | false | 0.0000190 |",
-        "| 0.000030 | 0.000000000003 | 4   | true  | 0.0000320 |",
-        "| 0.000030 | 0.000000000003 | 5   | false | 0.0000350 |",
-        "| 0.000030 | 0.000000000003 | 5   | true  | 0.0000110 |",
-        "| 0.000040 | 0.000000000004 | 5   | true  | 0.0000440 |",
-        "| 0.000040 | 0.000000000004 | 12  | false | 0.0000400 |",
-        "| 0.000040 | 0.000000000004 | 14  | true  | 0.0000400 |",
-        "| 0.000040 | 0.000000000004 | 8   | false | 0.0000440 |",
-        "| 0.000050 | 0.000000000005 | 9   | true  | 0.0000520 |",
-        "| 0.000050 | 0.000000000005 | 4   | true  | 0.0000780 |",
-        "| 0.000050 | 0.000000000005 | 8   | false | 0.0000330 |",
-        "| 0.000050 | 0.000000000005 | 100 | true  | 0.0000680 |",
-        "| 0.000050 | 0.000000000005 | 1   | false | 0.0001000 |",
-        "+----------+----------------+-----+-------+-----------+",
-    ];
-    assert_batches_eq!(expected, &actual);
-
     Ok(())
 }
 
 #[tokio::test]
-async fn decimal_arithmetic_op() -> Result<()> {
+async fn add_scalar_precision() -> Result<()> {
     let ctx = SessionContext::new();
     register_decimal_csv_table_by_sql(&ctx).await;
-    // add
     let sql = "select c1+1 from decimal_simple"; // add scalar
+
     let actual = execute_to_batches(&ctx, sql).await;
-    // array decimal(10,6) +  scalar decimal(20,0) => decimal(21,6)
+
+    // array decimal(10,6) + scalar decimal(20,0) => decimal(21,6)
     assert_eq!(
         &DataType::Decimal128(27, 6),
         actual[0].schema().field(0).data_type()
     );
-    let expected = vec![
-        "+------------------------------+",
-        "| decimal_simple.c1 + Int64(1) |",
-        "+------------------------------+",
-        "| 1.000010                     |",
-        "| 1.000020                     |",
-        "| 1.000020                     |",
-        "| 1.000030                     |",
-        "| 1.000030                     |",
-        "| 1.000030                     |",
-        "| 1.000040                     |",
-        "| 1.000040                     |",
-        "| 1.000040                     |",
-        "| 1.000040                     |",
-        "| 1.000050                     |",
-        "| 1.000050                     |",
-        "| 1.000050                     |",
-        "| 1.000050                     |",
-        "| 1.000050                     |",
-        "+------------------------------+",
-    ];
-    assert_batches_eq!(expected, &actual);
-    // array decimal(10,6) + array decimal(12,7) => decimal(13,7)
+    Ok(())
+}
+
+#[tokio::test]
+async fn add_precision() -> Result<()> {
+    let ctx = SessionContext::new();
+    register_decimal_csv_table_by_sql(&ctx).await;
     let sql = "select c1+c5 from decimal_simple";
+
     let actual = execute_to_batches(&ctx, sql).await;
+
+    // array decimal(10,6) + array decimal(12,7) => decimal(13,7)
     assert_eq!(
         &DataType::Decimal128(13, 7),
         actual[0].schema().field(0).data_type()
     );
-    let expected = vec![
-        "+---------------------------------------+",
-        "| decimal_simple.c1 + decimal_simple.c5 |",
-        "+---------------------------------------+",
-        "| 0.0000240                             |",
-        "| 0.0000450                             |",
-        "| 0.0000390                             |",
-        "| 0.0000620                             |",
-        "| 0.0000650                             |",
-        "| 0.0000410                             |",
-        "| 0.0000840                             |",
-        "| 0.0000800                             |",
-        "| 0.0000800                             |",
-        "| 0.0000840                             |",
-        "| 0.0001020                             |",
-        "| 0.0001280                             |",
-        "| 0.0000830                             |",
-        "| 0.0001180                             |",
-        "| 0.0001500                             |",
-        "+---------------------------------------+",
-    ];
-    assert_batches_eq!(expected, &actual);
-    // subtract
+    Ok(())
+}
+
+#[tokio::test]
+async fn subtract_scalar_precision() -> Result<()> {
+    let ctx = SessionContext::new();
+    register_decimal_csv_table_by_sql(&ctx).await;
     let sql = "select c1-1 from decimal_simple";
+
     let actual = execute_to_batches(&ctx, sql).await;
+
     assert_eq!(
         &DataType::Decimal128(27, 6),
         actual[0].schema().field(0).data_type()
     );
-    let expected = vec![
-        "+------------------------------+",
-        "| decimal_simple.c1 - Int64(1) |",
-        "+------------------------------+",
-        "| -0.999990                    |",
-        "| -0.999980                    |",
-        "| -0.999980                    |",
-        "| -0.999970                    |",
-        "| -0.999970                    |",
-        "| -0.999970                    |",
-        "| -0.999960                    |",
-        "| -0.999960                    |",
-        "| -0.999960                    |",
-        "| -0.999960                    |",
-        "| -0.999950                    |",
-        "| -0.999950                    |",
-        "| -0.999950                    |",
-        "| -0.999950                    |",
-        "| -0.999950                    |",
-        "+------------------------------+",
-    ];
-    assert_batches_eq!(expected, &actual);
+    Ok(())
+}
 
+#[tokio::test]
+async fn subtract_precision() -> Result<()> {
+    let ctx = SessionContext::new();
+    register_decimal_csv_table_by_sql(&ctx).await;
     let sql = "select c1-c5 from decimal_simple";
+
     let actual = execute_to_batches(&ctx, sql).await;
+
     assert_eq!(
         &DataType::Decimal128(13, 7),
         actual[0].schema().field(0).data_type()
     );
-    let expected = vec![
-        "+---------------------------------------+",
-        "| decimal_simple.c1 - decimal_simple.c5 |",
-        "+---------------------------------------+",
-        "| -0.0000040                            |",
-        "| -0.0000050                            |",
-        "| 0.0000010                             |",
-        "| -0.0000020                            |",
-        "| -0.0000050                            |",
-        "| 0.0000190                             |",
-        "| -0.0000040                            |",
-        "| 0.0000000                             |",
-        "| 0.0000000                             |",
-        "| -0.0000040                            |",
-        "| -0.0000020                            |",
-        "| -0.0000280                            |",
-        "| 0.0000170                             |",
-        "| -0.0000180                            |",
-        "| -0.0000500                            |",
-        "+---------------------------------------+",
-    ];
-    assert_batches_eq!(expected, &actual);
-    // multiply
+    Ok(())
+}
+
+#[tokio::test]
+async fn multiply_scalar_precision() -> Result<()> {
+    let ctx = SessionContext::new();
+    register_decimal_csv_table_by_sql(&ctx).await;
     let sql = "select c1*20 from decimal_simple";
+
     let actual = execute_to_batches(&ctx, sql).await;
+
     assert_eq!(
         &DataType::Decimal128(31, 6),
         actual[0].schema().field(0).data_type()
     );
-    let expected = vec![
-        "+-------------------------------+",
-        "| decimal_simple.c1 * Int64(20) |",
-        "+-------------------------------+",
-        "| 0.000200                      |",
-        "| 0.000400                      |",
-        "| 0.000400                      |",
-        "| 0.000600                      |",
-        "| 0.000600                      |",
-        "| 0.000600                      |",
-        "| 0.000800                      |",
-        "| 0.000800                      |",
-        "| 0.000800                      |",
-        "| 0.000800                      |",
-        "| 0.001000                      |",
-        "| 0.001000                      |",
-        "| 0.001000                      |",
-        "| 0.001000                      |",
-        "| 0.001000                      |",
-        "+-------------------------------+",
-    ];
-    assert_batches_eq!(expected, &actual);
+    Ok(())
+}
 
+#[tokio::test]
+async fn multiply_precision() -> Result<()> {
+    let ctx = SessionContext::new();
+    register_decimal_csv_table_by_sql(&ctx).await;
     let sql = "select c1*c5 from decimal_simple";
+
     let actual = execute_to_batches(&ctx, sql).await;
+
     assert_eq!(
         &DataType::Decimal128(23, 13),
         actual[0].schema().field(0).data_type()
     );
-    let expected = vec![
-        "+---------------------------------------+",
-        "| decimal_simple.c1 * decimal_simple.c5 |",
-        "+---------------------------------------+",
-        "| 0.0000000001400                       |",
-        "| 0.0000000005000                       |",
-        "| 0.0000000003800                       |",
-        "| 0.0000000009600                       |",
-        "| 0.0000000010500                       |",
-        "| 0.0000000003300                       |",
-        "| 0.0000000017600                       |",
-        "| 0.0000000016000                       |",
-        "| 0.0000000016000                       |",
-        "| 0.0000000017600                       |",
-        "| 0.0000000026000                       |",
-        "| 0.0000000039000                       |",
-        "| 0.0000000016500                       |",
-        "| 0.0000000034000                       |",
-        "| 0.0000000050000                       |",
-        "+---------------------------------------+",
-    ];
-    assert_batches_eq!(expected, &actual);
-    // divide
+    Ok(())
+}
+
+#[tokio::test]
+async fn divide_scalar_precision() -> Result<()> {
+    let ctx = SessionContext::new();
+    register_decimal_csv_table_by_sql(&ctx).await;
     let sql = "select c1/cast(0.00001 as decimal(5,5)) from decimal_simple";
-    let actual = execute_to_batches(&ctx, sql).await;
-    assert_eq!(
-        &DataType::Decimal128(21, 12),
-        actual[0].schema().field(0).data_type()
-    );
-    let expected = vec![
-        "+--------------------------------------+",
-        "| decimal_simple.c1 / Float64(0.00001) |",
-        "+--------------------------------------+",
-        "| 1.000000000000                       |",
-        "| 2.000000000000                       |",
-        "| 2.000000000000                       |",
-        "| 3.000000000000                       |",
-        "| 3.000000000000                       |",
-        "| 3.000000000000                       |",
-        "| 4.000000000000                       |",
-        "| 4.000000000000                       |",
-        "| 4.000000000000                       |",
-        "| 4.000000000000                       |",
-        "| 5.000000000000                       |",
-        "| 5.000000000000                       |",
-        "| 5.000000000000                       |",
-        "| 5.000000000000                       |",
-        "| 5.000000000000                       |",
-        "+--------------------------------------+",
-    ];
-    assert_batches_eq!(expected, &actual);
 
-    let sql = "select c1/c5 from decimal_simple";
     let actual = execute_to_batches(&ctx, sql).await;
-    assert_eq!(
-        &DataType::Decimal128(30, 19),
-        actual[0].schema().field(0).data_type()
-    );
-    let expected = vec![
-        "+---------------------------------------+",
-        "| decimal_simple.c1 / decimal_simple.c5 |",
-        "+---------------------------------------+",
-        "| 0.7142857142857142857                 |",
-        "| 0.8000000000000000000                 |",
-        "| 1.0526315789473684210                 |",
-        "| 0.9375000000000000000                 |",
-        "| 0.8571428571428571428                 |",
-        "| 2.7272727272727272727                 |",
-        "| 0.9090909090909090909                 |",
-        "| 1.0000000000000000000                 |",
-        "| 1.0000000000000000000                 |",
-        "| 0.9090909090909090909                 |",
-        "| 0.9615384615384615384                 |",
-        "| 0.6410256410256410256                 |",
-        "| 1.5151515151515151515                 |",
-        "| 0.7352941176470588235                 |",
-        "| 0.5000000000000000000                 |",
-        "+---------------------------------------+",
-    ];
-    assert_batches_eq!(expected, &actual);
-
-    // modulo
-    let sql = "select c5%cast(0.00001 as decimal(5,5)) from decimal_simple";
-    let actual = execute_to_batches(&ctx, sql).await;
-    assert_eq!(
-        &DataType::Decimal128(7, 7),
-        actual[0].schema().field(0).data_type()
-    );
-    let expected = vec![
-        "+--------------------------------------+",
-        "| decimal_simple.c5 % Float64(0.00001) |",
-        "+--------------------------------------+",
-        "| 0.0000040                            |",
-        "| 0.0000050                            |",
-        "| 0.0000090                            |",
-        "| 0.0000020                            |",
-        "| 0.0000050                            |",
-        "| 0.0000010                            |",
-        "| 0.0000040                            |",
-        "| 0.0000000                            |",
-        "| 0.0000000                            |",
-        "| 0.0000040                            |",
-        "| 0.0000020                            |",
-        "| 0.0000080                            |",
-        "| 0.0000030                            |",
-        "| 0.0000080                            |",
-        "| 0.0000000                            |",
-        "+--------------------------------------+",
-    ];
-    assert_batches_eq!(expected, &actual);
 
-    let sql = "select c1%c5 from decimal_simple";
-    let actual = execute_to_batches(&ctx, sql).await;
     assert_eq!(
-        &DataType::Decimal128(11, 7),
+        &DataType::Decimal128(21, 12),
         actual[0].schema().field(0).data_type()
     );
-    let expected = vec![
-        "+---------------------------------------+",
-        "| decimal_simple.c1 % decimal_simple.c5 |",
-        "+---------------------------------------+",
-        "| 0.0000100                             |",
-        "| 0.0000200                             |",
-        "| 0.0000010                             |",
-        "| 0.0000300                             |",
-        "| 0.0000300                             |",
-        "| 0.0000080                             |",
-        "| 0.0000400                             |",
-        "| 0.0000000                             |",
-        "| 0.0000000                             |",
-        "| 0.0000400                             |",
-        "| 0.0000500                             |",
-        "| 0.0000500                             |",
-        "| 0.0000170                             |",
-        "| 0.0000500                             |",
-        "| 0.0000500                             |",
-        "+---------------------------------------+",
-    ];
-    assert_batches_eq!(expected, &actual);
-
     Ok(())
 }
 
 #[tokio::test]
-async fn decimal_sort() -> Result<()> {
+async fn divide_precision() -> Result<()> {
     let ctx = SessionContext::new();
     register_decimal_csv_table_by_sql(&ctx).await;
-    let sql = "select * from decimal_simple where c1 >= 0.00004 order by c1";
-    let actual = execute_to_batches(&ctx, sql).await;
-    assert_eq!(
-        &DataType::Decimal128(10, 6),
-        actual[0].schema().field(0).data_type()
-    );
-    let expected = vec![
-        "+----------+----------------+-----+-------+-----------+",
-        "| c1       | c2             | c3  | c4    | c5        |",
-        "+----------+----------------+-----+-------+-----------+",
-        "| 0.000040 | 0.000000000004 | 5   | true  | 0.0000440 |",
-        "| 0.000040 | 0.000000000004 | 12  | false | 0.0000400 |",
-        "| 0.000040 | 0.000000000004 | 14  | true  | 0.0000400 |",
-        "| 0.000040 | 0.000000000004 | 8   | false | 0.0000440 |",
-        "| 0.000050 | 0.000000000005 | 9   | true  | 0.0000520 |",
-        "| 0.000050 | 0.000000000005 | 4   | true  | 0.0000780 |",
-        "| 0.000050 | 0.000000000005 | 8   | false | 0.0000330 |",
-        "| 0.000050 | 0.000000000005 | 100 | true  | 0.0000680 |",
-        "| 0.000050 | 0.000000000005 | 1   | false | 0.0001000 |",
-        "+----------+----------------+-----+-------+-----------+",
-    ];
-    assert_batches_eq!(expected, &actual);
-
-    let sql = "select * from decimal_simple where c1 >= 0.00004 order by c1 limit 10";
-    let actual = execute_to_batches(&ctx, sql).await;
-    assert_eq!(
-        &DataType::Decimal128(10, 6),
-        actual[0].schema().field(0).data_type()
-    );
-    let expected = vec![
-        "+----------+----------------+-----+-------+-----------+",
-        "| c1       | c2             | c3  | c4    | c5        |",
-        "+----------+----------------+-----+-------+-----------+",
-        "| 0.000040 | 0.000000000004 | 5   | true  | 0.0000440 |",
-        "| 0.000040 | 0.000000000004 | 12  | false | 0.0000400 |",
-        "| 0.000040 | 0.000000000004 | 14  | true  | 0.0000400 |",
-        "| 0.000040 | 0.000000000004 | 8   | false | 0.0000440 |",
-        "| 0.000050 | 0.000000000005 | 9   | true  | 0.0000520 |",
-        "| 0.000050 | 0.000000000005 | 4   | true  | 0.0000780 |",
-        "| 0.000050 | 0.000000000005 | 8   | false | 0.0000330 |",
-        "| 0.000050 | 0.000000000005 | 100 | true  | 0.0000680 |",
-        "| 0.000050 | 0.000000000005 | 1   | false | 0.0001000 |",
-        "+----------+----------------+-----+-------+-----------+",
-    ];
-    assert_batches_eq!(expected, &actual);
-
-    let sql = "select * from decimal_simple where c1 >= 0.00004 order by c1 limit 5";
-    let actual = execute_to_batches(&ctx, sql).await;
-    assert_eq!(
-        &DataType::Decimal128(10, 6),
-        actual[0].schema().field(0).data_type()
-    );
-    let expected = vec![
-        "+----------+----------------+----+-------+-----------+",
-        "| c1       | c2             | c3 | c4    | c5        |",
-        "+----------+----------------+----+-------+-----------+",
-        "| 0.000040 | 0.000000000004 | 5  | true  | 0.0000440 |",
-        "| 0.000040 | 0.000000000004 | 12 | false | 0.0000400 |",
-        "| 0.000040 | 0.000000000004 | 14 | true  | 0.0000400 |",
-        "| 0.000040 | 0.000000000004 | 8  | false | 0.0000440 |",
-        "| 0.000050 | 0.000000000005 | 9  | true  | 0.0000520 |",
-        "+----------+----------------+----+-------+-----------+",
-    ];
-    assert_batches_eq!(expected, &actual);
-
-    let sql = "select * from decimal_simple where c1 >= 0.00004 order by c1 desc";
-    let actual = execute_to_batches(&ctx, sql).await;
-    assert_eq!(
-        &DataType::Decimal128(10, 6),
-        actual[0].schema().field(0).data_type()
-    );
-    let expected = vec![
-        "+----------+----------------+-----+-------+-----------+",
-        "| c1       | c2             | c3  | c4    | c5        |",
-        "+----------+----------------+-----+-------+-----------+",
-        "| 0.000050 | 0.000000000005 | 9   | true  | 0.0000520 |",
-        "| 0.000050 | 0.000000000005 | 4   | true  | 0.0000780 |",
-        "| 0.000050 | 0.000000000005 | 8   | false | 0.0000330 |",
-        "| 0.000050 | 0.000000000005 | 100 | true  | 0.0000680 |",
-        "| 0.000050 | 0.000000000005 | 1   | false | 0.0001000 |",
-        "| 0.000040 | 0.000000000004 | 5   | true  | 0.0000440 |",
-        "| 0.000040 | 0.000000000004 | 12  | false | 0.0000400 |",
-        "| 0.000040 | 0.000000000004 | 14  | true  | 0.0000400 |",
-        "| 0.000040 | 0.000000000004 | 8   | false | 0.0000440 |",
-        "+----------+----------------+-----+-------+-----------+",
-    ];
-    assert_batches_eq!(expected, &actual);
-
-    let sql = "select * from decimal_simple where c1 < 0.00003 order by c1 desc,c4";
+    let sql = "select c1/c5 from decimal_simple";
+
     let actual = execute_to_batches(&ctx, sql).await;
+
     assert_eq!(
-        &DataType::Decimal128(10, 6),
+        &DataType::Decimal128(30, 19),

Review Comment:
   I moved the data expectations to the sqllogictest. But I left the tests that check precision and scale of the results, cause there is no way to reproduce these checks in sqllogictest.



-- 
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


[GitHub] [arrow-datafusion] ursabot commented on pull request #5086: [sqllogictest] Move `decimal.rs` tests

Posted by "ursabot (via GitHub)" <gi...@apache.org>.
ursabot commented on PR #5086:
URL: https://github.com/apache/arrow-datafusion/pull/5086#issuecomment-1407398164

   Benchmark runs are scheduled for baseline = 3da801d9d990bbd6c5047082b5da9ae5a52b795d and contender = 69678d53d09e6fde199a94eff2ff2e5a4083f183. 69678d53d09e6fde199a94eff2ff2e5a4083f183 is a master commit associated with this PR. Results will be available as each benchmark for each run completes.
   Conbench compare runs links:
   [Skipped :warning: Benchmarking of arrow-datafusion-commits is not supported on ec2-t3-xlarge-us-east-2] [ec2-t3-xlarge-us-east-2](https://conbench.ursa.dev/compare/runs/c8e9fb9b13cb4b9d8601e01d60b58fa8...04bf4f93180c4bba906dd01452580071/)
   [Skipped :warning: Benchmarking of arrow-datafusion-commits is not supported on test-mac-arm] [test-mac-arm](https://conbench.ursa.dev/compare/runs/234f0e79154d4fbda246eada8ef77447...bf82b9130910449096a3c00d8726158a/)
   [Skipped :warning: Benchmarking of arrow-datafusion-commits is not supported on ursa-i9-9960x] [ursa-i9-9960x](https://conbench.ursa.dev/compare/runs/1afa791cc3ac4fa98c1f5e0560f1b605...49b3b5a0f80c4a358702e812095909b5/)
   [Skipped :warning: Benchmarking of arrow-datafusion-commits is not supported on ursa-thinkcentre-m75q] [ursa-thinkcentre-m75q](https://conbench.ursa.dev/compare/runs/91c73c8b9f6e4e3fb5a6c9d0e0d8e107...65816c8d013e4d1c804ef1a4c21a8b3c/)
   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
   


-- 
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


[GitHub] [arrow-datafusion] melgenek commented on a diff in pull request #5086: [sqllogictest] Move `decimal.rs` tests

Posted by "melgenek (via GitHub)" <gi...@apache.org>.
melgenek commented on code in PR #5086:
URL: https://github.com/apache/arrow-datafusion/pull/5086#discussion_r1089552191


##########
datafusion/core/tests/sql/decimal.rs:
##########
@@ -879,37 +296,3 @@ async fn decimal_null_array_scalar_comparison() -> Result<()> {
     assert_eq!(&DataType::Boolean, actual[0].column(0).data_type());

Review Comment:
   Thank you for the hint, `arrow_typeof` works quite well! https://github.com/apache/arrow-datafusion/pull/5086/commits/8295aa5f7a138d1d44d3c05c436b88ef0b82140c



-- 
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