Class: Fluent::Plugin::GroongaOutput::TablesCreator

Inherits:
Object
  • Object
show all
Defined in:
lib/fluent/plugin/out_groonga.rb

Instance Method Summary collapse

Constructor Details

#initialize(client, definitions) ⇒ TablesCreator

Returns a new instance of TablesCreator.



265
266
267
268
# File 'lib/fluent/plugin/out_groonga.rb', line 265

def initialize(client, definitions)
  @client = client
  @definitions = definitions
end

Instance Method Details

#createObject



270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
# File 'lib/fluent/plugin/out_groonga.rb', line 270

def create
  return if @definitions.empty?

  table_list = @client.execute("table_list")
  @definitions.each do |definition|
    existing_table = table_list.find do |table|
      table.name == definition.name
    end
    if existing_table
      next unless definition.have_difference?(existing_table)
      # TODO: Is it OK?
      @client.execute("table_remove", "name" => definition.name)
    end

    @client.execute("table_create", definition.to_create_arguments)
    definition.indexes.each do |index|
      @client.execute("column_create", index.to_create_arguments)
    end
  end
end