Search in sources :

Example 1 with AstColumnList

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

the class SqlServerTransformer method transformLeastGreatest.

@Override
protected void transformLeastGreatest(AstFunNode node) {
    String name = node.getFunction().getName();
    AstIdentifierConstant v = new AstIdentifierConstant("V");
    Function func;
    if ("LEAST".equals(name))
        func = parserContext.getFunction("min");
    else
        func = parserContext.getFunction("max");
    AstValues values = new AstValues(0);
    for (SimpleNode child : node.children()) values.addChild(new AstParenthesis(child));
    AstTableRef tableRef = new AstTableRef(new AstParenthesis(values), new AstIdentifierConstant(name), new AstColumnList(v));
    node.replaceWith(new AstParenthesis(new AstSelect(new AstSelectList(func.node(v)), new AstFrom(tableRef))));
}
Also used : AstValues(com.developmentontheedge.sql.model.AstValues) AstSelect(com.developmentontheedge.sql.model.AstSelect) Function(com.developmentontheedge.sql.model.Function) PredefinedFunction(com.developmentontheedge.sql.model.PredefinedFunction) AstWindowFunction(com.developmentontheedge.sql.model.AstWindowFunction) AstSelectList(com.developmentontheedge.sql.model.AstSelectList) AstIdentifierConstant(com.developmentontheedge.sql.model.AstIdentifierConstant) AstColumnList(com.developmentontheedge.sql.model.AstColumnList) AstFrom(com.developmentontheedge.sql.model.AstFrom) AstParenthesis(com.developmentontheedge.sql.model.AstParenthesis) AstTableRef(com.developmentontheedge.sql.model.AstTableRef) SimpleNode(com.developmentontheedge.sql.model.SimpleNode)

Aggregations

AstColumnList (com.developmentontheedge.sql.model.AstColumnList)1 AstFrom (com.developmentontheedge.sql.model.AstFrom)1 AstIdentifierConstant (com.developmentontheedge.sql.model.AstIdentifierConstant)1 AstParenthesis (com.developmentontheedge.sql.model.AstParenthesis)1 AstSelect (com.developmentontheedge.sql.model.AstSelect)1 AstSelectList (com.developmentontheedge.sql.model.AstSelectList)1 AstTableRef (com.developmentontheedge.sql.model.AstTableRef)1 AstValues (com.developmentontheedge.sql.model.AstValues)1 AstWindowFunction (com.developmentontheedge.sql.model.AstWindowFunction)1 Function (com.developmentontheedge.sql.model.Function)1 PredefinedFunction (com.developmentontheedge.sql.model.PredefinedFunction)1 SimpleNode (com.developmentontheedge.sql.model.SimpleNode)1