Uh oh!
There was an error while loading. Please reload this page.
[SPARK-30276][SQL] Support Filter expression allows simultaneous use of DISTINCT - #29291
[SPARK-30276][SQL] Support Filter expression allows simultaneous use of DISTINCT#29291beliefer wants to merge 25 commits into
Conversation
SparkQA
commented
Jul 29, 2020
Test build #126778 has finished for PR 29291 at commit
|
SparkQA
commented
Jul 30, 2020
Test build #126797 has finished for PR 29291 at commit
|
beliefer
commented
Jul 30, 2020
cc @cloud-fan |
| // group without filter clause. | ||
| // This check can produce false-positives, e.g., SUM(DISTINCT a) & COUNT(DISTINCT a). | ||
| distinctAggs.size > 1 | ||
| distinctAggs.size > 1 || (distinctAggs.size == 1 && aggExpressions.exists(_.filter.isDefined)) |
There was a problem hiding this comment.
We can remove distinctAggs.size == 1, as it's indicarted by distinctAggs.size > 1 || ...
There was a problem hiding this comment.
If distinctAggs.size == 0 and aggExpressions.exists(_.filter.isDefined), we not need this rewrite.
The normal agg with filter could treated by physical plan.
There was a problem hiding this comment.
shouldn't it be distinctAggs.exists(_.filter.isDefined)?
There was a problem hiding this comment.
| // Setup all the filters in distinct aggregate. | ||
| val distinctAggExprs = aggExpressions | ||
| .filter(e => e.isDistinct && e.children.exists(!_.foldable)) | ||
| val distinctAggFilterAttrMap = distinctAggExprs.collect { |
There was a problem hiding this comment.
nit: val (distinctAggFilters, distinctAggFilterAttrs, maxCond) = distinctAggExprs.collect(...).unzip3
There was a problem hiding this comment.
But I want
val distinctAggFilterAttrLookup = distinctAggFilterAttrMap.map { tuple3 =>
tuple3._1 -> tuple3._3.toAttribute
}.toMap
There was a problem hiding this comment.
this is distinctAggFilters.zip(maxCond.map(_.toAttribute)).toMap
Uh oh!
There was an error while loading. Please reload this page.
SparkQA
commented
Jul 30, 2020
Test build #126810 has finished for PR 29291 at commit
|
beliefer
commented
Jul 31, 2020
retest this please |
cloud-fan
commented
Jul 31, 2020
can you rebase/merge with the master branch to get the github action fix? The jenkin is quite unstable now and we may need to rely on github actions |
beliefer
commented
Jul 31, 2020
OK |
Uh oh!
There was an error while loading. Please reload this page.
SparkQA
commented
Jul 31, 2020
Test build #126843 has finished for PR 29291 at commit
|
Uh oh!
There was an error while loading. Please reload this page.
| val (distinctAggFilters, distinctAggFilterAttrs, maxConds) = distinctAggExprs.collect { | ||
| case AggregateExpression(_, _, _, filter, _) if filter.isDefined => | ||
| val (e, attr) = expressionAttributePair(filter.get) | ||
| val aggregateExp = AggregateExpression(Max(attr), Partial, false) |
There was a problem hiding this comment.
nit: Max(attr).toAggregateExpression(distinct = false)
| SELECT COUNT(DISTINCT id), COUNT(DISTINCT id) FILTER (WHERE date_format(hiredate, "yyyy-MM-dd HH:mm:ss") = "2001-01-01 00:00:00") FROM emp; | ||
| SELECT COUNT(DISTINCT id) FILTER (WHERE hiredate = to_timestamp("2001-01-01 00:00:00")), COUNT(DISTINCT id) FILTER (WHERE hiredate = to_date('2001-01-01 00:00:00')) FROM emp; | ||
| SELECT SUM(salary), COUNT(DISTINCT id), COUNT(DISTINCT id) FILTER (WHERE hiredate = date "2001-01-01") FROM emp; | ||
| SELECT COUNT(DISTINCT 1) FILTER (WHERE a = 1) FROM testData; |
There was a problem hiding this comment.
can we also test COUNT(DISTINCT id) FILTER (WHERE true) and COUNT(DISTINCT id) FILTER (WHERE false)?
SparkQA
commented
Jul 31, 2020
Test build #126857 has finished for PR 29291 at commit
|
SparkQA
commented
Jul 31, 2020
Test build #126866 has finished for PR 29291 at commit
|
SparkQA
commented
Jul 31, 2020
Test build #126886 has finished for PR 29291 at commit
|
SparkQA
commented
Aug 3, 2020
Test build #126953 has finished for PR 29291 at commit
|
SparkQA
commented
Aug 3, 2020
Test build #126956 has finished for PR 29291 at commit
|
cloud-fan
commented
Aug 3, 2020
retest this please |
SparkQA
commented
Aug 3, 2020
Test build #126968 has finished for PR 29291 at commit
|
cloud-fan
commented
Aug 3, 2020
retest this please |
SparkQA
commented
Aug 3, 2020
Test build #126980 has finished for PR 29291 at commit
|
cloud-fan
commented
Aug 3, 2020
retest this please |
SparkQA
commented
Aug 3, 2020
Test build #126994 has finished for PR 29291 at commit
|
cloud-fan
commented
Aug 4, 2020
thanks, merging to master! |
beliefer
commented
Aug 4, 2020
@cloud-fan Thanks for your review and good idea. |
What changes were proposed in this pull request?
This PR is related to #26656.
#26656 only support use FILTER clause on aggregate expression without DISTINCT.
This PR will enhance this feature when one or more DISTINCT aggregate expressions which allows the use of the FILTER clause.
Such as:
Why are the changes needed?
Spark SQL only support use FILTER clause on aggregate expression without DISTINCT.
This PR support Filter expression allows simultaneous use of DISTINCT
Does this PR introduce any user-facing change?
Yes
How was this patch tested?
Exists and new UT