Jefffrey commented on code in PR #19402:
URL: https://github.com/apache/datafusion/pull/19402#discussion_r2634183518
##########
datafusion/functions/src/string/ltrim.rs:
##########
@@ -115,11 +115,7 @@ impl ScalarUDFImpl for LtrimFunc {
}
fn return_type(&self, arg_types: &[DataType]) -> Result<DataType> {
- if arg_types[0] == DataType::Utf8View {
- Ok(DataType::Utf8View)
- } else {
- utf8_to_str_type(&arg_types[0], "ltrim")
Review Comment:
`utf8_to_str_type()` preserves type to LargeUtf8 if input is large,
otherwise just Utf8; we can see we also preserve view type, so in this case we
are just preserving the input type as is
##########
datafusion/functions/src/string/split_part.rs:
##########
@@ -60,19 +63,16 @@ impl Default for SplitPartFunc {
impl SplitPartFunc {
pub fn new() -> Self {
- use DataType::*;
Self {
- signature: Signature::one_of(
+ signature: Signature::coercible(
vec![
- TypeSignature::Exact(vec![Utf8View, Utf8View, Int64]),
- TypeSignature::Exact(vec![Utf8View, Utf8, Int64]),
- TypeSignature::Exact(vec![Utf8View, LargeUtf8, Int64]),
- TypeSignature::Exact(vec![Utf8, Utf8View, Int64]),
- TypeSignature::Exact(vec![Utf8, Utf8, Int64]),
- TypeSignature::Exact(vec![LargeUtf8, Utf8View, Int64]),
- TypeSignature::Exact(vec![LargeUtf8, Utf8, Int64]),
- TypeSignature::Exact(vec![Utf8, LargeUtf8, Int64]),
- TypeSignature::Exact(vec![LargeUtf8, LargeUtf8, Int64]),
+
Coercion::new_exact(TypeSignatureClass::Native(logical_string())),
Review Comment:
More compact API
##########
datafusion/functions/src/string/ends_with.rs:
##########
@@ -95,14 +95,7 @@ impl ScalarUDFImpl for EndsWithFunc {
}
fn invoke_with_args(&self, args: ScalarFunctionArgs) ->
Result<ColumnarValue> {
- match args.args[0].data_type() {
- DataType::Utf8View | DataType::Utf8 | DataType::LargeUtf8 => {
- make_scalar_function(ends_with, vec![])(&args.args)
- }
- other => internal_err!(
- "Unsupported data type {other:?} for function ends_with.
Expected Utf8, LargeUtf8 or Utf8View"
- )?,
- }
+ make_scalar_function(ends_with, vec![])(&args.args)
Review Comment:
This is guarded by signature so no need to do it again here
##########
datafusion/functions/src/string/to_hex.rs:
##########
@@ -131,25 +118,37 @@ impl ScalarUDFImpl for ToHexFunc {
&self.signature
}
- fn return_type(&self, arg_types: &[DataType]) -> Result<DataType> {
- Ok(match arg_types[0] {
- Int8 | Int16 | Int32 | Int64 | UInt8 | UInt16 | UInt32 | UInt64 =>
Utf8,
- _ => {
- return plan_err!("The to_hex function can only accept
integers.");
- }
- })
+ fn return_type(&self, _arg_types: &[DataType]) -> Result<DataType> {
+ Ok(DataType::Utf8)
}
fn invoke_with_args(&self, args: ScalarFunctionArgs) ->
Result<ColumnarValue> {
match args.args[0].data_type() {
- Int64 => make_scalar_function(to_hex::<Int64Type>,
vec![])(&args.args),
- UInt64 => make_scalar_function(to_hex::<UInt64Type>,
vec![])(&args.args),
- Int32 => make_scalar_function(to_hex::<Int32Type>,
vec![])(&args.args),
- UInt32 => make_scalar_function(to_hex::<UInt32Type>,
vec![])(&args.args),
- Int16 => make_scalar_function(to_hex::<Int16Type>,
vec![])(&args.args),
- UInt16 => make_scalar_function(to_hex::<UInt16Type>,
vec![])(&args.args),
- Int8 => make_scalar_function(to_hex::<Int8Type>,
vec![])(&args.args),
- UInt8 => make_scalar_function(to_hex::<UInt8Type>,
vec![])(&args.args),
+ DataType::Null =>
Ok(ColumnarValue::Scalar(ScalarValue::Utf8(None))),
Review Comment:
I prefer having the `DataType::` but this is just personal preference, can
revert if is too verbose
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]