Search in sources :

Example 1 with KeepExpression

use of net.sf.jsqlparser.expression.KeepExpression in project JSqlParser by JSQLParser.

the class ExpressionDeParserTest method shouldDeParseComplexAnalyticExpressionWithKeep.

@Test
public void shouldDeParseComplexAnalyticExpressionWithKeep() {
    AnalyticExpression analyticExpression = new AnalyticExpression();
    KeepExpression keep = mock(KeepExpression.class);
    analyticExpression.setName("name");
    analyticExpression.setKeep(keep);
    will(appendToBuffer("keep")).given(keep).accept(expressionDeParser);
    expressionDeParser.visit(analyticExpression);
    assertEquals("name() keep OVER ()", buffer.toString());
}
Also used : KeepExpression(net.sf.jsqlparser.expression.KeepExpression) AnalyticExpression(net.sf.jsqlparser.expression.AnalyticExpression) Test(org.junit.Test)

Example 2 with KeepExpression

use of net.sf.jsqlparser.expression.KeepExpression in project JSqlParser by JSQLParser.

the class ExpressionDeParser method visit.

@Override
public void visit(AnalyticExpression aexpr) {
    String name = aexpr.getName();
    Expression expression = aexpr.getExpression();
    Expression offset = aexpr.getOffset();
    Expression defaultValue = aexpr.getDefaultValue();
    boolean isAllColumns = aexpr.isAllColumns();
    KeepExpression keep = aexpr.getKeep();
    ExpressionList partitionExpressionList = aexpr.getPartitionExpressionList();
    List<OrderByElement> orderByElements = aexpr.getOrderByElements();
    WindowElement windowElement = aexpr.getWindowElement();
    buffer.append(name).append("(");
    if (expression != null) {
        expression.accept(this);
        if (offset != null) {
            buffer.append(", ");
            offset.accept(this);
            if (defaultValue != null) {
                buffer.append(", ");
                defaultValue.accept(this);
            }
        }
    } else if (isAllColumns) {
        buffer.append("*");
    }
    buffer.append(") ");
    if (keep != null) {
        keep.accept(this);
        buffer.append(" ");
    }
    switch(aexpr.getType()) {
        case WITHIN_GROUP:
            buffer.append("WITHIN GROUP");
            break;
        default:
            buffer.append("OVER");
    }
    buffer.append(" (");
    if (partitionExpressionList != null && !partitionExpressionList.getExpressions().isEmpty()) {
        buffer.append("PARTITION BY ");
        List<Expression> expressions = partitionExpressionList.getExpressions();
        for (int i = 0; i < expressions.size(); i++) {
            if (i > 0) {
                buffer.append(", ");
            }
            expressions.get(i).accept(this);
        }
        buffer.append(" ");
    }
    if (orderByElements != null && !orderByElements.isEmpty()) {
        buffer.append("ORDER BY ");
        orderByDeParser.setExpressionVisitor(this);
        orderByDeParser.setBuffer(buffer);
        for (int i = 0; i < orderByElements.size(); i++) {
            if (i > 0) {
                buffer.append(", ");
            }
            orderByDeParser.deParseElement(orderByElements.get(i));
        }
        if (windowElement != null) {
            buffer.append(' ');
            buffer.append(windowElement);
        }
    }
    buffer.append(")");
}
Also used : KeepExpression(net.sf.jsqlparser.expression.KeepExpression) WindowElement(net.sf.jsqlparser.expression.WindowElement) KeepExpression(net.sf.jsqlparser.expression.KeepExpression) CaseExpression(net.sf.jsqlparser.expression.CaseExpression) NotExpression(net.sf.jsqlparser.expression.NotExpression) ValueListExpression(net.sf.jsqlparser.expression.ValueListExpression) CastExpression(net.sf.jsqlparser.expression.CastExpression) OracleHierarchicalExpression(net.sf.jsqlparser.expression.OracleHierarchicalExpression) IsNullExpression(net.sf.jsqlparser.expression.operators.relational.IsNullExpression) Expression(net.sf.jsqlparser.expression.Expression) IntervalExpression(net.sf.jsqlparser.expression.IntervalExpression) OrExpression(net.sf.jsqlparser.expression.operators.conditional.OrExpression) TimeKeyExpression(net.sf.jsqlparser.expression.TimeKeyExpression) BinaryExpression(net.sf.jsqlparser.expression.BinaryExpression) JsonExpression(net.sf.jsqlparser.expression.JsonExpression) LikeExpression(net.sf.jsqlparser.expression.operators.relational.LikeExpression) ExistsExpression(net.sf.jsqlparser.expression.operators.relational.ExistsExpression) InExpression(net.sf.jsqlparser.expression.operators.relational.InExpression) AndExpression(net.sf.jsqlparser.expression.operators.conditional.AndExpression) AnalyticExpression(net.sf.jsqlparser.expression.AnalyticExpression) AllComparisonExpression(net.sf.jsqlparser.expression.AllComparisonExpression) ExtractExpression(net.sf.jsqlparser.expression.ExtractExpression) AnyComparisonExpression(net.sf.jsqlparser.expression.AnyComparisonExpression) SignedExpression(net.sf.jsqlparser.expression.SignedExpression) OldOracleJoinBinaryExpression(net.sf.jsqlparser.expression.operators.relational.OldOracleJoinBinaryExpression) DateTimeLiteralExpression(net.sf.jsqlparser.expression.DateTimeLiteralExpression) OrderByElement(net.sf.jsqlparser.statement.select.OrderByElement) MultiExpressionList(net.sf.jsqlparser.expression.operators.relational.MultiExpressionList) ExpressionList(net.sf.jsqlparser.expression.operators.relational.ExpressionList) OracleHint(net.sf.jsqlparser.expression.OracleHint)

Aggregations

AnalyticExpression (net.sf.jsqlparser.expression.AnalyticExpression)2 KeepExpression (net.sf.jsqlparser.expression.KeepExpression)2 AllComparisonExpression (net.sf.jsqlparser.expression.AllComparisonExpression)1 AnyComparisonExpression (net.sf.jsqlparser.expression.AnyComparisonExpression)1 BinaryExpression (net.sf.jsqlparser.expression.BinaryExpression)1 CaseExpression (net.sf.jsqlparser.expression.CaseExpression)1 CastExpression (net.sf.jsqlparser.expression.CastExpression)1 DateTimeLiteralExpression (net.sf.jsqlparser.expression.DateTimeLiteralExpression)1 Expression (net.sf.jsqlparser.expression.Expression)1 ExtractExpression (net.sf.jsqlparser.expression.ExtractExpression)1 IntervalExpression (net.sf.jsqlparser.expression.IntervalExpression)1 JsonExpression (net.sf.jsqlparser.expression.JsonExpression)1 NotExpression (net.sf.jsqlparser.expression.NotExpression)1 OracleHierarchicalExpression (net.sf.jsqlparser.expression.OracleHierarchicalExpression)1 OracleHint (net.sf.jsqlparser.expression.OracleHint)1 SignedExpression (net.sf.jsqlparser.expression.SignedExpression)1 TimeKeyExpression (net.sf.jsqlparser.expression.TimeKeyExpression)1 ValueListExpression (net.sf.jsqlparser.expression.ValueListExpression)1 WindowElement (net.sf.jsqlparser.expression.WindowElement)1 AndExpression (net.sf.jsqlparser.expression.operators.conditional.AndExpression)1