Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add failing test for #3105 #3116

Closed
wants to merge 1 commit into from
Closed
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
52 changes: 51 additions & 1 deletion datafusion/core/tests/dataframe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
// specific language governing permissions and limitations
// under the License.

use arrow::array::Float64Array;
use arrow::datatypes::{DataType, Field, Schema};
use arrow::{
array::{Int32Array, StringArray},
Expand All @@ -31,7 +32,7 @@ use datafusion::logical_plan::{col, Expr};
use datafusion::prelude::CsvReadOptions;
use datafusion::{datasource::MemTable, prelude::JoinType};
use datafusion_expr::expr::GroupingSet;
use datafusion_expr::{avg, count, lit, sum};
use datafusion_expr::{avg, count, lit, sum, AggregateFunction};

#[tokio::test]
async fn join() -> Result<()> {
Expand Down Expand Up @@ -424,3 +425,52 @@ async fn aggregates_table(ctx: &SessionContext) -> Result<Arc<DataFrame>> {
)
.await
}

#[tokio::test]
async fn exact_median() -> Result<()> {
let schema = Schema::new(vec![
Field::new("a", DataType::Int32, true),
Field::new("b", DataType::Float64, true),
]);

let batch = RecordBatch::try_new(
Arc::new(schema.clone()),
vec![
Arc::new(Int32Array::from_slice(&[1, 1, 1, 1])),
Arc::new(Float64Array::from_slice(&[10.0, 0.0, 20.0, 100.0])),
],
)
.unwrap();

let ctx = SessionContext::new();
let provider = MemTable::try_new(Arc::new(schema), vec![vec![batch]]).unwrap();
ctx.register_table("t", Arc::new(provider)).unwrap();

let df = ctx
.table("t")
.unwrap()
.aggregate(
vec![col("a")],
vec![Expr::AggregateFunction {
fun: AggregateFunction::Median,
args: vec![col("b")],
distinct: false,
}
.alias("agg")],
)
.unwrap();

let results = df.collect().await.unwrap();

#[rustfmt::skip]
let expected = vec![
"+---+------+",
"| a | agg |",
"+---+------+",
"| 1 | 15.0 |",
"+---+------+",
];
assert_batches_eq!(expected, &results);

Ok(())
}