Skip to content

Commit

Permalink
Merge pull request #911 from im-auld/query-filters-issue-164
Browse files Browse the repository at this point in the history
Query filters issue 164
  • Loading branch information
spulec committed May 11, 2017
2 parents 0934b43 + cdc007f commit 95f759c
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
3 changes: 3 additions & 0 deletions moto/dynamodb2/responses.py
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,7 @@ def query(self):
else:
# 'KeyConditions': {u'forum_name': {u'ComparisonOperator': u'EQ', u'AttributeValueList': [{u'S': u'the-key'}]}}
key_conditions = self.body.get('KeyConditions')
query_filters = self.body.get("QueryFilter")
if key_conditions:
hash_key_name, range_key_name = dynamodb_backend2.get_table_keys_name(
name, key_conditions.keys())
Expand Down Expand Up @@ -357,6 +358,8 @@ def query(self):
else:
range_comparison = None
range_values = []
if query_filters:
filter_kwargs.update(query_filters)
index_name = self.body.get('IndexName')
exclusive_start_key = self.body.get('ExclusiveStartKey')
limit = self.body.get("Limit")
Expand Down
41 changes: 41 additions & 0 deletions tests/test_dynamodb2/test_dynamodb_table_with_range_key.py
Original file line number Diff line number Diff line change
Expand Up @@ -838,6 +838,47 @@ def test_query_filter_gte():
list(results).should.have.length_of(2)


@requires_boto_gte("2.9")
@mock_dynamodb2_deprecated
def test_query_non_hash_range_key():
table = create_table_with_local_indexes()
item_data = [
{
'forum_name': 'Cool Forum',
'subject': 'Check this out!',
'version': '1',
'threads': 1,
},
{
'forum_name': 'Cool Forum',
'subject': 'Read this now!',
'version': '3',
'threads': 5,
},
{
'forum_name': 'Cool Forum',
'subject': 'Please read this... please',
'version': '2',
'threads': 0,
}
]
for data in item_data:
item = Item(table, data)
item.save(overwrite=True)

results = table.query(
forum_name__eq='Cool Forum', version__gt="2"
)
results = list(results)
results.should.have.length_of(1)

results = table.query(
forum_name__eq='Cool Forum', version__lt="3"
)
results = list(results)
results.should.have.length_of(2)


@mock_dynamodb2_deprecated
def test_reverse_query():
conn = boto.dynamodb2.layer1.DynamoDBConnection()
Expand Down

0 comments on commit 95f759c

Please sign in to comment.