Skip to content

Commit

Permalink
fix: fail on WINDOW clause without matching GROUP BY (#5431)
Browse files Browse the repository at this point in the history
A WINDOW clause is only valid if there is no matching GROUP BY. Before this change, if user submitted a query without a GROUP BY it would silently be ignored, which is poor UX. With this change an helpful error message is displayed.

Co-authored-by: Andy Coates <big-andy-coates@users.noreply.github.com>
  • Loading branch information
big-andy-coates and big-andy-coates authored May 21, 2020
1 parent 37f5f0b commit 68354d4
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import io.confluent.ksql.function.udf.AsValue;
import io.confluent.ksql.name.ColumnName;
import io.confluent.ksql.name.SourceName;
import io.confluent.ksql.parser.NodeLocation;
import io.confluent.ksql.parser.tree.AllColumns;
import io.confluent.ksql.parser.tree.GroupBy;
import io.confluent.ksql.parser.tree.PartitionBy;
Expand Down Expand Up @@ -131,6 +132,13 @@ public OutputNode buildPlan() {
if (analysis.getGroupBy().isPresent()) {
currentNode = buildAggregateNode(currentNode);
} else {
if (analysis.getWindowExpression().isPresent()) {
final String loc = analysis.getWindowExpression().get()
.getLocation()
.map(NodeLocation::asPrefix)
.orElse("");
throw new KsqlException(loc + "WINDOW clause requires a GROUP BY clause.");
}
currentNode = buildUserProjectNode(currentNode);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,17 @@
"type": "io.confluent.ksql.util.KsqlException",
"message": "KSQL does not support persistent queries on windowed tables."
}
},
{
"name": "window without group by",
"statements": [
"CREATE STREAM INPUT (ID BIGINT KEY, NAME varchar, VALUE bigint) WITH (kafka_topic='test_topic', value_format='DELIMITED');",
"CREATE STREAM OUTPUT as SELECT * FROM INPUT WINDOW TUMBLING (SIZE 30 SECONDS);"
],
"expectedException": {
"type": "io.confluent.ksql.util.KsqlException",
"message": "WINDOW clause requires a GROUP BY clause."
}
}
]
}

0 comments on commit 68354d4

Please sign in to comment.