Thanks Nicolas for your report.  
On Friday 17 December 2010 11:04:25 am [email protected] 
wrote:
> Hello,
>
> I am using filters through CQL.
>
> I am trying to execute this extract of code which test that encoding and
> decoding works with CQL and dates.
>
> The main problem is that BEFORE and DURING temporal predicates are
> converted in simple property value comparison (lessthan or greaterThan).
> Whereas, with the AFTER temporal predicate it works fine because it is
> never converted but kept as temporal. How can we fix that issue?
>
> Thank you very much for your help.

The CQL.toCQL(...) method was donated but the original developer could not 
finish the work (the is the reason why it have a warning "work in progress").
Right now this method does not cover all cql syntax. Temporal predicate is one 
example. It is still required a lot of work. 

>
> Here is a description of my tests:
>
> //test 1 with AFTER temporal predicate
> Filter filter2Expected = CQL.toFilter("attr AFTER 2006-12-31T01:30:00Z");
> String ecqlEncoding2 = CQL.toCQL(filter2Expected);
> Filter ecqlDecoding2 = CQL.toFilter(ecqlEncoding2);
>
> //test 2 with BEFORE temporal predicate
> Filter filter3Expected = CQL.toFilter("attr BEFORE 2006-12-31T01:30:00Z");
> String ecqlEncoding3 = CQL.toCQL(filter3Expected);
> Filter ecqlDecoding3 = CQL.toFilter(ecqlEncoding3);
>
> //test 3 with DURING temporal predicate
> Filter filter4Expected = CQL.toFilter("dateAttr DURING
> 2006-10-10T01:30:00Z/2010-12-31T01:30:00Z"); String ecqlEncoding4 =
> CQL.toCQL(filter4Expected);
> Filter ecqlDecoding4 = CQL.toFilter(ecqlEncoding4);
>
> Test1 works fine:
> filter2Expected.toString() == "[ attr > Sun Dec 31 01:30:00 CET 2006 ]"
> ecqlEncoding2  == "attr AFTER 2006-12-31T01:30:00Z"
> ecqlDecoding2.toString() == "[ attr > Sun Dec 31 01:30:00 CET 2006 ]"
>
> Test2 does not work because the line " CQL.toFilter(ecqlEncoding3);" throws
> an exception: org.geotools.filter.text.cql2.CQLException: Encountered "<
> 2006-12-31T01:30:00Z" at line 1, column 6.
>
> In debug, what I saw is that the CQL.toCQL does not return a result similar
> to the AFTER predicate: ecqlEncoding3  == "attr < 2006-12-31T01:30:00Z" Or
> with in the previous test using AFTER predicate : ecqlEncoding2  == "attr
> AFTER 2006-12-31T01:30:00Z"
>
> It sounds like the toCQL function does not consider the BEFORE predicate as
> a temporal one but as a simple lessThan property predicate.
>
> Tes3 does not work for 2 reasons:
> --> the first one is the same as in test2 : temporal predicate is
> transformed in simple lessThan or greaterThan property predicates whereas
> it should not do that (like with AFTER predicate). --> the second one is an
> issue that I localized in the code of FilterToCQL.
> PropertyIsLessThanOrEqualTo. This method (and other similars) expects that
> the name of the property is always in expression1 of the filter. But it is
> not always the case. Typically in case of DURING predicate, a classcast
> exception is raised : java.lang.ClassCastException:
> org.geotools.filter.LiteralExpressionImpl cannot be cast to
> org.opengis.filter.expression.PropertyName. For this second problem, a
> workarounf could be to test expression1.class , like this:
>
> public Object visit(PropertyIsLessThanOrEqualTo filter, Object extraData) {
>         LOGGER.finer("exporting PropertyIsLessThanOrEqualTo");
>         StringBuffer output = asStringBuffer(extraData);
>
>         Expression expr1 = filter.getExpression1();
>         Expression expr2 = filter.getExpression2();
>
>         if(PropertyName.class.isInstance(expr1)){
>               PropertyName propertyName = (PropertyName) expr1;
>               propertyName.accept(this, output);
>               output.append(" <= ");
>               expr2.accept(this, output);
>         }
>         else{
>               PropertyName propertyName = (PropertyName) expr2;
>               propertyName.accept(this, output);
>               output.append(" >= ");
>               expr1.accept(this, output);
>         }
>
>         return output;
>     }
>
>
Good!, I am going to add this patch in trunk. Your collaboration is welcome.

all the best

>
> ---------------------------------------------------------------------------
>--- Lotusphere 2011
> Register now for Lotusphere 2011 and learn how
> to connect the dots, take your collaborative environment
> to the next level, and enter the era of Social Business.
> http://p.sf.net/sfu/lotusphere-d2d
> _______________________________________________
> Geotools-gt2-users mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users

-- 
Mauricio Pazos
www.axios.es
------------------------------------------------------------------------------
Lotusphere 2011
Register now for Lotusphere 2011 and learn how
to connect the dots, take your collaborative environment
to the next level, and enter the era of Social Business.
http://p.sf.net/sfu/lotusphere-d2d
_______________________________________________
Geotools-gt2-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users

Reply via email to