Skip to content

Commit c39d91f

Browse files
Merge pull request #2547 from quickwit-oss/trinity/count-str
add support for counting non integer in aggregation
2 parents 0f99d4f + 32b6e97 commit c39d91f

File tree

3 files changed

+48
-8
lines changed

3 files changed

+48
-8
lines changed

src/aggregation/agg_req_with_accessor.rs

Lines changed: 18 additions & 4 deletions
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

Lines changed: 29 additions & 3 deletions
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
}
@@ -435,6 +449,11 @@ mod tests {
435449
"field": "score",
436450
},
437451
},
452+
"count_str": {
453+
"value_count": {
454+
"field": "text",
455+
},
456+
},
438457
"range": range_agg
439458
}))
440459
.unwrap();
@@ -500,6 +519,13 @@ mod tests {
500519
})
501520
);
502521

522+
assert_eq!(
523+
res["count_str"],
524+
json!({
525+
"value": 7.0,
526+
})
527+
);
528+
503529
Ok(())
504530
}
505531

src/aggregation/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -578,7 +578,7 @@ mod tests {
578578
.set_indexing_options(
579579
TextFieldIndexing::default().set_index_option(IndexRecordOption::WithFreqs),
580580
)
581-
.set_fast(None)
581+
.set_fast(Some("raw"))
582582
.set_stored();
583583
let text_field = schema_builder.add_text_field("text", text_fieldtype);
584584
let date_field = schema_builder.add_date_field("date", FAST);

0 commit comments

Comments
 (0)