[Groonga-commit] groonga/groonga at 983afbc [master] logical_select: support "initial" stage dynamic column in labeled drilldown

Back to archive index

Kouhei Sutou null+****@clear*****
Tue Mar 21 15:11:43 JST 2017


Kouhei Sutou	2017-03-21 15:11:43 +0900 (Tue, 21 Mar 2017)

  New Revision: 983afbccc77871e3300b2a826da0b321ebb73756
  https://github.com/groonga/groonga/commit/983afbccc77871e3300b2a826da0b321ebb73756

  Message:
    logical_select: support "initial" stage dynamic column in labeled drilldown

  Added files:
    test/command/suite/sharding/logical_select/drilldowns/columns/stage/initial/output_columns.expected
    test/command/suite/sharding/logical_select/drilldowns/columns/stage/initial/output_columns.test
  Modified files:
    plugins/sharding/logical_select.rb

  Modified: plugins/sharding/logical_select.rb (+16 -12)
===================================================================
--- plugins/sharding/logical_select.rb    2017-03-21 15:10:45 +0900 (49f25be)
+++ plugins/sharding/logical_select.rb    2017-03-21 15:11:43 +0900 (fad67a0)
@@ -95,7 +95,7 @@ module Groonga
           key << "#{drilldown.calc_types}\0"
           key << "#{drilldown.calc_target_name}\0"
         end
-        dynamic_columns = DynamicColumns.parse(input, "")
+        dynamic_columns = DynamicColumns.parse(input)
         [
           :initial,
           :filtered,
@@ -218,22 +218,18 @@ module Groonga
       end
 
       class LabeledArgumentParser
-        def initialize(input)
-          @input = input
-          @arguments = input.arguments
-          @argument = Record.new(@arguments, nil)
+        def initialize(parameters)
+          @parameters = parameters
         end
 
         def parse(prefix_pattern)
           pattern = /\A#{prefix_pattern}\[(.+?)\]\.(.+)\z/
           labeled_arguments = {}
-          @arguments.each do |argument_id|
-            @argument.id = argument_id
-            key =****@argum*****
+          @parameters.each do |key, value|
             match_data = pattern.match(key)
             next if match_data.nil?
             labeled_argument = (labeled_arguments[match_data[1]] ||= {})
-            labeled_argument[match_data[2]] = @input[key]
+            labeled_argument[match_data[2]] = value
           end
           labeled_arguments
         end
@@ -310,7 +306,7 @@ module Groonga
           @sort_keys = parse_keys(@input[:sort_keys] || @input[:sortby])
           @output_columns = @input[:output_columns] || "_id, _key, *"
 
-          @dynamic_columns = DynamicColumns.parse(@input, "")
+          @dynamic_columns = DynamicColumns.parse(@input)
 
           @result_sets = []
           @unsorted_result_sets = []
@@ -348,9 +344,9 @@ module Groonga
 
       class DynamicColumns
         class << self
-          def parse(input, prefix)
+          def parse(input)
             parser = LabeledArgumentParser.new(input)
-            columns = parser.parse(/#{Regexp.escape(prefix)}columns?/)
+            columns = parser.parse(/columns?/)
 
             initial_contexts = []
             filtered_contexts = []
@@ -566,6 +562,7 @@ module Groonga
         attr_reader :output_columns
         attr_reader :calc_target_name
         attr_reader :calc_types
+        attr_reader :dynamic_columns
         attr_accessor :result_set
         attr_accessor :unsorted_result_set
         def initialize(label, parameters)
@@ -580,6 +577,8 @@ module Groonga
           @calc_target_name = parameters["calc_target"]
           @calc_types = parse_calc_types(parameters["calc_types"])
 
+          @dynamic_columns = DynamicColumns.parse(parameters)
+
           @result_set = nil
           @unsorted_result_set = nil
         end
@@ -587,6 +586,8 @@ module Groonga
         def close
           @result_set.close if @result_set
           @unsorted_result_set.close if @unsorted_result_set
+
+          @dynamic_columns.close
         end
 
         def need_command_version2?
@@ -699,6 +700,9 @@ module Groonga
                 end
               end
               result_set = group_result.table
+              drilldown.dynamic_columns.each_initial do |dynamic_column|
+                dynamic_column.apply(result_set)
+              end
               if drilldown.sort_keys.empty?
                 drilldown.result_set = result_set
               else

  Added: test/command/suite/sharding/logical_select/drilldowns/columns/stage/initial/output_columns.expected (+95 -0) 100644
===================================================================
--- /dev/null
+++ test/command/suite/sharding/logical_select/drilldowns/columns/stage/initial/output_columns.expected    2017-03-21 15:11:43 +0900 (0fcc156)
@@ -0,0 +1,95 @@
+plugin_register sharding
+[[0,0.0,0.0],true]
+table_create Logs_20170315 TABLE_NO_KEY
+[[0,0.0,0.0],true]
+column_create Logs_20170315 timestamp COLUMN_SCALAR Time
+[[0,0.0,0.0],true]
+column_create Logs_20170315 price COLUMN_SCALAR UInt32
+[[0,0.0,0.0],true]
+table_create Logs_20170316 TABLE_NO_KEY
+[[0,0.0,0.0],true]
+column_create Logs_20170316 timestamp COLUMN_SCALAR Time
+[[0,0.0,0.0],true]
+column_create Logs_20170316 price COLUMN_SCALAR UInt32
+[[0,0.0,0.0],true]
+table_create Logs_20170317 TABLE_NO_KEY
+[[0,0.0,0.0],true]
+column_create Logs_20170317 timestamp COLUMN_SCALAR Time
+[[0,0.0,0.0],true]
+column_create Logs_20170317 price COLUMN_SCALAR UInt32
+[[0,0.0,0.0],true]
+load --table Logs_20170315
+[
+{"timestamp": "2017/03/15 00:00:00", "price": 1000},
+{"timestamp": "2017/03/15 01:00:00", "price": 1000}
+]
+[[0,0.0,0.0],2]
+load --table Logs_20170316
+[
+{"timestamp": "2017/03/16 10:00:00", "price":  500},
+{"timestamp": "2017/03/16 11:00:00", "price":  500}
+]
+[[0,0.0,0.0],2]
+load --table Logs_20170317
+[
+{"timestamp": "2017/03/17 20:00:00", "price":  500},
+{"timestamp": "2017/03/17 20:00:00", "price":  300}
+]
+[[0,0.0,0.0],2]
+logical_select Logs   --shard_key timestamp   --output_columns _id   --limit 0   --drilldowns[label].keys price   --drilldowns[label].output_columns _key,_nsubrecs,tax_included   --drilldowns[label].columns[tax_included].stage initial   --drilldowns[label].columns[tax_included].type UInt32   --drilldowns[label].columns[tax_included].flags COLUMN_SCALAR   --drilldowns[label].columns[tax_included].value '_key * 1.08'
+[
+  [
+    0,
+    0.0,
+    0.0
+  ],
+  [
+    [
+      [
+        6
+      ],
+      [
+        [
+          "_id",
+          "UInt32"
+        ]
+      ]
+    ],
+    {
+      "label": [
+        [
+          3
+        ],
+        [
+          [
+            "_key",
+            "UInt32"
+          ],
+          [
+            "_nsubrecs",
+            "Int32"
+          ],
+          [
+            "tax_included",
+            "UInt32"
+          ]
+        ],
+        [
+          1000,
+          2,
+          1080
+        ],
+        [
+          500,
+          3,
+          540
+        ],
+        [
+          300,
+          1,
+          324
+        ]
+      ]
+    }
+  ]
+]

  Added: test/command/suite/sharding/logical_select/drilldowns/columns/stage/initial/output_columns.test (+44 -0) 100644
===================================================================
--- /dev/null
+++ test/command/suite/sharding/logical_select/drilldowns/columns/stage/initial/output_columns.test    2017-03-21 15:11:43 +0900 (75c5b39)
@@ -0,0 +1,44 @@
+#@on-error omit
+plugin_register sharding
+#@on-error default
+
+table_create Logs_20170315 TABLE_NO_KEY
+column_create Logs_20170315 timestamp COLUMN_SCALAR Time
+column_create Logs_20170315 price COLUMN_SCALAR UInt32
+
+table_create Logs_20170316 TABLE_NO_KEY
+column_create Logs_20170316 timestamp COLUMN_SCALAR Time
+column_create Logs_20170316 price COLUMN_SCALAR UInt32
+
+table_create Logs_20170317 TABLE_NO_KEY
+column_create Logs_20170317 timestamp COLUMN_SCALAR Time
+column_create Logs_20170317 price COLUMN_SCALAR UInt32
+
+load --table Logs_20170315
+[
+{"timestamp": "2017/03/15 00:00:00", "price": 1000},
+{"timestamp": "2017/03/15 01:00:00", "price": 1000}
+]
+
+load --table Logs_20170316
+[
+{"timestamp": "2017/03/16 10:00:00", "price":  500},
+{"timestamp": "2017/03/16 11:00:00", "price":  500}
+]
+
+load --table Logs_20170317
+[
+{"timestamp": "2017/03/17 20:00:00", "price":  500},
+{"timestamp": "2017/03/17 20:00:00", "price":  300}
+]
+
+logical_select Logs \
+  --shard_key timestamp \
+  --output_columns _id \
+  --limit 0 \
+  --drilldowns[label].keys price \
+  --drilldowns[label].output_columns _key,_nsubrecs,tax_included \
+  --drilldowns[label].columns[tax_included].stage initial \
+  --drilldowns[label].columns[tax_included].type UInt32 \
+  --drilldowns[label].columns[tax_included].flags COLUMN_SCALAR \
+  --drilldowns[label].columns[tax_included].value '_key * 1.08'
-------------- next part --------------
HTML����������������������������...
Download 



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