Google Query Language (GQL) Issues and Solution For Too Many Sub-queries Using Python

BadArgumentError: Cannot satisfy query — too many subqueries (max: 30, got 54). Probable cause: too many IN/!= filters in query.

GQL ‘IN’ does not allow sub-queries more than 30. For this purpose, I have divided sub queries into small chunks for less than or equal 30 sub-queries and result stored into an array.

  1. resultArray = []
  2. rLength = 0.0
  3. rCount = len(subQueryArray)
  4. rLength = len(subQueryArray)/29.0
  5. arrayLength = int(math.ceil( rLength ))
  6. # If subqueries are greater than 30 than divide sub-query length by 29 or 30
  7. if arrayLength > 1:
  8. for ii in range (0, arrayLength):
  9. #srange = start range, nrange = new range
  10. if ii == 0:
  11. srange = ii
  12. else:
  13. srange = nrange + 1
  14. nrange = 29 * (ii + 1)
  15. newList = []
  16. for nii in range (srange, nrange+1):
  17. if nii < rCount:
  18. newList.append(subQueryArray[nii])
  19. query = db.GqlQuery(“SELECT * FROM table_name ” +
    “WHERE req_id in :1”,
    newList)
  20. for result in query.run():
  21. # result.id belongs to table entity
  22. resultArray.append(result.id)