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());
}
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(")");
}
Aggregations