<commit_before>#ifdef USE_PRAGMA_IMPLEMENTATION
#pragma implementation
#endif

#include <mysql_priv.h>
#include <mysql/plugin.h>
#include <groonga.h>
#include <pthread.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>

#ifdef __cplusplus
extern "C" {
#endif

#include "ha_groonga.h"

/* static function definition */
static int mrn_init(void *p);
static int mrn_deinit(void *p);
static handler *mrn_handler_create(handlerton *hton,
				   TABLE_SHARE *share,
				   MEM_ROOT *root);
static void mrn_logger_func(int level, const char *time, const char *title,
			    const char *msg, const char *location, void *func_arg);
static bool mrn_flush_logs(handlerton *hton);
static grn_encoding mrn_charset_mysql_groonga(const char *csname);
static const char *mrn_charset_groonga_mysql(grn_encoding encoding);
static void mrn_ctx_init();
static grn_obj *mrn_db_open_or_create();
static mrn_share *mrn_share_get(const char *name);
static void mrn_share_put(mrn_share *share);
static void mrn_share_remove(mrn_share *share);


/* static variables */
static grn_hash *mrn_hash_sys;
static grn_obj *mrn_db_sys;
static pthread_mutex_t *mrn_mutex_sys;
  static const char *mrn_logfile_name=MRN_LOG_FILE_NAME;
static FILE *mrn_logfile = NULL;

static grn_logger_info mrn_logger_info = {
  GRN_LOG_DUMP,
  GRN_LOG_TIME|GRN_LOG_MESSAGE,
  mrn_logger_func,
  NULL
};

static MRN_CHARSET_MAP mrn_charset_map[] = {
  {"utf8", GRN_ENC_UTF8},
  {"cp932", GRN_ENC_SJIS},
  {"sjis", GRN_ENC_SJIS},
  {"eucjpms", GRN_ENC_EUC_JP},
  {"ujis", GRN_ENC_EUC_JP},
  {"latin1", GRN_ENC_LATIN1},
  {"koi8r", GRN_ENC_KOI8R},
  {0x0, GRN_ENC_DEFAULT},
  {0x0, GRN_ENC_NONE}
};

/* TLS variables */
__thread grn_ctx *mrn_ctx_tls;

/* handler declaration */
struct st_mysql_storage_engine storage_engine_structure =
{ MYSQL_HANDLERTON_INTERFACE_VERSION };

mysql_declare_plugin(mroonga)
{
  MYSQL_STORAGE_ENGINE_PLUGIN,
  &storage_engine_structure,
  "Mroonga",
  "<NAME>",
  "MySQL binding for Groonga",
  PLUGIN_LICENSE_BSD,
  mrn_init,
  mrn_deinit,
  0x0001,
  NULL,
  NULL,
  NULL
}
mysql_declare_plugin_end;

/* handler implementation */
ha_groonga::ha_groonga(handlerton *hton, TABLE_SHARE *share)
  :handler(hton, share)
{
}

ha_groonga::~ha_groonga()
{
}

const char *ha_groonga::table_type() const
{
  return "Mroonga";
}

const char *ha_groonga::index_type(uint inx)
{
  return "NONE";
}

static const char*ha_groonga_exts[] = {
  ".grn",
  NullS
};
const char **ha_groonga::bas_ext() const
{
  return ha_groonga_exts;
}

ulonglong ha_groonga::table_flags() const
{
  return HA_NO_TRANSACTIONS|HA_REQUIRE_PRIMARY_KEY;
}

ulong ha_groonga::index_flags(uint idx, uint part, bool all_parts) const
{
  return 0;
}



/*
  create a table, mrn_table and push it to db hash.
  currently only using in-memory table in groonga.
*/
int ha_groonga::create(const char *name, TABLE *form, HA_CREATE_INFO *info)
{
  mrn_ctx_init();
  MRN_TRACE;

  const char *obj_name = MRN_TABLE_NAME(name);
  char path[MRN_MAX_KEY_LEN];
  MRN_TABLE_PATH(path, obj_name);

  grn_obj *key_type = grn_ctx_get(mrn_ctx_tls, GRN_DB_SHORTTEXT);
  MRN_LOG(GRN_LOG_DEBUG, "-> grn_table_create: name='%s', path='%s'",obj_name, path);
  grn_obj *table_obj = grn_table_create(mrn_ctx_tls, obj_name, strlen(obj_name), path,
				  GRN_OBJ_PERSISTENT|GRN_OBJ_TABLE_PAT_KEY,
				  key_type,1000,GRN_ENC_UTF8);
  int i;<commit_msg>prohibit multi-column primary key.<commit_after>#ifdef USE_PRAGMA_IMPLEMENTATION
#pragma implementation
#endif

#include <mysql_priv.h>
#include <mysql/plugin.h>
#include <groonga.h>
#include <pthread.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>

#ifdef __cplusplus
extern "C" {
#endif

#include "ha_groonga.h"

/* static function definition */
static int mrn_init(void *p);
static int mrn_deinit(void *p);
static handler *mrn_handler_create(handlerton *hton,
				   TABLE_SHARE *share,
				   MEM_ROOT *root);
static void mrn_logger_func(int level, const char *time, const char *title,
			    const char *msg, const char *location, void *func_arg);
static bool mrn_flush_logs(handlerton *hton);
static grn_encoding mrn_charset_mysql_groonga(const char *csname);
static const char *mrn_charset_groonga_mysql(grn_encoding encoding);
static void mrn_ctx_init();
static grn_obj *mrn_db_open_or_create();
static mrn_share *mrn_share_get(const char *name);
static void mrn_share_put(mrn_share *share);
static void mrn_share_remove(mrn_share *share);


/* static variables */
static grn_hash *mrn_hash_sys;
static grn_obj *mrn_db_sys;
static pthread_mutex_t *mrn_mutex_sys;
  static const char *mrn_logfile_name=MRN_LOG_FILE_NAME;
static FILE *mrn_logfile = NULL;

static grn_logger_info mrn_logger_info = {
  GRN_LOG_DUMP,
  GRN_LOG_TIME|GRN_LOG_MESSAGE,
  mrn_logger_func,
  NULL
};

static MRN_CHARSET_MAP mrn_charset_map[] = {
  {"utf8", GRN_ENC_UTF8},
  {"cp932", GRN_ENC_SJIS},
  {"sjis", GRN_ENC_SJIS},
  {"eucjpms", GRN_ENC_EUC_JP},
  {"ujis", GRN_ENC_EUC_JP},
  {"latin1", GRN_ENC_LATIN1},
  {"koi8r", GRN_ENC_KOI8R},
  {0x0, GRN_ENC_DEFAULT},
  {0x0, GRN_ENC_NONE}
};

/* TLS variables */
__thread grn_ctx *mrn_ctx_tls;

/* handler declaration */
struct st_mysql_storage_engine storage_engine_structure =
{ MYSQL_HANDLERTON_INTERFACE_VERSION };

mysql_declare_plugin(mroonga)
{
  MYSQL_STORAGE_ENGINE_PLUGIN,
  &storage_engine_structure,
  "Mroonga",
  "<NAME>",
  "MySQL binding for Groonga",
  PLUGIN_LICENSE_BSD,
  mrn_init,
  mrn_deinit,
  0x0001,
  NULL,
  NULL,
  NULL
}
mysql_declare_plugin_end;

/* handler implementation */
ha_groonga::ha_groonga(handlerton *hton, TABLE_SHARE *share)
  :handler(hton, share)
{
}

ha_groonga::~ha_groonga()
{
}

const char *ha_groonga::table_type() const
{
  return "Mroonga";
}

const char *ha_groonga::index_type(uint inx)
{
  return "NONE";
}

static const char*ha_groonga_exts[] = {
  ".grn",
  NullS
};
const char **ha_groonga::bas_ext() const
{
  return ha_groonga_exts;
}

ulonglong ha_groonga::table_flags() const
{
  return HA_NO_TRANSACTIONS|HA_REQUIRE_PRIMARY_KEY;
}

ulong ha_groonga::index_flags(uint idx, uint part, bool all_parts) const
{
  return 0;
}



/*
  create a table, mrn_table and push it to db hash.
  currently only using in-memory table in groonga.
*/
int ha_groonga::create(const char *name, TABLE *form, HA_CREATE_INFO *info)
{
  mrn_ctx_init();
  MRN_TRACE;

  /* key_parts validation */
  int pkey_parts = form->key_info[form->s->primary_key].key_parts;
  if (pkey_parts > 1) {
    MRN_LOG(GRN_LOG_ERROR, "primary key must be single column");
    return HA_WRONG_CREATE_OPTION;
  }

  const char *obj_name = MRN_TABLE_NAME(name);
  char path[MRN_MAX_KEY_LEN];
  MRN_TABLE_PATH(path, obj_name);

  grn_obj *key_type = grn_ctx_get(mrn_ctx_tls, GRN_DB_SHORTTEXT);
  MRN_LOG(GRN_LOG_DEBUG, "-> grn_table_create: name='%s', path='%s'",obj_name, path);
  grn_obj *table_obj = grn_table_create(mrn_ctx_tls, obj_name, strlen(obj_name), path,
				  GRN_OBJ_PERSISTENT|GRN_OBJ_TABLE_PAT_KEY,
				  key_type,1000,GRN_ENC_UTF8);
  int i;
{'fraction_non_alphanumeric': 0.11461604339137882, 'fraction_numerical': 0.006994005138452755, 'mean_word_length': 5.763513513513513, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 25, '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': '5958439', 'n_tokens_mistral': 2997, 'n_tokens_neox': 2893, 'n_words': 563}