Skip to content

Commit

Permalink
DRILL-4795: Nested aggregate windowed query fails - IllegalStateExcep…
Browse files Browse the repository at this point in the history
…tion

close #563
  • Loading branch information
Gautam Parai authored and Aman Sinha committed Aug 9, 2016
1 parent aaf220f commit 0bac42d
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 4 deletions.
Expand Up @@ -848,9 +848,9 @@ public void testStatisticalWindowFunctions() throws Exception {
@Test // DRILL-2330
public void testNestedAggregates() throws Exception {

final String query = "select sum(min(l_extendedprice))" +
" over (partition by l_suppkey order by l_suppkey) as totprice" +
" from cp.`tpch/lineitem.parquet` where l_suppkey <= 10 group by l_suppkey order by 1 desc";
final String query = "select sum(min(l_extendedprice))"
+ " over (partition by l_suppkey order by l_suppkey) as totprice"
+ " from cp.`tpch/lineitem.parquet` where l_suppkey <= 10 group by l_suppkey order by 1 desc";

// Validate the plan
final String[] expectedPlan = {"Window.*partition \\{0\\} order by \\[0\\].*SUM\\(\\$1\\).*",
Expand All @@ -874,4 +874,57 @@ public void testNestedAggregates() throws Exception {
.baselineValues(904.0)
.go();
}

@Test // DRILL-4795, DRILL-4796
public void testNestedAggregates1() throws Exception {
try {
String query = "select sum(min(l_extendedprice)) over (partition by l_suppkey)\n"
+ " from cp.`tpch/nation.parquet` where l_suppkey <= 10";
test(query);
} catch(UserException ex) {
assert(ex.getMessage().contains("Expression 'l_suppkey' is not being grouped"));
}

try {
String query = "select sum(min(l_extendedprice)) over (partition by l_suppkey) as totprice\n"
+ " from cp.`tpch/nation.parquet` where l_suppkey <= 10";
test(query);
} catch(UserException ex) {
assert(ex.getMessage().contains("Expression 'l_suppkey' is not being grouped"));
}

try {
String query = "select sum(min(l_extendedprice)) over w1 as totprice\n"
+ " from cp.`tpch/nation.parquet` where l_suppkey <= 10\n"
+ " window w1 as (partition by l_suppkey)";
test(query);
} catch(UserException ex) {
assert(ex.getMessage().contains("Expression 'tpch/nation.parquet.l_suppkey' is not being grouped"));
}

try {
String query = "select sum(min(l_extendedprice)) over (partition by n_nationkey)\n"
+ " from cp.`tpch/nation.parquet` where l_suppkey <= 10 group by l_suppkey";
test(query);
} catch(UserException ex) {
assert(ex.getMessage().contains("Expression 'n_nationkey' is not being grouped"));
}

try {
String query = "select sum(min(l_extendedprice)) over (partition by n_nationkey) as totprice\n"
+ " from cp.`tpch/nation.parquet` where l_suppkey <= 10 group by l_suppkey";
test(query);
} catch(UserException ex) {
assert(ex.getMessage().contains("Expression 'n_nationkey' is not being grouped"));
}

try {
String query = "select sum(min(l_extendedprice)) over w2 as totprice\n"
+ " from cp.`tpch/nation.parquet` where l_suppkey <= 10 group by l_suppkey\n"
+ " window w2 as (partition by n_nationkey)";
test(query);
} catch(UserException ex) {
assert(ex.getMessage().contains("Expression 'tpch/nation.parquet.n_nationkey' is not being grouped"));
}
}
}
2 changes: 1 addition & 1 deletion pom.xml
Expand Up @@ -1287,7 +1287,7 @@
<dependency>
<groupId>org.apache.calcite</groupId>
<artifactId>calcite-core</artifactId>
<version>1.4.0-drill-r15</version>
<version>1.4.0-drill-r17</version>
<exclusions>
<exclusion>
<groupId>org.jgrapht</groupId>
Expand Down

0 comments on commit 0bac42d

Please sign in to comment.