Skip to content

Commit

Permalink
Add tests for StringView / character functions, fix regexp_like and…
Browse files Browse the repository at this point in the history
… `regexp_match` to work with StringView (#11753)

* Minor: Add tests for StringView / character functions

* Fix regexp_like and regexp_match to work with StringVeiw

* Update for ASCII and BTRIM

* Add comment about why it is ok to return boolean with catchall match

* Fix character_length

* Add ticket references
  • Loading branch information
alamb authored Aug 8, 2024
1 parent 193955e commit 368df80
Show file tree
Hide file tree
Showing 4 changed files with 427 additions and 105 deletions.
9 changes: 3 additions & 6 deletions datafusion/functions/src/regex/regexplike.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,10 @@ impl ScalarUDFImpl for RegexpLikeFunc {
use DataType::*;

Ok(match &arg_types[0] {
LargeUtf8 | Utf8 => Boolean,
Null => Null,
other => {
return plan_err!(
"The regexp_like function can only accept strings. Got {other}"
);
}
// Type coercion is done by DataFusion based on signature, so if we
// get here, the first argument is always a string
_ => Boolean,
})
}
fn invoke(&self, args: &[ColumnarValue]) -> Result<ColumnarValue> {
Expand Down
12 changes: 2 additions & 10 deletions datafusion/functions/src/regex/regexpmatch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,17 +74,9 @@ impl ScalarUDFImpl for RegexpMatchFunc {
}

fn return_type(&self, arg_types: &[DataType]) -> Result<DataType> {
use DataType::*;

Ok(match &arg_types[0] {
LargeUtf8 => List(Arc::new(Field::new("item", LargeUtf8, true))),
Utf8 => List(Arc::new(Field::new("item", Utf8, true))),
Null => Null,
other => {
return plan_err!(
"The regexp_match function can only accept strings. Got {other}"
);
}
DataType::Null => DataType::Null,
other => DataType::List(Arc::new(Field::new("item", other.clone(), true))),
})
}
fn invoke(&self, args: &[ColumnarValue]) -> Result<ColumnarValue> {
Expand Down
2 changes: 1 addition & 1 deletion datafusion/functions/src/unicode/character_length.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ impl CharacterLengthFunc {
Self {
signature: Signature::uniform(
1,
vec![Utf8, LargeUtf8],
vec![Utf8, LargeUtf8, Utf8View],
Volatility::Immutable,
),
aliases: vec![String::from("length"), String::from("char_length")],
Expand Down
Loading

0 comments on commit 368df80

Please sign in to comment.