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-23911][SQL] Add aggregate function. #21982

Closed
wants to merge 2 commits into from

Conversation

ueshin
Copy link
Member

@ueshin ueshin commented Aug 3, 2018

What changes were proposed in this pull request?

This pr adds aggregate function which applies a binary operator to an initial state and all elements in the array, and reduces this to a single state. The final state is converted into the final result by applying a finish function.

> SELECT aggregate(array(1, 2, 3), (acc, x) -> acc + x);
 6
> SELECT aggregate(array(1, 2, 3), (acc, x) -> acc + x, acc -> acc * 10);
 60

How was this patch tested?

Added tests.

@ueshin
Copy link
Member Author

ueshin commented Aug 3, 2018

@mn-mikke
Copy link
Contributor

mn-mikke commented Aug 3, 2018

Isn't this PR related to the Jira ticket SPARK-23911?

@ueshin ueshin changed the title [SPARK-23909][SQL] Add aggregate function. [SPARK-23911][SQL] Add aggregate function. Aug 3, 2018
@ueshin
Copy link
Member Author

ueshin commented Aug 3, 2018

Oops, yes, I wrote a wrong jira-id. Fixed. Thanks!

@SparkQA
Copy link

SparkQA commented Aug 3, 2018

Test build #94118 has finished for PR 21982 at commit 26bf379.

  • This patch fails Spark unit tests.
  • This patch merges cleanly.
  • This patch adds the following public classes (experimental):
  • case class ArrayAggregate(

@ueshin
Copy link
Member Author

ueshin commented Aug 3, 2018

Jenkins, retest this please.

@SparkQA
Copy link

SparkQA commented Aug 3, 2018

Test build #94130 has finished for PR 21982 at commit 26bf379.

  • This patch fails Spark unit tests.
  • This patch merges cleanly.
  • This patch adds the following public classes (experimental):
  • case class ArrayAggregate(

Copy link
Contributor

@hvanhovell hvanhovell left a comment

Choose a reason for hiding this comment

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

LGTM

@hvanhovell
Copy link
Contributor

retest this please

@SparkQA
Copy link

SparkQA commented Aug 3, 2018

Test build #94169 has finished for PR 21982 at commit 26bf379.

  • This patch fails Spark unit tests.
  • This patch merges cleanly.
  • This patch adds the following public classes (experimental):
  • case class ArrayAggregate(

@gatorsmile
Copy link
Member

retest this please

@gatorsmile
Copy link
Member

@ueshin You need to address the conflicts again. :)

@SparkQA
Copy link

SparkQA commented Aug 4, 2018

Test build #94205 has finished for PR 21982 at commit 26bf379.

  • This patch fails Spark unit tests.
  • This patch does not merge cleanly.
  • This patch adds the following public classes (experimental):
  • case class ArrayAggregate(

@SparkQA
Copy link

SparkQA commented Aug 4, 2018

Test build #94207 has finished for PR 21982 at commit 4290f55.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds the following public classes (experimental):
  • case class ArrayFilter(

@ueshin
Copy link
Member Author

ueshin commented Aug 4, 2018

Thanks! merging to master.

""",
examples = """
Examples:
> SELECT _FUNC_(array(1, 2, 3), (acc, x) -> acc + x);
Copy link
Member

Choose a reason for hiding this comment

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

@ueshin, would you mind if I ask to kindly double check if the example works? seems not in my local:

spark-sql> SELECT aggregate(array(1, 2, 3), (acc, x) -> acc + x);
2018-08-08 16:08:25 ERROR SparkSQLDriver:91 - Failed in [SELECT aggregate(array(1, 2, 3), (acc, x) -> acc + x)]
org.apache.spark.sql.catalyst.analysis.UnresolvedException: Invalid call to dataType on unresolved object, tree: 'acc
	at org.apache.spark.sql.catalyst.analysis.UnresolvedAttribute.dataType(unresolved.scala:105)
	at org.apache.spark.sql.catalyst.expressions.BinaryArithmetic.dataType(arithmetic.scala:119)
	at org.apache.spark.sql.catalyst.expressions.LambdaFunction.dataType(higherOrderFunctions.scala:72)
	at org.apache.spark.sql.hive.HiveSessionCatalog$$anonfun$1.apply(HiveSessionCatalog.scala:122)
	at org.apache.spark.sql.hive.HiveSessionCatalog$$anonfun$1.apply(HiveSessionCatalog.scala:121)
	at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:234)
	at scala.collection.TraversableLike$$anonfun$map$1.apply(TraversableLike.scala:234)
	at scala.collection.mutable.ResizableArray$class.foreach(ResizableArray.scala:59)
	at scala.collection.mutable.ArrayBuffer.foreach(ArrayBuffer.scala:48)
	at scala.collection.TraversableLike$class.map(TraversableLike.scala:234)
	at scala.collection.AbstractTraversable.map(Traversable.scala:104)

Copy link
Member Author

Choose a reason for hiding this comment

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

Oops, sorry, we need the second argument as an initial value.

SELECT aggregate(array(1, 2, 3), 0, (acc, x) -> acc + x);

I'll submit a follow-up pr soon.

Copy link
Member Author

Choose a reason for hiding this comment

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

Submitted #22035. Thanks!

asfgit pushed a commit that referenced this pull request Aug 8, 2018
## What changes were proposed in this pull request?

This pr is a follow-up pr of #21982 and fixes the examples.

## How was this patch tested?

Existing tests.

Closes #22035 from ueshin/issues/SPARK-23911/fup1.

Authored-by: Takuya UESHIN <[email protected]>
Signed-off-by: Takuya UESHIN <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants