Hi all,

I have a few issues with this patch which is supposed to address 
performance with filters.

1) It causes floating point strings to be truncated to an integer. The 
following simple test case illustrates:

Literal l = ff.literal("0.1");
Object o = l.evaluate(null);
assertEquals( "0.1", o.toString() );

2) Many of the changes are simply reformats, which make it hard to 
figure out exactly what was changed.

This is a bit of a serious bug imho. It means that whenever the literal 
is evaluated without a class passed in (which is more often then not) 
the values is truncated to an integer. One serious consequence in 
GeoServer is the inability to use floating point numbers in SLD filters.

Regardless, the offending code is in LiteralExpressionImpl:

Class[] contexts = new Class[] {Integer.class, BigInteger.class, 
Double.class};
for (int i = 0; i < contexts.length && parsedValue == null; i++) {
    parsedValue = v.value(contexts[i]);
}

To try and guess the return type is unsafe imho. If the converter api 
guaranteed that an exception would be thrown in the case of going from a 
floating point string to an integer then maybe... but it does not, nor 
am i sure it should.

I am also confused, because the jira issues refers to a slow down due to 
converters... but this code is still going through the converter pipeline.

Regardless, if the point here is performance i suggest we do the following:

I suggest the following change:

try {
   //try integer
   parsedValue = Integer.parseInt( literal );
}
catch( NumberFormatException e ) {
    //try double
    try {
       parsedValue = Double.parseDouble( literal );
    }
    catch( NumberFormatException e ) {
      //try big decimal
      try {
         parsedValue = new BigDecimal( literal );
      }
      catch( NumberFormatException e ) {
         //give up
      }
    }
}

-- 
Justin Deoliveira
The Open Planning Project
[EMAIL PROTECTED]

-------------------------------------------------------------------------
This SF.net email is sponsored by the 2008 JavaOne(SM) Conference 
Don't miss this year's exciting event. There's still time to save $100. 
Use priority code J8TL2D2. 
http://ad.doubleclick.net/clk;198757673;13503038;p?http://java.sun.com/javaone
_______________________________________________
Geotools-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-devel

Reply via email to