[Groonga-commit] groonga/groonga at bc26961 [master] load: accept empty arrays because a dumped load may contain empty arrays

Back to archive index

Susumu Yata null+****@clear*****
Fri Mar 4 17:23:45 JST 2016


Susumu Yata	2016-03-04 17:23:45 +0900 (Fri, 04 Mar 2016)

  New Revision: bc2696163406a08134a9c1a317f4c7089156b0a1
  https://github.com/groonga/groonga/commit/bc2696163406a08134a9c1a317f4c7089156b0a1

  Message:
    load: accept empty arrays because a dumped load may contain empty arrays
    
    GitHub: #497

  Modified files:
    lib/db.c

  Modified: lib/db.c (+27 -20)
===================================================================
--- lib/db.c    2016-03-04 17:12:47 +0900 (9c72905)
+++ lib/db.c    2016-03-04 17:23:45 +0900 (744ab2c)
@@ -12715,7 +12715,6 @@ bracket_close(grn_ctx *ctx, grn_loader *loader)
   uint32_t i, begin;
   uint32_t ncols;   /* Number of columns except _id and _key. */
   uint32_t nvalues; /* Number of values in brackets. */
-  uint32_t expected_nvalues;
   uint32_t depth;
 
   cols = (grn_obj **)GRN_BULK_HEAD(&loader->columns);
@@ -12826,27 +12825,35 @@ bracket_close(grn_ctx *ctx, grn_loader *loader)
   }
 
   /* Target columns and _id or _key are already specified. */
-  expected_nvalues = ncols;
-  if (loader->id_offset != -1 || loader->key_offset != -1) {
-    expected_nvalues++;
-  }
-  if (nvalues != expected_nvalues) {
-    ERR(GRN_INVALID_ARGUMENT,
-        "unexpected #values: expected:%u, actual:%u",
-        expected_nvalues, nvalues);
-    goto exit;
-  }
-  if (loader->id_offset != -1) {
-    id_value = value + loader->id_offset;
-    id = parse_id_value(ctx, id_value);
-    if (grn_table_at(ctx, loader->table, id) == GRN_ID_NIL) {
+  if (!nvalues) {
+    /*
+     * Accept empty arrays because a dump command may output a load command
+     * which contains empty arrays for a table with deleted records.
+     */
+    id = grn_table_add(ctx, loader->table, NULL, 0, NULL);
+  } else {
+    uint32_t expected_nvalues = ncols;
+    if (loader->id_offset != -1 || loader->key_offset != -1) {
+      expected_nvalues++;
+    }
+    if (nvalues != expected_nvalues) {
+      ERR(GRN_INVALID_ARGUMENT,
+          "unexpected #values: expected:%u, actual:%u",
+          expected_nvalues, nvalues);
+      goto exit;
+    }
+    if (loader->id_offset != -1) {
+      id_value = value + loader->id_offset;
+      id = parse_id_value(ctx, id_value);
+      if (grn_table_at(ctx, loader->table, id) == GRN_ID_NIL) {
+        id = grn_table_add(ctx, loader->table, NULL, 0, NULL);
+      }
+    } else if (loader->key_offset != -1) {
+      key_value = value + loader->key_offset;
+      id = loader_add(ctx, key_value);
+    } else {
       id = grn_table_add(ctx, loader->table, NULL, 0, NULL);
     }
-  } else if (loader->key_offset != -1) {
-    key_value = value + loader->key_offset;
-    id = loader_add(ctx, key_value);
-  } else {
-    id = grn_table_add(ctx, loader->table, NULL, 0, NULL);
   }
   if (id == GRN_ID_NIL) {
     /* Target record is not available. */
-------------- next part --------------
HTML����������������������������...
Descargar 



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