Skip to content

Commit 200508b

Browse files
committed
wire in and add a test
1 parent ed3906c commit 200508b

File tree

3 files changed

+37
-1
lines changed

3 files changed

+37
-1
lines changed

datafusion/core/src/lib.rs

+6
Original file line numberDiff line numberDiff line change
@@ -521,6 +521,12 @@ pub mod functions {
521521
pub use datafusion_functions::*;
522522
}
523523

524+
/// re-export of [`datafusion_functions_array`] crate, if "array_expressions" feature is enabled
525+
pub mod functions_array {
526+
#[cfg(feature = "array_expressions")]
527+
pub use datafusion_functions::*;
528+
}
529+
524530
#[cfg(test)]
525531
pub mod test;
526532
pub mod test_util;

datafusion/core/src/prelude.rs

+2
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ pub use datafusion_expr::{
3939
Expr,
4040
};
4141
pub use datafusion_functions::expr_fn::*;
42+
#[cfg(feature = "array_expressions")]
43+
pub use datafusion_functions_array::expr_fn::*;
4244

4345
pub use std::ops::Not;
4446
pub use std::ops::{Add, Div, Mul, Neg, Rem, Sub};

datafusion/core/tests/dataframe/dataframe_functions.rs

+29-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ use arrow::{
2020
array::{Int32Array, StringArray},
2121
record_batch::RecordBatch,
2222
};
23+
use arrow_array::types::Int32Type;
24+
use arrow_array::ListArray;
2325
use arrow_schema::SchemaRef;
2426
use std::sync::Arc;
2527

@@ -40,6 +42,7 @@ fn test_schema() -> SchemaRef {
4042
Arc::new(Schema::new(vec![
4143
Field::new("a", DataType::Utf8, false),
4244
Field::new("b", DataType::Int32, false),
45+
Field::new("l", DataType::new_list(DataType::Int32, true), true),
4346
]))
4447
}
4548

@@ -57,6 +60,12 @@ async fn create_test_table() -> Result<DataFrame> {
5760
"123AbcDef",
5861
])),
5962
Arc::new(Int32Array::from(vec![1, 10, 10, 100])),
63+
Arc::new(ListArray::from_iter_primitive::<Int32Type, _, _>(vec![
64+
Some(vec![Some(0), Some(1), Some(2)]),
65+
None,
66+
Some(vec![Some(3), None, Some(5)]),
67+
Some(vec![Some(6), Some(7)]),
68+
])),
6069
],
6170
)?;
6271

@@ -67,7 +76,7 @@ async fn create_test_table() -> Result<DataFrame> {
6776
ctx.table("test").await
6877
}
6978

70-
/// Excutes an expression on the test dataframe as a select.
79+
/// Executes an expression on the test dataframe as a select.
7180
/// Compares formatted output of a record batch with an expected
7281
/// vector of strings, using the assert_batch_eq! macro
7382
macro_rules! assert_fn_batches {
@@ -841,3 +850,22 @@ async fn test_fn_decode() -> Result<()> {
841850

842851
Ok(())
843852
}
853+
854+
#[tokio::test]
855+
async fn test_fn_array_to_string() -> Result<()> {
856+
let expr = array_to_string(col("l"), lit("***"));
857+
858+
let expected = [
859+
"+-------------------------------------+",
860+
"| array_to_string(test.l,Utf8(\"***\")) |",
861+
"+-------------------------------------+",
862+
"| 0***1***2 |",
863+
"| |",
864+
"| 3***5 |",
865+
"| 6***7 |",
866+
"+-------------------------------------+",
867+
];
868+
assert_fn_batches!(expr, expected);
869+
870+
Ok(())
871+
}

0 commit comments

Comments
 (0)