Have COUNT DISTINCT return 0 instead of NULL for no documents matching. (#50037)

(cherry picked from commit cb94731e6f41bc51c23e4aab495b64eea731a061)
This commit is contained in:
Andrei Stefan 2019-12-11 23:53:03 +02:00 committed by Andrei Stefan
parent 4619834b97
commit e9e2e5fc71
2 changed files with 23 additions and 4 deletions

View File

@ -657,6 +657,29 @@ SELECT COUNT(first_name)=COUNT(DISTINCT first_name) AS areEqual, COUNT(first_nam
true |90 |90
;
aggCountWithNull
schema::COUNT(NULL):l|COUNT(*):l|COUNT(DISTINCT languages):l|languages:bt
SELECT COUNT(NULL), COUNT(*), COUNT(DISTINCT languages), languages FROM test_emp GROUP BY languages ORDER BY languages DESC;
COUNT(NULL) | COUNT(*) |COUNT(DISTINCT languages)| languages
---------------+---------------+-------------------------+---------------
null |21 |1 |5
null |18 |1 |4
null |17 |1 |3
null |19 |1 |2
null |15 |1 |1
null |10 |0 |null
;
aggCountZeroDocuments
schema::COUNT(NULL):l|COUNT(*):l|COUNT(DISTINCT languages):l
SELECT COUNT(NULL), COUNT(*), COUNT(DISTINCT languages) FROM test_emp WHERE languages > 100;
COUNT(NULL) | COUNT(*) |COUNT(DISTINCT languages)
---------------+---------------+-------------------------
null |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;

View File

@ -12,7 +12,6 @@ import org.elasticsearch.search.aggregations.bucket.MultiBucketsAggregation.Buck
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;
@ -149,9 +148,6 @@ public class MetricAggExtractor implements BucketExtractor {
if (agg instanceof InternalAvg) {
return hasValue((InternalAvg) agg);
}
if (agg instanceof InternalCardinality) {
return hasValue((InternalCardinality) agg);
}
if (agg instanceof InternalSum) {
return hasValue((InternalSum) agg);
}