Navigation Menu

Skip to content

Commit

Permalink
logical_select: fix a bug that offset over shards reduce limit unexpe…
Browse files Browse the repository at this point in the history
…ctedly
  • Loading branch information
kou committed Oct 4, 2017
1 parent 31aef02 commit 0839cf6
Show file tree
Hide file tree
Showing 3 changed files with 193 additions and 1 deletion.
2 changes: 1 addition & 1 deletion plugins/sharding/logical_select.rb
Expand Up @@ -155,11 +155,11 @@ def write_records(writer, context)
result_sets.each do |result_set|
if result_set.size > current_offset
writer.write_table_records(result_set, output_columns, options)
current_limit -= result_set.size
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
Expand Down
119 changes: 119 additions & 0 deletions test/command/suite/sharding/logical_select/offset/with_limit.expected
@@ -0,0 +1,119 @@
plugin_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 --limit 2
[
[
0,
0.0,
0.0
],
[
[
[
9
],
[
[
"_id",
"UInt32"
],
[
"memo",
"ShortText"
],
[
"timestamp",
"Time"
]
],
[
2,
"2015-02-04 13:49:00",
1423025340.0
],
[
3,
"2015-02-04 13:50:00",
1423025400.0
]
]
]
]
73 changes: 73 additions & 0 deletions test/command/suite/sharding/logical_select/offset/with_limit.test
@@ -0,0 +1,73 @@
#@on-error omit
plugin_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 \
--limit 2

0 comments on commit 0839cf6

Please sign in to comment.