[ 
https://issues.apache.org/jira/browse/PHOENIX-1075?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14057823#comment-14057823
 ] 

Kyle Buzsaki commented on PHOENIX-1075:
---------------------------------------

The way we were parsing multiplication and division only caused problems when 
combined with truncating integer division, so I don't think that addition / 
subtraction will be affected.

In the interest of consistency though, I went ahead and switched the addition 
and subtraction to use a single rule. After doing so, all of the 
ArithmeticQueryIT tests still pass but a single unit test started failing. 
Here's the error message:

{code}
<<< FAILURE! - in org.apache.phoenix.compile.QueryMetaDataTest
testDateSubstractExpressionMetaData1(org.apache.phoenix.compile.QueryMetaDataTest)
  Time elapsed: 0.007 sec  <<< FAILURE!
java.lang.AssertionError: expected:<java.math.BigDecimal> but was:<null>
        at org.junit.Assert.fail(Assert.java:88)
        at org.junit.Assert.failNotEquals(Assert.java:743)
        at org.junit.Assert.assertEquals(Assert.java:118)
        at org.junit.Assert.assertEquals(Assert.java:144)
        at 
org.apache.phoenix.compile.QueryMetaDataTest.testDateSubstractExpressionMetaData1(QueryMetaDataTest.java:214)
{code}

Any guesses as to why? If I comment out that one assert, everything else passes 
fine.

> Mathematical order of operations are improperly evaluated.
> ----------------------------------------------------------
>
>                 Key: PHOENIX-1075
>                 URL: https://issues.apache.org/jira/browse/PHOENIX-1075
>             Project: Phoenix
>          Issue Type: Bug
>            Reporter: Kyle Buzsaki
>         Attachments: PHOENIX-1075.patch
>
>
> The root of the issue is that, as things are now, multiplication and division 
> don't actually have the same precedence in the grammar. Division is always 
> grouped more tightly than multiplication and is evaluated first. Most of the 
> time, this doesn't matter, but combined with the truncating integer division 
> used by LongDivideExpression it produces some unexpected and probably wrong 
> behavior. Below is an example:
> Expression: 6 * 4 / 3
> Evaluating left to right, this should reduce as follows:
> 6 * 4 / 3 
> 24 / 3
> 8
> As phoenix is now, division has a higher precedence than multiplication. 
> Therefore, the resulting expression tree looks like this:
> !http://i.imgur.com/2Zzsfpy.png!
> Because integer division in truncating, when the division evaluates the 
> expression tree looks like this:
> !http://i.imgur.com/3cLGD0e.png!
> Which then evaluates to 6.



--
This message was sent by Atlassian JIRA
(v6.2#6252)

Reply via email to