ddbcli 0.4.2.beta2 → 0.5.0.beta
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +34 -28
- data/lib/ddbcli/cli/help.rb +33 -28
- data/lib/ddbcli/ddb-driver.rb +126 -100
- data/lib/ddbcli/ddb-parser.tab.rb +776 -720
- data/lib/ddbcli/ddb-parser.y +53 -32
- data/lib/ddbcli/version.rb +1 -1
- data/spec/ddbcli_spec.rb +18 -6
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2c0e2c3493edb0a71f2b4676531af7dac96db8be
|
4
|
+
data.tar.gz: 066e62c63e99dbf54126bbfe679488846dbec728
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bea729ff5ae101274f98a0d95d666a4beb88ced9fa41149eb3be44ae5d32848fba539097a60206404bcf3639e52daab8751618ffeddea62e30ee42bf7ceb0fc3
|
7
|
+
data.tar.gz: 1bc777cd214d0237918569a2bb4e6ab400b57be6ab74085f81dae3a93bbd8baa9deb880e9a87e6f0c8499fb6116a431223652d11c0a6900e85262dbf5bc6c523
|
data/README.md
CHANGED
@@ -69,16 +69,16 @@ DEBUG: 'i' contains: [{"gender"=>"F"}, {"gender"=>"F"}, {"gender"=>"F"}] ...
|
|
69
69
|
##### Query #####
|
70
70
|
|
71
71
|
SHOW TABLES [LIMIT num] [LIKE '...']
|
72
|
-
|
72
|
+
display a table list
|
73
73
|
|
74
74
|
SHOW TABLE STATUS [LIKE '...']
|
75
|
-
|
75
|
+
display table statues
|
76
76
|
|
77
77
|
SHOW REGIONS
|
78
|
-
|
78
|
+
display a region list
|
79
79
|
|
80
80
|
SHOW CREATE TABLE table_name
|
81
|
-
|
81
|
+
display a CREATE TABLE statement
|
82
82
|
|
83
83
|
CREATE TABLE table_name (
|
84
84
|
key_name {STRING|NUMBER|BINARY} HASH
|
@@ -90,56 +90,62 @@ CREATE TABLE table_name (
|
|
90
90
|
, GLOBAL INDEX index2_name (hash_attr2 {STRING|NUMBER|BINARY} [, range_attr2 {STRING|NUMBER|BINARY}]) {ALL|KEYS_ONLY|INCLUDE (attr, ...)} [READ = num WRITE = num]
|
91
91
|
, ...]
|
92
92
|
) READ = num WRITE = num [STREAM = {true|false|NEW_IMAGE|OLD_IMAGE|NEW_AND_OLD_IMAGES|KEYS_ONLY}]
|
93
|
-
|
93
|
+
create a table
|
94
94
|
|
95
95
|
CREATE TABLE table_name LIKE another_table_name [READ = num WRITE = num] [STREAM = {true|false|NEW_IMAGE|OLD_IMAGE|NEW_AND_OLD_IMAGES|KEYS_ONLY}]
|
96
|
-
|
96
|
+
create a table like another table
|
97
97
|
|
98
98
|
DROP TABLE table_name [, table_name2, ...]
|
99
|
-
|
99
|
+
delete tables
|
100
100
|
|
101
101
|
ALTER TABLE table_name {READ = num WRITE = num|STREAM = {true|false|NEW_IMAGE|OLD_IMAGE|NEW_AND_OLD_IMAGES|KEYS_ONLY}}
|
102
|
-
|
102
|
+
update the provisioned throughput
|
103
103
|
|
104
|
-
ALTER TABLE table_name CHANGE INDEX index_name READ = num WRITE = num
|
105
|
-
|
104
|
+
ALTER TABLE table_name CHANGE GLOBAL INDEX index_name READ = num WRITE = num
|
105
|
+
update GSI provisioned throughput
|
106
|
+
|
107
|
+
ALTER TABLE table_name ADD GLOBAL INDEX index_name (hash_attr1 {STRING|NUMBER|BINARY} [, range_attr1 {STRING|NUMBER|BINARY}]) {ALL|KEYS_ONLY|INCLUDE (attr, ...)} READ = num WRITE = num
|
108
|
+
add GSI
|
109
|
+
|
110
|
+
ALTER TABLE table_name DROP GLOBAL INDEX index_name
|
111
|
+
delete GSI
|
106
112
|
|
107
113
|
GET {*|attr1,attr2,...} FROM table_name WHERE key1 = '...' AND ...
|
108
|
-
|
114
|
+
get items
|
109
115
|
|
110
116
|
INSERT INTO table_name (attr1, attr2, ...) VALUES ('val1', 'val2', ...), ('val3', 'val4', ...), ...
|
111
117
|
INSERT INTO table_name SELECT ...
|
112
118
|
INSERT INTO table_name SELECT ALL ...
|
113
|
-
|
119
|
+
create items
|
114
120
|
|
115
121
|
UPDATE table_name {SET|ADD} attr1 = 'val1', ... WHERE key1 = '...' AND ...
|
116
122
|
UPDATE ALL table_name {SET|ADD} attr1 = 'val1', ... [WHERE attr1 = '...' AND ...] [LIMIT limit]
|
117
|
-
|
123
|
+
update items
|
118
124
|
("UPDATE" can update only one record. Please use "UPDATE ALL", when you update more than one.)
|
119
125
|
|
120
126
|
UPDATE table_name DEL[ETE] attr1, ... WHERE key1 = '...' AND ...
|
121
127
|
UPDATE ALL table_name DEL[ETE] attr1, ... [WHERE attr1 = '...' AND ...] [LIMIT limit]
|
122
|
-
|
128
|
+
update items (delete attribute)
|
123
129
|
|
124
130
|
DELETE FROM table_name WHERE key1 = '...' AND ..
|
125
131
|
DELETE ALL FROM table_name WHERE [WHERE attr1 = '...' AND ...] [ORDER {ASC|DESC}] [LIMIT limit]
|
126
|
-
|
132
|
+
delete items
|
127
133
|
("DELETE" can delete only one record. Please use "DELETE ALL", when you update more than one.)
|
128
134
|
|
129
135
|
SELECT {*|attr1,attr2,...|COUNT(*)} FROM table_name [USE INDEX (index_name)] [WHERE key1 = '...' AND ...] [HAVING attr1 = '...' AND ...] [ORDER {ASC|DESC}] [LIMIT limit]
|
130
136
|
SELECT ALL {*|attr1,attr2,...|COUNT(*)} FROM table_name [WHERE attr1 = '...' AND ...] [LIMIT limit]
|
131
137
|
SELECT segment/total_segments {*|attr1,attr2,...|COUNT(*)} FROM table_name [WHERE attr1 = '...' AND ...] [LIMIT limit]
|
132
|
-
|
138
|
+
query using the Query/Scan action
|
133
139
|
see http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/QueryAndScan.html
|
134
140
|
|
135
141
|
DESC[RIBE] table_name
|
136
|
-
|
142
|
+
display information about the table
|
137
143
|
|
138
144
|
USE region_or_endpoint
|
139
|
-
|
145
|
+
change an endpoint
|
140
146
|
|
141
147
|
NEXT
|
142
|
-
|
148
|
+
display a continuation of a result
|
143
149
|
(NEXT statement is published after SELECT statement)
|
144
150
|
|
145
151
|
|
@@ -218,16 +224,16 @@ Append
|
|
218
224
|
|
219
225
|
##### Command #####
|
220
226
|
|
221
|
-
.help
|
222
|
-
.quit | .exit
|
223
|
-
.consistent (true|false)?
|
224
|
-
.iteratable (true|false)?
|
227
|
+
.help display this message
|
228
|
+
.quit | .exit exit ddbcli
|
229
|
+
.consistent (true|false)? display ConsistentRead parameter or changes it
|
230
|
+
.iteratable (true|false)? display iteratable option or changes it
|
225
231
|
all results are displayed if true
|
226
|
-
.debug (true|false)?
|
227
|
-
.retry NUM?
|
228
|
-
.retry_interval SECOND?
|
229
|
-
.timeout SECOND?
|
230
|
-
.version
|
232
|
+
.debug (true|false)? display a debug status or changes it
|
233
|
+
.retry NUM? display number of times of a retry or changes it
|
234
|
+
.retry_interval SECOND? display a retry interval second or changes it
|
235
|
+
.timeout SECOND? display a timeout second or changes it
|
236
|
+
.version display a version
|
231
237
|
```
|
232
238
|
|
233
239
|
# Test
|
data/lib/ddbcli/cli/help.rb
CHANGED
@@ -5,16 +5,16 @@ def print_help(options = {})
|
|
5
5
|
##### Query #####
|
6
6
|
|
7
7
|
SHOW TABLES [LIMIT num] [LIKE '...']
|
8
|
-
|
8
|
+
display a table list
|
9
9
|
|
10
10
|
SHOW TABLE STATUS [LIKE '...']
|
11
|
-
|
11
|
+
display table statues
|
12
12
|
|
13
13
|
SHOW REGIONS
|
14
|
-
|
14
|
+
display a region list
|
15
15
|
|
16
16
|
SHOW CREATE TABLE table_name
|
17
|
-
|
17
|
+
display a CREATE TABLE statement
|
18
18
|
|
19
19
|
CREATE TABLE table_name (
|
20
20
|
key_name {STRING|NUMBER|BINARY} HASH
|
@@ -26,57 +26,62 @@ CREATE TABLE table_name (
|
|
26
26
|
, GLOBAL INDEX index2_name (hash_attr2 {STRING|NUMBER|BINARY} [, range_attr2 {STRING|NUMBER|BINARY}]) {ALL|KEYS_ONLY|INCLUDE (attr, ...)} [READ = num WRITE = num]
|
27
27
|
, ...]
|
28
28
|
) READ = num WRITE = num [STREAM = {true|false|NEW_IMAGE|OLD_IMAGE|NEW_AND_OLD_IMAGES|KEYS_ONLY}]
|
29
|
-
|
29
|
+
create a table
|
30
30
|
|
31
31
|
CREATE TABLE table_name LIKE another_table_name [READ = num WRITE = num] [STREAM = {true|false|NEW_IMAGE|OLD_IMAGE|NEW_AND_OLD_IMAGES|KEYS_ONLY}]
|
32
|
-
|
32
|
+
create a table like another table
|
33
33
|
|
34
34
|
DROP TABLE table_name [, table_name2, ...]
|
35
|
-
|
35
|
+
delete tables
|
36
36
|
|
37
37
|
ALTER TABLE table_name {READ = num WRITE = num|STREAM = {true|false|NEW_IMAGE|OLD_IMAGE|NEW_AND_OLD_IMAGES|KEYS_ONLY}}
|
38
|
+
update the provisioned throughput
|
38
39
|
|
39
|
-
|
40
|
+
ALTER TABLE table_name CHANGE GLOBAL INDEX index_name READ = num WRITE = num
|
41
|
+
update GSI provisioned throughput
|
40
42
|
|
41
|
-
ALTER TABLE table_name
|
42
|
-
|
43
|
+
ALTER TABLE table_name ADD GLOBAL INDEX index_name (hash_attr1 {STRING|NUMBER|BINARY} [, range_attr1 {STRING|NUMBER|BINARY}]) {ALL|KEYS_ONLY|INCLUDE (attr, ...)} READ = num WRITE = num
|
44
|
+
add GSI
|
45
|
+
|
46
|
+
ALTER TABLE table_name DROP GLOBAL INDEX index_name
|
47
|
+
delete GSI
|
43
48
|
|
44
49
|
GET {*|attr1,attr2,...} FROM table_name WHERE key1 = '...' AND ...
|
45
|
-
|
50
|
+
get items
|
46
51
|
|
47
52
|
INSERT INTO table_name (attr1, attr2, ...) VALUES ('val1', 'val2', ...), ('val3', 'val4', ...), ...
|
48
53
|
INSERT INTO table_name SELECT ...
|
49
54
|
INSERT INTO table_name SELECT ALL ...
|
50
|
-
|
55
|
+
create items
|
51
56
|
|
52
57
|
UPDATE table_name {SET|ADD} attr1 = 'val1', ... WHERE key1 = '...' AND ...
|
53
58
|
UPDATE ALL table_name {SET|ADD} attr1 = 'val1', ... [WHERE attr1 = '...' AND ...] [LIMIT limit]
|
54
|
-
|
59
|
+
update items
|
55
60
|
("UPDATE" can update only one record. Please use "UPDATE ALL", when you update more than one.)
|
56
61
|
|
57
62
|
UPDATE table_name DEL[ETE] attr1, ... WHERE key1 = '...' AND ...
|
58
63
|
UPDATE ALL table_name DEL[ETE] attr1, ... [WHERE attr1 = '...' AND ...] [LIMIT limit]
|
59
|
-
|
64
|
+
update items (delete attribute)
|
60
65
|
|
61
66
|
DELETE FROM table_name WHERE key1 = '...' AND ..
|
62
67
|
DELETE ALL FROM table_name WHERE [WHERE attr1 = '...' AND ...] [ORDER {ASC|DESC}] [LIMIT limit]
|
63
|
-
|
68
|
+
delete items
|
64
69
|
("DELETE" can delete only one record. Please use "DELETE ALL", when you update more than one.)
|
65
70
|
|
66
71
|
SELECT {*|attr1,attr2,...|COUNT(*)} FROM table_name [USE INDEX (index_name)] [WHERE key1 = '...' AND ...] [HAVING attr1 = '...' AND ...] [ORDER {ASC|DESC}] [LIMIT limit]
|
67
72
|
SELECT ALL {*|attr1,attr2,...|COUNT(*)} FROM table_name [WHERE attr1 = '...' AND ...] [LIMIT limit]
|
68
73
|
SELECT segment/total_segments {*|attr1,attr2,...|COUNT(*)} FROM table_name [WHERE attr1 = '...' AND ...] [LIMIT limit]
|
69
|
-
|
74
|
+
query using the Query/Scan action
|
70
75
|
see http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/QueryAndScan.html
|
71
76
|
|
72
77
|
DESC[RIBE] table_name
|
73
|
-
|
78
|
+
display information about the table
|
74
79
|
|
75
80
|
USE region_or_endpoint
|
76
|
-
|
81
|
+
change an endpoint
|
77
82
|
|
78
83
|
NEXT
|
79
|
-
|
84
|
+
display a continuation of a result
|
80
85
|
(NEXT statement is published after SELECT statement)
|
81
86
|
|
82
87
|
|
@@ -155,16 +160,16 @@ Append
|
|
155
160
|
|
156
161
|
##### Command #####
|
157
162
|
|
158
|
-
.help
|
159
|
-
.quit | .exit
|
160
|
-
.consistent (true|false)?
|
161
|
-
.iteratable (true|false)?
|
163
|
+
.help display this message
|
164
|
+
.quit | .exit exit ddbcli
|
165
|
+
.consistent (true|false)? display ConsistentRead parameter or changes it
|
166
|
+
.iteratable (true|false)? display iteratable option or changes it
|
162
167
|
all results are displayed if true
|
163
|
-
.debug (true|false)?
|
164
|
-
.retry NUM?
|
165
|
-
.retry_interval SECOND?
|
166
|
-
.timeout SECOND?
|
167
|
-
.version
|
168
|
+
.debug (true|false)? display a debug status or changes it
|
169
|
+
.retry NUM? display number of times of a retry or changes it
|
170
|
+
.retry_interval SECOND? display a retry interval second or changes it
|
171
|
+
.timeout SECOND? display a timeout second or changes it
|
172
|
+
.version display a version
|
168
173
|
|
169
174
|
EOS
|
170
175
|
|
data/lib/ddbcli/ddb-driver.rb
CHANGED
@@ -61,6 +61,8 @@ module DynamoDB
|
|
61
61
|
do_show_create_table(parsed)
|
62
62
|
when :ALTER_TABLE
|
63
63
|
do_alter_table(parsed)
|
64
|
+
when :ALTER_TABLE_INDEX
|
65
|
+
do_alter_table_index(parsed)
|
64
66
|
when :USE
|
65
67
|
do_use(parsed)
|
66
68
|
when :CREATE
|
@@ -287,6 +289,7 @@ module DynamoDB
|
|
287
289
|
|
288
290
|
(table_info['GlobalSecondaryIndexes'] || []).each do |i|
|
289
291
|
index_name = i['IndexName']
|
292
|
+
next unless i['KeySchema']
|
290
293
|
key_names = i['KeySchema'].map {|j| j['AttributeName'] }
|
291
294
|
proj_type = i['Projection']['ProjectionType']
|
292
295
|
proj_attrs = i['Projection']['NonKeyAttributes']
|
@@ -359,33 +362,58 @@ module DynamoDB
|
|
359
362
|
def do_alter_table(parsed)
|
360
363
|
req_hash = {'TableName' => parsed.table}
|
361
364
|
|
362
|
-
if parsed.
|
363
|
-
req_hash['
|
364
|
-
'
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
if parsed.
|
371
|
-
|
372
|
-
|
373
|
-
|
365
|
+
if parsed.capacity
|
366
|
+
req_hash['ProvisionedThroughput'] = {
|
367
|
+
'ReadCapacityUnits' => parsed.capacity[:read],
|
368
|
+
'WriteCapacityUnits' => parsed.capacity[:write],
|
369
|
+
}
|
370
|
+
end
|
371
|
+
|
372
|
+
unless parsed.stream.nil?
|
373
|
+
if parsed.stream
|
374
|
+
view_type = (parsed.stream == true) ? 'KEYS_ONLY' : parsed.stream.to_s.upcase
|
375
|
+
|
376
|
+
req_hash['StreamSpecification'] = {
|
377
|
+
'StreamEnabled' => true,
|
378
|
+
'StreamViewType' => view_type,
|
374
379
|
}
|
380
|
+
else
|
381
|
+
req_hash['StreamSpecification'] = {'StreamEnabled' => false}
|
375
382
|
end
|
383
|
+
end
|
376
384
|
|
377
|
-
|
378
|
-
|
379
|
-
|
385
|
+
@client.query('UpdateTable', req_hash)
|
386
|
+
nil
|
387
|
+
end
|
380
388
|
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
+
def do_alter_table_index(parsed)
|
390
|
+
req_hash = {'TableName' => parsed.table}
|
391
|
+
index_definition = parsed.index_definition
|
392
|
+
gsi_updates = req_hash['GlobalSecondaryIndexUpdates'] = []
|
393
|
+
|
394
|
+
case parsed.action
|
395
|
+
when 'Update'
|
396
|
+
gsi_updates << {
|
397
|
+
'Update' => {
|
398
|
+
'IndexName' => index_definition[:name],
|
399
|
+
'ProvisionedThroughput' => {
|
400
|
+
'ReadCapacityUnits' => index_definition[:capacity][:read],
|
401
|
+
'WriteCapacityUnits' => index_definition[:capacity][:write],
|
402
|
+
},
|
403
|
+
},
|
404
|
+
}
|
405
|
+
when 'Create'
|
406
|
+
attr_defs = req_hash['AttributeDefinitions'] = []
|
407
|
+
|
408
|
+
gsi_updates << {
|
409
|
+
'Create' => define_index(index_definition, attr_defs, :global => true),
|
410
|
+
}
|
411
|
+
when 'Delete'
|
412
|
+
gsi_updates << {
|
413
|
+
'Delete' => {
|
414
|
+
'IndexName' => index_definition[:name],
|
415
|
+
},
|
416
|
+
}
|
389
417
|
end
|
390
418
|
|
391
419
|
@client.query('UpdateTable', req_hash)
|
@@ -458,105 +486,103 @@ module DynamoDB
|
|
458
486
|
local_indices = (parsed.indices || []).select {|i| not i[:global] }
|
459
487
|
global_indices = (parsed.indices || []).select {|i| i[:global] }
|
460
488
|
|
461
|
-
|
462
|
-
|
463
|
-
|
489
|
+
# local secondary index
|
490
|
+
unless local_indices.empty?
|
491
|
+
req_hash['LocalSecondaryIndexes'] = []
|
464
492
|
|
465
|
-
|
466
|
-
|
467
|
-
|
468
|
-
end
|
469
|
-
else
|
470
|
-
attr_defs << {
|
471
|
-
'AttributeName' => attr_name,
|
472
|
-
'AttributeType' => attr_type,
|
473
|
-
}
|
493
|
+
local_indices.each do |idx_def|
|
494
|
+
local_secondary_index = define_index(idx_def, req_hash['AttributeDefinitions'], :global => false, :hash_name => parsed.hash[:name])
|
495
|
+
req_hash['LocalSecondaryIndexes'] << local_secondary_index
|
474
496
|
end
|
475
497
|
end
|
476
498
|
|
477
|
-
|
478
|
-
|
479
|
-
|
499
|
+
# global secondary index
|
500
|
+
unless global_indices.empty?
|
501
|
+
req_hash['GlobalSecondaryIndexes'] = []
|
480
502
|
|
481
|
-
|
482
|
-
idx_def[
|
483
|
-
|
484
|
-
end
|
485
|
-
else
|
486
|
-
define_attribute.call(idx_def[:key], idx_def[:type])
|
503
|
+
global_indices.each do |idx_def|
|
504
|
+
global_secondary_index = define_index(idx_def, req_hash['AttributeDefinitions'], :global => true, :capacity => parsed.capacity)
|
505
|
+
req_hash['GlobalSecondaryIndexes'] << global_secondary_index
|
487
506
|
end
|
507
|
+
end
|
488
508
|
|
489
|
-
|
490
|
-
|
491
|
-
|
492
|
-
'ProjectionType' => idx_def[:projection][:type],
|
493
|
-
}
|
494
|
-
}
|
495
|
-
|
496
|
-
if global_idx
|
497
|
-
secondary_index['KeySchema'] = []
|
498
|
-
|
499
|
-
[:hash, :range].each do |key_type|
|
500
|
-
name_type = idx_def[:keys][key_type]
|
509
|
+
@client.query('CreateTable', req_hash)
|
510
|
+
nil
|
511
|
+
end
|
501
512
|
|
502
|
-
|
503
|
-
|
504
|
-
'AttributeName' => name_type[:key],
|
505
|
-
'KeyType' => key_type.to_s.upcase,
|
506
|
-
}
|
507
|
-
end
|
508
|
-
end
|
509
|
-
else
|
510
|
-
secondary_index['KeySchema'] = [
|
511
|
-
{
|
512
|
-
'AttributeName' => parsed.hash[:name],
|
513
|
-
'KeyType' => 'HASH',
|
514
|
-
},
|
515
|
-
{
|
516
|
-
'AttributeName' => idx_def[:key],
|
517
|
-
'KeyType' => 'RANGE',
|
518
|
-
},
|
519
|
-
]
|
520
|
-
end
|
513
|
+
def define_attribute(attr_name, attr_type, attr_defs)
|
514
|
+
same_attr = attr_defs.find {|i| i['AttributeName'] == attr_name }
|
521
515
|
|
522
|
-
|
523
|
-
|
516
|
+
if same_attr
|
517
|
+
if same_attr['AttributeType'] != attr_type
|
518
|
+
raise DynamoDB::Error, "different types have been defined: #{attr_name}"
|
524
519
|
end
|
520
|
+
else
|
521
|
+
attr_defs << {
|
522
|
+
'AttributeName' => attr_name,
|
523
|
+
'AttributeType' => attr_type,
|
524
|
+
}
|
525
|
+
end
|
526
|
+
end
|
525
527
|
|
526
|
-
|
527
|
-
|
528
|
+
def define_index(idx_def, attr_defs, def_idx_opts)
|
529
|
+
global_idx = def_idx_opts[:global]
|
528
530
|
|
529
|
-
|
530
|
-
|
531
|
-
|
532
|
-
}
|
531
|
+
if global_idx
|
532
|
+
idx_def[:keys].each do |key_type, name_type|
|
533
|
+
define_attribute(name_type[:key], name_type[:type], attr_defs)
|
533
534
|
end
|
535
|
+
else
|
536
|
+
define_attribute(idx_def[:key], idx_def[:type], attr_defs)
|
537
|
+
end
|
534
538
|
|
535
|
-
|
536
|
-
|
539
|
+
secondary_index = {
|
540
|
+
'IndexName' => idx_def[:name],
|
541
|
+
'Projection' => {
|
542
|
+
'ProjectionType' => idx_def[:projection][:type],
|
543
|
+
}
|
544
|
+
}
|
537
545
|
|
538
|
-
|
539
|
-
|
540
|
-
req_hash['LocalSecondaryIndexes'] = []
|
546
|
+
if global_idx
|
547
|
+
secondary_index['KeySchema'] = []
|
541
548
|
|
542
|
-
|
543
|
-
|
544
|
-
|
549
|
+
[:hash, :range].each do |key_type|
|
550
|
+
name_type = idx_def[:keys][key_type]
|
551
|
+
|
552
|
+
if name_type
|
553
|
+
secondary_index['KeySchema'] << {
|
554
|
+
'AttributeName' => name_type[:key],
|
555
|
+
'KeyType' => key_type.to_s.upcase,
|
556
|
+
}
|
557
|
+
end
|
545
558
|
end
|
559
|
+
else
|
560
|
+
secondary_index['KeySchema'] = [
|
561
|
+
{
|
562
|
+
'AttributeName' => def_idx_opts.fetch(:hash_name),
|
563
|
+
'KeyType' => 'HASH',
|
564
|
+
},
|
565
|
+
{
|
566
|
+
'AttributeName' => idx_def[:key],
|
567
|
+
'KeyType' => 'RANGE',
|
568
|
+
},
|
569
|
+
]
|
546
570
|
end
|
547
571
|
|
548
|
-
|
549
|
-
|
550
|
-
|
572
|
+
if idx_def[:projection][:attrs]
|
573
|
+
secondary_index['Projection']['NonKeyAttributes'] = idx_def[:projection][:attrs]
|
574
|
+
end
|
551
575
|
|
552
|
-
|
553
|
-
|
554
|
-
|
555
|
-
|
576
|
+
if global_idx
|
577
|
+
capacity = idx_def[:capacity] || def_idx_opts.fetch(:capacity)
|
578
|
+
|
579
|
+
secondary_index['ProvisionedThroughput'] = {
|
580
|
+
'ReadCapacityUnits' => capacity[:read],
|
581
|
+
'WriteCapacityUnits' => capacity[:write],
|
582
|
+
}
|
556
583
|
end
|
557
584
|
|
558
|
-
|
559
|
-
nil
|
585
|
+
secondary_index
|
560
586
|
end
|
561
587
|
|
562
588
|
def do_create_like(parsed)
|