ddbcli 0.2.7 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/README +4 -1
- data/bin/ddbcli +1 -1
- data/lib/ddbcli/cli/help.rb +5 -1
- data/lib/ddbcli/ddb-driver.rb +112 -23
- data/lib/ddbcli/ddb-parser.tab.rb +586 -515
- data/lib/ddbcli/ddb-parser.y +31 -0
- metadata +5 -9
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
MzMzZGJiNzFlZDY4ZGUwM2VkOTA3MzA4NjgxMzUzZjgxMjAyNmE0MQ==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
OGE3NGE3ZTVmMzhiMGRiNTllMWU3MGVmMjJkODczZTA1YmUzNDI2Ng==
|
7
|
+
SHA512:
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
NmU1Nzc3MzM3ZjJhNWRhYjNjYWZlYmE0MTA1OTMxYjkwMTAxZDU3NzFhZjQz
|
10
|
+
ZjIzZDhmNmRmYjkyNzEwZDllNGVhZGY3Zjk0ZTZkNTE0OGJhZTMxZGViZmJi
|
11
|
+
ZjczYWI3MjQxMWZiY2FiNThiZDA4ZWRhN2E1ZGI3MWRlYjBkMTk=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
ZDk5ODQ1NjBkMTIxNmZmM2E2ZTA4MjBiOGQ4Njc2ZDBjYmFmYWY3YjA4Zjgz
|
14
|
+
YmU1MTYyMDhiNWM2N2VhOTcwYWE1NTEwZmZkNmQzMDcxMDk0OTZlN2JhODdh
|
15
|
+
NDk0N2JlY2Y1MjRmY2MwYmQ5ZjUxMTk2MTlkYmY2MTMxY2E4ODI=
|
data/README
CHANGED
@@ -61,7 +61,10 @@ https://bitbucket.org/winebarrel/ddbcli
|
|
61
61
|
[, INDEX index1_name (attr1 {STRING|NUMBER|BINARY}) {ALL|KEYS_ONLY|INCLUDE (attr, ...)}
|
62
62
|
, INDEX index2_name (attr2 {STRING|NUMBER|BINARY}) {ALL|KEYS_ONLY|INCLUDE (attr, ...)}
|
63
63
|
, ...]
|
64
|
-
|
64
|
+
[, GLOBAL INDEX index1_name (hash_attr1 {STRING|NUMBER|BINARY} [, range_attr1 {STRING|NUMBER|BINARY}]) {ALL|KEYS_ONLY|INCLUDE (attr, ...)} [READ = num WRITE = num]
|
65
|
+
, GLOBAL INDEX index2_name (hash_attr2 {STRING|NUMBER|BINARY} [, range_attr2 {STRING|NUMBER|BINARY}]) {ALL|KEYS_ONLY|INCLUDE (attr, ...)} [READ = num WRITE = num]
|
66
|
+
, ...]
|
67
|
+
) READ = num WRITE = num
|
65
68
|
creates a table
|
66
69
|
|
67
70
|
CREATE TABLES table_name LIKE another_table_name [READ = num, WRITE = num]
|
data/bin/ddbcli
CHANGED
data/lib/ddbcli/cli/help.rb
CHANGED
@@ -22,7 +22,10 @@ CREATE TABLES table_name (
|
|
22
22
|
[, INDEX index1_name (attr1 {STRING|NUMBER|BINARY}) {ALL|KEYS_ONLY|INCLUDE (attr, ...)}
|
23
23
|
, INDEX index2_name (attr2 {STRING|NUMBER|BINARY}) {ALL|KEYS_ONLY|INCLUDE (attr, ...)}
|
24
24
|
, ...]
|
25
|
-
) READ = num
|
25
|
+
[, GLOBAL INDEX index1_name (hash_attr1 {STRING|NUMBER|BINARY} [, range_attr1 {STRING|NUMBER|BINARY}]) {ALL|KEYS_ONLY|INCLUDE (attr, ...)} [READ = num WRITE = num]
|
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
|
+
, ...]
|
28
|
+
) READ = num WRITE = num
|
26
29
|
creates a table
|
27
30
|
|
28
31
|
CREATE TABLES table_name LIKE another_table_name [READ = num, WRITE = num]
|
@@ -117,6 +120,7 @@ Shell
|
|
117
120
|
{"birth_date"=>"1964-04-30", "emp_no"=>225407,...
|
118
121
|
...
|
119
122
|
|
123
|
+
|
120
124
|
##### Output to a file #####
|
121
125
|
|
122
126
|
Overwrite
|
data/lib/ddbcli/ddb-driver.rb
CHANGED
@@ -252,6 +252,23 @@ module DynamoDB
|
|
252
252
|
indexes[index_name] = [key_name, proj_type, proj_attrs]
|
253
253
|
end
|
254
254
|
|
255
|
+
global_indexes = {}
|
256
|
+
|
257
|
+
(table_info['GlobalSecondaryIndexes'] || []).each do |i|
|
258
|
+
index_name = i['IndexName']
|
259
|
+
key_names = i['KeySchema'].map {|j| j['AttributeName'] }
|
260
|
+
proj_type = i['Projection']['ProjectionType']
|
261
|
+
proj_attrs = i['Projection']['NonKeyAttributes']
|
262
|
+
|
263
|
+
idx_throughput = i['ProvisionedThroughput']
|
264
|
+
idx_throughput = {
|
265
|
+
:read => idx_throughput['ReadCapacityUnits'],
|
266
|
+
:write => idx_throughput['WriteCapacityUnits'],
|
267
|
+
}
|
268
|
+
|
269
|
+
global_indexes[index_name] = [key_names, proj_type, proj_attrs, idx_throughput]
|
270
|
+
end
|
271
|
+
|
255
272
|
throughput = table_info['ProvisionedThroughput']
|
256
273
|
throughput = {
|
257
274
|
:read => throughput['ReadCapacityUnits'],
|
@@ -277,8 +294,25 @@ module DynamoDB
|
|
277
294
|
}.join(",\n ")
|
278
295
|
end
|
279
296
|
|
297
|
+
unless global_indexes.empty?
|
298
|
+
buf << ",\n " + global_indexes.map {|index_name, key_names_proj_itp|
|
299
|
+
key_names, proj_type, proj_attrs, idx_throughput = key_names_proj_itp
|
300
|
+
index_clause = "GLOBAL INDEX #{quote[index_name]} ("
|
301
|
+
|
302
|
+
index_clause << key_names.map {|key_name|
|
303
|
+
attr_type = attr_types[key_name]
|
304
|
+
"#{quote[key_name]} #{attr_type}"
|
305
|
+
}.join(', ')
|
306
|
+
|
307
|
+
index_clause << ") #{proj_type}"
|
308
|
+
index_clause << " (#{proj_attrs.join(', ')})" if proj_attrs
|
309
|
+
index_clause << ' ' + idx_throughput.map {|k, v| "#{k}=#{v}" }.join(' ')
|
310
|
+
index_clause
|
311
|
+
}.join(",\n ")
|
312
|
+
end
|
313
|
+
|
280
314
|
buf << "\n)"
|
281
|
-
buf << ' ' + throughput.map {|k, v| "#{k}=#{v}" }.join('
|
315
|
+
buf << ' ' + throughput.map {|k, v| "#{k}=#{v}" }.join(' ')
|
282
316
|
buf << "\n\n"
|
283
317
|
|
284
318
|
return buf
|
@@ -350,40 +384,95 @@ module DynamoDB
|
|
350
384
|
}
|
351
385
|
end
|
352
386
|
|
353
|
-
#
|
354
|
-
|
355
|
-
|
387
|
+
# secondary index
|
388
|
+
local_indices = (parsed.indices || []).select {|i| not i[:global] }
|
389
|
+
global_indices = (parsed.indices || []).select {|i| i[:global] }
|
356
390
|
|
357
|
-
|
391
|
+
define_index = lambda do |idx_def, def_idx_opts|
|
392
|
+
global_idx = def_idx_opts[:global]
|
393
|
+
|
394
|
+
if global_idx
|
395
|
+
idx_def[:keys].each do |key_type, name_type|
|
396
|
+
req_hash['AttributeDefinitions'] << {
|
397
|
+
'AttributeName' => name_type[:key],
|
398
|
+
'AttributeType' => name_type[:type],
|
399
|
+
}
|
400
|
+
end
|
401
|
+
else
|
358
402
|
req_hash['AttributeDefinitions'] << {
|
359
403
|
'AttributeName' => idx_def[:key],
|
360
404
|
'AttributeType' => idx_def[:type],
|
361
405
|
}
|
406
|
+
end
|
362
407
|
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
'AttributeName' => parsed.hash[:name],
|
368
|
-
'KeyType' => 'HASH',
|
369
|
-
},
|
370
|
-
{
|
371
|
-
'AttributeName' => idx_def[:key],
|
372
|
-
'KeyType' => 'RANGE',
|
373
|
-
},
|
374
|
-
],
|
375
|
-
'Projection' => {
|
376
|
-
'ProjectionType' => idx_def[:projection][:type],
|
377
|
-
}
|
408
|
+
secondary_index = {
|
409
|
+
'IndexName' => idx_def[:name],
|
410
|
+
'Projection' => {
|
411
|
+
'ProjectionType' => idx_def[:projection][:type],
|
378
412
|
}
|
413
|
+
}
|
414
|
+
|
415
|
+
if global_idx
|
416
|
+
secondary_index['KeySchema'] = []
|
417
|
+
|
418
|
+
[:hash, :range].each do |key_type|
|
419
|
+
name_type = idx_def[:keys][key_type]
|
379
420
|
|
380
|
-
|
381
|
-
|
421
|
+
if name_type
|
422
|
+
secondary_index['KeySchema'] << {
|
423
|
+
'AttributeName' => name_type[:key],
|
424
|
+
'KeyType' => key_type.to_s.upcase,
|
425
|
+
}
|
426
|
+
end
|
382
427
|
end
|
428
|
+
else
|
429
|
+
secondary_index['KeySchema'] = [
|
430
|
+
{
|
431
|
+
'AttributeName' => parsed.hash[:name],
|
432
|
+
'KeyType' => 'HASH',
|
433
|
+
},
|
434
|
+
{
|
435
|
+
'AttributeName' => idx_def[:key],
|
436
|
+
'KeyType' => 'RANGE',
|
437
|
+
},
|
438
|
+
]
|
439
|
+
end
|
440
|
+
|
441
|
+
if idx_def[:projection][:attrs]
|
442
|
+
secondary_index['Projection']['NonKeyAttributes'] = idx_def[:projection][:attrs]
|
443
|
+
end
|
444
|
+
|
445
|
+
if global_idx
|
446
|
+
capacity = idx_def[:capacity] || parsed.capacity
|
383
447
|
|
448
|
+
secondary_index['ProvisionedThroughput'] = {
|
449
|
+
'ReadCapacityUnits' => capacity[:read],
|
450
|
+
'WriteCapacityUnits' => capacity[:write],
|
451
|
+
}
|
452
|
+
end
|
453
|
+
|
454
|
+
secondary_index
|
455
|
+
end # define_index
|
456
|
+
|
457
|
+
# local secondary index
|
458
|
+
unless local_indices.empty?
|
459
|
+
req_hash['LocalSecondaryIndexes'] = []
|
460
|
+
|
461
|
+
local_indices.each do |idx_def|
|
462
|
+
local_secondary_index = define_index.call(idx_def, :global => false)
|
384
463
|
req_hash['LocalSecondaryIndexes'] << local_secondary_index
|
385
464
|
end
|
386
|
-
end
|
465
|
+
end
|
466
|
+
|
467
|
+
# global secondary index
|
468
|
+
unless global_indices.empty?
|
469
|
+
req_hash['GlobalSecondaryIndexes'] = []
|
470
|
+
|
471
|
+
global_indices.each do |idx_def|
|
472
|
+
global_secondary_index = define_index.call(idx_def, :global => true)
|
473
|
+
req_hash['GlobalSecondaryIndexes'] << global_secondary_index
|
474
|
+
end
|
475
|
+
end
|
387
476
|
|
388
477
|
@client.query('CreateTable', req_hash)
|
389
478
|
nil
|