Skip to content

Fix contains function expression #16046

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion datafusion/functions/src/string/contains.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,11 @@ fn contains(args: &[ArrayRef]) -> Result<ArrayRef, DataFusionError> {
#[cfg(test)]
mod test {
use super::ContainsFunc;
use crate::expr_fn::contains;
use arrow::array::{BooleanArray, StringArray};
use arrow::datatypes::{DataType, Field};
use datafusion_common::ScalarValue;
use datafusion_expr::{ColumnarValue, ScalarFunctionArgs, ScalarUDFImpl};
use datafusion_expr::{ColumnarValue, Expr, ScalarFunctionArgs, ScalarUDFImpl};
use std::sync::Arc;

#[test]
Expand Down Expand Up @@ -186,4 +187,16 @@ mod test {
*expect.into_array(2).unwrap()
);
}

#[test]
fn test_contains_api() {
let expr = contains(
Expr::Literal(ScalarValue::Utf8(Some("the quick brown fox".to_string()))),
Expr::Literal(ScalarValue::Utf8(Some("row".to_string()))),
);
assert_eq!(
expr.to_string(),
"contains(Utf8(\"the quick brown fox\"), Utf8(\"row\"))"
);
}
}
3 changes: 2 additions & 1 deletion datafusion/functions/src/string/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,8 @@ pub mod expr_fn {
"returns uuid v4 as a string value",
), (
contains,
"Return true if search_string is found within string.",
"Return true if `search_string` is found within `string`.",
string search_string
));

#[doc = "Removes all characters, spaces by default, from both sides of a string"]
Expand Down
Loading