-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlocal_secondary_index_spec.rb
116 lines (109 loc) · 4.63 KB
/
local_secondary_index_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
require 'aws-sdk-dynamodb'
RSpec.describe 'local secondary indexes' do
it 'query using an attribute other than the sort key on the table' do
delete_table('wins')
client = Aws::DynamoDB::Client.new(connection_info)
client.create_table({
table_name: 'wins',
attribute_definitions: [
{
attribute_name: 'finish',
attribute_type: 'S'
},
{
attribute_name: 'tournament',
attribute_type: 'S'
},
{
attribute_name: 'first_name',
attribute_type: 'S'
}
],
key_schema: [
{
attribute_name: 'finish',
key_type: 'HASH'
},
{
attribute_name: 'tournament',
key_type: 'RANGE'
}
],
local_secondary_indexes: [
{
index_name: 'lsi_first_name',
key_schema: [
{
attribute_name: 'finish',
key_type: 'HASH'
},
{
attribute_name: 'first_name',
key_type: 'RANGE'
}
],
projection: {
projection_type: 'ALL'
}
}
],
provisioned_throughput: {
read_capacity_units: 1,
write_capacity_units: 1
}
})
tournament_wins = {
reggio_emilia_93: {
'tournament': 'Reggio Emilia 1993',
'finish': 'first place',
'first_name': 'Vishy',
'last_name': 'Anand'
},
tilburg_92: {
'tournament': 'Tilburg 1992',
'finish': 'first place',
'category': 18,
'first_name': 'Vishy',
'last_name': 'Anand',
},
world_championship_2007: {
'tournament': 'WC 2007',
'finish': 'first place',
'first_name': 'Vishy',
'last_name': 'Anand'
},
world_championship_2008: {
'tournament': 'WC 2008',
'finish': 'first place',
'first_name': 'Vishy',
'last_name': 'Anand'
},
stavanger_2015: {
'tournament': 'Stavanger 2015',
'finish': 'second place',
'first_name': 'Vishy',
'last_name': 'Anand'
}
}
tournament_wins.each_value do |win|
client.put_item({
table_name: 'wins',
item: win
})
end
vishy_second_places_response = client.query({
table_name: 'wins',
index_name: 'lsi_first_name',
key_condition_expression: '#finish = :v_finish AND first_name = :v_fn',
expression_attribute_names: {
'#finish': 'finish'
},
expression_attribute_values: {
':v_finish': 'second place',
':v_fn': 'Vishy'
}
})
expect(vishy_second_places_response).not_to be_nil
expect(vishy_second_places_response.items.first['tournament']).to eql('Stavanger 2015')
end
end