Reuse ScalarFunc::find_str in ScalarFunc::instr
@@ -907,18 +907,9 @@ impl ScalarFunc {
) -> Result<Option<i64>> {
let s = try_opt!(self.children[0].eval_string_and_decode(ctx, row));
let substr = try_opt!(self.children[1].eval_string_and_decode(ctx, row));
- if substr.is_empty() {
- return Ok(Some(1));
- }
- if s.is_empty() {
- return Ok(Some(0));
- }
- let s = s.to_lowercase();
- let substr = substr.to_lowercase();
- match s.find(&substr) {
- Some(x) => Ok(Some(1 + s[..x].chars().count() as i64)),
- None => Ok(Some(0)),
- }
+ Ok(Self::find_str(&s.to_lowercase(), &substr.to_lowercase())
+ .map(|i| 1 + i as i64)
+ .or(Some(0)))
}
#[inline]
