Skip to content

Commit

Permalink
Export expr_fn, restore tests
Browse files Browse the repository at this point in the history
  • Loading branch information
alamb committed Mar 20, 2024
1 parent 6ae4207 commit b803062
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 0 deletions.
58 changes: 58 additions & 0 deletions datafusion/core/tests/dataframe/dataframe_functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
Expand Down Expand Up @@ -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<()> {
Expand All @@ -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"));
Expand Down
2 changes: 2 additions & 0 deletions datafusion/functions/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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`]
Expand Down

0 comments on commit b803062

Please sign in to comment.