Skip to content

Commit

Permalink
Merge pull request #4018 from eclipse/GH-4014-group-by-function
Browse files Browse the repository at this point in the history
GH-4014 handle function over var declared in group by
  • Loading branch information
hmottestad authored Jun 28, 2022
2 parents c86966e + e4b4f75 commit 158dc0b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -686,8 +686,9 @@ public TupleExpr visit(ASTSelect node, Object data) throws VisitorException {

private static boolean isIllegalCombinedWithGroupByExpression(ValueExpr expr, List<ProjectionElem> elements,
Set<String> groupNames) {
if (expr instanceof ValueConstant)
if (expr instanceof ValueConstant) {
return false;
}

VarNameCollector varNameCollector = new VarNameCollector();
expr.visit(varNameCollector);
Expand All @@ -704,6 +705,10 @@ private static boolean isIllegalCombinedWithGroupByExpression(ValueExpr expr, Li

private static boolean isIllegalCombinedWithGroupByExpression(String varName, List<ProjectionElem> elements,
Set<String> groupNames) {
if (groupNames.contains(varName)) {
return false;
}

do {
String prev = varName;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -517,4 +517,14 @@ public void testGroupByProjectionHandling_renameVariableWithAggregation() {
parser.parseQuery(query, null);
}

@Test
public void testGroupByProjectionHandling_function() {
String query = "select (strlen(concat(strlen(?s)+2, \"abc\", count(?o))) as ?len) where { \n" +
"?s ?p ?o .\n" +
"} group by ?s";

// should parse without error
parser.parseQuery(query, null);
}

}

0 comments on commit 158dc0b

Please sign in to comment.