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

Geert Graat commented on OLINGO-1628:
-------------------------------------

I encountered the same issue. As the reporter states, this problem only arises 
when you use the IN operator. When you pass in a double value (1.0) for a 
property of type Edm.Double, it is somehow recognized by Olingo as a 
Edm.Decimal type. That should not be a problem, as the [OData 
ABNF|https://docs.oasis-open.org/odata/odata/v4.01/os/abnf/odata-abnf-construction-rules.txt]
 (4.0.1, which includes the IN operator) states:
{code:java}
doubleValue  = decimalValue {code}
However, when the ExpressionParser validates the type of the IN parameters with 
the property, using the method {{checkInExpressionTypes}} in the 
{{ExpressionParser}} class (see top of the stacktrace above), it checks if the 
property type (Edm.Double) is compatible with the expression type 
(Edm.Decimal). Surprisingly, it is not!

More surprisingly, if you would compare the two the other way around, they are 
compatible!

Look at the method {{isCompatible}} of the {{EdmDecimal}} class:
{code:java}
@Override
public boolean isCompatible(final EdmPrimitiveType primitiveType) {
  return primitiveType instanceof EdmByte
      || primitiveType instanceof EdmSByte
      || primitiveType instanceof EdmInt16
      || primitiveType instanceof EdmInt32
      || primitiveType instanceof EdmInt64
      || primitiveType instanceof EdmSingle
      || primitiveType instanceof EdmDouble
      || primitiveType instanceof EdmDecimal;
} {code}
You see that it includes EdmDouble.

Now the same method in the EdmDouble class:
{code:java}
@Override
public boolean isCompatible(final EdmPrimitiveType primitiveType) {
  return primitiveType instanceof EdmByte
      || primitiveType instanceof EdmSByte
      || primitiveType instanceof EdmInt16
      || primitiveType instanceof EdmInt32
      || primitiveType instanceof EdmInt64
      || primitiveType instanceof EdmSingle
      || primitiveType instanceof EdmDouble;
} {code}
Note that this does *not* include the EdmDecimal type, which is the reason an 
exception is thrown.

So I think this should be fixed by adding the EdmDecimal type to the list in 
the {{isCompatible}} method of the {{EdmDouble}} class.
h3. Workaround

When I change the client to generate double values like this:
{code:java}
1.0e0 (representing 1.0) {code}
it is recognized as an Edm.Double type instead of Edm.Decimal, which passes the 
type check.

> Filter using in operator for double fails with "The types 'Edm.Decimal' and 
> 'Edm.Double' are not compatible."
> -------------------------------------------------------------------------------------------------------------
>
>                 Key: OLINGO-1628
>                 URL: https://issues.apache.org/jira/browse/OLINGO-1628
>             Project: Olingo
>          Issue Type: Bug
>          Components: odata4-server
>    Affects Versions: Version (Java) V4 5.0.0
>            Reporter: Seyoum Belay
>            Priority: Major
>
> With Olingo version 5.0, filter using in operator for double values fails 
> with "The types 'Edm.Decimal' and 'Edm.Double' are not compatible."
> For example, /Products?$filter=Quantity eq 1.5 is sucessful, but 
> /Products?$filter=Quantity in (1.5) fails with "The types 'Edm.Decimal' and 
> 'Edm.Double' are not compatible."
> Metadata:
>  <Property Name="Quantity" Type="Edm.Double"/>
>  
> Stack trace: 
> "The types 'Edm.Decimal' and 'Edm.Double' are not compatible."
>  Incompatible types.
>      at 
> org.apache.olingo.server.core.uri.parser.ExpressionParser.checkInExpressionTypes(ExpressionParser.java:372)
>      at 
> org.apache.olingo.server.core.uri.parser.ExpressionParser.parseExprPrimary(ExpressionParser.java:343)
>      at 
> org.apache.olingo.server.core.uri.parser.ExpressionParser.parseExprUnary(ExpressionParser.java:326)
>      at 
> org.apache.olingo.server.core.uri.parser.ExpressionParser.parseExprMul(ExpressionParser.java:295)
>      at 
> org.apache.olingo.server.core.uri.parser.ExpressionParser.parseExprAdd(ExpressionParser.java:281)
>      at 
> org.apache.olingo.server.core.uri.parser.ExpressionParser.parseExprRel(ExpressionParser.java:238)
>      at 
> org.apache.olingo.server.core.uri.parser.ExpressionParser.parseExprEquality(ExpressionParser.java:220)
>      at 
> org.apache.olingo.server.core.uri.parser.ExpressionParser.parseAnd(ExpressionParser.java:206)
>      at 
> org.apache.olingo.server.core.uri.parser.ExpressionParser.parseExpression(ExpressionParser.java:192)
>      at 
> org.apache.olingo.server.core.uri.parser.ExpressionParser.parse(ExpressionParser.java:186)
>      at 
> org.apache.olingo.server.core.uri.parser.FilterParser.parse(FilterParser.java:48)



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to