Search in sources :

Example 11 with SimpleNode

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

the class SqlServerTransformer method transformDateAdd.

@Override
protected void transformDateAdd(AstFunNode node) {
    SimpleNode date = node.child(0);
    SimpleNode number = node.child(1);
    String name = node.getFunction().getName();
    String type = name.equalsIgnoreCase("add_months") ? "MONTH" : name.equalsIgnoreCase("add_days") ? "DAY" : "MILLISECOND";
    node.replaceWith(DATEADD.node(new AstIdentifierConstant(type), number, date));
}
Also used : AstIdentifierConstant(com.developmentontheedge.sql.model.AstIdentifierConstant) SimpleNode(com.developmentontheedge.sql.model.SimpleNode)

Example 12 with SimpleNode

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

the class SqlServerTransformer method transformDecode.

@Override
protected void transformDecode(AstFunNode node) {
    AstCase astCase = new AstCase();
    for (int i = 1; i < node.jjtGetNumChildren() - 1; i++) {
        SimpleNode cond;
        if (node.child(i) instanceof AstSpecialConstant) {
            cond = new AstNullPredicate(0);
            cond.addChild(node.child(0));
        } else {
            cond = DefaultParserContext.FUNC_EQ.node(node.child(0), node.child(i));
        }
        astCase.addChild(new AstWhen(cond, node.child(++i)));
        if (i == node.jjtGetNumChildren() - 2) {
            astCase.addChild(new AstCaseElse(node.child(++i)));
        }
    }
    node.replaceWith(astCase);
}
Also used : AstCaseElse(com.developmentontheedge.sql.model.AstCaseElse) AstWhen(com.developmentontheedge.sql.model.AstWhen) AstCase(com.developmentontheedge.sql.model.AstCase) AstNullPredicate(com.developmentontheedge.sql.model.AstNullPredicate) SimpleNode(com.developmentontheedge.sql.model.SimpleNode) AstSpecialConstant(com.developmentontheedge.sql.model.AstSpecialConstant)

Example 13 with SimpleNode

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

the class SqlServerTransformer method transformLastDay.

@Override
protected void transformLastDay(AstFunNode node) {
    SimpleNode date = node.child(0);
    transformLastDay(node, date);
}
Also used : SimpleNode(com.developmentontheedge.sql.model.SimpleNode)

Example 14 with SimpleNode

use of com.developmentontheedge.sql.model.SimpleNode 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)

Example 15 with SimpleNode

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

the class SqlServerTransformer method transformLpad.

@Override
protected void transformLpad(AstFunNode node) {
    Function opConcat = DefaultParserContext.FUNC_PLUS;
    SimpleNode str = node.child(0);
    SimpleNode fill = node.child(2);
    SimpleNode size = node.child(1);
    SimpleNode rsize = size.clone();
    node.replaceWith(RIGHT.node(opConcat.node(REPLICATE.node(fill, size), str), rsize));
}
Also used : Function(com.developmentontheedge.sql.model.Function) PredefinedFunction(com.developmentontheedge.sql.model.PredefinedFunction) AstWindowFunction(com.developmentontheedge.sql.model.AstWindowFunction) SimpleNode(com.developmentontheedge.sql.model.SimpleNode)

Aggregations

SimpleNode (com.developmentontheedge.sql.model.SimpleNode)39 AstIdentifierConstant (com.developmentontheedge.sql.model.AstIdentifierConstant)12 AstStringConstant (com.developmentontheedge.sql.model.AstStringConstant)11 AstFunNode (com.developmentontheedge.sql.model.AstFunNode)10 AstParenthesis (com.developmentontheedge.sql.model.AstParenthesis)10 Function (com.developmentontheedge.sql.model.Function)9 PredefinedFunction (com.developmentontheedge.sql.model.PredefinedFunction)9 AstWindowFunction (com.developmentontheedge.sql.model.AstWindowFunction)7 AstFrom (com.developmentontheedge.sql.model.AstFrom)5 AstInterval (com.developmentontheedge.sql.model.AstInterval)5 AstSelect (com.developmentontheedge.sql.model.AstSelect)5 AstTableRef (com.developmentontheedge.sql.model.AstTableRef)5 AstCase (com.developmentontheedge.sql.model.AstCase)4 AstCaseElse (com.developmentontheedge.sql.model.AstCaseElse)4 AstFieldReference (com.developmentontheedge.sql.model.AstFieldReference)4 AstSelectList (com.developmentontheedge.sql.model.AstSelectList)4 AstStringPart (com.developmentontheedge.sql.model.AstStringPart)4 AstCast (com.developmentontheedge.sql.model.AstCast)3 AstDerivedColumn (com.developmentontheedge.sql.model.AstDerivedColumn)3 AstLimit (com.developmentontheedge.sql.model.AstLimit)3