Skip to content

Commit

Permalink
refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
KSDaemon committed Dec 17, 2024
1 parent ff93bfe commit 1fdc9af
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 52 deletions.
2 changes: 1 addition & 1 deletion rust/cubeorchestrator/src/cubestore_message_parser.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::transport::{DBResponsePrimitive, DBResponseValue};
use crate::cubestore_result_transform::{DBResponsePrimitive, DBResponseValue};
use cubeshared::codegen::{root_as_http_message, HttpCommand};
use neon::prelude::Finalize;
use serde::Deserialize;
Expand Down
54 changes: 49 additions & 5 deletions rust/cubeorchestrator/src/cubestore_result_transform.rs
Original file line number Diff line number Diff line change
@@ -1,22 +1,27 @@
use crate::{
cubestore_message_parser::CubeStoreResult,
transport::{
ConfigItem, DBResponsePrimitive, DBResponseValue, MembersMap, NormalizedQuery,
QueryTimeDimension, QueryType, ResultType, TransformDataRequest, BLENDING_QUERY_KEY_PREFIX,
BLENDING_QUERY_RES_SEPARATOR, COMPARE_DATE_RANGE_FIELD, COMPARE_DATE_RANGE_SEPARATOR,
MEMBER_SEPARATOR,
ConfigItem, MembersMap, NormalizedQuery, QueryTimeDimension, QueryType, ResultType,
TransformDataRequest,
},
};
use anyhow::{bail, Context, Result};
use chrono::{DateTime, SecondsFormat};
use chrono::{DateTime, SecondsFormat, Utc};
use itertools::multizip;
use serde::{Deserialize, Serialize};
use serde_json::Value;
use std::{
collections::{HashMap, HashSet},
fmt::Display,
sync::Arc,
};

pub const COMPARE_DATE_RANGE_FIELD: &str = "compareDateRange";
pub const COMPARE_DATE_RANGE_SEPARATOR: &str = " - ";
pub const BLENDING_QUERY_KEY_PREFIX: &str = "time.";
pub const BLENDING_QUERY_RES_SEPARATOR: &str = ".";
pub const MEMBER_SEPARATOR: &str = ".";

/// Transform specified `value` with specified `type` to the network protocol type.
pub fn transform_value(value: DBResponseValue, type_: &str) -> DBResponsePrimitive {
match value {
Expand Down Expand Up @@ -542,3 +547,42 @@ impl RequestResultData {
pub struct RequestResultArray {
pub results: Vec<RequestResultData>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum DBResponsePrimitive {
Null,
Boolean(bool),
Number(f64),
String(String),
}

impl Display for DBResponsePrimitive {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let str = match self {
DBResponsePrimitive::Null => "null".to_string(),
DBResponsePrimitive::Boolean(b) => b.to_string(),
DBResponsePrimitive::Number(n) => n.to_string(),
DBResponsePrimitive::String(s) => s.clone(),
};
write!(f, "{}", str)
}
}

#[derive(Debug, Clone, Deserialize)]
pub enum DBResponseValue {
DateTime(DateTime<Utc>),
Primitive(DBResponsePrimitive),
// TODO: Is this variant still used?
Object { value: DBResponsePrimitive },
}

impl Display for DBResponseValue {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let str = match self {
DBResponseValue::DateTime(dt) => dt.to_rfc3339(),
DBResponseValue::Primitive(p) => p.to_string(),
DBResponseValue::Object { value } => value.to_string(),
};
write!(f, "{}", str)
}
}
46 changes: 0 additions & 46 deletions rust/cubeorchestrator/src/transport.rs
Original file line number Diff line number Diff line change
@@ -1,53 +1,7 @@
use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};
use serde_json::Value;
use std::{collections::HashMap, fmt::Display};

pub const COMPARE_DATE_RANGE_FIELD: &str = "compareDateRange";
pub const COMPARE_DATE_RANGE_SEPARATOR: &str = " - ";
pub const BLENDING_QUERY_KEY_PREFIX: &str = "time.";
pub const BLENDING_QUERY_RES_SEPARATOR: &str = ".";
pub const MEMBER_SEPARATOR: &str = ".";

#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum DBResponsePrimitive {
Null,
Boolean(bool),
Number(f64),
String(String),
}

impl Display for DBResponsePrimitive {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let str = match self {
DBResponsePrimitive::Null => "null".to_string(),
DBResponsePrimitive::Boolean(b) => b.to_string(),
DBResponsePrimitive::Number(n) => n.to_string(),
DBResponsePrimitive::String(s) => s.clone(),
};
write!(f, "{}", str)
}
}

#[derive(Debug, Clone, Deserialize)]
pub enum DBResponseValue {
DateTime(DateTime<Utc>),
Primitive(DBResponsePrimitive),
// TODO: Is this variant still used?
Object { value: DBResponsePrimitive },
}

impl Display for DBResponseValue {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let str = match self {
DBResponseValue::DateTime(dt) => dt.to_rfc3339(),
DBResponseValue::Primitive(p) => p.to_string(),
DBResponseValue::Object { value } => value.to_string(),
};
write!(f, "{}", str)
}
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum ResultType {
#[serde(rename = "default")]
Expand Down

0 comments on commit 1fdc9af

Please sign in to comment.