-
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
Combine the logic of rank, dense_rank and percent_rank udwf to reduce duplications #12893
Conversation
); | ||
|
||
// define_udwf_and_expr!( |
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.
@jcsherin while defining the other udwf like this, it is not working, giving an error during compile time.
Am I going in the right direction ?
Thanks !
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 first argument needs to be a distinct identifier. I guess something like this will work,
define_udwf_and_expr!(BasicRank, rank, "...", Rank::basic);
define_udwf_and_expr!(PercentRank, rank, "...", Rank::percent_rank);
define_udwf_and_expr!(DenseRank, rank, "...", Rank::dense_rank);
let nullable = false; | ||
Ok(Field::new( | ||
field_args.name(), | ||
self.data_type.clone(), | ||
nullable, | ||
)) |
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 Rank.data_type
field can be removed.
let nullable = false; | |
Ok(Field::new( | |
field_args.name(), | |
self.data_type.clone(), | |
nullable, | |
)) | |
let return_type = match self.rank_type { | |
RankType::Basic | RankType::Dense => DataType::UInt64, | |
RankType::Percent => DataType::Float64, | |
}; | |
Ok(Field::new( | |
field_args.name(), | |
return_type.clone(), | |
false, | |
)) |
@@ -69,7 +114,7 @@ impl WindowUDFImpl for Rank { | |||
} | |||
|
|||
fn name(&self) -> &str { | |||
"rank" | |||
self.name.as_str() |
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.
Minor: &self.name
Please apply this patch to fix Download fix_macro_intra_doc_links.patch $ git apply fix_macro_intra_doc_links.patch It will resolve these errors:
This is because Patch contents diff --git a/datafusion/functions-window/src/macros.rs b/datafusion/functions-window/src/macros.rs
index e934f883b101..2905ccf4c204 100644
--- a/datafusion/functions-window/src/macros.rs
+++ b/datafusion/functions-window/src/macros.rs
@@ -303,7 +303,7 @@ macro_rules! create_udwf_expr {
($UDWF:ident, $OUT_FN_NAME:ident, $DOC:expr) => {
paste::paste! {
#[doc = " Create a [`WindowFunction`](datafusion_expr::Expr::WindowFunction) expression for"]
- #[doc = concat!(" [`", stringify!($UDWF), "`] user-defined window function.")]
+ #[doc = concat!(" `", stringify!($UDWF), "` user-defined window function.")]
#[doc = ""]
#[doc = concat!(" ", $DOC)]
pub fn $OUT_FN_NAME() -> datafusion_expr::Expr {
@@ -316,7 +316,7 @@ macro_rules! create_udwf_expr {
($UDWF:ident, $OUT_FN_NAME:ident, [$($PARAM:ident),+], $DOC:expr) => {
paste::paste! {
#[doc = " Create a [`WindowFunction`](datafusion_expr::Expr::WindowFunction) expression for"]
- #[doc = concat!(" [`", stringify!($UDWF), "`] user-defined window function.")]
+ #[doc = concat!(" `", stringify!($UDWF), "` user-defined window function.")]
#[doc = ""]
#[doc = concat!(" ", $DOC)]
pub fn $OUT_FN_NAME(
|
/// Get rank_type of the rank in window function with order by | ||
pub fn get_type(&self) -> RankType { | ||
self.rank_type |
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 ok to remove Rank::get_type()
as it is not used anywhere.
Thanks @jcsherin |
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.
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.
LGTM. Module doc's can be updated in rank.rs
.
done @berkaysynnada |
🎉 |
Which issue does this PR close?
Closes #.
Rationale for this change
The functionality of the rank, percent_rank and dense_rank is same.
Combining them into one
What changes are included in this PR?
Combining rank, dense_rank and percent_rank logic
Are these changes tested?
Are there any user-facing changes?