alamb commented on code in PR #16933:
URL: https://github.com/apache/datafusion/pull/16933#discussion_r2277174123
##########
datafusion/sql/tests/sql_integration.rs:
##########
@@ -4186,6 +4187,47 @@ fn test_select_distinct_order_by() {
);
}
+#[test]
+fn test_select_qualify_basic() {
+ let sql = "SELECT person.id, ROW_NUMBER() OVER (PARTITION BY person.age
ORDER BY person.id) as rn FROM person QUALIFY rn = 1";
+ let plan = logical_plan(sql).unwrap();
+ assert_snapshot!(
+ plan,
+ @r#"
+Projection: person.id, row_number() PARTITION BY [person.age] ORDER BY
[person.id ASC NULLS LAST] RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW AS
rn
+ Filter: row_number() PARTITION BY [person.age] ORDER BY [person.id ASC NULLS
LAST] RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW = Int64(1)
+ WindowAggr: windowExpr=[[row_number() PARTITION BY [person.age] ORDER BY
[person.id ASC NULLS LAST] RANGE BETWEEN UNBOUNDED PRECEDING AND CURRENT ROW]]
+ TableScan: person
+"#
+ );
+}
+
+#[test]
+fn test_select_qualify_without_window_function() {
+ let sql = "SELECT person.id FROM person QUALIFY person.id > 1";
+ let err = logical_plan(sql).unwrap_err();
+ assert_eq!(
+ err.strip_backtrace(),
+ "Error during planning: QUALIFY clause requires window functions in
the SELECT list or QUALIFY clause"
Review Comment:
I verified that this is consistent with the DuckDB behavior:
```sql
D SELECT person.id FROM person QUALIFY person.id > 1;
Binder Error:
at least one window function must appear in the SELECT column or QUALIFY
clause
```
--
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]