Class: Hivonic::Commands::CleanupQueryCommand

Inherits:
HiveQueryCommand show all
Defined in:
lib/hivonic/commands.rb

Direct Known Subclasses

CleanupTables, CleanupViews

Instance Attribute Summary

Attributes inherited from HiveQueryCommand

#db, #hive_opts

Attributes inherited from Subcommand

#dry_run, #exitstatus, #regexp, #time_format, #time_group_index, #ttl

Instance Method Summary collapse

Methods inherited from HiveQueryCommand

#initialize

Methods inherited from Subcommand

#initialize, #is_successful?, #output, #run, run, #successful?

Constructor Details

This class inherits a constructor from Hivonic::Commands::HiveQueryCommand

Instance Method Details

#build_queryObject



203
204
205
206
207
208
209
210
211
212
# File 'lib/hivonic/commands.rb', line 203

def build_query
  tables = list_tables

  tables.map do |table|
    opts           = {}
    opts['regexp'] = self.regexp

    drop_query_for table, opts
  end.join(' ')
end

#drop_query_for(table, opts) ⇒ Object



199
200
201
# File 'lib/hivonic/commands.rb', line 199

def drop_query_for(table, opts)
  raise NotImplementedError.new 'You must implement drop_query_for method on subclass'
end

#filter(tables) ⇒ Object



193
194
195
196
197
# File 'lib/hivonic/commands.rb', line 193

def filter(tables)
  tables.select do |table|
    is_table_expired? table
  end
end

#list_tablesObject



179
180
181
182
183
184
185
186
187
188
189
190
191
# File 'lib/hivonic/commands.rb', line 179

def list_tables
  opts                     = {}
  opts['regexp']           = self.regexp
  opts['time-format']      = self.time_format
  opts['time-group-index'] = self.time_group_index
  opts['ttl']              = self.ttl
  opts['hive-opts']        = self.hive_opts

  output, status = ListTables.run opts, [self.db]
  raise 'Uh oh!' unless is_successful? status
  puts "Expired Tables: \n#{output}\n"
  output.split(/\n/)
end

#queryObject



214
215
216
# File 'lib/hivonic/commands.rb', line 214

def query
  @query ||= build_query
end

#subcommandObject



218
219
220
221
222
223
224
225
# File 'lib/hivonic/commands.rb', line 218

def subcommand
  if self.query.nil? || self.query.empty?
    puts 'Nothing to cleanup!'
    Kernel.exit! 0
  else
    super
  end
end