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

[GitHub] [arrow-datafusion] alamb commented on a diff in pull request #7704: Minor: Consolidate UDF tests

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


##########
datafusion/core/tests/user_defined/user_defined_scalar_functions.rs:
##########
@@ -15,26 +15,40 @@
 // specific language governing permissions and limitations
 // under the License.
 
-use super::*;
 use arrow::compute::kernels::numeric::add;
+use arrow_array::{ArrayRef, Float64Array, Int32Array, RecordBatch};
+use arrow_schema::{DataType, Field, Schema};
+use datafusion::datasource::MemTable;
+use datafusion::prelude::*;
 use datafusion::{
     execution::registry::FunctionRegistry,
     physical_plan::{expressions::AvgAccumulator, functions::make_scalar_function},
+    test_util,
 };
-use datafusion_common::{cast::as_int32_array, ScalarValue};
-use datafusion_expr::{create_udaf, Accumulator, LogicalPlanBuilder};
+use datafusion_common::cast::as_float64_array;
+use datafusion_common::{assert_batches_eq, cast::as_int32_array, Result, ScalarValue};
+use datafusion_expr::{
+    create_udaf, create_udf, Accumulator, ColumnarValue, LogicalPlanBuilder, Volatility,
+};
+use std::sync::Arc;
 
 /// test that casting happens on udfs.
 /// c11 is f32, but `custom_sqrt` requires f64. Casting happens but the logical plan and
 /// physical plan have the same schema.
 #[tokio::test]
 async fn csv_query_custom_udf_with_cast() -> Result<()> {
-    let ctx = create_ctx();
+    let ctx = create_udf_context();
     register_aggregate_csv(&ctx).await?;
     let sql = "SELECT avg(custom_sqrt(c11)) FROM aggregate_test_100";
-    let actual = execute(&ctx, sql).await;
-    let expected = vec![vec!["0.6584408483418833"]];
-    assert_float_eq(&expected, &actual);
+    let actual = plan_and_collect(&ctx, sql).await.unwrap();

Review Comment:
   this was using a (very) old style to execute



##########
datafusion/core/tests/sql/expr.rs:
##########
@@ -886,18 +886,6 @@ async fn csv_query_nullif_divide_by_0() -> Result<()> {
     Ok(())
 }
 
-#[tokio::test]

Review Comment:
   this was randomly in the file for testing exprs when it is actually an (user defined) aggregate query  😕 



##########
datafusion/core/tests/sql/expr.rs:
##########
@@ -886,18 +886,6 @@ async fn csv_query_nullif_divide_by_0() -> Result<()> {
     Ok(())
 }
 
-#[tokio::test]

Review Comment:
   this was randomly in the file for testing exprs when it is actually an (user defined) aggregate query  😕 



##########
datafusion/core/tests/sql/mod.rs:
##########
@@ -101,54 +96,6 @@ pub mod select;
 mod sql_api;
 pub mod subqueries;
 pub mod timestamp;
-pub mod udf;
-
-fn assert_float_eq<T>(expected: &[Vec<T>], received: &[Vec<String>])

Review Comment:
   not needed



##########
datafusion/core/src/execution/context.rs:
##########
@@ -2330,87 +2330,6 @@ mod tests {
         Ok(())
     }
 
-    #[tokio::test]

Review Comment:
   moved to user defined tests



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