Skip to content

Commit 368df80

Browse files
authored
Add tests for StringView / character functions, fix regexp_like and 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
1 parent 193955e commit 368df80

File tree

4 files changed

+427
-105
lines changed

4 files changed

+427
-105
lines changed

datafusion/functions/src/regex/regexplike.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,13 +75,10 @@ impl ScalarUDFImpl for RegexpLikeFunc {
7575
use DataType::*;
7676

7777
Ok(match &arg_types[0] {
78-
LargeUtf8 | Utf8 => Boolean,
7978
Null => Null,
80-
other => {
81-
return plan_err!(
82-
"The regexp_like function can only accept strings. Got {other}"
83-
);
84-
}
79+
// Type coercion is done by DataFusion based on signature, so if we
80+
// get here, the first argument is always a string
81+
_ => Boolean,
8582
})
8683
}
8784
fn invoke(&self, args: &[ColumnarValue]) -> Result<ColumnarValue> {

datafusion/functions/src/regex/regexpmatch.rs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -74,17 +74,9 @@ impl ScalarUDFImpl for RegexpMatchFunc {
7474
}
7575

7676
fn return_type(&self, arg_types: &[DataType]) -> Result<DataType> {
77-
use DataType::*;
78-
7977
Ok(match &arg_types[0] {
80-
LargeUtf8 => List(Arc::new(Field::new("item", LargeUtf8, true))),
81-
Utf8 => List(Arc::new(Field::new("item", Utf8, true))),
82-
Null => Null,
83-
other => {
84-
return plan_err!(
85-
"The regexp_match function can only accept strings. Got {other}"
86-
);
87-
}
78+
DataType::Null => DataType::Null,
79+
other => DataType::List(Arc::new(Field::new("item", other.clone(), true))),
8880
})
8981
}
9082
fn invoke(&self, args: &[ColumnarValue]) -> Result<ColumnarValue> {

datafusion/functions/src/unicode/character_length.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ impl CharacterLengthFunc {
4444
Self {
4545
signature: Signature::uniform(
4646
1,
47-
vec![Utf8, LargeUtf8],
47+
vec![Utf8, LargeUtf8, Utf8View],
4848
Volatility::Immutable,
4949
),
5050
aliases: vec![String::from("length"), String::from("char_length")],

0 commit comments

Comments
 (0)