Skip to content
Merged
Show file tree
Hide file tree
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
127 changes: 0 additions & 127 deletions datafusion/physical-expr/src/aggregate/stddev.rs
Original file line number Diff line number Diff line change
Expand Up @@ -245,135 +245,8 @@ mod tests {
use super::*;
use crate::aggregate::utils::get_accum_scalar_values_as_arrays;
use crate::expressions::col;
use crate::expressions::tests::aggregate;
use crate::generic_test_op;
use arrow::{array::*, datatypes::*};

#[test]
fn stddev_f64_1() -> Result<()> {
let a: ArrayRef = Arc::new(Float64Array::from(vec![1_f64, 2_f64]));
generic_test_op!(a, DataType::Float64, StddevPop, ScalarValue::from(0.5_f64))
}

#[test]
fn stddev_f64_2() -> Result<()> {
let a: ArrayRef = Arc::new(Float64Array::from(vec![1.1_f64, 2_f64, 3_f64]));
generic_test_op!(
a,
DataType::Float64,
StddevPop,
ScalarValue::from(0.7760297817881877_f64)
)
}

#[test]
fn stddev_f64_3() -> Result<()> {
let a: ArrayRef =
Arc::new(Float64Array::from(vec![1_f64, 2_f64, 3_f64, 4_f64, 5_f64]));
generic_test_op!(
a,
DataType::Float64,
StddevPop,
ScalarValue::from(std::f64::consts::SQRT_2)
)
}

#[test]
fn stddev_f64_4() -> Result<()> {
let a: ArrayRef = Arc::new(Float64Array::from(vec![1.1_f64, 2_f64, 3_f64]));
generic_test_op!(
a,
DataType::Float64,
Stddev,
ScalarValue::from(0.9504384952922168_f64)
)
}

#[test]
fn stddev_i32() -> Result<()> {
let a: ArrayRef = Arc::new(Int32Array::from(vec![1, 2, 3, 4, 5]));
generic_test_op!(
a,
DataType::Int32,
StddevPop,
ScalarValue::from(std::f64::consts::SQRT_2)
)
}

#[test]
fn stddev_u32() -> Result<()> {
let a: ArrayRef =
Arc::new(UInt32Array::from(vec![1_u32, 2_u32, 3_u32, 4_u32, 5_u32]));
generic_test_op!(
a,
DataType::UInt32,
StddevPop,
ScalarValue::from(std::f64::consts::SQRT_2)
)
}

#[test]
fn stddev_f32() -> Result<()> {
let a: ArrayRef =
Arc::new(Float32Array::from(vec![1_f32, 2_f32, 3_f32, 4_f32, 5_f32]));
generic_test_op!(
a,
DataType::Float32,
StddevPop,
ScalarValue::from(std::f64::consts::SQRT_2)
)
}

#[test]
fn test_stddev_1_input() -> Result<()> {
let a: ArrayRef = Arc::new(Float64Array::from(vec![1_f64]));
let schema = Schema::new(vec![Field::new("a", DataType::Float64, false)]);
let batch = RecordBatch::try_new(Arc::new(schema.clone()), vec![a])?;

let agg = Arc::new(Stddev::new(
col("a", &schema)?,
"bla".to_string(),
DataType::Float64,
));
let actual = aggregate(&batch, agg).unwrap();
assert_eq!(actual, ScalarValue::Float64(None));

Ok(())
}

#[test]
fn stddev_i32_with_nulls() -> Result<()> {
let a: ArrayRef = Arc::new(Int32Array::from(vec![
Some(1),
None,
Some(3),
Some(4),
Some(5),
]));
generic_test_op!(
a,
DataType::Int32,
StddevPop,
ScalarValue::from(1.479019945774904_f64)
)
}

#[test]
fn stddev_i32_all_nulls() -> Result<()> {
let a: ArrayRef = Arc::new(Int32Array::from(vec![None, None]));
let schema = Schema::new(vec![Field::new("a", DataType::Int32, true)]);
let batch = RecordBatch::try_new(Arc::new(schema.clone()), vec![a])?;

let agg = Arc::new(Stddev::new(
col("a", &schema)?,
"bla".to_string(),
DataType::Float64,
));
let actual = aggregate(&batch, agg).unwrap();
assert_eq!(actual, ScalarValue::Float64(None));
Ok(())
}

#[test]
fn stddev_f64_merge_1() -> Result<()> {
let a = Arc::new(Float64Array::from(vec![1_f64, 2_f64, 3_f64]));
Expand Down
122 changes: 122 additions & 0 deletions datafusion/sqllogictest/test_files/aggregate.slt
Original file line number Diff line number Diff line change
Expand Up @@ -2338,6 +2338,128 @@ select covar_pop(c1, c2), arrow_typeof(covar_pop(c1, c2)) from t;
statement ok
drop table t;

# aggregate stddev f64_1
statement ok
create table t (c1 double) as values (1), (2);

query RT
select stddev_pop(c1), arrow_typeof(stddev_pop(c1)) from t;
----
0.5 Float64

statement ok
drop table t;

# aggregate stddev f64_2
statement ok
create table t (c1 double) as values (1.1), (2), (3);

query RT
select stddev_pop(c1), arrow_typeof(stddev_pop(c1)) from t;
----
0.776029781788 Float64

statement ok
drop table t;

# aggregate stddev f64_3
statement ok
create table t (c1 double) as values (1), (2), (3), (4), (5);

query RT
select stddev_pop(c1), arrow_typeof(stddev_pop(c1)) from t;
----
1.414213562373 Float64

statement ok
drop table t;

# aggregate stddev f64_4
statement ok
create table t (c1 double) as values (1.1), (2), (3);

query RT
select stddev(c1), arrow_typeof(stddev(c1)) from t;
----
0.950438495292 Float64

statement ok
drop table t;

# aggregate stddev i32
statement ok
create table t (c1 int) as values (1), (2), (3), (4), (5);

query RT
select stddev_pop(c1), arrow_typeof(stddev_pop(c1)) from t;
----
1.414213562373 Float64

statement ok
drop table t;

# aggregate stddev u32
statement ok
create table t (c1 int unsigned) as values (1), (2), (3), (4), (5);

query RT
select stddev_pop(c1), arrow_typeof(stddev_pop(c1)) from t;
----
1.414213562373 Float64

statement ok
drop table t;

# aggregate stddev f32
statement ok
create table t (c1 float) as values (1), (2), (3), (4), (5);

query RT
select stddev_pop(c1), arrow_typeof(stddev_pop(c1)) from t;
----
1.414213562373 Float64

statement ok
drop table t;

# aggregate stddev single_input
statement ok
create table t (c1 double) as values (1);

query RT
select stddev_pop(c1), arrow_typeof(stddev_pop(c1)) from t;
----
0 Float64

statement ok
drop table t;

# aggregate stddev with_nulls
statement ok
create table t (c1 int) as values (1), (null), (3), (4), (5);

query RT
select stddev_pop(c1), arrow_typeof(stddev_pop(c1)) from t;
----
1.479019945775 Float64

statement ok
drop table t;

# aggregate stddev all_nulls
statement ok
create table t (c1 int) as values (null), (null);

query RT
select stddev_pop(c1), arrow_typeof(stddev_pop(c1)) from t;
----
NULL Float64

statement ok
drop table t;



# simple_mean
query R
select mean(c1) from test
Expand Down