2

I am trying to get a count of my records from an Olingo ODATA (version 2) result set similar to the one below:

http://services.odata.org/OData/OData.svc/Categories/$count

The above url returns 3, and there are 3 'values' as you can see if you remove the /$count.

I am working on local host, where this url:

localhost/odata/livingODATA/address/

returns a result set, but localhost/odata/livingODATA/address/$count returns the error:

TEIID30088 Unrelated order by column g0.id cannot be used in a SET query, with SELECT DISTINCT, or GROUP BY

I have tried adding an order by, nothing seems to help.

Daniel
  • 3,541
  • 3
  • 33
  • 46
Ben Taliadoros
  • 7,003
  • 15
  • 60
  • 97

2 Answers2

1

Your problem is a illegal SQL query sent from olingo to TEIID, which might still make logical sense but triggers a TEIID Error. However, olingo is trying to SELECT simply count(*) while adding an unused ORDER BY g0.id to the query. For details on this error see those two bugs at the jboss community.

While this behaviour should be a issue for the Apache Olingo developer team, the $inlinecount=allpages uri-option could be at least for the moment a possible workaround. This adds a odata.count property to the result object containing a total count for your odata query, disregarding any $top or $skip options. This is a functionality meant for pagination purposes.

Official OData v2 Example

http://services.odata.org/OData/OData.svc/Products?$inlinecount=allpages

Your URI could be

localhost/odata/livingODATA/address?$inlinecount=allpages

or to prevent the service from loading all data at once you could add $top=0 and only load coun t(*):

localhost/odata/livingODATA/address?$inlinecount=allpages&$top=0

I hope this helps to get a few steps further.

Daniel
  • 3,541
  • 3
  • 33
  • 46
  • This was a great solution, however, this does not solve it for me. as the "count" is equal to whatever my value for top is. instead of showing odata.count: "5" it shows _count: "5" (or whatever is top). Im wondering if the data format on the db is an issue, it shouldnt be though – Ben Taliadoros Jun 09 '14 at 09:09
  • It seems the operation is part of the 4.0 version, but was referenced in the 2.0 'uri conventions': http://www.odata.org/documentation/odata-version-2-0/uri-conventions/ poor docs. thanks for the help – Ben Taliadoros Jun 10 '14 at 08:25
1

You can override the value for inline count by

ODataEntityProviderPropertiesBuilder propertiesBuilder = EntityProviderWriteProperties
                            .serviceRoot(serviceRoot).inlineCountType(InlineCount.ALLPAGES).inlineCount(dataSet.getTotal());

By the way it is working with version 2

Swetha
  • 41
  • 2