From 200508b6eb8d8b7f21ff1a8beb095d9631615dba Mon Sep 17 00:00:00 2001 From: Andrew Lamb Date: Fri, 2 Feb 2024 10:20:02 -0500 Subject: [PATCH] wire in and add a test --- datafusion/core/src/lib.rs | 6 ++++ datafusion/core/src/prelude.rs | 2 ++ .../tests/dataframe/dataframe_functions.rs | 30 ++++++++++++++++++- 3 files changed, 37 insertions(+), 1 deletion(-) diff --git a/datafusion/core/src/lib.rs b/datafusion/core/src/lib.rs index 0f7292e1c3d31..d78d7a38a1c34 100644 --- a/datafusion/core/src/lib.rs +++ b/datafusion/core/src/lib.rs @@ -521,6 +521,12 @@ pub mod functions { pub use datafusion_functions::*; } +/// re-export of [`datafusion_functions_array`] crate, if "array_expressions" feature is enabled +pub mod functions_array { + #[cfg(feature = "array_expressions")] + pub use datafusion_functions::*; +} + #[cfg(test)] pub mod test; pub mod test_util; diff --git a/datafusion/core/src/prelude.rs b/datafusion/core/src/prelude.rs index 69c33355402bf..d82a5a2cc1a11 100644 --- a/datafusion/core/src/prelude.rs +++ b/datafusion/core/src/prelude.rs @@ -39,6 +39,8 @@ pub use datafusion_expr::{ Expr, }; pub use datafusion_functions::expr_fn::*; +#[cfg(feature = "array_expressions")] +pub use datafusion_functions_array::expr_fn::*; pub use std::ops::Not; pub use std::ops::{Add, Div, Mul, Neg, Rem, Sub}; diff --git a/datafusion/core/tests/dataframe/dataframe_functions.rs b/datafusion/core/tests/dataframe/dataframe_functions.rs index 486ea712edeb7..48b9120698adb 100644 --- a/datafusion/core/tests/dataframe/dataframe_functions.rs +++ b/datafusion/core/tests/dataframe/dataframe_functions.rs @@ -20,6 +20,8 @@ use arrow::{ array::{Int32Array, StringArray}, record_batch::RecordBatch, }; +use arrow_array::types::Int32Type; +use arrow_array::ListArray; use arrow_schema::SchemaRef; use std::sync::Arc; @@ -40,6 +42,7 @@ fn test_schema() -> SchemaRef { Arc::new(Schema::new(vec![ Field::new("a", DataType::Utf8, false), Field::new("b", DataType::Int32, false), + Field::new("l", DataType::new_list(DataType::Int32, true), true), ])) } @@ -57,6 +60,12 @@ async fn create_test_table() -> Result { "123AbcDef", ])), Arc::new(Int32Array::from(vec![1, 10, 10, 100])), + Arc::new(ListArray::from_iter_primitive::(vec![ + Some(vec![Some(0), Some(1), Some(2)]), + None, + Some(vec![Some(3), None, Some(5)]), + Some(vec![Some(6), Some(7)]), + ])), ], )?; @@ -67,7 +76,7 @@ async fn create_test_table() -> Result { ctx.table("test").await } -/// Excutes an expression on the test dataframe as a select. +/// Executes an expression on the test dataframe as a select. /// Compares formatted output of a record batch with an expected /// vector of strings, using the assert_batch_eq! macro macro_rules! assert_fn_batches { @@ -841,3 +850,22 @@ async fn test_fn_decode() -> Result<()> { Ok(()) } + +#[tokio::test] +async fn test_fn_array_to_string() -> Result<()> { + let expr = array_to_string(col("l"), lit("***")); + + let expected = [ + "+-------------------------------------+", + "| array_to_string(test.l,Utf8(\"***\")) |", + "+-------------------------------------+", + "| 0***1***2 |", + "| |", + "| 3***5 |", + "| 6***7 |", + "+-------------------------------------+", + ]; + assert_fn_batches!(expr, expected); + + Ok(()) +}