Esempio n. 1
0
void
test_recreate_temporary_object_on_opened_database(void)
{
  const gchar table_name[] = "<users>";
  const gchar *path;

  path = cut_build_path(tmp_directory, "database.groonga", NULL);
  database = grn_db_create(context, path, NULL);
  grn_test_assert_not_null(context, database);
  grn_test_assert_null(context,
                           grn_table_create(context,
                                            table_name,
                                            strlen(table_name),
                                            NULL,
                                            GRN_OBJ_TABLE_HASH_KEY,
                                            grn_ctx_at(context, GRN_DB_UINT32),
                                            NULL));

  database2 = grn_db_open(context2, path);
  grn_test_assert_not_null(context2, database2);
  grn_test_assert_null(context2,
                       grn_ctx_get(context2,
                                   table_name,
                                   strlen(table_name)));
  grn_test_assert_null(context2,
                           grn_table_create(context,
                                            table_name,
                                            strlen(table_name),
                                            NULL,
                                            GRN_OBJ_TABLE_HASH_KEY,
                                            grn_ctx_at(context, GRN_DB_UINT32),
                                            NULL));
}
Esempio n. 2
0
void
test_get_persistent_object_from_opened_database(void)
{
  const gchar table_name[] = "Users";
  const gchar *path;

  path = cut_build_path(tmp_directory, "database.groonga", NULL);
  database = grn_db_create(context, path, NULL);
  grn_test_assert_not_null(context, database);
  grn_test_assert_not_null(context,
                           grn_table_create(context,
                                            table_name,
                                            strlen(table_name),
                                            NULL,
                                            GRN_OBJ_TABLE_HASH_KEY |
                                            GRN_OBJ_PERSISTENT,
                                            grn_ctx_at(context, GRN_DB_UINT32),
                                            NULL));

  database2 = grn_db_open(context2, path);
  grn_test_assert_not_null(context2, database2);
  grn_test_assert_not_null(context2,
                           grn_ctx_get(context2,
                                       table_name,
                                       strlen(table_name)));
}
void
cut_setup(void)
{
  const gchar *database_path;

  cut_set_fixture_data_dir(grn_test_get_base_dir(),
                           "fixtures",
                           "geo",
                           NULL);

  remove_tmp_directory();
  g_mkdir_with_parents(tmp_directory, 0700);

  context = g_new0(grn_ctx, 1);
  grn_ctx_init(context, 0);

  database_path = cut_build_path(tmp_directory, "database.groonga", NULL);
  database = grn_db_create(context, database_path, NULL);

  load_data();

  points = get("Points");
  short_degree_column = get("Points.short_degree");
  location_index_column = get("Locations.point");

  result = grn_table_create(context,
                            NULL, 0,
                            NULL,
                            GRN_TABLE_HASH_KEY | GRN_OBJ_WITH_SUBREC,
                            points, NULL);
}
Esempio n. 4
0
void
setup (void)
{
  grn_ctx_init(&context, 0);
  database = grn_db_create(&context, NULL, NULL);
  GRN_VOID_INIT(&buffer);
}
Esempio n. 5
0
void
cut_setup(void)
{
  const gchar *database_path;

  cut_set_fixture_data_dir(grn_test_get_base_dir(),
                           "fixtures",
                           "story",
                           "taiyaki",
                           NULL);

  remove_tmp_directory();
  g_mkdir_with_parents(tmp_directory, 0700);

  context = g_new0(grn_ctx, 1);
  grn_ctx_init(context, 0);

  database_path = cut_build_path(tmp_directory, "database.groonga", NULL);
  database = grn_db_create(context, database_path, NULL);

  setup_values();
  load_data();

  shops = get("Shops");
  location_index = get("Locations.shop");

  result = grn_table_create(context,
                            NULL, 0,
                            NULL,
                            GRN_TABLE_HASH_KEY | GRN_OBJ_WITH_SUBREC,
                            shops, NULL);
}
Esempio n. 6
0
static int
run(grn_ctx *ctx, const char *db_path, const char *ruby_script_path)
{
  grn_obj *db;

  db = grn_db_open(ctx, db_path);
  if (!db) {
    if (ctx->rc == GRN_NO_SUCH_FILE_OR_DIRECTORY) {
      db = grn_db_create(ctx, db_path, NULL);
      if (!db) {
        fprintf(stderr, "Failed to create database: <%s>: %s",
                db_path, ctx->errbuf);
        return EXIT_FAILURE;
      }
    } else {
      fprintf(stderr, "Failed to open database: <%s>: %s",
              db_path, ctx->errbuf);
      return EXIT_FAILURE;
    }
  }

  grn_mrb_load(ctx, ruby_script_path);
  if (ctx->rc != GRN_SUCCESS) {
      fprintf(stderr, "Failed to load Ruby script: <%s>: %s",
              ruby_script_path, ctx->errbuf);
  }

  grn_obj_close(ctx, db);

  if (ctx->rc == GRN_SUCCESS) {
    return EXIT_SUCCESS;
  } else {
    return EXIT_FAILURE;
  }
}
static void
ngx_http_groonga_create_database(ngx_http_groonga_loc_conf_t *location_conf,
                                 ngx_http_groonga_database_callback_data_t *data)
{
  const char *database_base_name;
  grn_ctx *context;

  database_base_name = strrchr(location_conf->database_path_cstr, '/');
  if (database_base_name) {
    char database_dir[PATH_MAX];
    database_dir[0] = '\0';
    strncat(database_dir,
            location_conf->database_path_cstr,
            database_base_name - location_conf->database_path_cstr);
    data->rc = ngx_http_groonga_mkdir_p(data->log, database_dir);
    if (data->rc != NGX_OK) {
      return;
    }
  }

  context = &(location_conf->context);
  grn_db_create(context, location_conf->database_path_cstr, NULL);
  if (context->rc == GRN_SUCCESS) {
    return;
  }

  ngx_log_error(NGX_LOG_EMERG, data->log, 0,
                "failed to create groonga database: %s",
                context->errbuf);
  data->rc = NGX_ERROR;
}
Esempio n. 8
0
void
cut_setup(void)
{
  logger = setup_grn_logger();
  grn_ctx_init(&context, 0);
  database = grn_db_create(&context, NULL, NULL);
}
Esempio n. 9
0
grn_index *
grn_index_open(grn_ctx *ctx, const char *path)
{
  grn_obj *db, *keys, *key_type, *lexicon, *inv, *tokenizer;
  if ((db = grn_db_create(ctx, NULL, NULL))) {
    char buffer[PATH_MAX];
    strcpy(buffer, path);
    strcat(buffer, ".SEN");
    if ((key_type = grn_ctx_at(ctx, GRN_DB_SHORTTEXT))) {
      if ((keys = grn_table_open(ctx, "<keys>", 6, buffer))) {
        strcpy(buffer, path);
        strcat(buffer, ".SEN.l");
        if ((lexicon = grn_table_open(ctx, "<lexicon>", 9, buffer))) {
          if ((tokenizer = grn_ctx_at(ctx, GRN_DB_MECAB))) {
            grn_obj_set_info(ctx, lexicon, GRN_INFO_DEFAULT_TOKENIZER, tokenizer);
            strcpy(buffer, path);
            strcat(buffer, ".SEN.i");
            if ((inv = grn_column_open(ctx, lexicon, "inv", 3, buffer, keys))) {
              grn_index *index;
              if ((index = malloc(sizeof(grn_index)))) {
                index->db = db;
                index->keys = keys;
                index->lexicon = lexicon;
                index->inv = inv;
                return index;
              }
            }
          }
        }
      }
    }
  }
  return NULL;
}
Esempio n. 10
0
void
cut_setup(void)
{
  const gchar *database_path;

  cut_set_fixture_data_dir(grn_test_get_base_dir(),
                           "fixtures",
                           "story",
                           "taiyaki",
                           NULL);

  remove_tmp_directory();
  g_mkdir_with_parents(tmp_directory, 0700);

  context = g_new0(grn_ctx, 1);
  grn_ctx_init(context, 0);

  database_path = cut_build_path(tmp_directory, "database.groonga", NULL);
  database = grn_db_create(context, database_path, NULL);

  assert_send_commands(cut_get_fixture_data_string("ddl.grn", NULL));
  assert_send_command(cut_get_fixture_data_string("areas.grn", NULL));
  assert_send_command(cut_get_fixture_data_string("categories.grn", NULL));
  assert_send_command(cut_get_fixture_data_string("shops.grn", NULL));
  assert_send_command(cut_get_fixture_data_string("synonyms.grn", NULL));
}
Esempio n. 11
0
void
test_expression_lifetime_over_database(void)
{
  const gchar *path;
  gint i, n_tries = 100;
  grn_obj *expression;

  cut_omit("will be SEGVed.");
  path = cut_build_path(tmp_directory, "database.groonga", NULL);
  for (i = 0; i < n_tries; i++) {
    gint j, n_records = 100;
    const gchar *query;
    grn_obj *table, *variable;
    grn_obj default_column;

    database = grn_db_create(context, path, NULL);
    grn_test_assert_context(context);

    assert_send_command("table_create Sites 0 ShortText");
    assert_send_command("column_create Sites point COLUMN_SCALAR Int32");
    for (j = 0; j < n_records; j++) {
      gchar *command;

      command = g_strdup_printf("load '"
                                "[[\"_key\", \"point\"],"
                                "[\"http://groonga.org/version/%d\",%d]]' "
                                "Sites",
                                j, j);
      assert_send_command(command);
      g_free(command);
    }

    table = get_object("Sites");
    GRN_EXPR_CREATE_FOR_QUERY(context, table, expression, variable);
    grn_obj_unlink(context, table);

    GRN_TEXT_INIT(&default_column, 0);
    GRN_TEXT_PUTS(context, &default_column, "point");
    query = "point:50";
    grn_expr_parse(context, expression,
                   query, strlen(query),
                   &default_column,
                   GRN_OP_MATCH, GRN_OP_AND,
                   GRN_EXPR_SYNTAX_QUERY | GRN_EXPR_ALLOW_COLUMN);
    grn_test_assert_context(context);
    grn_obj_unlink(context, &default_column);
    grn_expr_compile(context, expression);

    grn_obj_remove(context, database);
    database = NULL;

    remove_tmp_directory();
    g_mkdir_with_parents(tmp_directory, 0700);
  }

  grn_ctx_fin(context);
  g_free(context);
  context = NULL;
}
Esempio n. 12
0
 void cut_startup()
 {
   ctx = (grn_ctx *)malloc(sizeof(grn_ctx));
   grn_init();
   grn_ctx_init(ctx, 0);
   db = grn_db_create(ctx, NULL, NULL);
   grn_ctx_use(ctx, db);
 }
Esempio n. 13
0
void
cut_setup(void)
{
  cut_remove_path(tmp_directory, NULL);
  g_mkdir_with_parents(tmp_directory, 0700);
  path = g_build_filename(tmp_directory, "text-expr", NULL);
  grn_ctx_init(&context, 0);
  database = grn_db_create(&context, path, NULL);
}
Esempio n. 14
0
void
test_cursor(void)
{
  grn_table_cursor *c;
  database = grn_db_create(context, NULL, NULL);
  c = grn_table_cursor_open(context, database, NULL, 0, NULL, 0, 0, -1, 0);
  cut_assert_true(grn_table_cursor_next(context, c));
  grn_table_cursor_close(context, c);
}
Esempio n. 15
0
static void
bench_setup_common(gpointer user_data)
{
  BenchmarkData *data = user_data;

  grn_ctx_init(data->context, GRN_CTX_USE_QL);
  data->database = grn_db_create(data->context, NULL, NULL);
  data->expression = grn_expr_create(data->context, NULL, 0);
}
Esempio n. 16
0
void
test_expire_cache_on_recreate(void)
{
  const gchar *path;

  path = cut_build_path(tmp_directory, "database.groonga", NULL);
  database = grn_db_create(context, path, NULL);
  assert_send_command("table_create Sites 0 ShortText");
  assert_send_command("load '[[\"_key\"],[\"groonga.org\"]]' Sites");
  cut_assert_equal_string("[[[1],[[\"_key\",\"ShortText\"]],[\"groonga.org\"]]]",
                          send_command("select Sites --output_columns _key"));
  assert_send_command("table_remove Sites");
  grn_obj_remove(context, database);

  database = grn_db_create(context, path, NULL);
  assert_send_command("table_create Sites 0 ShortText");
  cut_assert_equal_string("[[[0],[[\"_key\",\"ShortText\"]]]]",
                          send_command("select Sites --output_columns _key"));
}
Esempio n. 17
0
void
cut_setup(void)
{
  logger = setup_grn_logger();
  grn_ctx_init(&context, 0);
  database = grn_db_create(&context, NULL, NULL);

  create_bookmarks_table();
  add_count_column_to_bookmarks_table();
  add_groonga_bookmark();
}
Esempio n. 18
0
void
cut_setup(void)
{
  remove_tmp_directory();
  g_mkdir_with_parents(tmp_directory, 0700);

  context = g_new0(grn_ctx, 1);
  grn_ctx_init(context, 0);

  database_path = cut_build_path(tmp_directory, "database.groonga", NULL);
  database = grn_db_create(context, database_path, NULL);
}
Esempio n. 19
0
void
cut_setup(void)
{
  context = NULL;

  logger = setup_grn_logger();

  context = g_new0(grn_ctx, 1);
  grn_ctx_init(context, 0);

  database = grn_db_create(context, NULL, NULL);
}
Esempio n. 20
0
static void
setup_database(void)
{
  remove_tmp_directory();
  g_mkdir_with_parents(tmp_directory, 0700);

  database = grn_db_create(context, database_path, NULL);
  grn_test_assert_context(context);

  setup_ddl();
  setup_data();
}
Esempio n. 21
0
void
cut_setup(void)
{
    gchar *table_path, *vgram_path;
    const gchar *type_name, *table_name;

    cut_set_fixture_data_dir(grn_test_get_base_dir(),
                             "fixtures",
                             "inverted-index",
                             NULL);

    logger = setup_grn_logger();

    expected_messages = NULL;
    record_ids = NULL;

    remove_tmp_directory();
    g_mkdir_with_parents(tmp_directory, 0700);
    path = g_build_filename(tmp_directory, "inverted-index", NULL);

    context = g_new0(grn_ctx, 1);
    grn_test_assert(grn_ctx_init(context, GRN_CTX_USE_QL));
    GRN_CTX_SET_ENCODING(context, GRN_ENC_UTF8);

    db = grn_db_create(context, NULL, NULL);
    grn_ctx_use(context, db);

    type_name = "name";
    type = grn_type_create(context, type_name, strlen(type_name),
                           GRN_OBJ_KEY_VAR_SIZE, TYPE_SIZE);

    table_name = "lexicon";
    table_path = g_build_filename(tmp_directory, "lexicon-table", NULL);
    lexicon = grn_table_create(context,
                               table_name, strlen(table_name),
                               table_path,
                               GRN_OBJ_PERSISTENT | GRN_OBJ_TABLE_PAT_KEY,
                               type, NULL);

    grn_obj_set_info(context, lexicon, GRN_INFO_DEFAULT_TOKENIZER,
                     grn_ctx_at(context, GRN_DB_BIGRAM));

    g_free(table_path);

    vgram_path = g_build_filename(tmp_directory, "vgram", NULL);
    /*
      vgram = grn_vgram_create(vgram_path);
    */
    g_free(vgram_path);

    inverted_index = NULL;
}
Esempio n. 22
0
static void
setup_database(BenchmarkData *data)
{
  grn_ctx *context = &(data->context);
  gchar *tmp_dir;
  gchar *database_last_component_name;
  gchar *database_path;
  guint i;

  tmp_dir = get_tmp_dir();
  database_last_component_name =
    g_strdup_printf("db-%d-%s-mruby",
                    data->n_records,
                    data->use_mruby ? "with" : "without");
  database_path = g_build_filename(tmp_dir,
                                   "range-select",
                                   database_last_component_name,
                                   NULL);
  g_free(database_last_component_name);

  if (g_file_test(database_path, G_FILE_TEST_EXISTS)) {
    data->database = grn_db_open(context, database_path);
    run_command(context, "dump");
  } else {
    data->database = grn_db_create(context, database_path, NULL);

    run_command(context, "table_create Entries TABLE_NO_KEY");
    run_command(context, "column_create Entries rank COLUMN_SCALAR Int32");
    run_command(context, "table_create Ranks TABLE_PAT_KEY Int32");
    run_command(context,
                "column_create Ranks entries_rank COLUMN_INDEX Entries rank");

    run_command(context, "load --table Entries");
    run_command(context, "[");
    for (i = 0; i < data->n_records; i++) {
#define BUFFER_SIZE 4096
      gchar buffer[BUFFER_SIZE];
      const gchar *separator;
      if (i == (data->n_records - 1)) {
        separator = "";
      } else {
        separator = ",";
      }
      snprintf(buffer, BUFFER_SIZE, "{\"rank\": %u}%s", i, separator);
      run_command(context, buffer);
#undef BUFFER_SIZE
    }
    run_command(context, "]");
  }

  g_free(database_path);
}
Esempio n. 23
0
void
cut_setup(void)
{
    cut_remove_path(tmp_directory, NULL);
    g_mkdir_with_parents(tmp_directory, 0700);
    path = g_build_filename(tmp_directory, "text-expr", NULL);
    context = g_new0(grn_ctx, 1);
    grn_ctx_init(context, 0);
    database = grn_db_create(context, path, NULL);

    expr = NULL;

    GRN_TEXT_INIT(&textbuf, 0);
    GRN_UINT32_INIT(&intbuf, 0);
}
Esempio n. 24
0
static void
setup_database(void)
{
  gchar *database_path;

  tmp_directory = g_build_filename(grn_test_get_tmp_dir(),
                                   NULL);
  database_path = g_build_filename(tmp_directory,
                                   "cast-table.db",
                                   NULL);

  g_mkdir_with_parents(tmp_directory, 0700);
  database = grn_db_create(&context, database_path, NULL);
  g_free(database_path);
}
Esempio n. 25
0
void
cut_setup(void)
{
  remove_tmp_directory();
  g_mkdir_with_parents(tmp_directory, 0700);

  context = NULL;
  logger = setup_grn_logger();

  context = g_new0(grn_ctx, 1);
  grn_ctx_init(context, 0);

  database = grn_db_create(context,
                           cut_build_path(tmp_directory, "table.db", NULL),
                           NULL);
}
Esempio n. 26
0
void
cut_setup(void)
{
  cut_remove_path(tmp_directory, NULL);
  g_mkdir_with_parents(tmp_directory, 0700);
  path = g_build_filename(tmp_directory, "text-table-select", NULL);
  grn_ctx_init(&context, 0);
  database = grn_db_create(&context, path, NULL);

  cond = NULL;
  expr = NULL;
  res = NULL;

  GRN_TEXT_INIT(&text_buf, 0);
  GRN_UINT32_INIT(&int_buf, 0);
  GRN_PTR_INIT(&ptr_buf, 0, GRN_ID_NIL);
}
Esempio n. 27
0
void
cut_setup(void)
{
  cut_remove_path(tmp_directory, NULL);
  g_mkdir_with_parents(tmp_directory, 0700);
  path = g_build_filename(tmp_directory, "text-expr", NULL);
  grn_ctx_init(&context, 0);
  database = grn_db_create(&context, path, NULL);

  expr = NULL;
  res = NULL;

  GRN_TEXT_INIT(&textbuf, 0);
  GRN_UINT32_INIT(&intbuf, 0);
  GRN_FLOAT_INIT(&floatbuf, 0);
  GRN_TIME_INIT(&timebuf, 0);
}
Esempio n. 28
0
/*
 * 新しくデータベースを作成する。
 * _options_ にはハッシュでオプションを指定する。
 *
 * @example
 *   # 一時データベースを作成:
 *   Groonga::Database.create
 *
 *   # 永続データベースを作成:
 *   Groonga::Database.create(:path => "/tmp/db.groonga")
 *
 * @overload create(options=nil)
 *   @return [Groonga::Database] 作成されたデータベースを返す。
 *   @param [::Hash] options The name and value
 *     pairs. Omitted names are initialized as the default value.
 *   @option options :path
 *     データベースを保存するパス。省略すると一時データベース
 *     となる。
 *   @option options :context (Groonga::Context.default)
 *     データベースを結びつけるコンテキスト。省略すると
 *     {Groonga::Context.default} を利用する。
 */
static VALUE
rb_grn_database_s_create (int argc, VALUE *argv, VALUE klass)
{
    grn_ctx *context;
    grn_obj *old_database, *database;
    grn_db_create_optarg create_args;
    const char *path = NULL;
    VALUE rb_database;
    VALUE rb_path, options, rb_context, builtin_type_names;
    grn_bool owner;

    rb_scan_args(argc, argv, "01", &options);

    rb_grn_scan_options(options,
                        "path", &rb_path,
                        "context", &rb_context,
                        "builtin_type_names", &builtin_type_names,
                        NULL);

    if (!NIL_P(rb_path))
        path = StringValuePtr(rb_path);
    context = rb_grn_context_ensure(&rb_context);

    create_args.builtin_type_names = NULL;
    create_args.n_builtin_type_names = 0;

    old_database = grn_ctx_db(context);
    if (old_database)
        grn_obj_unlink(context, old_database);
    reset_floating_objects(rb_context);
    database = grn_db_create(context, path, &create_args);
    rb_grn_context_check(context, rb_ary_new_from_values(argc, argv));
    owner = (context->flags & GRN_CTX_PER_DB) ? GRN_FALSE : GRN_TRUE;
    rb_database = GRNOBJECT2RVAL(klass, context, database, owner);
    rb_iv_set(rb_database, "@context", rb_context);
    if (!NIL_P(rb_context))
        rb_iv_set(rb_context, "database", rb_database);
    rb_grn_context_check(context, rb_ary_new_from_values(argc, argv));

    if (rb_block_given_p())
        return rb_ensure(rb_yield, rb_database,
                         rb_grn_database_close, rb_database);
    else
        return rb_database;
}
void
cut_setup(void)
{
  const gchar *database_path;

  remove_tmp_directory();
  g_mkdir_with_parents(tmp_directory, 0700);

  context = g_new0(grn_ctx, 1);
  grn_ctx_init(context, 0);

  database_path = cut_build_path(tmp_directory, "database.groonga", NULL);
  database = grn_db_create(context, database_path, NULL);

  assert_send_command("table_create Test TABLE_PAT_KEY ShortText");
  assert_send_command("column_create Test name COLUMN_SCALAR Text");
  table = get_object("Test");
}
Esempio n. 30
0
void
cut_setup(void)
{
  const gchar *database_path;

  remove_tmp_directory();
  g_mkdir_with_parents(tmp_directory, 0700);

  context = g_new0(grn_ctx, 1);
  grn_ctx_init(context, 0);

  database_path = cut_build_path(tmp_directory, "database.groonga", NULL);
  database = grn_db_create(context, database_path, NULL);
  table = NULL;
  column = NULL;
  result = NULL;
  cursor = NULL;
}