"Unable to perform query operation.", "Invalid query"

1470
7
Jump to solution
09-27-2021 09:10 PM
LuisDelValle
New Contributor II

Hi there,

I have a backend component that is sending a few requests to our ArcGIS server (Note: both Ids 2 and 8 are pointing to Views in the DB). The first request below is successful and data is retrieved

URL: {baseUrl}/rest/services/{environment}/ContactView/FeatureServer/2/query?where=1%3D1&f=pjson&resultOffset=0&resultRecordCount=500&outFields=*&returnGeometry=false
Response:
{ "objectIdFieldName": "ObjectId", "globalIdFieldName": "", "fields": [ { "name": "Name", "alias": "Name", "type": "esriFieldTypeString", "length": 255 } ], "features": [
// Data
], "exceededTransferLimit": true }

However, the second request fails

URL: {baseUrl}/rest/services/{environment}/ContactView/FeatureServer/8/query?where=1%3D1&f=pjson&resultOffset=0&resultRecordCount=500&outFields=*&returnGeometry=false
Response:
{ "error": { "code": 400, "message": "Unable to complete operation.", "details": [ "Unable to perform query operation.", "Invalid query" ] } }

 The interesting thing from the second request is that if I remove the values from resultOffset and resultRecordCount, e.g.

resultOffset=&resultRecordCount=

The request is successful and comes back with data.

Not sure what would be the issue - hope someone can shed some light on this

UPDATE: a bit more information about this, the DB View in question doesn't seem to have any problem, if I query the View directly in the DB, the View will return data. It is only when I use resultOffset and resultRecordCount in my REST request that makes this fails.

Does anyone know how ArcGIS tranlsate the REST query into a SQL statement?  Would it be something like the sql below?:

select * from MyView
ORDER BY (Select null)
OFFSET 0 ROWS FETCH NEXT 500 ROWS ONLY

If I run that sql above directly in the DB, I get data back from the View

Thanks in advance,

Luis

Tags (2)
0 Kudos
1 Solution

Accepted Solutions
LongDinh
Occasional Contributor II

Does resultOffset and resultRecordCount work with returnIDsOnly set to True?

Thinking that there might be something in the definition of the View? I can share that if needed

This will help. Are you you applying a definition query on top of the view before publishing or is this the actual definition in the Database? Are you creating the view from arcpy/ArcGIS Pro/ArcMap or through a DBMS management software?

I suspect it might be something to do with the indexing on the table. I found this BUG report which notes that setting the resultOffset and resultRecordCount with returnIDsOnly returns inconsistent results. 

View solution in original post

7 Replies
LongDinh
Occasional Contributor II

Hi @LuisDelValle,

Have you tried assigning the outFields parameter to a known field or * in your GET request to see if the result changes?

Also try the setting true the returnCountOnly and returnIDsOnly parameters to see if the service is connecting correctly. 

Is your second table (id:8) a spatial or non-spatial view?

LuisDelValle
New Contributor II

Hi @LongDinh ,

Thanks for your quick response. Both tables are non-spatial views. 

I have tried assigning the outFields parameter but the result doesn't change. If I set returnCountOnly and returnIDsOnly the request is successful demonstrating that the service is connecting correctly.

It seems that only if I set resultOffset and resultRecordCount the request will fail.

Thinking that there might be something in the definition of the View? I can share that if needed

0 Kudos
LongDinh
Occasional Contributor II

Does resultOffset and resultRecordCount work with returnIDsOnly set to True?

Thinking that there might be something in the definition of the View? I can share that if needed

This will help. Are you you applying a definition query on top of the view before publishing or is this the actual definition in the Database? Are you creating the view from arcpy/ArcGIS Pro/ArcMap or through a DBMS management software?

I suspect it might be something to do with the indexing on the table. I found this BUG report which notes that setting the resultOffset and resultRecordCount with returnIDsOnly returns inconsistent results. 

LuisDelValle
New Contributor II

Hi @LongDinh ,

The view is being created with ArcGIS Pro but as far as I know a definition query hasn't been applied on top of the view - I will check into that and share my findings and if anything changes after that.

Thanks a lot for sharing that article - including the exceededTransferLimit property in the query is something that is not being done right now in the backend component - I will also check with that and share my findings.

I'm including the definition of the view. It looks messy but it is basically a series of UNION ALL of five tables for something we call internally Features (I have changed the name of the tables to FeatureOne, FeatureTwo, etc) with joins to other two tables we call Organisation and OrganisationFeatureLayer (the last one an associative table) 

0 Kudos
LongDinh
Occasional Contributor II

I was not expecting such a large definition 😅 If ArcGIS Pro has validated it, I have confidence it is an acceptable table for publishing. 

The exceededTransferLimit property is a query result response property. You would generally perform the large query (e.g. where 1=1) and if exceededTransferLimit=True in your result json response, your application should then:

  • Get the total query record count using returnCountOnly, then
  • Paginate using the resultOffset and resultRecordCount parameters where resultOffset is your REST service's maxRecordCount property and the total query record count, respectively.

This is workflow is described in ArcGIS REST APIs - Services reference - Query (Feature Service/Layer)

 

 

0 Kudos
LuisDelValle
New Contributor II

Hi @LongDinh ,

It took me a while to get back to this post but here I am. Problem solved.

The issue was when we were creating the view using ArcGIS Pro, there was something missing in that process that created and issue (my theory) with the definition of the REST API for that view, that ultimately created that problem when we were sending the request with resultOffset and resultRecordCount.

When we created the View with a script using arcpy, that issue was solved and sending a request with resultOffset and resultRecordCount is now working.

I'm marking one of your comments as the solution as you initially asked/suggested about how we were creating the view.

Thanks a lot mate

LongDinh
Occasional Contributor II

Glad to hear you reached a solution!

Happy to help wherever I can 🙂