Hi Shashi, you just need to create a Date object representing the date in your query, and supply that as the argument to lessThan()/greaterThan() etc. Hope that helps
Sent from my Android
--
-- You received this message because you are subscribed to the "cqengine-discuss" group.
http://groups.google.com/group/cqengine-discuss
---
You received this message because you are subscribed to the Google Groups "cqengine-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cqengine-discu...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
private static final Attribute<TickSummary, ChronoLocalDate> DATE = new MultiValueAttribute<TickSummary, ChronoLocalDate>("date") {
@Override
public Iterable<ChronoLocalDate> getValues(TickSummary o, QueryOptions queryOptions) {
return o.getDetails().stream().map(tick -> tick.getDate()).collect(Collectors.toList());
}
};
private static void queryByCqnString(IndexedCollection<TickSummary> summaries) {
System.out.println("******* Query by CQN string *******");
Map<String, Attribute<TickSummary, ?>> attributes = Maps.newHashMap();
attributes.put("date", DATE);
CQNParser<TickSummary> parser = CQNParser.forPojoWithAttributes(TickSummary.class, attributes);
String queryAsString = "greaterThan(\"date\", \"LocalDate.parse(2015-04-20)\")";
System.out.println(queryAsString);
Query<TickSummary> query = parser.query(queryAsString);
DeduplicationOption deduplication = deduplicate(DeduplicationStrategy.MATERIALIZE);
ResultSet<TickSummary> resultSet = summaries.retrieve(query, queryOptions(deduplication));
resultSet.forEach(summary -> System.out.println(summary));
}
Exception in thread "main" com.googlecode.cqengine.query.parser.common.InvalidQueryException: Failed to parse query at com.googlecode.cqengine.query.parser.cqn.CQNParser.parse(CQNParser.java:76) at com.googlecode.cqengine.query.parser.common.QueryParser.query(QueryParser.java:161) at com.fast.tests.cpengine.MainCPEngine.queryByCqnString(MainCPEngine.java:95) at com.fast.tests.cpengine.MainCPEngine.main(MainCPEngine.java:83) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:497) at com.intellij.rt.execution.application.AppMain.main(AppMain.java:140)Caused by: java.lang.IllegalStateException: Failed to parse value using a valueOf() method in class 'java.time.chrono.ChronoLocalDate': LocalDate.parse(2015-04-20) at com.googlecode.cqengine.query.parser.cqn.support.FallbackValueParser.parse(FallbackValueParser.java:43) at com.googlecode.cqengine.query.parser.common.QueryParser.parseValue(QueryParser.java:128) at com.googlecode.cqengine.query.parser.common.QueryParser.parseValue(QueryParser.java:113) at com.googlecode.cqengine.query.parser.cqn.support.CQNAntlrListener.exitGreaterThanQuery(CQNAntlrListener.java:108) at com.googlecode.cqengine.query.parser.cqn.grammar.CQNGrammarParser$GreaterThanQueryContext.exitRule(CQNGrammarParser.java:1014) at org.antlr.v4.runtime.tree.ParseTreeWalker.exitRule(ParseTreeWalker.java:71) at org.antlr.v4.runtime.tree.ParseTreeWalker.walk(ParseTreeWalker.java:54) at org.antlr.v4.runtime.tree.ParseTreeWalker.walk(ParseTreeWalker.java:52) at org.antlr.v4.runtime.tree.ParseTreeWalker.walk(ParseTreeWalker.java:52) at org.antlr.v4.runtime.tree.ParseTreeWalker.walk(ParseTreeWalker.java:52) at com.googlecode.cqengine.query.parser.cqn.CQNParser.parse(CQNParser.java:69) ... 8 moreCaused by: java.lang.NoSuchMethodException: java.time.chrono.ChronoLocalDate.valueOf(java.lang.String) at java.lang.Class.getMethod(Class.java:1786) at com.googlecode.cqengine.query.parser.cqn.support.FallbackValueParser.parse(FallbackValueParser.java:39) ... 18 more
But with the type-safe Query API, you can easily create complex queries - even from UI !Easier to build a string? I don't think so. Creating string queries quickly became very complicated, because you have to properly escape everything, have to remember to put ' and ' in appropriate places, with parenthesis, etc.And in the end, you get an untestable, string creator mass, which fails miserably in execution when something changes.
CQNParser<TickSummary> parser = CQNParser.forPojoWithAttributes(TickSummary.class, attributes);
parser.registerValueParser(ChronoLocalDate.class, new ValueParser<ChronoLocalDate>() {
@Override
protected ChronoLocalDate parse(Class<? extends ChronoLocalDate> aClass, String s) {
return LocalDate.parse(s.replaceAll("\"", ""));
}
});
Just one little curiosity. With the query "greaterThan("date", "2015-04-20")", the string given to ValueParser is ""2015-04-20"". With the two extras ". If I remove them to the query there is a parsing error.
Yes in fact it is a webapp. The GUI and the server (which contains the CPEngine) are not on the same desktop.So I could use a String query (easier to serialize and create) or a pojo wich describes the statements.Is the Query object fully serializable?
From now, we need to send a Query to be executed by the server. As you said, it seems that Query object is not serializable. So we have to translate the user query into a serializable object in order to send it to the server. We could use a string or any pojo (with fields like attributeName, filterType (greaterThan, ...), filterValue(date/double/...), sortType(ascending/descending), etc).Do you see what I mean?