skushagra commented on code in PR #19190:
URL: https://github.com/apache/datafusion/pull/19190#discussion_r2647145455
##########
datafusion/spark/src/function/string/format_string.rs:
##########
@@ -78,15 +78,17 @@ impl ScalarUDFImpl for FormatStringFunc {
&self.signature
}
- fn return_type(&self, arg_types: &[DataType]) -> Result<DataType> {
- match arg_types[0] {
- DataType::Null => Ok(DataType::Utf8),
- DataType::Utf8 | DataType::LargeUtf8 | DataType::Utf8View => {
- Ok(arg_types[0].clone())
- }
- _ => plan_err!(
- "The format_string function expects the first argument to be
Utf8, LargeUtf8 or Utf8View"
- ),
+ fn return_type(&self, _arg_types: &[DataType]) -> Result<DataType> {
+ datafusion_common::internal_err!(
+ "return_type should not be called, use return_field_from_args
instead"
+ )
+ }
+
+ fn return_field_from_args(&self, args: ReturnFieldArgs) ->
Result<FieldRef> {
+ match args.arg_fields[0].data_type() {
+ DataType::Null => Ok(Arc::new(Field::new("format_string",
DataType::Utf8, true))),
+ DataType::Utf8 | DataType::LargeUtf8 | DataType::Utf8View =>
Ok(Arc::clone(&args.arg_fields[0])),
+ _ => exec_err!("format_string expects the first argument to be
Utf8, LargeUtf8 or Utf8View, got {} instead", args.arg_fields[0].data_type())
}
Review Comment:
Hi, thanks for the review!
I'm not certain whether `DataType::Null` can have `nullable = false` in
practice. If it's always nullable, then yes, we can simplify by using
`Arc::clone(&args.arg_fields[0])` for the Null case as well.
If you could confirm on this, I'll push the updated changes. I guess it
makes sense to update it this way!
EDIT:
I have updated the code, I believe this should be in accordance with the
above suggestion.
--
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]