-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Make FirstValue an UDAF, Change AggregateUDFImpl::accumulator
signature, support ORDER BY for UDAFs
#9874
Merged
Merged
Make FirstValue an UDAF, Change AggregateUDFImpl::accumulator
signature, support ORDER BY for UDAFs
#9874
Changes from all commits
Commits
Show all changes
49 commits
Select commit
Hold shift + click to select a range
b94f70f
first draft
jayzhan211 c743d13
clippy fix
jayzhan211 3a7e965
cleanup
jayzhan211 4917f56
use one vector for ordering req
jayzhan211 c9e8641
add sort exprs to accumulator
jayzhan211 3a5f0d1
clippy
jayzhan211 a3ea00a
cleanup
jayzhan211 f349f21
fix doc test
jayzhan211 6fcdaac
change to ref
jayzhan211 c3512a6
fix typo
jayzhan211 092d46e
fix doc
jayzhan211 8592e6b
fmt
jayzhan211 0f8fc24
move schema and logical ordering exprs
jayzhan211 3185f9f
remove redudant info
jayzhan211 3ecc772
rename
jayzhan211 faadc63
cleanup
jayzhan211 7e33910
add ignore nulls
jayzhan211 cfffcbf
Merge remote-tracking branch 'upstream/main' into udf-order-2
jayzhan211 6aaa15c
fix conflict
jayzhan211 b74b7d2
backup
jayzhan211 263e6cb
complete return_type
jayzhan211 0a77e4f
complete replace
jayzhan211 7b26377
split to first value udf
jayzhan211 4bfd91d
replace accumulator
jayzhan211 7f54141
fmt
jayzhan211 6339535
cleanup
jayzhan211 33ae6ee
small fix
jayzhan211 b4eb865
remove ordering types
jayzhan211 d8ab6c5
make state fields more flexible
jayzhan211 a3bff42
cleanup
jayzhan211 53465fd
replace done
jayzhan211 cc21496
cleanup
jayzhan211 b62544f
cleanup
jayzhan211 ddfabad
Merge remote-tracking branch 'upstream/main' into first-value-udf
jayzhan211 4b809b0
rm comments
jayzhan211 2534727
cleanup
jayzhan211 17378dd
rm test1
jayzhan211 dd1c4ba
fix state fields
jayzhan211 5d5d310
fmt
jayzhan211 23f20f9
args struct for accumulator
jayzhan211 b2ba8c3
simplify
jayzhan211 75aa2fe
add sig
jayzhan211 5b9625f
add comments
jayzhan211 d5c3f6f
fmt
jayzhan211 dc9549a
fix docs
jayzhan211 7ce3d41
Merge remote-tracking branch 'upstream/main' into first-value-udf
jayzhan211 49b4a76
use exprs utils
jayzhan211 d70cce5
rm state type
jayzhan211 29c4018
add comment
jayzhan211 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -69,11 +69,14 @@ use datafusion_common::{ | |
OwnedTableReference, SchemaReference, | ||
}; | ||
use datafusion_execution::registry::SerializerRegistry; | ||
use datafusion_expr::type_coercion::aggregates::NUMERICS; | ||
use datafusion_expr::{create_first_value, Signature, Volatility}; | ||
use datafusion_expr::{ | ||
logical_plan::{DdlStatement, Statement}, | ||
var_provider::is_system_variables, | ||
Expr, StringifiedPlan, UserDefinedLogicalNode, WindowUDF, | ||
}; | ||
use datafusion_physical_expr::create_first_value_accumulator; | ||
use datafusion_sql::{ | ||
parser::{CopyToSource, CopyToStatement, DFParser}, | ||
planner::{object_name_to_table_reference, ContextProvider, ParserOptions, SqlToRel}, | ||
|
@@ -82,6 +85,7 @@ use datafusion_sql::{ | |
|
||
use async_trait::async_trait; | ||
use chrono::{DateTime, Utc}; | ||
use log::debug; | ||
use parking_lot::RwLock; | ||
use sqlparser::dialect::dialect_from_str; | ||
use url::Url; | ||
|
@@ -1457,6 +1461,22 @@ impl SessionState { | |
datafusion_functions_array::register_all(&mut new_self) | ||
.expect("can not register array expressions"); | ||
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. We also panic if register fails here |
||
|
||
let first_value = create_first_value( | ||
"FIRST_VALUE", | ||
Signature::uniform(1, NUMERICS.to_vec(), Volatility::Immutable), | ||
Arc::new(create_first_value_accumulator), | ||
); | ||
|
||
match new_self.register_udaf(Arc::new(first_value)) { | ||
Ok(Some(existing_udaf)) => { | ||
debug!("Overwrite existing UDAF: {}", existing_udaf.name()); | ||
} | ||
Ok(None) => {} | ||
Err(err) => { | ||
panic!("Failed to register UDAF: {}", err); | ||
} | ||
} | ||
|
||
new_self | ||
} | ||
/// Returns new [`SessionState`] using the provided | ||
|
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
Oops, something went wrong.
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.
I was thinking about the impact on this API for UDAF writers last night.
Specifically, about the many existing UDAFs that exist / will exist at the time this change gets released and on the first time people encounter / try to use this API. i think the args with datatypes is much easier to use (and has less mental gymnastics to use). Thus I am going to propose an easier / beginner API for this that will require fewer changes to existing UDAFs and will be easier to use for first timers
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.
This is what i came up with: #9920