@@ -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