<commit_before>/*
 * mysqlEventHandler.cpp
 *
 *  Created on: Sep 17, 2014
 *      Author: <NAME> <EMAIL>
 */

#include "mysqlEventHandler.h"
#include "json/json.h"
#include "Logger.h"

using srch2::util::Logger;

/****************************Table_index*******************************/
//Table index populates the table id and table name.
mysql::Binary_log_event *Table_index::process_event(
        mysql::Table_map_event *tm) {
    if (find(tm->table_id) == end())
        insert(std::pair<uint64_t, mysql::Table_map_event *>(tm->table_id, tm));

    /* Consume this event so it won't be deallocated beneith our feet */
    return 0;
}

Table_index::~Table_index() {
    Int2event_map::iterator it = begin();
    do {
        delete it->second;
    } while (++it != end());
}

int Table_index::get_table_name(int table_id, std::string out) {
    iterator it;
    if ((it = find(table_id)) == end()) {
        std::stringstream os;
        os << "unknown_table_" << table_id;
        out.append(os.str());
        return 1;
    }

    out.append(it->second->table_name);
    return 0;
}

/************************Incident_handler******************************/
//This class handles all the incident events like LOST_EVENTS.
mysql::Binary_log_event * Incident_handler::process_event(
        mysql::Incident_event * incident) {
    Logger::debug("MYSQLCONNECTOR: Incident event type: %s\n length: %d,"
            " next pos: %d\n type= %u, message= %s",
            mysql::system::get_event_type_str(incident->get_event_type()),
            incident->header()->event_length, incident->header()->next_position,
            (unsigned) incident->type, incident->message.c_str());
    /* Consume the event */
    delete incident;
    return 0;
}

/*****************************Applier**********************************/
//This class handles insert, delete, update events.
Applier::Applier(Table_index * index, ServerInterface * serverHandle,
        std::vector<std::string> * schemaName, time_t & startTimestamp,
        std::string & pk) {
    m_table_index = index;
    this->serverHandle = serverHandle;
    this->schemaName = schemaName;
    this->startTimestamp = startTimestamp;
    this->pk = pk;
}

mysql::Binary_log_event * Applier::process_event(mysql::Row_event * rev) {
    //Ignore the old event
    time_t ts = rev->header()->timestamp;

    if (ts <= startTimestamp) {
        return rev;
    }

    startTimestamp = ts;    //Update the time stamp

    //Get the table id
    uint64_t table_id = rev->table_id;
    Int2event_map::iterator ti_it = m_table_index->find(table_id);
    if (ti_it == m_table_index->end()) {
        Logger::error("MYSQLCONNECTOR: Table id %d was not registered"
                " by any preceding table map event.");
        return rev;
    }
    /*
     * Each row event contains multiple rows and fields. The Row_iterator
     * allows us to iterate one row at a time.
     */
    mysql::Row_event_set rows(rev, ti_it->second);

    //Create a fully qualified table name
    std::ostringstream os;
    os << ti_it->second->db_name << '.' << ti_it->second->table_name;
<commit_msg>Changed the <= to < because the time is sec level not millisec level, not accurate enough.<commit_after>/*
 * mysqlEventHandler.cpp
 *
 *  Created on: Sep 17, 2014
 *      Author: <NAME> <EMAIL>
 */

#include "mysqlEventHandler.h"
#include "json/json.h"
#include "Logger.h"

using srch2::util::Logger;

/****************************Table_index*******************************/
//Table index populates the table id and table name.
mysql::Binary_log_event *Table_index::process_event(
        mysql::Table_map_event *tm) {
    if (find(tm->table_id) == end())
        insert(std::pair<uint64_t, mysql::Table_map_event *>(tm->table_id, tm));

    /* Consume this event so it won't be deallocated beneith our feet */
    return 0;
}

Table_index::~Table_index() {
    Int2event_map::iterator it = begin();
    do {
        delete it->second;
    } while (++it != end());
}

int Table_index::get_table_name(int table_id, std::string out) {
    iterator it;
    if ((it = find(table_id)) == end()) {
        std::stringstream os;
        os << "unknown_table_" << table_id;
        out.append(os.str());
        return 1;
    }

    out.append(it->second->table_name);
    return 0;
}

/************************Incident_handler******************************/
//This class handles all the incident events like LOST_EVENTS.
mysql::Binary_log_event * Incident_handler::process_event(
        mysql::Incident_event * incident) {
    Logger::debug("MYSQLCONNECTOR: Incident event type: %s\n length: %d,"
            " next pos: %d\n type= %u, message= %s",
            mysql::system::get_event_type_str(incident->get_event_type()),
            incident->header()->event_length, incident->header()->next_position,
            (unsigned) incident->type, incident->message.c_str());
    /* Consume the event */
    delete incident;
    return 0;
}

/*****************************Applier**********************************/
//This class handles insert, delete, update events.
Applier::Applier(Table_index * index, ServerInterface * serverHandle,
        std::vector<std::string> * schemaName, time_t & startTimestamp,
        std::string & pk) {
    m_table_index = index;
    this->serverHandle = serverHandle;
    this->schemaName = schemaName;
    this->startTimestamp = startTimestamp;
    this->pk = pk;
}

mysql::Binary_log_event * Applier::process_event(mysql::Row_event * rev) {
    //Ignore the old event
    time_t ts = rev->header()->timestamp;

    if (ts < startTimestamp) {
        return rev;
    }

    startTimestamp = ts;    //Update the time stamp

    //Get the table id
    uint64_t table_id = rev->table_id;
    Int2event_map::iterator ti_it = m_table_index->find(table_id);
    if (ti_it == m_table_index->end()) {
        Logger::error("MYSQLCONNECTOR: Table id %d was not registered"
                " by any preceding table map event.");
        return rev;
    }
    /*
     * Each row event contains multiple rows and fields. The Row_iterator
     * allows us to iterate one row at a time.
     */
    mysql::Row_event_set rows(rev, ti_it->second);

    //Create a fully qualified table name
    std::ostringstream os;
    os << ti_it->second->db_name << '.' << ti_it->second->table_name;

{'fraction_non_alphanumeric': 0.1834282099936749, 'fraction_numerical': 0.005376344086021506, 'mean_word_length': 3.3203551912568305, 'pattern_counts': {'":': 0, '<': 35, '<?xml version=': 0, '>': 63, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2545437', 'n_tokens_mistral': 1960, 'n_tokens_neox': 1917, 'n_words': 484}