@@ -43,6 +43,9 @@ pub struct DimensionSymbol {
4343 is_view : bool ,
4444 time_shift : Vec < CalendarDimensionTimeShift > ,
4545 time_shift_pk : Option < Rc < MemberSymbol > > ,
46+ is_self_time_shift_pk : bool , // If the dimension itself is a primary key and has time shifts,
47+ // we can not reevaluate itself again while processing time shifts
48+ // to avoid infinite recursion. So we raise this flag instead.
4649}
4750
4851impl DimensionSymbol {
@@ -58,6 +61,7 @@ impl DimensionSymbol {
5861 definition : Rc < dyn DimensionDefinition > ,
5962 time_shift : Vec < CalendarDimensionTimeShift > ,
6063 time_shift_pk : Option < Rc < MemberSymbol > > ,
64+ is_self_time_shift_pk : bool ,
6165 ) -> Rc < Self > {
6266 Rc :: new ( Self {
6367 cube_name,
@@ -71,6 +75,7 @@ impl DimensionSymbol {
7175 is_view,
7276 time_shift,
7377 time_shift_pk,
78+ is_self_time_shift_pk,
7479 } )
7580 }
7681
@@ -236,6 +241,8 @@ impl DimensionSymbol {
236241 {
237242 if let Some ( pk) = & self . time_shift_pk {
238243 return Some ( ( pk. full_name ( ) , ts. clone ( ) ) ) ;
244+ } else if self . is_self_time_shift_pk {
245+ return Some ( ( self . full_name ( ) , ts. clone ( ) ) ) ;
239246 }
240247 }
241248 None
@@ -383,6 +390,7 @@ impl SymbolFactory for DimensionSymbolFactory {
383390 let cube = cube_evaluator. cube_from_path ( cube_name. clone ( ) ) ?;
384391 let is_view = cube. static_data ( ) . is_view . unwrap_or ( false ) ;
385392 let is_calendar = cube. static_data ( ) . is_calendar . unwrap_or ( false ) ;
393+ let mut is_self_time_shift_pk = false ;
386394
387395 // If the cube is a calendar, we need to find the primary key member
388396 // so that we can use it for time shifts processing.
@@ -395,7 +403,10 @@ impl SymbolFactory for DimensionSymbolFactory {
395403 . unwrap_or_else ( || vec ! [ ] ) ;
396404
397405 if pk_members. iter ( ) . any ( |pk| * * pk == name) {
398- // To avoid evaluation loop.
406+ is_self_time_shift_pk = true ;
407+ // If the dimension itself is a primary key and has time shifts,
408+ // we can not reevaluate itself again as this will lead
409+ // to infinite recursion. So we raise this flag instead.
399410 None
400411 } else {
401412 let pk_member = pk_members
@@ -450,6 +461,7 @@ impl SymbolFactory for DimensionSymbolFactory {
450461 definition,
451462 time_shift,
452463 time_shift_pk,
464+ is_self_time_shift_pk,
453465 ) ) )
454466 }
455467}
0 commit comments