Navigation Menu

Skip to content

Commit

Permalink
Added feature that sort the results of logical_select in descending…
Browse files Browse the repository at this point in the history
… order.
  • Loading branch information
komainu8 committed Oct 25, 2017
1 parent b71df56 commit 7e2b7cf
Show file tree
Hide file tree
Showing 4 changed files with 214 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/mrb/scripts/table.rb
Expand Up @@ -102,7 +102,7 @@ def ensure_sort_key(key, converted_keys)
order = key[:order] || order
offset = key[:offset] || offset
else
key_name = key
key_name = key.dup
end

case key_name
Expand Down
5 changes: 5 additions & 0 deletions plugins/sharding/logical_select.rb
Expand Up @@ -152,6 +152,11 @@ def write_records(writer, context)
:offset => current_offset,
:limit => current_limit,
}
context.sort_keys.each do |sort_key|
if sort_key.match("-timestamp")
result_sets = result_sets.reverse
end
end
result_sets.each do |result_set|
if result_set.size > current_offset
writer.write_table_records(result_set, output_columns, options)
Expand Down
@@ -0,0 +1,142 @@
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 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 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]
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 --sort_keys -timestamp
[
[
0,
0.0,
0.0
],
[
[
[
9
],
[
[
"_id",
"UInt32"
],
[
"memo",
"ShortText"
],
[
"timestamp",
"Time"
]
],
[
4,
"2015-02-05 13:52:00",
1423111920.0
],
[
3,
"2015-02-05 13:51:00",
1423111860.0
],
[
2,
"2015-02-05 13:50:00",
1423111800.0
],
[
1,
"2015-02-05 13:49:00",
1423111740.0
],
[
3,
"2015-02-04 13:50:00",
1423025400.0
],
[
2,
"2015-02-04 13:49:00",
1423025340.0
],
[
1,
"2015-02-04 00:00:00",
1422975600.0
],
[
2,
"2015-02-03 23:59:59",
1422975599.0
],
[
1,
"2015-02-03 12:49:00",
1422935340.0
]
]
]
]
@@ -0,0 +1,66 @@
#@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 Logs_20150204 TABLE_NO_KEY
column_create Logs_20150204 timestamp COLUMN_SCALAR Time
column_create Logs_20150204 memo COLUMN_SCALAR ShortText

table_create Logs_20150205 TABLE_NO_KEY
column_create Logs_20150205 timestamp COLUMN_SCALAR Time
column_create Logs_20150205 memo COLUMN_SCALAR ShortText

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 \
--sort_keys -timestamp

0 comments on commit 7e2b7cf

Please sign in to comment.