Skip to content

Commit 5d1b009

Browse files
authored
chore: expose alias member property for measures (cube-js#9849)
* dev * dev * dev * dev * dev * upd * dev * dev * fmt * fix * upd * fmt
1 parent 760640c commit 5d1b009

File tree

7 files changed

+46
-0
lines changed

7 files changed

+46
-0
lines changed

packages/cubejs-api-gateway/openspec.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,9 @@ components:
163163
type: "string"
164164
meta:
165165
type: "object"
166+
aliasMember:
167+
description: "When measure is defined in View, it keeps the original path: Cube.measure"
168+
type: "string"
166169
V1CubeMetaFolder:
167170
type: "object"
168171
required:

packages/cubejs-client-core/src/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,7 @@ export type BaseCubeMember = {
364364
isVisible?: boolean;
365365
public?: boolean;
366366
meta?: any;
367+
aliasMember?: string;
367368
};
368369

369370
export type TCubeMeasure = BaseCubeMember & {

packages/cubejs-schema-compiler/src/compiler/CubeToMetaTransformer.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,7 @@ export class CubeToMetaTransformer {
223223
measures: drillMembersArray.filter((member) => this.cubeEvaluator.isMeasure(member)),
224224
dimensions: drillMembersArray.filter((member) => this.cubeEvaluator.isDimension(member)),
225225
},
226+
aliasMember: nameToMetric[1].aliasMember,
226227
meta: nameToMetric[1].meta
227228
};
228229
}

packages/cubejs-schema-compiler/test/unit/__snapshots__/views.test.ts.snap

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ Object {
4646
"measures": Array [
4747
Object {
4848
"aggType": "number",
49+
"aliasMember": "CubeA.count_a",
4950
"cumulative": false,
5051
"cumulativeTotal": false,
5152
"description": "Description for CubeA.count_a",
@@ -67,6 +68,7 @@ Object {
6768
},
6869
Object {
6970
"aggType": "number",
71+
"aliasMember": "CubeB.count_b",
7072
"cumulative": false,
7173
"cumulativeTotal": false,
7274
"description": "Description for CubeB.count_b",
@@ -126,6 +128,7 @@ Object {
126128
"measures": Array [
127129
Object {
128130
"aggType": "number",
131+
"aliasMember": "CubeA.count_a",
129132
"cumulative": false,
130133
"cumulativeTotal": false,
131134
"description": "Description for CubeA.count_a",
@@ -147,6 +150,7 @@ Object {
147150
},
148151
Object {
149152
"aggType": "number",
153+
"aliasMember": "CubeB.count_b",
150154
"cumulative": false,
151155
"cumulativeTotal": false,
152156
"description": "Description for CubeB.count_b",
@@ -240,6 +244,7 @@ Object {
240244
"measures": Array [
241245
Object {
242246
"aggType": "number",
247+
"aliasMember": "CubeA.count_a",
243248
"cumulative": false,
244249
"cumulativeTotal": false,
245250
"description": "Description for CubeA.count_a",
@@ -261,6 +266,7 @@ Object {
261266
},
262267
Object {
263268
"aggType": "number",
269+
"aliasMember": "CubeB.count_b",
264270
"cumulative": false,
265271
"cumulativeTotal": false,
266272
"description": "Description for CubeB.count_b",
@@ -320,6 +326,7 @@ Object {
320326
"measures": Array [
321327
Object {
322328
"aggType": "number",
329+
"aliasMember": "CubeA.count_a",
323330
"cumulative": false,
324331
"cumulativeTotal": false,
325332
"description": "Description for CubeA.count_a",
@@ -341,6 +348,7 @@ Object {
341348
},
342349
Object {
343350
"aggType": "number",
351+
"aliasMember": "CubeB.count_b",
344352
"cumulative": false,
345353
"cumulativeTotal": false,
346354
"description": "Description for CubeB.count_b",

rust/cubesql/cubeclient/src/models/v1_cube_meta_measure.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ pub struct V1CubeMetaMeasure {
2727
pub agg_type: Option<String>,
2828
#[serde(rename = "meta", skip_serializing_if = "Option::is_none")]
2929
pub meta: Option<serde_json::Value>,
30+
/// When measure is defined in View, it keeps the original path: Cube.measure
31+
#[serde(rename = "aliasMember", skip_serializing_if = "Option::is_none")]
32+
pub alias_member: Option<String>,
3033
}
3134

3235
impl V1CubeMetaMeasure {
@@ -39,6 +42,7 @@ impl V1CubeMetaMeasure {
3942
r#type,
4043
agg_type: None,
4144
meta: None,
45+
alias_member: None,
4246
}
4347
}
4448
}

rust/cubesql/cubesql/benches/large_model.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ pub fn get_large_model_test_meta(dims: usize) -> Vec<V1CubeMeta> {
7272
r#type: "number".to_string(),
7373
agg_type: Some("count".to_string()),
7474
meta: None,
75+
alias_member: None,
7576
},
7677
V1CubeMetaMeasure {
7778
name: format!("{}.sum", cube_name),
@@ -81,6 +82,7 @@ pub fn get_large_model_test_meta(dims: usize) -> Vec<V1CubeMeta> {
8182
r#type: "number".to_string(),
8283
agg_type: Some("sum".to_string()),
8384
meta: None,
85+
alias_member: None,
8486
},
8587
],
8688
dimensions: (1..=dims)

rust/cubesql/cubesql/src/compile/test/mod.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ pub fn get_test_meta() -> Vec<CubeMeta> {
106106
r#type: "number".to_string(),
107107
agg_type: Some("count".to_string()),
108108
meta: None,
109+
alias_member: None,
109110
},
110111
CubeMetaMeasure {
111112
name: "KibanaSampleDataEcommerce.maxPrice".to_string(),
@@ -115,6 +116,7 @@ pub fn get_test_meta() -> Vec<CubeMeta> {
115116
r#type: "number".to_string(),
116117
agg_type: Some("max".to_string()),
117118
meta: None,
119+
alias_member: None,
118120
},
119121
CubeMetaMeasure {
120122
name: "KibanaSampleDataEcommerce.sumPrice".to_string(),
@@ -124,6 +126,7 @@ pub fn get_test_meta() -> Vec<CubeMeta> {
124126
r#type: "number".to_string(),
125127
agg_type: Some("sum".to_string()),
126128
meta: None,
129+
alias_member: None,
127130
},
128131
CubeMetaMeasure {
129132
name: "KibanaSampleDataEcommerce.minPrice".to_string(),
@@ -133,6 +136,7 @@ pub fn get_test_meta() -> Vec<CubeMeta> {
133136
r#type: "number".to_string(),
134137
agg_type: Some("min".to_string()),
135138
meta: None,
139+
alias_member: None,
136140
},
137141
CubeMetaMeasure {
138142
name: "KibanaSampleDataEcommerce.avgPrice".to_string(),
@@ -142,6 +146,7 @@ pub fn get_test_meta() -> Vec<CubeMeta> {
142146
r#type: "number".to_string(),
143147
agg_type: Some("avg".to_string()),
144148
meta: None,
149+
alias_member: None,
145150
},
146151
CubeMetaMeasure {
147152
name: "KibanaSampleDataEcommerce.countDistinct".to_string(),
@@ -151,6 +156,7 @@ pub fn get_test_meta() -> Vec<CubeMeta> {
151156
r#type: "number".to_string(),
152157
agg_type: Some("countDistinct".to_string()),
153158
meta: None,
159+
alias_member: None,
154160
},
155161
],
156162
segments: vec![
@@ -209,6 +215,7 @@ pub fn get_test_meta() -> Vec<CubeMeta> {
209215
r#type: "number".to_string(),
210216
agg_type: Some("countDistinct".to_string()),
211217
meta: None,
218+
alias_member: None,
212219
},
213220
CubeMetaMeasure {
214221
name: "Logs.agentCountApprox".to_string(),
@@ -218,6 +225,7 @@ pub fn get_test_meta() -> Vec<CubeMeta> {
218225
r#type: "number".to_string(),
219226
agg_type: Some("countDistinctApprox".to_string()),
220227
meta: None,
228+
alias_member: None,
221229
},
222230
],
223231
segments: vec![],
@@ -244,6 +252,7 @@ pub fn get_test_meta() -> Vec<CubeMeta> {
244252
r#type: "number".to_string(),
245253
agg_type: Some("number".to_string()),
246254
meta: None,
255+
alias_member: None,
247256
}],
248257
segments: vec![],
249258
joins: None,
@@ -273,6 +282,7 @@ pub fn get_test_meta() -> Vec<CubeMeta> {
273282
short_title: None,
274283
description: None,
275284
meta: None,
285+
alias_member: None,
276286
})
277287
.chain(
278288
vec![
@@ -284,6 +294,7 @@ pub fn get_test_meta() -> Vec<CubeMeta> {
284294
r#type: "number".to_string(),
285295
agg_type: Some("count".to_string()),
286296
meta: None,
297+
alias_member: None,
287298
},
288299
CubeMetaMeasure {
289300
name: "WideCube.maxPrice".to_string(),
@@ -293,6 +304,7 @@ pub fn get_test_meta() -> Vec<CubeMeta> {
293304
r#type: "number".to_string(),
294305
agg_type: Some("max".to_string()),
295306
meta: None,
307+
alias_member: None,
296308
},
297309
CubeMetaMeasure {
298310
name: "WideCube.minPrice".to_string(),
@@ -302,6 +314,7 @@ pub fn get_test_meta() -> Vec<CubeMeta> {
302314
r#type: "number".to_string(),
303315
agg_type: Some("min".to_string()),
304316
meta: None,
317+
alias_member: None,
305318
},
306319
CubeMetaMeasure {
307320
name: "WideCube.avgPrice".to_string(),
@@ -311,6 +324,7 @@ pub fn get_test_meta() -> Vec<CubeMeta> {
311324
r#type: "number".to_string(),
312325
agg_type: Some("avg".to_string()),
313326
meta: None,
327+
alias_member: None,
314328
},
315329
CubeMetaMeasure {
316330
name: "WideCube.countDistinct".to_string(),
@@ -320,6 +334,7 @@ pub fn get_test_meta() -> Vec<CubeMeta> {
320334
r#type: "number".to_string(),
321335
agg_type: Some("countDistinct".to_string()),
322336
meta: None,
337+
alias_member: None,
323338
},
324339
]
325340
.into_iter(),
@@ -372,6 +387,7 @@ pub fn get_test_meta() -> Vec<CubeMeta> {
372387
short_title: None,
373388
description: Some(format!("Test number measure {i}")),
374389
meta: None,
390+
alias_member: None,
375391
},
376392
CubeMetaMeasure {
377393
name: format!("MultiTypeCube.measure_str{}", i),
@@ -381,6 +397,7 @@ pub fn get_test_meta() -> Vec<CubeMeta> {
381397
short_title: None,
382398
description: Some(format!("Test max(string) measure {i}")),
383399
meta: None,
400+
alias_member: None,
384401
},
385402
CubeMetaMeasure {
386403
name: format!("MultiTypeCube.measure_date{}", i),
@@ -390,6 +407,7 @@ pub fn get_test_meta() -> Vec<CubeMeta> {
390407
short_title: None,
391408
description: Some(format!("Test max(time) measure {i}")),
392409
meta: None,
410+
alias_member: None,
393411
},
394412
]
395413
})
@@ -403,6 +421,7 @@ pub fn get_test_meta() -> Vec<CubeMeta> {
403421
r#type: "number".to_string(),
404422
agg_type: Some("count".to_string()),
405423
meta: None,
424+
alias_member: None,
406425
},
407426
CubeMetaMeasure {
408427
name: "MultiTypeCube.maxPrice".to_string(),
@@ -412,6 +431,7 @@ pub fn get_test_meta() -> Vec<CubeMeta> {
412431
r#type: "number".to_string(),
413432
agg_type: Some("max".to_string()),
414433
meta: None,
434+
alias_member: None,
415435
},
416436
CubeMetaMeasure {
417437
name: "MultiTypeCube.minPrice".to_string(),
@@ -421,6 +441,7 @@ pub fn get_test_meta() -> Vec<CubeMeta> {
421441
r#type: "number".to_string(),
422442
agg_type: Some("min".to_string()),
423443
meta: None,
444+
alias_member: None,
424445
},
425446
CubeMetaMeasure {
426447
name: "MultiTypeCube.avgPrice".to_string(),
@@ -430,6 +451,7 @@ pub fn get_test_meta() -> Vec<CubeMeta> {
430451
r#type: "number".to_string(),
431452
agg_type: Some("avg".to_string()),
432453
meta: None,
454+
alias_member: None,
433455
},
434456
CubeMetaMeasure {
435457
name: "MultiTypeCube.countDistinct".to_string(),
@@ -439,6 +461,7 @@ pub fn get_test_meta() -> Vec<CubeMeta> {
439461
r#type: "number".to_string(),
440462
agg_type: Some("countDistinct".to_string()),
441463
meta: None,
464+
alias_member: None,
442465
},
443466
]
444467
.into_iter(),
@@ -469,6 +492,7 @@ pub fn get_string_cube_meta() -> Vec<CubeMeta> {
469492
r#type: "string".to_string(),
470493
agg_type: Some("string".to_string()),
471494
meta: None,
495+
alias_member: None,
472496
}],
473497
segments: vec![],
474498
joins: None,
@@ -495,6 +519,7 @@ pub fn get_sixteen_char_member_cube() -> Vec<CubeMeta> {
495519
r#type: "number".to_string(),
496520
agg_type: Some("sum".to_string()),
497521
meta: None,
522+
alias_member: None,
498523
},
499524
CubeMetaMeasure {
500525
name: "SixteenChar.sixteen_charchar_foo".to_string(),
@@ -504,6 +529,7 @@ pub fn get_sixteen_char_member_cube() -> Vec<CubeMeta> {
504529
r#type: "number".to_string(),
505530
agg_type: Some("avg".to_string()),
506531
meta: None,
532+
alias_member: None,
507533
},
508534
CubeMetaMeasure {
509535
name: "SixteenChar.sixteen_charchar_bar".to_string(),
@@ -513,6 +539,7 @@ pub fn get_sixteen_char_member_cube() -> Vec<CubeMeta> {
513539
r#type: "number".to_string(),
514540
agg_type: Some("count".to_string()),
515541
meta: None,
542+
alias_member: None,
516543
},
517544
],
518545
segments: vec![],

0 commit comments

Comments
 (0)