Jimexist commented on a change in pull request #558:
URL: https://github.com/apache/arrow-datafusion/pull/558#discussion_r654784583
##########
File path: datafusion/src/execution/context.rs
##########
@@ -1355,6 +1355,90 @@ mod tests {
Ok(())
}
+ #[tokio::test]
+ async fn window_partition_by() -> Result<()> {
+ let results = execute(
+ "SELECT \
+ c1, \
+ c2, \
+ SUM(c2) OVER (PARTITION BY c2), \
+ COUNT(c2) OVER (PARTITION BY c2), \
+ MAX(c2) OVER (PARTITION BY c2), \
+ MIN(c2) OVER (PARTITION BY c2), \
+ AVG(c2) OVER (PARTITION BY c2) \
+ FROM test \
+ ORDER BY c1, c2 \
+ LIMIT 5",
+ 4,
+ )
+ .await?;
+ dbg!(results.len());
+ // result in one batch, although e.g. having 2 batches do not change
+ // result semantics, having a len=1 assertion upfront keeps surprises
+ // at bay
+ assert_eq!(results.len(), 1);
Review comment:
fixed
##########
File path: datafusion/src/execution/context.rs
##########
@@ -1355,6 +1355,90 @@ mod tests {
Ok(())
}
+ #[tokio::test]
+ async fn window_partition_by() -> Result<()> {
+ let results = execute(
+ "SELECT \
+ c1, \
+ c2, \
+ SUM(c2) OVER (PARTITION BY c2), \
+ COUNT(c2) OVER (PARTITION BY c2), \
+ MAX(c2) OVER (PARTITION BY c2), \
+ MIN(c2) OVER (PARTITION BY c2), \
+ AVG(c2) OVER (PARTITION BY c2) \
+ FROM test \
+ ORDER BY c1, c2 \
+ LIMIT 5",
+ 4,
+ )
+ .await?;
+ dbg!(results.len());
+ // result in one batch, although e.g. having 2 batches do not change
+ // result semantics, having a len=1 assertion upfront keeps surprises
+ // at bay
+ assert_eq!(results.len(), 1);
+
+ let expected = vec![
+ "+----+----+---------+-----------+---------+---------+---------+",
+ "| c1 | c2 | SUM(c2) | COUNT(c2) | MAX(c2) | MIN(c2) | AVG(c2) |",
+ "+----+----+---------+-----------+---------+---------+---------+",
+ "| 0 | 1 | 4 | 4 | 1 | 1 | 1 |",
+ "| 0 | 2 | 8 | 4 | 2 | 2 | 2 |",
+ "| 0 | 3 | 12 | 4 | 3 | 3 | 3 |",
+ "| 0 | 4 | 16 | 4 | 4 | 4 | 4 |",
+ "| 0 | 5 | 20 | 4 | 5 | 5 | 5 |",
+ "+----+----+---------+-----------+---------+---------+---------+",
+ ];
+
+ // window function shall respect ordering
+ assert_batches_eq!(expected, &results);
+ Ok(())
+ }
+
+ #[tokio::test]
+ async fn window_partition_by_order_by() -> Result<()> {
+ let results = execute(
+ "SELECT \
+ c1, \
+ c2, \
+ ROW_NUMBER() OVER (PARTITION BY c2 ORDER BY c1), \
+ FIRST_VALUE(c2 + c1) OVER (PARTITION BY c2 ORDER BY c1), \
+ LAST_VALUE(c2 + c1) OVER (PARTITION BY c2 ORDER BY c1), \
+ NTH_VALUE(c2 + c1, 2) OVER (PARTITION BY c2 ORDER BY c1), \
+ SUM(c2) OVER (PARTITION BY c2 ORDER BY c1), \
+ COUNT(c2) OVER (PARTITION BY c2 ORDER BY c1), \
+ MAX(c2) OVER (PARTITION BY c2 ORDER BY c1), \
+ MIN(c2) OVER (PARTITION BY c2 ORDER BY c1), \
+ AVG(c2) OVER (PARTITION BY c2 ORDER BY c1) \
+ FROM test \
+ ORDER BY c1, c2 \
+ LIMIT 5",
+ 4,
+ )
+ .await?;
+ dbg!(results.len());
+ // result in one batch, although e.g. having 2 batches do not change
+ // result semantics, having a len=1 assertion upfront keeps surprises
+ // at bay
+ assert_eq!(results.len(), 1);
Review comment:
fixed
--
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.
For queries about this service, please contact Infrastructure at:
[email protected]