-
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
Convert stddev
and stddev_pop
to UDAF
#10834
Conversation
/// An accumulator to compute the average | ||
#[derive(Debug)] |
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.
StddevAccumulator
is used by correlation
. That's why I keep it.
We should remove it after converting correlation to UDAF.
@@ -939,32 +847,6 @@ mod tests { | |||
assert!(observed.is_err()); | |||
} | |||
|
|||
#[test] | |||
fn test_stddev_return_type() -> Result<()> { |
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.
I think those tests are covered by sqllogictests testing. I didn't add similar tests for UDAF.
@@ -747,82 +731,6 @@ mod tests { | |||
Ok(()) | |||
} | |||
|
|||
#[test] | |||
fn test_stddev_expr() -> Result<()> { |
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.
Same as above. It's already covered by sqllogictests.
} | ||
|
||
#[test] | ||
fn test_stddev_pop_expr() -> Result<()> { |
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.
Same as above. It's already covered by sqllogictests.
|
||
fn accumulator(&self, acc_args: AccumulatorArgs) -> Result<Box<dyn Accumulator>> { | ||
if acc_args.is_distinct { | ||
return internal_err!("STDDEV_POP(DISTINCT) aggregations are not available"); |
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.
should it be not_impl_err
?
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.
Thanks @comphead. Indeed. It's better.
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.
👍
Ok(Box::new(StddevAccumulator::try_new(StatsType::Sample)?)) | ||
} | ||
|
||
fn create_sliding_accumulator( |
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.
I think we could rely on the default impl, since they are equivalent
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.
datafusion/datafusion/expr/src/udaf.rs
Lines 414 to 419 in 6b70214
fn create_sliding_accumulator( | |
&self, | |
args: AccumulatorArgs, | |
) -> Result<Box<dyn Accumulator>> { | |
self.accumulator(args) | |
} |
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.
Thanks @jayzhan211, It's better.
&self, | ||
args: AccumulatorArgs, | ||
) -> Result<Box<dyn Accumulator>> { | ||
self.accumulator(args) |
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.
same here
Thanks @goldmedal and @comphead |
Thanks again @jayzhan211 @comphead |
* add stddev and stddev_pot udaf * remove aggregation function stddev and stddev_pop * register func and modified return type * cargo fmt * regen proto * cargo clippy * fix window function support * cargo fmt * throw not_impl_err instead * use default sliding accumulator
Which issue does this PR close?
Closes #10827 .
I converted
stddev_pop
to UDAF, too.Rationale for this change
What changes are included in this PR?
Are these changes tested?
Yes
Are there any user-facing changes?
no