예제 #1
0
void
test_equal_numeric(gconstpointer data)
{
  const gchar *type;

  type = gcut_data_get_string(data, "type");

  assert_send_command("table_create Sites TABLE_HASH_KEY ShortText");
  assert_send_command(
    cut_take_printf("column_create Sites score COLUMN_SCALAR %s", type));

  cut_assert_equal_string(
    "3",
    send_command("load --table Sites --columns '_key, score' \n"
                 "[\n"
                 " [\"groonga.org\", 5],\n"
                 " [\"ruby-lang.org\", 4],\n"
                 " [\"qwik.jp/senna/\", 3]\n"
                 "]"));
  cut_assert_equal_string(
    cut_take_printf("[[[1],"
                     "[[\"_key\",\"ShortText\"],"
                      "[\"score\",\"%s\"]],"
                     "[\"ruby-lang.org\",4]]]",
                    type),
    send_command("select Sites "
                 "--sortby -score "
                 "--output_columns _key,score "
                 "--filter 'score == 4'"));
}
예제 #2
0
void
test_no_columns(void)
{
  assert_send_command("table_create Users TABLE_HASH_KEY ShortText");
  assert_send_command("load --table Users\n"
                      "[\n"
                      "{\"_key\":\"mori\"}\n"
                      "{\"_key\":\"gunyara-kun\"}\n"
                      "{\"_key\":\"yu\"}\n"
                      "]");
  cut_assert_equal_string(
      "[[[3],"
       "[[\"_id\",\"UInt32\"],[\"_key\",\"ShortText\"]],"
       "[1,\"mori\"],"
       "[2,\"gunyara-kun\"],"
       "[3,\"yu\"]]]",
    send_command("select Users"));
  cut_assert_equal_string("true",
                          send_command("truncate Users"));
  cut_assert_equal_string(
      "[[[0],"
       "[[\"_id\",\"UInt32\"],[\"_key\",\"ShortText\"]]"
       "]]",
    send_command("select Users"));
}
void
test_key_normalize(gconstpointer data)
{
  assert_send_command("table_create NormalizedSynonyms "
                      "TABLE_PAT_KEY|KEY_NORMALIZE ShortText");
  assert_send_command("column_create NormalizedSynonyms words_scalar "
                      "COLUMN_SCALAR ShortText");
  assert_send_command("column_create NormalizedSynonyms words_vector "
                      "COLUMN_VECTOR ShortText");
  assert_send_command("load --table NormalizedSynonyms\n"
                      "[\n"
                      "[\"_key\", \"words_scalar\", \"words_vector\"],\n"
                      "[\"Ruby\", "
                       "\"(Ruby OR rroonga)\", "
                       "[\"Ruby\", \"rroonga\"]]\n"
                      "]");

  cut_assert_equal_string(
    "[[[3],"
     "[[\"_id\",\"UInt32\"],"
      "[\"_key\",\"Time\"],"
      "[\"content\",\"Text\"]],"
     "[3,1315839600.0,\"Start rroonga!\"],"
     "[4,1315926000.0,\"Start Ruby!\"],"
     "[9,1316358000.0,\"Learning Ruby and groonga...\"]]]",
    send_command(
      cut_take_printf("select Diaries "
                      "--sortby _id "
                      "--match_columns content --query ruby "
                      "--query_expansion NormalizedSynonyms.%s",
                      gcut_data_get_string(data, "column-name"))));
}
예제 #4
0
void
test_have_columns(void)
{
  cut_omit("This test is failed. See #892.");

  assert_send_command("table_create Users TABLE_PAT_KEY ShortText");
  assert_send_command("column_create Users name COLUMN_SCALAR ShortText");
  assert_send_command("load --table Users\n"
                      "[\n"
                      "{\"_key\":\"mori\", \"name\":\"Daijiro MORI\"},\n"
                      "{\"_key\":\"gunyara-kun\", \"name\":\"Tasuku SUENAGA\"},\n"
                      "{\"_key\":\"yu\", \"name\":\"Yutaro Shimamura\"}\n"
                      "]");
  cut_assert_equal_string(
      "[[[3],"
       "[[\"_id\",\"UInt32\"],"
        "[\"_key\",\"ShortText\"],"
        "[\"name\",\"ShortText\"]],"
       "[1,\"mori\",\"Daijiro MORI\"],"
       "[2,\"gunyara-kun\",\"Tasuku SUENAGA\"],"
       "[3,\"yu\",\"Yutaro Shimamura\"]]]",
    send_command("select Users --sortby _id"));
  cut_assert_equal_string("true",
                          send_command("truncate Users"));
  cut_assert_equal_string(
      "[[[0],"
       "[[\"_id\",\"UInt32\"],"
        "[\"_key\",\"ShortText\"],"
        "[\"name\",\"ShortText\"]]"
       "]]",
    send_command("select Users"));
}
예제 #5
0
void
test_columns(void)
{
    assert_send_command("table_create Users TABLE_HASH_KEY ShortText");
    assert_send_command("column_create Users name COLUMN_SCALAR ShortText");
    assert_send_command("column_create Users desc COLUMN_SCALAR ShortText");
    cut_assert_equal_string(
        "2",
        send_command("load --table Users --columns '_key,name,desc'\n"
                     "[\n"
                     "  [\"mori\", \"モリ\", \"タポ\"],\n"
                     "  [\"tapo\", \"タポ\", \"モリモリモリタポ\"]\n"
                     "]"));
    cut_assert_equal_string("[[[2],"
                            "["
                            "[\"_id\",\"UInt32\"],"
                            "[\"_key\",\"ShortText\"],"
                            "[\"name\",\"ShortText\"],"
                            "[\"desc\",\"ShortText\"]"
                            "],"
                            "[1,\"mori\",\"モリ\",\"タポ\"],"
                            "[2,\"tapo\",\"タポ\",\"モリモリモリタポ\"]"
                            "]]",
                            send_command("select Users"));
}
예제 #6
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));
}
void
test_japanese(gconstpointer data)
{
  const gchar *expected, *command;

  assert_send_command("table_create Users TABLE_NO_KEY");
  assert_send_command("column_create Users name COLUMN_SCALAR ShortText");
  assert_send_command("load --table Users\n"
                      "[\n"
                      "[\"name\"],\n"
                      "[\"もり\"],\n"
                      "[\"グニャラくん\"],\n"
                      "[\"ゆう\"],\n"
                      "[\"たぽ\"],\n"
                      "[\"たぽぽ\"],\n"
                      "[\"たぱ\"],\n"
                      "[\"たこ\"],\n"
                      "[\"とぽ\"]\n"
                      "]");

  expected =
      cut_take_printf("[[[8],"
                      "[[\"name\",\"ShortText\"],[\"_score\",\"Int32\"]],"
                      "%s"
                      "]]",
                      gcut_data_get_string(data, "expected"));
  command = cut_take_printf("select Users "
                            "--output_columns name,_score "
                            "--filter true "
                            "--sortby _score,name "
                            "--scorer '_score=edit_distance(name, \"%s\")'",
                            gcut_data_get_string(data, "string"));

  cut_assert_equal_string(expected, send_command(command));
}
예제 #8
0
void
test_vector_int32_reference_key(void)
{
  assert_send_command("table_create Users TABLE_HASH_KEY Int32");
  assert_send_command("column_create Users name COLUMN_SCALAR ShortText");
  assert_send_command("table_create Comments TABLE_PAT_KEY ShortText");
  assert_send_command("column_create Comments text COLUMN_SCALAR ShortText");
  assert_send_command("column_create Comments authors COLUMN_VECTOR Users");

  cut_assert_equal_string("2",
                          send_command("load --table Users\n"
                                       "[\n"
                                       "[\"_key\",\"name\"],\n"
                                       "[1000,\"ryoqun\"],\n"
                                       "[1001,\"hayamiz\"]\n"
                                       "]"));

  cut_assert_equal_string(
    "1",
    send_command("load --table Comments\n"
                 "[\n"
                 "[\"_key\",\"text\",\"authors\"],\n"
                 "[\"groonga\",\"it is fast\",[1000,1001]]\n"
                 "]"));

  cut_assert_equal_string("[[[1],"
                           "[[\"_id\",\"UInt32\"],"
                            "[\"_key\",\"ShortText\"],"
                            "[\"authors\",\"Users\"],"
                            "[\"text\",\"ShortText\"]],"
                           "[1,\"groonga\",[1000,1001],\"it is fast\"]]]",
                          send_command("select Comments"));
}
예제 #9
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;
}
예제 #10
0
void
test_register_by_absolute_path(void)
{
  assert_send_command(cut_take_printf("register %s/string", plugins_dir));
  assert_send_command("table_create Sites TABLE_HASH_KEY ShortText");
  assert_send_command("load '[[\"_key\"],[\"groonga.org\"]]' Sites");
  cut_assert_equal_string("[[[1],[[\"_score\",\"Int32\"]],[11]]]",
                          send_command("select Sites "
                                       "--output_columns _score "
                                       "--filter true "
                                       "--scorer '_score=str_len(_key)'"));
}
예제 #11
0
void
test_success(void)
{
  assert_send_command("register functions/cast");
  assert_send_command("table_create Numbers TABLE_HASH_KEY ShortText");
  assert_send_command("column_create Numbers int32 COLUMN_SCALAR Int32");
  assert_send_command("load '[[\"_key\"],[\"100\"]]' Numbers");
  cut_assert_equal_string("[[[1],[[\"int32\",\"Int32\"]],[100]]]",
                          send_command("select Numbers "                \
                                       "--output_columns int32 "        \
                                       "--scorer 'int32=cast(_key, Int32)'"));
}
예제 #12
0
void
test_register_function(void)
{
  assert_send_command("register string");
  assert_send_command("table_create Sites TABLE_HASH_KEY ShortText");
  assert_send_command("load '[[\"_key\"],[\"groonga.org\"]]' Sites");
  cut_assert_equal_string("[[[1],[[\"_score\",\"Int32\"]],[11]]]",
                          send_command("select Sites "
                                       "--output_columns _score "
                                       "--filter true "
                                       "--scorer '_score=str_len(_key)'"));
}
예제 #13
0
void
test_columns(void)
{
  assert_send_command("table_create Users TABLE_HASH_KEY ShortText");
  assert_send_command("column_create Users age COLUMN_SCALAR UInt32");
  assert_send_command("column_create Users comment COLUMN_SCALAR Text");
  cut_assert_equal_string(
      cut_take_printf("["
                      "["
                      "[\"id\",\"UInt32\"],"
                      "[\"name\",\"ShortText\"],"
                      "[\"path\",\"ShortText\"],"
                      "[\"type\",\"ShortText\"],"
                      "[\"flags\",\"ShortText\"],"
                      "[\"domain\",\"ShortText\"],"
                      "[\"range\",\"ShortText\"],"
                      "[\"source\",\"ShortText\"]"
                      "],"
                      "[%d,"
                      "\"_key\","
                      "\"\","
                      "\"\","
                      "\"COLUMN_SCALAR\","
                      "\"Users\","
                      "\"ShortText\","
                      "[]"
                      "],"
                      "[%d,"
                      "\"comment\","
                      "\"%s.0000102\","
                      "\"var\","
                      "\"COLUMN_SCALAR|PERSISTENT\","
                      "\"Users\","
                      "\"Text\","
                      "[]"
                      "],"
                      "[%d,"
                      "\"age\","
                      "\"%s.0000101\","
                      "\"fix\","
                      "\"COLUMN_SCALAR|PERSISTENT\","
                      "\"Users\","
                      "\"UInt32\","
                      "[]"
                      "]"
                      "]",
                      grn_obj_id(context, get("Users")),
                      grn_obj_id(context, get("Users.comment")), database_path,
                      grn_obj_id(context, get("Users.age")), database_path),
      send_command("column_list Users"));
}
예제 #14
0
void
test_nonexistent_columns(void)
{
    assert_send_command("table_create Users TABLE_NO_KEY");
    assert_send_command("column_create Users name COLUMN_SCALAR ShortText");
    grn_test_assert_send_command_error(context,
                                       GRN_INVALID_ARGUMENT,
                                       "nonexistent column: <nonexistent>",
                                       "load "
                                       "--table Users "
                                       "--columns nonexistent "
                                       "--values "
                                       "'[[\"nonexistent column value\"]]'");
}
예제 #15
0
void
test_invalid_column(void)
{
  GList *log = NULL;

  assert_send_command("table_create Users TABLE_HASH_KEY ShortText");
  assert_send_command("column_create Users desc COLUMN_SCALAR ShortText");
  grn_collect_logger_clear_messages(logger);
  assert_send_command("load --table Users --input_type json\n"
                      "{\"_key\": \"groonga\", \"info\" \"search engine\"}\n"
                      "");
  log = g_list_next(grn_collect_logger_get_messages(logger));
  cut_assert_equal_string("invalid column('info')", g_list_nth_data(log, 0));
}
예제 #16
0
static void
setup_data(void)
{
    assert_send_command("table_create Users TABLE_HASH_KEY ShortText");
    assert_send_command("table_create Bookmarks TABLE_HASH_KEY ShortText");
    assert_send_command("table_create Bigram TABLE_PAT_KEY ShortText "
                        "--default_tokenizer TokenBigram");

    assert_send_command("column_create Bookmarks user COLUMN_SCALAR Users");
    assert_send_command("column_create Users bookmarks COLUMN_INDEX "
                        "Bookmarks user");
    assert_send_command("column_create Bigram user COLUMN_INDEX|WITH_POSITION "
                        "Users _key");

    assert_send_command("load --table Users --columns '_key'\n"
                        "[\n"
                        "  [\"mori\"],\n"
                        "  [\"tapo\"]\n"
                        "]");
    assert_send_command("load --table Bookmarks --columns '_key, user'\n"
                        "[\n"
                        "  [\"http://groonga.org/\", \"yu\"],\n"
                        "  [\"http://cutter.sourceforge.net/\", \"tasukuchan\"]\n"
                        "]");
}
예제 #17
0
void
test_no_key_table(void)
{
    assert_send_command("table_create Users TABLE_NO_KEY");
    assert_send_command("column_create Users name COLUMN_SCALAR ShortText");
    assert_send_command("column_create Users desc COLUMN_SCALAR ShortText");
    cut_assert_equal_string("2",
                            send_command("load "
                                         "--table Users "
                                         "--columns 'name, desc' "
                                         "--values "
                                         "'[[\"mori\", \"the author of groonga\"],"
                                         "[\"gunyara-kun\", \"co-author\"]]'"));
}
예제 #18
0
void
test_no_key(void)
{
  GList *log = NULL;

  assert_send_command("table_create Users TABLE_HASH_KEY ShortText");
  assert_send_command("column_create Users desc COLUMN_SCALAR ShortText");
  grn_collect_logger_clear_messages(logger);
  assert_send_command("load --table Users --input_type json\n"
                      "{\"info\" \"search engine\"}\n"
                      "");
  log = g_list_next(grn_collect_logger_get_messages(logger));
  cut_assert_equal_string("neither _key nor _id is assigned", g_list_nth_data(log, 0));
}
예제 #19
0
void
test_duplicated_key(void)
{
  GList *log = NULL;

  assert_send_command("table_create Users TABLE_HASH_KEY ShortText");
  assert_send_command("column_create Users desc COLUMN_SCALAR ShortText");
  grn_collect_logger_clear_messages(logger);
  assert_send_command("load --table Users --input_type json\n"
                      "{\"_key\": \"groonga\", \"_id\": 1}\n"
                      "");
  log = g_list_next(grn_collect_logger_get_messages(logger));
  cut_assert_equal_string("duplicated key columns: _key and _id", g_list_nth_data(log, 0));
}
예제 #20
0
void
test_int64_compare_over_int32(void)
{
  assert_send_command("table_create Integers TABLE_NO_KEY");
  assert_send_command("column_create Integers int64 COLUMN_SCALAR Int64");
  assert_send_command("load --table Integers\n"
                      "[\n"
                      "{\"int64\":344494643000000}\n"
                      "]");
  cut_assert_equal_string(
      "[[[1],"
       "[[\"_id\",\"UInt32\"],[\"int64\",\"Int64\"]],"
       "[1,344494643000000]]]",
    send_command("select Integers --query int64:<=344494643000000"));
}
예제 #21
0
void
test_uint64(void)
{
    assert_send_command("table_create Students TABLE_HASH_KEY UInt64");
    assert_send_command("load --table Students --columns '_key'\n"
                        "[\n"
                        "  [29],\n"
                        "  [2929]\n"
                        "]");
    assert_send_command("delete Students 2929");
    cut_assert_equal_string("[[[1],"
                            "[[\"_key\",\"UInt64\"]],"
                            "[29]]]",
                            send_command("select Students "
                                         "--output_columns _key"));
}
예제 #22
0
void
test_invalid_start_with_symbol(void)
{
    const gchar *table_list_result;

    table_list_result =
        cut_take_printf("["
                        "[[\"id\",\"UInt32\"],"
                        "[\"name\",\"ShortText\"],"
                        "[\"path\",\"ShortText\"],"
                        "[\"flags\",\"ShortText\"],"
                        "[\"domain\",\"ShortText\"],"
                        "[\"range\",\"ShortText\"]],"
                        "[256,"
                        "\"Authors\","
                        "\"%s.0000100\","
                        "\"TABLE_PAT_KEY|PERSISTENT\","
                        "\"ShortText\","
                        "\"null\"]]",
                        database_path);

    assert_send_command("table_create Authors TABLE_PAT_KEY ShortText");
    cut_assert_equal_string(table_list_result, send_command("table_list"));
    grn_test_assert_send_command_error(context,
                                       GRN_INVALID_ARGUMENT,
                                       "JSON must start with '[' or '{': <invalid>",
                                       "load "
                                       "--table Authors "
                                       "--columns '_key' "
                                       "--values 'invalid'");
    cut_assert_equal_string(table_list_result, send_command("table_list"));
}
예제 #23
0
void
test_no_key(void)
{
  assert_send_command("table_create Users TABLE_NO_KEY");
  grn_test_assert_users_exist();
  grn_test_assert_equal_type(context, GRN_TABLE_NO_KEY, users->header.type);
}
예제 #24
0
static void
setup_ddl(void)
{
  assert_send_command("table_create Comments TABLE_HASH_KEY ShortText");
  comments = get_object("Comments");
  assert_send_command("column_create Comments content COLUMN_SCALAR ShortText");
  content = get_object("Comments.content");

  assert_send_command("table_create Terms "
                      "--flags TABLE_PAT_KEY|KEY_NORMALIZE "
                      "--key_type ShortText "
                      "--default_tokenizer TokenBigram");
  assert_send_command("column_create Terms comment_content COLUMN_INDEX "
                      "Comments "
                      "--source content");
}
예제 #25
0
void
test_hash_key(void)
{
  assert_send_command("table_create Users TABLE_HASH_KEY ShortText");
  grn_test_assert_users_exist();
  grn_test_assert_equal_type(context, GRN_TABLE_HASH_KEY, users->header.type);
}
예제 #26
0
void
test_prefix_search(void)
{
  assert_send_command("table_create Users TABLE_PAT_KEY ShortText");
  assert_send_command("load --table Users\n"
                      "[\n"
                      "{\"_key\":\"mori\"},\n"
                      "{\"_key\":\"morita\"},\n"
                      "{\"_key\":\"mona\"}\n"
                      "]");
  cut_assert_equal_string(
      "[[[2],"
       "[[\"_id\",\"UInt32\"],[\"_key\",\"ShortText\"]],"
       "[2,\"morita\"],"
       "[1,\"mori\"]]]",
    send_command("select Users --match_columns _key --query mor*"));
}
예제 #27
0
static void
setup_data(void)
{
  assert_send_command("load "
                      "'[[\"_key\",\"content\"],"
                      "[\"ボロ\",\"うちのボロTV(アナログ...)はまだ現役です\"]]' "
                      "Comments");
}
예제 #28
0
void
test_invalid_char(void)
{
  GList *log = NULL;

  assert_send_command("table_create Users TABLE_HASH_KEY ShortText");
  assert_send_command("column_create Users name COLUMN_SCALAR ShortText");
  assert_send_command("column_create Users desc COLUMN_SCALAR ShortText");
  grn_collect_logger_clear_messages(logger);
  assert_send_command("load --table Users --input_type json\n"
                      "{\"name\": \"groonga\" @ \"desc\" \"search engine\"}\n"
                      "");
  log = g_list_next(grn_collect_logger_get_messages(logger));
  cut_assert_equal_string("ignored invalid char('@') at", g_list_nth_data(log, 0));
  cut_assert_equal_string("{\"name\": \"groonga\" @", g_list_nth_data(log, 1));
  cut_assert_equal_string("                   ^", g_list_nth_data(log, 2));
}
예제 #29
0
void
test_is_table(gconstpointer data)
{
  const gchar *name;
  grn_obj *object;

  assert_send_command("table_create Users TABLE_HASH_KEY ShortText");
  assert_send_command("column_create Users name COLUMN_SCALAR ShortText");

  name = gcut_data_get_string(data, "name");
  object = grn_ctx_get(context, name, strlen(name));
  if (gcut_data_get_string(data, "expected")) {
    cut_assert_true(grn_obj_is_table(context, object));
  } else {
    cut_assert_false(grn_obj_is_table(context, object));
  }
}
예제 #30
0
void
test_vector_int32(void)
{
  assert_send_command("table_create Students TABLE_HASH_KEY ShortText");
  assert_send_command("column_create Students scores COLUMN_VECTOR Int32");

  cut_assert_equal_string("1",
                          send_command("load --table Students\n"
                                       "[{\"_key\": \"Daijiro MORI\", "
                                         "\"scores\": [5, 5, 5]}]"));
  cut_assert_equal_string("[[[1],"
                           "[[\"_id\",\"UInt32\"],"
                            "[\"_key\",\"ShortText\"],"
                            "[\"scores\",\"Int32\"]],"
                           "[1,\"Daijiro MORI\",[5,5,5]]]]",
                          send_command("select Students"));
}