korowa commented on code in PR #4852:
URL: https://github.com/apache/arrow-datafusion/pull/4852#discussion_r1064191660


##########
datafusion/physical-expr/src/aggregate/covariance.rs:
##########
@@ -253,33 +253,33 @@ impl Accumulator for CovarianceAccumulator {
         let mut arr1 = downcast_value!(values1, Float64Array).iter().flatten();
         let mut arr2 = downcast_value!(values2, Float64Array).iter().flatten();
 
-        for _i in 0..values1.len() {
-            let value1 = arr1.next();
-            let value2 = arr2.next();
+        for i in 0..values1.len() {
+            let value1 = match values1.is_valid(i) {
+                true => arr1.next(),
+                false => None,
+            };
+            let value2 = match values2.is_valid(i) {
+                true => arr2.next(),
+                false => None,
+            };
 
             if value1.is_none() || value2.is_none() {
-                if value1.is_none() && value2.is_none() {
-                    continue;
-                } else {
-                    return Err(DataFusionError::Internal(
-                        "The two columns are not aligned".to_string(),
-                    ));
-                }
-            } else {
-                let value1 = unwrap_or_internal_err!(value1);
-                let value2 = unwrap_or_internal_err!(value2);
-                let new_count = self.count + 1;
-                let delta1 = value1 - self.mean1;
-                let new_mean1 = delta1 / new_count as f64 + self.mean1;
-                let delta2 = value2 - self.mean2;
-                let new_mean2 = delta2 / new_count as f64 + self.mean2;
-                let new_c = delta1 * (value2 - new_mean2) + self.algo_const;
-
-                self.count += 1;
-                self.mean1 = new_mean1;
-                self.mean2 = new_mean2;
-                self.algo_const = new_c;
+                continue;
             }
+
+            let value1 = unwrap_or_internal_err!(value1);
+            let value2 = unwrap_or_internal_err!(value2);

Review Comment:
   Looks cleaner, and it seems we dont need this macro anymore



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to