@@ -380,40 +380,52 @@ impl SymbolFactory for DimensionSymbolFactory {
380380 vec ! [ ]
381381 } ;
382382
383- let time_shift_pk = if !time_shift. is_empty ( ) {
384- let pk_member = cube_evaluator
383+ let cube = cube_evaluator. cube_from_path ( cube_name. clone ( ) ) ?;
384+ let is_view = cube. static_data ( ) . is_view . unwrap_or ( false ) ;
385+ let is_calendar = cube. static_data ( ) . is_calendar . unwrap_or ( false ) ;
386+
387+ // If the cube is a calendar, we need to find the primary key member
388+ // so that we can use it for time shifts processing.
389+ let time_shift_pk = if is_calendar {
390+ let pk_members = cube_evaluator
385391 . static_data ( )
386392 . primary_keys
387393 . get ( & cube_name)
388394 . cloned ( )
389- . unwrap_or_else ( || vec ! [ ] )
390- . into_iter ( )
391- . map ( |primary_key| -> Result < _ , CubeError > {
392- let key_dimension_name = format ! ( "{}.{}" , cube_name, primary_key) ;
393- let pk_member = compiler. add_dimension_evaluator ( key_dimension_name) ?;
395+ . unwrap_or_else ( || vec ! [ ] ) ;
394396
395- Ok ( pk_member)
396- } )
397- . collect :: < Result < Vec < _ > , _ > > ( ) ?
398- . into_iter ( )
399- . filter ( |pk_member| {
400- if let Ok ( pk_dimension) = pk_member. as_dimension ( ) {
401- if pk_dimension. dimension_type ( ) == "time" { // TODO: What if calendar cube is joined via non-time dimension?
402- return true ;
397+ if pk_members. iter ( ) . any ( |pk| * * pk == name) {
398+ // To avoid evaluation loop.
399+ None
400+ } else {
401+ let pk_member = pk_members
402+ . into_iter ( )
403+ . map ( |primary_key| -> Result < _ , CubeError > {
404+ let key_dimension_name = format ! ( "{}.{}" , cube_name, primary_key) ;
405+ let pk_member = compiler. add_dimension_evaluator ( key_dimension_name) ?;
406+
407+ Ok ( pk_member)
408+ } )
409+ . collect :: < Result < Vec < _ > , _ > > ( ) ?
410+ . into_iter ( )
411+ . filter ( |pk_member| {
412+ if let Ok ( pk_dimension) = pk_member. as_dimension ( ) {
413+ // TODO: What if calendar cube is joined via non-time dimension?
414+ if pk_dimension. dimension_type ( ) == "time" {
415+ return true ;
416+ }
403417 }
404- }
405- false
406- } )
407- . collect :: < Vec < _ > > ( )
408- . first ( )
409- . cloned ( ) ;
410- pk_member
418+ false
419+ } )
420+ . collect :: < Vec < _ > > ( )
421+ . first ( )
422+ . cloned ( ) ;
423+ pk_member
424+ }
411425 } else {
412426 None
413427 } ;
414428
415- let cube = cube_evaluator. cube_from_path ( cube_name. clone ( ) ) ?;
416- let is_view = cube. static_data ( ) . is_view . unwrap_or ( false ) ;
417429 let owned_by_cube = definition. static_data ( ) . owned_by_cube . unwrap_or ( true ) ;
418430 let is_sub_query = definition. static_data ( ) . sub_query . unwrap_or ( false ) ;
419431 let is_multi_stage = definition. static_data ( ) . multi_stage . unwrap_or ( false ) ;
0 commit comments