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

Function window_using_aggregates

datafusion/core/tests/dataframe/mod.rs:1150–1233  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1148
1149#[tokio::test]
1150async fn window_using_aggregates() -> Result<()> {
1151 // build plan using DataFrame API
1152 let df = test_table().await?.filter(col("c1").eq(lit("a")))?;
1153 let mut aggr_expr = vec![
1154 (
1155 datafusion_functions_aggregate::first_last::first_value_udaf(),
1156 "first_value",
1157 ),
1158 (
1159 datafusion_functions_aggregate::first_last::last_value_udaf(),
1160 "last_val",
1161 ),
1162 (
1163 datafusion_functions_aggregate::approx_distinct::approx_distinct_udaf(),
1164 "approx_distinct",
1165 ),
1166 (
1167 datafusion_functions_aggregate::approx_median::approx_median_udaf(),
1168 "approx_median",
1169 ),
1170 (
1171 datafusion_functions_aggregate::median::median_udaf(),
1172 "median",
1173 ),
1174 (datafusion_functions_aggregate::min_max::max_udaf(), "max"),
1175 (datafusion_functions_aggregate::min_max::min_udaf(), "min"),
1176 ]
1177 .into_iter()
1178 .map(|(func, name)| {
1179 let w = WindowFunction::new(
1180 WindowFunctionDefinition::AggregateUDF(func),
1181 vec![col("c3")],
1182 );
1183
1184 Expr::from(w)
1185 .null_treatment(NullTreatment::IgnoreNulls)
1186 .order_by(vec![col("c2").sort(true, true), col("c3").sort(true, true)])
1187 .window_frame(WindowFrame::new_bounds(
1188 WindowFrameUnits::Rows,
1189 WindowFrameBound::Preceding(ScalarValue::UInt64(None)),
1190 WindowFrameBound::Preceding(ScalarValue::UInt64(Some(1))),
1191 ))
1192 .build()
1193 .unwrap()
1194 .alias(name)
1195 })
1196 .collect::<Vec<_>>();
1197 aggr_expr.extend_from_slice(&[col("c2"), col("c3")]);
1198
1199 let df: Vec<RecordBatch> = df.select(aggr_expr)?.collect().await?;
1200
1201 assert_snapshot!(
1202 batches_to_sort_string(&df),
1203 @r"
1204 +-------------+----------+-----------------+---------------+--------+-----+------+----+------+
1205 | first_value | last_val | approx_distinct | approx_median | median | max | min | c2 | c3 |
1206 +-------------+----------+-----------------+---------------+--------+-----+------+----+------+
1207 | | | | | | | | 1 | -85 |

Callers

nothing calls this directly

Calls 15

test_tableFunction · 0.85
newFunction · 0.85
AggregateUDFClass · 0.85
window_frameMethod · 0.80
null_treatmentMethod · 0.80
collectMethod · 0.80
colFunction · 0.50
litFunction · 0.50
filterMethod · 0.45
eqMethod · 0.45
mapMethod · 0.45
into_iterMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…