|
1 | 1 | use crate::{
|
2 | 2 | cubestore_message_parser::CubeStoreResult,
|
3 | 3 | 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, |
8 | 6 | },
|
9 | 7 | };
|
10 | 8 | use anyhow::{bail, Context, Result};
|
11 |
| -use chrono::{DateTime, SecondsFormat}; |
| 9 | +use chrono::{DateTime, SecondsFormat, Utc}; |
12 | 10 | use itertools::multizip;
|
13 | 11 | use serde::{Deserialize, Serialize};
|
14 | 12 | use serde_json::Value;
|
15 | 13 | use std::{
|
16 | 14 | collections::{HashMap, HashSet},
|
| 15 | + fmt::Display, |
17 | 16 | sync::Arc,
|
18 | 17 | };
|
19 | 18 |
|
| 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 | + |
20 | 25 | /// Transform specified `value` with specified `type` to the network protocol type.
|
21 | 26 | pub fn transform_value(value: DBResponseValue, type_: &str) -> DBResponsePrimitive {
|
22 | 27 | match value {
|
@@ -542,3 +547,42 @@ impl RequestResultData {
|
542 | 547 | pub struct RequestResultArray {
|
543 | 548 | pub results: Vec<RequestResultData>,
|
544 | 549 | }
|
| 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 | +} |
0 commit comments