[Groonga-commit] groonga/groonga at 7731876 [master] Support cascade delete for vector column that has not reference type

Back to archive index

Kouhei Sutou null+****@clear*****
Fri Sep 20 19:34:42 JST 2013


Kouhei Sutou	2013-09-20 19:34:42 +0900 (Fri, 20 Sep 2013)

  New Revision: 7731876d071eb55db97ce6b186f56eda74555f34
  https://github.com/groonga/groonga/commit/7731876d071eb55db97ce6b186f56eda74555f34

  Message:
    Support cascade delete for vector column that has not reference type
    
    "not reference type" means normal type such as ShortText.

  Added files:
    test/command/suite/delete/reference/vector_type.expected
    test/command/suite/delete/reference/vector_type.test
  Modified files:
    lib/db.c

  Modified: lib/db.c (+21 -5)
===================================================================
--- lib/db.c    2013-09-20 19:27:00 +0900 (92914f4)
+++ lib/db.c    2013-09-20 19:34:42 +0900 (e6ce743)
@@ -1576,11 +1576,11 @@ delete_reference_records_in_index(grn_ctx *ctx, grn_obj *table, grn_id id,
       case GRN_OBJ_COLUMN_VECTOR :
         {
           grn_obj value;
+          grn_obj new_value;
           GRN_TEXT_INIT(&value, 0);
           grn_obj_get_value(ctx, source, posting->rid, &value);
           if (value.header.type == GRN_UVECTOR) {
             int i, n_ids;
-            grn_obj new_value;
             GRN_RECORD_INIT(&new_value, GRN_OBJ_VECTOR, value.header.domain);
             n_ids = GRN_BULK_VSIZE(&value) / sizeof(grn_id);
             for (i = 0; i < n_ids; i++) {
@@ -1590,12 +1590,28 @@ delete_reference_records_in_index(grn_ctx *ctx, grn_obj *table, grn_id id,
               }
               GRN_RECORD_PUT(ctx, &new_value, reference_id);
             }
-            grn_obj_set_value(ctx, source, posting->rid, &new_value,
-                              GRN_OBJ_SET);
-            GRN_OBJ_FIN(ctx, &new_value);
           } else {
-            /* TODO */
+            unsigned int i, n_elements;
+            GRN_TEXT_INIT(&new_value, GRN_OBJ_VECTOR);
+            n_elements = grn_vector_size(ctx, &value);
+            for (i = 0; i < n_elements; i++) {
+              const char *content;
+              unsigned int content_length;
+              unsigned int weight;
+              grn_id domain;
+              content_length =
+                grn_vector_get_element(ctx, &value, i,
+                                       &content, &weight, &domain);
+              if (grn_table_get(ctx, table, content, content_length) == id) {
+                continue;
+              }
+              grn_vector_add_element(ctx, &new_value, content, content_length,
+                                     weight, domain);
+            }
           }
+          grn_obj_set_value(ctx, source, posting->rid, &new_value,
+                            GRN_OBJ_SET);
+          GRN_OBJ_FIN(ctx, &new_value);
           GRN_OBJ_FIN(ctx, &value);
         }
         break;

  Added: test/command/suite/delete/reference/vector_type.expected (+40 -0) 100644
===================================================================
--- /dev/null
+++ test/command/suite/delete/reference/vector_type.expected    2013-09-20 19:34:42 +0900 (01f2624)
@@ -0,0 +1,40 @@
+table_create Users TABLE_HASH_KEY ShortText
+[[0,0.0,0.0],true]
+table_create URLs TABLE_HASH_KEY ShortText
+[[0,0.0,0.0],true]
+column_create Users bookmarks COLUMN_VECTOR ShortText
+[[0,0.0,0.0],true]
+column_create URLs author COLUMN_SCALAR Users
+[[0,0.0,0.0],true]
+column_create URLs bookmarks_index COLUMN_INDEX Users bookmarks
+[[0,0.0,0.0],true]
+load --table Users
+[
+{"_key": "mori", "bookmarks": ["http://mroonga.org/", "http://groonga.org/", "http://ranguba.org/"]}
+]
+[[0,0.0,0.0],1]
+load --table URLs
+[
+{"_key": "http://groonga.org/", "author": "mori"}
+]
+[[0,0.0,0.0],1]
+delete URLs --key "http://groonga.org/"
+[[0,0.0,0.0],true]
+dump
+table_create Users TABLE_HASH_KEY ShortText
+column_create Users bookmarks COLUMN_VECTOR ShortText
+table_create URLs TABLE_HASH_KEY ShortText
+column_create URLs bookmarks_index COLUMN_INDEX Users bookmarks
+column_create URLs author COLUMN_SCALAR Users
+load --table Users
+[
+["_key","bookmarks"],
+["mori",["http://mroonga.org/","http://ranguba.org/"]]
+]
+load --table URLs
+[
+["_key","author"],
+["http://mroonga.org/",""],
+["http://ranguba.org/",""]
+]
+

  Added: test/command/suite/delete/reference/vector_type.test (+21 -0) 100644
===================================================================
--- /dev/null
+++ test/command/suite/delete/reference/vector_type.test    2013-09-20 19:34:42 +0900 (b507a38)
@@ -0,0 +1,21 @@
+table_create Users TABLE_HASH_KEY ShortText
+table_create URLs TABLE_HASH_KEY ShortText
+
+column_create Users bookmarks COLUMN_VECTOR ShortText
+column_create URLs author COLUMN_SCALAR Users
+
+column_create URLs bookmarks_index COLUMN_INDEX Users bookmarks
+
+load --table Users
+[
+{"_key": "mori", "bookmarks": ["http://mroonga.org/", "http://groonga.org/", "http://ranguba.org/"]}
+]
+
+load --table URLs
+[
+{"_key": "http://groonga.org/", "author": "mori"}
+]
+
+delete URLs --key "http://groonga.org/"
+
+dump
-------------- next part --------------
HTML����������������������������...
Download 



More information about the Groonga-commit mailing list
Back to archive index