[Groonga-commit] groonga/groonga [master] Added each parameter to load command.

Back to archive index

null+****@clear***** null+****@clear*****
2010年 8月 23日 (月) 20:56:59 JST


Daijiro MORI	2010-08-23 11:56:59 +0000 (Mon, 23 Aug 2010)

  New Revision: fe5e5a21065a11107fc8b84b265d5a3ca84d090f

  Log:
    Added each parameter to load command.

  Modified files:
    groonga.h
    lib/ctx.c
    lib/db.c
    lib/proc.c
    lib/ql.h

  Modified: groonga.h (+2 -1)
===================================================================
--- groonga.h    2010-08-23 08:01:16 +0000 (e957cfd)
+++ groonga.h    2010-08-23 11:56:59 +0000 (6373c5b)
@@ -2147,7 +2147,8 @@ GRN_API grn_rc grn_load(grn_ctx *ctx, grn_content_type input_type,
                         const char *table, unsigned table_len,
                         const char *columns, unsigned columns_len,
                         const char *values, unsigned values_len,
-                        const char *ifexists, unsigned ifexists_len);
+                        const char *ifexists, unsigned ifexists_len,
+                        const char *each, unsigned each_len);
 
 #define GRN_CTX_MORE                    (0x01<<0)
 #define GRN_CTX_TAIL                    (0x01<<1)

  Modified: lib/ctx.c (+2 -0)
===================================================================
--- lib/ctx.c    2010-08-23 08:01:16 +0000 (3c44081)
+++ lib/ctx.c    2010-08-23 11:56:59 +0000 (e7a4ad4)
@@ -204,6 +204,7 @@ grn_loader_init(grn_loader *loader)
   loader->table = NULL;
   loader->last = NULL;
   loader->ifexists = NULL;
+  loader->each = NULL;
   loader->values_size = 0;
   loader->nrecords = 0;
   loader->stat = GRN_LOADER_BEGIN;
@@ -219,6 +220,7 @@ grn_ctx_loader_clear(grn_ctx *ctx)
   uint32_t i = GRN_BULK_VSIZE(&loader->columns) / sizeof(grn_obj *);
   if (ctx->impl->db) { while (i--) { grn_obj_unlink(ctx, *p++); } }
   if (loader->ifexists) { grn_obj_unlink(ctx, loader->ifexists); }
+  if (loader->each) { grn_obj_unlink(ctx, loader->each); }
   while (v < ve) { GRN_OBJ_FIN(ctx, v++); }
   GRN_OBJ_FIN(ctx, &loader->values);
   GRN_OBJ_FIN(ctx, &loader->level);

  Modified: lib/db.c (+16 -1)
===================================================================
--- lib/db.c    2010-08-23 08:01:16 +0000 (0e12196)
+++ lib/db.c    2010-08-23 11:56:59 +0000 (9b67bb6)
@@ -7575,6 +7575,11 @@ brace_close(grn_ctx *ctx, grn_loader *loader)
           }
           value = values_next(ctx, value);
         }
+        if (loader->each) {
+          grn_obj *v = grn_expr_get_var_by_offset(ctx, loader->each, 0);
+          GRN_RECORD_SET(ctx, v, id);
+          grn_expr_exec(ctx, loader->each, 0);
+        }
         loader->nrecords++;
       } else {
         GRN_LOG(ctx, GRN_LOG_ERROR, "neither _key nor _id is assigned");
@@ -7886,7 +7891,8 @@ grn_load(grn_ctx *ctx, grn_content_type input_type,
          const char *table, unsigned table_len,
          const char *columns, unsigned columns_len,
          const char *values, unsigned values_len,
-         const char *ifexists, unsigned ifexists_len)
+         const char *ifexists, unsigned ifexists_len,
+         const char *each, unsigned each_len)
 {
   grn_loader *loader;
   if (!ctx || !ctx->impl) {
@@ -7934,6 +7940,15 @@ grn_load(grn_ctx *ctx, grn_content_type input_type,
                        GRN_EXPR_SYNTAX_SCRIPT|GRN_EXPR_ALLOW_UPDATE);
       }
     }
+    if (each && each_len) {
+      grn_obj *v;
+      GRN_EXPR_CREATE_FOR_QUERY(ctx, loader->table, loader->each, v);
+      if (loader->each && v) {
+        grn_expr_parse(ctx, loader->each, each, each_len,
+                       NULL, GRN_OP_EQUAL, GRN_OP_AND,
+                       GRN_EXPR_SYNTAX_SCRIPT|GRN_EXPR_ALLOW_UPDATE);
+      }
+    }
     loader->input_type = input_type;
   } else {
     input_type = loader->input_type;

  Modified: lib/proc.c (+4 -2)
===================================================================
--- lib/proc.c    2010-08-23 08:01:16 +0000 (6f09985)
+++ lib/proc.c    2010-08-23 11:56:59 +0000 (cd0c718)
@@ -363,7 +363,8 @@ proc_load(grn_ctx *ctx, int nargs, grn_obj **args, grn_user_data *user_data)
            GRN_TEXT_VALUE(VAR(1)), GRN_TEXT_LEN(VAR(1)),
            GRN_TEXT_VALUE(VAR(2)), GRN_TEXT_LEN(VAR(2)),
            GRN_TEXT_VALUE(VAR(0)), GRN_TEXT_LEN(VAR(0)),
-           GRN_TEXT_VALUE(VAR(3)), GRN_TEXT_LEN(VAR(3)));
+           GRN_TEXT_VALUE(VAR(3)), GRN_TEXT_LEN(VAR(3)),
+           GRN_TEXT_VALUE(VAR(5)), GRN_TEXT_LEN(VAR(5)));
   if (ctx->impl->loader.stat != GRN_LOADER_END) {
     grn_ctx_set_next_expr(ctx, grn_proc_get_info(ctx, user_data, NULL, NULL, NULL));
   } else {
@@ -2203,7 +2204,8 @@ grn_db_init_builtin_query(grn_ctx *ctx)
   DEF_VAR(vars[2], "columns");
   DEF_VAR(vars[3], "ifexists");
   DEF_VAR(vars[4], "input_type");
-  DEF_COMMAND("load", proc_load, 5, vars);
+  DEF_VAR(vars[5], "each");
+  DEF_COMMAND("load", proc_load, 6, vars);
 
   DEF_COMMAND("status", proc_status, 0, vars);
 

  Modified: lib/ql.h (+1 -0)
===================================================================
--- lib/ql.h    2010-08-23 08:01:16 +0000 (e2ae916)
+++ lib/ql.h    2010-08-23 11:56:59 +0000 (a385f1c)
@@ -151,6 +151,7 @@ typedef struct {
   grn_obj *table;
   grn_obj *last;
   grn_obj *ifexists;
+  grn_obj *each;
   uint32_t unichar;
   uint32_t values_size;
   uint32_t nrecords;




Groonga-commit メーリングリストの案内
Back to archive index