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());
}
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());
}
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());
}
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());
}
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));
}
}
}
}
Aggregations