Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion src/graph/formulas/generators/generic/coalesce.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,15 @@ impl CoalesceFormulaBuilder {
/// Generates a formula that uses the `COALESCE` function to return the first
/// non-null value from the provided component IDs.
pub fn build(self) -> Result<String, Error> {
if self.component_ids.len() == 1 {
if let Some(component_id) = self.component_ids.into_iter().next() {
return Ok(Expr::Component { component_id }.to_string());
} else {
return Err(Error::internal(
"Failed to create expression for single component ID.",
));
}
}
let expr = Expr::coalesce(
self.component_ids
.into_iter()
Expand Down Expand Up @@ -65,7 +74,7 @@ mod tests {
let formula = graph.coalesce(BTreeSet::from([1, 2]))?;
assert_eq!(formula, "COALESCE(#1, #2)");
let formula = graph.coalesce(BTreeSet::from([1]))?;
assert_eq!(formula, "COALESCE(#1)");
assert_eq!(formula, "#1");
let formula = graph.coalesce(BTreeSet::from([]));
assert_eq!(
formula,
Expand Down
Loading