Skip to content

Commit ec3a384

Browse files
committed
Add window tests to AbstractTestQueries regarding partitioning and ordering
1 parent d820ce5 commit ec3a384

1 file changed

Lines changed: 73 additions & 0 deletions

File tree

presto-tests/src/main/java/com/facebook/presto/tests/AbstractTestQueries.java

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3350,6 +3350,79 @@ public void testWindowImplicitCoercion()
33503350
assertEquals(actual, expected);
33513351
}
33523352

3353+
@Test
3354+
public void testWindowsSameOrdering()
3355+
throws Exception
3356+
{
3357+
MaterializedResult actual = computeActual("SELECT " +
3358+
"sum(quantity) OVER(PARTITION BY suppkey ORDER BY orderkey) q," +
3359+
"min(tax) OVER(PARTITION BY suppkey ORDER BY shipdate) m " +
3360+
"FROM lineitem ORDER BY q LIMIT 3");
3361+
3362+
MaterializedResult expected = resultBuilder(getSession(), DOUBLE, DOUBLE)
3363+
.row(1.0, 0.0)
3364+
.row(2.0, 0.0)
3365+
.row(2.0, 0.0)
3366+
.build();
3367+
3368+
assertEquals(actual, expected);
3369+
}
3370+
3371+
@Test
3372+
public void testWindowsPrefixPartitioning()
3373+
throws Exception
3374+
{
3375+
MaterializedResult actual = computeActual("SELECT " +
3376+
"min(discount) OVER(PARTITION BY suppkey, tax ORDER BY receiptdate) d," +
3377+
"avg(quantity) OVER(PARTITION BY suppkey ORDER BY orderkey) q " +
3378+
"FROM lineitem ORDER BY q LIMIT 3");
3379+
3380+
MaterializedResult expected = resultBuilder(getSession(), DOUBLE, DOUBLE)
3381+
.row(0.0, 1.0)
3382+
.row(0.0, 2.0)
3383+
.row(0.0, 2.0)
3384+
.build();
3385+
3386+
assertEquals(actual, expected);
3387+
}
3388+
3389+
@Test
3390+
public void testWindowsDifferentPartitions()
3391+
throws Exception
3392+
{
3393+
MaterializedResult actual = computeActual("SELECT " +
3394+
"sum(quantity) OVER(PARTITION BY suppkey ORDER BY orderkey) q," +
3395+
"avg(discount) OVER(PARTITION BY partkey ORDER BY receiptdate) d," +
3396+
"min(tax) OVER(PARTITION BY suppkey, tax ORDER BY receiptdate) t " +
3397+
"FROM lineitem ORDER BY q,d LIMIT 3");
3398+
3399+
MaterializedResult expected = resultBuilder(getSession(), DOUBLE, DOUBLE, DOUBLE)
3400+
.row(1.0, 0.038, 0.06)
3401+
.row(2.0, 0.0225, 0.06)
3402+
.row(2.0, 0.06, 0.02)
3403+
.build();
3404+
3405+
assertEquals(actual, expected);
3406+
}
3407+
3408+
@Test
3409+
public void testWindowsConstantExpression()
3410+
throws Exception
3411+
{
3412+
MaterializedResult actual = computeActual("SELECT " +
3413+
"sum(quantity) OVER (PARTITION BY suppkey ORDER BY receiptdate) q," +
3414+
"lag(tax, 1) OVER (PARTITION BY suppkey ORDER BY orderkey) t " +
3415+
"FROM lineitem ORDER BY q,t LIMIT 3");
3416+
3417+
MaterializedResult expected = resultBuilder(getSession(), DOUBLE, DOUBLE)
3418+
.row(1.0, 0.03)
3419+
.row(2.0, 0.07)
3420+
.row(5.0, 0.0)
3421+
.build();
3422+
3423+
assertEquals(actual, expected);
3424+
}
3425+
33533426
@Test
33543427
public void testHaving()
33553428
throws Exception

0 commit comments

Comments
 (0)