use of net.sf.jsqlparser.statement.select.OrderByElement in project herddb by diennea.
the class JSQLParserPlanner method planSort.
private PlannerOp planSort(PlannerOp input, OpSchema columns, List<OrderByElement> fieldCollations) {
boolean[] directions = new boolean[fieldCollations.size()];
boolean[] nullLastdirections = new boolean[fieldCollations.size()];
int[] fields = new int[fieldCollations.size()];
int i = 0;
for (OrderByElement col : fieldCollations) {
OrderByElement.NullOrdering nullDirection = col.getNullOrdering();
CompiledSQLExpression columnPos = SQLParserExpressionCompiler.compileExpression(col.getExpression(), columns);
checkSupported(columnPos instanceof AccessCurrentRowExpression);
AccessCurrentRowExpression pos = (AccessCurrentRowExpression) columnPos;
int index = pos.getIndex();
directions[i] = col.isAsc();
// default is NULL LAST
nullLastdirections[i] = nullDirection == OrderByElement.NullOrdering.NULLS_LAST || nullDirection == null;
fields[i++] = index;
}
return new SortOp(input, directions, fields, nullLastdirections);
}
use of net.sf.jsqlparser.statement.select.OrderByElement in project JSqlParser by JSQLParser.
the class StatementDeParserTest method shouldUseProvidedDeParsersWhenDeParsingUpdateUsingSelect.
@Test
@SuppressWarnings("PMD.JUnitTestsShouldIncludeAssert")
public void shouldUseProvidedDeParsersWhenDeParsingUpdateUsingSelect() {
Update update = new Update();
List<Column> columns = new ArrayList<Column>();
Select select = new Select();
Expression where = mock(Expression.class);
List<OrderByElement> orderByElements = new ArrayList<OrderByElement>();
Column column1 = new Column();
Column column2 = new Column();
SelectBody selectBody = mock(SelectBody.class);
OrderByElement orderByElement1 = new OrderByElement();
OrderByElement orderByElement2 = new OrderByElement();
Expression orderByElement1Expression = mock(Expression.class);
Expression orderByElement2Expression = mock(Expression.class);
update.setUseSelect(true);
update.setColumns(columns);
update.setSelect(select);
update.setWhere(where);
update.setOrderByElements(orderByElements);
columns.add(column1);
columns.add(column2);
select.setSelectBody(selectBody);
orderByElements.add(orderByElement1);
orderByElements.add(orderByElement2);
orderByElement1.setExpression(orderByElement1Expression);
orderByElement2.setExpression(orderByElement2Expression);
statementDeParser.visit(update);
then(expressionDeParser).should().visit(column1);
then(expressionDeParser).should().visit(column2);
then(selectBody).should().accept(selectDeParser);
then(where).should().accept(expressionDeParser);
then(orderByElement1Expression).should().accept(expressionDeParser);
then(orderByElement2Expression).should().accept(expressionDeParser);
}
use of net.sf.jsqlparser.statement.select.OrderByElement in project JSqlParser by JSQLParser.
the class StatementDeParserTest method shouldUseProvidedDeParsersWhenDeParsingUpdateNotUsingSelect.
@Test
@SuppressWarnings("PMD.JUnitTestsShouldIncludeAssert")
public void shouldUseProvidedDeParsersWhenDeParsingUpdateNotUsingSelect() {
Update update = new Update();
List<Column> columns = new ArrayList<Column>();
List<Expression> expressions = new ArrayList<Expression>();
Expression where = mock(Expression.class);
List<OrderByElement> orderByElements = new ArrayList<OrderByElement>();
Column column1 = new Column();
Column column2 = new Column();
Expression expression1 = mock(Expression.class);
Expression expression2 = mock(Expression.class);
OrderByElement orderByElement1 = new OrderByElement();
OrderByElement orderByElement2 = new OrderByElement();
Expression orderByElement1Expression = mock(Expression.class);
Expression orderByElement2Expression = mock(Expression.class);
update.setColumns(columns);
update.setExpressions(expressions);
update.setWhere(where);
update.setOrderByElements(orderByElements);
columns.add(column1);
columns.add(column2);
expressions.add(expression1);
expressions.add(expression2);
orderByElements.add(orderByElement1);
orderByElements.add(orderByElement2);
orderByElement1.setExpression(orderByElement1Expression);
orderByElement2.setExpression(orderByElement2Expression);
statementDeParser.visit(update);
then(expressionDeParser).should().visit(column1);
then(expressionDeParser).should().visit(column2);
then(expression1).should().accept(expressionDeParser);
then(expression2).should().accept(expressionDeParser);
then(where).should().accept(expressionDeParser);
then(orderByElement1Expression).should().accept(expressionDeParser);
then(orderByElement2Expression).should().accept(expressionDeParser);
}
use of net.sf.jsqlparser.statement.select.OrderByElement in project JSqlParser by JSQLParser.
the class SelectASTTest method testSelectASTColumn.
@Test
public void testSelectASTColumn() throws JSQLParserException {
String sql = "SELECT a, b FROM mytable order by b, c";
StringBuilder b = new StringBuilder(sql);
Statement stmt = CCJSqlParserUtil.parse(sql);
Select select = (Select) stmt;
PlainSelect ps = (PlainSelect) select.getSelectBody();
for (SelectItem item : ps.getSelectItems()) {
SelectExpressionItem sei = (SelectExpressionItem) item;
Column c = (Column) sei.getExpression();
SimpleNode astNode = c.getASTNode();
assertNotNull(astNode);
b.setCharAt(astNode.jjtGetFirstToken().beginColumn - 1, '*');
}
for (OrderByElement item : ps.getOrderByElements()) {
Column c = (Column) item.getExpression();
SimpleNode astNode = c.getASTNode();
assertNotNull(astNode);
b.setCharAt(astNode.jjtGetFirstToken().beginColumn - 1, '#');
}
assertEquals("SELECT *, * FROM mytable order by #, #", b.toString());
}
use of net.sf.jsqlparser.statement.select.OrderByElement in project JSqlParser by JSQLParser.
the class ExpressionVisitorAdapter method visit.
@Override
public void visit(AnalyticExpression expr) {
if (expr.getExpression() != null) {
expr.getExpression().accept(this);
}
if (expr.getDefaultValue() != null) {
expr.getDefaultValue().accept(this);
}
if (expr.getOffset() != null) {
expr.getOffset().accept(this);
}
if (expr.getKeep() != null) {
expr.getKeep().accept(this);
}
for (OrderByElement element : expr.getOrderByElements()) {
element.getExpression().accept(this);
}
if (expr.getWindowElement() != null) {
expr.getWindowElement().getRange().getStart().getExpression().accept(this);
expr.getWindowElement().getRange().getEnd().getExpression().accept(this);
expr.getWindowElement().getOffset().getExpression().accept(this);
}
}
Aggregations