Kouhei Sutou
null+****@clear*****
Tue Aug 23 20:14:22 JST 2016
Kouhei Sutou 2016-08-23 20:14:22 +0900 (Tue, 23 Aug 2016) New Revision: c1f138247e54417e569530beac3fc97dc83ec2ed https://github.com/groonga/groonga/commit/c1f138247e54417e569530beac3fc97dc83ec2ed Message: Add valid lexicon check on setting index sources If users create wrong index for sources by column_create, this check shows details. Added files: test/command/suite/column_create/index/source/mismatch/table_key_type/column_reference.expected test/command/suite/column_create/index/source/mismatch/table_key_type/column_reference.test test/command/suite/column_create/index/source/mismatch/table_key_type/table_key_reference.expected test/command/suite/column_create/index/source/mismatch/table_key_type/table_key_reference.test Modified files: lib/db.c test/command/suite/column_create/index/source/mismatch/table_key_reference/column_builtin.expected test/command/suite/column_create/index/source/mismatch/table_key_reference/table_key_builtin.expected Modified: lib/db.c (+61 -31) =================================================================== --- lib/db.c 2016-08-23 20:11:08 +0900 (e6caf88) +++ lib/db.c 2016-08-23 20:14:22 +0900 (505b4a3) @@ -8369,27 +8369,26 @@ grn_obj_spec_save(grn_ctx *ctx, grn_db_obj *obj) } inline static void -grn_obj_set_info_source_validate_report_error(grn_ctx *ctx, - grn_obj *column, - grn_obj *table_domain, - grn_obj *source, - grn_id source_type_id) +grn_obj_set_info_source_invalid_source_type_error(grn_ctx *ctx, + const char *message, + grn_obj *source, + grn_id source_type_id, + grn_obj *column, + grn_obj *expected_type) { - char column_name[GRN_TABLE_MAX_KEY_SIZE]; - char table_domain_name[GRN_TABLE_MAX_KEY_SIZE]; char source_name[GRN_TABLE_MAX_KEY_SIZE]; - char source_type_name[GRN_TABLE_MAX_KEY_SIZE]; - int column_name_size; - int table_domain_name_size; int source_name_size; - int source_type_name_size; grn_obj *source_type; + char source_type_name[GRN_TABLE_MAX_KEY_SIZE]; + int source_type_name_size; + char column_name[GRN_TABLE_MAX_KEY_SIZE]; + int column_name_size; + char expected_type_name[GRN_TABLE_MAX_KEY_SIZE]; + int expected_type_name_size; - column_name_size = grn_obj_name(ctx, column, - column_name, GRN_TABLE_MAX_KEY_SIZE); source_name_size = grn_obj_name(ctx, source, source_name, GRN_TABLE_MAX_KEY_SIZE); - if (GRN_OBJ_TABLEP(source)) { + if (grn_obj_is_table(ctx, source)) { source_name[source_name_size] = '\0'; grn_strncat(source_name, GRN_TABLE_MAX_KEY_SIZE, @@ -8397,9 +8396,7 @@ grn_obj_set_info_source_validate_report_error(grn_ctx *ctx, GRN_TABLE_MAX_KEY_SIZE - source_name_size - 1); source_name_size = strlen(source_name); } - table_domain_name_size = grn_obj_name(ctx, table_domain, - table_domain_name, - GRN_TABLE_MAX_KEY_SIZE); + source_type = grn_ctx_at(ctx, source_type_id); if (source_type) { source_type_name_size = grn_obj_name(ctx, source_type, @@ -8413,25 +8410,33 @@ grn_obj_set_info_source_validate_report_error(grn_ctx *ctx, GRN_TABLE_MAX_KEY_SIZE); source_type_name_size = strlen(source_type_name); } + + column_name_size = grn_obj_name(ctx, column, + column_name, GRN_TABLE_MAX_KEY_SIZE); + expected_type_name_size = grn_obj_name(ctx, expected_type, + expected_type_name, + GRN_TABLE_MAX_KEY_SIZE); ERR(GRN_INVALID_ARGUMENT, - "grn_obj_set_info(): GRN_INFO_SOURCE: " - "source type must equal to index table's key type: " - "source:<%.*s(%.*s)> index:<%.*s(%.*s)>", + "[column][index][source] %s: " + "source:<%.*s(%.*s)> " + "expected:<%.*s> " + "index:<%.*s>", + message, source_name_size, source_name, source_type_name_size, source_type_name, - column_name_size, column_name, - table_domain_name_size, table_domain_name); + expected_type_name_size, expected_type_name, + column_name_size, column_name); } inline static grn_rc grn_obj_set_info_source_validate(grn_ctx *ctx, grn_obj *obj, grn_obj *value) { - grn_rc rc = GRN_SUCCESS; grn_id lexicon_id; grn_obj *lexicon = NULL; grn_id lexicon_domain_id; grn_obj *lexicon_domain = NULL; grn_bool lexicon_domain_is_table; + grn_bool lexicon_have_tokenizer; grn_id *source_ids; int i, n_source_ids; @@ -8461,14 +8466,18 @@ grn_obj_set_info_source_validate(grn_ctx *ctx, grn_obj *obj, grn_obj *value) goto exit; } - if (!grn_obj_is_table(ctx, lexicon_domain)) { - goto exit; + lexicon_domain_is_table = grn_obj_is_table(ctx, lexicon_domain); + { + grn_obj *tokenizer; + grn_table_get_info(ctx, lexicon, NULL, NULL, &tokenizer, NULL, NULL); + lexicon_have_tokenizer = (tokenizer != NULL); } for (i = 0; i < n_source_ids; i++) { grn_id source_id = source_ids[i]; grn_obj *source; grn_id source_type_id; + grn_id source_type_is_table; source = grn_ctx_at(ctx, source_id); if (!source) { @@ -8479,12 +8488,33 @@ grn_obj_set_info_source_validate(grn_ctx *ctx, grn_obj *obj, grn_obj *value) } else { source_type_id = DB_OBJ(source)->range; } - if (lexicon_domain_id != source_type_id) { - grn_obj_set_info_source_validate_report_error(ctx, - obj, - lexicon_domain, - source, - source_type_id); + { + grn_obj *source_type; + source_type = grn_ctx_at(ctx, source_type_id); + source_type_is_table = grn_obj_is_table(ctx, source_type); + } + if (!lexicon_have_tokenizer) { + if (source_type_is_table) { + if (lexicon_id != source_type_id) { + grn_obj_set_info_source_invalid_source_type_error( + ctx, + "source type must equal to index table", + source, + source_type_id, + obj, + lexicon); + } + } else { + if (lexicon_domain_id != source_type_id) { + grn_obj_set_info_source_invalid_source_type_error( + ctx, + "source type must equal to index table's key", + source, + source_type_id, + obj, + lexicon_domain); + } + } } grn_obj_unlink(ctx, source); if (ctx->rc != GRN_SUCCESS) { Modified: test/command/suite/column_create/index/source/mismatch/table_key_reference/column_builtin.expected (+2 -2) =================================================================== --- test/command/suite/column_create/index/source/mismatch/table_key_reference/column_builtin.expected 2016-08-23 20:11:08 +0900 (0c1fb46) +++ test/command/suite/column_create/index/source/mismatch/table_key_reference/column_builtin.expected 2016-08-23 20:14:22 +0900 (91f985d) @@ -14,8 +14,8 @@ column_create TagsIndex sites_tags COLUMN_INDEX Sites tags 0.0, 0.0 ], - "grn_obj_set_info(): GRN_INFO_SOURCE: source type must equal to index table's key type: source:<Sites.tags(ShortText)> index:<Ta" + "[column][index][source] source type must equal to index table's key: source:<Sites.tags(ShortText)> expected:<Tags> index:<Tags" ], false ] -#|e| grn_obj_set_info(): GRN_INFO_SOURCE: source type must equal to index table's key type: source:<Sites.tags(ShortText)> index:<TagsIndex.sites_tags(Tags)> +#|e| [column][index][source] source type must equal to index table's key: source:<Sites.tags(ShortText)> expected:<Tags> index:<TagsIndex.sites_tags> Modified: test/command/suite/column_create/index/source/mismatch/table_key_reference/table_key_builtin.expected (+2 -2) =================================================================== --- test/command/suite/column_create/index/source/mismatch/table_key_reference/table_key_builtin.expected 2016-08-23 20:11:08 +0900 (e4b6d44) +++ test/command/suite/column_create/index/source/mismatch/table_key_reference/table_key_builtin.expected 2016-08-23 20:14:22 +0900 (ffbe9d5) @@ -12,8 +12,8 @@ column_create TagsIndex sites_tags COLUMN_INDEX TagPriorities _key 0.0, 0.0 ], - "grn_obj_set_info(): GRN_INFO_SOURCE: source type must equal to index table's key type: source:<TagPriorities._key(ShortText)> i" + "[column][index][source] source type must equal to index table's key: source:<TagPriorities._key(ShortText)> expected:<Tags> ind" ], false ] -#|e| grn_obj_set_info(): GRN_INFO_SOURCE: source type must equal to index table's key type: source:<TagPriorities._key(ShortText)> index:<TagsIndex.sites_tags(Tags)> +#|e| [column][index][source] source type must equal to index table's key: source:<TagPriorities._key(ShortText)> expected:<Tags> index:<TagsIndex.sites_tags> Added: test/command/suite/column_create/index/source/mismatch/table_key_type/column_reference.expected (+21 -0) 100644 =================================================================== --- /dev/null +++ test/command/suite/column_create/index/source/mismatch/table_key_type/column_reference.expected 2016-08-23 20:14:22 +0900 (4b0676d) @@ -0,0 +1,21 @@ +table_create Tags TABLE_HASH_KEY ShortText +[[0,0.0,0.0],true] +table_create Sites TABLE_HASH_KEY ShortText +[[0,0.0,0.0],true] +column_create Sites tags COLUMN_VECTOR Tags +[[0,0.0,0.0],true] +table_create TagsIndex TABLE_HASH_KEY ShortText +[[0,0.0,0.0],true] +column_create TagsIndex sites_tags COLUMN_INDEX Sites tags +[ + [ + [ + -22, + 0.0, + 0.0 + ], + "[column][index][source] source type must equal to index table: source:<Sites.tags(Tags)> expected:<TagsIndex> index:<TagsIndex." + ], + false +] +#|e| [column][index][source] source type must equal to index table: source:<Sites.tags(Tags)> expected:<TagsIndex> index:<TagsIndex.sites_tags> Added: test/command/suite/column_create/index/source/mismatch/table_key_type/column_reference.test (+7 -0) 100644 =================================================================== --- /dev/null +++ test/command/suite/column_create/index/source/mismatch/table_key_type/column_reference.test 2016-08-23 20:14:22 +0900 (63cbfec) @@ -0,0 +1,7 @@ +table_create Tags TABLE_HASH_KEY ShortText + +table_create Sites TABLE_HASH_KEY ShortText +column_create Sites tags COLUMN_VECTOR Tags + +table_create TagsIndex TABLE_HASH_KEY ShortText +column_create TagsIndex sites_tags COLUMN_INDEX Sites tags Added: test/command/suite/column_create/index/source/mismatch/table_key_type/table_key_reference.expected (+19 -0) 100644 =================================================================== --- /dev/null +++ test/command/suite/column_create/index/source/mismatch/table_key_type/table_key_reference.expected 2016-08-23 20:14:22 +0900 (def34b8) @@ -0,0 +1,19 @@ +table_create Tags TABLE_HASH_KEY ShortText +[[0,0.0,0.0],true] +table_create TagPriorities TABLE_HASH_KEY Tags +[[0,0.0,0.0],true] +table_create TagsIndex TABLE_HASH_KEY ShortText +[[0,0.0,0.0],true] +column_create TagsIndex sites_tags COLUMN_INDEX TagPriorities _key +[ + [ + [ + -22, + 0.0, + 0.0 + ], + "[column][index][source] source type must equal to index table: source:<TagPriorities._key(Tags)> expected:<TagsIndex> index:<Ta" + ], + false +] +#|e| [column][index][source] source type must equal to index table: source:<TagPriorities._key(Tags)> expected:<TagsIndex> index:<TagsIndex.sites_tags> Added: test/command/suite/column_create/index/source/mismatch/table_key_type/table_key_reference.test (+6 -0) 100644 =================================================================== --- /dev/null +++ test/command/suite/column_create/index/source/mismatch/table_key_type/table_key_reference.test 2016-08-23 20:14:22 +0900 (132373a) @@ -0,0 +1,6 @@ +table_create Tags TABLE_HASH_KEY ShortText + +table_create TagPriorities TABLE_HASH_KEY Tags + +table_create TagsIndex TABLE_HASH_KEY ShortText +column_create TagsIndex sites_tags COLUMN_INDEX TagPriorities _key -------------- next part -------------- HTML����������������������������... Download