[Groonga-commit] groonga/groonga at 2ceac81 [master] truncate: fix a bug that array can't be truncated

Back to archive index

Kouhei Sutou null+****@clear*****
Fri Feb 20 17:51:17 JST 2015


Kouhei Sutou	2015-02-20 17:51:17 +0900 (Fri, 20 Feb 2015)

  New Revision: 2ceac817cc9de51299b3ba3e456feb31b5e8b30c
  https://github.com/groonga/groonga/commit/2ceac817cc9de51299b3ba3e456feb31b5e8b30c

  Message:
    truncate: fix a bug that array can't be truncated

  Added files:
    test/command/suite/truncate/table/plain_array.expected
    test/command/suite/truncate/table/plain_array.test
  Modified files:
    lib/db.c

  Modified: lib/db.c (+11 -7)
===================================================================
--- lib/db.c    2015-02-20 17:38:41 +0900 (d3548ad)
+++ lib/db.c    2015-02-20 17:51:17 +0900 (82fd9a1)
@@ -1919,9 +1919,11 @@ grn_table_truncate(grn_ctx *ctx, grn_obj *table)
       }
       grn_hash_close(ctx, cols);
     }
-    grn_table_get_info(ctx, table, NULL, NULL, &tokenizer, &normalizer, NULL);
-    GRN_PTR_INIT(&token_filters, GRN_OBJ_VECTOR, GRN_ID_NIL);
-    grn_obj_get_info(ctx, table, GRN_INFO_TOKEN_FILTERS, &token_filters);
+    if (table->header.type != GRN_TABLE_NO_KEY) {
+      grn_table_get_info(ctx, table, NULL, NULL, &tokenizer, &normalizer, NULL);
+      GRN_PTR_INIT(&token_filters, GRN_OBJ_VECTOR, GRN_ID_NIL);
+      grn_obj_get_info(ctx, table, GRN_INFO_TOKEN_FILTERS, &token_filters);
+    }
     switch (table->header.type) {
     case GRN_TABLE_PAT_KEY :
       for (hooks = DB_OBJ(table)->hooks[GRN_HOOK_INSERT]; hooks; hooks = hooks->next) {
@@ -1954,10 +1956,12 @@ grn_table_truncate(grn_ctx *ctx, grn_obj *table)
       rc = grn_array_truncate(ctx, (grn_array *)table);
       break;
     }
-    grn_obj_set_info(ctx, table, GRN_INFO_DEFAULT_TOKENIZER, tokenizer);
-    grn_obj_set_info(ctx, table, GRN_INFO_NORMALIZER, normalizer);
-    grn_obj_set_info(ctx, table, GRN_INFO_TOKEN_FILTERS, &token_filters);
-    GRN_OBJ_FIN(ctx, &token_filters);
+    if (table->header.type != GRN_TABLE_NO_KEY) {
+      grn_obj_set_info(ctx, table, GRN_INFO_DEFAULT_TOKENIZER, tokenizer);
+      grn_obj_set_info(ctx, table, GRN_INFO_NORMALIZER, normalizer);
+      grn_obj_set_info(ctx, table, GRN_INFO_TOKEN_FILTERS, &token_filters);
+      GRN_OBJ_FIN(ctx, &token_filters);
+    }
     if (rc == GRN_SUCCESS) {
       grn_obj_touch(ctx, table, NULL);
     }

  Added: test/command/suite/truncate/table/plain_array.expected (+23 -0) 100644
===================================================================
--- /dev/null
+++ test/command/suite/truncate/table/plain_array.expected    2015-02-20 17:51:17 +0900 (1632bb6)
@@ -0,0 +1,23 @@
+table_create Diaries TABLE_NO_KEY
+[[0,0.0,0.0],true]
+column_create Diaries content COLUMN_SCALAR Text
+[[0,0.0,0.0],true]
+load --table Diaries
+[
+{"content": "I tried Groonga."}
+]
+[[0,0.0,0.0],1]
+dump
+table_create Diaries TABLE_NO_KEY
+column_create Diaries content COLUMN_SCALAR Text
+load --table Diaries
+[
+["_id","content"],
+[1,"I tried Groonga."]
+]
+truncate Diaries
+[[0,0.0,0.0],true]
+dump
+table_create Diaries TABLE_NO_KEY
+column_create Diaries content COLUMN_SCALAR Text
+

  Added: test/command/suite/truncate/table/plain_array.test (+13 -0) 100644
===================================================================
--- /dev/null
+++ test/command/suite/truncate/table/plain_array.test    2015-02-20 17:51:17 +0900 (bdfd162)
@@ -0,0 +1,13 @@
+table_create Diaries TABLE_NO_KEY
+column_create Diaries content COLUMN_SCALAR Text
+
+load --table Diaries
+[
+{"content": "I tried Groonga."}
+]
+
+dump
+
+truncate Diaries
+
+dump
-------------- next part --------------
HTML����������������������������...
Download 



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