Add window ranking function tests
*/
package com.facebook.presto.nativeworker;
+import com.google.common.collect.ImmutableList;
import org.testng.annotations.Test;
+import java.util.Arrays;
+import java.util.List;
+
public class TestHiveWindowQueries
extends AbstractTestHiveQueries
{
@@ -23,13 +27,61 @@ public class TestHiveWindowQueries
super(true);
}
+ protected List<String> getRankingQueries(String rankingFunction)
+ {
+ ImmutableList.Builder<String> queries = ImmutableList.builder();
+ List<String> columnProjections = Arrays.asList("orderkey, orderdate, totalprice");
+ List<String> overClauses = Arrays.asList("PARTITION BY orderkey ORDER BY totalprice",
+ "PARTITION BY custkey, orderkey ORDER BY totalprice",
+ "PARTITION BY orderdate ORDER BY orderkey asc, totalprice desc",
+ "PARTITION BY orderkey, orderdate ORDER BY totalprice asc nulls first",
+ "PARTITION BY orderkey, custkey ORDER BY orderdate asc nulls first, totalprice asc, shippriority desc",
+ "PARTITION BY custkey, orderkey, shippriority ORDER BY orderdate, totalprice asc nulls first",
+ "ORDER BY orderdate desc, totalprice asc, shippriority desc nulls first");
+
+ for (String columnProjection : columnProjections) {
+ for (String overClause : overClauses) {
+ queries.add(String.format("SELECT %s, %s OVER (%s) AS rnk FROM orders", columnProjection, rankingFunction, overClause));
+ }
+ }
+ return queries.build();
+ }
+
+ protected void testRankingFunction(String functionName)
+ {
+ List<String> queries = getRankingQueries(functionName);
+ for (String query : queries) {
+ assertQuery(query);
+ }
+ }
+
+ @Test
+ public void testCumeDist()
+ {
+ testRankingFunction("cume_dist()");
+ }
+
+ @Test
+ public void testDenseRank()
+ {
+ testRankingFunction("dense_rank()");
+ }
+
+ @Test
+ public void testPercentRank()
+ {
+ testRankingFunction("percent_rank()");
+ }
+
+ @Test
+ public void testRank()
+ {
+ testRankingFunction("rank()");
+ }
+
@Test
- public void testWindow()
+ public void testRowNumber()
{
- assertQuery("SELECT clerk, orderdate, orderkey, totalprice, row_number() OVER (PARTITION BY clerk ORDER BY totalprice) AS rnk FROM orders ORDER BY clerk, rnk");
- assertQuery("SELECT clerk, orderdate, orderkey, totalprice, rank() OVER (PARTITION BY clerk ORDER BY totalprice) AS rnk FROM orders ORDER BY clerk, rnk");
- assertQuery("SELECT clerk, orderdate, orderkey, totalprice, dense_rank() OVER (PARTITION BY clerk ORDER BY totalprice) AS rnk FROM orders ORDER BY clerk, rnk");
- assertQuery("SELECT clerk, orderdate, orderkey, totalprice, percent_rank() OVER (PARTITION BY clerk ORDER BY totalprice) AS rnk FROM orders ORDER BY clerk, rnk");
- assertQuery("SELECT clerk, orderdate, orderkey, totalprice, cume_dist() OVER (PARTITION BY clerk ORDER BY totalprice) AS rnk FROM orders ORDER BY clerk, rnk");
+ testRankingFunction("row_number()");
}
}
