You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@olingo.apache.org by Giacomo Pati <gi...@apache.org> on 2014/09/27 11:05:25 UTC

How to filter on entities having null navigation property

Hi all

Can't get this going. I have created a simple JPA OData service with
Olingo2. Which contains 2 entities:

Person:
  String name;
  Address homeAddress;
  Address workAddress;

Address:
  ...

I'd like to see which Persons do not have a workAddress, which I've put to:
.../My.svc/Persons?$filter=workAddress eq null

Which reslts in Invalid filter expression: 'null ne homeAddress'

I was digging into the code an saw that there is no such case defined in
class ParameterSetCombination, only SimpleTypes are supported. Then I was
running up and down the OData spec but I might have missed where it say
navigation properties are not allowed in equality expression in a filter.

Can anyone comment on the above?

Ciao & many thanks
-- 
Giacomo

Re: How to filter on entities having null navigation property

Posted by Giacomo Pati <gi...@pati.ch>.
Hi Christian

Many thanks for the answers, see my comments inlined below.

2014-09-29 15:22 GMT+02:00 Amend, Christian <ch...@sap.com>:

>  Hi Giacomo,
>
>
>
> - What makes Navigation Properties different from Properties?
>
> A Navigation Property represents only a link between entities while a
> property holds data. So a filer like “$filter=Address eq 1” cannot be
> resolved since there is no real value to compare. The example you gave with
> “Address eq null” makes sense but is unfortunately  not supported by the
> specification.
>

I do understand and I'll check with our .NET guys how there the
implementation look like as to me the spec isn't crystal clear in this
regards.

>
>
> - If I cannot change Address from a navigation property to a complex
> property how can I filter based on navigations?
>
> You can specify Simple and Complex Properties from the endpoint of the
> navigation as your values that you would like to filter on e.g. “Address/Id
> eq 1” or “Address/City eq null” . Please note that these filters can become
> quite complex and are not implemented in our samples. If you are interested
> in how to implement the filter visitor please have a look here:
> http://olingo.apache.org/doc/odata2/tutorials/Olingo_Tutorial_AdvancedRead_FilterVisitor.html
>

Ok, thanks, I do know about the FilterVisitors . I'll have to check how
this is possible for our case.

>
>
> If you need this feature to be in the JPA Processor implementation you can
> open a feature request in our JIRA(
> https://issues.apache.org/jira/browse/OLINGO/?selectedTab=com.atlassian.jira.jira-projects-plugin:summary-panel
> ) or implement it yourself and contribute it to Apache Olingo if you like.
>

We already identified some areas where the JPA processor implementation can
improve, but for this I'll switch to the dev@ list regarding potential JIRA
tickets and patches.

Ciao & thanks

>
>
> Best Regards,
>
> Christian
>
>
>
> *From:* Giacomo Pati [mailto:giacomo@pati.ch]
> *Sent:* Samstag, 27. September 2014 18:28
> *To:* user@olingo.apache.org
> *Subject:* Re: How to filter on entities having null navigation property
>
>
>
> Hi Michael
>
> 2014-09-27 12:29 GMT+02:00 mibo <mi...@apache.org>:
> >
> > Hi Giacomo,
> >
> > unfortunately I have to disappoint you because in section "4.5. Filter
> System Query Option ($filter)" it is defined that "$filter operators
> supports references to properties and literals" only.
> > (see:
> http://www.odata.org/documentation/odata-version-2-0/uri-conventions/)
> >
> > > The expression language that is used in $filter operators supports
> references to properties and literals.
>
> What makes a Navigation Property any different from a Property (except
> that only equality operators are meaningful in $filter expression, which is
> also true for some primitive types IIRC)?
>
> > > The literal values can be strings enclosed in single quotes, numbers
> and boolean values (true or false) or any of the additional literal
> representations shown in the Abstract Type System section.
> >
> > But as workaround you probably could model your Address as complex
> property.
> > Like in the sample service:
> >
> http://services.odata.org/OData/OData.svc/Suppliers?$format=json&$filter=Address%20ne%20null
> >
> http://services.odata.org/OData/OData.svc/Suppliers?$format=json&$filter=Address%20eq%20null
> >
>
> Unfortunately, I do not really understand what you mean by "model your
> Address as complex property". I'm not in charge to change the supplied JPA
> model, so I cannot change the Address type to a embedded one (if you've
> meant that)
>
> > Kind regards,
> > Michael
> >
> >
> > Am 27.09.2014 um 11:05 schrieb Giacomo Pati <gi...@apache.org>:
> >
> > > Hi all
> > >
> > > Can't get this going. I have created a simple JPA OData service with
> Olingo2. Which contains 2 entities:
> > >
> > > Person:
> > >   String name;
> > >   Address homeAddress;
> > >   Address workAddress;
> > >
> > > Address:
> > >   ...
> > >
> > > I'd like to see which Persons do not have a workAddress, which I've
> put to: .../My.svc/Persons?$filter=workAddress eq null
> > >
> > > Which reslts in Invalid filter expression: 'null ne homeAddress'
> > >
> > > I was digging into the code an saw that there is no such case defined
> in class ParameterSetCombination, only SimpleTypes are supported. Then I
> was running up and down the OData spec but I might have missed where it say
> navigation properties are not allowed in equality expression in a filter.
> > >
> > > Can anyone comment on the above?
> --
> Giacomo
>
-- 
Giacomo

RE: How to filter on entities having null navigation property

Posted by "Amend, Christian" <ch...@sap.com>.
Hi Giacomo,

- What makes Navigation Properties different from Properties?
A Navigation Property represents only a link between entities while a property holds data. So a filer like “$filter=Address eq 1” cannot be resolved since there is no real value to compare. The example you gave with “Address eq null” makes sense but is unfortunately  not supported by the specification.

- If I cannot change Address from a navigation property to a complex property how can I filter based on navigations?
You can specify Simple and Complex Properties from the endpoint of the navigation as your values that you would like to filter on e.g. “Address/Id eq 1” or “Address/City eq null” . Please note that these filters can become quite complex and are not implemented in our samples. If you are interested in how to implement the filter visitor please have a look here: http://olingo.apache.org/doc/odata2/tutorials/Olingo_Tutorial_AdvancedRead_FilterVisitor.html

If you need this feature to be in the JPA Processor implementation you can open a feature request in our JIRA(https://issues.apache.org/jira/browse/OLINGO/?selectedTab=com.atlassian.jira.jira-projects-plugin:summary-panel ) or implement it yourself and contribute it to Apache Olingo if you like.

Best Regards,
Christian

From: Giacomo Pati [mailto:giacomo@pati.ch]
Sent: Samstag, 27. September 2014 18:28
To: user@olingo.apache.org
Subject: Re: How to filter on entities having null navigation property


Hi Michael

2014-09-27 12:29 GMT+02:00 mibo <mi...@apache.org>>:
>
> Hi Giacomo,
>
> unfortunately I have to disappoint you because in section "4.5. Filter System Query Option ($filter)" it is defined that "$filter operators supports references to properties and literals" only.
> (see: http://www.odata.org/documentation/odata-version-2-0/uri-conventions/)
>
> > The expression language that is used in $filter operators supports references to properties and literals.

What makes a Navigation Property any different from a Property (except that only equality operators are meaningful in $filter expression, which is also true for some primitive types IIRC)?

> > The literal values can be strings enclosed in single quotes, numbers and boolean values (true or false) or any of the additional literal representations shown in the Abstract Type System section.
>
> But as workaround you probably could model your Address as complex property.
> Like in the sample service:
> http://services.odata.org/OData/OData.svc/Suppliers?$format=json&$filter=Address%20ne%20null
> http://services.odata.org/OData/OData.svc/Suppliers?$format=json&$filter=Address%20eq%20null
>

Unfortunately, I do not really understand what you mean by "model your Address as complex property". I'm not in charge to change the supplied JPA model, so I cannot change the Address type to a embedded one (if you've meant that)

> Kind regards,
> Michael
>
>
> Am 27.09.2014 um 11:05 schrieb Giacomo Pati <gi...@apache.org>>:
>
> > Hi all
> >
> > Can't get this going. I have created a simple JPA OData service with Olingo2. Which contains 2 entities:
> >
> > Person:
> >   String name;
> >   Address homeAddress;
> >   Address workAddress;
> >
> > Address:
> >   ...
> >
> > I'd like to see which Persons do not have a workAddress, which I've put to: .../My.svc/Persons?$filter=workAddress eq null
> >
> > Which reslts in Invalid filter expression: 'null ne homeAddress'
> >
> > I was digging into the code an saw that there is no such case defined in class ParameterSetCombination, only SimpleTypes are supported. Then I was running up and down the OData spec but I might have missed where it say navigation properties are not allowed in equality expression in a filter.
> >
> > Can anyone comment on the above?
--
Giacomo

Re: How to filter on entities having null navigation property

Posted by Giacomo Pati <gi...@pati.ch>.
Hi Michael

2014-09-27 12:29 GMT+02:00 mibo <mi...@apache.org>:
>
> Hi Giacomo,
>
> unfortunately I have to disappoint you because in section "4.5. Filter
System Query Option ($filter)" it is defined that "$filter operators
supports references to properties and literals" only.
> (see:
http://www.odata.org/documentation/odata-version-2-0/uri-conventions/)
>
> > The expression language that is used in $filter operators supports
references to properties and literals.

What makes a Navigation Property any different from a Property (except that
only equality operators are meaningful in $filter expression, which is also
true for some primitive types IIRC)?

> > The literal values can be strings enclosed in single quotes, numbers
and boolean values (true or false) or any of the additional literal
representations shown in the Abstract Type System section.
>
> But as workaround you probably could model your Address as complex
property.
> Like in the sample service:
>
http://services.odata.org/OData/OData.svc/Suppliers?$format=json&$filter=Address%20ne%20null
>
http://services.odata.org/OData/OData.svc/Suppliers?$format=json&$filter=Address%20eq%20null
>

Unfortunately, I do not really understand what you mean by "model your
Address as complex property". I'm not in charge to change the supplied JPA
model, so I cannot change the Address type to a embedded one (if you've
meant that)

> Kind regards,
> Michael
>
>
> Am 27.09.2014 um 11:05 schrieb Giacomo Pati <gi...@apache.org>:
>
> > Hi all
> >
> > Can't get this going. I have created a simple JPA OData service with
Olingo2. Which contains 2 entities:
> >
> > Person:
> >   String name;
> >   Address homeAddress;
> >   Address workAddress;
> >
> > Address:
> >   ...
> >
> > I'd like to see which Persons do not have a workAddress, which I've put
to: .../My.svc/Persons?$filter=workAddress eq null
> >
> > Which reslts in Invalid filter expression: 'null ne homeAddress'
> >
> > I was digging into the code an saw that there is no such case defined
in class ParameterSetCombination, only SimpleTypes are supported. Then I
was running up and down the OData spec but I might have missed where it say
navigation properties are not allowed in equality expression in a filter.
> >
> > Can anyone comment on the above?
-- 
Giacomo

Re: How to filter on entities having null navigation property

Posted by mibo <mi...@apache.org>.
Hi Giacomo,

unfortunately I have to disappoint you because in section "4.5. Filter System Query Option ($filter)" it is defined that "$filter operators supports references to properties and literals" only.
(see: http://www.odata.org/documentation/odata-version-2-0/uri-conventions/)

> The expression language that is used in $filter operators supports references to properties and literals. 
> The literal values can be strings enclosed in single quotes, numbers and boolean values (true or false) or any of the additional literal representations shown in the Abstract Type System section.

But as workaround you probably could model your Address as complex property.
Like in the sample service:
http://services.odata.org/OData/OData.svc/Suppliers?$format=json&$filter=Address%20ne%20null
http://services.odata.org/OData/OData.svc/Suppliers?$format=json&$filter=Address%20eq%20null

Kind regards,
Michael


Am 27.09.2014 um 11:05 schrieb Giacomo Pati <gi...@apache.org>:

> Hi all
> 
> Can't get this going. I have created a simple JPA OData service with Olingo2. Which contains 2 entities:
> 
> Person:
>   String name;
>   Address homeAddress;
>   Address workAddress;
> 
> Address:
>   ...
> 
> I'd like to see which Persons do not have a workAddress, which I've put to: .../My.svc/Persons?$filter=workAddress eq null
> 
> Which reslts in Invalid filter expression: 'null ne homeAddress'
> 
> I was digging into the code an saw that there is no such case defined in class ParameterSetCombination, only SimpleTypes are supported. Then I was running up and down the OData spec but I might have missed where it say navigation properties are not allowed in equality expression in a filter. 
> 
> Can anyone comment on the above?
> 
> Ciao & many thanks 
> -- 
> Giacomo