Skip to content

Commit

Permalink
Have COUNT DISTINCT return 0 instead of NULL for no documents matchin…
Browse files Browse the repository at this point in the history
…g. (#50037)

(cherry picked from commit cb94731)
  • Loading branch information
astefan committed Dec 12, 2019
1 parent 9f45cc6 commit fd06783
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
23 changes: 23 additions & 0 deletions x-pack/plugin/sql/qa/src/main/resources/agg.csv-spec
Original file line number Diff line number Diff line change
Expand Up @@ -635,6 +635,29 @@ SELECT COUNT(first_name)=COUNT(DISTINCT first_name) AS areEqual, COUNT(first_nam
true |90 |90
;

aggCountWithNull
schema::COUNT(*):l|COUNT(DISTINCT languages):l|languages:bt
SELECT COUNT(*), COUNT(DISTINCT languages), languages FROM test_emp GROUP BY languages ORDER BY languages DESC;

COUNT(*) |COUNT(DISTINCT languages)| languages
---------------+-------------------------+---------------
21 |1 |5
18 |1 |4
17 |1 |3
19 |1 |2
15 |1 |1
10 |0 |null
;

aggCountZeroDocuments
schema::COUNT(*):l|COUNT(DISTINCT languages):l
SELECT COUNT(*), COUNT(DISTINCT languages) FROM test_emp WHERE languages > 100;

COUNT(*) |COUNT(DISTINCT languages)
---------------+-------------------------
0 |0
;

aggCountAllEquality
schema::areEqual:b|afn:l
SELECT COUNT(first_name)=COUNT(ALL first_name) AS areEqual, COUNT(ALL first_name) afn FROM test_emp;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import org.elasticsearch.search.aggregations.bucket.filter.InternalFilter;
import org.elasticsearch.search.aggregations.matrix.stats.InternalMatrixStats;
import org.elasticsearch.search.aggregations.metrics.InternalAvg;
import org.elasticsearch.search.aggregations.metrics.InternalCardinality;
import org.elasticsearch.search.aggregations.metrics.InternalMax;
import org.elasticsearch.search.aggregations.metrics.InternalMin;
import org.elasticsearch.search.aggregations.metrics.InternalNumericMetricsAggregation;
Expand Down Expand Up @@ -149,9 +148,6 @@ private static boolean containsValues(InternalAggregation agg) {
if (agg instanceof InternalAvg) {
return hasValue((InternalAvg) agg);
}
if (agg instanceof InternalCardinality) {
return hasValue((InternalCardinality) agg);
}
if (agg instanceof InternalSum) {
return hasValue((InternalSum) agg);
}
Expand Down

0 comments on commit fd06783

Please sign in to comment.