1919use actix_web:: http:: header:: ContentType ;
2020use actix_web:: web:: { self , Json } ;
2121use actix_web:: { FromRequest , HttpRequest , Responder } ;
22- use arrow_json:: reader:: infer_json_schema_from_iterator;
2322use chrono:: { DateTime , Utc } ;
2423use datafusion:: error:: DataFusionError ;
2524use datafusion:: execution:: context:: SessionState ;
@@ -30,10 +29,7 @@ use std::pin::Pin;
3029use std:: sync:: Arc ;
3130use std:: time:: Instant ;
3231
33- // Eshan's Code Under test
34- #[ allow( unused_imports) ]
3532use arrow_schema:: Schema ;
36- #[ allow( unused_imports) ]
3733use crate :: handlers:: http:: send_schema_request;
3834
3935use crate :: event:: commit_schema;
@@ -68,40 +64,28 @@ pub async fn query(req: HttpRequest, query_request: Query) -> Result<impl Respon
6864 let session_state = QUERY_SESSION . state ( ) ;
6965 let mut query = into_query ( & query_request, & session_state) . await ?;
7066
71- // if CONFIG.parseable.mode == Mode::Query {
72- // if let Ok(schs) = send_schema_request(&query.table_name().unwrap()).await {
73- // let new_schema =
74- // Schema::try_merge(schs).map_err(|err| QueryError::Custom(err.to_string()))?;
67+ if CONFIG . parseable . mode == Mode :: Query {
68+ if let Ok ( schs) = send_schema_request ( & query. table_name ( ) . unwrap ( ) ) . await {
69+ let new_schema =
70+ Schema :: try_merge ( schs) . map_err ( |err| QueryError :: Custom ( err. to_string ( ) ) ) ?;
7571
76- // commit_schema(&query.table_name().unwrap(), Arc::new(new_schema.clone()))
77- // .map_err(|err| QueryError::Custom(format!("Error committing schema: {}", err)))?;
72+ commit_schema ( & query. table_name ( ) . unwrap ( ) , Arc :: new ( new_schema. clone ( ) ) )
73+ . map_err ( |err| QueryError :: Custom ( format ! ( "Error committing schema: {}" , err) ) ) ?;
7874
79- // commit_schema_to_storage(&query.table_name().unwrap(), new_schema)
80- // .await
81- // .map_err(|err| {
82- // QueryError::Custom(format!("Error committing schema to storage\nError:{err}"))
83- // })?;
84- // }
85- // }
75+ commit_schema_to_storage ( & query. table_name ( ) . unwrap ( ) , new_schema)
76+ . await
77+ . map_err ( |err| {
78+ QueryError :: Custom ( format ! ( "Error committing schema to storage\n Error:{err}" ) )
79+ } ) ?;
80+ }
81+ }
8682
8783 let mmem = if CONFIG . parseable . mode == Mode :: Query {
8884 // create a new query to send to the ingestors
8985 if let Some ( que) = transform_query_for_ingestor ( & query_request) {
9086 let vals = send_request_to_ingestor ( & que)
9187 . await
9288 . map_err ( |err| QueryError :: Custom ( err. to_string ( ) ) ) ?;
93- let infered_schema = infer_json_schema_from_iterator ( vals. iter ( ) . map ( Ok ) ) . map_err ( |err| {
94- QueryError :: Custom ( format ! ( "Error inferring schema from iterator\n Error:{err}" ) )
95- } ) ?;
96-
97- commit_schema ( & query. table_name ( ) . unwrap ( ) , Arc :: new ( infered_schema. clone ( ) ) )
98- . map_err ( |err| QueryError :: Custom ( format ! ( "Error committing schema: {}" , err) ) ) ?;
99-
100- commit_schema_to_storage ( & query. table_name ( ) . unwrap ( ) , infered_schema)
101- . await
102- . map_err ( |err| {
103- QueryError :: Custom ( format ! ( "Error committing schema to storage\n Error:{err}" ) )
104- } ) ?;
10589
10690 Some ( vals)
10791 } else {
0 commit comments