use of com.developmentontheedge.sql.model.AstOrderBy in project be5 by DevelopmentOnTheEdge.
the class Be5QueryExecutor method applySort.
private void applySort(DebugQueryLogger dql, AstStart ast) {
if (sortColumn >= 0) {
try {
DynamicProperty[] schema = getSchema(new Formatter().format(ast, context, parserContext));
int sortCol = getQuerySortingColumn(schema);
if (sortCol > 0) {
AstSelect sel = (AstSelect) ast.getQuery().jjtGetChild(ast.getQuery().jjtGetNumChildren() - 1);
AstOrderBy orderBy = sel.getOrderBy();
if (orderBy == null) {
orderBy = new AstOrderBy();
sel.addChild(orderBy);
AstLimit astLimit = sel.children().select(AstLimit.class).findFirst().orElse(null);
if (astLimit != null) {
sel.removeChild(astLimit);
sel.addChild(astLimit);
}
}
AstOrderingElement oe = new AstOrderingElement(AstNumericConstant.of(sortCol));
if (sortDesc) {
oe.setDirectionToken(new Token(0, "DESC"));
}
orderBy.addChild(oe);
orderBy.moveToFront(oe);
}
dql.log("With sort", ast);
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
use of com.developmentontheedge.sql.model.AstOrderBy in project be5 by DevelopmentOnTheEdge.
the class OracleTransformer method transformStringAgg.
@Override
protected void transformStringAgg(AstFunNode node) {
node.setFunction(LISTAGG);
if (node.isDistinct())
throw new IllegalStateException("DISTINCT clause is unsupported for " + node.getFunction().getName());
AstOrderBy orderBy;
if (node.child(node.jjtGetNumChildren() - 1) instanceof AstOrderBy) {
orderBy = (AstOrderBy) node.child(node.jjtGetNumChildren() - 1);
node.removeChild(node.jjtGetNumChildren() - 1);
} else {
orderBy = new AstOrderBy(new AstOrderingElement(node.child(0)));
}
node.replaceWith(new AstOrderedSetAggregate((AstFunNode) node.clone(), new AstWithinGroup(orderBy)));
}
use of com.developmentontheedge.sql.model.AstOrderBy in project be5 by DevelopmentOnTheEdge.
the class OrderByFilter method apply.
public void apply(AstQuery query, Map<String, String> columns) {
AstOrderBy orderBy = new AstOrderBy();
apply(columns, query, orderBy);
query.children().select(AstSelect.class).forEach(AstSelect::dropOrder);
AstSelect select;
if (query.jjtGetNumChildren() == 1)
select = (AstSelect) query.child(0);
else {
AstTableRef tableRef = new AstTableRef(new AstParenthesis(query.clone()), new AstIdentifierConstant("tmp"));
select = new AstSelect(new AstSelectList(), new AstFrom(tableRef));
query.replaceWith(new AstQuery(select));
}
select.addChild(orderBy);
}
use of com.developmentontheedge.sql.model.AstOrderBy in project be5 by DevelopmentOnTheEdge.
the class DB2Transformer method transformStringAgg.
@Override
protected void transformStringAgg(AstFunNode node) {
node.setFunction(LISTAGG);
if (node.isDistinct())
throw new IllegalStateException("DISTINCT clause is unsupported for " + node.getFunction().getName());
if (node.child(node.jjtGetNumChildren() - 1) instanceof AstOrderBy) {
AstOrderBy orderBy = (AstOrderBy) node.child(node.jjtGetNumChildren() - 1);
node.removeChild(node.jjtGetNumChildren() - 1);
node.replaceWith(new AstOrderedSetAggregate((AstFunNode) node.clone(), new AstWithinGroup(orderBy)));
}
}
Aggregations