11use cubeshared:: codegen:: { root_as_http_message, HttpCommand } ;
2- use std:: collections:: HashMap ;
32
43#[ derive( Debug ) ]
54pub enum ParseError {
@@ -24,9 +23,14 @@ impl std::fmt::Display for ParseError {
2423 }
2524}
2625
26+ pub struct CubeStoreResult < ' a > {
27+ pub columns : Vec < & ' a str > ,
28+ pub rows : Vec < Vec < & ' a str > > ,
29+ }
30+
2731impl std:: error:: Error for ParseError { }
2832
29- pub fn parse_cubestore_ws_result ( msg_data : & [ u8 ] ) -> Result < Vec < HashMap < & str , & str > > , ParseError > {
33+ pub fn parse_cubestore_ws_result ( msg_data : & [ u8 ] ) -> Result < CubeStoreResult , ParseError > {
3034 let http_message = root_as_http_message ( msg_data) . map_err ( |_| ParseError :: FlatBufferError ) ?;
3135
3236 let command_type = http_message. command_type ( ) ;
@@ -51,20 +55,19 @@ pub fn parse_cubestore_ws_result(msg_data: &[u8]) -> Result<Vec<HashMap<&str, &s
5155 }
5256
5357 let result_set_rows = result_set. rows ( ) . ok_or ( ParseError :: EmptyResultSet ) ?;
54- let mut result = Vec :: with_capacity ( result_set_rows. len ( ) ) ;
58+ let mut result = CubeStoreResult {
59+ columns : result_set_columns. iter ( ) . collect ( ) ,
60+ rows : Vec :: with_capacity ( result_set_rows. len ( ) )
61+ } ;
5562
5663 for row in result_set_rows. iter ( ) {
5764 let values = row. values ( ) . ok_or ( ParseError :: NullRow ) ?;
58- let row_obj: HashMap < _ , _ > = result_set_columns
65+ let row_obj: Vec < _ > = values
5966 . iter ( )
60- . zip ( values. iter ( ) )
61- . map ( |( col, val) | {
62- let value = val. string_value ( ) . unwrap_or ( "" ) ;
63- ( col, value)
64- } )
67+ . map ( |val| val. string_value ( ) . unwrap_or ( "" ) )
6568 . collect ( ) ;
6669
67- result. push ( row_obj) ;
70+ result. rows . push ( row_obj) ;
6871 }
6972
7073 Ok ( result)
0 commit comments