This is an automated email from the ASF dual-hosted git repository.
alamb pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/datafusion.git
The following commit(s) were added to refs/heads/main by this push:
new 4597d3bcff Minor: Add `ScalarFunctionArgs::return_type` method (#16113)
4597d3bcff is described below
commit 4597d3bcffe4433ee260151b16b57090bfaed8fc
Author: Andrew Lamb <[email protected]>
AuthorDate: Wed May 21 11:40:02 2025 -0400
Minor: Add `ScalarFunctionArgs::return_type` method (#16113)
---
datafusion/expr/src/udf.rs | 8 ++++++++
datafusion/functions/src/core/named_struct.rs | 2 +-
datafusion/functions/src/core/struct.rs | 2 +-
3 files changed, 10 insertions(+), 2 deletions(-)
diff --git a/datafusion/expr/src/udf.rs b/datafusion/expr/src/udf.rs
index 78bb56bc1c..3983d17516 100644
--- a/datafusion/expr/src/udf.rs
+++ b/datafusion/expr/src/udf.rs
@@ -306,6 +306,14 @@ pub struct ScalarFunctionArgs<'a, 'b> {
pub return_field: &'b Field,
}
+impl<'a, 'b> ScalarFunctionArgs<'a, 'b> {
+ /// The return type of the function. See [`Self::return_field`] for more
+ /// details.
+ pub fn return_type(&self) -> &DataType {
+ self.return_field.data_type()
+ }
+}
+
/// Information about arguments passed to the function
///
/// This structure contains metadata about how the function was called
diff --git a/datafusion/functions/src/core/named_struct.rs
b/datafusion/functions/src/core/named_struct.rs
index 5fb118a8a2..9346b62b90 100644
--- a/datafusion/functions/src/core/named_struct.rs
+++ b/datafusion/functions/src/core/named_struct.rs
@@ -150,7 +150,7 @@ impl ScalarUDFImpl for NamedStructFunc {
}
fn invoke_with_args(&self, args: ScalarFunctionArgs) ->
Result<ColumnarValue> {
- let DataType::Struct(fields) = args.return_field.data_type() else {
+ let DataType::Struct(fields) = args.return_type() else {
return internal_err!("incorrect named_struct return type");
};
diff --git a/datafusion/functions/src/core/struct.rs
b/datafusion/functions/src/core/struct.rs
index 416ad288fc..f068fc18a8 100644
--- a/datafusion/functions/src/core/struct.rs
+++ b/datafusion/functions/src/core/struct.rs
@@ -117,7 +117,7 @@ impl ScalarUDFImpl for StructFunc {
}
fn invoke_with_args(&self, args: ScalarFunctionArgs) ->
Result<ColumnarValue> {
- let DataType::Struct(fields) = args.return_field.data_type() else {
+ let DataType::Struct(fields) = args.return_type() else {
return internal_err!("incorrect struct return type");
};
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]