-
Notifications
You must be signed in to change notification settings - Fork 28k
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
[SPARK-39213][SQL] Create ANY_VALUE aggregate function #36584
Conversation
aaaad89
to
2a166f3
Compare
Can one of the admins verify this patch? |
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.
Generally LGTM, we should just update the function comment.
import org.apache.spark.sql.types._ | ||
|
||
/** | ||
* Returns some value of `child` for a group of rows. The result will not be deterministic. |
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.
Maybe just update this comment to mention that this return the first value in the group, and the implementation is the same as the First
aggregate function?
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.
Done
The function is non-deterministic. | ||
""", | ||
group = "agg_funcs", | ||
since = "3.3.0") |
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.
Since SPARK-39213 is not in the allow list for 3.3 (see https://lists.apache.org/thread/2tl67py05t1620v3fk8ms672mnxt6nol), the changes shouldn't be targeted to 3.3. Please, change the version to 3.4.0 here and other places.
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.
Good catch, thank you! Fixed.
@MaxGekk please review and help me merge this. |
How about to add the function to other APIs like first() in
BTW, if the purpose of this new feature is to make migrations to Spark SQL from other systems easier, I would propose to add it to Spark SQL only (and not extend functions.scala). |
@MaxGekk Yes, the purpose is ease of migration, removed change to |
sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/expressions/AnyValue.scala
Outdated
Show resolved
Hide resolved
""", | ||
group = "agg_funcs", | ||
since = "3.4.0") | ||
case class AnyValue(child: Expression, ignoreNulls: Boolean) |
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.
Could you explain, please, why do you need a separate expression and why any_value()
is not implemented as an alias of First
like first_value()
:
spark/sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/analysis/FunctionRegistry.scala
Line 469 in 7221ea3
expression[First]("first_value", true), |
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 primarily for documentation purposes.
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.
Waiting for CI.
+1, LGTM. Merging to master. |
What changes were proposed in this pull request?
Adding implementation for ANY_VALUE aggregate function. During optimization stage it is rewritten to
First
aggregate function.Why are the changes needed?
This feature provides feature parity with popular DBs and DWHs
Does this PR introduce any user-facing change?
Yes - introducing new aggregate function
ANY_VALUE
. Respective documentation is updated.How was this patch tested?
Unit tests