Skip to content

Commit

Permalink
fetch timestamp in blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
PSeitz committed Mar 21, 2024
1 parent ab9b243 commit e9ad9fa
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
19 changes: 12 additions & 7 deletions quickwit/quickwit-search/src/collector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -502,10 +502,11 @@ enum AggregationSegmentCollectors {
pub struct QuickwitSegmentCollector {
timestamp_filter_opt: Option<TimestampFilter>,
segment_top_k_collector: Option<QuickwitSegmentTopKCollector>,
// Caches for block fetching
filtered_docs: Box<[DocId; 64]>,
aggregation: Option<AggregationSegmentCollectors>,
num_hits: u64,
// Caches for block fetching
filtered_docs: Box<[DocId; 64]>,
timestamps_buffer: Box<[Option<DateTime>; 64]>,
}

impl QuickwitSegmentCollector {
Expand Down Expand Up @@ -786,18 +787,20 @@ fn compute_filtered_block<'a>(
timestamp_filter_opt: &Option<TimestampFilter>,
docs: &'a [DocId],
filtered_docs_buffer: &'a mut [DocId; COLLECT_BLOCK_BUFFER_LEN],
timestamps_buffer: &'a mut [Option<DateTime>; COLLECT_BLOCK_BUFFER_LEN],
) -> &'a [DocId] {
let Some(timestamp_filter) = &timestamp_filter_opt else {
return docs;
};
timestamp_filter.fetch_timestamps(docs, timestamps_buffer);
let mut len = 0;
for &doc in docs {
filtered_docs_buffer[len] = doc;
len += if timestamp_filter.is_within_range(doc) {
1
for (doc, date) in docs.iter().zip(timestamps_buffer.iter()) {
filtered_docs_buffer[len] = *doc;
len += if let Some(ts) = date {
timestamp_filter.contains(ts) as usize
} else {
0
};
}
}
&filtered_docs_buffer[..len]
}
Expand All @@ -811,6 +814,7 @@ impl SegmentCollector for QuickwitSegmentCollector {
&self.timestamp_filter_opt,
unfiltered_docs,
&mut self.filtered_docs,
&mut self.timestamps_buffer,
);

// Update results
Expand Down Expand Up @@ -1118,6 +1122,7 @@ impl Collector for QuickwitCollector {
segment_top_k_collector,
aggregation,
filtered_docs: Box::new([0; 64]),
timestamps_buffer: Box::new([None; 64]),
})
}

Expand Down
12 changes: 11 additions & 1 deletion quickwit/quickwit-search/src/filters.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,20 @@ pub struct TimestampFilter {
}

impl TimestampFilter {
#[inline]
pub fn fetch_timestamps<'a>(&self, docs: &'a [DocId], dates: &'a mut [Option<DateTime>]) {
self.timestamp_column
.first_vals(docs, &mut dates[..docs.len()]);
}
#[inline]
pub fn contains(&self, ts: &DateTime) -> bool {
self.time_range.contains(ts)
}

#[inline]
pub fn is_within_range(&self, doc_id: DocId) -> bool {
if let Some(ts) = self.timestamp_column.first(doc_id) {
self.time_range.contains(&ts)
self.contains(&ts)
} else {
false
}
Expand Down

0 comments on commit e9ad9fa

Please sign in to comment.