Search in sources :

Example 1 with AstWithinGroup

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

the class OracleTransformer method transformStringAgg.

@Override
protected void transformStringAgg(AstFunNode node) {
    node.setFunction(LISTAGG);
    if (node.isDistinct())
        throw new IllegalStateException("DISTINCT clause is unsupported for " + node.getFunction().getName());
    AstOrderBy orderBy;
    if (node.child(node.jjtGetNumChildren() - 1) instanceof AstOrderBy) {
        orderBy = (AstOrderBy) node.child(node.jjtGetNumChildren() - 1);
        node.removeChild(node.jjtGetNumChildren() - 1);
    } else {
        orderBy = new AstOrderBy(new AstOrderingElement(node.child(0)));
    }
    node.replaceWith(new AstOrderedSetAggregate((AstFunNode) node.clone(), new AstWithinGroup(orderBy)));
}
Also used : AstOrderBy(com.developmentontheedge.sql.model.AstOrderBy) AstWithinGroup(com.developmentontheedge.sql.model.AstWithinGroup) AstOrderingElement(com.developmentontheedge.sql.model.AstOrderingElement) AstFunNode(com.developmentontheedge.sql.model.AstFunNode) AstOrderedSetAggregate(com.developmentontheedge.sql.model.AstOrderedSetAggregate)

Example 2 with AstWithinGroup

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

the class DB2Transformer method transformStringAgg.

@Override
protected void transformStringAgg(AstFunNode node) {
    node.setFunction(LISTAGG);
    if (node.isDistinct())
        throw new IllegalStateException("DISTINCT clause is unsupported for " + node.getFunction().getName());
    if (node.child(node.jjtGetNumChildren() - 1) instanceof AstOrderBy) {
        AstOrderBy orderBy = (AstOrderBy) node.child(node.jjtGetNumChildren() - 1);
        node.removeChild(node.jjtGetNumChildren() - 1);
        node.replaceWith(new AstOrderedSetAggregate((AstFunNode) node.clone(), new AstWithinGroup(orderBy)));
    }
}
Also used : AstOrderBy(com.developmentontheedge.sql.model.AstOrderBy) AstWithinGroup(com.developmentontheedge.sql.model.AstWithinGroup) AstFunNode(com.developmentontheedge.sql.model.AstFunNode) AstOrderedSetAggregate(com.developmentontheedge.sql.model.AstOrderedSetAggregate)

Aggregations

AstFunNode (com.developmentontheedge.sql.model.AstFunNode)2 AstOrderBy (com.developmentontheedge.sql.model.AstOrderBy)2 AstOrderedSetAggregate (com.developmentontheedge.sql.model.AstOrderedSetAggregate)2 AstWithinGroup (com.developmentontheedge.sql.model.AstWithinGroup)2 AstOrderingElement (com.developmentontheedge.sql.model.AstOrderingElement)1