Kouhei Sutou
null+****@clear*****
Tue Mar 21 18:41:04 JST 2017
Kouhei Sutou 2017-03-21 18:41:04 +0900 (Tue, 21 Mar 2017) New Revision: cf9620d31c3ba49d43d275e453bec255517e32b8 https://github.com/groonga/groonga/commit/cf9620d31c3ba49d43d275e453bec255517e32b8 Message: logical_select: support drilldowns[LABEL].table Added files: test/command/suite/sharding/logical_select/drilldowns/columns/stage/initial/drilldown.expected test/command/suite/sharding/logical_select/drilldowns/columns/stage/initial/drilldown.test Modified files: plugins/sharding/logical_select.rb Modified: plugins/sharding/logical_select.rb (+45 -9) =================================================================== --- plugins/sharding/logical_select.rb 2017-03-21 15:11:43 +0900 (fad67a0) +++ plugins/sharding/logical_select.rb 2017-03-21 18:41:04 +0900 (40c1f42) @@ -511,16 +511,18 @@ module Groonga class LabeledDrilldowns include Enumerable + include TSort class << self def parse(input) parser = LabeledArgumentParser.new(input) drilldowns = parser.parse(/drilldowns?/) - contexts = [] + contexts = {} drilldowns.each do |label, parameters| next if parameters["keys"].nil? - contexts << LabeledDrilldownExecuteContext.new(label, parameters) + context = LabeledDrilldownExecuteContext.new(label, parameters) + contexts[label] = context end new(contexts) @@ -529,16 +531,32 @@ module Groonga def initialize(contexts) @contexts = contexts + @dependencies = {} + @contexts.each do |label, context| + if context.table + depended_context = @contexts[context.table] + if depended_context.nil? + raise "Unknown drilldown: <#{context.table}>" + end + @dependencies[label] = [depended_context] + else + @dependencies[label] = [] + end + end end def close - @contexts.each do |context| + @contexts.each_value do |context| context.close end end + def [](label) + @contexts[label] + end + def have_keys? - @contexts.size > 0 + not****@conte*****? end def n_result_sets @@ -546,7 +564,15 @@ module Groonga end def each(&block) - @contexts.each(&block) + @contexts.each_value(&block) + end + + def tsort_each_node(&block) + @contexts.each_value(&block) + end + + def tsort_each_child(context, &block) + @dependencies[context.label].each(&block) end end @@ -562,6 +588,7 @@ module Groonga attr_reader :output_columns attr_reader :calc_target_name attr_reader :calc_types + attr_reader :table attr_reader :dynamic_columns attr_accessor :result_set attr_accessor :unsorted_result_set @@ -576,6 +603,7 @@ module Groonga @output_columns ||= "_key, _nsubrecs" @calc_target_name = parameters["calc_target"] @calc_types = parse_calc_types(parameters["calc_types"]) + @table = parameters["table"] @dynamic_columns = DynamicColumns.parse(parameters) @@ -682,7 +710,7 @@ module Groonga def execute_labeled_drilldowns drilldowns =****@conte*****_drilldowns - drilldowns.each do |drilldown| + drilldowns.tsort_each do |drilldown| group_result = TableGroupResult.new keys = drilldown.keys begin @@ -693,10 +721,18 @@ module Groonga end group_result.limit = 1 group_result.flags = drilldown.calc_types - @context.result_sets.each do |result_set| + if drilldown.table + target_table = drilldowns[drilldown.table].result_set with_calc_target(group_result, - drilldown.calc_target(result_set)) do - result_set.group(keys, group_result) + drilldown.calc_target(target_table)) do + target_table.group(keys, group_result) + end + else + @context.result_sets.each do |result_set| + with_calc_target(group_result, + drilldown.calc_target(result_set)) do + result_set.group(keys, group_result) + end end end result_set = group_result.table Added: test/command/suite/sharding/logical_select/drilldowns/columns/stage/initial/drilldown.expected (+161 -0) 100644 =================================================================== --- /dev/null +++ test/command/suite/sharding/logical_select/drilldowns/columns/stage/initial/drilldown.expected 2017-03-21 18:41:04 +0900 (897dcf7) @@ -0,0 +1,161 @@ +plugin_register sharding +[[0,0.0,0.0],true] +table_create Items TABLE_HASH_KEY ShortText +[[0,0.0,0.0],true] +column_create Items price COLUMN_SCALAR UInt32 +[[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 items COLUMN_VECTOR Items +[[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 items COLUMN_VECTOR Items +[[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 items COLUMN_VECTOR Items +[[0,0.0,0.0],true] +load --table Items +[ +{"_key": "Book", "price": 1000}, +{"_key": "Note", "price": 1000}, +{"_key": "Box", "price": 500}, +{"_key": "Pen", "price": 500}, +{"_key": "Food", "price": 500}, +{"_key": "Drink", "price": 300} +] +[[0,0.0,0.0],6] +load --table Logs_20170315 +[ +{"timestamp": "2017/03/15 00:00:00", "items": ["Book", "Note", "Box", "Pen"]}, +{"timestamp": "2017/03/15 01:00:00", "items": ["Food", "Drink", "Pen"]} +] +[[0,0.0,0.0],2] +load --table Logs_20170316 +[ +{"timestamp": "2017/03/16 10:00:00", "items": ["Pen", "Note", "Food", "Drink"]}, +{"timestamp": "2017/03/16 11:00:00", "items": ["Note", "Box"]} +] +[[0,0.0,0.0],2] +load --table Logs_20170317 +[ +{"timestamp": "2017/03/17 20:00:00", "items": ["Food", "Book"]}, +{"timestamp": "2017/03/17 20:00:00", "items": ["Drink", "Note"]} +] +[[0,0.0,0.0],2] +logical_select Logs --shard_key timestamp --output_columns _id --limit 0 --drilldowns[item].keys items --drilldowns[item].sort_keys price --drilldowns[item].output_columns _key,_nsubrecs,price,price_with_tax --drilldowns[item].columns[price_with_tax].stage initial --drilldowns[item].columns[price_with_tax].type UInt32 --drilldowns[item].columns[price_with_tax].flags COLUMN_SCALAR --drilldowns[item].columns[price_with_tax].value 'price * 1.08' --drilldowns[real_price].table item --drilldowns[real_price].keys price_with_tax +[ + [ + 0, + 0.0, + 0.0 + ], + [ + [ + [ + 6 + ], + [ + [ + "_id", + "UInt32" + ] + ] + ], + { + "item": [ + [ + 6 + ], + [ + [ + "_key", + "ShortText" + ], + [ + "_nsubrecs", + "Int32" + ], + [ + "price", + "UInt32" + ], + [ + "price_with_tax", + "UInt32" + ] + ], + [ + "Drink", + 3, + 300, + 324 + ], + [ + "Food", + 3, + 500, + 540 + ], + [ + "Pen", + 3, + 500, + 540 + ], + [ + "Box", + 2, + 500, + 540 + ], + [ + "Book", + 2, + 1000, + 1080 + ], + [ + "Note", + 4, + 1000, + 1080 + ] + ], + "real_price": [ + [ + 3 + ], + [ + [ + "_key", + "UInt32" + ], + [ + "_nsubrecs", + "Int32" + ] + ], + [ + 324, + 1 + ], + [ + 540, + 3 + ], + [ + 1080, + 2 + ] + ] + } + ] +] Added: test/command/suite/sharding/logical_select/drilldowns/columns/stage/initial/drilldown.test (+60 -0) 100644 =================================================================== --- /dev/null +++ test/command/suite/sharding/logical_select/drilldowns/columns/stage/initial/drilldown.test 2017-03-21 18:41:04 +0900 (2b74329) @@ -0,0 +1,60 @@ +#@on-error omit +plugin_register sharding +#@on-error default + +table_create Items TABLE_HASH_KEY ShortText +column_create Items price COLUMN_SCALAR UInt32 + +table_create Logs_20170315 TABLE_NO_KEY +column_create Logs_20170315 timestamp COLUMN_SCALAR Time +column_create Logs_20170315 items COLUMN_VECTOR Items + +table_create Logs_20170316 TABLE_NO_KEY +column_create Logs_20170316 timestamp COLUMN_SCALAR Time +column_create Logs_20170316 items COLUMN_VECTOR Items + +table_create Logs_20170317 TABLE_NO_KEY +column_create Logs_20170317 timestamp COLUMN_SCALAR Time +column_create Logs_20170317 items COLUMN_VECTOR Items + +load --table Items +[ +{"_key": "Book", "price": 1000}, +{"_key": "Note", "price": 1000}, +{"_key": "Box", "price": 500}, +{"_key": "Pen", "price": 500}, +{"_key": "Food", "price": 500}, +{"_key": "Drink", "price": 300} +] + +load --table Logs_20170315 +[ +{"timestamp": "2017/03/15 00:00:00", "items": ["Book", "Note", "Box", "Pen"]}, +{"timestamp": "2017/03/15 01:00:00", "items": ["Food", "Drink", "Pen"]} +] + +load --table Logs_20170316 +[ +{"timestamp": "2017/03/16 10:00:00", "items": ["Pen", "Note", "Food", "Drink"]}, +{"timestamp": "2017/03/16 11:00:00", "items": ["Note", "Box"]} +] + +load --table Logs_20170317 +[ +{"timestamp": "2017/03/17 20:00:00", "items": ["Food", "Book"]}, +{"timestamp": "2017/03/17 20:00:00", "items": ["Drink", "Note"]} +] + +logical_select Logs \ + --shard_key timestamp \ + --output_columns _id \ + --limit 0 \ + --drilldowns[item].keys items \ + --drilldowns[item].sort_keys price \ + --drilldowns[item].output_columns _key,_nsubrecs,price,price_with_tax \ + --drilldowns[item].columns[price_with_tax].stage initial \ + --drilldowns[item].columns[price_with_tax].type UInt32 \ + --drilldowns[item].columns[price_with_tax].flags COLUMN_SCALAR \ + --drilldowns[item].columns[price_with_tax].value 'price * 1.08' \ + --drilldowns[real_price].table item \ + --drilldowns[real_price].keys price_with_tax -------------- next part -------------- HTML����������������������������...Download