Skip to content
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

Closed
wants to merge 1 commit into from

Conversation

vitaliili-db
Copy link
Contributor

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

@AmplabJenkins
Copy link

Can one of the admins verify this patch?

@vitaliili-db
Copy link
Contributor Author

@dtenedor

Copy link
Contributor

@dtenedor dtenedor left a 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.
Copy link
Contributor

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?

Copy link
Contributor Author

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")
Copy link
Member

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.

Copy link
Contributor Author

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.

@vitaliili-db
Copy link
Contributor Author

@MaxGekk please review and help me merge this.

@MaxGekk MaxGekk changed the title [SPARK-39213] Create ANY_VALUE aggregate function [SPARK-39213][SQL] Create ANY_VALUE aggregate function May 19, 2022
@MaxGekk
Copy link
Member

MaxGekk commented May 19, 2022

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).

@vitaliili-db
Copy link
Contributor Author

vitaliili-db commented May 19, 2022

@MaxGekk Yes, the purpose is ease of migration, removed change to functions.scala to limit scope to Spark SQL only.

""",
group = "agg_funcs",
since = "3.4.0")
case class AnyValue(child: Expression, ignoreNulls: Boolean)
Copy link
Member

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():

Copy link
Contributor Author

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.

Copy link
Member

@MaxGekk MaxGekk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Waiting for CI.

@MaxGekk
Copy link
Member

MaxGekk commented May 20, 2022

+1, LGTM. Merging to master.
Thank you, @vli-databricks, and @dtenedor for review.

@MaxGekk MaxGekk closed this in efc1e8a May 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants