Class: Hivonic::Commands::ListTables

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

Instance Attribute Summary

Attributes inherited from HiveQueryCommand

#db, #hive_opts

Attributes inherited from Subcommand

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

Instance Method Summary collapse

Methods inherited from HiveQueryCommand

#initialize, #subcommand

Methods inherited from Subcommand

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

Constructor Details

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

Instance Method Details

#filter(stdout) ⇒ Object



127
128
129
130
131
132
133
# File 'lib/hivonic/commands.rb', line 127

def filter(stdout)
  lines = stdout.split(/\n/)

  lines.select do |line|
    is_table_expired? line
  end.join("\n")
end

#is_expired?(time) ⇒ Boolean

Returns:

  • (Boolean)


113
114
115
# File 'lib/hivonic/commands.rb', line 113

def is_expired?(time)
  (Time.now.utc - self.ttl) > time
end

#is_table_expired?(table) ⇒ Boolean

Returns:

  • (Boolean)


117
118
119
120
121
122
123
124
125
# File 'lib/hivonic/commands.rb', line 117

def is_table_expired?(table)
  match = table.match self.regexp

  if match.nil?
    false
  else
    is_expired? Time.strptime(match[self.time_group_index], self.time_format)
  end
end

#output(stdout) ⇒ Object



135
136
137
138
139
140
141
# File 'lib/hivonic/commands.rb', line 135

def output(stdout)
  if dry_run
    super
  else
    filter(stdout)
  end
end

#queryObject



143
144
145
# File 'lib/hivonic/commands.rb', line 143

def query
  @query = "USE #{self.db}; SHOW TABLES;"
end