Class: Flydata::SourceMysql::PluginSupport::DdlQueryHandler

Inherits:
BinlogQueryHandler show all
Defined in:
lib/flydata/source_mysql/plugin_support/ddl_query_handler.rb

Constant Summary collapse

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

Constants included from PluginSupport::SyncRecordEmittable

PluginSupport::SyncRecordEmittable::RESPECT_ORDER, PluginSupport::SyncRecordEmittable::SEQ, PluginSupport::SyncRecordEmittable::SRC_POS, PluginSupport::SyncRecordEmittable::TABLE_NAME, PluginSupport::SyncRecordEmittable::TABLE_REV, PluginSupport::SyncRecordEmittable::TYPE, PluginSupport::SyncRecordEmittable::V

Instance Attribute Summary

Attributes included from PluginSupport::SyncRecordEmittable

#context

Instance Method Summary collapse

Methods inherited from BinlogQueryHandler

#pattern

Methods inherited from BinlogRecordHandler

#initialize

Methods included from PluginSupport::SyncRecordEmittable

#emit_sync_records

Constructor Details

This class inherits a constructor from Flydata::SourceMysql::PluginSupport::BinlogRecordHandler

Instance Method Details

#acceptable_db?(record) ⇒ Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/flydata/source_mysql/plugin_support/ddl_query_handler.rb', line 19

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

#emit_record(type, record) ⇒ Object



11
12
13
14
15
16
17
# File 'lib/flydata/source_mysql/plugin_support/ddl_query_handler.rb', line 11

def emit_record(type, record)
  # ddl event record doesn't have "table_name"
  record['table_name'] = table_info(record)[:table_name]
  super do |opt|
    yield opt
  end
end

#table_info(record) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/flydata/source_mysql/plugin_support/ddl_query_handler.rb', line 23

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