PrintVisitor v = new PrintVisitor();
v.visitQuery(SQLQueryParser.parse(sql));
String got = v.toString();
<<<<<<< HEAD
assertEquals(removeTzSuffix(expected), removeTzSuffix(got));
}
private static final Pattern REMOVE_TZ_PATTERN = Pattern.compile("(.*)(\\+.*|Z)'\\)$");
private String removeTzSuffix(String value) {
Matcher matcher = REMOVE_TZ_PATTERN.matcher(value);
if (matcher.matches() == false) throw new RuntimeException(REMOVE_TZ_PATTERN + " pattern does not match " + value);
return matcher.group(1);
=======
got = got.substring(0, got.length() - 8); // truncate timezone
assertEquals(expected, got);
sql = "select foo from docs where x = 1 AND x=2 AND x = 3";
expected = "SELECT foo FROM docs WHERE AND(x = 1, x = 2, x = 3)";
SQLQuery query = SQLQueryParser.parse(sql);
// AndExpression is not generated by the parser, build it by hand
Predicate pred = query.where.predicate;
List operands = new LinkedList();
operands.add(((Expression) pred.lvalue).lvalue);
operands.add(((Expression) pred.lvalue).rvalue);
operands.add(pred.rvalue);
query = new SQLQuery(query.select, query.from, new WhereClause(
new MultiExpression(Operator.AND, operands)), query.groupBy,
query.having, query.orderBy);
v = new PrintVisitor();
v.visitQuery(query);
assertEquals(expected, v.toString());
>>>>>>> 6ccc8df2095d3a89a586b7b13e1fdbf8ab1683ef
}
} |