File tree Expand file tree Collapse file tree 1 file changed +10
-1
lines changed
src/graph/formulas/generators/generic Expand file tree Collapse file tree 1 file changed +10
-1
lines changed Original file line number Diff line number Diff line change @@ -35,6 +35,15 @@ impl CoalesceFormulaBuilder {
3535 /// Generates a formula that uses the `COALESCE` function to return the first
3636 /// non-null value from the provided component IDs.
3737 pub fn build ( self ) -> Result < String , Error > {
38+ if self . component_ids . len ( ) == 1 {
39+ if let Some ( component_id) = self . component_ids . into_iter ( ) . next ( ) {
40+ return Ok ( Expr :: Component { component_id } . to_string ( ) ) ;
41+ } else {
42+ return Err ( Error :: internal (
43+ "Failed to create expression for single component ID." ,
44+ ) ) ;
45+ }
46+ }
3847 let expr = Expr :: coalesce (
3948 self . component_ids
4049 . into_iter ( )
@@ -65,7 +74,7 @@ mod tests {
6574 let formula = graph. coalesce ( BTreeSet :: from ( [ 1 , 2 ] ) ) ?;
6675 assert_eq ! ( formula, "COALESCE(#1, #2)" ) ;
6776 let formula = graph. coalesce ( BTreeSet :: from ( [ 1 ] ) ) ?;
68- assert_eq ! ( formula, "COALESCE(#1) " ) ;
77+ assert_eq ! ( formula, "#1 " ) ;
6978 let formula = graph. coalesce ( BTreeSet :: from ( [ ] ) ) ;
7079 assert_eq ! (
7180 formula,
You can’t perform that action at this time.
0 commit comments