Navigation Menu

Skip to content

Commit

Permalink
Fix a bug for "XXX && sub_filter(...)" type filter
Browse files Browse the repository at this point in the history
In the filter, "sub_filter(...)" is just ignored. "sub_filter(...)"
should substitute matched records from records that are matched
against "XXX".
  • Loading branch information
kou committed Jun 12, 2013
1 parent f9dfc31 commit 94fbf50
Show file tree
Hide file tree
Showing 3 changed files with 118 additions and 11 deletions.
19 changes: 8 additions & 11 deletions lib/db.c
Expand Up @@ -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) {
Expand All @@ -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,
Expand All @@ -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, {
Expand All @@ -2530,15 +2525,15 @@ 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];
int key_len;
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) {
Expand All @@ -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;
}
Expand Down
75 changes: 75 additions & 0 deletions test/command/suite/select/function/sub_filter/and.expected
@@ -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
]
]
]
]
]
35 changes: 35 additions & 0 deletions test/command/suite/select/function/sub_filter/and.test
@@ -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'

0 comments on commit 94fbf50

Please sign in to comment.