Skip to content

Commit 1fdc9af

Browse files
committed
refactoring
1 parent ff93bfe commit 1fdc9af

File tree

3 files changed

+50
-52
lines changed

3 files changed

+50
-52
lines changed

rust/cubeorchestrator/src/cubestore_message_parser.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::transport::{DBResponsePrimitive, DBResponseValue};
1+
use crate::cubestore_result_transform::{DBResponsePrimitive, DBResponseValue};
22
use cubeshared::codegen::{root_as_http_message, HttpCommand};
33
use neon::prelude::Finalize;
44
use serde::Deserialize;

rust/cubeorchestrator/src/cubestore_result_transform.rs

Lines changed: 49 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,27 @@
11
use crate::{
22
cubestore_message_parser::CubeStoreResult,
33
transport::{
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,
4+
ConfigItem, MembersMap, NormalizedQuery, QueryTimeDimension, QueryType, ResultType,
5+
TransformDataRequest,
86
},
97
};
108
use anyhow::{bail, Context, Result};
11-
use chrono::{DateTime, SecondsFormat};
9+
use chrono::{DateTime, SecondsFormat, Utc};
1210
use itertools::multizip;
1311
use serde::{Deserialize, Serialize};
1412
use serde_json::Value;
1513
use std::{
1614
collections::{HashMap, HashSet},
15+
fmt::Display,
1716
sync::Arc,
1817
};
1918

19+
pub const COMPARE_DATE_RANGE_FIELD: &str = "compareDateRange";
20+
pub const COMPARE_DATE_RANGE_SEPARATOR: &str = " - ";
21+
pub const BLENDING_QUERY_KEY_PREFIX: &str = "time.";
22+
pub const BLENDING_QUERY_RES_SEPARATOR: &str = ".";
23+
pub const MEMBER_SEPARATOR: &str = ".";
24+
2025
/// Transform specified `value` with specified `type` to the network protocol type.
2126
pub fn transform_value(value: DBResponseValue, type_: &str) -> DBResponsePrimitive {
2227
match value {
@@ -542,3 +547,42 @@ impl RequestResultData {
542547
pub struct RequestResultArray {
543548
pub results: Vec<RequestResultData>,
544549
}
550+
551+
#[derive(Debug, Clone, Serialize, Deserialize)]
552+
pub enum DBResponsePrimitive {
553+
Null,
554+
Boolean(bool),
555+
Number(f64),
556+
String(String),
557+
}
558+
559+
impl Display for DBResponsePrimitive {
560+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
561+
let str = match self {
562+
DBResponsePrimitive::Null => "null".to_string(),
563+
DBResponsePrimitive::Boolean(b) => b.to_string(),
564+
DBResponsePrimitive::Number(n) => n.to_string(),
565+
DBResponsePrimitive::String(s) => s.clone(),
566+
};
567+
write!(f, "{}", str)
568+
}
569+
}
570+
571+
#[derive(Debug, Clone, Deserialize)]
572+
pub enum DBResponseValue {
573+
DateTime(DateTime<Utc>),
574+
Primitive(DBResponsePrimitive),
575+
// TODO: Is this variant still used?
576+
Object { value: DBResponsePrimitive },
577+
}
578+
579+
impl Display for DBResponseValue {
580+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
581+
let str = match self {
582+
DBResponseValue::DateTime(dt) => dt.to_rfc3339(),
583+
DBResponseValue::Primitive(p) => p.to_string(),
584+
DBResponseValue::Object { value } => value.to_string(),
585+
};
586+
write!(f, "{}", str)
587+
}
588+
}

rust/cubeorchestrator/src/transport.rs

Lines changed: 0 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,7 @@
1-
use chrono::{DateTime, Utc};
21
use serde::{Deserialize, Serialize};
32
use serde_json::Value;
43
use std::{collections::HashMap, fmt::Display};
54

6-
pub const COMPARE_DATE_RANGE_FIELD: &str = "compareDateRange";
7-
pub const COMPARE_DATE_RANGE_SEPARATOR: &str = " - ";
8-
pub const BLENDING_QUERY_KEY_PREFIX: &str = "time.";
9-
pub const BLENDING_QUERY_RES_SEPARATOR: &str = ".";
10-
pub const MEMBER_SEPARATOR: &str = ".";
11-
12-
#[derive(Debug, Clone, Serialize, Deserialize)]
13-
pub enum DBResponsePrimitive {
14-
Null,
15-
Boolean(bool),
16-
Number(f64),
17-
String(String),
18-
}
19-
20-
impl Display for DBResponsePrimitive {
21-
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
22-
let str = match self {
23-
DBResponsePrimitive::Null => "null".to_string(),
24-
DBResponsePrimitive::Boolean(b) => b.to_string(),
25-
DBResponsePrimitive::Number(n) => n.to_string(),
26-
DBResponsePrimitive::String(s) => s.clone(),
27-
};
28-
write!(f, "{}", str)
29-
}
30-
}
31-
32-
#[derive(Debug, Clone, Deserialize)]
33-
pub enum DBResponseValue {
34-
DateTime(DateTime<Utc>),
35-
Primitive(DBResponsePrimitive),
36-
// TODO: Is this variant still used?
37-
Object { value: DBResponsePrimitive },
38-
}
39-
40-
impl Display for DBResponseValue {
41-
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
42-
let str = match self {
43-
DBResponseValue::DateTime(dt) => dt.to_rfc3339(),
44-
DBResponseValue::Primitive(p) => p.to_string(),
45-
DBResponseValue::Object { value } => value.to_string(),
46-
};
47-
write!(f, "{}", str)
48-
}
49-
}
50-
515
#[derive(Debug, Clone, Serialize, Deserialize)]
526
pub enum ResultType {
537
#[serde(rename = "default")]

0 commit comments

Comments
 (0)