-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
RFC: Make fields of ScalarUDF non pub #8039
Closed
Closed
Changes from all commits
Commits
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 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 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 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 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 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 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 |
---|---|---|
|
@@ -15,23 +15,31 @@ | |
// specific language governing permissions and limitations | ||
// under the License. | ||
|
||
//! Udf module contains foundational types that are used to represent UDFs in DataFusion. | ||
//! [`ScalarUDF`]: Scalar User Defined Functions | ||
|
||
use crate::{Expr, ReturnTypeFunction, ScalarFunctionImplementation, Signature}; | ||
use arrow::datatypes::DataType; | ||
use datafusion_common::Result; | ||
use std::fmt; | ||
use std::fmt::Debug; | ||
use std::fmt::Formatter; | ||
use std::sync::Arc; | ||
|
||
/// Logical representation of a UDF. | ||
/// Logical representation of a Scalar User Defined Function. | ||
/// | ||
/// A scalar function produces a single row output for each row of input. | ||
/// | ||
/// This struct contains the information DataFusion needs to plan and invoke | ||
/// functions such name, type signature, return type, and actual implementation. | ||
/// | ||
#[derive(Clone)] | ||
pub struct ScalarUDF { | ||
/// name | ||
pub name: String, | ||
/// signature | ||
pub signature: Signature, | ||
/// Return type | ||
pub return_type: ReturnTypeFunction, | ||
/// The name of the function | ||
name: String, | ||
/// The signature (the types of arguments that are supported) | ||
signature: Signature, | ||
/// Function that returns the return type given the argument types | ||
return_type: ReturnTypeFunction, | ||
/// actual implementation | ||
/// | ||
/// The fn param is the wrapped function but be aware that the function will | ||
|
@@ -40,7 +48,7 @@ pub struct ScalarUDF { | |
/// will be passed. In that case the single element is a null array to indicate | ||
/// the batch's row count (so that the generative zero-argument function can know | ||
/// the result array size). | ||
pub fun: ScalarFunctionImplementation, | ||
fun: ScalarFunctionImplementation, | ||
} | ||
|
||
impl Debug for ScalarUDF { | ||
|
@@ -89,4 +97,23 @@ impl ScalarUDF { | |
pub fn call(&self, args: Vec<Expr>) -> Expr { | ||
Expr::ScalarUDF(crate::expr::ScalarUDF::new(Arc::new(self.clone()), args)) | ||
} | ||
|
||
/// Returns this function's name | ||
pub fn name(&self) -> &str { | ||
&self.name | ||
} | ||
/// Returns this function's signature | ||
pub fn signature(&self) -> &Signature { | ||
&self.signature | ||
} | ||
/// return the return type of this function given the types of the arguments | ||
pub fn return_type(&self, args: &[DataType]) -> Result<DataType> { | ||
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. Rather than expose the underlying function pointer directly, I opted to handle the nuance of calling it here. |
||
// Old API returns an Arc of the datatype for some reason | ||
let res = (self.return_type)(args)?; | ||
Ok(res.as_ref().clone()) | ||
} | ||
/// return the implementation of this function | ||
pub fn fun(&self) -> &ScalarFunctionImplementation { | ||
&self.fun | ||
} | ||
} |
This file contains 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 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 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 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 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 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 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 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
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.
the key change in this PR is to remove
pub