[Groonga-commit] groonga/groonga at bf3c479 [master] logical_shard_list: add

Back to archive index

Kouhei Sutou null+****@clear*****
Thu Aug 6 17:49:29 JST 2015


Kouhei Sutou	2015-08-06 17:49:29 +0900 (Thu, 06 Aug 2015)

  New Revision: bf3c4795008100e0421e3472a183570d7ee9fd91
  https://github.com/groonga/groonga/commit/bf3c4795008100e0421e3472a183570d7ee9fd91

  Message:
    logical_shard_list: add
    
    TODO:
    
      * Documentation.

  Added files:
    plugins/sharding/logical_shard_list.rb
    test/command/suite/sharding/logical_shard_list/day.expected
    test/command/suite/sharding/logical_shard_list/day.test
    test/command/suite/sharding/logical_shard_list/days.expected
    test/command/suite/sharding/logical_shard_list/days.test
    test/command/suite/sharding/logical_shard_list/month.expected
    test/command/suite/sharding/logical_shard_list/month.test
    test/command/suite/sharding/logical_shard_list/months.expected
    test/command/suite/sharding/logical_shard_list/months.test
    test/command/suite/sharding/logical_shard_list/months_days.expected
    test/command/suite/sharding/logical_shard_list/months_days.test
    test/command/suite/sharding/logical_shard_list/nonexistent.expected
    test/command/suite/sharding/logical_shard_list/nonexistent.test
  Modified files:
    plugins/sharding.rb
    plugins/sharding/logical_enumerator.rb
    plugins/sharding/sources.am

  Modified: plugins/sharding.rb (+1 -0)
===================================================================
--- plugins/sharding.rb    2015-08-06 16:54:28 +0900 (078d4d7)
+++ plugins/sharding.rb    2015-08-06 17:49:29 +0900 (86401c1)
@@ -7,4 +7,5 @@ require "sharding/logical_parameters"
 require "sharding/logical_count"
 require "sharding/logical_range_filter"
 require "sharding/logical_select"
+require "sharding/logical_shard_list"
 require "sharding/logical_table_remove"

  Modified: plugins/sharding/logical_enumerator.rb (+9 -2)
===================================================================
--- plugins/sharding/logical_enumerator.rb    2015-08-06 16:54:28 +0900 (c34b1a6)
+++ plugins/sharding/logical_enumerator.rb    2015-08-06 17:49:29 +0900 (d08bfaa)
@@ -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
 
@@ -94,7 +97,11 @@ module Groonga
 
         @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)

  Added: plugins/sharding/logical_shard_list.rb (+28 -0) 100644
===================================================================
--- /dev/null
+++ plugins/sharding/logical_shard_list.rb    2015-08-06 17:49:29 +0900 (b8ef3f7)
@@ -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

  Modified: plugins/sharding/sources.am (+1 -0)
===================================================================
--- plugins/sharding/sources.am    2015-08-06 16:54:28 +0900 (a77e295)
+++ plugins/sharding/sources.am    2015-08-06 17:49:29 +0900 (df2b6d0)
@@ -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

  Added: test/command/suite/sharding/logical_shard_list/day.expected (+6 -0) 100644
===================================================================
--- /dev/null
+++ test/command/suite/sharding/logical_shard_list/day.expected    2015-08-06 17:49:29 +0900 (0b9a463)
@@ -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"}]]

  Added: test/command/suite/sharding/logical_shard_list/day.test (+7 -0) 100644
===================================================================
--- /dev/null
+++ test/command/suite/sharding/logical_shard_list/day.test    2015-08-06 17:49:29 +0900 (a5fdd91)
@@ -0,0 +1,7 @@
+#@on-error omit
+register sharding
+#@on-error default
+
+table_create Logs_20150806 TABLE_NO_KEY
+
+logical_shard_list Logs

  Added: test/command/suite/sharding/logical_shard_list/days.expected (+47 -0) 100644
===================================================================
--- /dev/null
+++ test/command/suite/sharding/logical_shard_list/days.expected    2015-08-06 17:49:29 +0900 (bca69cc)
@@ -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"
+    }
+  ]
+]

  Added: test/command/suite/sharding/logical_shard_list/days.test (+13 -0) 100644
===================================================================
--- /dev/null
+++ test/command/suite/sharding/logical_shard_list/days.test    2015-08-06 17:49:29 +0900 (375831d)
@@ -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

  Added: test/command/suite/sharding/logical_shard_list/month.expected (+6 -0) 100644
===================================================================
--- /dev/null
+++ test/command/suite/sharding/logical_shard_list/month.expected    2015-08-06 17:49:29 +0900 (d9962de)
@@ -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"}]]

  Added: test/command/suite/sharding/logical_shard_list/month.test (+7 -0) 100644
===================================================================
--- /dev/null
+++ test/command/suite/sharding/logical_shard_list/month.test    2015-08-06 17:49:29 +0900 (a0f21bd)
@@ -0,0 +1,7 @@
+#@on-error omit
+register sharding
+#@on-error default
+
+table_create Logs_201508 TABLE_NO_KEY
+
+logical_shard_list Logs

  Added: test/command/suite/sharding/logical_shard_list/months.expected (+32 -0) 100644
===================================================================
--- /dev/null
+++ test/command/suite/sharding/logical_shard_list/months.expected    2015-08-06 17:49:29 +0900 (13d9d90)
@@ -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"
+    }
+  ]
+]

  Added: test/command/suite/sharding/logical_shard_list/months.test (+10 -0) 100644
===================================================================
--- /dev/null
+++ test/command/suite/sharding/logical_shard_list/months.test    2015-08-06 17:49:29 +0900 (1e7501d)
@@ -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

  Added: test/command/suite/sharding/logical_shard_list/months_days.expected (+52 -0) 100644
===================================================================
--- /dev/null
+++ test/command/suite/sharding/logical_shard_list/months_days.expected    2015-08-06 17:49:29 +0900 (90cfade)
@@ -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"
+    }
+  ]
+]

  Added: test/command/suite/sharding/logical_shard_list/months_days.test (+14 -0) 100644
===================================================================
--- /dev/null
+++ test/command/suite/sharding/logical_shard_list/months_days.test    2015-08-06 17:49:29 +0900 (1590db4)
@@ -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

  Added: test/command/suite/sharding/logical_shard_list/nonexistent.expected (+4 -0) 100644
===================================================================
--- /dev/null
+++ test/command/suite/sharding/logical_shard_list/nonexistent.expected    2015-08-06 17:49:29 +0900 (fa1d8a9)
@@ -0,0 +1,4 @@
+register sharding
+[[0,0.0,0.0],true]
+logical_shard_list Logs
+[[0,0.0,0.0],[]]

  Added: test/command/suite/sharding/logical_shard_list/nonexistent.test (+5 -0) 100644
===================================================================
--- /dev/null
+++ test/command/suite/sharding/logical_shard_list/nonexistent.test    2015-08-06 17:49:29 +0900 (901b06d)
@@ -0,0 +1,5 @@
+#@on-error omit
+register sharding
+#@on-error default
+
+logical_shard_list Logs
-------------- next part --------------
HTML����������������������������...
Download 



More information about the Groonga-commit mailing list
Back to archive index