Skip to content

Commit 1d4d92a

Browse files
authored
Merge pull request #32081 from ptravers/pt/7101
fix string_to_array handle non string delimiter
2 parents d600074 + b062f5e commit 1d4d92a

File tree

3 files changed

+12
-6
lines changed

3 files changed

+12
-6
lines changed

src/expr/src/scalar/func.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2152,6 +2152,7 @@ fn string_to_array<'a>(
21522152
}
21532153

21542154
let delimiter = delimiter.unwrap_str();
2155+
21552156
if delimiter.is_empty() {
21562157
let mut row = Row::default();
21572158
let mut packer = row.packer();
@@ -8206,13 +8207,14 @@ impl VariadicFunc {
82068207
ScalarType::Array(Box::new(ScalarType::String)).nullable(in_nullable)
82078208
}
82088209
RegexpReplace => ScalarType::String.nullable(in_nullable),
8209-
StringToArray => {
8210-
ScalarType::Array(Box::new(ScalarType::String)).nullable(input_types[0].nullable)
8211-
}
8210+
StringToArray => ScalarType::Array(Box::new(ScalarType::String)).nullable(true),
82128211
}
82138212
}
82148213

82158214
/// Whether the function output is NULL if any of its inputs are NULL.
8215+
///
8216+
/// NB: if any input is NULL the output will be returned as NULL without
8217+
/// calling the function.
82168218
pub fn propagates_nulls(&self) -> bool {
82178219
// NOTE: The following is a list of the variadic functions
82188220
// that **DO NOT** propagate nulls.
@@ -8281,13 +8283,13 @@ impl VariadicFunc {
82818283
| ArrayFill { .. }
82828284
| TimezoneTime
82838285
| RegexpSplitToArray
8284-
| StringToArray
82858286
| RegexpReplace => false,
82868287
Coalesce
82878288
| Greatest
82888289
| Least
82898290
| MakeTimestamp
82908291
| ArrayIndex { .. }
8292+
| StringToArray
82918293
| ListIndex
82928294
| RegexpMatch => true,
82938295
}

src/sql/src/func.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3162,8 +3162,8 @@ pub static PG_CATALOG_BUILTINS: LazyLock<BTreeMap<&'static str, Func>> = LazyLoc
31623162
params!(Bytes, Bytes) => Operation::binary(|_ecx, _l, _r| bail_unsupported!("string_agg on BYTEA")) => Bytes, 3545;
31633163
},
31643164
"string_to_array" => Scalar {
3165-
params!(String, Any) => VariadicFunc::StringToArray => ScalarType::Array(Box::new(ScalarType::String)), 376;
3166-
params!(String, Any, String) => VariadicFunc::StringToArray => ScalarType::Array(Box::new(ScalarType::String)), 394;
3165+
params!(String, String) => VariadicFunc::StringToArray => ScalarType::Array(Box::new(ScalarType::String)), 376;
3166+
params!(String, String, String) => VariadicFunc::StringToArray => ScalarType::Array(Box::new(ScalarType::String)), 394;
31673167
},
31683168
"sum" => Aggregate {
31693169
params!(Int16) => AggregateFunc::SumInt16 => Int64, 2109;

test/sqllogictest/string.slt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1833,4 +1833,8 @@ select string_to_array(null, '') from string_to_array_words;
18331833
----
18341834
NULL
18351835

1836+
# string_to_array - non string input results in error.
1837+
query error
1838+
select string_to_array('hello world', 0) from string_to_array_words;
1839+
18361840
# string_to_array - end.

0 commit comments

Comments
 (0)