@Test
public void itShouldGenerateLingualQuery() throws ParseException {
String dateInString = "2012-01-10 00:00:00";
remoteFilterJson.setCondition("(f1 not in ('1') and f2 = '"+dateInString+"') or (f3=23.23 and f4=1234.123)");
String DATE_FORMAT = "yyyy-MM-dd HH:mm:ss";
SimpleDateFormat formatter = new SimpleDateFormat(DATE_FORMAT);
formatter.setTimeZone(TimeZone.getDefault());
Date date = formatter.parse(dateInString);
formatter.setTimeZone(TimeZone.getTimeZone("GMT"));
dateInString = formatter.format(date);
ANTLRInputStream stream = new ANTLRInputStream(remoteFilterJson.getCondition());
QueryParserLexer lexer = new QueryParserLexer(stream);
CommonTokenStream tokenStream = new CommonTokenStream(lexer);
QueryParserParser parser = new QueryParserParser(tokenStream);
parser.removeErrorListeners();
LingualQueryCreator customVisitor = new LingualQueryCreator(remoteFilterJson.getSchema());
String lingualExpression = customVisitor.visit(parser.eval());
Assert.assertEquals(
"((\"f1\" is not null and \"f1\" not in('1')) and \"f2\" = timestamp '"+dateInString+"') or (\"f3\" = cast(23.23 as float) and \"f4\" = cast(1234.123 as double))",
lingualExpression);
}
LingualQueryCreatorTest.java 文件源码
java
阅读 23
收藏 0
点赞 0
评论 0
项目:Hydrograph
作者:
评论列表
文章目录