Skip to content

Commit

Permalink
logical_shard_list: add
Browse files Browse the repository at this point in the history
TODO:

  * Documentation.
  • Loading branch information
kou committed Aug 6, 2015
1 parent eac4667 commit bf3c479
Show file tree
Hide file tree
Showing 16 changed files with 242 additions and 2 deletions.
1 change: 1 addition & 0 deletions plugins/sharding.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@
require "sharding/logical_count"
require "sharding/logical_range_filter"
require "sharding/logical_select"
require "sharding/logical_shard_list"
require "sharding/logical_table_remove"
11 changes: 9 additions & 2 deletions plugins/sharding/logical_enumerator.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
module Groonga
module Sharding
class LogicalEnumerator
include Enumerable

attr_reader :target_range
attr_reader :logical_table
attr_reader :shard_key_name
def initialize(command_name, input)
def initialize(command_name, input, options={})
@command_name = command_name
@input = input
@options = options
initialize_parameters
end

Expand Down Expand Up @@ -94,7 +97,11 @@ def initialize_parameters

@shard_key_name = @input[:shard_key]
if @shard_key_name.nil?
raise InvalidArgument, "[#{@command_name}] shard_key is missing"
require_shard_key = @options[:require_shard_key]
require_shard_key = true if require_shard_key.nil?
if require_shard_key
raise InvalidArgument, "[#{@command_name}] shard_key is missing"
end
end

@target_range = TargetRange.new(@command_name, @input)
Expand Down
28 changes: 28 additions & 0 deletions plugins/sharding/logical_shard_list.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
module Groonga
module Sharding
class LogicalShardListCommand < Command
register("logical_shard_list",
[
"logical_table",
])

def run_body(input)
enumerator = LogicalEnumerator.new("logical_shard_list",
input,
:require_shard_key => false)
shard_names = enumerator.collect do |current_shard, shard_range|
current_shard.table_name
end

writer.array("shards", shard_names.size) do
shard_names.each do |shard_name|
writer.map("shard", 1) do
writer.write("name")
writer.write(shard_name)
end
end
end
end
end
end
end
1 change: 1 addition & 0 deletions plugins/sharding/sources.am
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ sharding_scripts = \
logical_parameters.rb \
logical_range_filter.rb \
logical_select.rb \
logical_shard_list.rb \
logical_table_remove.rb \
parameters.rb \
range_expression_builder.rb
6 changes: 6 additions & 0 deletions test/command/suite/sharding/logical_shard_list/day.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
register sharding
[[0,0.0,0.0],true]
table_create Logs_20150806 TABLE_NO_KEY
[[0,0.0,0.0],true]
logical_shard_list Logs
[[0,0.0,0.0],[{"name":"Logs_20150806"}]]
7 changes: 7 additions & 0 deletions test/command/suite/sharding/logical_shard_list/day.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#@on-error omit
register sharding
#@on-error default

table_create Logs_20150806 TABLE_NO_KEY

logical_shard_list Logs
47 changes: 47 additions & 0 deletions test/command/suite/sharding/logical_shard_list/days.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
register sharding
[[0,0.0,0.0],true]
table_create Logs_20150201 TABLE_NO_KEY
[[0,0.0,0.0],true]
table_create Logs_20150202 TABLE_NO_KEY
[[0,0.0,0.0],true]
table_create Logs_20150227 TABLE_NO_KEY
[[0,0.0,0.0],true]
table_create Logs_20150301 TABLE_NO_KEY
[[0,0.0,0.0],true]
table_create Logs_20150302 TABLE_NO_KEY
[[0,0.0,0.0],true]
table_create Logs_20150130 TABLE_NO_KEY
[[0,0.0,0.0],true]
table_create Logs_20150131 TABLE_NO_KEY
[[0,0.0,0.0],true]
logical_shard_list Logs
[
[
0,
0.0,
0.0
],
[
{
"name": "Logs_20150130"
},
{
"name": "Logs_20150131"
},
{
"name": "Logs_20150201"
},
{
"name": "Logs_20150202"
},
{
"name": "Logs_20150227"
},
{
"name": "Logs_20150301"
},
{
"name": "Logs_20150302"
}
]
]
13 changes: 13 additions & 0 deletions test/command/suite/sharding/logical_shard_list/days.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#@on-error omit
register sharding
#@on-error default

table_create Logs_20150201 TABLE_NO_KEY
table_create Logs_20150202 TABLE_NO_KEY
table_create Logs_20150227 TABLE_NO_KEY
table_create Logs_20150301 TABLE_NO_KEY
table_create Logs_20150302 TABLE_NO_KEY
table_create Logs_20150130 TABLE_NO_KEY
table_create Logs_20150131 TABLE_NO_KEY

logical_shard_list Logs
6 changes: 6 additions & 0 deletions test/command/suite/sharding/logical_shard_list/month.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
register sharding
[[0,0.0,0.0],true]
table_create Logs_201508 TABLE_NO_KEY
[[0,0.0,0.0],true]
logical_shard_list Logs
[[0,0.0,0.0],[{"name":"Logs_201508"}]]
7 changes: 7 additions & 0 deletions test/command/suite/sharding/logical_shard_list/month.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#@on-error omit
register sharding
#@on-error default

table_create Logs_201508 TABLE_NO_KEY

logical_shard_list Logs
32 changes: 32 additions & 0 deletions test/command/suite/sharding/logical_shard_list/months.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
register sharding
[[0,0.0,0.0],true]
table_create Logs_201501 TABLE_NO_KEY
[[0,0.0,0.0],true]
table_create Logs_201412 TABLE_NO_KEY
[[0,0.0,0.0],true]
table_create Logs_201512 TABLE_NO_KEY
[[0,0.0,0.0],true]
table_create Logs_201401 TABLE_NO_KEY
[[0,0.0,0.0],true]
logical_shard_list Logs
[
[
0,
0.0,
0.0
],
[
{
"name": "Logs_201401"
},
{
"name": "Logs_201412"
},
{
"name": "Logs_201501"
},
{
"name": "Logs_201512"
}
]
]
10 changes: 10 additions & 0 deletions test/command/suite/sharding/logical_shard_list/months.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#@on-error omit
register sharding
#@on-error default

table_create Logs_201501 TABLE_NO_KEY
table_create Logs_201412 TABLE_NO_KEY
table_create Logs_201512 TABLE_NO_KEY
table_create Logs_201401 TABLE_NO_KEY

logical_shard_list Logs
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
register sharding
[[0,0.0,0.0],true]
table_create Logs_201502 TABLE_NO_KEY
[[0,0.0,0.0],true]
table_create Logs_20150227 TABLE_NO_KEY
[[0,0.0,0.0],true]
table_create Logs_20150204 TABLE_NO_KEY
[[0,0.0,0.0],true]
table_create Logs_20150130 TABLE_NO_KEY
[[0,0.0,0.0],true]
table_create Logs_20150203 TABLE_NO_KEY
[[0,0.0,0.0],true]
table_create Logs_20150302 TABLE_NO_KEY
[[0,0.0,0.0],true]
table_create Logs_201503 TABLE_NO_KEY
[[0,0.0,0.0],true]
table_create Logs_20150131 TABLE_NO_KEY
[[0,0.0,0.0],true]
logical_shard_list Logs
[
[
0,
0.0,
0.0
],
[
{
"name": "Logs_20150130"
},
{
"name": "Logs_20150131"
},
{
"name": "Logs_201502"
},
{
"name": "Logs_20150203"
},
{
"name": "Logs_20150204"
},
{
"name": "Logs_20150227"
},
{
"name": "Logs_201503"
},
{
"name": "Logs_20150302"
}
]
]
14 changes: 14 additions & 0 deletions test/command/suite/sharding/logical_shard_list/months_days.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#@on-error omit
register sharding
#@on-error default

table_create Logs_201502 TABLE_NO_KEY
table_create Logs_20150227 TABLE_NO_KEY
table_create Logs_20150204 TABLE_NO_KEY
table_create Logs_20150130 TABLE_NO_KEY
table_create Logs_20150203 TABLE_NO_KEY
table_create Logs_20150302 TABLE_NO_KEY
table_create Logs_201503 TABLE_NO_KEY
table_create Logs_20150131 TABLE_NO_KEY

logical_shard_list Logs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
register sharding
[[0,0.0,0.0],true]
logical_shard_list Logs
[[0,0.0,0.0],[]]
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#@on-error omit
register sharding
#@on-error default

logical_shard_list Logs

0 comments on commit bf3c479

Please sign in to comment.