[Groonga-commit] groonga/groonga at 1973935 [master] Accept selector only proc

Zurück zum Archiv-Index

Kouhei Sutou null+****@clear*****
Wed Jul 8 11:18:24 JST 2015


Kouhei Sutou	2015-07-08 11:18:24 +0900 (Wed, 08 Jul 2015)

  New Revision: 1973935994f209ef5172d0bac499c90a618c8c31
  https://github.com/groonga/groonga/commit/1973935994f209ef5172d0bac499c90a618c8c31

  Message:
    Accept selector only proc
    
    The proc can't be used as function. It means that the proc can't be used
    with sequential search.

  Added files:
    test/command/suite/select/function/sub_filter/no_index.expeced
    test/command/suite/select/function/sub_filter/no_index.test
  Modified files:
    include/groonga/obj.h
    lib/expr.c
    lib/obj.c
    lib/proc.c

  Modified: include/groonga/obj.h (+1 -0)
===================================================================
--- include/groonga/obj.h    2015-07-07 18:39:27 +0900 (7544a6c)
+++ include/groonga/obj.h    2015-07-08 11:18:24 +0900 (9ff892c)
@@ -28,6 +28,7 @@ GRN_API grn_bool grn_obj_is_table(grn_ctx *ctx, grn_obj *obj);
 GRN_API grn_bool grn_obj_is_proc(grn_ctx *ctx, grn_obj *obj);
 GRN_API grn_bool grn_obj_is_function_proc(grn_ctx *ctx, grn_obj *obj);
 GRN_API grn_bool grn_obj_is_selector_proc(grn_ctx *ctx, grn_obj *obj);
+GRN_API grn_bool grn_obj_is_selector_only_proc(grn_ctx *ctx, grn_obj *obj);
 GRN_API grn_bool grn_obj_is_scorer_proc(grn_ctx *ctx, grn_obj *obj);
 
 #ifdef __cplusplus

  Modified: lib/expr.c (+9 -0)
===================================================================
--- lib/expr.c    2015-07-07 18:39:27 +0900 (9ce1fa0)
+++ lib/expr.c    2015-07-08 11:18:24 +0900 (7630913)
@@ -1255,6 +1255,15 @@ grn_proc_call(grn_ctx *ctx, grn_obj *proc, int nargs, grn_obj *caller)
   grn_proc *p = (grn_proc *)proc;
   if (nargs > ctx->impl->stack_curr) { return GRN_INVALID_ARGUMENT; }
   GRN_API_ENTER;
+  if (grn_obj_is_selector_only_proc(ctx, proc)) {
+    char name[GRN_TABLE_MAX_KEY_SIZE];
+    int name_size;
+    name_size = grn_obj_name(ctx, proc, name, GRN_TABLE_MAX_KEY_SIZE);
+    ERR(GRN_FUNCTION_NOT_IMPLEMENTED,
+        "selector only proc can't be called: <%.*s>",
+        name_size, name);
+    GRN_API_RETURN(ctx->rc);
+  }
   args = ctx->impl->stack + ctx->impl->stack_curr - nargs;
   pctx.proc = p;
   pctx.caller = caller;

  Modified: lib/obj.c (+13 -0)
===================================================================
--- lib/obj.c    2015-07-07 18:39:27 +0900 (87850b6)
+++ lib/obj.c    2015-07-08 11:18:24 +0900 (bca1597)
@@ -93,6 +93,19 @@ grn_obj_is_selector_proc(grn_ctx *ctx, grn_obj *obj)
 }
 
 grn_bool
+grn_obj_is_selector_only_proc(grn_ctx *ctx, grn_obj *obj)
+{
+  grn_proc *proc;
+
+  if (!grn_obj_is_selector_proc(ctx, obj)) {
+    return GRN_FALSE;
+  }
+
+  proc = (grn_proc *)obj;
+  return proc->funcs[PROC_INIT] == NULL;
+}
+
+grn_bool
 grn_obj_is_scorer_proc(grn_ctx *ctx, grn_obj *obj)
 {
   grn_proc *proc;

  Modified: lib/proc.c (+1 -18)
===================================================================
--- lib/proc.c    2015-07-07 18:39:27 +0900 (86b0fd5)
+++ lib/proc.c    2015-07-08 11:18:24 +0900 (ba7c3e5)
@@ -5283,23 +5283,6 @@ exit :
   return rc;
 }
 
-static grn_obj *
-func_sub_filter(grn_ctx *ctx, int nargs, grn_obj **args, grn_user_data *user_data)
-{
-  selector_to_function_data data;
-
-  if (selector_to_function_data_init(ctx, &data, user_data)) {
-    grn_rc rc;
-    rc = run_sub_filter(ctx, data.table, nargs, args, data.records, GRN_OP_AND);
-    if (rc == GRN_SUCCESS) {
-      selector_to_function_data_selected(ctx, &data);
-    }
-  }
-  selector_to_function_data_fin(ctx, &data);
-
-  return data.found;
-}
-
 static grn_rc
 selector_sub_filter(grn_ctx *ctx, grn_obj *table, grn_obj *index,
                     int nargs, grn_obj **args,
@@ -7028,7 +7011,7 @@ grn_db_init_builtin_query(grn_ctx *ctx)
     grn_obj *selector_proc;
 
     selector_proc = grn_proc_create(ctx, "sub_filter", -1, GRN_PROC_FUNCTION,
-                                    func_sub_filter, NULL, NULL, 0, NULL);
+                                    NULL, NULL, NULL, 0, NULL);
     grn_proc_set_selector(ctx, selector_proc, selector_sub_filter);
   }
 

  Added: test/command/suite/select/function/sub_filter/no_index.expeced (+45 -0) 100644
===================================================================
--- /dev/null
+++ test/command/suite/select/function/sub_filter/no_index.expeced    2015-07-08 11:18:24 +0900 (189d1d2)
@@ -0,0 +1,45 @@
+table_create Users TABLE_PAT_KEY ShortText
+[[0,0.0,0.0],true]
+column_create Users birthday COLUMN_SCALAR Time
+[[0,0.0,0.0],true]
+table_create Files TABLE_PAT_KEY ShortText
+[[0,0.0,0.0],true]
+column_create Files author COLUMN_SCALAR Users
+[[0,0.0,0.0],true]
+table_create Packages TABLE_PAT_KEY ShortText
+[[0,0.0,0.0],true]
+column_create Packages files COLUMN_VECTOR Files
+[[0,0.0,0.0],true]
+column_create Files packages_files_index COLUMN_INDEX Packages files
+[[0,0.0,0.0],true]
+table_create Birthdays TABLE_PAT_KEY Time
+[[0,0.0,0.0],true]
+column_create Birthdays users_birthday COLUMN_INDEX Users birthday
+[[0,0.0,0.0],true]
+load --table Users
+[
+{"_key": "Alice",  "birthday": "1992-02-09 00:00:00"},
+{"_key": "Bob",    "birthday": "1988-01-04 00:00:00"},
+{"_key": "Carlos", "birthday": "1982-12-29 00:00:00"}
+]
+[[0,0.0,0.0],3]
+load --table Files
+[
+{"_key": "include/groonga.h", "author": "Alice"},
+{"_key": "src/groonga.c",     "author": "Bob"},
+{"_key": "lib/groonga.rb",    "author": "Carlos"},
+{"_key": "README.textile",    "author": "Alice"},
+{"_key": "ha_mroonga.cc",     "author": "Bob"},
+{"_key": "ha_mroonga.hpp",    "author": "Carlos"}
+]
+[[0,0.0,0.0],6]
+load --table Packages
+[
+{"_key": "groonga", "files": ["include/groonga.h", "src/groonga.c"]},
+{"_key": "rroonga", "files": ["lib/groonga.rb", "README.textile"]},
+{"_key": "mroonga", "files": ["ha_mroonga.cc", "ha_mroonga.hpp"]}
+]
+[[0,0.0,0.0],3]
+select Packages   --filter 'sub_filter(files.author, "birthday >= \\"1988-01-04 00:00:00\\" && birthday < \\"1992-02-09 00:00:00\\"")'   --output_columns '_key, files, files.author.birthday'
+[[[-38,0.0,0.0],"selector only proc can't be called: <sub_filter>"],[]]
+#|e| selector only proc can't be called: <sub_filter>

  Added: test/command/suite/select/function/sub_filter/no_index.test (+42 -0) 100644
===================================================================
--- /dev/null
+++ test/command/suite/select/function/sub_filter/no_index.test    2015-07-08 11:18:24 +0900 (4b860a7)
@@ -0,0 +1,42 @@
+table_create Users TABLE_PAT_KEY ShortText
+column_create Users birthday COLUMN_SCALAR Time
+
+table_create Files TABLE_PAT_KEY ShortText
+column_create Files author COLUMN_SCALAR Users
+
+table_create Packages TABLE_PAT_KEY ShortText
+column_create Packages files COLUMN_VECTOR Files
+
+# column_create Users files_author_index COLUMN_INDEX Files author
+column_create Files packages_files_index COLUMN_INDEX Packages files
+
+table_create Birthdays TABLE_PAT_KEY Time
+column_create Birthdays users_birthday COLUMN_INDEX Users birthday
+
+load --table Users
+[
+{"_key": "Alice",  "birthday": "1992-02-09 00:00:00"},
+{"_key": "Bob",    "birthday": "1988-01-04 00:00:00"},
+{"_key": "Carlos", "birthday": "1982-12-29 00:00:00"}
+]
+
+load --table Files
+[
+{"_key": "include/groonga.h", "author": "Alice"},
+{"_key": "src/groonga.c",     "author": "Bob"},
+{"_key": "lib/groonga.rb",    "author": "Carlos"},
+{"_key": "README.textile",    "author": "Alice"},
+{"_key": "ha_mroonga.cc",     "author": "Bob"},
+{"_key": "ha_mroonga.hpp",    "author": "Carlos"}
+]
+
+load --table Packages
+[
+{"_key": "groonga", "files": ["include/groonga.h", "src/groonga.c"]},
+{"_key": "rroonga", "files": ["lib/groonga.rb", "README.textile"]},
+{"_key": "mroonga", "files": ["ha_mroonga.cc", "ha_mroonga.hpp"]}
+]
+
+select Packages \
+  --filter 'sub_filter(files.author, "birthday >= \\"1988-01-04 00:00:00\\" && birthday < \\"1992-02-09 00:00:00\\"")' \
+  --output_columns '_key, files, files.author.birthday'
-------------- next part --------------
HTML����������������������������...
Download 



More information about the Groonga-commit mailing list
Zurück zum Archiv-Index