Skip to content

Commit b1774b5

Browse files
committed
update measure symbol to support named time shifts
1 parent aa5599e commit b1774b5

File tree

1 file changed

+19
-1
lines changed
  • rust/cubesqlplanner/cubesqlplanner/src/planner/sql_evaluator/symbols

1 file changed

+19
-1
lines changed

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

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -570,6 +570,7 @@ impl SymbolFactory for MeasureSymbolFactory {
570570
{
571571
let mut shifts: HashMap<String, DimensionTimeShift> = HashMap::new();
572572
let mut common_shift = None;
573+
let mut named_shift = None;
573574
for shift_ref in time_shift_references.iter() {
574575
let interval = match &shift_ref.interval {
575576
Some(raw) => {
@@ -604,6 +605,16 @@ impl SymbolFactory for MeasureSymbolFactory {
604605
},
605606
);
606607
};
608+
} else if let Some(name) = &shift_ref.name {
609+
if named_shift.is_none() {
610+
named_shift = Some(name.clone());
611+
} else {
612+
if named_shift != Some(name.clone()) {
613+
return Err(CubeError::user(format!(
614+
"Measure can contain only one named time_shift (without time_dimension).",
615+
)));
616+
}
617+
}
607618
} else {
608619
if common_shift.is_none() {
609620
common_shift = interval;
@@ -616,12 +627,19 @@ impl SymbolFactory for MeasureSymbolFactory {
616627
}
617628
}
618629
}
619-
if common_shift.is_some() && !shifts.is_empty() {
630+
631+
if (common_shift.is_some() || named_shift.is_some()) && !shifts.is_empty() {
620632
return Err(CubeError::user(format!(
621633
"Measure cannot mix common time_shifts (without time_dimension) with dimension-specific ones.",
622634
)));
635+
} else if common_shift.is_some() && named_shift.is_some() {
636+
return Err(CubeError::user(format!(
637+
"Measure cannot mix common unnamed and named time_shifts.",
638+
)));
623639
} else if common_shift.is_some() {
624640
Some(MeasureTimeShifts::Common(common_shift.unwrap()))
641+
} else if named_shift.is_some() {
642+
Some(MeasureTimeShifts::Named(named_shift.unwrap()))
625643
} else {
626644
Some(MeasureTimeShifts::Dimensions(
627645
shifts.into_values().collect_vec(),

0 commit comments

Comments
 (0)