Sigm0oid / dynamodb-geo.py

A python port of awslabs/dynamodb-geo, for dynamodb geospatial querying
MIT License
32 stars 21 forks source link

queryRectangle throws ValidationException for rangeKey predicate #43

Open ranchodeluxe opened 4 years ago

ranchodeluxe commented 4 years ago

Hello, We are doing a simple bbox request that results in this ValidationError below.

box_request = dynamodbgeo.QueryRectangleRequest(
dynamodbgeo.GeoPoint(lower_left["Latitude"], lower_left["Longitude"]),
dynamodbgeo.GeoPoint(upper_right["Latitude"], upper_right["Longitude"]), 
{
            "ProjectionExpression": "geoJson, hashKey, rangeKey",
})
response = gdm.queryRectangle(box_request)

We are trying to figure out why this error is only occurring for general geographic region. Our data has geohash keys and it works fine in other regions. I feel like queryRectangle might be changing the query condition while paginating? Wondering if anyone here has seen this type of behavior before?

{
  "errorMessage": "An error occurred (ValidationException) when calling the Query operation: The provided starting key does not match the range key predicate",
  "errorType": "ClientError",
  "stackTrace": [
    "  File \"/var/task/handler.py\", line 142, in handler\n    result_point = search_database_box(event_body)\n",
    "  File \"/var/task/handler.py\", line 102, in search_database_box\n    result_points = geo_load_box(datarequest['lower_left'],datarequest['upper_right'])\n",
    "  File \"/var/task/handler.py\", line 86, in geo_load_box\n    response = gdm.queryRectangle(box_request)\n",
    "  File \"/var/task/dynamodbgeo/GeoDataManager.py\", line 49, in queryRectangle\n    results = self.dispatchQueries(covering, QueryRectangleInput)\n",
    "  File \"/var/task/dynamodbgeo/GeoDataManager.py\", line 40, in dispatchQueries\n    geoQueryInput.QueryInput, hashKey, range))\n",
    "  File \"/var/task/dynamodbgeo/DynamoDBManager.py\", line 37, in queryGeohash\n    response = self.config.dynamoDBClient.query(**params)\n",
    "  File \"/var/task/botocore/client.py\", line 357, in _api_call\n    return self._make_api_call(operation_name, kwargs)\n",
    "  File \"/var/task/botocore/client.py\", line 676, in _make_api_call\n    raise error_class(parsed_response, operation_name)\n"
  ]
}
Sigm0oid commented 4 years ago

Hi @ ranchodeluxe Having a look...

Sigm0oid commented 4 years ago

@ranchodeluxe Can you please provide me with a sample of both hashmaps you're using here lower_left and lower_left?

wey314 commented 3 years ago

Hello, I am facing the same issue. Indeed it is due to pagination. The ExclusiveStartKey remains in the params dict, it must be removed before next query. Simple fix in DynamoDBManager.py:

        while 'LastEvaluatedKey' in response: 
            params['ExclusiveStartKey']=response['LastEvaluatedKey']
            response = self.config.dynamoDBClient.query(**params)
            del params['ExclusiveStartKey'] # cleanup
            data.extend(response['Items'])