ddbcli 0.1.5 → 0.1.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README +7 -2
- data/bin/ddbcli +1 -1
- data/lib/ddbcli/cli/help.rb +6 -1
- data/lib/ddbcli/ddb-driver.rb +61 -5
- data/lib/ddbcli/ddb-parser.tab.rb +558 -529
- data/lib/ddbcli/ddb-parser.y +14 -1
- metadata +2 -2
data/README
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
=
|
1
|
+
= ddbcli
|
2
2
|
|
3
3
|
== Description
|
4
4
|
|
@@ -42,6 +42,9 @@ https://bitbucket.org/winebarrel/ddbcli
|
|
42
42
|
SHOW TABLES
|
43
43
|
displays a table list
|
44
44
|
|
45
|
+
SHOW TABLE STATUS
|
46
|
+
displays table statues
|
47
|
+
|
45
48
|
SHOW REGIONS
|
46
49
|
displays a region list
|
47
50
|
|
@@ -70,6 +73,8 @@ https://bitbucket.org/winebarrel/ddbcli
|
|
70
73
|
gets items
|
71
74
|
|
72
75
|
INSERT INTO table_name (attr1, attr2, ...) VALUES ('val1', 'val2', ...), ('val3', 'val4', ...), ...
|
76
|
+
INSERT INTO table_name SELECT ...
|
77
|
+
INSERT INTO table_name SELECT ALL ...
|
73
78
|
creates items
|
74
79
|
|
75
80
|
UPDATE table_name {SET|ADD} attr1 = 'val1', ... WHERE key1 = '...' AND ...
|
@@ -147,7 +152,7 @@ https://bitbucket.org/winebarrel/ddbcli
|
|
147
152
|
##### Command #####
|
148
153
|
|
149
154
|
.help displays this message
|
150
|
-
.quit | .exit exits
|
155
|
+
.quit | .exit exits ddbcli
|
151
156
|
.consistent (true|false)? displays ConsistentRead parameter or changes it
|
152
157
|
.iteratable (true|false)? displays iteratable option or changes it
|
153
158
|
all results are displayed if true
|
data/bin/ddbcli
CHANGED
data/lib/ddbcli/cli/help.rb
CHANGED
@@ -5,6 +5,9 @@ def print_help
|
|
5
5
|
SHOW TABLES
|
6
6
|
displays a table list
|
7
7
|
|
8
|
+
SHOW TABLE STATUS
|
9
|
+
displays table statues
|
10
|
+
|
8
11
|
SHOW REGIONS
|
9
12
|
displays a region list
|
10
13
|
|
@@ -33,6 +36,8 @@ GET {*|attrs} FROM table_name WHERE key1 = '...' AND ...
|
|
33
36
|
gets items
|
34
37
|
|
35
38
|
INSERT INTO table_name (attr1, attr2, ...) VALUES ('val1', 'val2', ...), ('val3', 'val4', ...), ...
|
39
|
+
INSERT INTO table_name SELECT ...
|
40
|
+
INSERT INTO table_name SELECT ALL ...
|
36
41
|
creates items
|
37
42
|
|
38
43
|
UPDATE table_name {SET|ADD} attr1 = 'val1', ... WHERE key1 = '...' AND ...
|
@@ -110,7 +115,7 @@ Shell
|
|
110
115
|
##### Command #####
|
111
116
|
|
112
117
|
.help displays this message
|
113
|
-
.quit | .exit exits
|
118
|
+
.quit | .exit exits ddbcli
|
114
119
|
.consistent (true|false)? displays ConsistentRead parameter or changes it
|
115
120
|
.iteratable (true|false)? displays iteratable option or changes it
|
116
121
|
all results are displayed if true
|
data/lib/ddbcli/ddb-driver.rb
CHANGED
@@ -52,6 +52,8 @@ module DynamoDB
|
|
52
52
|
retval = case command
|
53
53
|
when :SHOW_TABLES
|
54
54
|
do_show_tables(parsed)
|
55
|
+
when :SHOW_TABLE_STATUS
|
56
|
+
do_show_table_status(parsed)
|
55
57
|
when :SHOW_REGIONS
|
56
58
|
do_show_regions(parsed)
|
57
59
|
when :SHOW_CREATE_TABLE
|
@@ -84,6 +86,10 @@ module DynamoDB
|
|
84
86
|
do_delete_all(parsed)
|
85
87
|
when :INSERT
|
86
88
|
do_insert(parsed)
|
89
|
+
when :INSERT_SELECT
|
90
|
+
do_insert_select('Query', parsed)
|
91
|
+
when :INSERT_SCAN
|
92
|
+
do_insert_select('Scan', parsed)
|
87
93
|
when :NEXT
|
88
94
|
if @last_action and @last_parsed and @last_evaluated_key
|
89
95
|
do_select(@last_action, @last_parsed, :last_evaluated_key => @last_evaluated_key)
|
@@ -152,10 +158,14 @@ module DynamoDB
|
|
152
158
|
private
|
153
159
|
|
154
160
|
def do_show_tables(parsed)
|
161
|
+
do_show_tables0(parsed.limit)
|
162
|
+
end
|
163
|
+
|
164
|
+
def do_show_tables0(limit = nil)
|
155
165
|
req_hash = {}
|
156
166
|
table_names = []
|
157
167
|
|
158
|
-
req_hash['Limit'] =
|
168
|
+
req_hash['Limit'] = limit if limit
|
159
169
|
|
160
170
|
list = lambda do |last_evaluated_table_name|
|
161
171
|
req_hash['ExclusiveStartTableName'] = last_evaluated_table_name if last_evaluated_table_name
|
@@ -169,7 +179,7 @@ module DynamoDB
|
|
169
179
|
loop do
|
170
180
|
letn = list.call(letn)
|
171
181
|
|
172
|
-
if
|
182
|
+
if limit or not letn
|
173
183
|
break
|
174
184
|
end
|
175
185
|
end
|
@@ -177,6 +187,18 @@ module DynamoDB
|
|
177
187
|
return table_names
|
178
188
|
end
|
179
189
|
|
190
|
+
def do_show_table_status(parsed)
|
191
|
+
table_names = do_show_tables0
|
192
|
+
h = {}
|
193
|
+
|
194
|
+
table_names.map do |table_name|
|
195
|
+
table_info = @client.query('DescribeTable', 'TableName' => table_name)['Table']
|
196
|
+
h[table_name] = table_info['TableStatus']
|
197
|
+
end
|
198
|
+
|
199
|
+
return h
|
200
|
+
end
|
201
|
+
|
180
202
|
def do_show_regions(parsed)
|
181
203
|
DynamoDB::Endpoint.regions
|
182
204
|
end
|
@@ -384,6 +406,12 @@ module DynamoDB
|
|
384
406
|
end
|
385
407
|
|
386
408
|
def do_select(action, parsed, opts = {})
|
409
|
+
do_select0(action, parsed, opts) do |i|
|
410
|
+
convert_to_ruby_value(i)
|
411
|
+
end
|
412
|
+
end
|
413
|
+
|
414
|
+
def do_select0(action, parsed, opts = {})
|
387
415
|
select_proc = lambda do |last_evaluated_key|
|
388
416
|
req_hash = {'TableName' => parsed.table}
|
389
417
|
req_hash['AttributesToGet'] = parsed.attrs unless parsed.attrs.empty?
|
@@ -450,12 +478,14 @@ module DynamoDB
|
|
450
478
|
retval += res_data['Count']
|
451
479
|
end
|
452
480
|
else
|
453
|
-
retval = res_data['Items'].map {|i|
|
481
|
+
retval = block_given? ? res_data['Items'].map {|i| yield(i) } : res_data['Items']
|
454
482
|
|
455
|
-
if @iteratable and not parsed.limit
|
483
|
+
if (@iteratable or opts[:iteratable]) and not parsed.limit
|
456
484
|
while res_data['LastEvaluatedKey']
|
457
485
|
res_data = select_proc.call(res_data['LastEvaluatedKey'])
|
458
|
-
retval.concat(
|
486
|
+
retval.concat(
|
487
|
+
block_given? ? res_data['Items'].map {|i| yield(i) } : res_data['Items']
|
488
|
+
)
|
459
489
|
end
|
460
490
|
end
|
461
491
|
end
|
@@ -730,6 +760,32 @@ module DynamoDB
|
|
730
760
|
Rownum.new(n)
|
731
761
|
end
|
732
762
|
|
763
|
+
def do_insert_select(action, parsed)
|
764
|
+
items = do_select0(action, parsed.select, :iteratable => true)
|
765
|
+
n = 0
|
766
|
+
|
767
|
+
until (chunk = items.slice!(0, MAX_NUMBER_BATCH_PROCESS_ITEMS)).empty?
|
768
|
+
operations = []
|
769
|
+
|
770
|
+
req_hash = {
|
771
|
+
'RequestItems' => {
|
772
|
+
parsed.table => operations,
|
773
|
+
},
|
774
|
+
}
|
775
|
+
|
776
|
+
chunk.each do |item|
|
777
|
+
operations << {
|
778
|
+
'PutRequest' => {'Item' => item}
|
779
|
+
}
|
780
|
+
end
|
781
|
+
|
782
|
+
batch_write_item(req_hash)
|
783
|
+
n += chunk.length
|
784
|
+
end
|
785
|
+
|
786
|
+
Rownum.new(n)
|
787
|
+
end
|
788
|
+
|
733
789
|
def str_to_num(str)
|
734
790
|
str =~ /\./ ? str.to_f : str.to_i
|
735
791
|
end
|