Search in sources :

Example 1 with Node

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

Example 2 with Node

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

the class MySqlTransformer method transformIdentifier.

@Override
protected void transformIdentifier(AstIdentifierConstant identifier) {
    if (identifier.getQuoteSymbol() == QuoteSymbol.DOUBLE_QUOTE) {
        Node parent = identifier.jjtGetParent();
        if (parent instanceof AstDerivedColumn)
            return;
        identifier.setQuoteSymbol(QuoteSymbol.BACKTICK);
    }
    if (identifier.getValue().equalsIgnoreCase("current_timestamp")) {
        identifier.replaceWith(parserContext.getFunction("now").node());
    }
}
Also used : Node(com.developmentontheedge.sql.model.Node) AstFunNode(com.developmentontheedge.sql.model.AstFunNode) SimpleNode(com.developmentontheedge.sql.model.SimpleNode) AstDerivedColumn(com.developmentontheedge.sql.model.AstDerivedColumn)

Aggregations

AstDerivedColumn (com.developmentontheedge.sql.model.AstDerivedColumn)2 AstFunNode (com.developmentontheedge.sql.model.AstFunNode)2 Node (com.developmentontheedge.sql.model.Node)2 SimpleNode (com.developmentontheedge.sql.model.SimpleNode)2 AstCase (com.developmentontheedge.sql.model.AstCase)1 AstCaseElse (com.developmentontheedge.sql.model.AstCaseElse)1 AstCast (com.developmentontheedge.sql.model.AstCast)1 AstDateAdd (com.developmentontheedge.sql.model.AstDateAdd)1 AstExcept (com.developmentontheedge.sql.model.AstExcept)1 AstExtract (com.developmentontheedge.sql.model.AstExtract)1 AstFrom (com.developmentontheedge.sql.model.AstFrom)1 AstIdentifierConstant (com.developmentontheedge.sql.model.AstIdentifierConstant)1 QuoteSymbol (com.developmentontheedge.sql.model.AstIdentifierConstant.QuoteSymbol)1 AstInterval (com.developmentontheedge.sql.model.AstInterval)1 AstNullPredicate (com.developmentontheedge.sql.model.AstNullPredicate)1 AstNumericConstant (com.developmentontheedge.sql.model.AstNumericConstant)1 AstOrderBy (com.developmentontheedge.sql.model.AstOrderBy)1 AstParenthesis (com.developmentontheedge.sql.model.AstParenthesis)1 AstPosition (com.developmentontheedge.sql.model.AstPosition)1 AstSpecialConstant (com.developmentontheedge.sql.model.AstSpecialConstant)1