-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Simplify AsyncScalarUdfImpl so it extends ScalarUdfImpl #16523
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,7 +17,7 @@ | |
|
||
use crate::{ReturnFieldArgs, ScalarFunctionArgs, ScalarUDF, ScalarUDFImpl}; | ||
use arrow::array::ArrayRef; | ||
use arrow::datatypes::{DataType, Field, FieldRef, SchemaRef}; | ||
use arrow::datatypes::{DataType, FieldRef}; | ||
use async_trait::async_trait; | ||
use datafusion_common::config::ConfigOptions; | ||
use datafusion_common::error::Result; | ||
|
@@ -35,34 +35,7 @@ use std::sync::Arc; | |
/// | ||
/// The name is chosen to mirror ScalarUDFImpl | ||
#[async_trait] | ||
pub trait AsyncScalarUDFImpl: Debug + Send + Sync { | ||
/// the function cast as any | ||
fn as_any(&self) -> &dyn Any; | ||
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. The point of this PR is to remove this duplication from |
||
|
||
/// The name of the function | ||
fn name(&self) -> &str; | ||
|
||
/// The signature of the function | ||
fn signature(&self) -> &Signature; | ||
|
||
/// The return type of the function | ||
fn return_type(&self, _arg_types: &[DataType]) -> Result<DataType>; | ||
|
||
/// What type will be returned by this function, given the arguments? | ||
/// | ||
/// By default, this function calls [`Self::return_type`] with the | ||
/// types of each argument. | ||
fn return_field_from_args(&self, args: ReturnFieldArgs) -> Result<FieldRef> { | ||
let data_types = args | ||
.arg_fields | ||
.iter() | ||
.map(|f| f.data_type()) | ||
.cloned() | ||
.collect::<Vec<_>>(); | ||
let return_type = self.return_type(&data_types)?; | ||
Ok(Arc::new(Field::new(self.name(), return_type, true))) | ||
} | ||
|
||
pub trait AsyncScalarUDFImpl: ScalarUDFImpl { | ||
/// The ideal batch size for this function. | ||
/// | ||
/// This is used to determine what size of data to be evaluated at once. | ||
|
@@ -74,7 +47,7 @@ pub trait AsyncScalarUDFImpl: Debug + Send + Sync { | |
/// Invoke the function asynchronously with the async arguments | ||
async fn invoke_async_with_args( | ||
&self, | ||
args: AsyncScalarFunctionArgs, | ||
args: ScalarFunctionArgs, | ||
option: &ConfigOptions, | ||
) -> Result<ArrayRef>; | ||
} | ||
|
@@ -107,7 +80,7 @@ impl AsyncScalarUDF { | |
/// Invoke the function asynchronously with the async arguments | ||
pub async fn invoke_async_with_args( | ||
&self, | ||
args: AsyncScalarFunctionArgs, | ||
args: ScalarFunctionArgs, | ||
option: &ConfigOptions, | ||
) -> Result<ArrayRef> { | ||
self.inner.invoke_async_with_args(args, option).await | ||
|
@@ -145,10 +118,3 @@ impl Display for AsyncScalarUDF { | |
write!(f, "AsyncScalarUDF: {}", self.inner.name()) | ||
} | ||
} | ||
|
||
#[derive(Debug)] | ||
pub struct AsyncScalarFunctionArgs { | ||
pub args: Vec<ColumnarValue>, | ||
pub number_rows: usize, | ||
pub schema: SchemaRef, | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is interesting here that
invoke_async_with_args has a copy of the
config_options` 🤔 -- I think that is soemthing that @Omega359 has tried to get into normal scalar functions for a whileThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It makes sense to me. We allow the custom config. Allowing access to the config option can make UDF flexible.