Kouhei Sutou
null+****@clear*****
Wed Apr 13 18:51:49 JST 2016
Kouhei Sutou 2016-04-13 18:51:49 +0900 (Wed, 13 Apr 2016) New Revision: 35b0dd1c4540ea891217776d45cffb454b9b6023 https://github.com/groonga/groonga/commit/35b0dd1c4540ea891217776d45cffb454b9b6023 Message: select drilldown: accept no "keys", no "table" and no "calc_target" It's meaningless drilldown (we can get the same information from records area of target table) but it may be useful... Added files: test/command/suite/select/drilldown/labeled/all_records/no_calc_target.expected test/command/suite/select/drilldown/labeled/all_records/no_calc_target.test Modified files: lib/db.c lib/proc/proc_select.c test/command/suite/select/drilldown/labeled/keys/empty.expected Modified: lib/db.c (+1 -1) =================================================================== --- lib/db.c 2016-04-13 18:33:38 +0900 (beb1423) +++ lib/db.c 2016-04-13 18:51:49 +0900 (96045d4) @@ -4169,7 +4169,7 @@ grn_table_group(grn_ctx *ctx, grn_obj *table, { grn_rc rc = GRN_SUCCESS; grn_bool group_by_all_records = GRN_FALSE; - if (n_keys == 0 && n_results == 1 && results[0].calc_target) { + if (n_keys == 0 && n_results == 1) { group_by_all_records = GRN_TRUE; } else if (!table || !n_keys || !n_results) { ERR(GRN_INVALID_ARGUMENT, "table or n_keys or n_results is void"); Modified: lib/proc/proc_select.c (+31 -33) =================================================================== --- lib/proc/proc_select.c 2016-04-13 18:33:38 +0900 (31be727) +++ lib/proc/proc_select.c 2016-04-13 18:51:49 +0900 (ef30987) @@ -607,6 +607,8 @@ grn_select_drilldowns_execute(grn_ctx *ctx, result->flags = GRN_TABLE_GROUP_CALC_COUNT; result->op = 0; result->max_n_subrecs = 0; + result->key_begin = 0; + result->key_end = 0; result->calc_target = NULL; if (drilldown->table_name) { @@ -630,21 +632,22 @@ grn_select_drilldowns_execute(grn_ctx *ctx, } } - keys = grn_table_sort_key_from_str(ctx, - drilldown->keys, - drilldown->keys_len, - target_table, &n_keys); - - if (!keys && !drilldown->calc_target_name) { - GRN_PLUGIN_CLEAR_ERROR(ctx); - continue; - } + if (drilldown->keys_len > 0) { + keys = grn_table_sort_key_from_str(ctx, + drilldown->keys, + drilldown->keys_len, + target_table, &n_keys); + if (!keys) { + GRN_PLUGIN_CLEAR_ERROR(ctx); + continue; + } - if (n_keys > 1) { - result->max_n_subrecs = 1; - result->key_begin = 0; result->key_end = n_keys - 1; + if (n_keys > 1) { + result->max_n_subrecs = 1; + } } + if (drilldown->calc_target_name) { result->calc_target = grn_obj_column(ctx, target_table, drilldown->calc_target_name, @@ -655,7 +658,9 @@ grn_select_drilldowns_execute(grn_ctx *ctx, } grn_table_group(ctx, target_table, keys, n_keys, result, 1); - grn_table_sort_key_close(ctx, keys, n_keys); + if (keys) { + grn_table_sort_key_close(ctx, keys, n_keys); + } } exit : @@ -1158,37 +1163,30 @@ proc_select_find_all_drilldown_labels(grn_ctx *ctx, grn_user_data *user_data, grn_table_cursor *cursor; cursor = grn_table_cursor_open(ctx, vars, NULL, 0, NULL, 0, 0, -1, 0); if (cursor) { -#define N_SUFFIXES 3 const char *prefix = "drilldown["; int prefix_len = strlen(prefix); - const char *suffixes[N_SUFFIXES] = {"].keys", "].table", "].calc_target"}; - int suffix_len; while (grn_table_cursor_next(ctx, cursor)) { void *key; char *name; int name_len; name_len = grn_table_cursor_get_key(ctx, cursor, &key); name = key; - suffix_len = 0; - if (name_len >= prefix_len && + if (name_len > prefix_len + 1 && strncmp(prefix, name, prefix_len) == 0) { - int i; - for (i = 0; i < N_SUFFIXES; i++) { - int len = strlen(suffixes[i]); - if (name_len >= (prefix_len + 1 + len) && - strncmp(suffixes[i], name + name_len - len, len) == 0) { - suffix_len = len; - break; - } - } - if (suffix_len > 0) { - grn_table_add(ctx, labels, - name + prefix_len, - name_len - prefix_len - suffix_len, - NULL); + const char *label_end; + size_t label_len; + label_end = memchr(name + prefix_len + 1, + ']', + name_len - prefix_len - 1); + if (!label_end) { + continue; } + label_len = (label_end - name) - prefix_len; + grn_table_add(ctx, labels, + name + prefix_len, + label_len, + NULL); } -#undef N_SUFFIXES } grn_table_cursor_close(ctx, cursor); } Added: test/command/suite/select/drilldown/labeled/all_records/no_calc_target.expected (+72 -0) 100644 =================================================================== --- /dev/null +++ test/command/suite/select/drilldown/labeled/all_records/no_calc_target.expected 2016-04-13 18:51:49 +0900 (7296242) @@ -0,0 +1,72 @@ +table_create Memos TABLE_HASH_KEY ShortText +[[0,0.0,0.0],true] +load --table Memos +[ +{"_key": "Groonga is fast!"}, +{"_key": "Mroonga is fast!"}, +{"_key": "Groonga sticker!"}, +{"_key": "Rroonga is fast!"} +] +[[0,0.0,0.0],4] +select Memos --drilldown[n_records].output_columns _key,_nsubrecs +[ + [ + 0, + 0.0, + 0.0 + ], + [ + [ + [ + 4 + ], + [ + [ + "_id", + "UInt32" + ], + [ + "_key", + "ShortText" + ] + ], + [ + 1, + "Groonga is fast!" + ], + [ + 2, + "Mroonga is fast!" + ], + [ + 3, + "Groonga sticker!" + ], + [ + 4, + "Rroonga is fast!" + ] + ], + { + "n_records": [ + [ + 1 + ], + [ + [ + "_key", + "ShortText" + ], + [ + "_nsubrecs", + "Int32" + ] + ], + [ + "all_records", + 4 + ] + ] + } + ] +] Added: test/command/suite/select/drilldown/labeled/all_records/no_calc_target.test (+12 -0) 100644 =================================================================== --- /dev/null +++ test/command/suite/select/drilldown/labeled/all_records/no_calc_target.test 2016-04-13 18:51:49 +0900 (195cbf9) @@ -0,0 +1,12 @@ +table_create Memos TABLE_HASH_KEY ShortText + +load --table Memos +[ +{"_key": "Groonga is fast!"}, +{"_key": "Mroonga is fast!"}, +{"_key": "Groonga sticker!"}, +{"_key": "Rroonga is fast!"} +] + +select Memos \ + --drilldown[n_records].output_columns _key,_nsubrecs Modified: test/command/suite/select/drilldown/labeled/keys/empty.expected (+49 -1) =================================================================== --- test/command/suite/select/drilldown/labeled/keys/empty.expected 2016-04-13 18:33:38 +0900 (49c8db5) +++ test/command/suite/select/drilldown/labeled/keys/empty.expected 2016-04-13 18:51:49 +0900 (e88cca8) @@ -13,4 +13,52 @@ load --table Memos ] [[0,0.0,0.0],4] select Memos --limit 0 --drilldown[tag].keys '' -[[0,0.0,0.0],[[[4],[["_id","UInt32"],["_key","ShortText"],["tag","Tags"]]],{}]] +[ + [ + 0, + 0.0, + 0.0 + ], + [ + [ + [ + 4 + ], + [ + [ + "_id", + "UInt32" + ], + [ + "_key", + "ShortText" + ], + [ + "tag", + "Tags" + ] + ] + ], + { + "tag": [ + [ + 1 + ], + [ + [ + "_key", + "ShortText" + ], + [ + "_nsubrecs", + "Int32" + ] + ], + [ + "all_records", + 4 + ] + ] + } + ] +] -------------- next part -------------- HTML����������������������������...다운로드