You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@jackrabbit.apache.org by Cheng Zhang <zh...@yahoo.com> on 2009/01/17 05:48:48 UTC

A bug? Query returns wrong records

Hi,

I have a node type oag:CustomerReviews. Below is the dump from NodeTypeManager.


{http://www.openandgreen.com/oag/1.0}CustomerReviews
    Supertypes
        {http://www.jcp.org/jcr/nt/1.0}unstructured
    Mixin    false
    OrderableChildNodes    false
    PrimaryItemName    <null>
    PropertyDefinition (declared in {http://www.openandgreen.com/oag/1.0}CustomerReviews) id=1471555952
        Name        {}AverageRating
        RequiredType    Double
        ValueConstraints    
        DefaultValue    
        AutoCreated    false
        Mandatory    false
        OnVersion    COPY
        Protected    false
        Multiple    false
    PropertyDefinition (declared in {http://www.openandgreen.com/oag/1.0}CustomerReviews) id=-1454872483
        Name        {}TotalReviewPages
        RequiredType    Long
        ValueConstraints    
        DefaultValue    
        AutoCreated    false
        Mandatory    false
        OnVersion    COPY
        Protected    false
        Multiple    false
    PropertyDefinition (declared in {http://www.openandgreen.com/oag/1.0}CustomerReviews) id=-1820687444
        Name        {}TotalReviews
        RequiredType    Long
        ValueConstraints    
        DefaultValue    
        AutoCreated    false
        Mandatory    false
        OnVersion    COPY
        Protected    false
        Multiple    false
    NodeDefinition (declared in {http://www.openandgreen.com/oag/1.0}CustomerReviews) id=-1424822435
        Name        {}Review
        RequiredPrimaryType    {http://www.openandgreen.com/oag/1.0}Review
        AutoCreated    false
        Mandatory    false
        OnVersion    COPY
        Protected    false
        AllowsSameNameSiblings    true


I created a node for this type. Below is the document view export result.

<?xml version="1.0" encoding="UTF-8"?>
<CustomerReviews jcr:primaryType="oag:CustomerReviews" AverageRating="4.5" TotalReviewPages="37" TotalReviews="182" xmlns:fn="http://www.w3.org/2005/xpath-functions" xmlns:fn_old="http://www.w3.org/2004/10/xpath-functions" xmlns:xs="http://www.w3.org/2001/XMLSchema" 
xmlns:jcr="http://www.jcp.org/jcr/1.0" 
xmlns:oag="http://www.openandgreen.com/oag/1.0" xmlns:mix="http://www.jcp.org/jcr/mix/1.0" xmlns:sv="http://www.jcp.org/jcr/sv/1.0" xmlns:rep="internal" xmlns:nt="http://www.jcp.org/jcr/nt/1.0">
<Review jcr:primaryType="oag:Review"/>
</CustomerReviews>


Problem: query below returns one row which is wrong.

  select * from oag:CustomerReviews where AverageRating > 5

but query below is ok:

  select * from oag:CustomerReviews where AverageRating > 5.0

A bug?

Thanks a lot,
Kevin


Re: A bug? Query returns wrong records

Posted by Marcel Reutegger <ma...@gmx.net>.
Hi,

On Tue, Jul 28, 2009 at 19:54, Mark Waschkowski<mw...@gmail.com> wrote:
> Hi Alex,
> Thanks for the info, I am also running into this issue. If I am doing an
> xpath query on a double property, does that mean I have to ensure that a
> '.0' is on the end?

correct, that will indicate to the query handler that it is of type double

> Or is there a way to 'cast' (or otherwise
> suggest) the value in the xpath?
>
> ie. something similar to:
> nodes/*[@gba> xs:double(10000)]

that's currently not supported.

> I would rather cast the double rather than appending '.0' on the end of my
> query, as some of the queries we run are generated based on user input which
> may or may not include the '.0'. My code will be more understandable with a
> cast rather than a check for a '.' and appending of a '.0' if one doesn't
> exist...

it adds some lines of code but the following should do the trick:

        double value = ....
        NumberFormat nf = NumberFormat.getNumberInstance();
        nf.setMinimumFractionDigits(1);
        nf.setMaximumFractionDigits(Integer.MAX_VALUE);
        String v = nf.format(value);

regards
 marcel

Re: A bug? Query returns wrong records

Posted by Mark Waschkowski <mw...@gmail.com>.
Hi Alex,
Thanks for the info, I am also running into this issue. If I am doing an
xpath query on a double property, does that mean I have to ensure that a
'.0' is on the end? Or is there a way to 'cast' (or otherwise
suggest) the value in the xpath?

ie. something similar to:
nodes/*[@gba> xs:double(10000)]

I would rather cast the double rather than appending '.0' on the end of my
query, as some of the queries we run are generated based on user input which
may or may not include the '.0'. My code will be more understandable with a
cast rather than a check for a '.' and appending of a '.0' if one doesn't
exist...

Thank you,

Mark

On Tue, Jan 20, 2009 at 5:25 AM, Alexander Klimetschek <ak...@day.com>wrote:

> On Sat, Jan 17, 2009 at 5:48 AM, Cheng Zhang <zh...@yahoo.com>
> wrote:
> > Problem: query below returns one row which is wrong.
> >
> >  select * from oag:CustomerReviews where AverageRating > 5
> >
> > but query below is ok:
> >
> >  select * from oag:CustomerReviews where AverageRating > 5.0
> >
> > A bug?
>
> AFAIK a double value (such as AverageRating) must be compared against
> a double literal in sql/xpath queries, ie. include a dot like "5.0".
> The JCR spec does not mandate long<->double conversion in that case:
> "In case of type mismatches in a comparison LONGs can be converted to
> DOUBLEs".
>
> [1] http://www.day.com/specs/jcr/1.0/8.5.4.3_WHERE.html
>
> Regards,
> Alex
>
> --
> Alexander Klimetschek
> alexander.klimetschek@day.com
>

Re: A bug? Query returns wrong records

Posted by Alexander Klimetschek <ak...@day.com>.
On Sat, Jan 17, 2009 at 5:48 AM, Cheng Zhang <zh...@yahoo.com> wrote:
> Problem: query below returns one row which is wrong.
>
>  select * from oag:CustomerReviews where AverageRating > 5
>
> but query below is ok:
>
>  select * from oag:CustomerReviews where AverageRating > 5.0
>
> A bug?

AFAIK a double value (such as AverageRating) must be compared against
a double literal in sql/xpath queries, ie. include a dot like "5.0".
The JCR spec does not mandate long<->double conversion in that case:
"In case of type mismatches in a comparison LONGs can be converted to
DOUBLEs".

[1] http://www.day.com/specs/jcr/1.0/8.5.4.3_WHERE.html

Regards,
Alex

-- 
Alexander Klimetschek
alexander.klimetschek@day.com