kosiew commented on code in PR #25475:
URL: https://github.com/apache/datafusion/pull/25475#discussion_r4204726795
##########
datafusion/sql/src/unparser/expr.rs:
##########
@@ -3955,4 +3962,111 @@ mod tests {
"NULL"
);
}
+
+ #[test]
+ fn test_unparse_null_treatment_window_and_aggregate() -> Result<()> {
+ use datafusion_expr::expr::NullTreatment;
+ use datafusion_functions_aggregate::first_last::first_value_udaf;
+ use datafusion_functions_window::nth_value::first_value_udwf;
+
+ // Window function with IgnoreNulls
+ let window_ignore = Expr::from(WindowFunction {
+ fun: WindowFunctionDefinition::WindowUDF(first_value_udwf()),
+ params: WindowFunctionParams {
+ args: vec![col("a")],
+ partition_by: vec![],
+ order_by: vec![Sort::new(col("b"), true, true)],
+ window_frame: WindowFrame::new(None),
+ null_treatment: Some(NullTreatment::IgnoreNulls),
+ distinct: false,
+ filter: None,
+ },
+ });
+
+ // Window function with RespectNulls
+ let window_respect = Expr::from(WindowFunction {
+ fun: WindowFunctionDefinition::WindowUDF(first_value_udwf()),
+ params: WindowFunctionParams {
+ args: vec![col("a")],
+ partition_by: vec![],
+ order_by: vec![Sort::new(col("b"), true, true)],
+ window_frame: WindowFrame::new(None),
+ null_treatment: Some(NullTreatment::RespectNulls),
+ distinct: false,
+ filter: None,
+ },
+ });
+
+ // Window function with None (Control)
+ let window_none = Expr::from(WindowFunction {
+ fun: WindowFunctionDefinition::WindowUDF(first_value_udwf()),
+ params: WindowFunctionParams {
+ args: vec![col("a")],
+ partition_by: vec![],
+ order_by: vec![Sort::new(col("b"), true, true)],
+ window_frame: WindowFrame::new(None),
+ null_treatment: None,
+ distinct: false,
+ filter: None,
+ },
+ });
+
+ // Aggregate function with IgnoreNulls
+ let agg_ignore =
+
Expr::AggregateFunction(datafusion_expr::expr::AggregateFunction::new_udf(
+ first_value_udaf(),
+ vec![col("a")],
+ false,
+ None,
+ vec![],
+ Some(NullTreatment::IgnoreNulls),
+ ));
+
+ // Aggregate function with RespectNulls
+ let agg_respect =
+
Expr::AggregateFunction(datafusion_expr::expr::AggregateFunction::new_udf(
+ first_value_udaf(),
+ vec![col("a")],
+ false,
+ None,
+ vec![],
+ Some(NullTreatment::RespectNulls),
+ ));
+
+ // Aggregate function with None (Control)
+ let agg_none =
+
Expr::AggregateFunction(datafusion_expr::expr::AggregateFunction::new_udf(
+ first_value_udaf(),
+ vec![col("a")],
+ false,
+ None,
+ vec![],
+ None,
+ ));
+
+ let actual_window_ignore = expr_to_sql(&window_ignore)?.to_string();
+ let actual_window_respect = expr_to_sql(&window_respect)?.to_string();
+ let actual_window_none = expr_to_sql(&window_none)?.to_string();
+ let actual_agg_ignore = expr_to_sql(&agg_ignore)?.to_string();
+ let actual_agg_respect = expr_to_sql(&agg_respect)?.to_string();
+ let actual_agg_none = expr_to_sql(&agg_none)?.to_string();
+
+ assert_eq!(
+ actual_window_ignore,
+ "first_value(a) IGNORE NULLS OVER (ORDER BY b ASC NULLS FIRST ROWS
BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING)"
+ );
+ assert_eq!(
+ actual_window_respect,
+ "first_value(a) RESPECT NULLS OVER (ORDER BY b ASC NULLS FIRST
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING)"
+ );
+ assert_eq!(
+ actual_window_none,
+ "first_value(a) OVER (ORDER BY b ASC NULLS FIRST ROWS BETWEEN
UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING)"
+ );
Review Comment:
Optional follow-up: could you add plan-to-SQL round-trip coverage for IGNORE
NULLS and RESPECT NULLS on both window and aggregate FIRST_VALUE? It would be
useful to include an argument-clause form such as `SELECT FIRST_VALUE(id IGNORE
NULLS) OVER (ORDER BY id) AS v FROM person`, then reparse the emitted SQL text
before replanning so the test exercises the full serialization path.
--
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]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]