Skip to content

Commit

Permalink
truncate: fix a bug that array can't be truncated
Browse files Browse the repository at this point in the history
  • Loading branch information
kou committed Feb 20, 2015
1 parent 131e60b commit 2ceac81
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 7 deletions.
18 changes: 11 additions & 7 deletions lib/db.c
Expand Up @@ -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) {
Expand Down Expand Up @@ -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);
}
Expand Down
23 changes: 23 additions & 0 deletions 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

13 changes: 13 additions & 0 deletions 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

0 comments on commit 2ceac81

Please sign in to comment.