Search in sources :

Example 1 with AstCount

use of com.developmentontheedge.sql.model.AstCount in project be5 by DevelopmentOnTheEdge.

the class CountApplier method transform.

public void transform(ParserContext ctx, AstStart ast) {
    AstQuery query = ast.getQuery();
    query.children().select(AstSelect.class).forEach(AstSelect::dropOrder);
    if (query.jjtGetNumChildren() > 1)
        throw new UnsupportedOperationException("UNION queries are not supported for COUNT");
    AstSelect select = query.children().select(AstSelect.class).findFirst().get();
    AstSelectList selectList = select.getSelectList();
    selectList.removeChildren();
    AstCount countFn = new AstCount();
    AstDerivedColumn countNode = new AstDerivedColumn(countFn, "CNT");
    countNode.setAsToken(true);
    selectList.addChild(countNode);
}
Also used : AstSelect(com.developmentontheedge.sql.model.AstSelect) AstQuery(com.developmentontheedge.sql.model.AstQuery) AstSelectList(com.developmentontheedge.sql.model.AstSelectList) AstCount(com.developmentontheedge.sql.model.AstCount) AstDerivedColumn(com.developmentontheedge.sql.model.AstDerivedColumn)

Aggregations

AstCount (com.developmentontheedge.sql.model.AstCount)1 AstDerivedColumn (com.developmentontheedge.sql.model.AstDerivedColumn)1 AstQuery (com.developmentontheedge.sql.model.AstQuery)1 AstSelect (com.developmentontheedge.sql.model.AstSelect)1 AstSelectList (com.developmentontheedge.sql.model.AstSelectList)1