Navigation Menu

Skip to content

Commit

Permalink
Add check exist of "WITH SECTION" flag when a full-text search for ve…
Browse files Browse the repository at this point in the history
…ctor column.

Because we can't a full-text search for vector column
if we don't set "WITH_SECTION" flag.
  • Loading branch information
komainu8 committed Jun 19, 2018
1 parent 57cf8ad commit fbf58b7
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 0 deletions.
30 changes: 30 additions & 0 deletions lib/db.c
Expand Up @@ -8821,6 +8821,36 @@ grn_obj_set_info_source_validate(grn_ctx *ctx, grn_obj *obj, grn_obj *value)

source_ids = (grn_id *)GRN_BULK_HEAD(value);
n_source_ids = GRN_BULK_VSIZE(value) / sizeof(grn_id);
if (n_source_ids == 1) {
grn_obj *source;

source = grn_ctx_at(ctx, source_ids[0]);
switch (source->header.type) {
case GRN_COLUMN_VAR_SIZE :
switch (source->header.flags & GRN_OBJ_COLUMN_TYPE_MASK) {
case GRN_OBJ_COLUMN_VECTOR :
if ((obj->header.flags & GRN_OBJ_COLUMN_INDEX)
&& (obj->header.flags & GRN_OBJ_WITH_POSITION)) {
if (!(obj->header.flags & GRN_OBJ_WITH_SECTION)) {
char index_name[GRN_TABLE_MAX_KEY_SIZE];
int index_name_size;
index_name_size = grn_obj_name(ctx, obj,
index_name, GRN_TABLE_MAX_KEY_SIZE);
ERR(GRN_INVALID_ARGUMENT,
"grn_obj_set_info(): GRN_INFO_SOURCE: "
"vector column index must be created with WITH_SECTION flag: <%.*s>",
index_name_size, index_name);
goto exit;
}
}
default:
break;
}
default:
break;
}
}

if (n_source_ids > 1 && !(obj->header.flags & GRN_OBJ_WITH_SECTION)) {
char index_name[GRN_TABLE_MAX_KEY_SIZE];
int index_name_size;
Expand Down
25 changes: 25 additions & 0 deletions test/command/suite/column_create/index/without_section.expected
@@ -0,0 +1,25 @@
table_create Memos TABLE_NO_KEY
[[0,0.0,0.0],true]
column_create Memos content COLUMN_VECTOR ShortText
[[0,0.0,0.0],true]
load --table Memos
[
{"content": ["Groonga", "Mroonga", "PGroonga"]},
{"content": ["Hello", "Good-bye"]}
]
[[0,0.0,0.0],2]
table_create Terms TABLE_PAT_KEY ShortText --default_tokenizer TokenBigram --normalizer NormalizerAuto
[[0,0.0,0.0],true]
column_create Terms memos_content COLUMN_INDEX|WITH_POSITION Memos content
[
[
[
-22,
0.0,
0.0
],
"grn_obj_set_info(): GRN_INFO_SOURCE: vector column index must be created with WITH_SECTION flag: <Terms.memos_content>"
],
false
]
#|e| grn_obj_set_info(): GRN_INFO_SOURCE: vector column index must be created with WITH_SECTION flag: <Terms.memos_content>
10 changes: 10 additions & 0 deletions test/command/suite/column_create/index/without_section.test
@@ -0,0 +1,10 @@
table_create Memos TABLE_NO_KEY
column_create Memos content COLUMN_VECTOR ShortText
load --table Memos
[
{"content": ["Groonga", "Mroonga", "PGroonga"]},
{"content": ["Hello", "Good-bye"]}
]

table_create Terms TABLE_PAT_KEY ShortText --default_tokenizer TokenBigram --normalizer NormalizerAuto
column_create Terms memos_content COLUMN_INDEX|WITH_POSITION Memos content

0 comments on commit fbf58b7

Please sign in to comment.