Navigation Menu

Skip to content

Commit

Permalink
dump: add --dump_records option
Browse files Browse the repository at this point in the history
You can disable dumping records by "--dump_records no".
  • Loading branch information
kou committed Apr 4, 2015
1 parent eeca84d commit b2aeffb
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 8 deletions.
22 changes: 14 additions & 8 deletions lib/proc.c
Expand Up @@ -3437,27 +3437,32 @@ proc_dump(grn_ctx *ctx, int nargs, grn_obj **args, grn_user_data *user_data)
grn_obj *tables = VAR(0);
grn_obj *dump_plugins_raw = VAR(1);
grn_obj *dump_schema_raw = VAR(2);
grn_obj *dump_records_raw = VAR(3);
grn_bool is_dump_plugins;
grn_bool is_dump_schema;
grn_bool is_dump_records;

grn_ctx_set_output_type(ctx, GRN_CONTENT_GROONGA_COMMAND_LIST);

is_dump_plugins = bool_option_value(dump_plugins_raw, GRN_TRUE);
is_dump_schema = bool_option_value(dump_schema_raw, GRN_TRUE);
is_dump_records = bool_option_value(dump_records_raw, GRN_TRUE);

if (is_dump_plugins) {
dump_plugins(ctx, outbuf);
}
if (is_dump_schema) {
dump_schema(ctx, outbuf);
}
/* To update index columns correctly, we first create the whole schema, then
load non-derivative records, while skipping records of index columns. That
way, groonga will silently do the job of updating index columns for us. */
if (GRN_TEXT_LEN(tables) > 0) {
dump_selected_tables_records(ctx, outbuf, tables);
} else {
dump_all_records(ctx, outbuf);
if (is_dump_records) {
/* To update index columns correctly, we first create the whole schema, then
load non-derivative records, while skipping records of index columns. That
way, groonga will silently do the job of updating index columns for us. */
if (GRN_TEXT_LEN(tables) > 0) {
dump_selected_tables_records(ctx, outbuf, tables);
} else {
dump_all_records(ctx, outbuf);
}
}

dump_indexes(ctx, outbuf);
Expand Down Expand Up @@ -6812,7 +6817,8 @@ grn_db_init_builtin_query(grn_ctx *ctx)
DEF_VAR(vars[0], "tables");
DEF_VAR(vars[1], "dump_plugins");
DEF_VAR(vars[2], "dump_schema");
DEF_COMMAND("dump", proc_dump, 3, vars);
DEF_VAR(vars[3], "dump_records");
DEF_COMMAND("dump", proc_dump, 4, vars);

/* Deprecated. Use "plugin_register" instead. */
DEF_VAR(vars[0], "path");
Expand Down
24 changes: 24 additions & 0 deletions test/command/suite/dump/record/dump_records_no.expected
@@ -0,0 +1,24 @@
plugin_register token_filters/stop_word
[[0,0.0,0.0],true]
table_create Users TABLE_HASH_KEY ShortText
[[0,0.0,0.0],true]
column_create Users name 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 users_name_index COLUMN_INDEX|WITH_POSITION Users name
[[0,0.0,0.0],true]
load --table Users
[
{"_key": "alice", "name": "Alice"}
]
[[0,0.0,0.0],1]
dump --dump_records no
plugin_register token_filters/stop_word

table_create Users TABLE_HASH_KEY ShortText
column_create Users name COLUMN_SCALAR ShortText

table_create Terms TABLE_PAT_KEY ShortText --default_tokenizer TokenBigram --normalizer NormalizerAuto

column_create Terms users_name_index COLUMN_INDEX|WITH_POSITION Users name
16 changes: 16 additions & 0 deletions test/command/suite/dump/record/dump_records_no.test
@@ -0,0 +1,16 @@
plugin_register token_filters/stop_word

table_create Users TABLE_HASH_KEY ShortText
column_create Users name COLUMN_SCALAR ShortText

table_create Terms TABLE_PAT_KEY ShortText \
--default_tokenizer TokenBigram \
--normalizer NormalizerAuto
column_create Terms users_name_index COLUMN_INDEX|WITH_POSITION Users name

load --table Users
[
{"_key": "alice", "name": "Alice"}
]

dump --dump_records no

0 comments on commit b2aeffb

Please sign in to comment.