@@ -86,25 +86,37 @@ def post(self):
8686
8787 try :
8888 handler = mysql_proxy .session .integration_controller .get_data_handler (db )
89- result = handler .native_query (query )
89+ raw_result = handler .native_query (query )
9090 except Exception as e :
91- query_response = {"type" : "error" , "error_code" : 0 , "error_message" : str (e )}
91+ error_type = "unexpected"
92+ result = SQLAnswer (
93+ resp_type = SQL_RESPONSE_TYPE .ERROR ,
94+ error_code = 0 ,
95+ error_message = str (e ),
96+ )
9297 else :
93- if result .type == SQL_RESPONSE_TYPE .ERROR :
94- query_response = {"type" : "error" , "error_code" : 0 , "error_message" : result .error_message }
95- elif result .type == SQL_RESPONSE_TYPE .OK :
96- query_response = {"type" : "ok" }
98+ if raw_result .type == SQL_RESPONSE_TYPE .ERROR :
99+ # raw_result will be ErrorResponse.
100+ error_type = "expected"
101+ result = SQLAnswer (
102+ resp_type = SQL_RESPONSE_TYPE .ERROR ,
103+ error_code = 0 ,
104+ error_message = raw_result .error_message ,
105+ )
106+ elif raw_result .type == SQL_RESPONSE_TYPE .OK :
107+ result = SQLAnswer (
108+ resp_type = SQL_RESPONSE_TYPE .OK ,
109+ error_code = 0 ,
110+ error_message = None ,
111+ )
97112 else :
98- df = result .data_frame
99- result_set = ResultSet .from_df (df )
100- query_response = {
101- "type" : "table" ,
102- "column_names" : result_set .get_column_names (),
103- "data" : result_set .to_lists (json_types = True ),
104- }
113+ # raw_result will be TableResponse.
114+ result_set = ResultSet .from_table_response (raw_result )
115+ result = SQLAnswer (
116+ resp_type = SQL_RESPONSE_TYPE .TABLE ,
117+ result_set = result_set ,
118+ )
105119
106- query_response ["context" ] = mysql_proxy .get_context ()
107- query_response = query_response , 200
108120 else :
109121 try :
110122 result : SQLAnswer = mysql_proxy .process_query (query )
@@ -137,16 +149,16 @@ def post(self):
137149 )
138150 logger .exception ("Error query processing:" )
139151
140- context = mysql_proxy .get_context ()
152+ context = mysql_proxy .get_context ()
141153
142- if response_format == ReponseFormat .JSONLINES :
143- query_response = result .stream_http_response_jsonlines (context = context )
144- query_response = Response (query_response , mimetype = "application/jsonlines" )
145- elif response_format == ReponseFormat .SSE :
146- query_response = result .stream_http_response_sse (context = context )
147- query_response = Response (query_response , mimetype = "text/event-stream" )
148- else :
149- query_response = result .dump_http_response (context = context ), 200
154+ if response_format == ReponseFormat .JSONLINES :
155+ query_response = result .stream_http_response_jsonlines (context = context )
156+ query_response = Response (query_response , mimetype = "application/jsonlines" )
157+ elif response_format == ReponseFormat .SSE :
158+ query_response = result .stream_http_response_sse (context = context )
159+ query_response = Response (query_response , mimetype = "text/event-stream" )
160+ else :
161+ query_response = result .dump_http_response (context = context ), 200
150162
151163 hooks .after_api_query (
152164 company_id = ctx .company_id ,
0 commit comments