From b803062ef2a230deb7608ef10dffde56efbdeb8f Mon Sep 17 00:00:00 2001 From: Andrew Lamb Date: Wed, 20 Mar 2024 16:03:30 -0400 Subject: [PATCH] Export expr_fn, restore tests --- .../tests/dataframe/dataframe_functions.rs | 58 +++++++++++++++++++ datafusion/functions/src/lib.rs | 2 + 2 files changed, 60 insertions(+) diff --git a/datafusion/core/tests/dataframe/dataframe_functions.rs b/datafusion/core/tests/dataframe/dataframe_functions.rs index 04bef652f9c6..cea701492910 100644 --- a/datafusion/core/tests/dataframe/dataframe_functions.rs +++ b/datafusion/core/tests/dataframe/dataframe_functions.rs @@ -650,6 +650,26 @@ async fn test_fn_split_part() -> Result<()> { Ok(()) } +#[tokio::test] +async fn test_fn_starts_with() -> Result<()> { + let expr = starts_with(col("a"), lit("abc")); + + let expected = [ + "+---------------------------------+", + "| starts_with(test.a,Utf8(\"abc\")) |", + "+---------------------------------+", + "| true |", + "| true |", + "| false |", + "| false |", + "+---------------------------------+", + ]; + + assert_fn_batches!(expr, expected); + + Ok(()) +} + #[tokio::test] async fn test_fn_ends_with() -> Result<()> { let expr = ends_with(col("a"), lit("DEF")); @@ -729,6 +749,25 @@ async fn test_cast() -> Result<()> { Ok(()) } +#[tokio::test] +async fn test_fn_to_hex() -> Result<()> { + let expr = to_hex(col("b")); + + let expected = [ + "+----------------+", + "| to_hex(test.b) |", + "+----------------+", + "| 1 |", + "| a |", + "| a |", + "| 64 |", + "+----------------+", + ]; + assert_fn_batches!(expr, expected); + + Ok(()) +} + #[tokio::test] #[cfg(feature = "unicode_expressions")] async fn test_fn_translate() -> Result<()> { @@ -749,6 +788,25 @@ async fn test_fn_translate() -> Result<()> { Ok(()) } +#[tokio::test] +async fn test_fn_upper() -> Result<()> { + let expr = upper(col("a")); + + let expected = [ + "+---------------+", + "| upper(test.a) |", + "+---------------+", + "| ABCDEF |", + "| ABC123 |", + "| CBADEF |", + "| 123ABCDEF |", + "+---------------+", + ]; + assert_fn_batches!(expr, expected); + + Ok(()) +} + #[tokio::test] async fn test_fn_encode() -> Result<()> { let expr = encode(col("a"), lit("hex")); diff --git a/datafusion/functions/src/lib.rs b/datafusion/functions/src/lib.rs index 507f899446d2..f469b343e144 100644 --- a/datafusion/functions/src/lib.rs +++ b/datafusion/functions/src/lib.rs @@ -138,6 +138,8 @@ pub mod expr_fn { pub use super::math::expr_fn::*; #[cfg(feature = "regex_expressions")] pub use super::regex::expr_fn::*; + #[cfg(feature = "string_expressions")] + pub use super::string::expr_fn::*; } /// Registers all enabled packages with a [`FunctionRegistry`]