Skip to content

Commit c535af6

Browse files
committed
Add test to search splits contained in time range
1 parent f3ab102 commit c535af6

File tree

2 files changed

+93
-3
lines changed

2 files changed

+93
-3
lines changed

quickwit/quickwit-indexing/src/test_utils.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
// limitations under the License.
1414

1515
use std::num::NonZeroUsize;
16+
use std::ops::RangeInclusive;
1617
use std::str::FromStr;
1718
use std::sync::Arc;
1819
use std::sync::atomic::{AtomicUsize, Ordering};
@@ -251,8 +252,12 @@ pub struct MockSplitBuilder {
251252

252253
impl MockSplitBuilder {
253254
pub fn new(split_id: &str) -> Self {
255+
Self::new_with_time_range(split_id, Some(121000..=130198))
256+
}
257+
258+
pub fn new_with_time_range(split_id: &str, time_range: Option<RangeInclusive<i64>>) -> Self {
254259
Self {
255-
split_metadata: mock_split_meta(split_id, &IndexUid::for_test("test-index", 0)),
260+
split_metadata: mock_split_meta(split_id, &IndexUid::for_test("test-index", 0), time_range),
256261
}
257262
}
258263

@@ -277,14 +282,14 @@ pub fn mock_split(split_id: &str) -> Split {
277282
}
278283

279284
/// Mock split meta helper.
280-
pub fn mock_split_meta(split_id: &str, index_uid: &IndexUid) -> SplitMetadata {
285+
pub fn mock_split_meta(split_id: &str, index_uid: &IndexUid, time_range: Option<RangeInclusive<i64>>) -> SplitMetadata {
281286
SplitMetadata {
282287
index_uid: index_uid.clone(),
283288
split_id: split_id.to_string(),
284289
partition_id: 13u64,
285290
num_docs: if split_id == "split1" { 1_000_000 } else { 10 },
286291
uncompressed_docs_size_in_bytes: 256,
287-
time_range: Some(121000..=130198),
292+
time_range,
288293
create_timestamp: 0,
289294
footer_offsets: 700..800,
290295
..Default::default()

quickwit/quickwit-search/src/root.rs

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5076,4 +5076,89 @@ mod tests {
50765076
assert_eq!(search_response.failed_splits.len(), 1);
50775077
Ok(())
50785078
}
5079+
5080+
#[tokio::test]
5081+
async fn test_search_partial_hits_phase_filters_by_time_range() -> anyhow::Result<()> {
5082+
let search_request = quickwit_proto::search::SearchRequest {
5083+
start_timestamp: Some(122_000),
5084+
end_timestamp: Some(129_000),
5085+
index_id_patterns: vec!["test-index".to_string()],
5086+
query_ast: qast_json_helper("test", &["body"]),
5087+
max_hits: 10,
5088+
..Default::default()
5089+
};
5090+
5091+
let index_metadata = IndexMetadata::for_test("test-index", "ram:///test-index");
5092+
let index_uid = index_metadata.index_uid.clone();
5093+
5094+
let mut mock_metastore = MockMetastoreService::new();
5095+
mock_metastore
5096+
.expect_list_indexes_metadata()
5097+
.returning(move |_q| {
5098+
Ok(ListIndexesMetadataResponse::for_test(vec![
5099+
index_metadata.clone(),
5100+
]))
5101+
});
5102+
mock_metastore.expect_list_splits().returning(move |_req| {
5103+
let splits = vec![
5104+
MockSplitBuilder::new_with_time_range("split_before", Some(100_000..=110_000))
5105+
.with_index_uid(&index_uid)
5106+
.build(),
5107+
MockSplitBuilder::new_with_time_range(
5108+
"split_overlap_start",
5109+
Some(120_000..=123_000),
5110+
)
5111+
.with_index_uid(&index_uid)
5112+
.build(),
5113+
MockSplitBuilder::new_with_time_range("split_overlap_end", Some(128_000..=140_000))
5114+
.with_index_uid(&index_uid)
5115+
.build(),
5116+
MockSplitBuilder::new_with_time_range(
5117+
"split_covering_whole",
5118+
Some(100_000..=200_000),
5119+
)
5120+
.with_index_uid(&index_uid)
5121+
.build(),
5122+
MockSplitBuilder::new_with_time_range("split_inside", Some(124_000..=126_000))
5123+
.with_index_uid(&index_uid)
5124+
.build(),
5125+
];
5126+
let resp = ListSplitsResponse::try_from_splits(splits).unwrap();
5127+
Ok(ServiceStream::from(vec![Ok(resp)]))
5128+
});
5129+
5130+
let mut mock_search = MockSearchService::new();
5131+
mock_search.expect_leaf_search().times(1).returning(|_req| {
5132+
Ok(quickwit_proto::search::LeafSearchResponse {
5133+
num_hits: 1,
5134+
partial_hits: vec![mock_partial_hit("split_inside", 1, 1)],
5135+
failed_splits: Vec::new(),
5136+
num_attempted_splits: 1,
5137+
..Default::default()
5138+
})
5139+
});
5140+
mock_search.expect_fetch_docs().returning(|fetch_req| {
5141+
Ok(quickwit_proto::search::FetchDocsResponse {
5142+
hits: get_doc_for_fetch_req(fetch_req),
5143+
})
5144+
});
5145+
5146+
let searcher_pool = searcher_pool_for_test([("127.0.0.1:1001", mock_search)]);
5147+
let search_job_placer = SearchJobPlacer::new(searcher_pool);
5148+
let cluster_client = ClusterClient::new(search_job_placer);
5149+
5150+
let ctx = SearcherContext::for_test();
5151+
let resp = root_search(
5152+
&ctx,
5153+
search_request,
5154+
MetastoreServiceClient::from_mock(mock_metastore),
5155+
&cluster_client,
5156+
)
5157+
.await?;
5158+
5159+
assert_eq!(resp.num_hits, 1);
5160+
assert_eq!(resp.hits.len(), 1);
5161+
5162+
Ok(())
5163+
}
50795164
}

0 commit comments

Comments
 (0)