From 2ceac817cc9de51299b3ba3e456feb31b5e8b30c Mon Sep 17 00:00:00 2001 From: Kouhei Sutou Date: Fri, 20 Feb 2015 17:51:17 +0900 Subject: [PATCH] truncate: fix a bug that array can't be truncated --- lib/db.c | 18 +++++++++------ .../suite/truncate/table/plain_array.expected | 23 +++++++++++++++++++ .../suite/truncate/table/plain_array.test | 13 +++++++++++ 3 files changed, 47 insertions(+), 7 deletions(-) create mode 100644 test/command/suite/truncate/table/plain_array.expected create mode 100644 test/command/suite/truncate/table/plain_array.test diff --git a/lib/db.c b/lib/db.c index d3548adc55..82fd9a18a3 100644 --- a/lib/db.c +++ b/lib/db.c @@ -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); } diff --git a/test/command/suite/truncate/table/plain_array.expected b/test/command/suite/truncate/table/plain_array.expected new file mode 100644 index 0000000000..1632bb63f7 --- /dev/null +++ b/test/command/suite/truncate/table/plain_array.expected @@ -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 + diff --git a/test/command/suite/truncate/table/plain_array.test b/test/command/suite/truncate/table/plain_array.test new file mode 100644 index 0000000000..bdfd1623a5 --- /dev/null +++ b/test/command/suite/truncate/table/plain_array.test @@ -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