Skip to content

Commit 02239d4

Browse files
committed
fix
1 parent 7c8f335 commit 02239d4

File tree

4 files changed

+41
-14
lines changed

4 files changed

+41
-14
lines changed

packages/cubejs-schema-compiler/src/adapter/BaseQuery.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4214,23 +4214,23 @@ export class BaseQuery {
42144214
'{{ min_expr }} as {{ quoted_min_name }}\n' +
42154215
'FROM {{ from_prepared }}\n' +
42164216
'{% if filter %}WHERE {{ filter }}{% endif %}',
4217-
calc_groups_join: 'SELECT "{{ original_cube }}".*, ' +
4217+
calc_groups_join: 'SELECT {{ original_cube }}.*, ' +
42184218
'{%for single_value in single_values %}' +
4219-
'\'{{ single_value.value }}\' as "{{ single_value.name }}"{% if not loop.last %}, {% endif %}' +
4219+
'{{ single_value.value }} as {{ single_value.name }}{% if not loop.last %}, {% endif %}' +
42204220
'{% endfor %}' +
42214221
'{% if single_values and groups %}, {% endif %}' +
42224222
'{%for group in groups %}' +
4223-
'"{{ group.name }}"{% if not loop.last %}, {% endif %}' +
4223+
'{{ group.name }}{% if not loop.last %}, {% endif %}' +
42244224
'{% endfor %}' +
42254225
'FROM {{ original_cube_sql }} {{ original_cube }}\n' +
42264226
'{% for group in groups %}' +
42274227
'CROSS JOIN\n' +
42284228
'(\n' +
42294229
'{% for value in group.values %}' +
4230-
'SELECT \'{{ value }}\' as "{{ group.name }}"' +
4230+
'SELECT {{ value }} as {{ group.name }}' +
42314231
'{% if not loop.last %} UNION ALL\n{% endif %}' +
42324232
'{% endfor %}' +
4233-
') "{{ group.name }}_values"\n' +
4233+
') {{ group.alias }}\n' +
42344234
'{% endfor %}'
42354235
},
42364236
expressions: {

rust/cubesqlplanner/cubesqlplanner/src/planner/sql_evaluator/sql_nodes/cube_calc_groups.rs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -72,27 +72,21 @@ impl SqlNode for CubeCalcGroupsSqlNode {
7272
MemberSymbol::CubeTable(ev) => {
7373
let res = if let Some(calc_groups) = self.items.get(ev.cube_name()) {
7474
let mut single_values = vec![];
75-
let mut groups = vec![];
75+
let mut template_groups = vec![];
7676
for calc_group in calc_groups {
7777
if calc_group.values.len() == 1 {
7878
single_values.push(TemplateCalcSingleValue {
7979
name: calc_group.name.clone(),
8080
value: calc_group.values[0].clone(),
8181
})
8282
} else {
83-
groups.push(TemplateCalcGroup {
83+
template_groups.push(TemplateCalcGroup {
8484
name: calc_group.name.clone(),
85+
alias: format!("{}_values", calc_group.name),
8586
values: calc_group.values.clone(),
8687
})
8788
}
8889
}
89-
let template_groups = groups
90-
.iter()
91-
.map(|group| TemplateCalcGroup {
92-
name: group.name.clone(),
93-
values: group.values.clone(),
94-
})
95-
.collect_vec();
9690
let res = templates.calc_groups_join(
9791
&ev.cube_name(),
9892
&input,

rust/cubesqlplanner/cubesqlplanner/src/planner/sql_templates/plan.rs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,38 @@ impl PlanSqlTemplates {
355355
single_values: Vec<TemplateCalcSingleValue>,
356356
groups: Vec<TemplateCalcGroup>,
357357
) -> Result<String, CubeError> {
358+
let original_cube = self.quote_identifier(original_cube)?;
359+
let single_values = single_values
360+
.into_iter()
361+
.map(|v| -> Result<_, CubeError> {
362+
Ok(TemplateCalcSingleValue {
363+
value: self.quote_string(&v.value)?,
364+
name: self.quote_identifier(&v.name)?,
365+
})
366+
})
367+
.collect::<Result<Vec<_>, _>>()?;
368+
let groups = groups
369+
.into_iter()
370+
.map(|g| -> Result<_, CubeError> {
371+
let TemplateCalcGroup {
372+
name,
373+
alias,
374+
values,
375+
} = g;
376+
let name = self.quote_identifier(&name)?;
377+
let alias = self.quote_identifier(&alias)?;
378+
let values = values
379+
.into_iter()
380+
.map(|v| self.quote_string(&v))
381+
.collect::<Result<Vec<_>, _>>()?;
382+
383+
Ok(TemplateCalcGroup {
384+
name,
385+
alias,
386+
values,
387+
})
388+
})
389+
.collect::<Result<Vec<_>, _>>()?;
358390
self.render.render_template(
359391
"statements/calc_groups_join",
360392
context! {

rust/cubesqlplanner/cubesqlplanner/src/planner/sql_templates/structs.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ pub struct TemplateOrderByColumn {
2121
#[derive(Debug, Clone, Serialize, Deserialize)]
2222
pub struct TemplateCalcGroup {
2323
pub name: String,
24+
pub alias: String,
2425
pub values: Vec<String>,
2526
}
2627

0 commit comments

Comments
 (0)