alamb commented on code in PR #11787: URL: https://github.com/apache/datafusion/pull/11787#discussion_r1702675305
########## datafusion/functions/src/string/starts_with.rs: ########## @@ -30,12 +30,8 @@ use crate::utils::make_scalar_function; /// Returns true if string starts with prefix. /// starts_with('alphabet', 'alph') = 't' -pub fn starts_with<T: OffsetSizeTrait>(args: &[ArrayRef]) -> Result<ArrayRef> { - let left = as_generic_string_array::<T>(&args[0])?; - let right = as_generic_string_array::<T>(&args[1])?; - - let result = arrow::compute::kernels::comparison::starts_with(left, right)?; - +pub fn starts_with(args: &[ArrayRef]) -> Result<ArrayRef> { + let result = arrow::compute::kernels::comparison::starts_with(&args[0], &args[1])?; Review Comment: 👍 ########## datafusion/functions/src/string/starts_with.rs: ########## @@ -81,18 +75,73 @@ impl ScalarUDFImpl for StartsWithFunc { } fn return_type(&self, _arg_types: &[DataType]) -> Result<DataType> { - use DataType::*; - - Ok(Boolean) + Ok(DataType::Boolean) } fn invoke(&self, args: &[ColumnarValue]) -> Result<ColumnarValue> { match args[0].data_type() { - DataType::Utf8 => make_scalar_function(starts_with::<i32>, vec![])(args), - DataType::LargeUtf8 => { - return make_scalar_function(starts_with::<i64>, vec![])(args); + DataType::Utf8View | DataType::Utf8 | DataType::LargeUtf8 => { + make_scalar_function(starts_with, vec![])(args) } - _ => internal_err!("Unsupported data type"), + _ => internal_err!("Unsupported data types for starts_with")?, Review Comment: ```suggestion _ => internal_err!("Unsupported data types for starts_with. Expected Utf8, LargeUtf8 or Utf8View")?, ``` (though this error "shouldn't" occur , which is why it is an internal error -- the type coercion rules should take care of it) -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: github-unsubscr...@datafusion.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: github-unsubscr...@datafusion.apache.org For additional commands, e-mail: github-h...@datafusion.apache.org