Skip to content

Commit 0bac391

Browse files
committed
add support for counting non integer in aggregation
1 parent 52d4e81 commit 0bac391

File tree

2 files changed

+35
-7
lines changed

2 files changed

+35
-7
lines changed

src/aggregation/agg_req_with_accessor.rs

+18-4
Original file line numberDiff line numberDiff line change
@@ -271,10 +271,6 @@ impl AggregationWithAccessor {
271271
field: ref field_name,
272272
..
273273
})
274-
| Count(CountAggregation {
275-
field: ref field_name,
276-
..
277-
})
278274
| Max(MaxAggregation {
279275
field: ref field_name,
280276
..
@@ -299,6 +295,24 @@ impl AggregationWithAccessor {
299295
get_ff_reader(reader, field_name, Some(get_numeric_or_date_column_types()))?;
300296
add_agg_with_accessor(&agg, accessor, column_type, &mut res)?;
301297
}
298+
Count(CountAggregation {
299+
field: ref field_name,
300+
..
301+
}) => {
302+
let allowed_column_types = [
303+
ColumnType::I64,
304+
ColumnType::U64,
305+
ColumnType::F64,
306+
ColumnType::Str,
307+
ColumnType::DateTime,
308+
ColumnType::Bool,
309+
ColumnType::IpAddr,
310+
// ColumnType::Bytes Unsupported
311+
];
312+
let (accessor, column_type) =
313+
get_ff_reader(reader, field_name, Some(&allowed_column_types))?;
314+
add_agg_with_accessor(&agg, accessor, column_type, &mut res)?;
315+
}
302316
Percentiles(ref percentiles) => {
303317
let (accessor, column_type) = get_ff_reader(
304318
reader,

src/aggregation/metric/stats.rs

+17-3
Original file line numberDiff line numberDiff line change
@@ -220,9 +220,23 @@ impl SegmentStatsCollector {
220220
.column_block_accessor
221221
.fetch_block(docs, &agg_accessor.accessor);
222222
}
223-
for val in agg_accessor.column_block_accessor.iter_vals() {
224-
let val1 = f64_from_fastfield_u64(val, &self.field_type);
225-
self.stats.collect(val1);
223+
if [
224+
ColumnType::I64,
225+
ColumnType::U64,
226+
ColumnType::F64,
227+
ColumnType::DateTime,
228+
]
229+
.contains(&self.field_type)
230+
{
231+
for val in agg_accessor.column_block_accessor.iter_vals() {
232+
let val1 = f64_from_fastfield_u64(val, &self.field_type);
233+
self.stats.collect(val1);
234+
}
235+
} else {
236+
for _val in agg_accessor.column_block_accessor.iter_vals() {
237+
// we ignore the value and simply record that we got something
238+
self.stats.collect(0.0);
239+
}
226240
}
227241
}
228242
}

0 commit comments

Comments
 (0)