Skip to content

Commit 03737c6

Browse files
committed
in work
1 parent e5641f6 commit 03737c6

File tree

6 files changed

+74
-82
lines changed

6 files changed

+74
-82
lines changed

packages/cubejs-schema-compiler/src/compiler/CubeEvaluator.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -547,6 +547,9 @@ export class CubeEvaluator extends CubeSymbols {
547547
let aliasMember;
548548

549549
const member = members[memberName];
550+
if (member.type === 'switch' || member.multiStage) {
551+
ownedByCube = false;
552+
}
550553
if (member.sql && !member.subQuery) {
551554
const funcArgs = this.funcArguments(member.sql);
552555
const { cubeReferencesUsed, evaluatedSql, pathReferencesUsed } = this.collectUsedCubeReferences(cube.name, member.sql);

packages/cubejs-schema-compiler/src/compiler/CubeValidator.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -911,7 +911,7 @@ const viewSchema = inherit(baseSchema, {
911911
meta: Joi.any(),
912912
})
913913
]))
914-
]).required(),
914+
]),
915915
excludes: Joi.array().items(Joi.string().required()),
916916
}).oxor('split', 'prefix').messages({
917917
'object.oxor': 'Using split together with prefix is not supported'

packages/cubejs-schema-compiler/test/integration/postgres/calc-groups.test.ts

Lines changed: 65 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -247,17 +247,79 @@ cubes:
247247
- name: count
248248
type: count
249249
250-
- name: source
250+
- name: source_a
251251
sql: >
252-
SELECT 1
252+
SELECT 10 as ID, 'some category' as PRODUCT_CATEGORY, 'some name' as NAME, 100 as PRICE_USD, 0 as PRICE_EUR
253+
union all
254+
SELECT 11 as ID, 'some category' as PRODUCT_CATEGORY, 'some name' as NAME, 500 as PRICE_USD, 0 as PRICE_EUR
255+
union all
256+
SELECT 12 as ID, 'some category A' as PRODUCT_CATEGORY, 'some name' as NAME, 200 as PRICE_USD, 0 as PRICE_EUR
257+
union all
258+
SELECT 13 as ID, 'some category A' as PRODUCT_CATEGORY, 'some name' as NAME, 300 as PRICE_USD, 0 as PRICE_EUR
253259
public: false
254260
255261
dimensions:
256262
- name: pk
257263
type: number
258-
sql: "1"
264+
sql: ID
259265
primary_key: true
260266
267+
- name: product_category
268+
sql: PRODUCT_CATEGORY
269+
type: string
270+
271+
measures:
272+
- name: count
273+
type: 'count'
274+
275+
- name: price_usd
276+
type: 'sum'
277+
sql: PRICE_USD
278+
279+
- name: price_eur
280+
type: 'sum'
281+
sql: PRICE_EUR
282+
283+
284+
- name: source_b
285+
sql: >
286+
SELECT 10 as ID, 'some category' as PRODUCT_CATEGORY, 'some name' as NAME, 0 as PRICE_USD, 100 as PRICE_EUR
287+
union all
288+
SELECT 11 as ID, 'some category' as PRODUCT_CATEGORY, 'some name' as NAME, 0 as PRICE_USD, 500 as PRICE_EUR
289+
union all
290+
SELECT 12 as ID, 'some category B' as PRODUCT_CATEGORY, 'some name' as NAME, 0 as PRICE_USD, 200 as PRICE_EUR
291+
union all
292+
SELECT 13 as ID, 'some category B' as PRODUCT_CATEGORY, 'some name' as NAME, 0 as PRICE_USD, 300 as PRICE_EUR
293+
union all
294+
SELECT 14 as ID, 'some category B' as PRODUCT_CATEGORY, 'some name' as NAME, 0 as PRICE_USD, 300 as PRICE_EUR
295+
public: false
296+
297+
dimensions:
298+
- name: pk
299+
type: number
300+
sql: ID
301+
primary_key: true
302+
303+
- name: product_category
304+
sql: PRODUCT_CATEGORY
305+
type: string
306+
307+
measures:
308+
- name: count
309+
type: 'count'
310+
311+
- name: price_usd
312+
type: 'sum'
313+
sql: PRICE_USD
314+
315+
- name: price_eur
316+
type: 'sum'
317+
sql: PRICE_EUR
318+
319+
views:
320+
321+
- name: source
322+
dimensions:
261323
- name: source
262324
type: switch
263325
values: ["A", "B"]
@@ -334,78 +396,6 @@ cubes:
334396
sql: "{CUBE.price_usd}"
335397
336398
337-
- name: source_a
338-
sql: >
339-
SELECT 10 as ID, 'some category' as PRODUCT_CATEGORY, 'some name' as NAME, 100 as PRICE_USD, 0 as PRICE_EUR
340-
union all
341-
SELECT 11 as ID, 'some category' as PRODUCT_CATEGORY, 'some name' as NAME, 500 as PRICE_USD, 0 as PRICE_EUR
342-
union all
343-
SELECT 12 as ID, 'some category A' as PRODUCT_CATEGORY, 'some name' as NAME, 200 as PRICE_USD, 0 as PRICE_EUR
344-
union all
345-
SELECT 13 as ID, 'some category A' as PRODUCT_CATEGORY, 'some name' as NAME, 300 as PRICE_USD, 0 as PRICE_EUR
346-
public: false
347-
348-
dimensions:
349-
- name: pk
350-
type: number
351-
sql: ID
352-
primary_key: true
353-
354-
- name: product_category
355-
sql: PRODUCT_CATEGORY
356-
type: string
357-
358-
measures:
359-
- name: count
360-
type: 'count'
361-
362-
- name: price_usd
363-
type: 'sum'
364-
sql: PRICE_USD
365-
366-
- name: price_eur
367-
type: 'sum'
368-
sql: PRICE_EUR
369-
370-
371-
- name: source_b
372-
sql: >
373-
SELECT 10 as ID, 'some category' as PRODUCT_CATEGORY, 'some name' as NAME, 0 as PRICE_USD, 100 as PRICE_EUR
374-
union all
375-
SELECT 11 as ID, 'some category' as PRODUCT_CATEGORY, 'some name' as NAME, 0 as PRICE_USD, 500 as PRICE_EUR
376-
union all
377-
SELECT 12 as ID, 'some category B' as PRODUCT_CATEGORY, 'some name' as NAME, 0 as PRICE_USD, 200 as PRICE_EUR
378-
union all
379-
SELECT 13 as ID, 'some category B' as PRODUCT_CATEGORY, 'some name' as NAME, 0 as PRICE_USD, 300 as PRICE_EUR
380-
union all
381-
SELECT 14 as ID, 'some category B' as PRODUCT_CATEGORY, 'some name' as NAME, 0 as PRICE_USD, 300 as PRICE_EUR
382-
public: false
383-
384-
dimensions:
385-
- name: pk
386-
type: number
387-
sql: ID
388-
primary_key: true
389-
390-
- name: product_category
391-
sql: PRODUCT_CATEGORY
392-
type: string
393-
394-
measures:
395-
- name: count
396-
type: 'count'
397-
398-
- name: price_usd
399-
type: 'sum'
400-
sql: PRICE_USD
401-
402-
- name: price_eur
403-
type: 'sum'
404-
sql: PRICE_EUR
405-
406-
views:
407-
408-
409399
- name: orders_view
410400
cubes:
411401
- join_path: orders

rust/cubesqlplanner/cubesqlplanner/src/planner/sql_evaluator/collectors/join_hints_collector.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
use crate::cube_bridge::join_hints::JoinHintItem;
2+
use crate::planner::sql_evaluator::collectors::has_multi_stage_members;
23
use crate::planner::sql_evaluator::{MemberSymbol, TraversalVisitor};
34
use cubenativeutils::CubeError;
45
use itertools::Itertools;
@@ -30,12 +31,10 @@ impl TraversalVisitor for JoinHintsCollector {
3031
//We don't add multi stage members childs to join hints
3132
return Ok(None);
3233
}
33-
if !node.owned_by_cube() {
34-
return Ok(Some(()));
35-
}
34+
3635
match node.as_ref() {
3736
MemberSymbol::Dimension(e) => {
38-
if !e.is_view() {
37+
if !e.is_view() && e.dimension_type() != "switch" {
3938
if !path.is_empty() {
4039
if path.len() == 1 {
4140
self.hints.push(JoinHintItem::Single(path[0].clone()))

rust/cubesqlplanner/cubesqlplanner/src/planner/sql_evaluator/symbols/dimension_symbol.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,7 @@ impl SymbolFactory for DimensionSymbolFactory {
436436
let cube = cube_evaluator.cube_from_path(cube_name.clone())?;
437437
let alias =
438438
PlanSqlTemplates::memeber_alias_name(cube.static_data().resolved_alias(), &name, &None);
439-
let is_view = cube.static_data().is_view.unwrap_or(false);
439+
let is_view = cube.static_data().is_view.unwrap_or(false) && is_sql_direct_ref;
440440
let is_calendar = cube.static_data().is_calendar.unwrap_or(false);
441441
let mut is_self_time_shift_pk = false;
442442

rust/cubesqlplanner/cubesqlplanner/src/planner/sql_evaluator/symbols/measure_symbol.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -755,7 +755,7 @@ impl SymbolFactory for MeasureSymbolFactory {
755755
let alias =
756756
PlanSqlTemplates::memeber_alias_name(cube.static_data().resolved_alias(), &name, &None);
757757

758-
let is_view = cube.static_data().is_view.unwrap_or(false);
758+
let is_view = cube.static_data().is_view.unwrap_or(false) && is_sql_is_direct_ref;
759759

760760
let is_reference = is_view
761761
|| (!owned_by_cube

0 commit comments

Comments
 (0)