1
1
use cubeshared:: codegen:: { root_as_http_message, HttpCommand } ;
2
- use std:: collections:: HashMap ;
3
2
4
3
#[ derive( Debug ) ]
5
4
pub enum ParseError {
@@ -24,9 +23,14 @@ impl std::fmt::Display for ParseError {
24
23
}
25
24
}
26
25
26
+ pub struct CubeStoreResult < ' a > {
27
+ pub columns : Vec < & ' a str > ,
28
+ pub rows : Vec < Vec < & ' a str > > ,
29
+ }
30
+
27
31
impl std:: error:: Error for ParseError { }
28
32
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 > {
30
34
let http_message = root_as_http_message ( msg_data) . map_err ( |_| ParseError :: FlatBufferError ) ?;
31
35
32
36
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
51
55
}
52
56
53
57
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
+ } ;
55
62
56
63
for row in result_set_rows. iter ( ) {
57
64
let values = row. values ( ) . ok_or ( ParseError :: NullRow ) ?;
58
- let row_obj: HashMap < _ , _ > = result_set_columns
65
+ let row_obj: Vec < _ > = values
59
66
. 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 ( "" ) )
65
68
. collect ( ) ;
66
69
67
- result. push ( row_obj) ;
70
+ result. rows . push ( row_obj) ;
68
71
}
69
72
70
73
Ok ( result)
0 commit comments