Sha256: 10a87eab9e764cd24216f5f7823ac853ae1293d14751428e5a0a53ab220a3885

Contents?: true

Size: 809 Bytes

Versions: 29

Compression:

Stored size: 809 Bytes

Contents

require 'flydata/fluent-plugins/mysql/binlog_query_handler'

module Mysql

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

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

  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
end

end

Version data entries

29 entries across 29 versions & 1 rubygems

Version Path
flydata-0.5.11 lib/flydata/fluent-plugins/mysql/ddl_query_handler.rb
flydata-0.5.10 lib/flydata/fluent-plugins/mysql/ddl_query_handler.rb
flydata-0.5.9 lib/flydata/fluent-plugins/mysql/ddl_query_handler.rb
flydata-0.5.8 lib/flydata/fluent-plugins/mysql/ddl_query_handler.rb
flydata-0.5.7 lib/flydata/fluent-plugins/mysql/ddl_query_handler.rb
flydata-0.5.6 lib/flydata/fluent-plugins/mysql/ddl_query_handler.rb
flydata-0.5.5 lib/flydata/fluent-plugins/mysql/ddl_query_handler.rb
flydata-0.5.4 lib/flydata/fluent-plugins/mysql/ddl_query_handler.rb
flydata-0.5.3 lib/flydata/fluent-plugins/mysql/ddl_query_handler.rb
flydata-0.5.2 lib/flydata/fluent-plugins/mysql/ddl_query_handler.rb
flydata-0.5.1 lib/flydata/fluent-plugins/mysql/ddl_query_handler.rb
flydata-0.5.0 lib/flydata/fluent-plugins/mysql/ddl_query_handler.rb
flydata-0.4.3 lib/flydata/fluent-plugins/mysql/ddl_query_handler.rb
flydata-0.4.2 lib/flydata/fluent-plugins/mysql/ddl_query_handler.rb
flydata-0.4.1 lib/flydata/fluent-plugins/mysql/ddl_query_handler.rb
flydata-0.4.0 lib/flydata/fluent-plugins/mysql/ddl_query_handler.rb
flydata-0.3.24 lib/flydata/fluent-plugins/mysql/ddl_query_handler.rb
flydata-0.3.23 lib/flydata/fluent-plugins/mysql/ddl_query_handler.rb
flydata-0.3.22 lib/flydata/fluent-plugins/mysql/ddl_query_handler.rb
flydata-0.3.21 lib/flydata/fluent-plugins/mysql/ddl_query_handler.rb