Search in sources :

Example 1 with AstFirstDayOf

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

the class DB2Transformer method transformDateTrunc.

@Override
protected void transformDateTrunc(AstFunNode node) {
    Function opConcat = DefaultParserContext.FUNC_MINUS;
    SimpleNode date = node.child(1);
    String field = ((AstStringConstant) node.child(0)).getValue();
    AstFirstDayOf month = new AstFirstDayOf(new AstParenthesis(opConcat.node(DAY.node(date), AstNumericConstant.of(1))), "DAYS");
    if (field.equalsIgnoreCase("'MONTH'"))
        node.replaceWith(opConcat.node(date, month));
    else {
        AstFirstDayOf year = new AstFirstDayOf(new AstParenthesis(opConcat.node(MONTH.node(date), AstNumericConstant.of(1))), "MONTHS");
        node.replaceWith(opConcat.node(date, opConcat.node(year, month)));
    }
}
Also used : Function(com.developmentontheedge.sql.model.Function) PredefinedFunction(com.developmentontheedge.sql.model.PredefinedFunction) AstWindowFunction(com.developmentontheedge.sql.model.AstWindowFunction) AstStringConstant(com.developmentontheedge.sql.model.AstStringConstant) AstParenthesis(com.developmentontheedge.sql.model.AstParenthesis) SimpleNode(com.developmentontheedge.sql.model.SimpleNode) AstFirstDayOf(com.developmentontheedge.sql.model.AstFirstDayOf)

Example 2 with AstFirstDayOf

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

the class DB2Transformer method transformDateAdd.

@Override
protected void transformDateAdd(AstFunNode node) {
    Function opPlus = DefaultParserContext.FUNC_PLUS;
    Function opTimes = DefaultParserContext.FUNC_TIMES;
    SimpleNode date = node.child(0);
    SimpleNode number = node.child(1);
    String name = node.getFunction().getName();
    String type = name.equalsIgnoreCase("add_months") ? "MONTHS" : name.equalsIgnoreCase("add_days") ? "DAYS" : "MICROSECONDS";
    if (type.equals("MICROSECONDS"))
        number = new AstParenthesis(opTimes.node(number, AstNumericConstant.of(1000)));
    node.replaceWith(new AstParenthesis(opPlus.node(date, new AstFirstDayOf(number, type))));
}
Also used : Function(com.developmentontheedge.sql.model.Function) PredefinedFunction(com.developmentontheedge.sql.model.PredefinedFunction) AstWindowFunction(com.developmentontheedge.sql.model.AstWindowFunction) AstParenthesis(com.developmentontheedge.sql.model.AstParenthesis) SimpleNode(com.developmentontheedge.sql.model.SimpleNode) AstFirstDayOf(com.developmentontheedge.sql.model.AstFirstDayOf)

Aggregations

AstFirstDayOf (com.developmentontheedge.sql.model.AstFirstDayOf)2 AstParenthesis (com.developmentontheedge.sql.model.AstParenthesis)2 AstWindowFunction (com.developmentontheedge.sql.model.AstWindowFunction)2 Function (com.developmentontheedge.sql.model.Function)2 PredefinedFunction (com.developmentontheedge.sql.model.PredefinedFunction)2 SimpleNode (com.developmentontheedge.sql.model.SimpleNode)2 AstStringConstant (com.developmentontheedge.sql.model.AstStringConstant)1