Skip to content

Commit ac2f955

Browse files
committed
fix dtos for native query processing (thnx unit tests)
1 parent df99c14 commit ac2f955

File tree

3 files changed

+54
-16
lines changed

3 files changed

+54
-16
lines changed

packages/cubejs-api-gateway/src/helpers/toConfigMap.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ type MetaConfigMap = {
2828
};
2929

3030
/**
31-
* Convert cpecified array of MetaConfig objects to the
31+
* Convert specified array of MetaConfig objects to the
3232
* MetaConfigMap.
3333
*/
3434
function toConfigMap(metaConfig: MetaConfig[]): MetaConfigMap {

rust/cubeorchestrator/src/query_result_transform.rs

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
use crate::{
22
query_message_parser::QueryResult,
33
transport::{
4-
ConfigItem, MembersMap, NormalizedQuery, QueryTimeDimension, QueryType, ResultType,
5-
TransformDataRequest,
4+
AnnotatedConfigItem, ConfigItem, MembersMap, NormalizedQuery, QueryTimeDimension,
5+
QueryType, ResultType, TransformDataRequest,
66
},
77
};
88
use anyhow::{bail, Context, Result};
@@ -197,7 +197,8 @@ pub fn get_compact_row(
197197
if let Some(alias) = members_to_alias_map.get(m) {
198198
if let Some(key) = columns_pos.get(alias) {
199199
if let Some(value) = db_row.get(*key) {
200-
row.push(transform_value(value.clone(), &annotation_item.member_type));
200+
let mtype = annotation_item.member_type.as_deref().unwrap_or("");
201+
row.push(transform_value(value.clone(), mtype));
201202
}
202203
}
203204
}
@@ -214,9 +215,9 @@ pub fn get_compact_row(
214215
if let Some(alias) = members_to_alias_map.get(&blending_key) {
215216
if let Some(key) = columns_pos.get(alias) {
216217
if let Some(value) = db_row.get(*key) {
217-
let member_type = annotation
218-
.get(alias)
219-
.map_or("", |annotation_item| &annotation_item.member_type);
218+
let member_type = annotation.get(alias).map_or("", |annotation_item| {
219+
annotation_item.member_type.as_deref().unwrap_or("")
220+
});
220221

221222
row.push(transform_value(value.clone(), member_type));
222223
}
@@ -263,8 +264,13 @@ pub fn get_vanilla_row(
263264
}
264265
};
265266

266-
let transformed_value =
267-
transform_value(value.clone(), &annotation_for_member.member_type);
267+
let transformed_value = transform_value(
268+
value.clone(),
269+
annotation_for_member
270+
.member_type
271+
.as_ref()
272+
.unwrap_or(&"".to_string()),
273+
);
268274

269275
// Handle deprecated time dimensions without granularity
270276
let path: Vec<&str> = member_name.split(MEMBER_SEPARATOR).collect();
@@ -527,15 +533,18 @@ pub struct RequestResultData {
527533
#[serde(rename = "requestId")]
528534
#[serde(skip_serializing_if = "Option::is_none")]
529535
pub request_id: Option<String>,
530-
pub annotation: HashMap<String, HashMap<String, ConfigItem>>,
536+
pub annotation: HashMap<String, HashMap<String, AnnotatedConfigItem>>,
531537
#[serde(rename = "dataSource")]
532-
pub data_source: String,
538+
#[serde(skip_serializing_if = "Option::is_none")]
539+
pub data_source: Option<String>,
533540
#[serde(rename = "dbType")]
534-
pub db_type: String,
541+
#[serde(skip_serializing_if = "Option::is_none")]
542+
pub db_type: Option<String>,
535543
#[serde(rename = "extDbType")]
536544
#[serde(skip_serializing_if = "Option::is_none")]
537545
pub ext_db_type: Option<String>,
538-
pub external: bool,
546+
#[serde(skip_serializing_if = "Option::is_none")]
547+
pub external: Option<bool>,
539548
#[serde(rename = "slowQuery")]
540549
pub slow_query: bool,
541550
#[serde(skip_serializing_if = "Option::is_none")]

rust/cubeorchestrator/src/transport.rs

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,9 @@ pub struct ParsedMemberExpression {
118118
#[derive(Debug, Clone, Serialize, Deserialize)]
119119
pub struct QueryTimeDimension {
120120
pub dimension: String,
121+
#[serde(rename = "dateRange")]
121122
pub date_range: Option<Vec<String>>,
123+
#[serde(rename = "compareDateRange")]
122124
pub compare_date_range: Option<Vec<String>>,
123125
pub granularity: Option<String>,
124126
}
@@ -140,13 +142,15 @@ pub struct GranularityMeta {
140142

141143
#[derive(Debug, Clone, Serialize, Deserialize)]
142144
pub struct ConfigItem {
143-
pub title: String,
145+
#[serde(skip_serializing_if = "Option::is_none")]
146+
pub title: Option<String>,
144147
#[serde(skip_serializing_if = "Option::is_none")]
145148
pub short_title: Option<String>,
146149
#[serde(skip_serializing_if = "Option::is_none")]
147150
pub description: Option<String>,
148151
#[serde(rename = "type")]
149-
pub member_type: String,
152+
#[serde(skip_serializing_if = "Option::is_none")]
153+
pub member_type: Option<String>,
150154
#[serde(skip_serializing_if = "Option::is_none")]
151155
pub format: Option<String>,
152156
#[serde(skip_serializing_if = "Option::is_none")]
@@ -161,6 +165,31 @@ pub struct ConfigItem {
161165
pub granularities: Option<Vec<GranularityMeta>>,
162166
}
163167

168+
#[derive(Debug, Clone, Serialize, Deserialize)]
169+
pub struct AnnotatedConfigItem {
170+
#[serde(skip_serializing_if = "Option::is_none")]
171+
pub title: Option<String>,
172+
#[serde(skip_serializing_if = "Option::is_none")]
173+
pub short_title: Option<String>,
174+
#[serde(skip_serializing_if = "Option::is_none")]
175+
pub description: Option<String>,
176+
#[serde(rename = "type")]
177+
#[serde(skip_serializing_if = "Option::is_none")]
178+
pub member_type: Option<String>,
179+
#[serde(skip_serializing_if = "Option::is_none")]
180+
pub format: Option<String>,
181+
#[serde(skip_serializing_if = "Option::is_none")]
182+
pub meta: Option<Value>,
183+
#[serde(skip_serializing_if = "Option::is_none")]
184+
#[serde(rename = "drillMembers")]
185+
pub drill_members: Option<Vec<Value>>,
186+
#[serde(skip_serializing_if = "Option::is_none")]
187+
#[serde(rename = "drillMembersGrouped")]
188+
pub drill_members_grouped: Option<Value>,
189+
#[serde(skip_serializing_if = "Option::is_none")]
190+
pub granularity: Option<GranularityMeta>,
191+
}
192+
164193
#[derive(Debug, Clone, Serialize, Deserialize)]
165194
pub struct Order {
166195
pub id: String,
@@ -172,7 +201,7 @@ pub struct NormalizedQueryFilter {
172201
pub member: String,
173202
pub operator: FilterOperator,
174203
#[serde(skip_serializing_if = "Option::is_none")]
175-
pub values: Option<Vec<String>>,
204+
pub values: Option<Vec<DBResponsePrimitive>>,
176205
#[serde(skip_serializing_if = "Option::is_none")]
177206
pub dimension: Option<String>,
178207
}

0 commit comments

Comments
 (0)