@@ -36,18 +36,52 @@ struct HttpServerState {
3636
3737static HttpServerState global_state;
3838
39+ std::string GetColumnType (MaterializedQueryResult &result, idx_t column) {
40+ if (result.RowCount () == 0 ) {
41+ return " String" ;
42+ }
43+ switch (result.types [column].id ()) {
44+ case LogicalTypeId::FLOAT :
45+ return " Float" ;
46+ case LogicalTypeId::DOUBLE :
47+ return " Double" ;
48+ case LogicalTypeId::INTEGER :
49+ return " Int32" ;
50+ case LogicalTypeId::BIGINT :
51+ return " Int64" ;
52+ case LogicalTypeId::UINTEGER :
53+ return " UInt32" ;
54+ case LogicalTypeId::UBIGINT :
55+ return " UInt64" ;
56+ case LogicalTypeId::VARCHAR :
57+ return " String" ;
58+ case LogicalTypeId::TIME :
59+ return " DateTime" ;
60+ case LogicalTypeId::DATE :
61+ return " Date" ;
62+ case LogicalTypeId::TIMESTAMP :
63+ return " DateTime" ;
64+ case LogicalTypeId::BOOLEAN :
65+ return " Int8" ;
66+ default :
67+ return " String" ;
68+ }
69+ return " String" ;
70+ }
71+
3972// Convert the query result to JSON format
4073static std::string ConvertResultToJSON (MaterializedQueryResult &result) {
4174 auto doc = yyjson_mut_doc_new (nullptr );
4275 auto root = yyjson_mut_obj (doc);
4376 yyjson_mut_doc_set_root (doc, root);
44-
4577 // Add meta information
4678 auto meta_array = yyjson_mut_arr (doc);
4779 for (idx_t col = 0 ; col < result.ColumnCount (); ++col) {
4880 auto column_obj = yyjson_mut_obj (doc);
4981 yyjson_mut_obj_add_str (doc, column_obj, " name" , result.ColumnName (col).c_str ());
5082 yyjson_mut_arr_append (meta_array, column_obj);
83+ std::string tp (GetColumnType (result, col));
84+ yyjson_mut_obj_add_strcpy (doc, column_obj, " type" , tp.c_str ());
5185 }
5286 yyjson_mut_obj_add_val (doc, root, " meta" , meta_array);
5387
@@ -70,7 +104,11 @@ static std::string ConvertResultToJSON(MaterializedQueryResult &result) {
70104
71105 // Add row count
72106 yyjson_mut_obj_add_int (doc, root, " rows" , result.RowCount ());
73-
107+ // "statistics":{"elapsed":0.00031403,"rows_read":1,"bytes_read":0}}
108+ auto stat_obj = yyjson_mut_obj_add_obj (doc, root, " statistics" );
109+ yyjson_mut_obj_add_real (doc, stat_obj, " elapsed" , 0.01 );
110+ yyjson_mut_obj_add_int (doc, stat_obj, " rows_read" , 1 );
111+ yyjson_mut_obj_add_int (doc, stat_obj, " bytes_read" , 0 );
74112 // Write to string
75113 auto data = yyjson_mut_write (doc, 0 , nullptr );
76114 if (!data) {
0 commit comments