Kouhei Sutou
null+****@clear*****
Mon Jun 29 22:54:39 JST 2015
Kouhei Sutou 2015-06-29 22:54:39 +0900 (Mon, 29 Jun 2015) New Revision: f5bb1bb613dade5250e4fb301143ddbddeb28f35 https://github.com/groonga/groonga/commit/f5bb1bb613dade5250e4fb301143ddbddeb28f35 Message: logical_select: support --offset Added files: test/command/suite/sharding/logical_select/offset/negative.expected test/command/suite/sharding/logical_select/offset/negative.test test/command/suite/sharding/logical_select/offset/positive.expected test/command/suite/sharding/logical_select/offset/positive.test Modified files: plugins/sharding/logical_select.rb Modified: plugins/sharding/logical_select.rb (+12 -2) =================================================================== --- plugins/sharding/logical_select.rb 2015-06-29 22:42:54 +0900 (bbff5fb) +++ plugins/sharding/logical_select.rb 2015-06-29 22:54:39 +0900 (5a02a19) @@ -10,6 +10,7 @@ module Groonga "max", "max_border", "filter", + "offset", "limit", "drilldown", "drilldown_sortby", @@ -52,15 +53,24 @@ module Groonga writer.write_table_columns(first_result_set, output_columns) end + current_offset = context.offset + current_offset += n_hits if current_offset < 0 current_limit = context.limit current_limit += n_hits + 1 if current_limit < 0 options = { + :offset => current_offset, :limit => current_limit, } result_sets.each do |result_set| - writer.write_table_records(result_set, output_columns, options) + if result_set.size > current_offset + writer.write_table_records(result_set, output_columns, options) + end + if current_offset > 0 + current_offset = [current_offset - result_set.size, 0].max + end current_limit -= result_set.size break if current_limit <= 0 + options[:offset] = current_offset options[:limit] = current_limit end end @@ -98,7 +108,7 @@ module Groonga @input = input @enumerator = LogicalEnumerator.new("logical_select", @input) @filter = @input[:filter] - @offset = 0 + @offset = (@input[:offset] || 0).to_i @limit = (@input[:limit] || 10).to_i @result_sets = [] Added: test/command/suite/sharding/logical_select/offset/negative.expected (+125 -0) 100644 =================================================================== --- /dev/null +++ test/command/suite/sharding/logical_select/offset/negative.expected 2015-06-29 22:54:39 +0900 (cdd5fd1) @@ -0,0 +1,125 @@ +register sharding +[[0,0.0,0.0],true] +table_create Logs_20150203 TABLE_NO_KEY +[[0,0.0,0.0],true] +column_create Logs_20150203 timestamp COLUMN_SCALAR Time +[[0,0.0,0.0],true] +column_create Logs_20150203 memo COLUMN_SCALAR ShortText +[[0,0.0,0.0],true] +table_create Times_20150203 TABLE_PAT_KEY Time +[[0,0.0,0.0],true] +column_create Times_20150203 timestamp_index COLUMN_INDEX Logs_20150203 timestamp +[[0,0.0,0.0],true] +table_create Logs_20150204 TABLE_NO_KEY +[[0,0.0,0.0],true] +column_create Logs_20150204 timestamp COLUMN_SCALAR Time +[[0,0.0,0.0],true] +column_create Logs_20150204 memo COLUMN_SCALAR ShortText +[[0,0.0,0.0],true] +table_create Times_20150204 TABLE_PAT_KEY Time +[[0,0.0,0.0],true] +column_create Times_20150204 timestamp_index COLUMN_INDEX Logs_20150204 timestamp +[[0,0.0,0.0],true] +table_create Logs_20150205 TABLE_NO_KEY +[[0,0.0,0.0],true] +column_create Logs_20150205 timestamp COLUMN_SCALAR Time +[[0,0.0,0.0],true] +column_create Logs_20150205 memo COLUMN_SCALAR ShortText +[[0,0.0,0.0],true] +table_create Times_20150205 TABLE_PAT_KEY Time +[[0,0.0,0.0],true] +column_create Times_20150205 timestamp_index COLUMN_INDEX Logs_20150205 timestamp +[[0,0.0,0.0],true] +load --table Logs_20150203 +[ +{ + "timestamp": "2015-02-03 12:49:00", + "memo": "2015-02-03 12:49:00" +}, +{ + "timestamp": "2015-02-03 23:59:59", + "memo": "2015-02-03 23:59:59" +} +] +[[0,0.0,0.0],2] +load --table Logs_20150204 +[ +{ + "timestamp": "2015-02-04 00:00:00", + "memo": "2015-02-04 00:00:00" +}, +{ + "timestamp": "2015-02-04 13:49:00", + "memo": "2015-02-04 13:49:00" +}, +{ + "timestamp": "2015-02-04 13:50:00", + "memo": "2015-02-04 13:50:00" +} +] +[[0,0.0,0.0],3] +load --table Logs_20150205 +[ +{ + "timestamp": "2015-02-05 13:49:00", + "memo": "2015-02-05 13:49:00" +}, +{ + "timestamp": "2015-02-05 13:50:00", + "memo": "2015-02-05 13:50:00" +}, +{ + "timestamp": "2015-02-05 13:51:00", + "memo": "2015-02-05 13:51:00" +}, +{ + "timestamp": "2015-02-05 13:52:00", + "memo": "2015-02-05 13:52:00" +} +] +[[0,0.0,0.0],4] +logical_select Logs timestamp --offset -5 +[ + [ + 0, + 0.0, + 0.0 + ], + [ + [ + [ + 9 + ], + [ + [ + "memo", + "ShortText" + ], + [ + "timestamp", + "Time" + ] + ], + [ + "2015-02-04 13:50:00", + 1423025400.0 + ], + [ + "2015-02-05 13:49:00", + 1423111740.0 + ], + [ + "2015-02-05 13:50:00", + 1423111800.0 + ], + [ + "2015-02-05 13:51:00", + 1423111860.0 + ], + [ + "2015-02-05 13:52:00", + 1423111920.0 + ] + ] + ] +] Added: test/command/suite/sharding/logical_select/offset/negative.test (+72 -0) 100644 =================================================================== --- /dev/null +++ test/command/suite/sharding/logical_select/offset/negative.test 2015-06-29 22:54:39 +0900 (0b4ff3c) @@ -0,0 +1,72 @@ +#@on-error omit +register sharding +#@on-error default + +table_create Logs_20150203 TABLE_NO_KEY +column_create Logs_20150203 timestamp COLUMN_SCALAR Time +column_create Logs_20150203 memo COLUMN_SCALAR ShortText +table_create Times_20150203 TABLE_PAT_KEY Time +column_create Times_20150203 timestamp_index COLUMN_INDEX Logs_20150203 timestamp + +table_create Logs_20150204 TABLE_NO_KEY +column_create Logs_20150204 timestamp COLUMN_SCALAR Time +column_create Logs_20150204 memo COLUMN_SCALAR ShortText +table_create Times_20150204 TABLE_PAT_KEY Time +column_create Times_20150204 timestamp_index COLUMN_INDEX Logs_20150204 timestamp + +table_create Logs_20150205 TABLE_NO_KEY +column_create Logs_20150205 timestamp COLUMN_SCALAR Time +column_create Logs_20150205 memo COLUMN_SCALAR ShortText +table_create Times_20150205 TABLE_PAT_KEY Time +column_create Times_20150205 timestamp_index COLUMN_INDEX Logs_20150205 timestamp + +load --table Logs_20150203 +[ +{ + "timestamp": "2015-02-03 12:49:00", + "memo": "2015-02-03 12:49:00" +}, +{ + "timestamp": "2015-02-03 23:59:59", + "memo": "2015-02-03 23:59:59" +} +] + +load --table Logs_20150204 +[ +{ + "timestamp": "2015-02-04 00:00:00", + "memo": "2015-02-04 00:00:00" +}, +{ + "timestamp": "2015-02-04 13:49:00", + "memo": "2015-02-04 13:49:00" +}, +{ + "timestamp": "2015-02-04 13:50:00", + "memo": "2015-02-04 13:50:00" +} +] + +load --table Logs_20150205 +[ +{ + "timestamp": "2015-02-05 13:49:00", + "memo": "2015-02-05 13:49:00" +}, +{ + "timestamp": "2015-02-05 13:50:00", + "memo": "2015-02-05 13:50:00" +}, +{ + "timestamp": "2015-02-05 13:51:00", + "memo": "2015-02-05 13:51:00" +}, +{ + "timestamp": "2015-02-05 13:52:00", + "memo": "2015-02-05 13:52:00" +} +] + +logical_select Logs timestamp \ + --offset -5 Added: test/command/suite/sharding/logical_select/offset/positive.expected (+129 -0) 100644 =================================================================== --- /dev/null +++ test/command/suite/sharding/logical_select/offset/positive.expected 2015-06-29 22:54:39 +0900 (d6af24e) @@ -0,0 +1,129 @@ +register sharding +[[0,0.0,0.0],true] +table_create Logs_20150203 TABLE_NO_KEY +[[0,0.0,0.0],true] +column_create Logs_20150203 timestamp COLUMN_SCALAR Time +[[0,0.0,0.0],true] +column_create Logs_20150203 memo COLUMN_SCALAR ShortText +[[0,0.0,0.0],true] +table_create Times_20150203 TABLE_PAT_KEY Time +[[0,0.0,0.0],true] +column_create Times_20150203 timestamp_index COLUMN_INDEX Logs_20150203 timestamp +[[0,0.0,0.0],true] +table_create Logs_20150204 TABLE_NO_KEY +[[0,0.0,0.0],true] +column_create Logs_20150204 timestamp COLUMN_SCALAR Time +[[0,0.0,0.0],true] +column_create Logs_20150204 memo COLUMN_SCALAR ShortText +[[0,0.0,0.0],true] +table_create Times_20150204 TABLE_PAT_KEY Time +[[0,0.0,0.0],true] +column_create Times_20150204 timestamp_index COLUMN_INDEX Logs_20150204 timestamp +[[0,0.0,0.0],true] +table_create Logs_20150205 TABLE_NO_KEY +[[0,0.0,0.0],true] +column_create Logs_20150205 timestamp COLUMN_SCALAR Time +[[0,0.0,0.0],true] +column_create Logs_20150205 memo COLUMN_SCALAR ShortText +[[0,0.0,0.0],true] +table_create Times_20150205 TABLE_PAT_KEY Time +[[0,0.0,0.0],true] +column_create Times_20150205 timestamp_index COLUMN_INDEX Logs_20150205 timestamp +[[0,0.0,0.0],true] +load --table Logs_20150203 +[ +{ + "timestamp": "2015-02-03 12:49:00", + "memo": "2015-02-03 12:49:00" +}, +{ + "timestamp": "2015-02-03 23:59:59", + "memo": "2015-02-03 23:59:59" +} +] +[[0,0.0,0.0],2] +load --table Logs_20150204 +[ +{ + "timestamp": "2015-02-04 00:00:00", + "memo": "2015-02-04 00:00:00" +}, +{ + "timestamp": "2015-02-04 13:49:00", + "memo": "2015-02-04 13:49:00" +}, +{ + "timestamp": "2015-02-04 13:50:00", + "memo": "2015-02-04 13:50:00" +} +] +[[0,0.0,0.0],3] +load --table Logs_20150205 +[ +{ + "timestamp": "2015-02-05 13:49:00", + "memo": "2015-02-05 13:49:00" +}, +{ + "timestamp": "2015-02-05 13:50:00", + "memo": "2015-02-05 13:50:00" +}, +{ + "timestamp": "2015-02-05 13:51:00", + "memo": "2015-02-05 13:51:00" +}, +{ + "timestamp": "2015-02-05 13:52:00", + "memo": "2015-02-05 13:52:00" +} +] +[[0,0.0,0.0],4] +logical_select Logs timestamp --offset 3 +[ + [ + 0, + 0.0, + 0.0 + ], + [ + [ + [ + 9 + ], + [ + [ + "memo", + "ShortText" + ], + [ + "timestamp", + "Time" + ] + ], + [ + "2015-02-04 13:49:00", + 1423025340.0 + ], + [ + "2015-02-04 13:50:00", + 1423025400.0 + ], + [ + "2015-02-05 13:49:00", + 1423111740.0 + ], + [ + "2015-02-05 13:50:00", + 1423111800.0 + ], + [ + "2015-02-05 13:51:00", + 1423111860.0 + ], + [ + "2015-02-05 13:52:00", + 1423111920.0 + ] + ] + ] +] Added: test/command/suite/sharding/logical_select/offset/positive.test (+72 -0) 100644 =================================================================== --- /dev/null +++ test/command/suite/sharding/logical_select/offset/positive.test 2015-06-29 22:54:39 +0900 (7ca70b0) @@ -0,0 +1,72 @@ +#@on-error omit +register sharding +#@on-error default + +table_create Logs_20150203 TABLE_NO_KEY +column_create Logs_20150203 timestamp COLUMN_SCALAR Time +column_create Logs_20150203 memo COLUMN_SCALAR ShortText +table_create Times_20150203 TABLE_PAT_KEY Time +column_create Times_20150203 timestamp_index COLUMN_INDEX Logs_20150203 timestamp + +table_create Logs_20150204 TABLE_NO_KEY +column_create Logs_20150204 timestamp COLUMN_SCALAR Time +column_create Logs_20150204 memo COLUMN_SCALAR ShortText +table_create Times_20150204 TABLE_PAT_KEY Time +column_create Times_20150204 timestamp_index COLUMN_INDEX Logs_20150204 timestamp + +table_create Logs_20150205 TABLE_NO_KEY +column_create Logs_20150205 timestamp COLUMN_SCALAR Time +column_create Logs_20150205 memo COLUMN_SCALAR ShortText +table_create Times_20150205 TABLE_PAT_KEY Time +column_create Times_20150205 timestamp_index COLUMN_INDEX Logs_20150205 timestamp + +load --table Logs_20150203 +[ +{ + "timestamp": "2015-02-03 12:49:00", + "memo": "2015-02-03 12:49:00" +}, +{ + "timestamp": "2015-02-03 23:59:59", + "memo": "2015-02-03 23:59:59" +} +] + +load --table Logs_20150204 +[ +{ + "timestamp": "2015-02-04 00:00:00", + "memo": "2015-02-04 00:00:00" +}, +{ + "timestamp": "2015-02-04 13:49:00", + "memo": "2015-02-04 13:49:00" +}, +{ + "timestamp": "2015-02-04 13:50:00", + "memo": "2015-02-04 13:50:00" +} +] + +load --table Logs_20150205 +[ +{ + "timestamp": "2015-02-05 13:49:00", + "memo": "2015-02-05 13:49:00" +}, +{ + "timestamp": "2015-02-05 13:50:00", + "memo": "2015-02-05 13:50:00" +}, +{ + "timestamp": "2015-02-05 13:51:00", + "memo": "2015-02-05 13:51:00" +}, +{ + "timestamp": "2015-02-05 13:52:00", + "memo": "2015-02-05 13:52:00" +} +] + +logical_select Logs timestamp \ + --offset 3 -------------- next part -------------- HTML����������������������������...Download