1818
1919use crate :: event:: error:: EventError ;
2020use crate :: handlers:: http:: fetch_schema;
21+ use crate :: option:: Mode ;
2122use crate :: utils:: arrow:: record_batches_to_json;
2223use actix_web:: http:: header:: ContentType ;
2324use actix_web:: web:: { self , Json } ;
@@ -113,6 +114,7 @@ pub async fn query(req: HttpRequest, query_request: Query) -> Result<HttpRespons
113114 let time_range =
114115 TimeRange :: parse_human_time ( & query_request. start_time , & query_request. end_time ) ?;
115116 let tables = resolve_stream_names ( & query_request. query ) ?;
117+ update_schema_when_distributed ( & tables) . await ?;
116118 let query: LogicalQuery =
117119 into_query ( & query_request, & session_state, time_range, & tables) . await ?;
118120 let creds = extract_session_key_from_req ( & req) ?;
@@ -122,7 +124,6 @@ pub async fn query(req: HttpRequest, query_request: Query) -> Result<HttpRespons
122124 . first ( )
123125 . ok_or_else ( || QueryError :: MalformedQuery ( "No table name found in query" ) ) ?;
124126 user_auth_for_datasets ( & permissions, & tables) . await ?;
125- update_schema_when_distributed ( & tables) . await ?;
126127 let time = Instant :: now ( ) ;
127128
128129 // if the query is `select count(*) from <dataset>`
@@ -392,12 +393,13 @@ pub async fn update_schema_when_distributed(tables: &Vec<String>) -> Result<(),
392393 // if the mode is query or prism, we need to update the schema in memory
393394 // no need to commit schema to storage
394395 // as the schema is read from memory everytime
395- for table in tables {
396- if let Ok ( new_schema) = fetch_schema ( table) . await {
397- commit_schema ( table, Arc :: new ( new_schema) ) ?;
396+ if PARSEABLE . options . mode == Mode :: Query || PARSEABLE . options . mode == Mode :: Prism {
397+ for table in tables {
398+ if let Ok ( new_schema) = fetch_schema ( table) . await {
399+ commit_schema ( table, Arc :: new ( new_schema) ) ?;
400+ }
398401 }
399402 }
400-
401403 Ok ( ( ) )
402404}
403405
0 commit comments