-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Docs: Add example of creating a field in return_field_from_args
#16039
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
a77bec2
02d6ea7
83c40fb
44de835
47141c6
2f19428
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -317,9 +317,9 @@ pub struct ScalarFunctionArgs<'a, 'b> { | |
| pub struct ReturnFieldArgs<'a> { | ||
| /// The data types of the arguments to the function | ||
| pub arg_fields: &'a [Field], | ||
| /// Is argument `i` to the function a scalar (constant) | ||
| /// Is argument `i` to the function a scalar (constant)? | ||
| /// | ||
| /// If argument `i` is not a scalar, it will be None | ||
| /// If the argument `i` is not a scalar, it will be None | ||
| /// | ||
| /// For example, if a function is called like `my_function(column_a, 5)` | ||
| /// this field will be `[None, Some(ScalarValue::Int32(Some(5)))]` | ||
|
|
@@ -451,7 +451,7 @@ pub trait ScalarUDFImpl: Debug + Send + Sync { | |
| /// | ||
| /// # Notes | ||
| /// | ||
| /// Most UDFs should implement [`Self::return_type`] and not this | ||
| /// Most UDFs can implement [`Self::return_type`] and not this | ||
| /// function as the output type for most functions only depends on the types | ||
| /// of their inputs (e.g. `sqrt(f32)` is always `f32`). | ||
| /// | ||
|
|
@@ -461,6 +461,26 @@ pub trait ScalarUDFImpl: Debug + Send + Sync { | |
| /// 2. return types based on the **values** of the arguments (rather than | ||
| /// their **types**. | ||
| /// | ||
| /// # Example creating `Field` | ||
| /// | ||
| /// Note the [`Field`] is ignored, except for structured types such as | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do you mean to say the name of the field is ignored?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, excellent call, I will make a PR to fix
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| /// `DataType::Struct`. | ||
| /// | ||
| /// ```rust | ||
| /// # use arrow::datatypes::{DataType, Field}; | ||
| /// # use datafusion_common::Result; | ||
| /// # use datafusion_expr::ReturnFieldArgs; | ||
| /// # struct Example{}; | ||
| /// # impl Example { | ||
| /// fn return_field_from_args(&self, args: ReturnFieldArgs) -> Result<Field> { | ||
| /// // report output is only nullable if any one of the arguments are nullable | ||
| /// let nullable = args.arg_fields.iter().any(|f| f.is_nullable()); | ||
| /// let field = Field::new("ignored_name", DataType::Int32, true); | ||
| /// Ok(field) | ||
| /// } | ||
| /// # } | ||
| /// ``` | ||
| /// | ||
| /// # Output Type based on Values | ||
| /// | ||
| /// For example, the following two function calls get the same argument | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.