[Groonga-commit] groonga/groonga at 94fbf50 [master] Fix a bug for "XXX && sub_filter(...)" type filter

Back to archive index

Kouhei Sutou null+****@clear*****
Wed Jun 12 11:28:39 JST 2013


Kouhei Sutou	2013-06-12 11:28:39 +0900 (Wed, 12 Jun 2013)

  New Revision: 94fbf50c17886689eac58c8c02213588de98c0d8
  https://github.com/groonga/groonga/commit/94fbf50c17886689eac58c8c02213588de98c0d8

  Message:
    Fix a bug for "XXX && sub_filter(...)" type filter
    
    In the filter, "sub_filter(...)" is just ignored. "sub_filter(...)"
    should substitute matched records from records that are matched
    against "XXX".

  Added files:
    test/command/suite/select/function/sub_filter/and.expected
    test/command/suite/select/function/sub_filter/and.test
  Modified files:
    lib/db.c

  Modified: lib/db.c (+8 -11)
===================================================================
--- lib/db.c    2013-06-11 17:56:12 +0900 (176d9a5)
+++ lib/db.c    2013-06-12 11:28:39 +0900 (6ba2096)
@@ -2496,7 +2496,6 @@ grn_accessor_resolve(grn_ctx *ctx, grn_obj *accessor, int deep,
       grn_id *tid;
       grn_obj *domain;
       grn_obj *next_res;
-      grn_operator next_op;
       grn_search_optarg next_optarg;
       grn_rset_recinfo *recinfo;
       if (optarg) {
@@ -2505,10 +2504,7 @@ grn_accessor_resolve(grn_ctx *ctx, grn_obj *accessor, int deep,
       } else {
         memset(&next_optarg, 0, sizeof(grn_search_optarg));
       }
-      if (i == 1) {
-        next_res = res;
-        next_op = op;
-      } else {
+      {
         grn_obj *range = grn_ctx_at(ctx, DB_OBJ(index)->range);
         next_res = grn_table_create(ctx, NULL, 0, NULL,
                                     GRN_TABLE_HASH_KEY|GRN_OBJ_WITH_SUBREC,
@@ -2521,7 +2517,6 @@ grn_accessor_resolve(grn_ctx *ctx, grn_obj *accessor, int deep,
           }
           break;
         }
-        next_op = GRN_OP_OR;
       }
       domain = grn_ctx_at(ctx, index->header.domain);
       GRN_HASH_EACH(ctx, (grn_hash *)current_res, id, &tid, NULL, &recinfo, {
@@ -2530,7 +2525,7 @@ grn_accessor_resolve(grn_ctx *ctx, grn_obj *accessor, int deep,
         if (domain->header.type == GRN_TABLE_NO_KEY) {
           rc = grn_ii_sel(ctx, (grn_ii *)index,
                           (const char *)tid, sizeof(grn_id),
-                          (grn_hash *)next_res, next_op,
+                          (grn_hash *)next_res, GRN_OP_OR,
                           &next_optarg);
         } else {
           char key[GRN_TABLE_MAX_KEY_SIZE];
@@ -2538,7 +2533,7 @@ grn_accessor_resolve(grn_ctx *ctx, grn_obj *accessor, int deep,
           key_len = grn_table_get_key(ctx, domain, *tid,
                                       key, GRN_TABLE_MAX_KEY_SIZE);
           rc = grn_ii_sel(ctx, (grn_ii *)index, key, key_len,
-                          (grn_hash *)next_res, next_op,
+                          (grn_hash *)next_res, GRN_OP_OR,
                           &next_optarg);
         }
         if (rc != GRN_SUCCESS) {
@@ -2550,15 +2545,17 @@ grn_accessor_resolve(grn_ctx *ctx, grn_obj *accessor, int deep,
         grn_obj_unlink(ctx, current_res);
       }
       if (rc != GRN_SUCCESS) {
-        if (res != next_res) {
-          grn_obj_unlink(ctx, next_res);
-        }
+        grn_obj_unlink(ctx, next_res);
         break;
       }
       current_res = next_res;
     }
   }
 
+  if (rc == GRN_SUCCESS) {
+    rc = grn_table_setoperation(ctx, res, current_res, res, op);
+  }
+
   GRN_OBJ_FIN(ctx, &accessor_stack);
   return rc;
 }

  Added: test/command/suite/select/function/sub_filter/and.expected (+75 -0) 100644
===================================================================
--- /dev/null
+++ test/command/suite/select/function/sub_filter/and.expected    2013-06-12 11:28:39 +0900 (b9a8ad5)
@@ -0,0 +1,75 @@
+table_create Files TABLE_PAT_KEY ShortText
+[[0,0.0,0.0],true]
+column_create Files revision COLUMN_SCALAR UInt32
+[[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 Revisions TABLE_PAT_KEY UInt32
+[[0,0.0,0.0],true]
+column_create Revisions files_revision_index COLUMN_INDEX Files revision
+[[0,0.0,0.0],true]
+table_create Names TABLE_PAT_KEY ShortText   --default_tokenizer TokenBigramSplitSymbolAlpha
+[[0,0.0,0.0],true]
+column_create Names packages_key_index COLUMN_INDEX|WITH_POSITION Packages _key
+[[0,0.0,0.0],true]
+load --table Files
+[
+{"_key": "include/groonga.h", "revision": 100},
+{"_key": "src/groonga.c",     "revision": 29},
+{"_key": "lib/groonga.rb",    "revision": 12},
+{"_key": "README.textile",    "revision": 24},
+{"_key": "ha_mroonga.cc",     "revision": 40},
+{"_key": "ha_mroonga.hpp",    "revision": 6}
+]
+[[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 '_key @ "rroonga" && sub_filter(files, "revision >= 10 && revision < 40")'   --output_columns '_key, files, files.revision'
+[
+  [
+    0,
+    0.0,
+    0.0
+  ],
+  [
+    [
+      [
+        1
+      ],
+      [
+        [
+          "_key",
+          "ShortText"
+        ],
+        [
+          "files",
+          "Files"
+        ],
+        [
+          "files.revision",
+          "UInt32"
+        ]
+      ],
+      [
+        "rroonga",
+        [
+          "lib/groonga.rb",
+          "README.textile"
+        ],
+        [
+          12,
+          24
+        ]
+      ]
+    ]
+  ]
+]

  Added: test/command/suite/select/function/sub_filter/and.test (+35 -0) 100644
===================================================================
--- /dev/null
+++ test/command/suite/select/function/sub_filter/and.test    2013-06-12 11:28:39 +0900 (a0202e6)
@@ -0,0 +1,35 @@
+table_create Files TABLE_PAT_KEY ShortText
+column_create Files revision COLUMN_SCALAR UInt32
+
+table_create Packages TABLE_PAT_KEY ShortText
+column_create Packages files COLUMN_VECTOR Files
+
+column_create Files packages_files_index COLUMN_INDEX Packages files
+
+table_create Revisions TABLE_PAT_KEY UInt32
+column_create Revisions files_revision_index COLUMN_INDEX Files revision
+
+table_create Names TABLE_PAT_KEY ShortText \
+  --default_tokenizer TokenBigramSplitSymbolAlpha
+column_create Names packages_key_index COLUMN_INDEX|WITH_POSITION Packages _key
+
+load --table Files
+[
+{"_key": "include/groonga.h", "revision": 100},
+{"_key": "src/groonga.c",     "revision": 29},
+{"_key": "lib/groonga.rb",    "revision": 12},
+{"_key": "README.textile",    "revision": 24},
+{"_key": "ha_mroonga.cc",     "revision": 40},
+{"_key": "ha_mroonga.hpp",    "revision": 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"]}
+]
+
+select Packages \
+  --filter '_key @ "rroonga" && sub_filter(files, "revision >= 10 && revision < 40")' \
+  --output_columns '_key, files, files.revision'
-------------- next part --------------
HTML����������������������������...
Download 



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