Skip to content

Commit

Permalink
Add QueryFilter support
Browse files Browse the repository at this point in the history
  • Loading branch information
krasnoukhov committed May 17, 2014
1 parent d6c92a2 commit 198c83d
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 0 deletions.
28 changes: 28 additions & 0 deletions lib/fake_dynamo/api.yml
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,34 @@
- :enum: [EQ, LE, LT, GE, GT, BEGINS_WITH, BETWEEN]
- :within: !ruby/range 1..2
- :required
QueryFilter:
- :map:
:key:
- :string
:value:
- :structure:
AttributeValueList:
- :list:
- :structure:
S:
- :string
N:
- :string
B:
- :blob
SS:
- :list:
- :string
NS:
- :list:
- :string
BS:
- :list:
- :blob
ComparisonOperator:
- :string
- :required
- :enum: [EQ, NE, LE, LT, GE, GT, NOT_NULL, NULL, CONTAINS, NOT_CONTAINS, BEGINS_WITH, IN, BETWEEN]
ScanIndexForward:
- :boolean
ExclusiveStartKey:
Expand Down
4 changes: 4 additions & 0 deletions lib/fake_dynamo/table.rb
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,10 @@ def query(data)
conditions = {}
end

if filter_conditions = data['QueryFilter']
conditions.merge!(filter_conditions)
end

results, last_evaluated_item, _ = filter(matched_items, conditions, data['Limit'], true, sack_attributes(data, index))

response = {'Count' => results.size}.merge(consumed_capacity(data))
Expand Down
25 changes: 25 additions & 0 deletions spec/fake_dynamo/table_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,26 @@ module FakeDynamo
}
end

let(:filter_query) do
{
'TableName' => 'Table1',
'Limit' => 5,
'KeyConditions' => {
'name' => {
'AttributeValueList' => [{'S' => 'att1'}],
'ComparisonOperator' => 'EQ'
},
},
'QueryFilter' => {
'score' => {
'AttributeValueList' => [{'N' => '3'}],
'ComparisonOperator' => 'GT'
},
'ScanIndexForward' => true
}
}
end

context 'query projection' do
let(:query) do
{
Expand Down Expand Up @@ -608,6 +628,11 @@ module FakeDynamo
result['Count'].should eq(5)
end

it 'should handle filter query' do
result = subject.query(filter_query)
result['Count'].should eq(2)
end

it 'should handle scanindexforward' do
result = subject.query(query)
result['Items'].first['age'].should eq({'N' => '3'})
Expand Down

0 comments on commit 198c83d

Please sign in to comment.