[Groonga-commit] groonga/groonga at 48c4642 [master] load: strictly manage the status of columns

Back to archive index

Susumu Yata null+****@clear*****
Fri Mar 4 13:31:26 JST 2016


Susumu Yata	2016-03-04 13:31:26 +0900 (Fri, 04 Mar 2016)

  New Revision: 48c4642bee6fcf82e1990d80e1d94d8d140d6f6a
  https://github.com/groonga/groonga/commit/48c4642bee6fcf82e1990d80e1d94d8d140d6f6a

  Message:
    load: strictly manage the status of columns
    
    Only the first array in --values is handled as a list of column names if
    --columns is not specified.
    
    GitHub: #497

  Modified files:
    lib/ctx.c
    lib/db.c
    lib/grn_ctx_impl.h

  Modified: lib/ctx.c (+1 -0)
===================================================================
--- lib/ctx.c    2016-03-04 12:24:34 +0900 (8ffcba9)
+++ lib/ctx.c    2016-03-04 13:31:26 +0900 (6cfe141)
@@ -515,6 +515,7 @@ grn_loader_init(grn_loader *loader)
   loader->values_size = 0;
   loader->nrecords = 0;
   loader->stat = GRN_LOADER_BEGIN;
+  loader->columns_status = GRN_LOADER_COLUMNS_UNSET;
   loader->rc = GRN_SUCCESS;
   loader->errbuf[0] = '\0';
 }

  Modified: lib/db.c (+18 -8)
===================================================================
--- lib/db.c    2016-03-04 12:24:34 +0900 (3259e3a)
+++ lib/db.c    2016-03-04 13:31:26 +0900 (e3603e6)
@@ -12698,7 +12698,8 @@ bracket_close(grn_ctx *ctx, grn_loader *loader)
     return;
   }
   nvalues = values_len(ctx, value, value_end);
-  if (depth == 0 || !loader->table || loader->rc != GRN_SUCCESS) {
+  if (depth == 0 || !loader->table ||
+      loader->columns_status == GRN_LOADER_COLUMNS_BROKEN) {
     goto exit;
   }
 
@@ -12706,7 +12707,7 @@ bracket_close(grn_ctx *ctx, grn_loader *loader)
   case GRN_TABLE_HASH_KEY :
   case GRN_TABLE_PAT_KEY :
   case GRN_TABLE_DAT_KEY :
-    if (loader->key_offset != -1) {
+    if (loader->columns_status == GRN_LOADER_COLUMNS_SET) {
       /* Target columns and _id or _key are already specified. */
       if (nvalues == ncols + 1) {
         /* The number of values is OK. */
@@ -12739,6 +12740,7 @@ bracket_close(grn_ctx *ctx, grn_loader *loader)
                 loader->key_offset,
                 column_name_size, column_name, i);
             grn_loader_save_error(ctx, loader);
+            loader->columns_status = GRN_LOADER_COLUMNS_BROKEN;
             goto exit;
           }
           key_column_name = value;
@@ -12751,6 +12753,7 @@ bracket_close(grn_ctx *ctx, grn_loader *loader)
                 "nonexistent column: <%.*s>",
                 column_name_size, column_name);
             grn_loader_save_error(ctx, loader);
+            loader->columns_status = GRN_LOADER_COLUMNS_BROKEN;
             goto exit;
           }
           GRN_PTR_PUT(ctx, &loader->columns, col);
@@ -12760,18 +12763,21 @@ bracket_close(grn_ctx *ctx, grn_loader *loader)
       if (loader->key_offset == -1) {
         ERR(GRN_INVALID_ARGUMENT, "missing key column");
         grn_loader_save_error(ctx, loader);
+        loader->columns_status = GRN_LOADER_COLUMNS_BROKEN;
         goto exit;
       }
       nvalues = 0;
+      loader->columns_status = GRN_LOADER_COLUMNS_SET;
     }
     break;
   case GRN_TABLE_NO_KEY :
-    if (nvalues == 0 || nvalues == ncols) {
-      /*
-       * Target columns are already specified and the number of values is OK.
-       */
-      id = grn_table_add(ctx, loader->table, NULL, 0, NULL);
-    } else if (!ncols) {
+    if (loader->columns_status == GRN_LOADER_COLUMNS_SET) {
+      /* Target columns are already specified. */
+/*    if (nvalues == 0 || nvalues == ncols) {*/
+      if (nvalues == ncols) {
+        id = grn_table_add(ctx, loader->table, NULL, 0, NULL);
+      }
+    } else {
       /*
        * Target columns are not specified yet and values are handled as column
        * names.
@@ -12787,6 +12793,7 @@ bracket_close(grn_ctx *ctx, grn_loader *loader)
                 "nonexistent column: <%.*s>",
                 column_name_size, column_name);
             grn_loader_save_error(ctx, loader);
+            loader->columns_status = GRN_LOADER_COLUMNS_BROKEN;
             goto exit;
           }
           GRN_PTR_PUT(ctx, &loader->columns, col);
@@ -12800,10 +12807,12 @@ bracket_close(grn_ctx *ctx, grn_loader *loader)
               (int)GRN_TEXT_LEN(&buffer), GRN_TEXT_VALUE(&buffer));
           grn_loader_save_error(ctx, loader);
           GRN_OBJ_FIN(ctx, &buffer);
+          loader->columns_status = GRN_LOADER_COLUMNS_BROKEN;
           goto exit;
         }
       }
       nvalues = 0;
+      loader->columns_status = GRN_LOADER_COLUMNS_SET;
     }
     break;
   default :
@@ -13426,6 +13435,7 @@ grn_load_(grn_ctx *ctx, grn_content_type input_type,
         }
       }
       GRN_OBJ_FIN(ctx, &parsed_columns);
+      loader->columns_status = GRN_LOADER_COLUMNS_SET;
     }
     if (ifexists && ifexists_len) {
       grn_obj *v;

  Modified: lib/grn_ctx_impl.h (+12 -0)
===================================================================
--- lib/grn_ctx_impl.h    2016-03-04 12:24:34 +0900 (0258b96)
+++ lib/grn_ctx_impl.h    2016-03-04 13:31:26 +0900 (cb3421f)
@@ -59,6 +59,17 @@ typedef enum {
   GRN_LOADER_END
 } grn_loader_stat;
 
+/*
+ * Status of target columns used in Format 1.
+ * Target columns are specified via --columns or the first array in a Format 1
+ * JSON object.
+ */
+typedef enum {
+  GRN_LOADER_COLUMNS_UNSET = 0, /* Columns are not available. */
+  GRN_LOADER_COLUMNS_SET,       /* Columns are available. */
+  GRN_LOADER_COLUMNS_BROKEN     /* Columns are specified but broken. */
+} grn_loader_columns_status;
+
 typedef struct {
   grn_obj values;
   grn_obj level;
@@ -74,6 +85,7 @@ typedef struct {
   uint32_t nrecords;
   grn_loader_stat stat;
   grn_content_type input_type;
+  grn_loader_columns_status columns_status;
   grn_rc rc;
   char errbuf[GRN_CTX_MSGSIZE];
 } grn_loader;
-------------- next part --------------
HTML����������������������������...
Télécharger 



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