[Groonga-commit] groonga/groonga at e1d026d [master] logical_select: support drilldown_calc_types and drilldown_calc_target

Back to archive index

Kouhei Sutou null+****@clear*****
Thu Jul 9 15:21:58 JST 2015


Kouhei Sutou	2015-07-09 15:21:58 +0900 (Thu, 09 Jul 2015)

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

  Message:
    logical_select: support drilldown_calc_types and drilldown_calc_target

  Added files:
    test/command/suite/sharding/logical_select/drilldown/plain/calc_types/all.expected
    test/command/suite/sharding/logical_select/drilldown/plain/calc_types/all.test
    test/command/suite/sharding/logical_select/drilldown/plain/calc_types/avg.expected
    test/command/suite/sharding/logical_select/drilldown/plain/calc_types/avg.test
    test/command/suite/sharding/logical_select/drilldown/plain/calc_types/max.expected
    test/command/suite/sharding/logical_select/drilldown/plain/calc_types/max.test
    test/command/suite/sharding/logical_select/drilldown/plain/calc_types/min.expected
    test/command/suite/sharding/logical_select/drilldown/plain/calc_types/min.test
    test/command/suite/sharding/logical_select/drilldown/plain/calc_types/sum.expected
    test/command/suite/sharding/logical_select/drilldown/plain/calc_types/sum.test
  Modified files:
    plugins/sharding/logical_select.rb

  Modified: plugins/sharding/logical_select.rb (+60 -35)
===================================================================
--- plugins/sharding/logical_select.rb    2015-07-09 15:07:46 +0900 (153a52f)
+++ plugins/sharding/logical_select.rb    2015-07-09 15:21:58 +0900 (3261a89)
@@ -19,6 +19,8 @@ module Groonga
                  "drilldown_output_columns",
                  "drilldown_offset",
                  "drilldown_limit",
+                 "drilldown_calc_types",
+                 "drilldown_calc_target",
                ])
 
       def run_body(input)
@@ -167,6 +169,39 @@ module Groonga
         end
       end
 
+      module Calculatable
+        def calc_target(table)
+          return nil if @calc_target_name.nil?
+          table.find_column(@calc_target_name)
+        end
+
+        private
+        def parse_calc_types(raw_types)
+          return TableGroupFlags::CALC_COUNT if raw_types.nil?
+
+          types = 0
+          raw_types.strip.split(/ *, */).each do |name|
+            case name
+            when "COUNT"
+              types |= TableGroupFlags::CALC_COUNT
+            when "MAX"
+              types |= TableGroupFlags::CALC_MAX
+            when "MIN"
+              types |= TableGroupFlags::CALC_MIN
+            when "SUM"
+              types |= TableGroupFlags::CALC_SUM
+            when "AVG"
+              types |= TableGroupFlags::CALC_AVG
+            when "NONE"
+              # Do nothing
+            else
+              raise InvalidArgument, "invalid drilldown calc type: <#{name}>"
+            end
+          end
+          types
+        end
+      end
+
       class ExecuteContext
         include KeysParsable
 
@@ -211,12 +246,15 @@ module Groonga
 
       class PlainDrilldownExecuteContext
         include KeysParsable
+        include Calculatable
 
         attr_reader :keys
         attr_reader :offset
         attr_reader :limit
         attr_reader :sort_keys
         attr_reader :output_columns
+        attr_reader :calc_target_name
+        attr_reader :calc_types
         attr_reader :result_sets
         attr_reader :unsorted_result_sets
         def initialize(input)
@@ -227,6 +265,8 @@ module Groonga
           @sort_keys = parse_keys(@input[:drilldown_sortby])
           @output_columns = @input[:drilldown_output_columns]
           @output_columns ||= "_key, _nsubrecs"
+          @calc_target_name = @input[:drilldown_calc_target]
+          @calc_types = parse_calc_types(@input[:drilldown_calc_types])
 
           @result_sets = []
           @unsorted_result_sets = []
@@ -301,6 +341,7 @@ module Groonga
 
       class LabeledDrilldownExecuteContext
         include KeysParsable
+        include Calculatable
 
         attr_reader :label
         attr_reader :keys
@@ -332,11 +373,6 @@ module Groonga
           @unsorted_result_set.close if @unsored_result_set
         end
 
-        def calc_target(table)
-          return nil if @calc_target_name.nil?
-          table.find_column(@calc_target_name)
-        end
-
         def need_command_version2?
           /[.\[]/ === @output_columns
         end
@@ -358,32 +394,6 @@ module Groonga
           end
           converted_columns.join(",")
         end
-
-        private
-        def parse_calc_types(raw_types)
-          return TableGroupFlags::CALC_COUNT if raw_types.nil?
-
-          types = 0
-          raw_types.strip.split(/ *, */).each do |name|
-            case name
-            when "COUNT"
-              types |= TableGroupFlags::CALC_COUNT
-            when "MAX"
-              types |= TableGroupFlags::CALC_MAX
-            when "MIN"
-              types |= TableGroupFlags::CALC_MIN
-            when "SUM"
-              types |= TableGroupFlags::CALC_SUM
-            when "AVG"
-              types |= TableGroupFlags::CALC_AVG
-            when "NONE"
-              # Do nothing
-            else
-              raise InvalidArgument, "invalid drilldown calc type: <#{name}>"
-            end
-          end
-          types
-        end
       end
 
       class Executor
@@ -433,10 +443,13 @@ module Groonga
             group_result.key_begin = 0
             group_result.key_end = 0
             group_result.limit = 1
-            group_result.flags = TableGroupFlags::CALC_COUNT
+            group_result.flags = drilldown.calc_types
             drilldown.keys.each do |key|
               @context.result_sets.each do |result_set|
-                result_set.group([key], group_result)
+                with_calc_target(group_result,
+                                 drilldown.calc_target(result_set)) do
+                  result_set.group([key], group_result)
+                end
               end
               result_set = group_result.table
               if drilldown.sort_keys.empty?
@@ -467,8 +480,10 @@ module Groonga
               group_result.limit = 1
               group_result.flags = drilldown.calc_types
               @context.result_sets.each do |result_set|
-                group_result.calc_target = drilldown.calc_target(result_set)
-                result_set.group(keys, group_result)
+                with_calc_target(group_result,
+                                 drilldown.calc_target(result_set)) do
+                  result_set.group(keys, group_result)
+                end
               end
               result_set = group_result.table
               if drilldown.sort_keys.empty?
@@ -483,6 +498,16 @@ module Groonga
             end
           end
         end
+
+        def with_calc_target(group_result, calc_target)
+          group_result.calc_target = calc_target
+          begin
+            yield
+          ensure
+            calc_target.close if calc_target
+            group_result.calc_target = nil
+          end
+        end
       end
 
       class ShardExecutor

  Added: test/command/suite/sharding/logical_select/drilldown/plain/calc_types/all.expected (+131 -0) 100644
===================================================================
--- /dev/null
+++ test/command/suite/sharding/logical_select/drilldown/plain/calc_types/all.expected    2015-07-09 15:21:58 +0900 (b1fc5d5)
@@ -0,0 +1,131 @@
+register sharding
+[[0,0.0,0.0],true]
+table_create Tags TABLE_PAT_KEY ShortText
+[[0,0.0,0.0],true]
+table_create Memos_20150709 TABLE_HASH_KEY ShortText
+[[0,0.0,0.0],true]
+column_create Memos_20150709 created_at COLUMN_SCALAR Time
+[[0,0.0,0.0],true]
+column_create Memos_20150709 tag COLUMN_SCALAR Tags
+[[0,0.0,0.0],true]
+column_create Memos_20150709 priority COLUMN_SCALAR Int64
+[[0,0.0,0.0],true]
+table_create Memos_20150710 TABLE_HASH_KEY ShortText
+[[0,0.0,0.0],true]
+column_create Memos_20150710 created_at COLUMN_SCALAR Time
+[[0,0.0,0.0],true]
+column_create Memos_20150710 tag COLUMN_SCALAR Tags
+[[0,0.0,0.0],true]
+column_create Memos_20150710 priority COLUMN_SCALAR Int64
+[[0,0.0,0.0],true]
+load --table Memos_20150709
+[
+{"_key": "Groonga1", "tag": "Groonga", "priority": 10,
+ "created_at": "2015/07/09 00:00:00"},
+{"_key": "Groonga2", "tag": "Groonga", "priority": 20,
+ "created_at": "2015/07/09 01:00:00"},
+{"_key": "Groonga3", "tag": "Groonga", "priority": 60,
+ "created_at": "2015/07/09 02:00:00"},
+{"_key": "Mroonga1", "tag": "Mroonga", "priority": 61,
+ "created_at": "2015/07/09 03:00:00"}
+]
+[[0,0.0,0.0],4]
+load --table Memos_20150710
+[
+{"_key": "Mroonga2", "tag": "Mroonga", "priority": 24,
+ "created_at": "2015/07/10 00:00:00"},
+{"_key": "Mroonga3", "tag": "Mroonga", "priority": 8,
+ "created_at": "2015/07/10 01:00:00"},
+{"_key": "Rroonga1", "tag": "Rroonga", "priority": 3,
+ "created_at": "2015/07/10 02:00:00"},
+{"_key": "Rroonga2", "tag": "Rroonga", "priority": -9,
+ "created_at": "2015/07/10 03:00:00"},
+{"_key": "Rroonga3", "tag": "Rroonga", "priority": 0,
+ "created_at": "2015/07/10 04:00:00"}
+]
+[[0,0.0,0.0],5]
+logical_select Memos   --shard_key created_at   --limit 0   --drilldown tag   --drilldown_calc_types 'MAX, MIN, SUM, AVG'   --drilldown_calc_target priority   --drilldown_output_columns _key,_max,_min,_sum,_avg
+[
+  [
+    0,
+    0.0,
+    0.0
+  ],
+  [
+    [
+      [
+        9
+      ],
+      [
+        [
+          "_id",
+          "UInt32"
+        ],
+        [
+          "_key",
+          "ShortText"
+        ],
+        [
+          "created_at",
+          "Time"
+        ],
+        [
+          "priority",
+          "Int64"
+        ],
+        [
+          "tag",
+          "Tags"
+        ]
+      ]
+    ],
+    [
+      [
+        3
+      ],
+      [
+        [
+          "_key",
+          "ShortText"
+        ],
+        [
+          "_max",
+          "Int64"
+        ],
+        [
+          "_min",
+          "Int64"
+        ],
+        [
+          "_sum",
+          "Int64"
+        ],
+        [
+          "_avg",
+          "Float"
+        ]
+      ],
+      [
+        "Groonga",
+        60,
+        10,
+        90,
+        30.0
+      ],
+      [
+        "Mroonga",
+        61,
+        8,
+        93,
+        31.0
+      ],
+      [
+        "Rroonga",
+        3,
+        -9,
+        -6,
+        -2.0
+      ]
+    ]
+  ]
+]

  Added: test/command/suite/sharding/logical_select/drilldown/plain/calc_types/all.test (+49 -0) 100644
===================================================================
--- /dev/null
+++ test/command/suite/sharding/logical_select/drilldown/plain/calc_types/all.test    2015-07-09 15:21:58 +0900 (8e324dc)
@@ -0,0 +1,49 @@
+#@on-error omit
+register sharding
+#@on-error default
+
+table_create Tags TABLE_PAT_KEY ShortText
+
+table_create Memos_20150709 TABLE_HASH_KEY ShortText
+column_create Memos_20150709 created_at COLUMN_SCALAR Time
+column_create Memos_20150709 tag COLUMN_SCALAR Tags
+column_create Memos_20150709 priority COLUMN_SCALAR Int64
+
+table_create Memos_20150710 TABLE_HASH_KEY ShortText
+column_create Memos_20150710 created_at COLUMN_SCALAR Time
+column_create Memos_20150710 tag COLUMN_SCALAR Tags
+column_create Memos_20150710 priority COLUMN_SCALAR Int64
+
+load --table Memos_20150709
+[
+{"_key": "Groonga1", "tag": "Groonga", "priority": 10,
+ "created_at": "2015/07/09 00:00:00"},
+{"_key": "Groonga2", "tag": "Groonga", "priority": 20,
+ "created_at": "2015/07/09 01:00:00"},
+{"_key": "Groonga3", "tag": "Groonga", "priority": 60,
+ "created_at": "2015/07/09 02:00:00"},
+{"_key": "Mroonga1", "tag": "Mroonga", "priority": 61,
+ "created_at": "2015/07/09 03:00:00"}
+]
+
+load --table Memos_20150710
+[
+{"_key": "Mroonga2", "tag": "Mroonga", "priority": 24,
+ "created_at": "2015/07/10 00:00:00"},
+{"_key": "Mroonga3", "tag": "Mroonga", "priority": 8,
+ "created_at": "2015/07/10 01:00:00"},
+{"_key": "Rroonga1", "tag": "Rroonga", "priority": 3,
+ "created_at": "2015/07/10 02:00:00"},
+{"_key": "Rroonga2", "tag": "Rroonga", "priority": -9,
+ "created_at": "2015/07/10 03:00:00"},
+{"_key": "Rroonga3", "tag": "Rroonga", "priority": 0,
+ "created_at": "2015/07/10 04:00:00"}
+]
+
+logical_select Memos \
+  --shard_key created_at \
+  --limit 0 \
+  --drilldown tag \
+  --drilldown_calc_types 'MAX, MIN, SUM, AVG' \
+  --drilldown_calc_target priority \
+  --drilldown_output_columns _key,_max,_min,_sum,_avg

  Added: test/command/suite/sharding/logical_select/drilldown/plain/calc_types/avg.expected (+110 -0) 100644
===================================================================
--- /dev/null
+++ test/command/suite/sharding/logical_select/drilldown/plain/calc_types/avg.expected    2015-07-09 15:21:58 +0900 (e43ba83)
@@ -0,0 +1,110 @@
+register sharding
+[[0,0.0,0.0],true]
+table_create Tags TABLE_PAT_KEY ShortText
+[[0,0.0,0.0],true]
+table_create Memos_20150709 TABLE_HASH_KEY ShortText
+[[0,0.0,0.0],true]
+column_create Memos_20150709 created_at COLUMN_SCALAR Time
+[[0,0.0,0.0],true]
+column_create Memos_20150709 tag COLUMN_SCALAR Tags
+[[0,0.0,0.0],true]
+column_create Memos_20150709 priority COLUMN_SCALAR Int64
+[[0,0.0,0.0],true]
+table_create Memos_20150710 TABLE_HASH_KEY ShortText
+[[0,0.0,0.0],true]
+column_create Memos_20150710 created_at COLUMN_SCALAR Time
+[[0,0.0,0.0],true]
+column_create Memos_20150710 tag COLUMN_SCALAR Tags
+[[0,0.0,0.0],true]
+column_create Memos_20150710 priority COLUMN_SCALAR Int64
+[[0,0.0,0.0],true]
+load --table Memos_20150709
+[
+{"_key": "Groonga1", "tag": "Groonga", "priority": 10,
+ "created_at": "2015/07/09 00:00:00"},
+{"_key": "Groonga2", "tag": "Groonga", "priority": 20,
+ "created_at": "2015/07/09 01:00:00"},
+{"_key": "Groonga3", "tag": "Groonga", "priority": 60,
+ "created_at": "2015/07/09 02:00:00"},
+{"_key": "Mroonga1", "tag": "Mroonga", "priority": 61,
+ "created_at": "2015/07/09 03:00:00"}
+]
+[[0,0.0,0.0],4]
+load --table Memos_20150710
+[
+{"_key": "Mroonga2", "tag": "Mroonga", "priority": 24,
+ "created_at": "2015/07/10 00:00:00"},
+{"_key": "Mroonga3", "tag": "Mroonga", "priority": 8,
+ "created_at": "2015/07/10 01:00:00"},
+{"_key": "Rroonga1", "tag": "Rroonga", "priority": 3,
+ "created_at": "2015/07/10 02:00:00"},
+{"_key": "Rroonga2", "tag": "Rroonga", "priority": -9,
+ "created_at": "2015/07/10 03:00:00"},
+{"_key": "Rroonga3", "tag": "Rroonga", "priority": 0,
+ "created_at": "2015/07/10 04:00:00"}
+]
+[[0,0.0,0.0],5]
+logical_select Memos   --shard_key created_at   --limit 0   --drilldown tag   --drilldown_calc_types AVG   --drilldown_calc_target priority   --drilldown_output_columns _key,_avg
+[
+  [
+    0,
+    0.0,
+    0.0
+  ],
+  [
+    [
+      [
+        9
+      ],
+      [
+        [
+          "_id",
+          "UInt32"
+        ],
+        [
+          "_key",
+          "ShortText"
+        ],
+        [
+          "created_at",
+          "Time"
+        ],
+        [
+          "priority",
+          "Int64"
+        ],
+        [
+          "tag",
+          "Tags"
+        ]
+      ]
+    ],
+    [
+      [
+        3
+      ],
+      [
+        [
+          "_key",
+          "ShortText"
+        ],
+        [
+          "_avg",
+          "Float"
+        ]
+      ],
+      [
+        "Groonga",
+        30.0
+      ],
+      [
+        "Mroonga",
+        31.0
+      ],
+      [
+        "Rroonga",
+        -2.0
+      ]
+    ]
+  ]
+]

  Added: test/command/suite/sharding/logical_select/drilldown/plain/calc_types/avg.test (+50 -0) 100644
===================================================================
--- /dev/null
+++ test/command/suite/sharding/logical_select/drilldown/plain/calc_types/avg.test    2015-07-09 15:21:58 +0900 (7e22e93)
@@ -0,0 +1,50 @@
+#@on-error omit
+register sharding
+#@on-error default
+
+table_create Tags TABLE_PAT_KEY ShortText
+
+table_create Memos_20150709 TABLE_HASH_KEY ShortText
+column_create Memos_20150709 created_at COLUMN_SCALAR Time
+column_create Memos_20150709 tag COLUMN_SCALAR Tags
+column_create Memos_20150709 priority COLUMN_SCALAR Int64
+
+table_create Memos_20150710 TABLE_HASH_KEY ShortText
+column_create Memos_20150710 created_at COLUMN_SCALAR Time
+column_create Memos_20150710 tag COLUMN_SCALAR Tags
+column_create Memos_20150710 priority COLUMN_SCALAR Int64
+
+load --table Memos_20150709
+[
+{"_key": "Groonga1", "tag": "Groonga", "priority": 10,
+ "created_at": "2015/07/09 00:00:00"},
+{"_key": "Groonga2", "tag": "Groonga", "priority": 20,
+ "created_at": "2015/07/09 01:00:00"},
+{"_key": "Groonga3", "tag": "Groonga", "priority": 60,
+ "created_at": "2015/07/09 02:00:00"},
+{"_key": "Mroonga1", "tag": "Mroonga", "priority": 61,
+ "created_at": "2015/07/09 03:00:00"}
+]
+
+load --table Memos_20150710
+[
+{"_key": "Mroonga2", "tag": "Mroonga", "priority": 24,
+ "created_at": "2015/07/10 00:00:00"},
+{"_key": "Mroonga3", "tag": "Mroonga", "priority": 8,
+ "created_at": "2015/07/10 01:00:00"},
+{"_key": "Rroonga1", "tag": "Rroonga", "priority": 3,
+ "created_at": "2015/07/10 02:00:00"},
+{"_key": "Rroonga2", "tag": "Rroonga", "priority": -9,
+ "created_at": "2015/07/10 03:00:00"},
+{"_key": "Rroonga3", "tag": "Rroonga", "priority": 0,
+ "created_at": "2015/07/10 04:00:00"}
+]
+
+logical_select Memos \
+  --shard_key created_at \
+  --limit 0 \
+  --drilldown tag \
+  --drilldown_calc_types AVG \
+  --drilldown_calc_target priority \
+  --drilldown_output_columns _key,_avg
+

  Added: test/command/suite/sharding/logical_select/drilldown/plain/calc_types/max.expected (+110 -0) 100644
===================================================================
--- /dev/null
+++ test/command/suite/sharding/logical_select/drilldown/plain/calc_types/max.expected    2015-07-09 15:21:58 +0900 (20e24d4)
@@ -0,0 +1,110 @@
+register sharding
+[[0,0.0,0.0],true]
+table_create Tags TABLE_PAT_KEY ShortText
+[[0,0.0,0.0],true]
+table_create Memos_20150709 TABLE_HASH_KEY ShortText
+[[0,0.0,0.0],true]
+column_create Memos_20150709 created_at COLUMN_SCALAR Time
+[[0,0.0,0.0],true]
+column_create Memos_20150709 tag COLUMN_SCALAR Tags
+[[0,0.0,0.0],true]
+column_create Memos_20150709 priority COLUMN_SCALAR Int64
+[[0,0.0,0.0],true]
+table_create Memos_20150710 TABLE_HASH_KEY ShortText
+[[0,0.0,0.0],true]
+column_create Memos_20150710 created_at COLUMN_SCALAR Time
+[[0,0.0,0.0],true]
+column_create Memos_20150710 tag COLUMN_SCALAR Tags
+[[0,0.0,0.0],true]
+column_create Memos_20150710 priority COLUMN_SCALAR Int64
+[[0,0.0,0.0],true]
+load --table Memos_20150709
+[
+{"_key": "Groonga1", "tag": "Groonga", "priority": 10,
+ "created_at": "2015/07/09 00:00:00"},
+{"_key": "Groonga2", "tag": "Groonga", "priority": 20,
+ "created_at": "2015/07/09 01:00:00"},
+{"_key": "Groonga3", "tag": "Groonga", "priority": 60,
+ "created_at": "2015/07/09 02:00:00"},
+{"_key": "Mroonga1", "tag": "Mroonga", "priority": 61,
+ "created_at": "2015/07/09 03:00:00"}
+]
+[[0,0.0,0.0],4]
+load --table Memos_20150710
+[
+{"_key": "Mroonga2", "tag": "Mroonga", "priority": 24,
+ "created_at": "2015/07/10 00:00:00"},
+{"_key": "Mroonga3", "tag": "Mroonga", "priority": 8,
+ "created_at": "2015/07/10 01:00:00"},
+{"_key": "Rroonga1", "tag": "Rroonga", "priority": 3,
+ "created_at": "2015/07/10 02:00:00"},
+{"_key": "Rroonga2", "tag": "Rroonga", "priority": -9,
+ "created_at": "2015/07/10 03:00:00"},
+{"_key": "Rroonga3", "tag": "Rroonga", "priority": 0,
+ "created_at": "2015/07/10 04:00:00"}
+]
+[[0,0.0,0.0],5]
+logical_select Memos   --shard_key created_at   --limit 0   --drilldown tag   --drilldown_calc_types MAX   --drilldown_calc_target priority   --drilldown_output_columns _key,_max
+[
+  [
+    0,
+    0.0,
+    0.0
+  ],
+  [
+    [
+      [
+        9
+      ],
+      [
+        [
+          "_id",
+          "UInt32"
+        ],
+        [
+          "_key",
+          "ShortText"
+        ],
+        [
+          "created_at",
+          "Time"
+        ],
+        [
+          "priority",
+          "Int64"
+        ],
+        [
+          "tag",
+          "Tags"
+        ]
+      ]
+    ],
+    [
+      [
+        3
+      ],
+      [
+        [
+          "_key",
+          "ShortText"
+        ],
+        [
+          "_max",
+          "Int64"
+        ]
+      ],
+      [
+        "Groonga",
+        60
+      ],
+      [
+        "Mroonga",
+        61
+      ],
+      [
+        "Rroonga",
+        3
+      ]
+    ]
+  ]
+]

  Added: test/command/suite/sharding/logical_select/drilldown/plain/calc_types/max.test (+49 -0) 100644
===================================================================
--- /dev/null
+++ test/command/suite/sharding/logical_select/drilldown/plain/calc_types/max.test    2015-07-09 15:21:58 +0900 (21c10e6)
@@ -0,0 +1,49 @@
+#@on-error omit
+register sharding
+#@on-error default
+
+table_create Tags TABLE_PAT_KEY ShortText
+
+table_create Memos_20150709 TABLE_HASH_KEY ShortText
+column_create Memos_20150709 created_at COLUMN_SCALAR Time
+column_create Memos_20150709 tag COLUMN_SCALAR Tags
+column_create Memos_20150709 priority COLUMN_SCALAR Int64
+
+table_create Memos_20150710 TABLE_HASH_KEY ShortText
+column_create Memos_20150710 created_at COLUMN_SCALAR Time
+column_create Memos_20150710 tag COLUMN_SCALAR Tags
+column_create Memos_20150710 priority COLUMN_SCALAR Int64
+
+load --table Memos_20150709
+[
+{"_key": "Groonga1", "tag": "Groonga", "priority": 10,
+ "created_at": "2015/07/09 00:00:00"},
+{"_key": "Groonga2", "tag": "Groonga", "priority": 20,
+ "created_at": "2015/07/09 01:00:00"},
+{"_key": "Groonga3", "tag": "Groonga", "priority": 60,
+ "created_at": "2015/07/09 02:00:00"},
+{"_key": "Mroonga1", "tag": "Mroonga", "priority": 61,
+ "created_at": "2015/07/09 03:00:00"}
+]
+
+load --table Memos_20150710
+[
+{"_key": "Mroonga2", "tag": "Mroonga", "priority": 24,
+ "created_at": "2015/07/10 00:00:00"},
+{"_key": "Mroonga3", "tag": "Mroonga", "priority": 8,
+ "created_at": "2015/07/10 01:00:00"},
+{"_key": "Rroonga1", "tag": "Rroonga", "priority": 3,
+ "created_at": "2015/07/10 02:00:00"},
+{"_key": "Rroonga2", "tag": "Rroonga", "priority": -9,
+ "created_at": "2015/07/10 03:00:00"},
+{"_key": "Rroonga3", "tag": "Rroonga", "priority": 0,
+ "created_at": "2015/07/10 04:00:00"}
+]
+
+logical_select Memos \
+  --shard_key created_at \
+  --limit 0 \
+  --drilldown tag \
+  --drilldown_calc_types MAX \
+  --drilldown_calc_target priority \
+  --drilldown_output_columns _key,_max

  Added: test/command/suite/sharding/logical_select/drilldown/plain/calc_types/min.expected (+110 -0) 100644
===================================================================
--- /dev/null
+++ test/command/suite/sharding/logical_select/drilldown/plain/calc_types/min.expected    2015-07-09 15:21:58 +0900 (a07e666)
@@ -0,0 +1,110 @@
+register sharding
+[[0,0.0,0.0],true]
+table_create Tags TABLE_PAT_KEY ShortText
+[[0,0.0,0.0],true]
+table_create Memos_20150709 TABLE_HASH_KEY ShortText
+[[0,0.0,0.0],true]
+column_create Memos_20150709 created_at COLUMN_SCALAR Time
+[[0,0.0,0.0],true]
+column_create Memos_20150709 tag COLUMN_SCALAR Tags
+[[0,0.0,0.0],true]
+column_create Memos_20150709 priority COLUMN_SCALAR Int64
+[[0,0.0,0.0],true]
+table_create Memos_20150710 TABLE_HASH_KEY ShortText
+[[0,0.0,0.0],true]
+column_create Memos_20150710 created_at COLUMN_SCALAR Time
+[[0,0.0,0.0],true]
+column_create Memos_20150710 tag COLUMN_SCALAR Tags
+[[0,0.0,0.0],true]
+column_create Memos_20150710 priority COLUMN_SCALAR Int64
+[[0,0.0,0.0],true]
+load --table Memos_20150709
+[
+{"_key": "Groonga1", "tag": "Groonga", "priority": 10,
+ "created_at": "2015/07/09 00:00:00"},
+{"_key": "Groonga2", "tag": "Groonga", "priority": 20,
+ "created_at": "2015/07/09 01:00:00"},
+{"_key": "Groonga3", "tag": "Groonga", "priority": 60,
+ "created_at": "2015/07/09 02:00:00"},
+{"_key": "Mroonga1", "tag": "Mroonga", "priority": 61,
+ "created_at": "2015/07/09 03:00:00"}
+]
+[[0,0.0,0.0],4]
+load --table Memos_20150710
+[
+{"_key": "Mroonga2", "tag": "Mroonga", "priority": 24,
+ "created_at": "2015/07/10 00:00:00"},
+{"_key": "Mroonga3", "tag": "Mroonga", "priority": 8,
+ "created_at": "2015/07/10 01:00:00"},
+{"_key": "Rroonga1", "tag": "Rroonga", "priority": 3,
+ "created_at": "2015/07/10 02:00:00"},
+{"_key": "Rroonga2", "tag": "Rroonga", "priority": -9,
+ "created_at": "2015/07/10 03:00:00"},
+{"_key": "Rroonga3", "tag": "Rroonga", "priority": 0,
+ "created_at": "2015/07/10 04:00:00"}
+]
+[[0,0.0,0.0],5]
+logical_select Memos   --shard_key created_at   --limit 0   --drilldown tag   --drilldown_calc_types MIN   --drilldown_calc_target priority   --drilldown_output_columns _key,_min
+[
+  [
+    0,
+    0.0,
+    0.0
+  ],
+  [
+    [
+      [
+        9
+      ],
+      [
+        [
+          "_id",
+          "UInt32"
+        ],
+        [
+          "_key",
+          "ShortText"
+        ],
+        [
+          "created_at",
+          "Time"
+        ],
+        [
+          "priority",
+          "Int64"
+        ],
+        [
+          "tag",
+          "Tags"
+        ]
+      ]
+    ],
+    [
+      [
+        3
+      ],
+      [
+        [
+          "_key",
+          "ShortText"
+        ],
+        [
+          "_min",
+          "Int64"
+        ]
+      ],
+      [
+        "Groonga",
+        10
+      ],
+      [
+        "Mroonga",
+        8
+      ],
+      [
+        "Rroonga",
+        -9
+      ]
+    ]
+  ]
+]

  Added: test/command/suite/sharding/logical_select/drilldown/plain/calc_types/min.test (+49 -0) 100644
===================================================================
--- /dev/null
+++ test/command/suite/sharding/logical_select/drilldown/plain/calc_types/min.test    2015-07-09 15:21:58 +0900 (6935bff)
@@ -0,0 +1,49 @@
+#@on-error omit
+register sharding
+#@on-error default
+
+table_create Tags TABLE_PAT_KEY ShortText
+
+table_create Memos_20150709 TABLE_HASH_KEY ShortText
+column_create Memos_20150709 created_at COLUMN_SCALAR Time
+column_create Memos_20150709 tag COLUMN_SCALAR Tags
+column_create Memos_20150709 priority COLUMN_SCALAR Int64
+
+table_create Memos_20150710 TABLE_HASH_KEY ShortText
+column_create Memos_20150710 created_at COLUMN_SCALAR Time
+column_create Memos_20150710 tag COLUMN_SCALAR Tags
+column_create Memos_20150710 priority COLUMN_SCALAR Int64
+
+load --table Memos_20150709
+[
+{"_key": "Groonga1", "tag": "Groonga", "priority": 10,
+ "created_at": "2015/07/09 00:00:00"},
+{"_key": "Groonga2", "tag": "Groonga", "priority": 20,
+ "created_at": "2015/07/09 01:00:00"},
+{"_key": "Groonga3", "tag": "Groonga", "priority": 60,
+ "created_at": "2015/07/09 02:00:00"},
+{"_key": "Mroonga1", "tag": "Mroonga", "priority": 61,
+ "created_at": "2015/07/09 03:00:00"}
+]
+
+load --table Memos_20150710
+[
+{"_key": "Mroonga2", "tag": "Mroonga", "priority": 24,
+ "created_at": "2015/07/10 00:00:00"},
+{"_key": "Mroonga3", "tag": "Mroonga", "priority": 8,
+ "created_at": "2015/07/10 01:00:00"},
+{"_key": "Rroonga1", "tag": "Rroonga", "priority": 3,
+ "created_at": "2015/07/10 02:00:00"},
+{"_key": "Rroonga2", "tag": "Rroonga", "priority": -9,
+ "created_at": "2015/07/10 03:00:00"},
+{"_key": "Rroonga3", "tag": "Rroonga", "priority": 0,
+ "created_at": "2015/07/10 04:00:00"}
+]
+
+logical_select Memos \
+  --shard_key created_at \
+  --limit 0 \
+  --drilldown tag \
+  --drilldown_calc_types MIN \
+  --drilldown_calc_target priority \
+  --drilldown_output_columns _key,_min

  Added: test/command/suite/sharding/logical_select/drilldown/plain/calc_types/sum.expected (+110 -0) 100644
===================================================================
--- /dev/null
+++ test/command/suite/sharding/logical_select/drilldown/plain/calc_types/sum.expected    2015-07-09 15:21:58 +0900 (45b78cd)
@@ -0,0 +1,110 @@
+register sharding
+[[0,0.0,0.0],true]
+table_create Tags TABLE_PAT_KEY ShortText
+[[0,0.0,0.0],true]
+table_create Memos_20150709 TABLE_HASH_KEY ShortText
+[[0,0.0,0.0],true]
+column_create Memos_20150709 created_at COLUMN_SCALAR Time
+[[0,0.0,0.0],true]
+column_create Memos_20150709 tag COLUMN_SCALAR Tags
+[[0,0.0,0.0],true]
+column_create Memos_20150709 priority COLUMN_SCALAR Int64
+[[0,0.0,0.0],true]
+table_create Memos_20150710 TABLE_HASH_KEY ShortText
+[[0,0.0,0.0],true]
+column_create Memos_20150710 created_at COLUMN_SCALAR Time
+[[0,0.0,0.0],true]
+column_create Memos_20150710 tag COLUMN_SCALAR Tags
+[[0,0.0,0.0],true]
+column_create Memos_20150710 priority COLUMN_SCALAR Int64
+[[0,0.0,0.0],true]
+load --table Memos_20150709
+[
+{"_key": "Groonga1", "tag": "Groonga", "priority": 10,
+ "created_at": "2015/07/09 00:00:00"},
+{"_key": "Groonga2", "tag": "Groonga", "priority": 20,
+ "created_at": "2015/07/09 01:00:00"},
+{"_key": "Groonga3", "tag": "Groonga", "priority": 60,
+ "created_at": "2015/07/09 02:00:00"},
+{"_key": "Mroonga1", "tag": "Mroonga", "priority": 61,
+ "created_at": "2015/07/09 03:00:00"}
+]
+[[0,0.0,0.0],4]
+load --table Memos_20150710
+[
+{"_key": "Mroonga2", "tag": "Mroonga", "priority": 24,
+ "created_at": "2015/07/10 00:00:00"},
+{"_key": "Mroonga3", "tag": "Mroonga", "priority": 8,
+ "created_at": "2015/07/10 01:00:00"},
+{"_key": "Rroonga1", "tag": "Rroonga", "priority": 3,
+ "created_at": "2015/07/10 02:00:00"},
+{"_key": "Rroonga2", "tag": "Rroonga", "priority": -9,
+ "created_at": "2015/07/10 03:00:00"},
+{"_key": "Rroonga3", "tag": "Rroonga", "priority": 0,
+ "created_at": "2015/07/10 04:00:00"}
+]
+[[0,0.0,0.0],5]
+logical_select Memos   --shard_key created_at   --limit 0   --drilldown tag   --drilldown_calc_types SUM   --drilldown_calc_target priority   --drilldown_output_columns _key,_sum
+[
+  [
+    0,
+    0.0,
+    0.0
+  ],
+  [
+    [
+      [
+        9
+      ],
+      [
+        [
+          "_id",
+          "UInt32"
+        ],
+        [
+          "_key",
+          "ShortText"
+        ],
+        [
+          "created_at",
+          "Time"
+        ],
+        [
+          "priority",
+          "Int64"
+        ],
+        [
+          "tag",
+          "Tags"
+        ]
+      ]
+    ],
+    [
+      [
+        3
+      ],
+      [
+        [
+          "_key",
+          "ShortText"
+        ],
+        [
+          "_sum",
+          "Int64"
+        ]
+      ],
+      [
+        "Groonga",
+        90
+      ],
+      [
+        "Mroonga",
+        93
+      ],
+      [
+        "Rroonga",
+        -6
+      ]
+    ]
+  ]
+]

  Added: test/command/suite/sharding/logical_select/drilldown/plain/calc_types/sum.test (+49 -0) 100644
===================================================================
--- /dev/null
+++ test/command/suite/sharding/logical_select/drilldown/plain/calc_types/sum.test    2015-07-09 15:21:58 +0900 (600d456)
@@ -0,0 +1,49 @@
+#@on-error omit
+register sharding
+#@on-error default
+
+table_create Tags TABLE_PAT_KEY ShortText
+
+table_create Memos_20150709 TABLE_HASH_KEY ShortText
+column_create Memos_20150709 created_at COLUMN_SCALAR Time
+column_create Memos_20150709 tag COLUMN_SCALAR Tags
+column_create Memos_20150709 priority COLUMN_SCALAR Int64
+
+table_create Memos_20150710 TABLE_HASH_KEY ShortText
+column_create Memos_20150710 created_at COLUMN_SCALAR Time
+column_create Memos_20150710 tag COLUMN_SCALAR Tags
+column_create Memos_20150710 priority COLUMN_SCALAR Int64
+
+load --table Memos_20150709
+[
+{"_key": "Groonga1", "tag": "Groonga", "priority": 10,
+ "created_at": "2015/07/09 00:00:00"},
+{"_key": "Groonga2", "tag": "Groonga", "priority": 20,
+ "created_at": "2015/07/09 01:00:00"},
+{"_key": "Groonga3", "tag": "Groonga", "priority": 60,
+ "created_at": "2015/07/09 02:00:00"},
+{"_key": "Mroonga1", "tag": "Mroonga", "priority": 61,
+ "created_at": "2015/07/09 03:00:00"}
+]
+
+load --table Memos_20150710
+[
+{"_key": "Mroonga2", "tag": "Mroonga", "priority": 24,
+ "created_at": "2015/07/10 00:00:00"},
+{"_key": "Mroonga3", "tag": "Mroonga", "priority": 8,
+ "created_at": "2015/07/10 01:00:00"},
+{"_key": "Rroonga1", "tag": "Rroonga", "priority": 3,
+ "created_at": "2015/07/10 02:00:00"},
+{"_key": "Rroonga2", "tag": "Rroonga", "priority": -9,
+ "created_at": "2015/07/10 03:00:00"},
+{"_key": "Rroonga3", "tag": "Rroonga", "priority": 0,
+ "created_at": "2015/07/10 04:00:00"}
+]
+
+logical_select Memos \
+  --shard_key created_at \
+  --limit 0 \
+  --drilldown tag \
+  --drilldown_calc_types SUM \
+  --drilldown_calc_target priority \
+  --drilldown_output_columns _key,_sum
-------------- next part --------------
HTML����������������������������...
Download 



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