You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@arrow.apache.org by ja...@apache.org on 2023/06/09 15:07:21 UTC

[arrow-datafusion] branch main updated: move functions.rs to sqllogictests (#6608)

This is an automated email from the ASF dual-hosted git repository.

jakevin pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow-datafusion.git


The following commit(s) were added to refs/heads/main by this push:
     new d9e91d187c move functions.rs to sqllogictests (#6608)
d9e91d187c is described below

commit d9e91d187c8af7f39999f8b1a11d53383826a471
Author: zhenxing jiang <ji...@gmail.com>
AuthorDate: Fri Jun 9 23:07:13 2023 +0800

    move functions.rs to sqllogictests (#6608)
---
 datafusion/core/tests/sql/functions.rs             | 143 ---------------------
 datafusion/core/tests/sql/mod.rs                   |   1 -
 .../tests/sqllogictests/test_files/functions.slt   |  88 ++++++++++++-
 3 files changed, 87 insertions(+), 145 deletions(-)

diff --git a/datafusion/core/tests/sql/functions.rs b/datafusion/core/tests/sql/functions.rs
deleted file mode 100644
index b7531cc687..0000000000
--- a/datafusion/core/tests/sql/functions.rs
+++ /dev/null
@@ -1,143 +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 sqrt_f32_vs_f64() -> Result<()> {
-    let ctx = create_ctx();
-    register_aggregate_csv(&ctx).await?;
-    // sqrt(f32)'s plan passes
-    let sql = "SELECT avg(sqrt(c11)) FROM aggregate_test_100";
-    let actual = execute(&ctx, sql).await;
-    let sql = "SELECT avg(CAST(sqrt(c11) AS double)) FROM aggregate_test_100";
-    let expected = execute(&ctx, sql).await;
-
-    assert_eq!(actual, expected);
-    let sql = "SELECT avg(sqrt(CAST(c11 AS double))) FROM aggregate_test_100";
-    let actual = execute(&ctx, sql).await;
-    let expected = vec![vec!["0.6584408483418833"]];
-    assert_float_eq(&expected, &actual);
-    Ok(())
-}
-
-#[tokio::test]
-async fn case_sensitive_identifiers_functions() {
-    let ctx = SessionContext::new();
-    ctx.register_table("t", table_with_sequence(1, 1).unwrap())
-        .unwrap();
-
-    let expected = vec![
-        "+-----------+",
-        "| sqrt(t.i) |",
-        "+-----------+",
-        "| 1.0       |",
-        "+-----------+",
-    ];
-
-    let results = plan_and_collect(&ctx, "SELECT sqrt(i) FROM t")
-        .await
-        .unwrap();
-
-    assert_batches_sorted_eq!(expected, &results);
-
-    let results = plan_and_collect(&ctx, "SELECT SQRT(i) FROM t")
-        .await
-        .unwrap();
-    assert_batches_sorted_eq!(expected, &results);
-
-    // Using double quotes allows specifying the function name with capitalization
-    let err = plan_and_collect(&ctx, "SELECT \"SQRT\"(i) FROM t")
-        .await
-        .unwrap_err();
-    assert!(err
-        .to_string()
-        .contains("Error during planning: Invalid function 'SQRT'"));
-
-    let results = plan_and_collect(&ctx, "SELECT \"sqrt\"(i) FROM t")
-        .await
-        .unwrap();
-    assert_batches_sorted_eq!(expected, &results);
-}
-
-#[tokio::test]
-async fn case_builtin_math_expression() {
-    let ctx = SessionContext::new();
-
-    let type_values = vec![
-        (
-            DataType::Int8,
-            Arc::new(Int8Array::from(vec![1])) as ArrayRef,
-        ),
-        (
-            DataType::Int16,
-            Arc::new(Int16Array::from(vec![1])) as ArrayRef,
-        ),
-        (
-            DataType::Int32,
-            Arc::new(Int32Array::from(vec![1])) as ArrayRef,
-        ),
-        (
-            DataType::Int64,
-            Arc::new(Int64Array::from(vec![1])) as ArrayRef,
-        ),
-        (
-            DataType::UInt8,
-            Arc::new(UInt8Array::from(vec![1])) as ArrayRef,
-        ),
-        (
-            DataType::UInt16,
-            Arc::new(UInt16Array::from(vec![1])) as ArrayRef,
-        ),
-        (
-            DataType::UInt32,
-            Arc::new(UInt32Array::from(vec![1])) as ArrayRef,
-        ),
-        (
-            DataType::UInt64,
-            Arc::new(UInt64Array::from(vec![1])) as ArrayRef,
-        ),
-        (
-            DataType::Float32,
-            Arc::new(Float32Array::from(vec![1.0_f32])) as ArrayRef,
-        ),
-        (
-            DataType::Float64,
-            Arc::new(Float64Array::from(vec![1.0_f64])) as ArrayRef,
-        ),
-    ];
-
-    for (data_type, array) in type_values.iter() {
-        let schema =
-            Arc::new(Schema::new(vec![Field::new("v", data_type.clone(), false)]));
-        let batch = RecordBatch::try_new(schema.clone(), vec![array.clone()]).unwrap();
-        ctx.deregister_table("t").unwrap();
-        ctx.register_batch("t", batch).unwrap();
-        let expected = vec![
-            "+-----------+",
-            "| sqrt(t.v) |",
-            "+-----------+",
-            "| 1.0       |",
-            "+-----------+",
-        ];
-        let results = plan_and_collect(&ctx, "SELECT sqrt(v) FROM t")
-            .await
-            .unwrap();
-
-        assert_batches_sorted_eq!(expected, &results);
-    }
-}
diff --git a/datafusion/core/tests/sql/mod.rs b/datafusion/core/tests/sql/mod.rs
index 10660f7873..0413a06b6a 100644
--- a/datafusion/core/tests/sql/mod.rs
+++ b/datafusion/core/tests/sql/mod.rs
@@ -83,7 +83,6 @@ pub mod arrow_files;
 pub mod create_drop;
 pub mod explain_analyze;
 pub mod expr;
-pub mod functions;
 pub mod group_by;
 pub mod joins;
 pub mod limit;
diff --git a/datafusion/core/tests/sqllogictests/test_files/functions.slt b/datafusion/core/tests/sqllogictests/test_files/functions.slt
index b52dca5770..92597118c6 100644
--- a/datafusion/core/tests/sqllogictests/test_files/functions.slt
+++ b/datafusion/core/tests/sqllogictests/test_files/functions.slt
@@ -479,4 +479,90 @@ SELECT struct(c1,c2,c3,c4,a,b) from simple_struct_test
 {c0: 1, c1: 1, c2: 3.1, c3: 3.14, c4: str, c5: text}
 
 statement ok
-drop table simple_struct_test
\ No newline at end of file
+drop table simple_struct_test
+
+# create aggregate_test_100 table for functions test
+statement ok
+CREATE EXTERNAL TABLE aggregate_test_100 (
+  c1  VARCHAR NOT NULL,
+  c2  TINYINT NOT NULL,
+  c3  SMALLINT NOT NULL,
+  c4  SMALLINT,
+  c5  INT,
+  c6  BIGINT NOT NULL,
+  c7  SMALLINT NOT NULL,
+  c8  INT NOT NULL,
+  c9  BIGINT UNSIGNED NOT NULL,
+  c10 VARCHAR NOT NULL,
+  c11 FLOAT NOT NULL,
+  c12 DOUBLE NOT NULL,
+  c13 VARCHAR NOT NULL
+)
+STORED AS CSV
+WITH HEADER ROW
+LOCATION '../../testing/data/csv/aggregate_test_100.csv'
+
+
+# sqrt_f32_vs_f64
+query R
+SELECT avg(sqrt(c11)) FROM aggregate_test_100
+----
+0.658440848589
+
+query R
+SELECT avg(CAST(sqrt(c11) AS double)) FROM aggregate_test_100
+----
+0.658440848589
+
+query R
+SELECT avg(sqrt(CAST(c11 AS double))) FROM aggregate_test_100
+----
+0.658440848342
+
+statement ok
+drop table aggregate_test_100
+
+
+# case_sensitive_identifiers_functions
+statement ok
+create table t as values (
+    arrow_cast(2, 'Int8'),
+    arrow_cast(2, 'Int16'),
+    arrow_cast(2, 'Int32'),
+    arrow_cast(2, 'Int64'),
+    arrow_cast(2, 'UInt8'),
+    arrow_cast(2, 'UInt16'),
+    arrow_cast(2, 'UInt32'),
+    arrow_cast(2, 'UInt64'),
+    arrow_cast(2, 'Float32'),
+    arrow_cast(2, 'Float64')
+)
+;
+
+query R
+SELECT sqrt(column1) FROM t
+----
+1.414213562373
+
+query R
+SELECT SQRT(column1) FROM t
+----
+1.414213562373
+
+statement error Error during planning: Invalid function 'SQRT'
+SELECT "SQRT"(column1) FROM t
+
+query R
+SELECT "sqrt"(column1) FROM t
+----
+1.414213562373
+
+# case_builtin_math_expression
+query RRRRRRRRRR
+SELECT sqrt(column1),sqrt(column2),sqrt(column3),sqrt(column4),sqrt(column5),sqrt(column6),sqrt(column7),sqrt(column8),sqrt(column9),sqrt(column10) FROM t
+----
+1.414213562373 1.414213562373 1.414213562373 1.414213562373 1.414213562373 1.414213562373 1.414213562373 1.414213562373 1.4142135 1.414213562373
+
+statement ok
+drop table t
+