Kouhei Sutou
null+****@clear*****
Fri Nov 21 21:44:44 JST 2014
Kouhei Sutou 2014-11-21 21:44:44 +0900 (Fri, 21 Nov 2014) New Revision: 743db75d8964b8ea99b7909ae1bd5155927178ff https://github.com/groonga/groonga/commit/743db75d8964b8ea99b7909ae1bd5155927178ff Message: select drilldown[].sortby: support sort by column value of grouped record Added files: test/command/suite/select/drilldown/labeled/sortby/sub_record_column/multiple.expected test/command/suite/select/drilldown/labeled/sortby/sub_record_column/multiple.test Modified files: lib/db.c Modified: lib/db.c (+33 -1) =================================================================== --- lib/db.c 2014-11-21 13:28:02 +0900 (3825200) +++ lib/db.c 2014-11-21 21:44:44 +0900 (0e717a0) @@ -9361,6 +9361,34 @@ is_compressed_column(grn_ctx *ctx, grn_obj *obj) return (obj->header.flags & (GRN_OBJ_COMPRESS_ZLIB | GRN_OBJ_COMPRESS_LZ4)); } +static grn_bool +is_sub_record_accessor(grn_ctx *ctx, grn_obj *obj) +{ + grn_accessor *accessor; + + if (!obj) { + return GRN_FALSE; + } + + if (obj->header.type != GRN_ACCESSOR) { + return GRN_FALSE; + } + + for (accessor = (grn_accessor *)obj; accessor; accessor = accessor->next) { + switch (accessor->action) { + case GRN_ACCESSOR_GET_VALUE : + if (GRN_TABLE_IS_GROUPED(accessor->obj)) { + return GRN_TRUE; + } + break; + default : + break; + } + } + + return GRN_FALSE; +} + static int range_is_idp(grn_obj *obj) { @@ -9435,11 +9463,15 @@ grn_table_sort(grn_ctx *ctx, grn_obj *table, int offset, int limit, } else { int j; grn_bool have_compressed_column = GRN_FALSE; + grn_bool have_sub_record_accessor = GRN_FALSE; grn_table_sort_key *kp; for (kp = keys, j = n_keys; j; kp++, j--) { if (is_compressed_column(ctx, kp->key)) { have_compressed_column = GRN_TRUE; } + if (is_sub_record_accessor(ctx, kp->key)) { + have_sub_record_accessor = GRN_TRUE; + } if (range_is_idp(kp->key)) { kp->offset = KEY_ID; } else { @@ -9509,7 +9541,7 @@ grn_table_sort(grn_ctx *ctx, grn_obj *table, int offset, int limit, } } } - if (have_compressed_column) { + if (have_compressed_column || have_sub_record_accessor) { i = grn_table_sort_value(ctx, table, offset, limit, result, keys, n_keys); } else { Added: test/command/suite/select/drilldown/labeled/sortby/sub_record_column/multiple.expected (+121 -0) 100644 =================================================================== --- /dev/null +++ test/command/suite/select/drilldown/labeled/sortby/sub_record_column/multiple.expected 2014-11-21 21:44:44 +0900 (3e22e32) @@ -0,0 +1,121 @@ +table_create Tags TABLE_PAT_KEY 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] +column_create Memos date COLUMN_SCALAR Time +[[0,0.0,0.0],true] +load --table Memos +[ +{"_key": "Rroonga is fast!", "tag": "Rroonga", "date": "2014-11-17 00:00:00"}, +{"_key": "Mroonga is fast!", "tag": "Mroonga", "date": "2014-11-16 00:00:00"}, +{"_key": "Groonga is fast!", "tag": "Groonga", "date": "2014-11-16 00:00:00"}, +{"_key": "Groonga sticker!", "tag": "Groonga", "date": "2014-11-16 00:00:00"}, +{"_key": "Groonga is good!", "tag": "Groonga", "date": "2014-11-17 00:00:00"} +] +[[0,0.0,0.0],5] +select Memos --filter true --drilldown[tag].keys tag,date --drilldown[tag].output_columns _value.tag,_value.date,_nsubrecs --drilldown[tag].sortby _value.tag._key,_value.date +[ + [ + 0, + 0.0, + 0.0 + ], + [ + [ + [ + 5 + ], + [ + [ + "_id", + "UInt32" + ], + [ + "_key", + "ShortText" + ], + [ + "date", + "Time" + ], + [ + "tag", + "Tags" + ] + ], + [ + 1, + "Rroonga is fast!", + 1416150000.0, + "Rroonga" + ], + [ + 2, + "Mroonga is fast!", + 1416063600.0, + "Mroonga" + ], + [ + 3, + "Groonga is fast!", + 1416063600.0, + "Groonga" + ], + [ + 4, + "Groonga sticker!", + 1416063600.0, + "Groonga" + ], + [ + 5, + "Groonga is good!", + 1416150000.0, + "Groonga" + ] + ], + { + "tag": [ + [ + 4 + ], + [ + [ + "tag", + "Tags" + ], + [ + "date", + "Time" + ], + [ + "_nsubrecs", + "Int32" + ] + ], + [ + "Groonga", + 1416063600.0, + 2 + ], + [ + "Groonga", + 1416150000.0, + 1 + ], + [ + "Mroonga", + 1416063600.0, + 1 + ], + [ + "Rroonga", + 1416150000.0, + 1 + ] + ] + } + ] +] Added: test/command/suite/select/drilldown/labeled/sortby/sub_record_column/multiple.test (+20 -0) 100644 =================================================================== --- /dev/null +++ test/command/suite/select/drilldown/labeled/sortby/sub_record_column/multiple.test 2014-11-21 21:44:44 +0900 (be75861) @@ -0,0 +1,20 @@ +table_create Tags TABLE_PAT_KEY ShortText + +table_create Memos TABLE_HASH_KEY ShortText +column_create Memos tag COLUMN_SCALAR Tags +column_create Memos date COLUMN_SCALAR Time + +load --table Memos +[ +{"_key": "Rroonga is fast!", "tag": "Rroonga", "date": "2014-11-17 00:00:00"}, +{"_key": "Mroonga is fast!", "tag": "Mroonga", "date": "2014-11-16 00:00:00"}, +{"_key": "Groonga is fast!", "tag": "Groonga", "date": "2014-11-16 00:00:00"}, +{"_key": "Groonga sticker!", "tag": "Groonga", "date": "2014-11-16 00:00:00"}, +{"_key": "Groonga is good!", "tag": "Groonga", "date": "2014-11-17 00:00:00"} +] + +select Memos \ + --filter true \ + --drilldown[tag].keys tag,date \ + --drilldown[tag].output_columns _value.tag,_value.date,_nsubrecs \ + --drilldown[tag].sortby _value.tag._key,_value.date -------------- next part -------------- HTML����������������������������...下載