hivonic 0.2.1 → 0.3.0
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +10 -0
- data/bin/hivonic +10 -2
- data/lib/hivonic/commands.rb +37 -4
- data/lib/hivonic/version.rb +1 -1
- data/test/unit/commands_test.rb +1 -0
- 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: 15830f42fedc4df4e21533db43f475daf06fd565
|
4
|
+
data.tar.gz: 6d058be4e343b6b917f8d015087d00a052064de9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 89c55470ee78cbacafb6746e67c1d55afe21539c68150b263e1ce097ec7b8bedeeeb2073c127337665d4ddf4599cc7e3986f63ce34c86b347ac5e4128d7bde5e
|
7
|
+
data.tar.gz: 77424c5772365a789a3aee119fb11c0642b78f65ff71569df593e11027f9704563528b00cc5441e484aae7640b7dd00d7480c8bf3590c4d29107f27002dbc0d2
|
data/CHANGELOG.md
CHANGED
@@ -1,6 +1,16 @@
|
|
1
1
|
Hivonic Changelog
|
2
2
|
===
|
3
3
|
|
4
|
+
0.3.0
|
5
|
+
---
|
6
|
+
* Now cleans up views in addition to tables
|
7
|
+
* Tweaked HIVONIC_REGEXP default so it is a little less opinionated
|
8
|
+
* Fixed cleanup, so it no longer calls build_query repeatedly (also a performance improvement)
|
9
|
+
|
10
|
+
0.2.2
|
11
|
+
---
|
12
|
+
* Fixed issue with mock() instance that represents output from the subcommand in tests
|
13
|
+
|
4
14
|
0.2.1
|
5
15
|
---
|
6
16
|
* Tweaked HIVONIC_REGEXP env var's default value
|
data/bin/hivonic
CHANGED
@@ -15,7 +15,7 @@ program_desc 'A simple hive utility application for cleaning up temporary tables
|
|
15
15
|
# arg_name 'database'
|
16
16
|
|
17
17
|
hive_opts = ENV['HIVONIC_HIVE_OPTS'] || '-S' # -hiveconf hive.root.logger=DEBUG -S
|
18
|
-
regexp = ENV['HIVONIC_REGEXP'] || '\A(tmp
|
18
|
+
regexp = ENV['HIVONIC_REGEXP'] || '\A(tmp)[a-z|_|0-9]+_(\d{14})\z'
|
19
19
|
time_format = ENV['HIVONIC_TIME_FORMAT'] || '%Y%m%d%H%M%S'
|
20
20
|
time_group_index = ENV['HIVONIC_TIME_GROUP_INDEX'] || 2
|
21
21
|
ttl = ENV['HIVONIC_TTL'] || 86400
|
@@ -54,9 +54,17 @@ command :rm do |c|
|
|
54
54
|
end
|
55
55
|
|
56
56
|
command :cleanup do |c|
|
57
|
+
c.flag [:type], :default_value => 'tables'
|
57
58
|
c.action do |global_options, options, args|
|
58
59
|
database_check!(args)
|
59
|
-
|
60
|
+
case options[:type]
|
61
|
+
when 'tables'
|
62
|
+
Hivonic::Commands.run 'cleanup_tables', global_options, args
|
63
|
+
when 'views'
|
64
|
+
Hivonic::Commands.run 'cleanup_views', global_options, args
|
65
|
+
else
|
66
|
+
exit_now!('Unknown type for cleanup command')
|
67
|
+
end
|
60
68
|
end
|
61
69
|
end
|
62
70
|
|
data/lib/hivonic/commands.rb
CHANGED
@@ -73,6 +73,7 @@ module Hivonic::Commands
|
|
73
73
|
stdout = "DRY RUN: Subcommand => #{subcommand}"
|
74
74
|
@exitstatus = 0
|
75
75
|
else
|
76
|
+
puts "Running: Subcommand => #{subcommand}"
|
76
77
|
stdout = `#{subcommand}`
|
77
78
|
@exitstatus = $?.exitstatus
|
78
79
|
end
|
@@ -155,13 +156,26 @@ module Hivonic::Commands
|
|
155
156
|
end
|
156
157
|
|
157
158
|
def query
|
158
|
-
@query = "DROP TABLE #{self.db}.#{self.table};"
|
159
|
+
@query = "DROP TABLE IF EXISTS #{self.db}.#{self.table};"
|
160
|
+
end
|
161
|
+
end
|
162
|
+
|
163
|
+
class DropView < HiveQueryCommand
|
164
|
+
attr_reader :view
|
165
|
+
|
166
|
+
def initialize(opts, args)
|
167
|
+
super
|
168
|
+
@view = args[1]
|
169
|
+
end
|
170
|
+
|
171
|
+
def query
|
172
|
+
@query = "DROP VIEW IF EXISTS #{self.db}.#{self.view};"
|
159
173
|
end
|
160
174
|
end
|
161
175
|
|
162
176
|
register_handler_for :drop_table
|
163
177
|
|
164
|
-
class
|
178
|
+
class CleanupQueryCommand < HiveQueryCommand
|
165
179
|
def list_tables
|
166
180
|
opts = {}
|
167
181
|
opts['regexp'] = self.regexp
|
@@ -172,6 +186,7 @@ module Hivonic::Commands
|
|
172
186
|
|
173
187
|
output, status = ListTables.run opts, [self.db]
|
174
188
|
raise 'Uh oh!' unless is_successful? status
|
189
|
+
puts "Expired Tables: \n#{output}\n"
|
175
190
|
output.split(/\n/)
|
176
191
|
end
|
177
192
|
|
@@ -181,6 +196,10 @@ module Hivonic::Commands
|
|
181
196
|
end
|
182
197
|
end
|
183
198
|
|
199
|
+
def drop_query_for(table, opts)
|
200
|
+
raise NotImplementedError.new 'You must implement drop_query_for method on subclass'
|
201
|
+
end
|
202
|
+
|
184
203
|
def build_query
|
185
204
|
tables = list_tables
|
186
205
|
|
@@ -188,12 +207,12 @@ module Hivonic::Commands
|
|
188
207
|
opts = {}
|
189
208
|
opts['regexp'] = self.regexp
|
190
209
|
|
191
|
-
|
210
|
+
drop_query_for table, opts
|
192
211
|
end.join(' ')
|
193
212
|
end
|
194
213
|
|
195
214
|
def query
|
196
|
-
@query
|
215
|
+
@query ||= build_query
|
197
216
|
end
|
198
217
|
|
199
218
|
def subcommand
|
@@ -206,5 +225,19 @@ module Hivonic::Commands
|
|
206
225
|
end
|
207
226
|
end
|
208
227
|
|
228
|
+
class CleanupTables < CleanupQueryCommand
|
229
|
+
def drop_query_for(table, opts)
|
230
|
+
DropTable.new(opts, [self.db, table]).query
|
231
|
+
end
|
232
|
+
end
|
233
|
+
|
209
234
|
register_handler_for :cleanup_tables
|
235
|
+
|
236
|
+
class CleanupViews < CleanupQueryCommand
|
237
|
+
def drop_query_for(table, opts)
|
238
|
+
DropView.new(opts, [self.db, table]).query
|
239
|
+
end
|
240
|
+
end
|
241
|
+
|
242
|
+
register_handler_for :cleanup_views
|
210
243
|
end
|
data/lib/hivonic/version.rb
CHANGED
data/test/unit/commands_test.rb
CHANGED
@@ -6,6 +6,7 @@ class Hivonic::CommandsTest < Test::Unit::TestCase
|
|
6
6
|
should 'pass opts and args to #run method of the handler' do
|
7
7
|
Hivonic::Commands.expects(:handler_for).with(cmd = mock()).returns(handler = mock())
|
8
8
|
handler.expects(:run).with(opts = mock(), args = mock()).returns([output = mock(), exitstatus = mock()])
|
9
|
+
output.expects(:empty?).returns(false)
|
9
10
|
assert_equal exitstatus, Hivonic::Commands.run(cmd, opts, args)
|
10
11
|
end
|
11
12
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hivonic
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Will Drew
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-06-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: gli
|