[Groonga-commit] groonga/groonga at 073feb7 [master] dump: don't dump records of lexicon

Back to archive index

Kouhei Sutou null+****@clear*****
Fri Apr 3 15:10:34 JST 2015


Kouhei Sutou	2015-04-03 15:10:34 +0900 (Fri, 03 Apr 2015)

  New Revision: 073feb77d65e84fc7e6ab1bd1112a291cb2c3f67
  https://github.com/groonga/groonga/commit/073feb77d65e84fc7e6ab1bd1112a291cb2c3f67

  Message:
    dump: don't dump records of lexicon

  Added files:
    test/command/suite/dump/record/lexicon.expected
    test/command/suite/dump/record/lexicon.test
  Modified files:
    lib/proc.c

  Modified: lib/proc.c (+17 -7)
===================================================================
--- lib/proc.c    2015-04-03 15:01:44 +0900 (28a3169)
+++ lib/proc.c    2015-04-03 15:10:34 +0900 (3fd4b07)
@@ -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:
@@ -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);
@@ -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 &&
@@ -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++) {
@@ -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;
@@ -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]);
   }

  Added: test/command/suite/dump/record/lexicon.expected (+23 -0) 100644
===================================================================
--- /dev/null
+++ test/command/suite/dump/record/lexicon.expected    2015-04-03 15:10:34 +0900 (470a508)
@@ -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!"]
+]

  Added: test/command/suite/dump/record/lexicon.test (+14 -0) 100644
===================================================================
--- /dev/null
+++ test/command/suite/dump/record/lexicon.test    2015-04-03 15:10:34 +0900 (6d41058)
@@ -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
-------------- next part --------------
HTML����������������������������...
Download 



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