Search in sources :

Example 21 with Expression

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

the class ExpressionDeParserTest method shouldDeParseAnalyticExpressionWithExpression.

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

Example 22 with Expression

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

the class ExpressionDeParserTest method shouldDeParseAnalyticExpressionWithOffset.

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

Example 23 with Expression

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

the class ExpressionDeParserTest method shouldDeParseComplexAnalyticExpressionWithPartitionExpressionList.

@Test
public void shouldDeParseComplexAnalyticExpressionWithPartitionExpressionList() {
    AnalyticExpression analyticExpression = new AnalyticExpression();
    ExpressionList partitionExpressionList = new ExpressionList();
    List<Expression> partitionExpressions = new ArrayList<Expression>();
    Expression partitionExpression1 = mock(Expression.class);
    Expression partitionExpression2 = mock(Expression.class);
    analyticExpression.setName("name");
    analyticExpression.setPartitionExpressionList(partitionExpressionList);
    partitionExpressionList.setExpressions(partitionExpressions);
    partitionExpressions.add(partitionExpression1);
    partitionExpressions.add(partitionExpression2);
    will(appendToBuffer("partition expression 1")).given(partitionExpression1).accept(expressionDeParser);
    will(appendToBuffer("partition expression 2")).given(partitionExpression2).accept(expressionDeParser);
    expressionDeParser.visit(analyticExpression);
    assertEquals("name() OVER (PARTITION BY partition expression 1, partition expression 2 )", buffer.toString());
}
Also used : Expression(net.sf.jsqlparser.expression.Expression) KeepExpression(net.sf.jsqlparser.expression.KeepExpression) AnalyticExpression(net.sf.jsqlparser.expression.AnalyticExpression) ArrayList(java.util.ArrayList) AnalyticExpression(net.sf.jsqlparser.expression.AnalyticExpression) ExpressionList(net.sf.jsqlparser.expression.operators.relational.ExpressionList) Test(org.junit.Test)

Example 24 with Expression

use of net.sf.jsqlparser.expression.Expression 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);
}
Also used : Column(net.sf.jsqlparser.schema.Column) Expression(net.sf.jsqlparser.expression.Expression) ArrayList(java.util.ArrayList) Select(net.sf.jsqlparser.statement.select.Select) OrderByElement(net.sf.jsqlparser.statement.select.OrderByElement) SelectBody(net.sf.jsqlparser.statement.select.SelectBody) Update(net.sf.jsqlparser.statement.update.Update) Test(org.junit.Test)

Example 25 with Expression

use of net.sf.jsqlparser.expression.Expression 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);
}
Also used : Column(net.sf.jsqlparser.schema.Column) Expression(net.sf.jsqlparser.expression.Expression) ArrayList(java.util.ArrayList) OrderByElement(net.sf.jsqlparser.statement.select.OrderByElement) Update(net.sf.jsqlparser.statement.update.Update) Test(org.junit.Test)

Aggregations

Expression (net.sf.jsqlparser.expression.Expression)100 AndExpression (net.sf.jsqlparser.expression.operators.conditional.AndExpression)33 ArrayList (java.util.ArrayList)32 Test (org.junit.Test)30 BinaryExpression (net.sf.jsqlparser.expression.BinaryExpression)28 SignedExpression (net.sf.jsqlparser.expression.SignedExpression)26 ExpressionList (net.sf.jsqlparser.expression.operators.relational.ExpressionList)21 Column (net.sf.jsqlparser.schema.Column)19 CompiledSQLExpression (herddb.sql.expressions.CompiledSQLExpression)17 AlterExpression (net.sf.jsqlparser.statement.alter.AlterExpression)17 LikeExpression (net.sf.jsqlparser.expression.operators.relational.LikeExpression)15 StatementExecutionException (herddb.model.StatementExecutionException)14 NotExpression (net.sf.jsqlparser.expression.NotExpression)14 Table (net.sf.jsqlparser.schema.Table)14 CaseExpression (net.sf.jsqlparser.expression.CaseExpression)12 OrExpression (net.sf.jsqlparser.expression.operators.conditional.OrExpression)12 Column (herddb.model.Column)11 TimeKeyExpression (net.sf.jsqlparser.expression.TimeKeyExpression)11 InExpression (net.sf.jsqlparser.expression.operators.relational.InExpression)11 Function (net.sf.jsqlparser.expression.Function)10