Sha256: dac7ac437e7ef2d8c41c34898329fd19763b8ed2af5509434301786f71aea8ea

Contents?: true

Size: 954 Bytes

Versions: 2

Compression:

Stored size: 954 Bytes

Contents

require_relative 'alter_table_query_handler'

module Mysql
  class BinlogQueryDispatcher
    def initialize
      @handlers = []
    end

    def dispatch(record)
      @handlers.each do |handler|
        query = normalize_query(record["query"])
        if (handler.pattern.match(query))
          handler.process(record, query)
          break
        end
      end
    end

    private

    def normalize_query(query)
      query = strip_comments(query)
    end

    def strip_comments(query)
      query = query.gsub(/--\s.*\n/, ' ')  # -- style comments
      query = query.gsub(/\/\*[^\*].*\*\//, ' ') # /* */ style comments
      query = query.gsub(/\s+/, ' ') # replace multiple spaces with a space
    end
  end

  class FlydataBinlogQueryDispatcher < BinlogQueryDispatcher
    def initialize(context)
      @handlers = [
# TODO Uncomment below to enable AlterTable support
#        AlterTableQueryHandler.new(context),
      ]
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
flydata-0.1.15 lib/flydata/fluent-plugins/mysql/binlog_query_dispatcher.rb
flydata-0.1.13 lib/flydata/fluent-plugins/mysql/binlog_query_dispatcher.rb