Skip to content

Commit 1824991

Browse files
linxGnufulmicoton
andauthored
ISSUE-1086 Check query against latest schema - root streaming (#1109)
* ISSUE-1086 Check query against latest schema - root streaming * Adapt changes Co-authored-by: Paul Masurel <[email protected]>
1 parent 8d9a1a1 commit 1824991

File tree

2 files changed

+65
-2
lines changed

2 files changed

+65
-2
lines changed

quickwit-search/src/root.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1086,7 +1086,7 @@ mod tests {
10861086
assert!(root_search(
10871087
&quickwit_proto::SearchRequest {
10881088
index_id: "test-idx".to_string(),
1089-
query: r#"invalid_body:"test""#.to_string(),
1089+
query: r#"invalid_field:"test""#.to_string(),
10901090
search_fields: vec!["body".to_string()],
10911091
start_timestamp: None,
10921092
end_timestamp: None,
@@ -1105,7 +1105,7 @@ mod tests {
11051105
&quickwit_proto::SearchRequest {
11061106
index_id: "test-idx".to_string(),
11071107
query: "test".to_string(),
1108-
search_fields: vec!["invalid_body".to_string()],
1108+
search_fields: vec!["invalid_field".to_string()],
11091109
start_timestamp: None,
11101110
end_timestamp: None,
11111111
max_hits: 10,

quickwit-search/src/search_stream/root.rs

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ pub async fn root_search_stream(
5353
.map_err(|err| {
5454
SearchError::InternalError(format!("Failed to build doc mapper. Cause: {}", err))
5555
})?;
56+
57+
// try to build query against current schema
58+
let _query = doc_mapper.query(doc_mapper.schema(), &search_request)?;
59+
5660
let doc_mapper_str = serde_json::to_string(&doc_mapper).map_err(|err| {
5761
SearchError::InternalError(format!("Failed to serialize doc mapper: Cause {}", err))
5862
})?;
@@ -277,4 +281,63 @@ mod tests {
277281
assert_eq!(result.unwrap_err().to_string(), "Internal error: `error`.");
278282
Ok(())
279283
}
284+
285+
#[tokio::test]
286+
async fn test_root_search_stream_with_invalid_query() -> anyhow::Result<()> {
287+
let mut metastore = MockMetastore::new();
288+
metastore
289+
.expect_index_metadata()
290+
.returning(|_index_id: &str| {
291+
Ok(IndexMetadata::for_test(
292+
"test-idx",
293+
"file:///path/to/index/test-idx",
294+
))
295+
});
296+
metastore.expect_list_splits().returning(
297+
|_index_id: &str, _split_state: SplitState, _time_range: Option<Range<i64>>, _tags| {
298+
Ok(vec![mock_split("split")])
299+
},
300+
);
301+
302+
let client_pool =
303+
SearchClientPool::from_mocks(vec![Arc::new(MockSearchService::new())]).await?;
304+
305+
assert!(root_search_stream(
306+
quickwit_proto::SearchStreamRequest {
307+
index_id: "test-idx".to_string(),
308+
query: r#"invalid_field:"test""#.to_string(),
309+
search_fields: vec!["body".to_string()],
310+
start_timestamp: None,
311+
end_timestamp: None,
312+
fast_field: "timestamp".to_string(),
313+
output_format: OutputFormat::Csv as i32,
314+
partition_by_field: Some("timestamp".to_string()),
315+
},
316+
&metastore,
317+
ClusterClient::new(client_pool.clone()),
318+
&client_pool,
319+
)
320+
.await
321+
.is_err());
322+
323+
assert!(root_search_stream(
324+
quickwit_proto::SearchStreamRequest {
325+
index_id: "test-idx".to_string(),
326+
query: "test".to_string(),
327+
search_fields: vec!["invalid_field".to_string()],
328+
start_timestamp: None,
329+
end_timestamp: None,
330+
fast_field: "timestamp".to_string(),
331+
output_format: OutputFormat::Csv as i32,
332+
partition_by_field: Some("timestamp".to_string()),
333+
},
334+
&metastore,
335+
ClusterClient::new(client_pool.clone()),
336+
&client_pool
337+
)
338+
.await
339+
.is_err());
340+
341+
Ok(())
342+
}
280343
}

0 commit comments

Comments
 (0)