|
10 | 10 | import org.elasticsearch.search.aggregations.InternalAggregation; |
11 | 11 | import org.elasticsearch.search.aggregations.bucket.MultiBucketsAggregation.Bucket; |
12 | 12 | import org.elasticsearch.search.aggregations.bucket.filter.InternalFilter; |
13 | | -import org.elasticsearch.search.aggregations.matrix.stats.MatrixStats; |
| 13 | +import org.elasticsearch.search.aggregations.matrix.stats.InternalMatrixStats; |
| 14 | +import org.elasticsearch.search.aggregations.metrics.InternalAvg; |
| 15 | +import org.elasticsearch.search.aggregations.metrics.InternalCardinality; |
| 16 | +import org.elasticsearch.search.aggregations.metrics.InternalMax; |
| 17 | +import org.elasticsearch.search.aggregations.metrics.InternalMin; |
14 | 18 | import org.elasticsearch.search.aggregations.metrics.InternalNumericMetricsAggregation; |
15 | | -import org.elasticsearch.search.aggregations.metrics.InternalNumericMetricsAggregation.SingleValue; |
16 | 19 | import org.elasticsearch.search.aggregations.metrics.InternalStats; |
17 | | -import org.elasticsearch.search.aggregations.metrics.PercentileRanks; |
18 | | -import org.elasticsearch.search.aggregations.metrics.Percentiles; |
| 20 | +import org.elasticsearch.search.aggregations.metrics.InternalSum; |
| 21 | +import org.elasticsearch.search.aggregations.metrics.InternalTDigestPercentileRanks; |
| 22 | +import org.elasticsearch.search.aggregations.metrics.InternalTDigestPercentiles; |
19 | 23 | import org.elasticsearch.xpack.sql.SqlIllegalArgumentException; |
20 | 24 | import org.elasticsearch.xpack.sql.querydsl.agg.Aggs; |
21 | 25 | import org.elasticsearch.xpack.sql.util.DateUtils; |
|
25 | 29 | import java.util.Map; |
26 | 30 | import java.util.Objects; |
27 | 31 |
|
| 32 | +import static org.elasticsearch.search.aggregations.matrix.stats.MatrixAggregationInspectionHelper.hasValue; |
| 33 | +import static org.elasticsearch.search.aggregations.support.AggregationInspectionHelper.hasValue; |
| 34 | + |
28 | 35 | public class MetricAggExtractor implements BucketExtractor { |
29 | 36 |
|
30 | 37 | static final String NAME = "m"; |
@@ -123,26 +130,35 @@ private Object handleDateTime(Object object) { |
123 | 130 | /** |
124 | 131 | * Check if the given aggregate has been executed and has computed values |
125 | 132 | * or not (the bucket is null). |
126 | | - * |
127 | | - * Waiting on https://github.com/elastic/elasticsearch/issues/34903 |
128 | 133 | */ |
129 | 134 | private static boolean containsValues(InternalAggregation agg) { |
130 | 135 | // Stats & ExtendedStats |
131 | 136 | if (agg instanceof InternalStats) { |
132 | | - return ((InternalStats) agg).getCount() != 0; |
| 137 | + return hasValue((InternalStats) agg); |
| 138 | + } |
| 139 | + if (agg instanceof InternalMatrixStats) { |
| 140 | + return hasValue((InternalMatrixStats) agg); |
| 141 | + } |
| 142 | + if (agg instanceof InternalMax) { |
| 143 | + return hasValue((InternalMax) agg); |
| 144 | + } |
| 145 | + if (agg instanceof InternalMin) { |
| 146 | + return hasValue((InternalMin) agg); |
| 147 | + } |
| 148 | + if (agg instanceof InternalAvg) { |
| 149 | + return hasValue((InternalAvg) agg); |
133 | 150 | } |
134 | | - if (agg instanceof MatrixStats) { |
135 | | - return ((MatrixStats) agg).getDocCount() != 0; |
| 151 | + if (agg instanceof InternalCardinality) { |
| 152 | + return hasValue((InternalCardinality) agg); |
136 | 153 | } |
137 | | - // sum returns 0 even for null; since that's a common case, we return it as such |
138 | | - if (agg instanceof SingleValue) { |
139 | | - return Double.isFinite(((SingleValue) agg).value()); |
| 154 | + if (agg instanceof InternalSum) { |
| 155 | + return hasValue((InternalSum) agg); |
140 | 156 | } |
141 | | - if (agg instanceof PercentileRanks) { |
142 | | - return Double.isFinite(((PercentileRanks) agg).percent(0)); |
| 157 | + if (agg instanceof InternalTDigestPercentileRanks) { |
| 158 | + return hasValue((InternalTDigestPercentileRanks) agg); |
143 | 159 | } |
144 | | - if (agg instanceof Percentiles) { |
145 | | - return Double.isFinite(((Percentiles) agg).percentile(0)); |
| 160 | + if (agg instanceof InternalTDigestPercentiles) { |
| 161 | + return hasValue((InternalTDigestPercentiles) agg); |
146 | 162 | } |
147 | 163 | return true; |
148 | 164 | } |
|
0 commit comments