MCPcopy Create free account
hub / github.com/apache/datafusion / evaluate

Method evaluate

datafusion/functions-aggregate/src/correlation.rs:192–223  ·  view source on GitHub ↗
(&mut self)

Source from the content-addressed store, hash-verified

190 }
191
192 fn evaluate(&mut self) -> Result<ScalarValue> {
193 let covar = self.covar.evaluate()?;
194 let stddev1 = self.stddev1.evaluate()?;
195 let stddev2 = self.stddev2.evaluate()?;
196
197 // First check if we have NaN values by examining the internal state
198 // This handles the case where both inputs are NaN even with count=1
199 let mean1 = self.covar.get_mean1();
200 let mean2 = self.covar.get_mean2();
201
202 // If both means are NaN, then both input columns contain only NaN values
203 if mean1.is_nan() && mean2.is_nan() {
204 return Ok(ScalarValue::Float64(Some(f64::NAN)));
205 }
206 let n = self.covar.get_count();
207 if mean1.is_nan() || mean2.is_nan() || n < 2 {
208 return Ok(ScalarValue::Float64(None));
209 }
210
211 if let ScalarValue::Float64(Some(c)) = covar
212 && let ScalarValue::Float64(Some(s1)) = stddev1
213 && let ScalarValue::Float64(Some(s2)) = stddev2
214 {
215 if s1 == 0_f64 || s2 == 0_f64 {
216 return Ok(ScalarValue::Float64(None));
217 } else {
218 return Ok(ScalarValue::Float64(Some(c / s1 / s2)));
219 }
220 }
221
222 Ok(ScalarValue::Float64(None))
223 }
224
225 fn size(&self) -> usize {
226 size_of_val(self) - size_of_val(&self.covar) + self.covar.size()

Callers

nothing calls this directly

Calls 10

newFunction · 0.85
get_mean1Method · 0.80
get_mean2Method · 0.80
take_neededMethod · 0.80
get_countMethod · 0.45
lenMethod · 0.45
pushMethod · 0.45
append_nullMethod · 0.45
intoMethod · 0.45
finishMethod · 0.45

Tested by

no test coverage detected