Kouhei Sutou
null+****@clear*****
Sun Apr 10 22:23:05 JST 2016
Kouhei Sutou 2016-04-10 22:23:05 +0900 (Sun, 10 Apr 2016) New Revision: a89424a92c74dc0eacf30b35401efcf2c989e377 https://github.com/groonga/groonga/commit/a89424a92c74dc0eacf30b35401efcf2c989e377 Message: test select drilldown: add a test for nonexistent label case Added files: test/command/suite/select/drilldown/labeled/table/nonexistent.expected test/command/suite/select/drilldown/labeled/table/nonexistent.test Modified files: lib/proc/proc_select.c Modified: lib/proc/proc_select.c (+34 -9) =================================================================== --- lib/proc/proc_select.c 2016-04-10 22:09:42 +0900 (4d18427) +++ lib/proc/proc_select.c 2016-04-10 22:23:05 +0900 (e7b6ee2) @@ -589,6 +589,11 @@ grn_select_drilldowns_execute(grn_ctx *ctx, results = GRN_PLUGIN_MALLOCN(ctx, grn_table_group_result, n_drilldowns); for (i = 0; i < n_drilldowns; i++) { + grn_table_group_result *result = results + i; + result->table = NULL; + } + + for (i = 0; i < n_drilldowns; i++) { grn_table_sort_key *keys = NULL; unsigned int n_keys; grn_obj *target_table = table; @@ -600,7 +605,6 @@ grn_select_drilldowns_execute(grn_ctx *ctx, drilldown = drilldowns + index; result = results + index; - result->table = NULL; result->limit = 1; result->flags = GRN_TABLE_GROUP_CALC_COUNT; result->op = 0; @@ -613,7 +617,16 @@ grn_select_drilldowns_execute(grn_ctx *ctx, labels, drilldown->table_name, drilldown->table_name_len); - if (dependent_id != GRN_ID_NIL) { + if (dependent_id == GRN_ID_NIL) { + GRN_PLUGIN_ERROR(ctx, GRN_INVALID_ARGUMENT, + "[select][drilldown][%.*s][table] " + "nonexistent label: <%.*s>", + (int)(drilldown->label_len), + drilldown->label, + (int)(drilldown->table_name_len), + drilldown->table_name); + break; + } else { uint32_t dependent_index = dependent_id - 1; target_table = results[dependent_index].table; } @@ -720,13 +733,6 @@ grn_select_drilldowns_output(grn_ctx *ctx, condition); } - if (result->calc_target) { - grn_obj_unlink(ctx, result->calc_target); - } - if (result->table) { - grn_obj_unlink(ctx, result->table); - } - GRN_QUERY_LOG(ctx, GRN_QUERY_LOG_SIZE, ":", "drilldown(%d)[%.*s]", n_hits, (int)(drilldown->label_len), drilldown->label); @@ -757,6 +763,25 @@ grn_select_drilldowns(grn_ctx *ctx, grn_obj *table, condition, results); + { + unsigned int i; + + for (i = 0; i < n_drilldowns; i++) { + grn_table_group_result *result = results + i; + + if (!result->table) { + continue; + } + + if (result->calc_target) { + grn_obj_unlink(ctx, result->calc_target); + } + if (result->table) { + grn_obj_close(ctx, result->table); + } + + } + } GRN_PLUGIN_FREE(ctx, results); } Added: test/command/suite/select/drilldown/labeled/table/nonexistent.expected (+78 -0) 100644 =================================================================== --- /dev/null +++ test/command/suite/select/drilldown/labeled/table/nonexistent.expected 2016-04-10 22:23:05 +0900 (2237313) @@ -0,0 +1,78 @@ +table_create Tags TABLE_PAT_KEY ShortText +[[0,0.0,0.0],true] +column_create Tags category COLUMN_SCALAR ShortText +[[0,0.0,0.0],true] +table_create Memos TABLE_HASH_KEY ShortText +[[0,0.0,0.0],true] +column_create Memos tag COLUMN_SCALAR Tags +[[0,0.0,0.0],true] +load --table Memos +[ +{"_key": "Groonga is fast!", "tag": "Groonga"}, +{"_key": "Mroonga is fast!", "tag": "Mroonga"}, +{"_key": "Groonga sticker!", "tag": "Groonga"}, +{"_key": "Rroonga is fast!", "tag": "Rroonga"} +] +[[0,0.0,0.0],4] +load --table Tags +[ +{"_key": "Groonga", "category": "C/C++"}, +{"_key": "Mroonga", "category": "C/C++"}, +{"_key": "Rroonga", "category": "Ruby"} +] +[[0,0.0,0.0],3] +select Memos --drilldown[category].table nonexistent --drilldown[category].keys category --drilldown[category].output_columns _key,_nsubrecs --drilldown[tag].keys tag --drilldown[tag].output_columns _key,_nsubrecs,category +[ + [ + [ + -22, + 0.0, + 0.0 + ], + "[select][drilldown][category][table] nonexistent label: <nonexistent>" + ], + [ + [ + [ + 4 + ], + [ + [ + "_id", + "UInt32" + ], + [ + "_key", + "ShortText" + ], + [ + "tag", + "Tags" + ] + ], + [ + 1, + "Groonga is fast!", + "Groonga" + ], + [ + 2, + "Mroonga is fast!", + "Mroonga" + ], + [ + 3, + "Groonga sticker!", + "Groonga" + ], + [ + 4, + "Rroonga is fast!", + "Rroonga" + ] + ], + { + } + ] +] +#|e| [select][drilldown][category][table] nonexistent label: <nonexistent> Added: test/command/suite/select/drilldown/labeled/table/nonexistent.test (+27 -0) 100644 =================================================================== --- /dev/null +++ test/command/suite/select/drilldown/labeled/table/nonexistent.test 2016-04-10 22:23:05 +0900 (44acfba) @@ -0,0 +1,27 @@ +table_create Tags TABLE_PAT_KEY ShortText +column_create Tags category COLUMN_SCALAR ShortText + +table_create Memos TABLE_HASH_KEY ShortText +column_create Memos tag COLUMN_SCALAR Tags + +load --table Memos +[ +{"_key": "Groonga is fast!", "tag": "Groonga"}, +{"_key": "Mroonga is fast!", "tag": "Mroonga"}, +{"_key": "Groonga sticker!", "tag": "Groonga"}, +{"_key": "Rroonga is fast!", "tag": "Rroonga"} +] + +load --table Tags +[ +{"_key": "Groonga", "category": "C/C++"}, +{"_key": "Mroonga", "category": "C/C++"}, +{"_key": "Rroonga", "category": "Ruby"} +] + +select Memos \ + --drilldown[category].table nonexistent \ + --drilldown[category].keys category \ + --drilldown[category].output_columns _key,_nsubrecs \ + --drilldown[tag].keys tag \ + --drilldown[tag].output_columns _key,_nsubrecs,category -------------- next part -------------- HTML����������������������������... Download