Re: Expression toString... Possible bug

From: Mikaël Cluseau (nwr..wrk.dyndns.org)
Date: Wed Oct 06 2004 - 16:45:09 EDT

  • Next message: Derek Rendall: "My Cayenne Modeler new feature wish list"

    Budhiraja, Nikhil wrote:

    >Mike,
    >
    >Thanks for the input...i just picked up a random expression, but we have several times more complex expressions, and
    >I don't see the parenthesis anywhere ..
    >
    >And, switching ANDS and OR's ALSO generates an erroneous output.
    >
    > Expression first = Expression.fromString("a = 1");
    > Expression second = Expression.fromString("a = 2");
    > Expression third = Expression.fromString("a != 1");
    > Expression fourth = Expression.fromString("a != 2");
    >
    > Expression firstAndSecond = first.orExp(second);
    > Expression thirdAndFourth = third.orExp(fourth);
    >
    > Expression finalExpression = firstAndSecond.andExp(thirdAndFourth);
    > System.out.println("finalExpression = "+finalExpression);
    >
    >
    >Produces,
    >finalExpression = a = 1 or a = 2 and a != 1 or a != 2
    >
    >
    >I guess it must be a bug then...
    >
    >
    Right, it's a bug because you loose the semantics you express *in the
    code*. It's a very common way of building expression, I really don't
    understand why it hasn't been pointed before... is there another
    "official" way of doing, people ?

    >
    >-----Original Message-----
    >From: Mikaël Cluseau [mailto:nwr..wrk.dyndns.org]
    >Sent: Wednesday, October 06, 2004 3:43 PM
    >To: Budhiraja, Nikhil
    >Subject: Re: Expression toString... Possible bug
    >
    >
    >I'm not a Cayenne guru, I'm more a newbie but...
    >
    >Budhiraja, Nikhil wrote:
    >
    >
    >
    >>E.g.
    >> Expression first = Expression.fromString("a = 1");
    >> Expression second = Expression.fromString("a = 2");
    >> Expression third = Expression.fromString("a != 1");
    >> Expression fourth = Expression.fromString("a != 2");
    >>
    >> Expression firstAndSecond = first.andExp(second);
    >> Expression thirdAndFourth = third.andExp(fourth);
    >>
    >> Expression finalExpression =
    >>firstAndSecond.orExp(thirdAndFourth);
    >> System.out.println("finalExpression =
    >>"+finalExpression);
    >>
    >>I expected to see
    >>((a = 1) and (a = 2)) or ((a != 1) and (a != 2))
    >>
    >>But instead I see
    >>finalExpression = a = 1 and a = 2 or a != 1 and a != 2
    >>
    >>
    >>
    >For me, it is not a bug because operator precedence will produce the
    >right tree :
    >
    >(E) --- OR --- AND --- a = 1
    > \ `--- a = 2
    > `--- AND --- a != 1
    > `--- a != 2
    >
    >Can you try to switch ANDs to ORs and OR to AND ? You should get (a = 1
    >OR a = 2) AND (a != 1 OR a != 2) if there is no bug, and a = 1 OR a = 2
    >AND a != 1 OR a != 2 if there is one.
    >
    >i.e. the first gives
    >
    >(E) --- AND --- OR --- a = 1
    > \ `--- a = 2
    > `--- OR --- a != 1
    > `--- a != 2
    >
    >and the second gives
    >
    >(E) --- OR --- OR --- a = 1
    > \ `--- AND --- a = 2
    > \ `--- a != 1
    > `--- a != 2
    >
    >which is very different of the expected semantics.
    >
    >
    >
    >>But if I do
    >>Expression.fromString("(a = 1 and a = 2) or (a != 1 and a != 2)"));
    >>
    >>I get the right result:
    >>finalExpression2 = ((a = 1) and (a = 2)) or ((a != 1) and (a != 2))
    >>
    >>
    >>
    >This is where I could find a bug (it might be a feature), since the same
    >operator precedence should remove useless parenthesis (the expression
    >should be in an abstract model).
    >
    >
    >



    This archive was generated by hypermail 2.0.0 : Wed Oct 06 2004 - 16:45:13 EDT