-- | A helper function in raggCount that implements the basic fold for Count aggregation        
countFold :: ColumnName -> ColumnName -> RTable -> RDataType
countFold src trg rtab =         
    V.foldr' ( \rtup accValue ->                                                                     
                            --if (getRTupColValue src) rtup /= Null && accValue /= Null
                            if (isNotNull $ (getRTupColValue src) rtup)  && (isNotNull accValue)  
                                then
                                    RInt 1 + accValue
                                else
                                    --if (getRTupColValue src) rtup == Null && accValue /= Null 
                                    if (isNull $ (getRTupColValue src) rtup) && (isNotNull accValue)  
                                        then
                                            accValue  -- ignore Null value
                                        else
                                            --if (getRTupColValue src) rtup /= Null && accValue == Null 
                                            if (isNotNull $ (getRTupColValue src) rtup) && (isNull accValue)
                                                then
                                                    RInt 1  -- ignore so far Null agg result
                                                else
                                                    Null -- agg of Nulls is Null
             ) (Null) rtab
countFold :: ColumnName -> ColumnName -> RTable -> RDataType
countFold src trg rtab =         
    V.foldr' ( \rtup accValue ->                                                                     
                            --if (getRTupColValue src) rtup /= Null && accValue /= Null
                            if (isNotNull $ (getRTupColValue src) rtup)  && (isNotNull accValue)  
                                then
                                    RInt 1 + accValue
                                else
                                    --if (getRTupColValue src) rtup == Null && accValue /= Null 
                                    if (isNull $ (getRTupColValue src) rtup) && (isNotNull accValue)  
                                        then
                                            accValue  -- ignore Null value
                                        else
                                            --if (getRTupColValue src) rtup /= Null && accValue == Null 
                                            if (isNotNull $ (getRTupColValue src) rtup) && (isNull accValue)
                                                then
                                                    RInt 1  -- ignore so far Null agg result
                                                else
                                                    Null -- agg of Nulls is Null
             ) (Null) rtab
countFold src trg rtab =         
    V.foldr' ( \rtup accValue ->                                                                     
                            --if (getRTupColValue src) rtup /= Null && accValue /= Null
                            if (isNotNull $ (getRTupColValue src) rtup)  && (isNotNull accValue)  
                                then
                                    RInt 1 + accValue
                                else
                                    --if (getRTupColValue src) rtup == Null && accValue /= Null 
                                    if (isNull $ (getRTupColValue src) rtup) && (isNotNull accValue)  
                                        then
                                            accValue  -- ignore Null value
                                        else
                                            --if (getRTupColValue src) rtup /= Null && accValue == Null 
                                            if (isNotNull $ (getRTupColValue src) rtup) && (isNull accValue)
                                                then
                                                    RInt 1  -- ignore so far Null agg result
                                                else
                                                    Null -- agg of Nulls is Null
             ) (Null) rtab