11use crate :: {
22 cubestore_message_parser:: CubeStoreResult ,
33 transport:: {
4- ConfigItem , MembersMap , NormalizedQuery , QueryTimeDimension , QueryType , ResultType ,
5- TransformDataRequest , BLENDING_QUERY_KEY_PREFIX , BLENDING_QUERY_RES_SEPARATOR ,
6- COMPARE_DATE_RANGE_FIELD , COMPARE_DATE_RANGE_SEPARATOR , MEMBER_SEPARATOR ,
4+ ConfigItem , DBResponsePrimitive , DBResponseValue , MembersMap , NormalizedQuery ,
5+ QueryTimeDimension , QueryType , ResultType , TransformDataRequest , BLENDING_QUERY_KEY_PREFIX ,
6+ BLENDING_QUERY_RES_SEPARATOR , COMPARE_DATE_RANGE_FIELD , COMPARE_DATE_RANGE_SEPARATOR ,
7+ MEMBER_SEPARATOR ,
78 } ,
89} ;
910use anyhow:: { bail, Context , Result } ;
@@ -17,18 +18,28 @@ use std::{
1718} ;
1819
1920/// Transform specified `value` with specified `type` to the network protocol type.
20- pub fn transform_value ( value : String , type_ : & str ) -> String {
21- if type_ == "time" || type_. is_empty ( ) {
22- DateTime :: parse_from_rfc3339 ( & value)
23- . map ( |dt| dt. to_rfc3339_opts ( SecondsFormat :: Millis , true ) )
24- . unwrap_or_else ( |_| value)
25- } else {
26- value
21+ pub fn transform_value ( value : DBResponseValue , type_ : & str ) -> DBResponsePrimitive {
22+ match value {
23+ DBResponseValue :: DateTime ( dt) if type_ == "time" || type_. is_empty ( ) => {
24+ let formatted = dt. to_rfc3339_opts ( SecondsFormat :: Millis , true ) ;
25+ DBResponsePrimitive :: String ( formatted)
26+ }
27+ DBResponseValue :: Primitive ( DBResponsePrimitive :: String ( ref s) ) if type_ == "time" => {
28+ let formatted = DateTime :: parse_from_rfc3339 ( s)
29+ . map ( |dt| dt. to_rfc3339_opts ( SecondsFormat :: Millis , true ) )
30+ . unwrap_or_else ( |_| s. clone ( ) ) ;
31+ DBResponsePrimitive :: String ( formatted)
32+ }
33+ DBResponseValue :: Primitive ( p) => p,
34+ DBResponseValue :: Object { value } => value,
35+ _ => DBResponsePrimitive :: Null ,
2736 }
2837}
2938
3039/// Parse date range value from time dimension.
31- pub fn get_date_range_value ( time_dimensions : Option < & Vec < QueryTimeDimension > > ) -> Result < String > {
40+ pub fn get_date_range_value (
41+ time_dimensions : Option < & Vec < QueryTimeDimension > > ,
42+ ) -> Result < DBResponsePrimitive > {
3243 let time_dimensions = match time_dimensions {
3344 Some ( time_dimensions) => time_dimensions,
3445 None => bail ! ( "QueryTimeDimension should be specified for the compare date range query." ) ,
@@ -51,7 +62,9 @@ pub fn get_date_range_value(time_dimensions: Option<&Vec<QueryTimeDimension>>) -
5162 ) ;
5263 }
5364
54- Ok ( date_range. join ( COMPARE_DATE_RANGE_SEPARATOR ) )
65+ Ok ( DBResponsePrimitive :: String (
66+ date_range. join ( COMPARE_DATE_RANGE_SEPARATOR ) ,
67+ ) )
5568}
5669
5770/// Parse blending query key from time dimension for query.
@@ -169,10 +182,10 @@ pub fn get_compact_row(
169182 query_type : & QueryType ,
170183 members : & [ String ] ,
171184 time_dimensions : Option < & Vec < QueryTimeDimension > > ,
172- db_row : & [ String ] ,
185+ db_row : & [ DBResponseValue ] ,
173186 columns_pos : & HashMap < String , usize > ,
174- ) -> Result < Vec < String > > {
175- let mut row: Vec < String > = Vec :: with_capacity ( members. len ( ) ) ;
187+ ) -> Result < Vec < DBResponsePrimitive > > {
188+ let mut row: Vec < DBResponsePrimitive > = Vec :: with_capacity ( members. len ( ) ) ;
176189
177190 for m in members {
178191 if let Some ( annotation_item) = annotation. get ( m) {
@@ -217,9 +230,9 @@ pub fn get_vanilla_row(
217230 annotation : & HashMap < String , ConfigItem > ,
218231 query_type : & QueryType ,
219232 query : & NormalizedQuery ,
220- db_row : & [ String ] ,
233+ db_row : & [ DBResponseValue ] ,
221234 columns_pos : & HashMap < String , usize > ,
222- ) -> Result < HashMap < String , String > > {
235+ ) -> Result < HashMap < String , DBResponsePrimitive > > {
223236 let mut row = HashMap :: new ( ) ;
224237
225238 for ( alias, & index) in columns_pos {
@@ -379,9 +392,9 @@ pub fn get_final_cubestore_result_array(
379392pub enum TransformedData {
380393 Compact {
381394 members : Vec < String > ,
382- dataset : Vec < Vec < String > > ,
395+ dataset : Vec < Vec < DBResponsePrimitive > > ,
383396 } ,
384- Vanilla ( Vec < HashMap < String , String > > ) ,
397+ Vanilla ( Vec < HashMap < String , DBResponsePrimitive > > ) ,
385398}
386399
387400impl TransformedData {
0 commit comments