Search in sources :

Example 1 with AstFunNode

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

the class GenericDbmsTransformer method transformInterval.

private void transformInterval(AstInterval interval) {
    SimpleNode mul = interval.jjtGetParent();
    if (AstFunNode.isFunction("*").test(mul)) {
        String type = interval.getLiteral();
        String fn;
        switch(type) {
            case "1 MONTH":
                fn = "ADD_MONTHS";
                break;
            case "1 DAYS":
            case "1 DAY":
                fn = "ADD_DAYS";
                break;
            case "1 MILLISECOND":
                fn = "ADD_MILLIS";
                break;
            default:
                throw new IllegalStateException("Unsupported interval format: " + interval.format());
        }
        SimpleNode content = mul.other(interval);
        if (content instanceof AstParenthesis)
            content = ((AstParenthesis) content).child(0);
        SimpleNode add = mul.jjtGetParent();
        if (!AstFunNode.isFunction("+").test(add))
            throw new IllegalStateException("Interval grandparent is " + add + ", expected addition");
        SimpleNode date = add.other(mul);
        AstFunNode addFunction = parserContext.getFunction(fn).node(date, content);
        date.pullUpPrefix();
        SimpleNode toReplace = add;
        if (toReplace.jjtGetParent() instanceof AstParenthesis)
            toReplace = toReplace.jjtGetParent();
        toReplace.replaceWith(addFunction);
        transformDateAdd(addFunction);
    }
}
Also used : AstFunNode(com.developmentontheedge.sql.model.AstFunNode) AstParenthesis(com.developmentontheedge.sql.model.AstParenthesis) SimpleNode(com.developmentontheedge.sql.model.SimpleNode)

Example 2 with AstFunNode

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

the class MacroExpander method expandMacros.

public void expandMacros(SimpleNode node) {
    for (int i = 0; i < node.jjtGetNumChildren(); i++) {
        SimpleNode child = node.child(i);
        expandMacros(child);
        if ((child instanceof AstFunNode) && ((AstFunNode) child).getFunction() instanceof BeMacroFunction) {
            transformMacroFunction((AstFunNode) child);
        }
    }
}
Also used : AstFunNode(com.developmentontheedge.sql.model.AstFunNode) BeMacroFunction(com.developmentontheedge.sql.model.BeMacroFunction) SimpleNode(com.developmentontheedge.sql.model.SimpleNode)

Example 3 with AstFunNode

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

the class OracleTransformer method transformBitOr.

@Override
protected void transformBitOr(AstFunNode node) {
    AstFunNode sum = DefaultParserContext.FUNC_PLUS.node(node.child(0), node.child(1));
    node.replaceWith(DefaultParserContext.FUNC_MINUS.node(sum, BITAND.node(node.child(0), node.child(1))));
}
Also used : AstFunNode(com.developmentontheedge.sql.model.AstFunNode)

Example 4 with AstFunNode

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

the class CategoryFilter method processTableRef.

private void processTableRef(AstTableRef ref) {
    String alias = Optional.ofNullable(ref.getAlias()).orElse(entity);
    AstFunNode categoryCondition = DefaultParserContext.FUNC_EQ.node(new AstFieldReference(identifier("classifications"), identifier("categoryID")), AstNumericConstant.of(categoryId));
    AstFunNode recordCondition = DefaultParserContext.FUNC_EQ.node(new AstFieldReference(identifier("classifications"), identifier("recordID")), new AstFieldReference(identifier(alias), identifier(primaryKeyColumn)));
    AstJoin join = JoinType.INNER.node("classifications", DefaultParserContext.FUNC_AND.node(categoryCondition, recordCondition));
    ref.appendSibling(join);
}
Also used : AstJoin(com.developmentontheedge.sql.model.AstJoin) AstFunNode(com.developmentontheedge.sql.model.AstFunNode) AstFieldReference(com.developmentontheedge.sql.model.AstFieldReference)

Example 5 with AstFunNode

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

the class MySqlTransformer method transformConcat.

@Override
protected void transformConcat(AstFunNode node) {
    if (isConcat(node))
        return;
    node.setFunction(parserContext.getFunction("concat"));
    List<SimpleNode> flatChildren = node.children().flatMap(child -> isConcat(child) ? child.children() : Stream.of(child)).toList();
    node.removeChildren();
    flatChildren.forEach(node::addChild);
    SimpleNode parent = node.jjtGetParent();
    if (parent instanceof AstParenthesis)
        parent.replaceWith(node);
}
Also used : AstIdentifierConstant(com.developmentontheedge.sql.model.AstIdentifierConstant) AstCaseElse(com.developmentontheedge.sql.model.AstCaseElse) AstParenthesis(com.developmentontheedge.sql.model.AstParenthesis) AstFrom(com.developmentontheedge.sql.model.AstFrom) AstPosition(com.developmentontheedge.sql.model.AstPosition) AstExcept(com.developmentontheedge.sql.model.AstExcept) Node(com.developmentontheedge.sql.model.Node) AstExtract(com.developmentontheedge.sql.model.AstExtract) QuoteSymbol(com.developmentontheedge.sql.model.AstIdentifierConstant.QuoteSymbol) DefaultParserContext(com.developmentontheedge.sql.model.DefaultParserContext) Function(com.developmentontheedge.sql.model.Function) AstNullPredicate(com.developmentontheedge.sql.model.AstNullPredicate) AstFunNode(com.developmentontheedge.sql.model.AstFunNode) AstCast(com.developmentontheedge.sql.model.AstCast) PredefinedFunction(com.developmentontheedge.sql.model.PredefinedFunction) AstDerivedColumn(com.developmentontheedge.sql.model.AstDerivedColumn) AstStringConstant(com.developmentontheedge.sql.model.AstStringConstant) AstStringPart(com.developmentontheedge.sql.model.AstStringPart) SimpleNode(com.developmentontheedge.sql.model.SimpleNode) AstCase(com.developmentontheedge.sql.model.AstCase) AstWith(com.developmentontheedge.sql.model.AstWith) AstSpecialConstant(com.developmentontheedge.sql.model.AstSpecialConstant) List(java.util.List) AstWhen(com.developmentontheedge.sql.model.AstWhen) Stream(java.util.stream.Stream) AstInterval(com.developmentontheedge.sql.model.AstInterval) AstOrderBy(com.developmentontheedge.sql.model.AstOrderBy) AstNumericConstant(com.developmentontheedge.sql.model.AstNumericConstant) AstDateAdd(com.developmentontheedge.sql.model.AstDateAdd) AstParenthesis(com.developmentontheedge.sql.model.AstParenthesis) SimpleNode(com.developmentontheedge.sql.model.SimpleNode)

Aggregations

AstFunNode (com.developmentontheedge.sql.model.AstFunNode)17 SimpleNode (com.developmentontheedge.sql.model.SimpleNode)10 AstIdentifierConstant (com.developmentontheedge.sql.model.AstIdentifierConstant)6 AstFieldReference (com.developmentontheedge.sql.model.AstFieldReference)4 AstFrom (com.developmentontheedge.sql.model.AstFrom)4 AstParenthesis (com.developmentontheedge.sql.model.AstParenthesis)4 AstSelect (com.developmentontheedge.sql.model.AstSelect)4 AstDerivedColumn (com.developmentontheedge.sql.model.AstDerivedColumn)3 AstLimit (com.developmentontheedge.sql.model.AstLimit)3 AstOrderBy (com.developmentontheedge.sql.model.AstOrderBy)3 AstSelectList (com.developmentontheedge.sql.model.AstSelectList)3 AstStringConstant (com.developmentontheedge.sql.model.AstStringConstant)3 AstTableRef (com.developmentontheedge.sql.model.AstTableRef)3 AstWhere (com.developmentontheedge.sql.model.AstWhere)3 AstBetweenPredicate (com.developmentontheedge.sql.model.AstBetweenPredicate)2 AstCase (com.developmentontheedge.sql.model.AstCase)2 AstCaseElse (com.developmentontheedge.sql.model.AstCaseElse)2 AstCast (com.developmentontheedge.sql.model.AstCast)2 AstExcept (com.developmentontheedge.sql.model.AstExcept)2 AstExtract (com.developmentontheedge.sql.model.AstExtract)2