Class: Mysql::DdlQueryHandler

Inherits:
BinlogQueryHandler show all
Defined in:
lib/flydata/fluent-plugins/mysql/ddl_query_handler.rb

Constant Summary collapse

DDL_TABLE_QUERY =
/^(?:(?:ALTER|CREATE|DROP|RENAME) +(?:\w+ +)*TABLE +([^ ]+)|TRUNCATE +(?:TABLE +)?([^ ;]+))/i

Constants inherited from BinlogRecordHandler

BinlogRecordHandler::RESPECT_ORDER, BinlogRecordHandler::SEQ, BinlogRecordHandler::SRC_POS, BinlogRecordHandler::TABLE_NAME, BinlogRecordHandler::TABLE_REV, BinlogRecordHandler::TYPE, BinlogRecordHandler::V

Instance Method Summary collapse

Methods inherited from BinlogQueryHandler

#pattern

Methods inherited from BinlogRecordHandler

#initialize

Constructor Details

This class inherits a constructor from Mysql::BinlogRecordHandler

Instance Method Details

#acceptable_db?(record) ⇒ Boolean

Returns:

  • (Boolean)

8
9
10
# File 'lib/flydata/fluent-plugins/mysql/ddl_query_handler.rb', line 8

def acceptable_db?(record)
  supported_database == table_info(record)[:db_name]
end

#table_info(record) ⇒ Object


12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/flydata/fluent-plugins/mysql/ddl_query_handler.rb', line 12

def table_info(record)
  table_info = { db_name: record["db_name"], table_name: nil }
  if DDL_TABLE_QUERY =~ record["normalized_query"]
    table_name_in_query = ($1 ? $1 : $2).tr("`", "")

    if (idx = table_name_in_query.index("."))
      table_info[:db_name] = table_name_in_query[0...idx]
      table_info[:table_name] = table_name_in_query[idx+1..-1]
    else
      table_info[:table_name] = table_name_in_query
    end
  end
  table_info
end