1919use actix_web:: http:: header:: ContentType ;
2020use actix_web:: web:: { self , Json } ;
2121use actix_web:: { FromRequest , HttpRequest , Responder } ;
22- use arrow_schema :: Schema ;
22+ use arrow_json :: reader :: infer_json_schema_from_iterator ;
2323use chrono:: { DateTime , Utc } ;
2424use datafusion:: error:: DataFusionError ;
2525use datafusion:: execution:: context:: SessionState ;
@@ -30,8 +30,13 @@ use std::pin::Pin;
3030use std:: sync:: Arc ;
3131use std:: time:: Instant ;
3232
33- use crate :: event:: commit_schema;
33+ // Eshan's Code Under test
34+ #[ allow( unused_imports) ]
35+ use arrow_schema:: Schema ;
36+ #[ allow( unused_imports) ]
3437use crate :: handlers:: http:: send_schema_request;
38+
39+ use crate :: event:: commit_schema;
3540use crate :: metrics:: QUERY_EXECUTE_TIME ;
3641use crate :: option:: { Mode , CONFIG } ;
3742use crate :: query:: error:: ExecuteError ;
@@ -63,28 +68,41 @@ pub async fn query(req: HttpRequest, query_request: Query) -> Result<impl Respon
6368 let session_state = QUERY_SESSION . state ( ) ;
6469 let mut query = into_query ( & query_request, & session_state) . await ?;
6570
66- if CONFIG . parseable . mode == Mode :: Query {
67- if let Ok ( schs) = send_schema_request ( & query. table_name ( ) . unwrap ( ) ) . await {
68- let new_schema =
69- Schema :: try_merge ( schs) . map_err ( |err| QueryError :: Custom ( err. to_string ( ) ) ) ?;
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()))?;
7075
71- commit_schema ( & query. table_name ( ) . unwrap ( ) , Arc :: new ( new_schema. clone ( ) ) )
72- . map_err ( |err| QueryError :: Custom ( format ! ( "Error committing schema: {}" , err) ) ) ?;
76+ // commit_schema(&query.table_name().unwrap(), Arc::new(new_schema.clone()))
77+ // .map_err(|err| QueryError::Custom(format!("Error committing schema: {}", err)))?;
7378
74- commit_schema_to_storage ( & query. table_name ( ) . unwrap ( ) , new_schema)
75- . await
76- . map_err ( |err| {
77- QueryError :: Custom ( format ! ( "Error committing schema to storage\n Error:{err}" ) )
78- } ) ?;
79- }
80- }
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+ // }
8186
8287 let mmem = if CONFIG . parseable . mode == Mode :: Query {
8388 // create a new query to send to the ingestors
8489 if let Some ( que) = transform_query_for_ingestor ( & query_request) {
8590 let vals = send_request_to_ingestor ( & que)
8691 . await
8792 . 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+ } ) ?;
105+
88106 Some ( vals)
89107 } else {
90108 None
0 commit comments