Search in sources :

Example 36 with Expression

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

the class CCJSqlParserUtilTest method testParseCondExpressionIssue471.

@Test
public void testParseCondExpressionIssue471() throws Exception {
    Expression result = CCJSqlParserUtil.parseCondExpression("(SSN,SSM) IN ('11111111111111', '22222222222222')");
    assertEquals("(SSN, SSM) IN ('11111111111111', '22222222222222')", result.toString());
}
Also used : Expression(net.sf.jsqlparser.expression.Expression) Test(org.junit.Test)

Example 37 with Expression

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

the class CCJSqlParserUtilTest method testParseCondExpressionNonPartial.

@Test
public void testParseCondExpressionNonPartial() throws Exception {
    Expression result = CCJSqlParserUtil.parseCondExpression("x=92 and y=29", false);
    assertEquals("x = 92 AND y = 29", result.toString());
}
Also used : Expression(net.sf.jsqlparser.expression.Expression) Test(org.junit.Test)

Example 38 with Expression

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

the class CCJSqlParserUtilTest method testParseCondExpression.

@Test
public void testParseCondExpression() throws Exception {
    Expression result = CCJSqlParserUtil.parseCondExpression("a+b>5 and c<3");
    assertEquals("a + b > 5 AND c < 3", result.toString());
}
Also used : Expression(net.sf.jsqlparser.expression.Expression) Test(org.junit.Test)

Example 39 with Expression

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

the class CCJSqlParserUtilTest method testParseCondExpressionNonPartial2.

@Test(expected = JSQLParserException.class)
public void testParseCondExpressionNonPartial2() throws Exception {
    Expression result = CCJSqlParserUtil.parseCondExpression("x=92 lasd y=29", false);
    System.out.println(result.toString());
}
Also used : Expression(net.sf.jsqlparser.expression.Expression) Test(org.junit.Test)

Example 40 with Expression

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

the class CNFConverter method pushAnd.

/**
 * This helper function is used to deal with pushing and up:
 * generally, pop the top element out of the stack,
 * use BFS to traverse the tree and push and up.
 * It will case the expression tree to have the and as the new
 * root and multiple or as the children. Push them on the queue
 * and repeat the same process until the newly generated or
 * operator does not have any and operators in it(which means no
 * elements will be added into the queue). when one level is
 * finished, regroup the tree. Do this until the stack is empty,
 * the result will be the expression in CNF form.
 * @param stack the stack stores a list of combined data.
 */
private void pushAnd(Stack<Mule> stack) {
    int level = 0;
    if (!stack.isEmpty()) {
        level = stack.peek().level;
    }
    while (!stack.isEmpty()) {
        Mule mule = stack.pop();
        /* we finish a level, uniform the tree by calling gather. */
        if (level != mule.level) {
            gather();
            level = mule.level;
        }
        Queue<Mule> queue = new LinkedList<Mule>();
        /* this time we do not need to take down the level of the
             * tree, so simply set a 0 to the last parameter. */
        Mule combined = new Mule(mule.parent, mule.child, 0);
        queue.offer(combined);
        while (!queue.isEmpty()) {
            Mule get = queue.poll();
            Expression parent = get.parent;
            Expression child = get.child;
            /* based on the code above, the stack only have the expression
                 * which they are multi operators. so safely convert them. */
            MultipleExpression children = (MultipleExpression) child;
            int index = 0;
            MultiAndExpression and = null;
            /* find the children that the child is an multi and operator. */
            for (; index < children.size(); index++) {
                if (children.getChild(index) instanceof MultiAndExpression) {
                    and = (MultiAndExpression) children.getChild(index);
                    break;
                }
            }
            if (index == children.size()) {
                continue;
            }
            children.removeChild(index);
            MultipleExpression parents = (MultipleExpression) parent;
            List<Expression> list = new ArrayList<Expression>();
            MultiAndExpression newand = new MultiAndExpression(list);
            parents.setChild(parents.getIndex(children), newand);
            for (int i = 0; i < and.size(); i++) {
                Expression temp = clone.shallowCopy(children);
                MultipleExpression mtemp = (MultipleExpression) temp;
                mtemp.addChild(mtemp.size(), and.getChild(i));
                newand.addChild(i, mtemp);
                queue.offer(new Mule(newand, mtemp, 0));
            }
        }
    }
}
Also used : BinaryExpression(net.sf.jsqlparser.expression.BinaryExpression) LikeExpression(net.sf.jsqlparser.expression.operators.relational.LikeExpression) NotExpression(net.sf.jsqlparser.expression.NotExpression) Expression(net.sf.jsqlparser.expression.Expression) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList)

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