Search in sources :

Example 56 with Expression

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

the class CNFTest method test5.

/**
 * This is the case when we test the tree that only contains AND
 * operator without having an OR operator.
 *
 * Here is the original expression tree:
 *                            NOT
 *                             |
 *                            ( )
 *                             |
 *                             OR
 *                /                          \
 *              ( )                          ( )
 *               |                            |
 *              NOT                           OR
 *               |                       /          \
 *              AND                    LIKE          =
 *        /            \           /        \      /    \
 *       >              <         S.C      "%%"   S.D   {t '12:04:34'}
 *    /     \         /    \
 *  S.A     3.5      S.B    4
 *
 * Here is the converted expression tree:
 *
 *                                                AND
 *                                           /             \
 *                                         AND              =
 *                                  /            \        /   \
 *                                AND         NOT LIKE   S.D  {t '12:04:34'}
 *                         /             \    /      \
 *                        >              <   S.C    "%%"
 *                   /       \         /    \
 *                  S.A      3.5      S.B    4
 */
@Test
public void test5() throws Exception {
    Expression expr = CCJSqlParserUtil.parseCondExpression("NOT ((NOT (S.A > 3.5 AND S.B < 4)) OR " + "(S.C LIKE '\"%%\"' OR S.D = {t '12:04:34'}))");
    Expression expected = CCJSqlParserUtil.parseCondExpression("S.A > 3.5 AND S.B < 4 AND S.C NOT LIKE '\"%%\"' " + "AND NOT S.D = {t '12:04:34'}");
    Expression result = CNFConverter.convertToCNF(expr);
    assertEquals(expected.toString(), result.toString());
}
Also used : Expression(net.sf.jsqlparser.expression.Expression) Test(org.junit.Test)

Example 57 with Expression

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

the class ExecuteDeParserTest method shouldUseProvidedExpressionVisitorWhenDeParsingExecute.

@Test
public void shouldUseProvidedExpressionVisitorWhenDeParsingExecute() {
    Execute execute = new Execute();
    String name = "name";
    ExpressionList exprList = new ExpressionList();
    List<Expression> expressions = new ArrayList<Expression>();
    Expression expression1 = mock(Expression.class);
    Expression expression2 = mock(Expression.class);
    execute.setName(name);
    execute.setExprList(exprList);
    exprList.setExpressions(expressions);
    expressions.add(expression1);
    expressions.add(expression2);
    executeDeParser.deParse(execute);
    then(expression1).should().accept(expressionVisitor);
    then(expression2).should().accept(expressionVisitor);
}
Also used : Execute(net.sf.jsqlparser.statement.execute.Execute) Expression(net.sf.jsqlparser.expression.Expression) ArrayList(java.util.ArrayList) ExpressionList(net.sf.jsqlparser.expression.operators.relational.ExpressionList) Test(org.junit.Test)

Example 58 with Expression

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

the class ExpressionDeParserTest method shouldDeParseAnalyticExpressionWithDefaultValue.

@Test
public void shouldDeParseAnalyticExpressionWithDefaultValue() {
    AnalyticExpression analyticExpression = new AnalyticExpression();
    Expression expression = mock(Expression.class);
    Expression offset = mock(Expression.class);
    Expression defaultValue = mock(Expression.class);
    analyticExpression.setName("name");
    analyticExpression.setExpression(expression);
    analyticExpression.setOffset(offset);
    analyticExpression.setDefaultValue(defaultValue);
    will(appendToBuffer("expression")).given(expression).accept(expressionDeParser);
    will(appendToBuffer("offset")).given(offset).accept(expressionDeParser);
    will(appendToBuffer("default value")).given(defaultValue).accept(expressionDeParser);
    expressionDeParser.visit(analyticExpression);
    assertEquals("name(expression, offset, default value) 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 59 with Expression

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

the class StatementDeParserTest method shouldUseProvidedDeParsersWhenDeParsingReplaceWithoutItemsList.

@Test
@SuppressWarnings("PMD.JUnitTestsShouldIncludeAssert")
public void shouldUseProvidedDeParsersWhenDeParsingReplaceWithoutItemsList() {
    Replace replace = new Replace();
    Table table = new Table();
    List<Column> columns = new ArrayList<Column>();
    List<Expression> expressions = new ArrayList<Expression>();
    Column column1 = new Column();
    Column column2 = new Column();
    Expression expression1 = mock(Expression.class);
    Expression expression2 = mock(Expression.class);
    replace.setTable(table);
    replace.setColumns(columns);
    replace.setExpressions(expressions);
    columns.add(column1);
    columns.add(column2);
    expressions.add(expression1);
    expressions.add(expression2);
    statementDeParser.visit(replace);
    then(expression1).should().accept(expressionDeParser);
    then(expression2).should().accept(expressionDeParser);
}
Also used : Replace(net.sf.jsqlparser.statement.replace.Replace) Table(net.sf.jsqlparser.schema.Table) Column(net.sf.jsqlparser.schema.Column) Expression(net.sf.jsqlparser.expression.Expression) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 60 with Expression

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

the class StatementDeParserTest method shouldUseProvidedDeparsersWhenDeParsingDelete.

@Test
@SuppressWarnings("PMD.JUnitTestsShouldIncludeAssert")
public void shouldUseProvidedDeparsersWhenDeParsingDelete() {
    Delete delete = new Delete();
    Table table = new Table();
    Expression where = mock(Expression.class);
    List<OrderByElement> orderByElements = new ArrayList<OrderByElement>();
    OrderByElement orderByElement1 = new OrderByElement();
    OrderByElement orderByElement2 = new OrderByElement();
    Expression orderByElement1Expression = mock(Expression.class);
    Expression orderByElement2Expression = mock(Expression.class);
    delete.setTable(table);
    delete.setWhere(where);
    delete.setOrderByElements(orderByElements);
    orderByElements.add(orderByElement1);
    orderByElements.add(orderByElement2);
    orderByElement1.setExpression(orderByElement1Expression);
    orderByElement2.setExpression(orderByElement2Expression);
    statementDeParser.visit(delete);
    then(where).should().accept(expressionDeParser);
    then(orderByElement1Expression).should().accept(expressionDeParser);
    then(orderByElement2Expression).should().accept(expressionDeParser);
}
Also used : Delete(net.sf.jsqlparser.statement.delete.Delete) Table(net.sf.jsqlparser.schema.Table) Expression(net.sf.jsqlparser.expression.Expression) ArrayList(java.util.ArrayList) OrderByElement(net.sf.jsqlparser.statement.select.OrderByElement) Test(org.junit.Test)

Aggregations

Expression (net.sf.jsqlparser.expression.Expression)92 AndExpression (net.sf.jsqlparser.expression.operators.conditional.AndExpression)30 Test (org.junit.Test)30 ArrayList (java.util.ArrayList)26 BinaryExpression (net.sf.jsqlparser.expression.BinaryExpression)25 Column (net.sf.jsqlparser.schema.Column)19 SignedExpression (net.sf.jsqlparser.expression.SignedExpression)18 ExpressionList (net.sf.jsqlparser.expression.operators.relational.ExpressionList)17 Table (net.sf.jsqlparser.schema.Table)14 CompiledSQLExpression (herddb.sql.expressions.CompiledSQLExpression)12 LikeExpression (net.sf.jsqlparser.expression.operators.relational.LikeExpression)12 AlterExpression (net.sf.jsqlparser.statement.alter.AlterExpression)12 NotExpression (net.sf.jsqlparser.expression.NotExpression)11 StatementExecutionException (herddb.model.StatementExecutionException)10 Select (net.sf.jsqlparser.statement.select.Select)10 AnalyticExpression (net.sf.jsqlparser.expression.AnalyticExpression)9 CaseExpression (net.sf.jsqlparser.expression.CaseExpression)9 KeepExpression (net.sf.jsqlparser.expression.KeepExpression)9 OrExpression (net.sf.jsqlparser.expression.operators.conditional.OrExpression)9 PlainSelect (net.sf.jsqlparser.statement.select.PlainSelect)9