Navigation Menu

Skip to content

Commit

Permalink
dump: don't dump records of lexicon
Browse files Browse the repository at this point in the history
  • Loading branch information
kou committed Apr 3, 2015
1 parent 94834e5 commit 073feb7
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 7 deletions.
24 changes: 17 additions & 7 deletions lib/proc.c
Expand Up @@ -2944,6 +2944,7 @@ dump_records(grn_ctx *ctx, grn_obj *outbuf, grn_obj *table)
grn_table_cursor *cursor;
int i, ncolumns, n_use_columns;
grn_obj columnbuf, delete_commands, use_columns, column_name;
grn_bool have_only_index_column = GRN_TRUE;

switch (table->header.type) {
case GRN_TABLE_HASH_KEY:
Expand All @@ -2959,12 +2960,6 @@ dump_records(grn_ctx *ctx, grn_obj *outbuf, grn_obj *table)
return;
}

GRN_TEXT_INIT(&delete_commands, 0);

GRN_TEXT_PUTS(ctx, outbuf, "load --table ");
dump_obj_name(ctx, outbuf, table);
GRN_TEXT_PUTS(ctx, outbuf, "\n[\n");

GRN_PTR_INIT(&columnbuf, GRN_OBJ_VECTOR, GRN_ID_NIL);
grn_obj_columns(ctx, table, DUMP_COLUMNS, strlen(DUMP_COLUMNS), &columnbuf);
columns = (grn_obj **)GRN_BULK_HEAD(&columnbuf);
Expand All @@ -2977,6 +2972,10 @@ dump_records(grn_ctx *ctx, grn_obj *outbuf, grn_obj *table)
continue;
}

if (columns[i]->header.type != GRN_ACCESSOR) {
have_only_index_column = GRN_FALSE;
}

GRN_BULK_REWIND(&column_name);
grn_column_name_(ctx, columns[i], &column_name);
if (GRN_TEXT_LEN(&column_name) == GRN_COLUMN_NAME_ID_LEN &&
Expand All @@ -2997,6 +2996,14 @@ dump_records(grn_ctx *ctx, grn_obj *outbuf, grn_obj *table)
GRN_PTR_PUT(ctx, &use_columns, columns[i]);
}

if (have_only_index_column) {
goto exit;
}

GRN_TEXT_PUTS(ctx, outbuf, "load --table ");
dump_obj_name(ctx, outbuf, table);
GRN_TEXT_PUTS(ctx, outbuf, "\n[\n");

n_use_columns = GRN_BULK_VSIZE(&use_columns) / sizeof(grn_obj *);
GRN_TEXT_PUTC(ctx, outbuf, '[');
for (i = 0; i < n_use_columns; i++) {
Expand All @@ -3009,6 +3016,7 @@ dump_records(grn_ctx *ctx, grn_obj *outbuf, grn_obj *table)
}
GRN_TEXT_PUTS(ctx, outbuf, "],\n");

GRN_TEXT_INIT(&delete_commands, 0);
cursor = grn_table_cursor_open(ctx, table, NULL, 0, NULL, 0, 0, -1,
GRN_CURSOR_BY_KEY);
for (i = 0; (id = grn_table_cursor_next(ctx, cursor)) != GRN_ID_NIL;
Expand Down Expand Up @@ -3096,14 +3104,16 @@ dump_records(grn_ctx *ctx, grn_obj *outbuf, grn_obj *table)
grn_ctx_output_flush(ctx, 0);
}
}
grn_table_cursor_close(ctx, cursor);
GRN_TEXT_PUTS(ctx, outbuf, "\n]\n");
GRN_TEXT_PUT(ctx, outbuf, GRN_TEXT_VALUE(&delete_commands),
GRN_TEXT_LEN(&delete_commands));
grn_obj_unlink(ctx, &delete_commands);

exit :
grn_obj_unlink(ctx, &column_name);
grn_obj_unlink(ctx, &use_columns);

grn_table_cursor_close(ctx, cursor);
for (i = 0; i < ncolumns; i++) {
grn_obj_unlink(ctx, columns[i]);
}
Expand Down
23 changes: 23 additions & 0 deletions test/command/suite/dump/record/lexicon.expected
@@ -0,0 +1,23 @@
table_create Memos TABLE_NO_KEY
[[0,0.0,0.0],true]
column_create Memos content COLUMN_SCALAR ShortText
[[0,0.0,0.0],true]
table_create Terms TABLE_PAT_KEY ShortText --default_tokenizer TokenBigram --normalizer NormalizerAuto
[[0,0.0,0.0],true]
column_create Terms memos_content_index COLUMN_INDEX|WITH_POSITION Memos content
[[0,0.0,0.0],true]
load --table Memos
[
{"content": "Groonga is fast!"}
]
[[0,0.0,0.0],1]
dump
table_create Memos TABLE_NO_KEY
column_create Memos content COLUMN_SCALAR ShortText
table_create Terms TABLE_PAT_KEY ShortText --default_tokenizer TokenBigram --normalizer NormalizerAuto
column_create Terms memos_content_index COLUMN_INDEX|WITH_POSITION Memos content
load --table Memos
[
["content"],
["Groonga is fast!"]
]
14 changes: 14 additions & 0 deletions test/command/suite/dump/record/lexicon.test
@@ -0,0 +1,14 @@
table_create Memos TABLE_NO_KEY
column_create Memos content COLUMN_SCALAR ShortText

table_create Terms TABLE_PAT_KEY ShortText \
--default_tokenizer TokenBigram \
--normalizer NormalizerAuto
column_create Terms memos_content_index COLUMN_INDEX|WITH_POSITION Memos content

load --table Memos
[
{"content": "Groonga is fast!"}
]

dump

0 comments on commit 073feb7

Please sign in to comment.