[Groonga-commit] groonga/groonga at 41b1f1f [master] dump: add --dump_schema option

Back to archive index

Kouhei Sutou null+****@clear*****
Sat Apr 4 22:22:04 JST 2015


Kouhei Sutou	2015-04-04 22:22:04 +0900 (Sat, 04 Apr 2015)

  New Revision: 41b1f1f5f13ca2d9fa31baa0ef5d106196d56c11
  https://github.com/groonga/groonga/commit/41b1f1f5f13ca2d9fa31baa0ef5d106196d56c11

  Message:
    dump: add --dump_schema option
    
    You can disable dumping schema by "--dump_schema no".

  Added files:
    test/command/suite/dump/schema/dump_schema_no.test
  Copied files:
    test/command/suite/dump/schema/dump_schema_no.expected
      (from test/command/suite/dump/schema/column/index/with_reference_column.expected)
  Modified files:
    lib/proc.c
    test/command/suite/dump/schema/column/index/with_reference_column.expected
    test/command/suite/dump/schema/column/reference/each_other.expected
    test/command/suite/dump/schema/column/vector/with_weight.expected
    test/command/suite/dump/schema/plugin/multiple.expected
    test/command/suite/dump/schema/plugin/native.expected
    test/command/suite/dump/schema/plugin/ruby.expected
    test/command/suite/dump/schema/table/double_array_trie/reference_key.expected
    test/command/suite/dump/schema/table/double_array_trie/type_key.expected
    test/command/suite/dump/schema/table/hash/reference_key.expected
    test/command/suite/dump/schema/table/hash/type_key.expected
    test/command/suite/dump/schema/table/no_key/minimum.expected
    test/command/suite/dump/schema/table/patricia_trie/reference_key.expected
    test/command/suite/dump/schema/table/patricia_trie/type_key.expected

  Modified: lib/proc.c (+61 -21)
===================================================================
--- lib/proc.c    2015-04-04 21:56:00 +0900 (2c50c33)
+++ lib/proc.c    2015-04-04 22:22:04 +0900 (564bf3f)
@@ -2874,8 +2874,7 @@ reference_column_p(grn_ctx *ctx, grn_obj *column)
 
 static void
 dump_columns(grn_ctx *ctx, grn_obj *outbuf, grn_obj *table,
-             grn_obj *pending_reference_columns,
-             grn_obj *pending_index_columns)
+             grn_obj *pending_reference_columns)
 {
   grn_hash *columns;
   columns = grn_hash_create(ctx, NULL, sizeof(grn_id), 0,
@@ -2892,7 +2891,7 @@ dump_columns(grn_ctx *ctx, grn_obj *outbuf, grn_obj *table,
       grn_obj *column;
       if ((column = grn_ctx_at(ctx, *key))) {
         if (GRN_OBJ_INDEX_COLUMNP(column)) {
-          GRN_PTR_PUT(ctx, pending_index_columns, column);
+          /* do nothing */
         } else if (reference_column_p(ctx, column)) {
           GRN_PTR_PUT(ctx, pending_reference_columns, column);
         } else {
@@ -3123,8 +3122,7 @@ exit :
 
 static void
 dump_table(grn_ctx *ctx, grn_obj *outbuf, grn_obj *table,
-           grn_obj *pending_reference_columns,
-           grn_obj *pending_index_columns)
+           grn_obj *pending_reference_columns)
 {
   grn_obj *domain = NULL, *range = NULL;
   grn_obj_flags default_flags = GRN_OBJ_PERSISTENT;
@@ -3209,9 +3207,7 @@ dump_table(grn_ctx *ctx, grn_obj *outbuf, grn_obj *table,
     grn_obj_unlink(ctx, domain);
   }
 
-  dump_columns(ctx, outbuf, table,
-               pending_reference_columns,
-               pending_index_columns);
+  dump_columns(ctx, outbuf, table, pending_reference_columns);
 }
 
 static void
@@ -3240,7 +3236,7 @@ dump_pending_columns(grn_ctx *ctx, grn_obj *outbuf, grn_obj *pending_columns)
 }
 
 static void
-dump_schema(grn_ctx *ctx, grn_obj *outbuf, grn_obj *pending_index_columns)
+dump_schema(grn_ctx *ctx, grn_obj *outbuf)
 {
   grn_obj *db = ctx->impl->db;
   grn_table_cursor *cur;
@@ -3263,9 +3259,7 @@ dump_schema(grn_ctx *ctx, grn_obj *outbuf, grn_obj *pending_index_columns)
       case GRN_TABLE_PAT_KEY:
       case GRN_TABLE_DAT_KEY:
       case GRN_TABLE_NO_KEY:
-        dump_table(ctx, outbuf, object,
-                   &pending_reference_columns,
-                   pending_index_columns);
+        dump_table(ctx, outbuf, object, &pending_reference_columns);
         break;
       default:
         break;
@@ -3367,6 +3361,51 @@ dump_all_records(grn_ctx *ctx, grn_obj *outbuf)
   }
 }
 
+static void
+dump_indexes(grn_ctx *ctx, grn_obj *outbuf)
+{
+  grn_obj *db = ctx->impl->db;
+  grn_table_cursor *cursor;
+  grn_id id;
+  grn_bool is_first_index_column = GRN_TRUE;
+
+  cursor = grn_table_cursor_open(ctx, db, NULL, 0, NULL, 0, 0, -1,
+                              GRN_CURSOR_BY_ID);
+  if (!cursor) {
+    return;
+  }
+
+  while ((id = grn_table_cursor_next(ctx, cursor)) != GRN_ID_NIL) {
+    grn_obj *object;
+
+    object = grn_ctx_at(ctx, id);
+    if (!object) {
+      /* XXX: this clause is executed when MeCab tokenizer is enabled in
+         database but the groonga isn't supported MeCab.
+         We should return error mesage about it and error exit status
+         but it's too difficult for this architecture. :< */
+      ERRCLR(ctx);
+      continue;
+    }
+
+    if (object->header.type == GRN_COLUMN_INDEX) {
+      grn_obj *table;
+      grn_obj *column = object;
+
+      if (is_first_index_column && GRN_TEXT_LEN(outbuf) > 0) {
+        GRN_TEXT_PUTC(ctx, outbuf, '\n');
+      }
+      is_first_index_column = GRN_FALSE;
+
+      table = grn_ctx_at(ctx, column->header.domain);
+      dump_column(ctx, outbuf, table, column);
+      grn_obj_unlink(ctx, table);
+    }
+    grn_obj_unlink(ctx, object);
+  }
+  grn_table_cursor_close(ctx, cursor);
+}
+
 static grn_bool
 bool_option_value(grn_obj *option, grn_bool default_value)
 {
@@ -3397,20 +3436,21 @@ proc_dump(grn_ctx *ctx, int nargs, grn_obj **args, grn_user_data *user_data)
   grn_obj *outbuf = ctx->impl->outbuf;
   grn_obj *tables = VAR(0);
   grn_obj *dump_plugins_raw = VAR(1);
+  grn_obj *dump_schema_raw = VAR(2);
   grn_bool is_dump_plugins;
-  grn_obj pending_index_columns;
-
-  GRN_PTR_INIT(&pending_index_columns, GRN_OBJ_VECTOR, GRN_ID_NIL);
+  grn_bool is_dump_schema;
 
   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);
+
   if (is_dump_plugins) {
     dump_plugins(ctx, outbuf);
-    grn_ctx_output_flush(ctx, 0);
   }
-  dump_schema(ctx, outbuf, &pending_index_columns);
-  grn_ctx_output_flush(ctx, 0);
+  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. */
@@ -3420,8 +3460,7 @@ proc_dump(grn_ctx *ctx, int nargs, grn_obj **args, grn_user_data *user_data)
     dump_all_records(ctx, outbuf);
   }
 
-  dump_pending_columns(ctx, outbuf, &pending_index_columns);
-  grn_obj_close(ctx, &pending_index_columns);
+  dump_indexes(ctx, outbuf);
 
   /* remove the last newline because another one will be added by the caller.
      maybe, the caller of proc functions currently doesn't consider the
@@ -6772,7 +6811,8 @@ grn_db_init_builtin_query(grn_ctx *ctx)
 
   DEF_VAR(vars[0], "tables");
   DEF_VAR(vars[1], "dump_plugins");
-  DEF_COMMAND("dump", proc_dump, 2, vars);
+  DEF_VAR(vars[2], "dump_schema");
+  DEF_COMMAND("dump", proc_dump, 3, vars);
 
   /* Deprecated. Use "plugin_register" instead. */
   DEF_VAR(vars[0], "path");

  Modified: test/command/suite/dump/schema/column/index/with_reference_column.expected (+1 -0)
===================================================================
--- test/command/suite/dump/schema/column/index/with_reference_column.expected    2015-04-04 21:56:00 +0900 (489c3fe)
+++ test/command/suite/dump/schema/column/index/with_reference_column.expected    2015-04-04 22:22:04 +0900 (a92f51d)
@@ -22,4 +22,5 @@ column_create Users name COLUMN_SCALAR ShortText
 table_create Terms TABLE_PAT_KEY ShortText --default_tokenizer TokenBigram --normalizer NormalizerAuto
 
 column_create Users bookmark COLUMN_SCALAR Bookmarks
+
 column_create Terms users_name_index COLUMN_INDEX|WITH_POSITION Users name

  Modified: test/command/suite/dump/schema/column/reference/each_other.expected (+0 -1)
===================================================================
--- test/command/suite/dump/schema/column/reference/each_other.expected    2015-04-04 21:56:00 +0900 (c3afc52)
+++ test/command/suite/dump/schema/column/reference/each_other.expected    2015-04-04 22:22:04 +0900 (654bae5)
@@ -19,4 +19,3 @@ column_create Users name COLUMN_SCALAR ShortText
 
 column_create Bookmarks user COLUMN_SCALAR Users
 column_create Users bookmark COLUMN_SCALAR Bookmarks
-

  Modified: test/command/suite/dump/schema/column/vector/with_weight.expected (+0 -1)
===================================================================
--- test/command/suite/dump/schema/column/vector/with_weight.expected    2015-04-04 21:56:00 +0900 (1cb2f06)
+++ test/command/suite/dump/schema/column/vector/with_weight.expected    2015-04-04 22:22:04 +0900 (23149d7)
@@ -5,4 +5,3 @@ column_create Bookmarks tags COLUMN_VECTOR|WITH_WEIGHT ShortText
 dump
 table_create Bookmarks TABLE_HASH_KEY ShortText
 column_create Bookmarks tags COLUMN_VECTOR|WITH_WEIGHT ShortText
-

  Copied: test/command/suite/dump/schema/dump_schema_no.expected (+6 -9) 64%
===================================================================
--- test/command/suite/dump/schema/column/index/with_reference_column.expected    2015-04-04 21:56:00 +0900 (489c3fe)
+++ test/command/suite/dump/schema/dump_schema_no.expected    2015-04-04 22:22:04 +0900 (3272ede)
@@ -1,3 +1,5 @@
+plugin_register token_filters/stop_word
+[[0,0.0,0.0],true]
 table_create Bookmarks TABLE_HASH_KEY ShortText
 [[0,0.0,0.0],true]
 column_create Bookmarks title COLUMN_SCALAR ShortText
@@ -8,18 +10,13 @@ column_create Users name COLUMN_SCALAR ShortText
 [[0,0.0,0.0],true]
 column_create Users bookmark COLUMN_SCALAR Bookmarks
 [[0,0.0,0.0],true]
+column_create Bookmarks user COLUMN_SCALAR Users
+[[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]
-dump
-table_create Bookmarks TABLE_HASH_KEY ShortText
-column_create Bookmarks title COLUMN_SCALAR ShortText
+dump --dump_schema 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 Users bookmark COLUMN_SCALAR Bookmarks
 column_create Terms users_name_index COLUMN_INDEX|WITH_POSITION Users name

  Added: test/command/suite/dump/schema/dump_schema_no.test (+17 -0) 100644
===================================================================
--- /dev/null
+++ test/command/suite/dump/schema/dump_schema_no.test    2015-04-04 22:22:04 +0900 (4e2f44f)
@@ -0,0 +1,17 @@
+plugin_register token_filters/stop_word
+
+table_create Bookmarks TABLE_HASH_KEY ShortText
+column_create Bookmarks title COLUMN_SCALAR ShortText
+
+table_create Users TABLE_HASH_KEY ShortText
+column_create Users name COLUMN_SCALAR ShortText
+
+column_create Users bookmark COLUMN_SCALAR Bookmarks
+column_create Bookmarks user COLUMN_SCALAR Users
+
+table_create Terms TABLE_PAT_KEY ShortText \
+  --default_tokenizer TokenBigram \
+  --normalizer NormalizerAuto
+column_create Terms users_name_index COLUMN_INDEX|WITH_POSITION Users name
+
+dump --dump_schema no

  Modified: test/command/suite/dump/schema/plugin/multiple.expected (+0 -1)
===================================================================
--- test/command/suite/dump/schema/plugin/multiple.expected    2015-04-04 21:56:00 +0900 (9bb11f0)
+++ test/command/suite/dump/schema/plugin/multiple.expected    2015-04-04 22:22:04 +0900 (d493448)
@@ -5,4 +5,3 @@ plugin_register query_expanders/tsv
 dump
 plugin_register token_filters/stop_word
 plugin_register query_expanders/tsv
-

  Modified: test/command/suite/dump/schema/plugin/native.expected (+0 -1)
===================================================================
--- test/command/suite/dump/schema/plugin/native.expected    2015-04-04 21:56:00 +0900 (31cb23e)
+++ test/command/suite/dump/schema/plugin/native.expected    2015-04-04 22:22:04 +0900 (0f4e362)
@@ -2,4 +2,3 @@ plugin_register token_filters/stop_word
 [[0,0.0,0.0],true]
 dump
 plugin_register token_filters/stop_word
-

  Modified: test/command/suite/dump/schema/plugin/ruby.expected (+0 -1)
===================================================================
--- test/command/suite/dump/schema/plugin/ruby.expected    2015-04-04 21:56:00 +0900 (e3da468)
+++ test/command/suite/dump/schema/plugin/ruby.expected    2015-04-04 22:22:04 +0900 (3fb1b1f)
@@ -2,4 +2,3 @@ plugin_register sharding
 [[0,0.0,0.0],true]
 dump
 plugin_register sharding
-

  Modified: test/command/suite/dump/schema/table/double_array_trie/reference_key.expected (+0 -1)
===================================================================
--- test/command/suite/dump/schema/table/double_array_trie/reference_key.expected    2015-04-04 21:56:00 +0900 (0ab9a1d)
+++ test/command/suite/dump/schema/table/double_array_trie/reference_key.expected    2015-04-04 22:22:04 +0900 (b13b384)
@@ -6,4 +6,3 @@ dump
 table_create Names TABLE_PAT_KEY ShortText
 
 table_create Users TABLE_DAT_KEY Names
-

  Modified: test/command/suite/dump/schema/table/double_array_trie/type_key.expected (+0 -1)
===================================================================
--- test/command/suite/dump/schema/table/double_array_trie/type_key.expected    2015-04-04 21:56:00 +0900 (a460876)
+++ test/command/suite/dump/schema/table/double_array_trie/type_key.expected    2015-04-04 22:22:04 +0900 (ebbc206)
@@ -2,4 +2,3 @@ table_create Users TABLE_DAT_KEY ShortText
 [[0,0.0,0.0],true]
 dump
 table_create Users TABLE_DAT_KEY ShortText
-

  Modified: test/command/suite/dump/schema/table/hash/reference_key.expected (+0 -1)
===================================================================
--- test/command/suite/dump/schema/table/hash/reference_key.expected    2015-04-04 21:56:00 +0900 (a3a5079)
+++ test/command/suite/dump/schema/table/hash/reference_key.expected    2015-04-04 22:22:04 +0900 (c582c26)
@@ -6,4 +6,3 @@ dump
 table_create Names TABLE_PAT_KEY ShortText
 
 table_create Users TABLE_HASH_KEY Names
-

  Modified: test/command/suite/dump/schema/table/hash/type_key.expected (+0 -1)
===================================================================
--- test/command/suite/dump/schema/table/hash/type_key.expected    2015-04-04 21:56:00 +0900 (66d84b3)
+++ test/command/suite/dump/schema/table/hash/type_key.expected    2015-04-04 22:22:04 +0900 (a8e86f0)
@@ -2,4 +2,3 @@ table_create Users TABLE_HASH_KEY ShortText
 [[0,0.0,0.0],true]
 dump
 table_create Users TABLE_HASH_KEY ShortText
-

  Modified: test/command/suite/dump/schema/table/no_key/minimum.expected (+0 -1)
===================================================================
--- test/command/suite/dump/schema/table/no_key/minimum.expected    2015-04-04 21:56:00 +0900 (dd94f11)
+++ test/command/suite/dump/schema/table/no_key/minimum.expected    2015-04-04 22:22:04 +0900 (ecbf5f7)
@@ -2,4 +2,3 @@ table_create Users TABLE_NO_KEY
 [[0,0.0,0.0],true]
 dump
 table_create Users TABLE_NO_KEY
-

  Modified: test/command/suite/dump/schema/table/patricia_trie/reference_key.expected (+0 -1)
===================================================================
--- test/command/suite/dump/schema/table/patricia_trie/reference_key.expected    2015-04-04 21:56:00 +0900 (c98aeb6)
+++ test/command/suite/dump/schema/table/patricia_trie/reference_key.expected    2015-04-04 22:22:04 +0900 (6513770)
@@ -6,4 +6,3 @@ dump
 table_create Names TABLE_PAT_KEY ShortText
 
 table_create Users TABLE_PAT_KEY Names
-

  Modified: test/command/suite/dump/schema/table/patricia_trie/type_key.expected (+0 -1)
===================================================================
--- test/command/suite/dump/schema/table/patricia_trie/type_key.expected    2015-04-04 21:56:00 +0900 (ab2d6a3)
+++ test/command/suite/dump/schema/table/patricia_trie/type_key.expected    2015-04-04 22:22:04 +0900 (24bd239)
@@ -2,4 +2,3 @@ table_create Users TABLE_PAT_KEY ShortText
 [[0,0.0,0.0],true]
 dump
 table_create Users TABLE_PAT_KEY ShortText
-
-------------- next part --------------
HTML����������������������������...
Descargar 



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